diff --git a/Generators/include/Generators/GeneratorFromFile.h b/Generators/include/Generators/GeneratorFromFile.h index 42656baddd402..14a74db8dbc57 100644 --- a/Generators/include/Generators/GeneratorFromFile.h +++ b/Generators/include/Generators/GeneratorFromFile.h @@ -16,6 +16,8 @@ #include "FairGenerator.h" #include "Generators/Generator.h" +#include +#include class TBranch; class TFile; @@ -94,6 +96,10 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack bool mContinueMode = false; //! whether we want to continue simulation of previously inhibited tracks bool mRoundRobin = false; //! whether we want to take events from file in a round robin fashion + bool mRandomize = false; //! whether we want to randomize the order of events in the input file + unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value + bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles + TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations) std::unique_ptr mOrigMCEventHeader; //! the MC event header of the original file diff --git a/Generators/include/Generators/GeneratorFromO2KineParam.h b/Generators/include/Generators/GeneratorFromO2KineParam.h index c0e032f740aba..298d52ba0a1f9 100644 --- a/Generators/include/Generators/GeneratorFromO2KineParam.h +++ b/Generators/include/Generators/GeneratorFromO2KineParam.h @@ -25,13 +25,16 @@ namespace eventgen /** ** a parameter class/struct to keep the settings of ** the FromO2Kine event generator and - ** allow the user to modify them + ** allow the user to modify them **/ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper { bool skipNonTrackable = true; bool continueMode = false; bool roundRobin = false; // read events with period boundary conditions + bool randomize = false; // randomize the order of events + unsigned int rngseed = 0; // randomizer seed, 0 for random value + bool randomphi = false; // randomize phi angle std::string fileName = ""; // filename to read from - takes precedence over SimConfig if given O2ParamDef(GeneratorFromO2KineParam, "GeneratorFromO2Kine"); }; diff --git a/Generators/src/GeneratorFromFile.cxx b/Generators/src/GeneratorFromFile.cxx index df8efc29bd1e4..d3cd7b967c4d5 100644 --- a/Generators/src/GeneratorFromFile.cxx +++ b/Generators/src/GeneratorFromFile.cxx @@ -175,6 +175,13 @@ GeneratorFromO2Kine::GeneratorFromO2Kine(const char* name) setPositionUnit(1.); setTimeUnit(1.); + if (strncmp(name, "alien:/", 7) == 0) { + mAlienInstance = TGrid::Connect("alien"); + if (!mAlienInstance) { + LOG(fatal) << "Could not connect to alien, did you check the alien token?"; + return; + } + } mEventFile = TFile::Open(name); if (mEventFile == nullptr) { LOG(fatal) << "EventFile " << name << " not found"; @@ -210,6 +217,12 @@ bool GeneratorFromO2Kine::Init() mSkipNonTrackable = param.skipNonTrackable; mContinueMode = param.continueMode; mRoundRobin = param.roundRobin; + mRandomize = param.randomize; + mRngSeed = param.rngseed; + mRandomPhi = param.randomphi; + if (mRandomize) { + gRandom->SetSeed(mRngSeed); + } return true; } @@ -229,6 +242,18 @@ bool GeneratorFromO2Kine::importParticles() // It might need some adjustment to make it work with secondaries or to continue // from a kinematics snapshot + // Randomize the order of events in the input file + if (mRandomize) { + mEventCounter = gRandom->Integer(mEventsAvailable); + } + + double dPhi = 0.; + // Phi rotation + if (mRandomPhi) { + dPhi = gRandom->Uniform(2 * TMath::Pi()); + LOG(info) << "Rotating phi by " << dPhi; + } + if (mEventCounter < mEventsAvailable) { int particlecounter = 0; @@ -253,6 +278,15 @@ bool GeneratorFromO2Kine::importParticles() auto pdg = t.GetPdgCode(); auto px = t.Px(); auto py = t.Py(); + if (mRandomPhi) { + // transformation applied through rotation matrix + auto cos = TMath::Cos(dPhi); + auto sin = TMath::Sin(dPhi); + auto newPx = px * cos - py * sin; + auto newPy = px * sin + py * cos; + px = newPx; + py = newPy; + } auto pz = t.Pz(); auto vx = t.Vx(); auto vy = t.Vy();