Skip to content

Commit 4afcb33

Browse files
committed
Removed mGlobal* + created example for hybrid generator
1 parent b1c2d37 commit 4afcb33

File tree

11 files changed

+210606
-48
lines changed

11 files changed

+210606
-48
lines changed

Generators/include/Generators/GeneratorFromFile.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator
102102
unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value
103103
bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles
104104
TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
105-
bool mGlobal = true; // whether to use the global configuration
106-
std::unique_ptr<O2KineGenConfig> mConfig; //! Local configuration of the generator
105+
std::unique_ptr<O2KineGenConfig> mConfig; //! Configuration object
107106

108107
std::unique_ptr<o2::dataformats::MCEventHeader> mOrigMCEventHeader; //! the MC event header of the original file
109108

Generators/include/Generators/GeneratorPythia8.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ class GeneratorPythia8 : public Generator
285285
long mInitialRNGSeed = -1; // initial seed for Pythia random number state;
286286
// will be transported to Pythia in the Init function through the Pythia::readString("Random:seed") mechanism.
287287
// Value of -1 means unitialized; 0 will be time-dependent and values >1 <= MAX_SEED concrete reproducible seeding
288-
bool mGlobalParam = true; // if true the use of the global parameters is foreseen, otherwise it means the parametric constructor has been called
289-
std::unique_ptr<Pythia8GenConfig> mGenConfig; // local configuration
288+
std::unique_ptr<Pythia8GenConfig> mGenConfig; // configuration object
290289

291290
constexpr static long MAX_SEED = 900000000;
292291

Generators/src/GeneratorFactory.cxx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
6969

