CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
Babayaga.cxx
Go to the documentation of this file.
1//*****************************************************************************
2//
3// BABAYAGA.cxx
4//
5// Algorithm runs BHABHA precess
6//
7// July 2007 Rong-Gang Ping to migrate BABAYAGA3.5 for BES3
8// The accuracy is about 0.1% (see Nucl. Phys. B 758(2006) 227-253)
9//*****************************************************************************
10
11// Header for this module:-
15
16// Framework Related Headers:-
17#include "HepMC/GenEvent.h"
18#include "HepMC/GenVertex.h"
19#include "HepMC/GenParticle.h"
20
21#include "GaudiKernel/MsgStream.h"
22#include "GaudiKernel/ISvcLocator.h"
23#include "GaudiKernel/AlgFactory.h"
24#include "GaudiKernel/DataSvc.h"
25#include "GaudiKernel/SmartDataPtr.h"
26
28#include "CLHEP/Vector/LorentzVector.h"
29#include "cfortran/cfortran.h"
30
31#include <stdlib.h>
32
33//COMMON/MOMSET/PM,PP,PFINEL,PFINPOS,QPH
34//dimension PM(0:3),PP(0:3),PFINEL(0:3),PFINPOS(0:3),QPH(40,0:3) //OUTPUT RESULTS PM(0:3),PP(0:3) for beam electron and positron
35//particle
36
37 typedef struct {
38 double q1[4][160001];
39 double p1[4][160001];
40 double q2[4][160001];
41 double p2[4][160001];
42 double phot[4][10][160001];
43 } MOMSET_DEF;
44//MOMSET_DEF MOMSET;
45#define MOMSET COMMON_BLOCK(MOMSET_DEF, momset)
47
48//COMMON/ISRPHOTONS/NCQPH
49typedef struct{
50 int ncqph[160000];
52#define ISRPHOTONS COMMON_BLOCK(ISRPHOTONS_DEF, isrphotons)
54
55//common/beamEnergy/ebeam
56typedef struct {
57double ebeam;
59#define BEAMENERGY COMMON_BLOCK(BEAMENERGY_DEF, beamenergy)
61//BEAMENERGY_DEF,BEAMENERGY
62
63//common/expcuts/thmin,thmax,emin,zmax,egmin,thgmin,thgmax
64typedef struct {
65double thmin,thmax,emin,zmax,egmin,thgmin,thgmax;
67#define EXPCUTS COMMON_BLOCK(EXPCUTS_DEF, expcuts)
69//EXPCUTS_DEF,EXPCUTS;
70
71//common/switchFSR/ON,ILL
72typedef struct{
73int on,ill;
75#define SWITCH COMMON_BLOCK(SWITCH_DEF,switchfsr)
77
78//common/switcharun/IARUN
79typedef struct{
82#define SWITCHARUN COMMON_BLOCK(SWITCHARUN_DEF,switcharun)
84
85//COMMON/CHANNEL/ICH
86typedef struct{
87int ich;
89#define CHANNEL COMMON_BLOCK(CHANNEL_DEF,channel)
91
92//common/resonances/IRES
93typedef struct{
94int ires;
96#define RESONANCES COMMON_BLOCK(RESONANCES_DEF,resonances)
98
99//COMMON/DECLAREINT/INT
100typedef struct{
103#define DECLAREINT COMMON_BLOCK(DECLAREINT_DEF,declareint)
105
106//COMMON/DECLARESTR/INTUPLE,PHCUT,CUTG
107typedef struct{
108char tuple,phcut,cutg;
110#define DECLARESTR COMMON_BLOCK(DECLARESTR_DEF,declarestr)
112
113
114
115//--//Unify Babayaga random engine with Bes random servive
116extern "C" {
117 extern float flat_();
118}
119
120float flat_(){
121 float rr;
122 double rd=BabayagaRandom::random();
123// std::cout<<"BabayagaRandom::random()="<<rd<<endl;
124 rr=(float)rd;
125 return (float)BabayagaRandom::random();
126 // return rr;
127}
128
129
130
131PROTOCCALLSFSUB1(BABAYAGA,babayaga,INT)
132#define BABAYAGA(NEVENTS) CCALLSFSUB1(BABAYAGA,babayaga,INT,NEVENTS)
133
134
135Babayaga::Babayaga(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
136{
137 // declareProperty("Seed", m_Int = 62341342); // seed for random number generator
138 declareProperty("Channel", m_Ich = 1); // 1: e+e-->e+e-;2:e+e_->mu+mu-;3:e+e-->gamma gamma;4:e+e--->pi+pi-
139 declareProperty("Ebeam", m_Ebeam = 1.548); // Ecm = 2*Ebeam [GeV]
140 declareProperty("MinThetaAngle", m_Thmin = 70); // [degree]
141 declareProperty("MaxThetaAngle", m_Thmax = 178); // [degree]
142 declareProperty("MinimumEnergy", m_Emin = 0.4); // Minimum Energy(GeV)
143 declareProperty("MaximumAcollinearity", m_Zmax = 10); //Maximum acollinearity (degree)
144 declareProperty("RunningAlpha", m_Iarun = 1); //running alpha, 0=off, 1=on
145 declareProperty("HadronicResonance", m_Ires = 0); //hadronic resoances for ICH=1 or 2
146 declareProperty("FSR_swich", m_on = 0); // FSR switch for ICH=2 ( 0=off, 1=on)
147 declareProperty("MinEnerCutG", m_Egmin = 0.01); // minimum energy for CUTG=Y (GeV)
148 declareProperty("MinAngCutG", m_Thgmin = 5); // minimum angle for cuts =Y (deg.)
149 declareProperty("MaxAngCutG", m_Thgmax = 21); //maximum angle for CUTG=Y (deg.)
150 declareProperty("HBOOK", HN= 1); //INTUPLE: if events have to be stored (1/0)
151 declareProperty("PHCUT", m_PHCUT = 0); //PHCUT: to avoid double counting when ICH = 3 (1/0), for other channels, it set as 0 by default
152 declareProperty("CUTG", m_CUTG = 0); //CUTG: explicit cuts on the generated photons (1/0)
153}
154
156
157 MsgStream log(messageService(), name());
158
159 log << MSG::INFO << "Babayaga initialize" << endreq;
160
161 //set Bes unified random engine
162 static const bool CREATEIFNOTTHERE(true);
163 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
164 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
165 {
166 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
167 return RndmStatus;
168 }
169 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("Babayaga");
170 std::cout<<"==============================="<<engine<<endl;
172 // *****************
173
174 if(HN==1) {DECLARESTR.tuple='Y';} else DECLARESTR.tuple='N';
175 if(m_PHCUT==1){ DECLARESTR.phcut='Y';} else DECLARESTR.cutg='N';
176 if(m_CUTG ==1){ DECLARESTR.cutg='Y';} else DECLARESTR.cutg='N';
177 CHANNEL.ich = m_Ich;
178 BEAMENERGY.ebeam=m_Ebeam;
179 EXPCUTS.thmin=m_Thmin;
180 EXPCUTS.thmax=m_Thmax;
181 EXPCUTS.emin =m_Emin;
182 EXPCUTS.zmax=m_Zmax;
183 SWITCHARUN.iarun=m_Iarun;
184 RESONANCES.ires =m_Ires;
185 SWITCH.on =m_on;
186 EXPCUTS.egmin=m_Egmin;
187 EXPCUTS.thgmin=m_Thgmin;
188 EXPCUTS.thgmax=m_Thgmax;
189
190 // std::cout<<"m_Ires= "<<m_Ires<<endl;
191
192 getMaxEvent();
193 std::cout<<"m_evtMax = "<<m_evtMax<<std::endl;
194 DECLAREINT.seed=m_Int;
195 BABAYAGA(m_evtMax);
196
197 return StatusCode::SUCCESS;
198}
199
200static int evtgen=1;
201StatusCode Babayaga::execute()
202{
203 MsgStream log(messageService(), name());
204// log << MSG::INFO << "BABAYAGA executing" << endreq;
205// std::cout<<"BABAYAGA begin executing"<<std::endl;
206
207 int npart = 0;
208 int pid1,pid2,pst1,pst2;
209 if(m_Ich==1) {pid1=11; pid2=-11; pst1=1;pst2=1;}
210 if(m_Ich==2) {pid1=13; pid2=-13; pst1=1;pst2=1;}
211 if(m_Ich==3) {pid1=22; pid2= 22; pst1=1;pst2=1;}
212 if(m_Ich==4) {pid1=-211; pid2= 211; pst1=1;pst2=1;}
213
214 // Fill event information
215 GenEvent* evt = new GenEvent(1,1);
216
217 GenVertex* prod_vtx = new GenVertex();
218// prod_vtx->add_particle_out( p );
219 evt->add_vertex( prod_vtx );
220
221 // incoming beam e- HepLorentzVector(px,py,pz,energy) required!
222 GenParticle* p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[1][evtgen], MOMSET.p1[2][evtgen],
223 MOMSET.p1[3][evtgen], MOMSET.p1[0][evtgen]),
224 11, 3);
225 p->suggest_barcode( ++npart );
226 prod_vtx->add_particle_in(p);
227
228// std::cout<<"incoming beam e+"<<endl;
229 // incoming beam e+, e+ moving along the z-direction
230 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[1][evtgen], MOMSET.q1[2][evtgen],
231 MOMSET.q1[3][evtgen], MOMSET.q1[4][evtgen]),
232 -11, 3);
233
234 p->suggest_barcode( ++npart );
235 prod_vtx->add_particle_in(p);
236
237 // scattered lepton +
238 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[1][evtgen], MOMSET.p2[2][evtgen],
239 MOMSET.p2[3][evtgen], MOMSET.p2[0][evtgen]),
240 pid1,pst1);
241 p->suggest_barcode( ++npart );
242 prod_vtx->add_particle_out(p);
243
244 // debuging pingrg
245 // std::cout<<"evtgen= "<<evtgen<<std::endl;
246 //std::cout<<"b:e-: "<<MOMSET.p1[0][evtgen]<<"; "<< MOMSET.p1[1][evtgen]<<"; "<<MOMSET.p1[2][evtgen]<<"; "<< MOMSET.p1[3][evtgen]<<std::endl;
247 //std::cout<<"b:e+: "<<MOMSET.q1[0][evtgen]<<"; "<< MOMSET.q1[1][evtgen]<<"; "<<MOMSET.q1[2][evtgen]<<"; "<< MOMSET.q1[3][evtgen]<<std::endl;
248 //std::cout<<"e-: "<<MOMSET.p2[0][evtgen]<<"; "<< MOMSET.p2[1][evtgen]<<"; "<<MOMSET.p2[2][evtgen]<<"; "<< MOMSET.p2[3][evtgen]<<std::endl;
249 //std::cout<<"e+: "<<MOMSET.q2[0][evtgen]<<"; "<< MOMSET.q2[1][evtgen]<<"; "<<MOMSET.q2[2][evtgen]<<"; "<< MOMSET.q2[3][evtgen]<<std::endl;
250
251 // scattered lepton -
252 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[1][evtgen], MOMSET.q2[2][evtgen],
253 MOMSET.q2[3][evtgen], MOMSET.q2[0][evtgen]),
254 pid2, pst2);
255 p->suggest_barcode( ++npart );
256 prod_vtx->add_particle_out(p);
257
258
259 int iphot=0;
260 // std::cout<<"evtgen, ncqph[events#] "<<evtgen<<"; "<<ISRPHOTONS.ncqph[evtgen-1]<<std::endl;
261 for (iphot=0; iphot<ISRPHOTONS.ncqph[evtgen-1]; iphot++)
262 {
263 // debuging, pingrg
264 // std::cout<<"evtgen, iphot= "<<evtgen<<"; "<<iphot<<std::endl;
265 //std::cout<<MOMSET.phot[0][iphot][evtgen]<<", "<<MOMSET.phot[1][iphot][evtgen]<<", "<<MOMSET.phot[2][iphot][evtgen]<<", "<<MOMSET.phot[3][iphot][evtgen]<<std::endl;
266
267 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.phot[1][iphot][evtgen], MOMSET.phot[2][iphot][evtgen],
268 MOMSET.phot[3][iphot][evtgen], MOMSET.phot[0][iphot][evtgen]),
269 22, 1);
270 p->suggest_barcode( ++npart );
271 prod_vtx->add_particle_out(p);
272
273 }
274
275
276 evtgen++;
277
278 if( log.level() < MSG::INFO )
279 {
280 evt->print();
281 }
282
283 // Check if the McCollection already exists
284 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
285 if (anMcCol!=0)
286 {
287 // Add event to existing collection
288 MsgStream log(messageService(), name());
289 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
290 McGenEvent* mcEvent = new McGenEvent(evt);
291 anMcCol->push_back(mcEvent);
292 }
293 else
294 {
295 // Create Collection and add to the transient store
296 McGenEventCol *mcColl = new McGenEventCol;
297 McGenEvent* mcEvent = new McGenEvent(evt);
298 mcColl->push_back(mcEvent);
299 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
300 if (sc != StatusCode::SUCCESS)
301 {
302 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
303 delete mcColl;
304 delete evt;
305 delete mcEvent;
306 return StatusCode::FAILURE;
307 }
308 else
309 {
310 // log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in McGenEvent" << endreq;
311 }
312 }
313
314 return StatusCode::SUCCESS;
315}
316
318{
319 MsgStream log(messageService(), name());
320 char delcmd[300];
321 strcpy(delcmd,"cat ");
322 strcat(delcmd,"CrossSection.txt");
323 system(delcmd);
324
325 std::cout<< "BABAYAGA finalized" << endl;
326 return StatusCode::SUCCESS;
327}
328
330 IProperty* appPropMgr=0;
331 StatusCode status =
332 serviceLocator()->getService("ApplicationMgr", IProperty::interfaceID(),
333 reinterpret_cast<IInterface*&>( appPropMgr ));
334 if( status.isFailure() ) return status;
335
336 IntegerProperty evtMax("EvtMax",0);
337 status = appPropMgr->getProperty( &evtMax );
338 if (status.isFailure()) return status;
339
340 m_evtMax = evtMax.value();
341 return status;
342}
343
#define MOMSET
Definition Babayaga.cxx:45
#define SWITCHARUN
Definition Babayaga.cxx:82
#define EXPCUTS
Definition Babayaga.cxx:67
#define BABAYAGA(NEVENTS)
Definition Babayaga.cxx:132
#define DECLAREINT
Definition Babayaga.cxx:103
#define ISRPHOTONS
Definition Babayaga.cxx:52
#define DECLARESTR
Definition Babayaga.cxx:110
#define SWITCH
Definition Babayaga.cxx:75
#define CHANNEL
Definition Babayaga.cxx:89
#define BEAMENERGY
Definition Babayaga.cxx:59
#define RESONANCES
Definition Babayaga.cxx:96
float flat_()
Definition Babayaga.cxx:120
ObjectVector< McGenEvent > McGenEventCol
Definition McGenEvent.h:39
#define COMMON_BLOCK_DEF(DEFINITION, NAME)
Definition cfortran.h:271
#define PROTOCCALLSFSUB1(UN, LN, T1)
Definition cfortran.h:1001
static void setRandomEngine(CLHEP::HepRandomEngine *randomEngine)
static double random()
StatusCode getMaxEvent()
Definition Babayaga.cxx:329
StatusCode finalize()
Definition Babayaga.cxx:317
Babayaga(const string &name, ISvcLocator *pSvcLocator)
Definition Babayaga.cxx:135
StatusCode initialize()
Definition Babayaga.cxx:155
StatusCode execute()
Definition Babayaga.cxx:201
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.
double egmin
Definition Babayaga.cxx:65