Skip to content

Commit 769dfb3

Browse files
committed
HybridGen: Add missing EventHeader propagation
The HybridGen needs to forward event headers from the underlying generators. In order to access these, we need to make a protected function public. Also adding eventHeader treatment to BoxGenerator.
1 parent 3318e86 commit 769dfb3

File tree

7 files changed

+38
-17
lines changed

7 files changed

+38
-17
lines changed

Generators/include/Generators/BoxGenerator.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "TParticle.h"
1919
#include <vector>
2020
#include <Generators/BoxGunParam.h>
21+
#include "SimulationDataFormat/MCEventHeader.h"
2122

2223
namespace o2::eventgen
2324
{
@@ -92,6 +93,14 @@ class BoxGenerator : public Generator
9293
return true;
9394
}
9495

96+
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override
97+
{
98+
using Key = o2::dataformats::MCInfoKeys;
99+
if (eventHeader) {
100+
eventHeader->putInfo<std::string>(Key::generator, "o2::eventgen::BoxGenerator");
101+
}
102+
}
103+
95104
private:
96105
double mPtMin{0.}, mPtMax{0.}; // Transverse momentum range [GeV]
97106
double mPhiMin{0.}, mPhiMax{360.}; // Azimuth angle range [degree]

Generators/include/Generators/Generator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Generator : public FairGenerator
7373
/** methods to override **/
7474
virtual Bool_t generateEvent() = 0; // generates event (in structure internal to generator)
7575
virtual Bool_t importParticles() = 0; // fills the mParticles vector (transfer from generator state)
76+
virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader) {};
7677

7778
/** setters **/
7879
void setMomentumUnit(double val) { mMomentumUnit = val; };
@@ -102,9 +103,6 @@ class Generator : public FairGenerator
102103
/** operator= **/
103104
Generator& operator=(const Generator&);
104105

105-
/** methods that can be overridded **/
106-
virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader){};
107-
108106
/** internal methods **/
109107
Bool_t addTracks(FairPrimaryGenerator* primGen);
110108
Bool_t boostEvent();

Generators/include/Generators/GeneratorFromFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ class GeneratorFromEventPool : public o2::eventgen::Generator
135135
}
136136
bool importParticles() override
137137
{
138+
mO2KineGenerator->clearParticles(); // clear old container before filling with new ones
138139
auto import_good = mO2KineGenerator->importParticles();
139140
// transfer the particles (could be avoided)
140141
mParticles = mO2KineGenerator->getParticles();
142+
141143
return import_good;
142144
}
143145

Generators/include/Generators/GeneratorHybrid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class GeneratorHybrid : public Generator
6161
Bool_t Init() override;
6262
Bool_t generateEvent() override;
6363
Bool_t importParticles() override;
64+
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
6465

6566
void setNEvents(int n) { mNEvents = n; }
6667

@@ -106,6 +107,7 @@ class GeneratorHybrid : public Generator
106107
bool mIsInitialized = false;
107108

108109
int mNEvents = -1; // the number of events to be done, if known (helps initiating cleanup)
110+
o2::dataformats::MCEventHeader mMCEventHeader; // to capture event headers
109111

110112
enum class GenMode {
111113
kSeq,

Generators/src/GeneratorFromFile.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,12 @@ bool GeneratorFromEventPool::Init()
398398
LOG(error) << "No file found that can be used with EventPool generator";
399399
return false;
400400
}
401+
LOG(info) << "Found " << mPoolFilesAvailable.size() << " available event pool files";
401402

402403
// now choose the actual file
403-
std::uniform_int_distribution<int> distribution(0, mPoolFilesAvailable.size());
404-
mFileChosen = mPoolFilesAvailable[distribution(mRandomEngine)];
405-
LOG(info) << "EventPool is using file " << mFileChosen;
404+
std::uniform_int_distribution<int> distribution(0, mPoolFilesAvailable.size() - 1);
405+
auto chosenIndex = distribution(mRandomEngine);
406+
mFileChosen = mPoolFilesAvailable[chosenIndex];
406407

407408
// we bring up the internal mO2KineGenerator
408409
auto kine_config = O2KineGenConfig{

Generators/src/GeneratorHybrid.cxx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,16 @@ bool GeneratorHybrid::importParticles()
332332
LOG(info) << "Importing particles for task " << genIndex;
333333

334334
// at this moment the mIndex-th generator is ready to be used
335-
std::copy(gens[genIndex]->getParticles().begin(), gens[genIndex]->getParticles().end(), std::back_insert_iterator(mParticles));
335+
mParticles.clear();
336+
mParticles = gens[genIndex]->getParticles();
337+
338+
// fetch the event Header information from the underlying generator
339+
mMCEventHeader.clearInfo();
340+
gens[genIndex]->updateHeader(&mMCEventHeader);
336341

337342
mInputTaskQueue.push(genIndex);
338343
mTasksStarted++;
339344

340-
// we need to fix particles statuses --> need to enforce this on the importParticles level of individual generators
341-
for (auto& p : mParticles) {
342-
auto st = o2::mcgenstatus::MCGenStatusEncoding(p.GetStatusCode(), p.GetStatusCode()).fullEncoding;
343-
p.SetStatusCode(st);
344-
p.SetBit(ParticleStatus::kToBeDone, true);
345-
}
346-
347345
mseqCounter++;
348346
mEventCounter++;
349347
if (mEventCounter == mNEvents) {
@@ -353,6 +351,17 @@ bool GeneratorHybrid::importParticles()
353351
return true;
354352
}
355353

354+
void GeneratorHybrid::updateHeader(o2::dataformats::MCEventHeader* eventHeader)
355+
{
356+
if (eventHeader) {
357+
// we forward the original header information if any
358+
eventHeader->copyInfoFrom(mMCEventHeader);
359+
360+
// put additional information about
361+
eventHeader->putInfo<std::string>("forwarding-generator", "HybridGen");
362+
}
363+
}
364+
356365
template <typename T>
357366
std::string GeneratorHybrid::jsonValueToString(const T& value)
358367
{

run/SimExamples/Hybrid/runo2sim.sh

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ else
6363
fi
6464

6565
# Generation of 1000 events using STARlight in a slight.hepmc file
66-
${O2_ROOT}/examples/HepMC_STARlight/run-starlight.sh
66+
#${O2_ROOT}/examples/HepMC_STARlight/run-starlight.sh
6767

6868
# Generation of event pool with pythia8 (10000 events) in a evtpool.root file
69-
${O2DPG_ROOT}/MC/run/examples/event_pool.sh --make
69+
#${O2DPG_ROOT}/MC/run/examples/event_pool.sh --make
7070

7171
# Starting simulation with Hybrid generator
72-
${O2_ROOT}/bin/o2-sim --noGeant -j $JOBS --field ccdb --vertexMode kCCDB --run 300000 --configKeyValues "MFTBase.buildAlignment=true;GeneratorHybrid.configFile=$PWD/hybridconfig.json;GeneratorHybrid.randomize=false;${more}" -g hybrid -o genevents --timestamp 1546300800000 --seed 836302859 -n $NEV
72+
${O2_ROOT}/bin/o2-sim-serial --noGeant -j $JOBS --field ccdb --vertexMode kNoVertex --run 300000 --configKeyValues "MFTBase.buildAlignment=true;GeneratorHybrid.configFile=$PWD/hybridconfig_1.json;${more}" -g hybrid -o genevents --timestamp 1546300800000 --seed 836302859 -n $NEV

0 commit comments

Comments
 (0)