1 //--------------------------------------------------------------------------
4 // This software is part of the EvtGen package developed jointly
5 // for the BaBar and CLEO collaborations. If you use all or part
6 // of it, please give an appropriate acknowledgement.
8 // Copyright Information: See EvtGen/COPYRIGHT
9 // Copyright (C) 1998 Caltech, UCSB
13 // Description: Main class to provide user interface to EvtGen.
15 // Modification history:
17 // RYD March 24, 1998 Module created
19 //------------------------------------------------------------------------
21 #include "EvtGenBase/EvtPatches.hh"
25 #include "EvtGenBase/EvtComplex.hh"
27 #include "EvtGen/EvtGen.hh"
28 #include "EvtGenBase/EvtVector4R.hh"
29 #include "EvtGenBase/EvtVectorParticle.hh"
30 #include "EvtGenBase/EvtParticle.hh"
31 #include "EvtGenBase/EvtScalarParticle.hh"
32 #include "EvtGenBase/EvtDecayTable.hh"
33 #include "EvtGenBase/EvtPDL.hh"
34 #include "EvtGenBase/EvtStdHep.hh"
35 #include "EvtGenBase/EvtSecondary.hh"
36 #include "EvtGenBase/EvtReport.hh"
37 #include "EvtGenBase/EvtId.hh"
38 #include "EvtGenBase/EvtRandom.hh"
39 #include "EvtGenBase/EvtRandomEngine.hh"
40 #include "EvtGenBase/EvtSimpleRandomEngine.hh"
41 #include "EvtGenBase/EvtParticleFactory.hh"
42 //#include "CLHEP/Vector/LorentzVector.h"
43 #include "TLorentzVector.h"
44 #include "EvtGenModels/EvtModelReg.hh"
45 #include "EvtGenBase/EvtStatus.hh"
46 #include "EvtGenBase/EvtAbsRadCorr.hh"
47 #include "EvtGenBase/EvtRadCorr.hh"
48 #include "EvtGenModels/EvtPHOTOS.hh"
54 extern "C" void begevtgenstore_(int *,int *,int *,int *,
55 int *,int *,int *,int *,int *,
56 double *,double *,double *,
57 double *,double *,double *,
58 double *,double *,double *);
61 extern void evtgen_(float svertex[3],float *e_cms,float *beta_zs,
67 //This is a bit uggly, should not do anything
68 //in a destructor. This will fail if EvtGen is made a static
69 //because then this destructor might be called _after_
70 //the destructoin of objects that it depends on, e.g., EvtPDL.
72 if (getenv("EVTINFO")){
73 EvtDecayTable::printSummary();
78 EvtGen::EvtGen(const char* const decayName,
79 const char* const pdtTableName,
80 EvtRandomEngine* randomEngine,
81 EvtAbsRadCorr* isrEngine,
82 const std::list<EvtDecayBase*>* extraModels){
85 report(INFO,"EvtGen") << "Initializing EvtGen"<<endl;
87 report(INFO,"EvtGen") << "Storing known decay models"<<endl;
88 EvtModelReg dummy(extraModels);
90 report(INFO,"EvtGen") << "Main decay file name :"<<decayName<<endl;
91 report(INFO,"EvtGen") << "PDT table file name :"<<pdtTableName<<endl;
93 report(INFO,"EvtGen") << "Initializing RadCorr=PHOTOS"<<endl;
95 static EvtPHOTOS defaultRadCorrEngine;
96 EvtRadCorr::setRadCorrEngine(&defaultRadCorrEngine);
99 EvtRadCorr::setRadCorrEngine(isrEngine);
102 _pdl.readPDT(pdtTableName);
104 EvtDecayTable::readDecayFile(decayName,false);
106 if (randomEngine==0){
107 static EvtSimpleRandomEngine defaultRandomEngine;
108 EvtRandom::setRandomEngine((EvtRandomEngine*)&defaultRandomEngine);
109 report(INFO,"EvtGen") <<"No random engine given in "
110 <<"EvtGen::EvtGen constructor, "
111 <<"will use default EvtSimpleRandomEngine."<<endl;
114 EvtRandom::setRandomEngine(randomEngine);
117 report(INFO,"EvtGen") << "Done initializing EvtGen"<<endl;
122 void EvtGen::readUDecay(const char* const uDecayName){
126 if ( uDecayName[0] == 0) {
127 report(INFO,"EvtGen") << "Is not reading a user decay file!"<<endl;
130 indec.open(uDecayName);
132 EvtDecayTable::readDecayFile(uDecayName,true);
136 report(INFO,"EvtGen") << "Can not find UDECAY file '"
137 <<uDecayName<<"'. Stopping"<<endl;
145 void EvtGen::generateDecay(int stdhepid,
148 EvtStdHep *evtStdHep,
149 EvtSpinDensity *spinDensity ){
155 p=EvtParticleFactory::particleFactory(EvtPDL::evtIdFromStdHep(stdhepid),P);
158 p=EvtParticleFactory::particleFactory(EvtPDL::evtIdFromStdHep(stdhepid),
167 p->makeStdHep(*evtStdHep);
169 evtStdHep->translate(D);
176 void EvtGen::generateDecay(EvtParticle *p){
181 EvtStatus::initRejectFlag();
185 if ( EvtStatus::getRejectFlag()==0 ) {
189 for (size_t ii=0;ii<p->getNDaug();ii++){
190 EvtParticle *temp=p->getDaug(ii);
193 p->resetFirstOrNot();
199 report(ERROR,"EvtGen") << "Your event has been rejected 10000 times!"<<endl;
200 report(ERROR,"EvtGen") << "Will now abort."<<endl;
210 //void EvtGen::generateEvent(int stdhepid,CLHEP::HepLorentzVector P,CLHEP::HepLorentzVector D){
211 void EvtGen::generateEvent(int stdhepid,TLorentzVector P,TLorentzVector D){
212 EvtParticle *root_part;
213 EvtVectorParticle *vector_part;
215 vector_part=new EvtVectorParticle;
218 //p_init.set(P.t(),P.x(),P.y(),P.z());
219 p_init.set(P.E(),P.Px(),P.Py(),P.Pz());
220 vector_part->init(EvtPDL::evtIdFromStdHep(stdhepid),p_init);
222 root_part=(EvtParticle *)vector_part;
224 root_part->setVectorSpinDensity();
226 generateEvent(root_part,D);
228 root_part->deleteTree();
232 //void EvtGen::generateEvent(EvtParticle *root_part,CLHEP::HepLorentzVector D){
233 void EvtGen::generateEvent(EvtParticle *root_part,TLorentzVector D){
240 static EvtStdHep evtstdhep;
241 // static EvtSecondary evtsecondary;
251 generateDecay(root_part);
252 // root_part->Decay();
256 EvtId list_of_stable[10];
257 EvtParticle* stable_parent[10];
260 list_of_stable[0]=EvtId(-1,-1);
264 // evtsecondary.init();
265 // root_part->makeStdHep(evtstdhep,evtsecondary,list_of_stable);
266 root_part->makeStdHep(evtstdhep);
268 //report(INFO,"EvtGen") << evtstdhep;
269 //report(INFO,"EvtGen") << evtsecondary;
271 npart=evtstdhep.getNPart();
273 for(i=0;i<evtstdhep.getNPart();i++){
277 int jmotherfirst=evtstdhep.getFirstMother(i)+1;
278 int jmotherlast=evtstdhep.getLastMother(i)+1;
279 int jdaugfirst=evtstdhep.getFirstDaughter(i)+1;
280 int jdauglast=evtstdhep.getLastDaughter(i)+1;
282 partnum=evtstdhep.getStdHepID(i);
284 istat=evtstdhep.getIStat(i);
286 p4=evtstdhep.getP4(i);
287 x4=evtstdhep.getX4(i);
301 begevtgenstore_(&j,&nevent,&npart,&istat,
302 &partnum,&jmotherfirst,&jmotherlast,
303 &jdaugfirst,&jdauglast,