BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
CosmicGun.cxx
Go to the documentation of this file.
1
2#include "CosmicGun.h"
3#include <iomanip>
4#include <iostream>
5#include <math.h>
6
7//--------------------------------------------------------
8//
9// These are the fortran subroutines
10//
11extern "C" {
12void cosmic2_( void );
13void cosipr_( void );
14void cosgin_( void );
15void cosgen_( float* emin, float* emax, int* iacc );
16}
17//--------------------------------------------------------
18//
19// and the common blocks
20//
21struct genpar {
23 int NBIN;
24 float PROBE[100];
25};
27
28struct coscut {
29 float ctcut;
30};
32
33struct cosevt {
34 float ENER, COSTH, PHI, CHRG;
35};
37
38struct flxout {
39 float FLUX, FLUX2;
40};
42
43//--------------------------------------------------------
44//
45// singleton pattern
46//
47CosmicGun* CosmicGun::mpointer = 0;
48
49CosmicGun* CosmicGun::GetCosmicGun( void ) {
50 if ( !mpointer ) mpointer = new CosmicGun();
51 return mpointer;
52}
53
54//--------------------------------------------------------
55//
56// constructor with some default settings
57//
58// 9 August 2005, RMcP: remove initialization from constructor.
59CosmicGun::CosmicGun( void ) {
60 m_event = 0;
61 m_emin = 50;
62 m_emax = 500;
63 m_coscut = 0.35;
64 m_printevt = 20;
65 m_printmod = 50;
66
67 coscut_.ctcut = m_coscut;
68 genpar_.LEMIN = log10( m_emin );
69 genpar_.LEMAX = log10( m_emax );
70 genpar_.NBIN = 100;
71 genpar_.LBINWID = ( genpar_.LEMAX - genpar_.LEMIN ) / genpar_.NBIN;
72
73 // cosipr_();
74 // cosgin_();
75}
76
77// Add separate generator initialization routine
78// to avoid forced default initialization, RMcP 9 Aug 05.
80 std::cout << " CosmicGun::InitializeGenerator: E(min,max)=(" << m_emin << "," << m_emax
81 << ") GeV, and cos(ThetaCut)=" << m_coscut << std::endl;
82 cosipr_();
83 cosgin_();
84 cosmic2_();
85 return flxout_.FLUX2;
86}
87
88void CosmicGun::PrintLevel( int printevt, int printmod ) {
89 if ( printevt >= 0 ) { m_printevt = printevt; }
90 else
91 {
92 std::cerr << "CosmicGun::PrintLevel - warning ignored input printevt = " << printevt
93 << std::endl;
94 }
95 if ( printmod >= 1 ) { m_printmod = printmod; }
96 else
97 {
98 std::cerr << "CosmicGun::PrintLevel - warning ignored input printmod = " << printmod
99 << std::endl;
100 }
101}
102
103HepLorentzVector CosmicGun::GenerateEvent( void ) {
104 int iacc = 0;
105
106 while ( iacc == 0 ) { cosgen_( &m_emin, &m_emax, &iacc ); }
107 m_event++;
108
109 float sinth = sqrt( 1 - pow( cosevt_.COSTH, 2 ) );
110 float e = cosevt_.ENER;
111 float px = cosevt_.ENER * sinth * sin( cosevt_.PHI );
112 float py = cosevt_.ENER * sinth * cos( cosevt_.PHI );
113 float pz = cosevt_.ENER * cosevt_.COSTH;
114 HepLorentzVector p( px, py, pz, e );
115
116 // if(m_event < m_printevt || m_event%m_printmod == 0)
117 if ( m_event < m_printevt )
118 {
119 std::cout << "CosmicGun::GenerateEvent: " << std::setw( 4 ) << m_event << " muon charge "
120 << std::setw( 2 ) << cosevt_.CHRG << " with momentum : " << p << std::endl;
121 }
122
123 return p;
124}
125
126int CosmicGun::GetMuonCharge( void ) { return (int)cosevt_.CHRG; }
127
128void CosmicGun::SetEnergyRange( float emin, float emax ) {
129 if ( emin >= emax || emin < 0 )
130 {
131 std::cout << "Error input energy range : (" << emin << " - " << emax << ") - ignored "
132 << std::endl;
133 return;
134 }
135 m_emin = emin;
136 m_emax = emax;
137
138 genpar_.LEMIN = log10( m_emin );
139 genpar_.LEMAX = log10( m_emax );
140 genpar_.NBIN = 100;
141 genpar_.LBINWID = ( genpar_.LEMAX - genpar_.LEMIN ) / genpar_.NBIN;
142}
143
144void CosmicGun::SetCosCut( float ctcut ) {
145 m_coscut = ctcut;
146
147 coscut_.ctcut = m_coscut;
148}
void cosgin_(void)
genpar genpar_
Definition CosmicGun.cxx:26
void cosmic2_(void)
flxout flxout_
Definition CosmicGun.cxx:41
cosevt cosevt_
Definition CosmicGun.cxx:36
void cosgen_(float *emin, float *emax, int *iacc)
coscut coscut_
Definition CosmicGun.cxx:31
void cosipr_(void)
*********Class see also m_nmax DOUBLE PRECISION m_emin
Definition KarFin.h:12
void PrintLevel(int printevt, int printmod)
Definition CosmicGun.cxx:88
void SetEnergyRange(float emin, float emax)
int GetMuonCharge(void)
HepLorentzVector GenerateEvent(void)
float InitializeGenerator()
Definition CosmicGun.cxx:79
void SetCosCut(float ctcut)
static CosmicGun * GetCosmicGun(void)
Definition CosmicGun.cxx:49
float ctcut
Definition CosmicGun.cxx:29
float CHRG
Definition CosmicGun.cxx:34
float COSTH
Definition CosmicGun.cxx:34
float PHI
Definition CosmicGun.cxx:34
float ENER
Definition CosmicGun.cxx:34
float FLUX
Definition CosmicGun.cxx:39
float FLUX2
Definition CosmicGun.cxx:39
int NBIN
Definition CosmicGun.cxx:23
float LEMAX
Definition CosmicGun.cxx:22
float LEMIN
Definition CosmicGun.cxx:22
float PROBE[100]
Definition CosmicGun.cxx:24
float LBINWID
Definition CosmicGun.cxx:22