Skip to content

Commit 8ec256c

Browse files
authored
GenO2Kine: Event-pool developments
Developments needed for event-pool feature, which relies on GenO2Kine for reading from the pool: - allow reading kine file from Alien - randomize event picking from file - possibility to phi-rotate events https://its.cern.ch/jira/browse/O2-5216
1 parent 03fd79a commit 8ec256c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

Generators/include/Generators/GeneratorFromFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "FairGenerator.h"
1818
#include "Generators/Generator.h"
19+
#include <TRandom3.h>
20+
#include <TGrid.h>
1921

2022
class TBranch;
2123
class TFile;
@@ -94,6 +96,10 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator
9496
bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack
9597
bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks
9698
bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion
99+
bool mRandomize = false; //! whether we want to randomize the order of events in the input file
100+
unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value
101+
bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles
102+
TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
97103

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

Generators/include/Generators/GeneratorFromO2KineParam.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ namespace eventgen
2525
/**
2626
** a parameter class/struct to keep the settings of
2727
** the FromO2Kine event generator and
28-
** allow the user to modify them
28+
** allow the user to modify them
2929
**/
3030

3131
struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper<GeneratorFromO2KineParam> {
3232
bool skipNonTrackable = true;
3333
bool continueMode = false;
3434
bool roundRobin = false; // read events with period boundary conditions
35+
bool randomize = false; // randomize the order of events
36+
unsigned int rngseed = 0; // randomizer seed, 0 for random value
37+
bool randomphi = false; // randomize phi angle
3538
std::string fileName = ""; // filename to read from - takes precedence over SimConfig if given
3639
O2ParamDef(GeneratorFromO2KineParam, "GeneratorFromO2Kine");
3740
};

Generators/src/GeneratorFromFile.cxx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ GeneratorFromO2Kine::GeneratorFromO2Kine(const char* name)
175175
setPositionUnit(1.);
176176
setTimeUnit(1.);
177177

178+
if (strncmp(name, "alien:/", 7) == 0) {
179+
mAlienInstance = TGrid::Connect("alien");
180+
if (!mAlienInstance) {
181+
LOG(fatal) << "Could not connect to alien, did you check the alien token?";
182+
return;
183+
}
184+
}
178185
mEventFile = TFile::Open(name);
179186
if (mEventFile == nullptr) {
180187
LOG(fatal) << "EventFile " << name << " not found";
@@ -210,6 +217,12 @@ bool GeneratorFromO2Kine::Init()
210217
mSkipNonTrackable = param.skipNonTrackable;
211218
mContinueMode = param.continueMode;
212219
mRoundRobin = param.roundRobin;
220+
mRandomize = param.randomize;
221+
mRngSeed = param.rngseed;
222+
mRandomPhi = param.randomphi;
223+
if (mRandomize) {
224+
gRandom->SetSeed(mRngSeed);
225+
}
213226

214227
return true;
215228
}
@@ -229,6 +242,18 @@ bool GeneratorFromO2Kine::importParticles()
229242
// It might need some adjustment to make it work with secondaries or to continue
230243
// from a kinematics snapshot
231244

245+
// Randomize the order of events in the input file
246+
if (mRandomize) {
247+
mEventCounter = gRandom->Integer(mEventsAvailable);
248+
}
249+
250+
double dPhi = 0.;
251+
// Phi rotation
252+
if (mRandomPhi) {
253+
dPhi = gRandom->Uniform(2 * TMath::Pi());
254+
LOG(info) << "Rotating phi by " << dPhi;
255+
}
256+
232257
if (mEventCounter < mEventsAvailable) {
233258
int particlecounter = 0;
234259

@@ -253,6 +278,15 @@ bool GeneratorFromO2Kine::importParticles()
253278
auto pdg = t.GetPdgCode();
254279
auto px = t.Px();
255280
auto py = t.Py();
281+
if (mRandomPhi) {
282+
// transformation applied through rotation matrix
283+
auto cos = TMath::Cos(dPhi);
284+
auto sin = TMath::Sin(dPhi);
285+
auto newPx = px * cos - py * sin;
286+
auto newPy = px * sin + py * cos;
287+
px = newPx;
288+
py = newPy;
289+
}
256290
auto pz = t.Pz();
257291
auto vx = t.Vx();
258292
auto vy = t.Vy();

0 commit comments

Comments
 (0)