001
002
003
004
005
006
007 #include <string>
008 using std::string;
009 #include <string.h>
010
011
012
013
014 #include "generatorMods/PythiaModule.hh"
015 #include "pythia_i/Pythia.hh"
016 #include "stdhep_i/CdfHepevt.hh"
017
018
019
020
021 #include <iostream>
022 #include <iomanip>
023 using std::cout;
024 using std::endl;
025 using std::setw;
026
027
028
029
030 #include "AbsEnv/AbsEnv.hh"
031 #include "stdhep_i/CdfHepevt.hh"
032
033
034
035
036
037
038
039
040 const char* PythiaModule::genId="Pythia";
041
042
043
044
045
046 PythiaModule::PythiaModule() :
047 AbsGenModule( PythiaModule::genId,
048 "AC++ Pythia module"),
049 _pythiaMenu( new PythiaMenu( this, 0, "PythiaMenu") )
050 {
051
052 _initializeTalkTo();
053 }
054
055
056
057
058
059 PythiaModule::~PythiaModule()
060 {
061 delete _pythiaMenu;
062 }
063
064 AppResult PythiaModule::genBeginRun(AbsEvent* aRun) {
065 return AppResult::OK;
066 }
067
068 AppResult PythiaModule::genBeginJob() {
069
070 Pythia* pythia = Pythia::Instance();
071
072 if(Pythia::Instance()->pydat3().lenMdme() == 8000 &&
073 Pythia::Instance()->pypars().mstp(182) < 200) {
074 errlog(ELfatal,"[PYTHIA_VERS_ERRO]")
075 << "PythiaModule: Common blocks are incorrect for Pythia version,"
076 << "please delete binaries, setup lund v6_203 (or later) and rebuild."
077 << endmsg;
078 }
079
080 int index;
081 int massCode[] = {310,3112,3122,3222,3312,3322,3334};
082 for (int i = 0; i<7; i++) {
083 index = Pythia::Instance()->Pycomp(&massCode[i]);
084 Pythia::Instance()->pydat3().mdcy(index,1) = 0;
085 }
086 std::cout<< "PythiaModule: Please note the following long lived strange "
087 << "particles have been" << std::endl;
088 std::cout<< " set stable and cannot be set to decay"<<std::endl;
089 std::cout<< " K_0S, Lambda, Sigma, Xi and Omega." <<std::endl;
090
091
092 if (pythia->pypars().mstp(131)) {
093 pythia->pypars().mstp(131)=0;
094 ERRLOG(ELerror,"[PYTHIA_NO_PILEUP]")
095 << "PythiaModule: Pile up selected but is not currently supported, "
096 << "now turned off"
097 << endmsg;
098 }
099
100 if (_pythiaMenu->allowBMixing()) {
101 ERRLOG(ELsuccess,"[PYTHIA_DCYTBL_R")
102 << "PythiaModule: B-Bbar mixing is enabled though this will "
103 << "conflict with EvtGen if used" << endmsg;
104 } else {
105 if( pythia->pydat1().mstj(26) != 0)
106 ERRLOG(ELwarning,"[PYTHIA_BMIXOF_R]")
107 << "PythiaModule: B-Bbar mixing is disabled and should "
108 << "be done using EvtGen" << endmsg;
109 pythia->pydat1().mstj(26)=0;
110 }
111
112 std::string fileMode = _pythiaMenu->decayFileMode();
113 std::string fileName = _pythiaMenu->decayFile();
114 if (!fileName.empty()) {
115 if (fileMode=="READ" || fileMode=="read") {
116 int mode=_pythiaMenu->decayTableMode();
117 int lun=37;
118 if (pythia->Opdcay(fileName,&lun,"R")) {
119 ERRLOG(ELerror,"[PYTHIA_NO_DCYTBL]")
120 << "PythiaModule: decay table file "
121 << "\"" << fileName << "\"\n"
122 << "cannot be opened for read!" << endmsg;
123 } else {
124 pythia->Pyupda(&mode,&lun);
125 pythia->Cldcay(&lun);
126 ERRLOG(ELsuccess,"[PYTHIA_DCYTBL_R")
127 << "PythiaModule: read decay table file "
128 << "\"" << fileName << "\"" << endmsg;
129 }
130 }
131 }
132
133 if(pythia->pypars().mstp(142)) {
134 double expwt = _pythiaMenu->expWeight();
135 int param = _pythiaMenu->weightParam();
136 pythia->Pyevwt(¶m, &expwt);
137 }
138 std::string frame = _pythiaMenu->frame();
139 std::string target = _pythiaMenu->getTarget();
140 double winval = _pythiaMenu->win();
141 int minlist = _pythiaMenu->initlistlevel();
142 pythia->pysubs().msel() = _pythiaMenu->msel();
143
144 std::string pygiveFile = _pythiaMenu->pygiveFile();
145 if(pygiveFile.size())
146 {
147 std::cout << "Pygive file " << pygiveFile << std::endl;
148 pythia->Pygive(pygiveFile);
149 }
150
151 if (_pythiaMenu->tuneUE() > 0 ) {
152 if( pythia->pypars().mstp(181)==6 && pythia->pypars().mstp(182) > 404 ){
153 pythia->Pytune(_pythiaMenu->tuneUE());
154 } else {
155 ERRLOG(ELerror,"[PYTHIA_NO_TUNEUE]")
156 << "PythiaModule: Pytune called, "
157 << "please upgrade to version 6.405 or later" << endmsg;
158 }
159 }
160 pythia->Pyinit(frame,target,&winval );
161 pythia->setEvents(0);
162 pythia->setEventListLevel(minlist);
163 pythia->Pylist(&minlist);
164
165
166 if (!fileName.empty()) {
167 if (fileMode=="WRITE" || fileMode=="write") {
168 int mode=1;
169 int lun=37;
170 if (pythia->Opdcay(fileName,&lun,"W")) {
171 ERRLOG(ELerror,"[PYTHIA_NO_DCYTBL]")
172 << "PythiaModule: decay table file "
173 << "\"" << fileName << "\"\n"
174 << "cannot be opened for write!" << endmsg;
175 } else {
176 pythia->Pyupda(&mode,&lun);
177 pythia->Cldcay(&lun);
178 ERRLOG(ELsuccess,"[PYTHIA_DCYTBL_W]")
179 << "PythiaModule: wrote decay table file "
180 << "\"" << fileName << "\"" << endmsg;
181 }
182 }
183 }
184 pythia->setFirstListEvent( _pythiaMenu->firstlistevent() );
185 pythia->setLastListEvent ( _pythiaMenu->lastlistevent() );
186 pythia->setEventListLevel(_pythiaMenu->eventlistlevel());
187 std::cout << " Event list level "
188 << _pythiaMenu->eventlistlevel()
189 << std::endl;
190
191 return AppResult::OK;
192 }
193
194 int PythiaModule::callGenerator(AbsEvent* anEvent) {
195
196 Pythia* pythia = Pythia::Instance();
197
198
199 pythia->Pyevnt();
200 bool eventList = ( pythia->events() >= pythia->FirstListEvent() &&
201 pythia->events() <= pythia->LastListEvent() );
202
203 if (_pythiaMenu->selectPdg()!=0) {
204 int code = _pythiaMenu->selectPdg();
205 int icount = 0;
206 while(pythia->findPdgCode(&code)==false) {
207 if ( verbose() ) {
208 if (++icount%100==0 && eventList) std::cout << name() << "::callGenerator generated " << icount << std::endl;
209 }
210 pythia->Pyevnt();
211 }
212 }
213
214
215 pythia->addEvent();
216 int mevlist= pythia->EventListLevel();
217
218 int medit = _pythiaMenu->pyeditAction();
219 if( medit >= 0 ) pythia->Pyedit(&medit);
220 if ( eventList ) {
221 std::cout << "PYEVNT event no. " << pythia->events()
222 <<" level " << mevlist;
223 if( medit >= 0 ) std::cout << " after PYEDIT action = " << medit;
224 std::cout << std::endl;
225 pythia->Pylist(&mevlist);
226 }
227
228 return 0;
229 }
230
231 void PythiaModule::fillHepevt() {
232
233 Pythia* pythia = Pythia::Instance();
234
235 int mconv=1;
236
237 pythia->Lunhep(&mconv);
238 CdfHepevt::Instance()->HepevtPtr()->NEVHEP = pythia->events();
239
240
241 CdfHepevt::Instance()->Hepev4Ptr()->SCALELH[5] =
242 pythia->pypars().pari(17);
243
244 CdfHepevt::Instance()->Hepev4Ptr()->EVENTWEIGHTLH=
245 pythia->pypars().pari(10);
246
247
248 }
249
250 AppResult PythiaModule::genEndRun(AbsEvent* aRun) {
251 Pythia* pythia = Pythia::Instance();
252 int mstat = _pythiaMenu->statlistlevel();
253 cout << "Call PYSTAT at endRun" << endl;
254 pythia->Pystat(&mstat);
255
256 return AppResult::OK;
257 }
258
259 AppResult PythiaModule::genEndJob() {
260 Pythia* pythia = Pythia::Instance();
261 int mstat = _pythiaMenu->statlistlevel();
262 cout << "Call PYSTAT at endJob" << endl;
263 pythia->Pystat(&mstat);
264
265 return AppResult::OK;
266 }
267
268
269
270
271
272
273
274
275
276
Send problems or questions to cdfcode@fnal.gov