12 #ifndef Pythia8_RivetHooks_H 13 #define Pythia8_RivetHooks_H 16 #include "Pythia8/Pythia.h" 17 #include "Pythia8/Plugins.h" 18 #include "Pythia8Plugins/HepMC3.h" 21 #include "Rivet/AnalysisHandler.hh" 33 bool makeDir(vector<string> path, mode_t mode = 0777) {
41 for (
string& dir : path) {
44 pathNow += (first ?
"" :
"/") + dir;
46 if (stat(pathNow.c_str(), &info) == 0) {
47 if ((info.st_mode & S_IFDIR) == 0)
return false;
52 if (mkdir(pathNow.c_str(), mode) != 0)
return false;
69 pythiaPtr(pythiaPtrIn) {}
70 ~
RivetHooks() {
if (rivetPtr !=
nullptr)
delete rivetPtr;}
78 if (
flag(
"Rivet:skipZeroWeights") && pythiaPtr->
info.
weight() == 0) {
79 loggerPtr->INFO_MSG(
"skipping zero-weight event");
89 if (rivetPtr ==
nullptr) {
93 rivetPtr =
new Rivet::AnalysisHandler();
96 rivetPtr->setCheckBeams(
flag(
"Rivet:checkBeams"));
99 if (mode(
"Rivet:dumpPeriod") > 0) {
100 string dumpName = word(
"Rivet:dumpName");
101 if (dumpName ==
"") dumpName = word(
"Rivet:fileName");
102 rivetPtr->setFinalizePeriod(dumpName, mode(
"Rivet:dumpPeriod"));
106 for (
string& preload : wvec(
"Rivet:preloads"))
107 rivetPtr->readData(preload);
110 for (
string& analysis : wvec(
"Rivet:analyses"))
111 rivetPtr->addAnalysis(analysis);
114 rivetPtr->init(hepmc.
event());
119 rivetPtr->analyze(hepmc.
event());
129 if (rivetPtr ==
nullptr)
return;
130 string filename = word(
"Rivet:fileName");
132 if (path.size() > 1) {
134 makeDir(vector<string>(path.begin(), path.end() - 1));
139 rivetPtr->finalize();
140 rivetPtr->writeData(filename);
150 Rivet::AnalysisHandler* rivetMain = rivetPtr;
151 if (rivetMain ==
nullptr) {
152 loggerPtr->ERROR_MSG(
"could not retrieve first RivetHooks");
159 if (hookPtr ==
this)
continue;
161 if (hookNow ==
nullptr) {
162 loggerPtr->ERROR_MSG(
"could not retrieve RivetHooks for thread ",
168 Rivet::AnalysisHandler* rivetNow = hookNow->rivetPtr;
169 if (rivetNow ==
nullptr) {
170 loggerPtr->ERROR_MSG(
"could not retrieve AnalysisHandler for thread ",
181 rivetMain->merge(*rivetNow);
182 }
catch (
const Rivet::UserError err) {
183 loggerPtr->ERROR_MSG(
"failed to merge analyses in thread ",
187 rivetMain->merge(*rivetNow);
200 Rivet::AnalysisHandler* rivetPtr{};
210 settingsPtr->addWord(
"Rivet:fileName",
"rivet.yoda");
211 settingsPtr->addWVec(
"Rivet:analyses", {});
212 settingsPtr->addWVec(
"Rivet:preloads", {});
213 settingsPtr->
addFlag(
"Rivet:checkBeams",
true);
214 settingsPtr->addWord(
"Rivet:dumpName",
"");
215 settingsPtr->addMode(
"Rivet:dumpPeriod", -1,
true,
false, -1, 0);
216 settingsPtr->
addFlag(
"Rivet:skipZeroWeights",
false);
226 PYTHIA8_PLUGIN_VERSIONS(PYTHIA_VERSION_INTEGER)
void onEndEvent(Status) override
Perform the Rivet analysis.
Definition: RivetHooks.h:75
vector< string > splitString(string val, string delim)
Split a string by a delimiter.
Definition: PythiaStdlib.cc:72
GenEvent & event()
Get a reference to the current GenEvent.
Definition: HepMC2.h:465
Settings * settingsPtr
Pointer to the settings database.
Definition: PhysicsBase.h:85
Definition: PhysicsBase.h:26
mutex * mutexPtr
Mutex that should be locked for thread-unsafe code.
Definition: PhysicsBase.h:131
PYTHIA8_PLUGIN_PARALLEL(true)
Declare the plugin.
void onStat() override
Write the Rivet analyses.
Definition: RivetHooks.h:126
void onStat(vector< PhysicsBase * > hookPtrs, Pythia *) override
Merge the Rivet analysis handlers.
Definition: RivetHooks.h:147
UserHook to run Rivet analyses.
Definition: RivetHooks.h:62
void rivetSettings(Settings *settingsPtr)
Register Rivet settings.
Definition: RivetHooks.h:209
Status
Enumerate the different status codes the event generation can have.
Definition: PhysicsBase.h:31
string toString(bool val)
Convert a boolean to a string.
Definition: PythiaStdlib.h:208
bool makeDir(vector< string > path, mode_t mode=0777)
Definition: HepMC3Hooks.h:29
Logger * loggerPtr
Pointer to logger.
Definition: PhysicsBase.h:91
Header for classes to set beam momentum and interaction vertex spread.
Definition: Analysis.h:20
The Pythia class contains the top-level routines to generate an event.
Definition: Pythia.h:72
bool fillNextEvent(Pythia &pythia)
Definition: HepMC2.h:445
const Info & info
Public information and statistic on the generation.
Definition: Pythia.h:378
UserHooks is base class for user access to program execution.
Definition: UserHooks.h:32
RivetHooks()
Constructors and destructor.
Definition: RivetHooks.h:67
bool flag(string key) const
Shorthand to read settings values.
Definition: PhysicsBase.h:44
double weight(int i=0) const
Event weights and accumulated weight.
Definition: Info.cc:162
Definition: Settings.h:196
void addFlag(string keyIn, bool defaultIn)
Add new entry.
Definition: Settings.h:280