Skip to content

Commit 241ee99

Browse files
committed
Fix for dpl-eventgen usage, added nEvents protection and executable
selection
1 parent 0af4938 commit 241ee99

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

MC/config/PWGGAJE/external/generator/generator_pythia8_powheg.C

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
R__ADD_INCLUDE_PATH($O2DPG_MC_CONFIG_ROOT)
22
///#include "FairGenerator.h"
3-
//#include "Generators/GeneratorPythia8.h"
3+
#include "Generators/GeneratorPythia8.h"
44
#include "Pythia8/Pythia.h"
55
#include "Generators/GeneratorPythia8Param.h"
66
#include "CommonUtils/FileSystemUtils.h"
@@ -24,13 +24,31 @@ using namespace Pythia8;
2424

2525
// Pythia8 generator using POWHEG data that are generated during the initialization
2626
// of the external generator. The POWHEG configuration file is copied to the current
27-
// directory with the right name and the POWHEG events are generated using the pwhg_main_hvq executable.
27+
// directory with the right name and the POWHEG events are generated using the executable
28+
// specified via the type parameter, namely:
29+
// 0: pwhg_main_hvq
30+
// 1: pwhg_main_W
31+
// 2: pwhg_main_Z
32+
// 3: pwhg_main_dijet
33+
// 4: pwhg_main_directphoton
2834
class GeneratorJEPythia8POWHEG : public o2::eventgen::GeneratorPythia8
2935
{
3036
public:
3137
/// default constructor
32-
GeneratorJEPythia8POWHEG(std::string confpath = "pwgpath")
38+
GeneratorJEPythia8POWHEG(std::string confpath = "pwgpath", short int type = 0)
3339
{
40+
// Assign events to generate with POWHEG
41+
unsigned int nPowhegEvents = getTotalNEvents();
42+
if (nPowhegEvents == 0) {
43+
LOG(fatal) << "Number of events not set or set to 0.";
44+
exit(1);
45+
}
46+
// Check on nEvents to generate with POWHEG
47+
// due to integer limit hardcoded in the generator
48+
if (nPowhegEvents > std::numeric_limits<int>::max()) {
49+
LOG(fatal) << "Number of events for POWHEG exceeds the maximum allowed value";
50+
exit(1);
51+
}
3452
// Check if file exist and is not empty
3553
if (std::filesystem::exists(confpath) && std::filesystem::file_size(confpath) > 0) {
3654
// Copy the file to the current directory
@@ -51,7 +69,7 @@ public:
5169
if (line.find("numevts") != std::string::npos)
5270
{
5371
// Set the number of events to the number of events defined in the configuration
54-
line = "numevts " + std::to_string(mSimConfig.getNEvents());
72+
line = "numevts " + std::to_string(nPowhegEvents);
5573
// replace it in the file
5674
isnumevts = true;
5775
}
@@ -61,35 +79,46 @@ public:
6179
dst << "iseed " << seed << std::endl;
6280
}
6381
if (!isnumevts) {
64-
dst << "numevts " << mSimConfig.getNEvents() << std::endl;
82+
dst << "numevts " << nPowhegEvents << std::endl;
6583
}
6684
src.close();
6785
dst.close();
6886
} else {
6987
LOG(fatal) << "POWHEG configuration file not found or empty" << std::endl;
7088
exit(1);
7189
}
72-
// Generate the POWHEG events
73-
std::string cmd = "pwhg_main_hvq";
74-
system(cmd.c_str());
90+
// Get POWHEG executable to use
91+
if (type >= mPowhegGen.size()) {
92+
LOG(warn) << "Available POWHEG generators are:";
93+
for (int k = 0; k < mPowhegGen.size(); k++)
94+
{
95+
LOG(warn) << "\t" << k << ": " << mPowhegGen[k];
96+
}
97+
LOG(fatal) << "POWHEG generator type " << type << " not found";
98+
exit(1);
99+
} else {
100+
LOG(info) << "Running POWHEG using the " << mPowhegGen[type] << " executable";
101+
// Generate the POWHEG events
102+
system(mPowhegGen[type].c_str());
103+
}
75104
};
76105

77106
private:
78-
o2::conf::SimConfig mSimConfig = o2::conf::SimConfig::Instance(); // local sim config object
107+
const std::vector<std::string> mPowhegGen = {"pwhg_main_hvq", "pwhg_main_W", "pwhg_main_Z", "pwhg_main_dijet", "pwhg_main_directphoton"}; // POWHEG executables
79108
};
80109

81110
} // namespace eventgen
82111
} // namespace o2
83112

84113
/** generator instance and settings **/
85114

86-
FairGenerator *getGeneratorJEPythia8POWHEG(std::string powhegconf = "pwgpath", std::string pythia8conf = "")
115+
FairGenerator *getGeneratorJEPythia8POWHEG(std::string powhegconf = "pwgpath", std::string pythia8conf = "", short int type = 0)
87116
{
88117
using namespace o2::eventgen;
89118
// Expand paths for the POWHEG configuration file
90119
powhegconf = o2::utils::expandShellVarsInFileName(powhegconf);
91120
LOG(info) << "Using POWHEG configuration file: " << powhegconf;
92-
auto myGen = new GeneratorJEPythia8POWHEG(powhegconf);
121+
auto myGen = new GeneratorJEPythia8POWHEG(powhegconf, type);
93122
if(GeneratorPythia8Param::Instance().config.empty() && pythia8conf.empty()) {
94123
LOG(fatal) << "No configuration provided for Pythia8";
95124
}

0 commit comments

Comments
 (0)