001
002
003
004
005
006
007
008
009
010
011
012
013 #include "generatorMods/EvtGenMod.hh"
014 #include "EvtGenBase/EvtRandomEngine.hh"
015
016
017 #include "r_n/CdfRn.hh"
018 #include "CLHEP/config/CLHEP.h"
019 #include "CLHEP/Random/RandomEngine.h"
020 #include "CLHEP/Vector/LorentzRotation.h"
021
022 #include "AbsEnv/AbsEnv.hh"
023 #include "SimulationObjects/HEPG_StorableBank.hh"
024 #include "Edm/Handle.hh"
025 #include "Edm/ConstHandle.hh"
026 #include "Edm/EventRecord.hh"
027
028 #include "stdhep_i/CdfHepEvt.hh" // <= to be fixed
029
030 #include <string>
031 #include <assert.h>
032 #include <time.h>
033 #include <iostream>
034 #include <cstdlib>
035
036 const char* EvtGenMod::genId="EvtGen";
037
038
039
040
041
042
043
044
045
046
047
048
049 class EvtCLHEPRandomEngine:public EvtRandomEngine{
050 public:
051 double random();
052 EvtCLHEPRandomEngine(long seed1, long seed2);
053 private:
054 HepRandomEngine* _engine;
055 };
056
057 double EvtCLHEPRandomEngine::random(){
058 return _engine->flat();
059 }
060
061
062 EvtCLHEPRandomEngine::EvtCLHEPRandomEngine(long seed1, long seed2) {
063 CdfRn* rn = CdfRn::Instance();
064 rn->SetEngineSeeds(seed1, seed2, EvtGenMod::genId);
065 _engine = CdfRn::Instance()->GetEngine(EvtGenMod::genId);
066 }
067
068
069
070
071
072
073
074 EvtGenMod::EvtGenMod() :
075 AbsDecpackModule(EvtGenMod::genId,"AC++ EvtGen module"),
076 _useRootParticle("UseRootParticle",this,false),
077 _rootParticlePx("RootParticlePx",this,0.0),
078 _rootParticlePy("RootParticlePy",this,0.0),
079 _rootParticlePz("RootParticlePz",this,0.0),
080 _rootParticleHepID("RootParticleHepID",this,0),
081 _useUserDecayFile("UseUserDecayFile",this,false),
082 _userDecayFile("UserDecayFile",this,"dummy"),
083 _adjustCPAsymm("AdjustCPAsymm",this,false),
084 _decayPromptCharm("DecayPromptCharm",this,false),
085 _decayBMeson("DecayBMeson",this,true),
086 _decayBBaryon("DecayBBaryon",this,true),
087 _randomSeed1("RandomSeed1",this,0),
088 _randomSeed2("RandomSeed2",this,0)
089 {
090 _eventCount = 0;
091 _generator = NULL;
092 _myevtgenInterface = NULL;
093 _myRandomEngine = NULL;
094 _initializeTalkTo();
095 }
096
097
098
099
100
101 EvtGenMod::~EvtGenMod()
102 {
103 }
104
105
106
107
108
109 AppResult EvtGenMod::genBeginJob()
110 {
111 char *decay_file, *pdt_table;
112 std::string filename;
113
114 _myRandomEngine=new EvtCLHEPRandomEngine(_randomSeed1.value(), _randomSeed2.value());
115
116
117 if((decay_file = getenv("EVTGEN_DECAY_FILE"))==NULL) {
118 ERRLOG(ELfatal,"[EVTGEN_NO_DCYTBL]")
119 << "EvtGenModule: EVTGEN_DECAY_FILE not set"
120 << endmsg;
121 }
122 else if((pdt_table = getenv("EVTGEN_PDT_TABLE"))==NULL) {
123 ERRLOG(ELfatal,"[EVTGEN_NO_DCYTBL]")
124 << "EvtGenModule: EVTGEN_PDT_TABLE not set"
125 << endmsg;
126 }
127 else {
128 _generator = new EvtGen(decay_file,pdt_table,_myRandomEngine);
129
130 filename = _userDecayFile.value();
131 if(_useUserDecayFile.value()) {
132 _generator->readUDecay(filename.c_str());
133 }
134
135 _myevtgenInterface = new EvtGenInterface(_generator,_adjustCPAsymm.value(),_verbose.value(), _decayBMeson.value(), _decayBBaryon.value(), _decayPromptCharm.value());
136 }
137 return AppResult::OK;
138 }
139
140 int EvtGenMod::callGenerator(AbsEvent* anEvent)
141 {
142
143
144
145 _eventCount++;
146 double p[3];
147 int errorFlag;
148
149 if (_verbose.value())
150 std::cout << "=========== begining event # " << _eventCount << std::endl;
151
152 if(_useRootParticle.value()) {
153 if( _eventCount < 3 && _eventCount > 0)
154 std::cout << name() << "Using root particle\n";
155 p[0]=_rootParticlePx.value();
156 p[1]=_rootParticlePy.value();
157 p[2]=_rootParticlePz.value();
158
159 errorFlag = _myevtgenInterface->DecayRoot(_rootParticleHepID.value(),p);
160 }
161 else {
162 if( _eventCount < 3 && _eventCount > 0)
163 std::cout << name() << "Finding B Mesons and about to enter DecayAll\n";
164
165 errorFlag = _myevtgenInterface->DecayAll();
166 }
167
168 return 1;
169 }
170
171 AppResult EvtGenMod::genEndJob()
172 {
173 if(_generator != NULL)
174 delete _generator;
175 if(_myevtgenInterface != NULL)
176 delete _myevtgenInterface;
177
178 return AppResult::OK;
179 }
180
181 AppResult EvtGenMod::genBeginRun( AbsEvent* anEvent )
182 {
183 return AppResult::OK;
184 }
185
186 AppResult EvtGenMod::genEndRun( AbsEvent* anEvent )
187 {
188 return AppResult::OK;
189 }
190
191
192
193
194
195
196 void EvtGenMod::_initializeTalkTo() {
197 _useRootParticle.addDescription("\t\tSelect root particle (T) or read HepEvt (F)");
198 _rootParticleHepID.addDescription("\t\tUses standard PDG particle codes");
199 _adjustCPAsymm.addDescription("\t\tAccount for integrated probability of B mixing;\n\t\tUsed to generate CP violation.\n\t\t Default = false");
200 _decayPromptCharm.addDescription("\t\tDecay prompt charm from hard scatter generator\n\t\t Default = false");
201 _decayBMeson.addDescription("Decay B mesons from hard scatter generator\n\t\t Default = true\t\t");
202 _decayBBaryon.addDescription("Decay B baryons from hard scatter generator\n\t\t Default = true\t\t");
203 commands()->append(&_useRootParticle);
204 commands()->append(&_rootParticlePx);
205 commands()->append(&_rootParticlePy);
206 commands()->append(&_rootParticlePz);
207 commands()->append(&_rootParticleHepID);
208 commands()->append(&_useUserDecayFile);
209 commands()->append(&_userDecayFile);
210 commands()->append(&_adjustCPAsymm);
211 commands()->append(&_decayPromptCharm);
212 commands()->append(&_decayBMeson);
213 commands()->append(&_decayBBaryon);
214 commands()->append(&_randomSeed1);
215 commands()->append(&_randomSeed2);
216 }
217
218
Send problems or questions to cdfcode@fnal.gov