BOSS 7.0.1
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:-
12#include "../Babayaga/Babayaga.h"
13#include "../Babayaga/BabayagaRandom.h"
14#include "BesKernel/IBesRndmGenSvc.h"
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
27#include "GeneratorObject/McGenEvent.h"
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)
47typedef struct {
48 double CutNgam,CutEgam;
49} RADBB_DEF;
50//RADBB_DEF RADBB;
51#define RADBB COMMON_BLOCK(RADBB_DEF, radbb)
53
54//COMMON/ISRPHOTONS/NCQPH
55typedef struct{
56 int ncqph[160000];
58#define ISRPHOTONS COMMON_BLOCK(ISRPHOTONS_DEF, isrphotons)
60
61//common/beamEnergy/ebeam
62typedef struct {
63double ebeam;
65#define BEAMENERGY COMMON_BLOCK(BEAMENERGY_DEF, beamenergy)
67//BEAMENERGY_DEF,BEAMENERGY
68
69//common/expcuts/thmin,thmax,emin,zmax,egmin,thgmin,thgmax
70typedef struct {
71double thmin,thmax,emin,zmax,egmin,thgmin,thgmax;
73#define EXPCUTS COMMON_BLOCK(EXPCUTS_DEF, expcuts)
75//EXPCUTS_DEF,EXPCUTS;
76
77//common/switchFSR/ON,ILL
78typedef struct{
79int on,ill;
81#define SWITCH COMMON_BLOCK(SWITCH_DEF,switchfsr)
83
84//common/switcharun/IARUN
85typedef struct{
88#define SWITCHARUN COMMON_BLOCK(SWITCHARUN_DEF,switcharun)
90
91//COMMON/CHANNEL/ICH
92typedef struct{
93int ich;
95#define CHANNEL COMMON_BLOCK(CHANNEL_DEF,channel)
97
98//common/resonances/IRES
99typedef struct{
102#define RESONANCES COMMON_BLOCK(RESONANCES_DEF,resonances)
104
105//COMMON/DECLAREINT/INT
106typedef struct{
109#define DECLAREINT COMMON_BLOCK(DECLAREINT_DEF,declareint)
111
112//COMMON/DECLARESTR/INTUPLE,PHCUT,CUTG
113typedef struct{
114char tuple,phcut,cutg;
116#define DECLARESTR COMMON_BLOCK(DECLARESTR_DEF,declarestr)
118
119
120
121//--//Unify Babayaga random engine with Bes random servive
122extern "C" {
123 extern float flat_();
124}
125
126float flat_(){
127 float rr;
128 double rd=BabayagaRandom::random();
129// std::cout<<"BabayagaRandom::random()="<<rd<<endl;
130 rr=(float)rd;
131 return (float)BabayagaRandom::random();
132 // return rr;
133}
134
135
136
137PROTOCCALLSFSUB1(BABAYAGA,babayaga,INT)
138#define BABAYAGA(NEVENTS) CCALLSFSUB1(BABAYAGA,babayaga,INT,NEVENTS)
139
140
141Babayaga::Babayaga(const string& name, ISvcLocator* pSvcLocator):Algorithm( name, pSvcLocator )
142{
143 // declareProperty("Seed", m_Int = 62341342); // seed for random number generator
144 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-
145 declareProperty("Ebeam", m_Ebeam = 1.548); // Ecm = 2*Ebeam [GeV]
146 declareProperty("MinThetaAngle", m_Thmin = 70); // [degree]
147 declareProperty("MaxThetaAngle", m_Thmax = 178); // [degree]
148 declareProperty("MinimumEnergy", m_Emin = 0.4); // Minimum Energy(GeV)
149 declareProperty("MaximumAcollinearity", m_Zmax = 10); //Maximum acollinearity (degree)
150 declareProperty("RunningAlpha", m_Iarun = 1); //running alpha, 0=off, 1=on
151 declareProperty("HadronicResonance", m_Ires = 0); //hadronic resoances for ICH=1 or 2
152 declareProperty("FSR_swich", m_on = 0); // FSR switch for ICH=2 ( 0=off, 1=on)
153 declareProperty("MinEnerCutG", m_Egmin = 0.01); // minimum energy for CUTG=Y (GeV)
154 declareProperty("MinAngCutG", m_Thgmin = 5); // minimum angle for cuts =Y (deg.)
155 declareProperty("MaxAngCutG", m_Thgmax = 21); //maximum angle for CUTG=Y (deg.)
156 declareProperty("HBOOK", HN= 1); //INTUPLE: if events have to be stored (1/0)
157 declareProperty("PHCUT", m_PHCUT = 0); //PHCUT: to avoid double counting when ICH = 3 (1/0), for other channels, it set as 0 by default
158 declareProperty("CUTG", m_CUTG = 0); //CUTG: explicit cuts on the generated photons (1/0)
159 declareProperty("CutNgam", m_CutNgam = 0); //mininum number of ISR photon cut on Radiative Bhabha events
160 declareProperty("CutEgam", m_CutEgam = 0); //in GeV, mininum energy of ISR photon cut on Radiative Bhabha events
161}
162
164
165 MsgStream log(messageService(), name());
166
167 log << MSG::INFO << "Babayaga initialize" << endreq;
168
169 //set Bes unified random engine
170 static const bool CREATEIFNOTTHERE(true);
171 StatusCode RndmStatus = service("BesRndmGenSvc", p_BesRndmGenSvc, CREATEIFNOTTHERE);
172 if (!RndmStatus.isSuccess() || 0 == p_BesRndmGenSvc)
173 {
174 log << MSG::ERROR << " Could not initialize Random Number Service" << endreq;
175 return RndmStatus;
176 }
177 CLHEP::HepRandomEngine* engine = p_BesRndmGenSvc->GetEngine("Babayaga");
178 std::cout<<"==============================="<<engine<<endl;
180 // *****************
181
182 if(HN==1) {DECLARESTR.tuple='Y';} else DECLARESTR.tuple='N';
183 if(m_PHCUT==1){ DECLARESTR.phcut='Y';} else DECLARESTR.cutg='N';
184 if(m_CUTG ==1){ DECLARESTR.cutg='Y';} else DECLARESTR.cutg='N';
185 CHANNEL.ich = m_Ich;
186 BEAMENERGY.ebeam=m_Ebeam;
187 EXPCUTS.thmin=m_Thmin;
188 EXPCUTS.thmax=m_Thmax;
189 EXPCUTS.emin =m_Emin;
190 EXPCUTS.zmax=m_Zmax;
191 SWITCHARUN.iarun=m_Iarun;
192 RESONANCES.ires =m_Ires;
193 SWITCH.on =m_on;
194 EXPCUTS.egmin=m_Egmin;
195 EXPCUTS.thgmin=m_Thgmin;
196 EXPCUTS.thgmax=m_Thgmax;
197
198 // std::cout<<"m_Ires= "<<m_Ires<<endl;
199
200 getMaxEvent();
201 std::cout<<"m_evtMax = "<<m_evtMax<<std::endl;
202 DECLAREINT.seed=m_Int;
203 BABAYAGA(m_evtMax);
204
205 return StatusCode::SUCCESS;
206}
207
208static int evtgen=1;
209StatusCode Babayaga::execute()
210{
211 MsgStream log(messageService(), name());
212// log << MSG::INFO << "BABAYAGA executing" << endreq;
213// std::cout<<"BABAYAGA begin executing"<<std::endl;
214
215 int npart = 0;
216 int pid1,pid2,pst1,pst2;
217 if(m_Ich==1) {pid1=11; pid2=-11; pst1=1;pst2=1;}
218 if(m_Ich==2) {pid1=13; pid2=-13; pst1=1;pst2=1;}
219 if(m_Ich==3) {pid1=22; pid2= 22; pst1=1;pst2=1;}
220 if(m_Ich==4) {pid1=-211; pid2= 211; pst1=1;pst2=1;}
221
222 // Fill event information
223 GenEvent* evt = new GenEvent(1,1);
224
225 GenVertex* prod_vtx = new GenVertex();
226// prod_vtx->add_particle_out( p );
227 evt->add_vertex( prod_vtx );
228
229 // incoming beam e- HepLorentzVector(px,py,pz,energy) required!
230 GenParticle* p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p1[1][evtgen], MOMSET.p1[2][evtgen],
231 MOMSET.p1[3][evtgen], MOMSET.p1[0][evtgen]),
232 11, 3);
233 p->suggest_barcode( ++npart );
234 prod_vtx->add_particle_in(p);
235
236// std::cout<<"incoming beam e+"<<endl;
237 // incoming beam e+, e+ moving along the z-direction
238 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q1[1][evtgen], MOMSET.q1[2][evtgen],
239 MOMSET.q1[3][evtgen], MOMSET.q1[4][evtgen]),
240 -11, 3);
241
242 p->suggest_barcode( ++npart );
243 prod_vtx->add_particle_in(p);
244
245 // scattered lepton +
246 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.p2[1][evtgen], MOMSET.p2[2][evtgen],
247 MOMSET.p2[3][evtgen], MOMSET.p2[0][evtgen]),
248 pid1,pst1);
249 p->suggest_barcode( ++npart );
250 prod_vtx->add_particle_out(p);
251
252 // debuging pingrg
253 // std::cout<<"evtgen= "<<evtgen<<std::endl;
254 //std::cout<<"b:e-: "<<MOMSET.p1[0][evtgen]<<"; "<< MOMSET.p1[1][evtgen]<<"; "<<MOMSET.p1[2][evtgen]<<"; "<< MOMSET.p1[3][evtgen]<<std::endl;
255 //std::cout<<"b:e+: "<<MOMSET.q1[0][evtgen]<<"; "<< MOMSET.q1[1][evtgen]<<"; "<<MOMSET.q1[2][evtgen]<<"; "<< MOMSET.q1[3][evtgen]<<std::endl;
256 //std::cout<<"e-: "<<MOMSET.p2[0][evtgen]<<"; "<< MOMSET.p2[1][evtgen]<<"; "<<MOMSET.p2[2][evtgen]<<"; "<< MOMSET.p2[3][evtgen]<<std::endl;
257 //std::cout<<"e+: "<<MOMSET.q2[0][evtgen]<<"; "<< MOMSET.q2[1][evtgen]<<"; "<<MOMSET.q2[2][evtgen]<<"; "<< MOMSET.q2[3][evtgen]<<std::endl;
258
259 // scattered lepton -
260 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.q2[1][evtgen], MOMSET.q2[2][evtgen],
261 MOMSET.q2[3][evtgen], MOMSET.q2[0][evtgen]),
262 pid2, pst2);
263 p->suggest_barcode( ++npart );
264 prod_vtx->add_particle_out(p);
265
266
267 int iphot=0;
268 // std::cout<<"evtgen, ncqph[events#] "<<evtgen<<"; "<<ISRPHOTONS.ncqph[evtgen-1]<<std::endl;
269 for (iphot=0; iphot<ISRPHOTONS.ncqph[evtgen-1]; iphot++)
270 {
271 // debuging, pingrg
272 // std::cout<<"evtgen, iphot= "<<evtgen<<"; "<<iphot<<std::endl;
273 //std::cout<<MOMSET.phot[0][iphot][evtgen]<<", "<<MOMSET.phot[1][iphot][evtgen]<<", "<<MOMSET.phot[2][iphot][evtgen]<<", "<<MOMSET.phot[3][iphot][evtgen]<<std::endl;
274
275 p = new GenParticle( CLHEP::HepLorentzVector( MOMSET.phot[1][iphot][evtgen], MOMSET.phot[2][iphot][evtgen],
276 MOMSET.phot[3][iphot][evtgen], MOMSET.phot[0][iphot][evtgen]),
277 22, 1);
278 p->suggest_barcode( ++npart );
279 prod_vtx->add_particle_out(p);
280
281 }
282
283
284 evtgen++;
285
286 if( log.level() < MSG::INFO )
287 {
288 evt->print();
289 }
290
291 // Check if the McCollection already exists
292 SmartDataPtr<McGenEventCol> anMcCol(eventSvc(), "/Event/Gen");
293 if (anMcCol!=0)
294 {
295 // Add event to existing collection
296 MsgStream log(messageService(), name());
297 log << MSG::INFO << "Add McGenEvent to existing collection" << endreq;
298 McGenEvent* mcEvent = new McGenEvent(evt);
299 anMcCol->push_back(mcEvent);
300 }
301 else
302 {
303 // Create Collection and add to the transient store
304 McGenEventCol *mcColl = new McGenEventCol;
305 McGenEvent* mcEvent = new McGenEvent(evt);
306 mcColl->push_back(mcEvent);
307 StatusCode sc = eventSvc()->registerObject("/Event/Gen",mcColl);
308 if (sc != StatusCode::SUCCESS)
309 {
310 log << MSG::ERROR << "Could not register McGenEvent" << endreq;
311 delete mcColl;
312 delete evt;
313 delete mcEvent;
314 return StatusCode::FAILURE;
315 }
316 else
317 {
318 // log << MSG::INFO << "McGenEventCol created and " << npart <<" particles stored in McGenEvent" << endreq;
319 }
320 }
321
322 return StatusCode::SUCCESS;
323}
324
326{
327 MsgStream log(messageService(), name());
328 char delcmd[300];
329 strcpy(delcmd,"cat ");
330 strcat(delcmd,"CrossSection.txt");
331 system(delcmd);
332
333 std::cout<< "BABAYAGA finalized" << endl;
334 return StatusCode::SUCCESS;
335}
336
338 IProperty* appPropMgr=0;
339 StatusCode status =
340 serviceLocator()->getService("ApplicationMgr", IProperty::interfaceID(),
341 reinterpret_cast<IInterface*&>( appPropMgr ));
342 if( status.isFailure() ) return status;
343
344 IntegerProperty evtMax("EvtMax",0);
345 status = appPropMgr->getProperty( &evtMax );
346 if (status.isFailure()) return status;
347
348 m_evtMax = evtMax.value();
349 return status;
350}
351
#define MOMSET
Definition: Babayaga.cxx:45
#define SWITCHARUN
Definition: Babayaga.cxx:88
#define EXPCUTS
Definition: Babayaga.cxx:73
#define BABAYAGA(NEVENTS)
Definition: Babayaga.cxx:138
#define RADBB
Definition: Babayaga.cxx:51
#define DECLAREINT
Definition: Babayaga.cxx:109
#define ISRPHOTONS
Definition: Babayaga.cxx:58
#define DECLARESTR
Definition: Babayaga.cxx:116
#define SWITCH
Definition: Babayaga.cxx:81
#define CHANNEL
Definition: Babayaga.cxx:95
#define BEAMENERGY
Definition: Babayaga.cxx:65
#define RESONANCES
Definition: Babayaga.cxx:102
float flat_()
Definition: Babayaga.cxx:126
#define COMMON_BLOCK_DEF(DEFINITION, NAME)
#define PROTOCCALLSFSUB1(UN, LN, T1)
static void setRandomEngine(CLHEP::HepRandomEngine *randomEngine)
static double random()
StatusCode getMaxEvent()
Definition: Babayaga.cxx:337
StatusCode finalize()
Definition: Babayaga.cxx:325
Babayaga(const string &name, ISvcLocator *pSvcLocator)
Definition: Babayaga.cxx:141
StatusCode initialize()
Definition: Babayaga.cxx:163
StatusCode execute()
Definition: Babayaga.cxx:209
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)=0
Interface to the CLHEP engine.
double ebeam
Definition: Babayaga.cxx:63
double egmin
Definition: Babayaga.cxx:71
double CutEgam
Definition: Babayaga.cxx:48