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