15 #include <HepMC/GenEvent.h>
16 #include <Pythia8/Pythia.h>
17 #include <Pythia8Plugins/HepMC2.h>
19 #include <boost/format.hpp>
21 #include <gsl/gsl_randist.h>
35 , _registeredTriggers()
39 , _configFile(
"phpythia8.cfg")
41 , _pythiaToHepMC(
NULL)
42 , _save_integrated_luminosity(true)
43 , _integral_node(nullptr)
45 char *charPath = getenv(
"PYTHIA8");
48 cout <<
"PHPythia8::Could not find $PYTHIA8 path!" << endl;
52 std::string thePath(charPath);
53 thePath +=
"/xmldoc/";
54 _pythia =
new Pythia8::Pythia(thePath.c_str());
56 _pythiaToHepMC =
new HepMC::Pythia8ToHepMC();
57 _pythiaToHepMC->set_store_proc(
true);
58 _pythiaToHepMC->set_store_pdf(
true);
59 _pythiaToHepMC->set_store_xsec(
true);
71 if (!_configFile.empty()) read_config();
72 for (
unsigned int j = 0; j < _commands.size(); j++)
74 _pythia->readString(_commands[j]);
77 create_node_tree(topNode);
90 seed = seed % 900000000;
93 if ((seed > 0) && (seed <= 900000000))
95 _pythia->readString(
"Random:setSeed = on");
96 _pythia->readString(str(boost::format(
"Random:seed = %1%") % seed));
100 cout <<
PHWHERE <<
" ERROR: seed " << seed <<
" is not valid" << endl;
121 cout <<
" PHPythia8::End - " << _eventcount
122 <<
" events passed trigger" << endl;
123 cout <<
" Fraction passed: " << _eventcount
124 <<
"/" << _pythia->info.nAccepted()
125 <<
" = " << _eventcount / float(_pythia->info.nAccepted()) << endl;
126 cout <<
" *------- End PYTHIA Trigger Statistics ------------------------"
127 <<
"-------------------------------------------------* " << endl;
131 cout <<
"Integral information on stored on node RUN/PHGenIntegral:" << endl;
133 cout <<
" *------- End PYTHIA Integral Node Print ------------------------"
134 <<
"-------------------------------------------------* " << endl;
142 int PHPythia8::read_config(
const char *cfg_file)
144 if (cfg_file) _configFile = cfg_file;
147 cout <<
"PHPythia8::read_config - Reading " << _configFile << endl;
149 ifstream infile(_configFile.c_str());
152 cout <<
"PHPythia8::read_config - Failed to open file " << _configFile << endl;
156 _pythia->readFile(_configFile.c_str());
164 _pythia->info.list();
171 bool passedGen =
false;
172 bool passedTrigger =
false;
175 while (!passedTrigger)
182 passedGen = _pythia->next();
187 bool andScoreKeeper =
true;
190 cout <<
"PHPythia8::process_event - triggersize: " << _registeredTriggers.size() << endl;
193 for (
unsigned int tr = 0; tr < _registeredTriggers.size(); tr++)
195 bool trigResult = _registeredTriggers[tr]->Apply(_pythia);
199 cout <<
"PHPythia8::process_event trigger: "
200 << _registeredTriggers[tr]->GetName() <<
" " << trigResult << endl;
203 if (_triggersOR && trigResult)
205 passedTrigger =
true;
208 else if (_triggersAND)
210 andScoreKeeper &= trigResult;
215 cout <<
"PHPythia8::process_event - failed trigger: "
216 << _registeredTriggers[tr]->GetName() << endl;
220 if ((andScoreKeeper && _triggersAND) || (_registeredTriggers.size() == 0))
222 passedTrigger =
true;
231 HepMC::GenEvent *genevent =
new HepMC::GenEvent(HepMC::Units::GEV, HepMC::Units::MM);
232 _pythiaToHepMC->fill_next_event(*_pythia, genevent, _eventcount);
238 cout <<
"PHPythia8::process_event - Failed to add event to HepMC record!" << endl;
245 if (_eventcount < 2 && verbosity >=
VERBOSITY_SOME) _pythia->event.list();
256 _integral_node->
set_Integrated_Lumi(_pythia->info.nAccepted() / (_pythia->info.sigmaGen() * 1e9));
271 cout <<
PHWHERE <<
"RUN Node missing doing nothing" << endl;
275 _integral_node = findNode::getClass<PHGenIntegral>(sumNode,
"PHGenIntegral");
280 sumNode->addNode(newmapnode);
284 cout <<
"PHPythia8::create_node_tree - Fatal Error - "
285 <<
"RUN/PHGenIntegral node already exist. "
286 <<
"It is messy to overwrite integrated luminosities. Please turn off this function in the macro with " << endl;
287 cout <<
" PHPythia8::save_integrated_luminosity(false);" << endl;
288 cout <<
"The current RUN/PHGenIntegral node is ";
289 _integral_node->identify(cout);
293 assert(_integral_node);
306 _registeredTriggers.push_back(theTrigger);
int verbosity
The verbosity level. 0 means not verbose at all.
int get_embedding_id() const
PHHepMCGenEvent * insert_event(HepMC::GenEvent *evt)
send HepMC::GenEvent to DST tree. This function takes ownership of evt
int End(PHCompositeNode *topNode)
Called at the end of all processing.
virtual void set_N_Processed_Event(ULong64_t nProcessedEvent)
Number of processed events in the Fun4All cycles.
virtual void set_N_Generator_Accepted_Event(ULong64_t nGeneratorAcceptedEvent)
Number of accepted events in the event generator. This can be higher than fNProcessedEvent depending ...
virtual void identify(std::ostream &os=std::cout) const
void print_config() const
int Init(PHCompositeNode *topNode)
Output a lot of messages.
Output even more messages.
Output some useful messages during manual command line running.
virtual void set_Sum_Of_Weight(Double_t sumOfWeight)
virtual std::string GetName()
int process_event(PHCompositeNode *topNode)
void register_trigger(PHPy8GenTrigger *theTrigger)
set event selection criteria
int ResetEvent(PHCompositeNode *topNode)
Clean up after each event.
virtual void set_Integrated_Lumi(Double_t integratedLumi)
Integrated luminosity in pb^-1.
PHPythia8(const std::string &name="PHPythia8")
int create_node_tree(PHCompositeNode *topNode)
init interface nodes
void set_embedding_id(int id)