20 #include <HepMC/PythiaWrapper.h>
21 #include <HepMC/IO_HEPEVT.h>
22 #include <HepMC/IO_GenEvent.h>
23 #include <HepMC/IO_AsciiParticles.h>
24 #include <HepMC/GenEvent.h>
26 #include <gsl/gsl_randist.h>
39 #define pytune pytune_
40 extern "C" int pytune(
int *itune);
50 _configFile(
"phpythia6.cfg"),
52 _filename_ascii(
"pythia_hepmc.dat"),
53 _registeredTriggers(),
78 HepMC::HEPEVT_Wrapper::set_max_number_entries(4000);
79 HepMC::HEPEVT_Wrapper::set_sizeof_real(8);
83 fSeed = abs(fSeed)%900000000;
85 if ( (fSeed>=0) && (fSeed<=900000000) ) {
89 cout <<
PHWHERE <<
" ERROR: seed " << fSeed <<
" is not valid" << endl;
110 <<
" events passed trigger" << endl;
114 cout <<
" *------- End PYTHIA Trigger Statistics ------------------------"
115 <<
"-------------------------------------------------* " << endl;
124 cout <<
"PHPythia6::read_config - Reading " <<
_configFile << endl;
127 if (infile.fail ()) {
128 cout <<
"PHPythia6::read_config - Failed to open file " <<
_configFile << endl;
146 getline(infile, FullLine);
147 while ( !infile.eof() )
151 if ( FullLine[0]==
'#' || FullLine.substr(0, 2) ==
"//" )
153 getline(infile,FullLine);
158 istringstream
line( FullLine.c_str() );
164 std::transform(label.begin(), label.end(), label.begin(), (int(*)(int)) std::tolower);
167 if ( label ==
"nevents" )
170 cout <<
"nevents\t" << _nevents << endl;
172 else if ( label ==
"roots" )
175 cout <<
"roots\t" << _roots << endl;
177 else if ( label ==
"proj" )
180 cout <<
"proj\t" << _proj << endl;
182 else if ( label ==
"targ" )
185 cout <<
"targ\t" << _targ << endl;
187 else if ( label ==
"frame" )
190 cout <<
"frame\t" << _frame << endl;
192 else if ( label ==
"p1" || label ==
"p2")
199 cout <<
"p1\t" << index <<
" " << value << endl;
206 cout <<
"p2\t" << index <<
" " << value << endl;
229 else if ( label ==
"msel" )
233 cout <<
"msel\t" << value << endl;
236 else if ( label ==
"msub" )
241 pysubs.msub[index-1] = (int) value;
242 cout <<
"msub\t" << index <<
" " << value << endl;
245 else if ( label ==
"mstp" )
248 pypars.mstp[index-1] = (int) value;
249 cout <<
"mstp\t" << index <<
" " << value << endl;
252 else if ( label ==
"mstj" )
255 pydat1.mstj[index-1] = (int) value;
256 cout <<
"mstj\t" << index <<
" " << value << endl;
259 else if ( label ==
"mstu" )
262 pydat1.mstu[index-1] = (int) value;
263 cout <<
"mstu\t" << index <<
" " << value << endl;
266 else if ( label ==
"ckin" )
270 cout <<
"ckin\t" << index <<
" " << value << endl;
272 else if ( label ==
"parp" )
276 cout <<
"parp\t" << index <<
" " << value << endl;
278 else if ( label ==
"parj" )
282 cout <<
"parj\t" << index <<
" " << value << endl;
284 else if ( label ==
"paru" )
288 cout <<
"paru\t" << index <<
" " << value << endl;
290 else if ( label ==
"parf" )
294 cout <<
"parf\t" << index <<
" " << value << endl;
296 else if ( label ==
"mdme" )
303 cout <<
"mdme\t" << idc <<
" " << index <<
" " << value << endl;
305 else if ( label ==
"pmas" )
311 cout <<
"pmas\t" << idc <<
" " << index <<
" " << value << endl;
313 else if ( label ==
"pytune" )
318 cout <<
"pytune\t" << ivalue << endl;
323 cout <<
"************************************************************" << endl;
324 cout <<
"PHPythia6::ReadConfig(), ERROR this option is not supported: " << FullLine << endl;
325 cout <<
"************************************************************" << endl;
329 getline( infile, FullLine );
333 call_pyinit( _frame.c_str(), _proj.c_str(), _targ.c_str(), _roots );
350 bool passedTrigger =
false;
351 std::vector<bool> theTriggerResults;
358 HepMC::IO_HEPEVT hepevtio;
359 HepMC::GenEvent* evt;
361 while (!passedTrigger) {
368 evt = hepevtio.read_next_event();
371 evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
377 evt->set_signal_process_id(
pypars.msti[1-1]);
380 evt->set_mpi(
pypars.msti[31-1] );
383 evt->set_cross_section( HepMC::getPythiaCrossSection() );
386 HepMC::PdfInfo pdfinfo;
387 pdfinfo.set_x1(
pypars.pari[33-1]);
388 pdfinfo.set_x2(
pypars.pari[34-1]);
389 pdfinfo.set_scalePDF(
pypars.pari[22-1]);
390 pdfinfo.set_id1(
pypars.msti[15-1]);
391 pdfinfo.set_id2(
pypars.msti[16-1]);
392 evt->set_pdf_info(pdfinfo);
396 bool andScoreKeeper =
true;
405 cout <<
"PHPythia6::process_event trigger: "
410 passedTrigger =
true;
413 andScoreKeeper &= trigResult;
417 cout <<
"PHPythia8::process_event - failed trigger: "
423 passedTrigger =
true;
428 if(!passedTrigger)
delete evt;
443 cout <<
"PHPythia6::process_event - Failed to add event to HepMC record!" << endl;
447 if (
verbosity > 2) cout <<
"PHPythia6::process_event - FINISHED WHOLE EVENT" << endl;
457 if (fmod(number, 1.0) != 0) {
458 cout <<
"Warning: Value " << number <<
" is not an integer." << endl;
459 cout <<
"This parameter requires an integer value." << endl;
460 cout <<
"Value of parameter truncated to " << (int) number << endl;
473 if(
verbosity > 1) cout <<
"PHPythia6::registerTrigger - trigger " << theTrigger->
GetName() <<
" registered" << endl;