7070
#ifdef GENERATORS_WITH_PYTHIA8
7171
auto makePythia8Gen = [](std::string& config) {
72-
auto gen = new o2::eventgen::GeneratorPythia8();
72+
auto& singleton = GeneratorPythia8Param::Instance();
73+
auto pars = o2::eventgen::Pythia8GenConfig {
74+
.config = config.size() > 0 ? config : singleton.config,
75+
.hooksFileName = singleton.hooksFileName,
76+
.hooksFuncName = singleton.hooksFuncName,
77+
.includePartonEvent = singleton.includePartonEvent,
78+
.particleFilter = singleton.particleFilter,
79+
.verbose = singleton.verbose,
80+
};
81+
auto gen = new o2::eventgen::GeneratorPythia8(pars);
7382
if (!config.empty()) {
7483
LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl;
7584
gen->setConfig(config); // assign config; will be executed in Init function
@@ -143,12 +152,22 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
143152
LOG(info) << "using external kinematics";
144153
} else if (genconfig.compare("extkinO2") == 0) {
145154
// external kinematics from previous O2 output
146-
auto name1 = GeneratorFromO2KineParam::Instance().fileName;
155+
auto& singleton = GeneratorFromO2KineParam::Instance();
156+
auto name1 = singleton.fileName;
147157
auto name2 = conf.getExtKinematicsFileName();
148-
auto extGen = new o2::eventgen::GeneratorFromO2Kine(name1.size() > 0 ? name1.c_str() : name2.c_str());
158+
auto pars = O2KineGenConfig{
159+
.skipNonTrackable = singleton.skipNonTrackable,
160+
.continueMode = singleton.continueMode,
161+
.roundRobin = singleton.roundRobin,
162+
.randomize = singleton.randomize,
163+
.rngseed = singleton.rngseed,
164+
.randomphi = singleton.randomphi,
165+
.fileName = name1.size() > 0 ? name1.c_str() : name2.c_str()
166+
};
167+
auto extGen = new o2::eventgen::GeneratorFromO2Kine(pars);
149168
extGen->SetStartEvent(conf.getStartEvent());
150169
primGen->AddGenerator(extGen);
151-
if (GeneratorFromO2KineParam::Instance().continueMode) {
170+
if (pars.continueMode) {
152171
auto o2PrimGen = dynamic_cast<o2::eventgen::PrimaryGenerator*>(primGen);
153172
if (o2PrimGen) {
154173
o2PrimGen->setApplyVertex(false);

Generators/src/GeneratorFromFile.cxx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ GeneratorFromO2Kine::GeneratorFromO2Kine(const char* name)
209209

210210
GeneratorFromO2Kine::GeneratorFromO2Kine(O2KineGenConfig const& pars) : GeneratorFromO2Kine(pars.fileName.c_str())
211211
{
212-
mGlobal = false;
213212
mConfig = std::make_unique<O2KineGenConfig>(pars);
214213
}
215214

@@ -218,24 +217,13 @@ bool GeneratorFromO2Kine::Init()
218217

219218
// read and set params
220219

221-
if (mGlobal) {
222-
auto& param = GeneratorFromO2KineParam::Instance();
223-
LOG(info) << "Init \'FromO2Kine\' generator with following parameters";
224-
LOG(info) << param;
225-
mSkipNonTrackable = param.skipNonTrackable;
226-
mContinueMode = param.continueMode;
227-
mRoundRobin = param.roundRobin;
228-
mRandomize = param.randomize;
229-
mRngSeed = param.rngseed;
230-
mRandomPhi = param.randomphi;
231-
} else {
232-
mSkipNonTrackable = mConfig->skipNonTrackable;
233-
mContinueMode = mConfig->continueMode;
234-
mRoundRobin = mConfig->roundRobin;
235-
mRandomize = mConfig->randomize;
236-
mRngSeed = mConfig->rngseed;
237-
mRandomPhi = mConfig->randomphi;
238-
}
220+
LOG(info) << "Init \'FromO2Kine\' generator";
221+
mSkipNonTrackable = mConfig->skipNonTrackable;
222+
mContinueMode = mConfig->continueMode;
223+
mRoundRobin = mConfig->roundRobin;
224+
mRandomize = mConfig->randomize;
225+
mRngSeed = mConfig->rngseed;
226+
mRandomPhi = mConfig->randomphi;
239227
if (mRandomize) {
240228
gRandom->SetSeed(mRngSeed);
241229
}

Generators/src/GeneratorHybrid.cxx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ GeneratorHybrid::GeneratorHybrid(const std::string& inputgens)
6262
} else if (gen.compare(0, 7, "pythia8") == 0) {
6363
// Check if mConfigs[index] contains pythia8_ and a number
6464
if (mConfigs[index].compare("") == 0) {
65-
gens.push_back(std::make_unique<o2::eventgen::GeneratorPythia8>());
65+
auto pars = Pythia8GenConfig();
66+
gens.push_back(std::make_unique<o2::eventgen::GeneratorPythia8>(pars));
6667
} else {
6768
// Get the index of pythia8 configuration
6869
int confPythia8Index = std::stoi(mConfigs[index].substr(8));
@@ -137,16 +138,18 @@ Bool_t GeneratorHybrid::generateEvent()
137138
mIndex = gRandom->Integer(mGens.size());
138139
} else {
139140
while (mFractions[mCurrentFraction] == 0 || mseqCounter == mFractions[mCurrentFraction]) {
140-
if (mFractions[mCurrentFraction] != 0)
141+
if (mFractions[mCurrentFraction] != 0) {
141142
mseqCounter = 0;
143+
}
142144
mCurrentFraction = (mCurrentFraction + 1) % mFractions.size();
143145
}
144146
mIndex = mCurrentFraction;
145147
}
146-
if (mConfigs[mIndex].compare("") == 0)
148+
if (mConfigs[mIndex].compare("") == 0) {
147149
LOG(info) << "GeneratorHybrid: generating event with generator " << mGens[mIndex];
148-
else
150+
} else {
149151
LOG(info) << "GeneratorHybrid: generating event with generator " << mConfigs[mIndex];
152+
}
150153
gens[mIndex]->clearParticles(); // clear container of this class
151154
gens[mIndex]->generateEvent();
152155
// notify the sub event generator
@@ -246,8 +249,9 @@ Bool_t GeneratorHybrid::parseJSON(const std::string& path)
246249
if (name == "boxgen" || name == "pythia8" || name == "extkinO2" || name == "external" || name == "hepmc") {
247250
LOG(fatal) << "No configuration provided for generator " << name;
248251
return false;
249-
} else
252+
} else {
250253
mConfigs.push_back("");
254+
}
251255
}
252256
}
253257
}

Generators/src/GeneratorPythia8.cxx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ GeneratorPythia8::GeneratorPythia8(Pythia8GenConfig const& pars) : Generator("AL
8080
setConfig(pars.config);
8181
setHooksFileName(pars.hooksFileName);
8282
setHooksFuncName(pars.hooksFuncName);
83-
mGlobalParam = false;
8483
}
8584

8685
/*****************************************************************/
@@ -579,11 +578,7 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
579578
}
580579
}
581580
}
582-
int verbose;
583-
if (mGlobalParam)
584-
verbose = GeneratorPythia8Param::Instance().verbose;
585-
else
586-
verbose = mGenConfig->verbose;
581+
int verbose = mGenConfig->verbose;
587582
if (verbose) {
588583
LOG(info) << "Pythia event was pruned from " << event.size()
589584
<< " to " << pruned.size() << " particles";
@@ -597,11 +592,7 @@ void GeneratorPythia8::initUserFilterCallback()
597592
{
598593
mUserFilterFcn = [](Pythia8::Particle const&) -> bool { return true; };
599594

600-
std::string filter;
601-
if (mGlobalParam)
602-
filter = GeneratorPythia8Param::Instance().particleFilter;
603-
else
604-
filter = mGenConfig->particleFilter;
595+
std::string filter = mGenConfig->particleFilter;
605596
if (filter.size() > 0) {
606597
LOG(info) << "Initializing the callback for user-based particle pruning " << filter;
607598
auto expandedFileName = o2::utils::expandShellVarsInFileName(filter);
@@ -630,11 +621,7 @@ Bool_t
630621
// event record in the AOD.
631622

632623
std::function<bool(const Pythia8::Particle&)> partonSelect = [](const Pythia8::Particle&) { return true; };
633-
bool includeParton;
634-
if (mGlobalParam)
635-
includeParton = GeneratorPythia8Param::Instance().includePartonEvent;
636-
else
637-
includeParton = mGenConfig->includePartonEvent;
624+
bool includeParton = mGenConfig->includePartonEvent;
638625
if (not includeParton) {
639626

640627
// Select pythia particles

run/SimExamples/Hybrid/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- doxy
2+
\page refrunSimExamplesHybrid Example Hybrid
3+
/doxy -->
4+
5+
The usage of the Hybrid generator with the o2-sim is presented in this short manual.
6+
All the other generators are implemented as sub-generators and they can be called thanks to a
7+
JSON file, fed to o2-sim via the GeneratorHybrid.configFile parameter.
8+
9+
The example can be run automatically using the runo2sim.sh script, which contains most of the
10+
available generators in O2. The JSON template can be generated using the ${O2DPG_ROOT}/MC/bin/o2_hybrid_gen.py script. To use this example the user can simply copy the entire Hybrid example folder and execute the script after giving it execution permissions (`chmod +x runo2sim.sh`).
11+
12+
# Files description
13+
14+
- **runo2sim.sh** &rarr; allows to use the hybrid generator example
15+
- **hybridconfig.json** &rarr; example JSON file for the hybrid generator configuration
16+
- **example.optns** &rarr; options file to be used in EPOS4 implemented as subgenerator in this example (the .optns must be available in the current working directory)
17+
- **evtpool.root** &rarr; cached events to be used with the extkinO2 generator
18+
- **epos4.hepmc** &rarr; EPOS4 events stored as hepmc file

0 commit comments

Comments
 (0)