BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
CosmicGun.cxx
Go to the documentation of this file.
1
2#include <iostream>
3#include <iomanip>
4#include <math.h>
6
7//--------------------------------------------------------
8//
9// These are the fortran subroutines
10//
11extern "C"{
12 void cosmic2_(void);
13 void cosipr_(void);
14 void cosgin_(void);
15 void 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
50 if(!mpointer) mpointer = new CosmicGun();
51 return mpointer;
52}
53
54
55//--------------------------------------------------------
56//
57// constructor with some default settings
58//
59// 9 August 2005, RMcP: remove initialization from constructor.
60CosmicGun::CosmicGun(void){
61 m_event = 0;
62 m_emin = 50;
63 m_emax = 500;
64 m_coscut = 0.35;
65 m_printevt = 20;
66 m_printmod = 50;
67
68 coscut_.ctcut = m_coscut;
69 genpar_.LEMIN = log10(m_emin);
70 genpar_.LEMAX = log10(m_emax);
71 genpar_.NBIN = 100;
73
74 // cosipr_();
75 // cosgin_();
76
77}
78
79// Add separate generator initialization routine
80// to avoid forced default initialization, RMcP 9 Aug 05.
82 std::cout << " CosmicGun::InitializeGenerator: E(min,max)=(" << m_emin << "," << m_emax
83 << ") GeV, and cos(ThetaCut)="<< m_coscut << std::endl;
84 cosipr_();
85 cosgin_();
86 cosmic2_();
87 return flxout_.FLUX2;
88}
89
90void CosmicGun::PrintLevel(int printevt,int printmod){
91 if (printevt >= 0)
92 {
93 m_printevt = printevt;
94 }
95 else
96 {
97 std::cerr << "CosmicGun::PrintLevel - warning ignored input printevt = " << printevt << std::endl;
98 }
99 if (printmod >= 1)
100 {
101 m_printmod = printmod;
102 }
103 else
104 {
105 std::cerr << "CosmicGun::PrintLevel - warning ignored input printmod = " << printmod << std::endl;
106 }
107}
108
109HepLorentzVector CosmicGun::GenerateEvent(void){
110 int iacc = 0;
111
112 while(iacc == 0){
113 cosgen_(&m_emin, &m_emax, &iacc);
114 }
115 m_event++;
116
117 float sinth = sqrt( 1-pow(cosevt_.COSTH,2) );
118 float e = cosevt_.ENER;
119 float px = cosevt_.ENER * sinth * sin( cosevt_.PHI);
120 float py = cosevt_.ENER * sinth * cos( cosevt_.PHI);
121 float pz = cosevt_.ENER * cosevt_.COSTH;
122 HepLorentzVector p(px,py,pz,e);
123
124 // if(m_event < m_printevt || m_event%m_printmod == 0)
125 if(m_event < m_printevt)
126 {
127 std::cout << "CosmicGun::GenerateEvent: " << std::setw(4) << m_event
128 << " muon charge " << std::setw(2) << cosevt_.CHRG << " with momentum : " << p << std::endl;
129 }
130
131 return p;
132}
133
135 return (int)cosevt_.CHRG;
136}
137
138void CosmicGun::SetEnergyRange(float emin, float emax){
139 if(emin >= emax || emin < 0 )
140 {
141 std::cout << "Error input energy range : (" << emin << " - " << emax << ") - ignored " << std::endl;
142 return;
143 }
144 m_emin = emin;
145 m_emax = emax;
146
147 genpar_.LEMIN = log10(m_emin);
148 genpar_.LEMAX = log10(m_emax);
149 genpar_.NBIN = 100;
151
152}
153
154void CosmicGun::SetCosCut(float ctcut){
155 m_coscut = ctcut;
156
157 coscut_.ctcut = m_coscut;
158}
159
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
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)
void PrintLevel(int printevt, int printmod)
Definition CosmicGun.cxx:90
void SetEnergyRange(float emin, float emax)
int GetMuonCharge(void)
HepLorentzVector GenerateEvent(void)
float InitializeGenerator()
Definition CosmicGun.cxx:81
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