Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added alien path compatibility, Phi rotation and event pool randomisation to GenO2Kine #13571

Merged
merged 22 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c45b477
Implemented flag for .root kinematics input
jackal1-66 Oct 7, 2024
45be6ac
Event pooling with order randomisation of tree entries
jackal1-66 Oct 17, 2024
8621151
Added rng seed flag
jackal1-66 Oct 18, 2024
8749040
Added possibility of random rotation of Phi in event pool
jackal1-66 Oct 18, 2024
b70c6c8
Added GRID kine input compatibility
jackal1-66 Oct 21, 2024
3abdf90
Merge branch 'AliceO2Group:dev' into eventpool1
jackal1-66 Oct 21, 2024
ce45b43
Introduction of GeneratorHybrid class for multiple generators configu…
jackal1-66 Oct 24, 2024
d3ffd4d
Merge branch 'eventpool1' of https://github.com/jackal1-66/AliceO2 in…
jackal1-66 Oct 24, 2024
c96cdea
Merge branch 'AliceO2Group:dev' into eventpool1
jackal1-66 Oct 24, 2024
8e3a4ad
Implemented configurations and fractions parameters for hybrid generator
jackal1-66 Oct 25, 2024
76291b0
Merge branch 'AliceO2Group:dev' into eventpool
jackal1-66 Oct 29, 2024
640f076
Merge branch 'AliceO2Group:dev' into eventpool1
jackal1-66 Oct 29, 2024
3391bcc
Added features to use alien path, phi rotation and event randomisation
jackal1-66 Oct 29, 2024
3a8dc30
Removal of unused implementation attempt
jackal1-66 Oct 29, 2024
d8e70e1
Deleted feature for RUN2 based generator
jackal1-66 Oct 29, 2024
c9a5dad
Merge branch 'AliceO2Group:dev' into eventpool
jackal1-66 Oct 30, 2024
ab696dd
Merge branch 'AliceO2Group:dev' into eventpool1
jackal1-66 Oct 30, 2024
2d3b692
Merge branch 'eventpool1' into eventpool
jackal1-66 Oct 30, 2024
335f4c9
Revert "Add SMatrixGPU compatibility to trackParCov (#13602)"
jackal1-66 Oct 30, 2024
983ce32
Revert "Merge branch 'eventpool1' into eventpool"
jackal1-66 Oct 30, 2024
b465c39
Reapply "Add SMatrixGPU compatibility to trackParCov (#13602)"
jackal1-66 Oct 30, 2024
84619f1
Better rotation handling
jackal1-66 Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Common/SimConfig/include/SimConfig/SimConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct SimConfigData {
std::string mTrigger; // chosen VMC generator trigger
unsigned int mNEvents; // number of events to be simulated
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
std::string mKineInput; // file name of external kinematics file used as input for the generation (events redirection)
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
unsigned int mStartEvent; // index of first event to be taken
float mBMax; // maximum for impact parameter sampling
Expand Down Expand Up @@ -154,6 +155,7 @@ class SimConfig
unsigned int getNEvents() const { return mConfigData.mNEvents; }

std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; }
std::string getKineInput() const { return mConfigData.mKineInput; }
std::string getEmbedIntoFileName() const { return mConfigData.mEmbedIntoFileName; }
unsigned int getStartEvent() const { return mConfigData.mStartEvent; }
float getBMax() const { return mConfigData.mBMax; }
Expand Down
2 changes: 2 additions & 0 deletions Common/SimConfig/src/SimConfig.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options
"forwardKine", bpo::bool_switch(), "forward kinematics on a FairMQ channel")(
"noDiscOutput", bpo::bool_switch(), "switch off writing sim results to disc (useful in combination with forwardKine)");
options.add_options()("fromCollContext", bpo::value<std::string>()->default_value(""), "Use a pregenerated collision context to infer number of events to simulate, how to embedd them, the vertex position etc. Takes precedence of other options such as \"--nEvents\".");
options.add_options()("kine-input", bpo::value<std::string>()->default_value(""), "Use a pregenerated kinematic .root file. The optional \':\' character with a number after it can be used to infer number of events to skip on the input file.");
}

void SimConfig::determineActiveModules(std::vector<std::string> const& inputargs, std::vector<std::string> const& skippedModules, std::vector<std::string>& activeModules, bool isUpgrade)
Expand Down Expand Up @@ -304,6 +305,7 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const&
mConfigData.mTrigger = vm["trigger"].as<std::string>();
mConfigData.mNEvents = vm["nEvents"].as<unsigned int>();
mConfigData.mExtKinFileName = vm["extKinFile"].as<std::string>();
mConfigData.mKineInput = vm["kine-input"].as<std::string>();
mConfigData.mEmbedIntoFileName = vm["embedIntoFile"].as<std::string>();
mConfigData.mStartEvent = vm["startEvent"].as<unsigned int>();
mConfigData.mBMax = vm["bMax"].as<float>();
Expand Down
7 changes: 7 additions & 0 deletions Generators/include/Generators/GeneratorFromFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "FairGenerator.h"
#include "Generators/Generator.h"
#include <TRandom3.h>
#include <TGrid.h>

class TBranch;
class TFile;
Expand Down Expand Up @@ -57,6 +59,7 @@ class GeneratorFromFile : public FairGenerator
int mEventsAvailable = 0;
bool mSkipNonTrackable = true; //! whether to pass non-trackable (decayed particles) to the MC stack
bool mFixOffShell = true; // fix particles with M_assigned != M_calculated
TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
ClassDefOverride(GeneratorFromFile, 1);
};

Expand Down Expand Up @@ -94,6 +97,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<o2::dataformats::MCEventHeader> mOrigMCEventHeader; //! the MC event header of the original file

Expand Down
3 changes: 3 additions & 0 deletions Generators/include/Generators/GeneratorFromO2KineParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
/**
** a parameter class/struct to keep the settings of
** the FromO2Kine event generator and
** allow the user to modify them

Check failure on line 28 in Generators/include/Generators/GeneratorFromO2KineParam.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
**/

struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper<GeneratorFromO2KineParam> {
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");
};
Expand Down
39 changes: 39 additions & 0 deletions Generators/src/GeneratorFromFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ namespace eventgen
{
GeneratorFromFile::GeneratorFromFile(const char* name)
{
if (strncmp(name, "alien:/", 7) == 0) {
jackal1-66 marked this conversation as resolved.
Show resolved Hide resolved
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 \n";
Expand Down Expand Up @@ -175,6 +182,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";
Expand Down Expand Up @@ -210,6 +224,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;
}
Expand All @@ -229,6 +249,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;

Expand All @@ -253,6 +285,13 @@ bool GeneratorFromO2Kine::importParticles()
auto pdg = t.GetPdgCode();
auto px = t.Px();
auto py = t.Py();
if (mRandomPhi) {
auto phi = TMath::ATan2(py, px);
auto pt = TMath::Sqrt(px * px + py * py);
phi += dPhi;
px = pt * TMath::Cos(phi);
py = pt * TMath::Sin(phi);
}
jackal1-66 marked this conversation as resolved.
Show resolved Hide resolved
auto pz = t.Pz();
auto vx = t.Vx();
auto vy = t.Vy();
Expand Down
40 changes: 40 additions & 0 deletions run/o2sim_parallel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,46 @@ int main(int argc, char* argv[])
}
return r;
}
// check if Kinematics input file is provided
LOG(info) << "Kinematics input file: " << conf.getKineInput();
jackal1-66 marked this conversation as resolved.
Show resolved Hide resolved
if (conf.getKineInput().size() > 0) {
std::string path = conf.getKineInput();
std::size_t pos = path.find(':');
std::string kinefilename;
int ntf = 1;
if (pos != std::string::npos) {
kinefilename = path.substr(0, pos);
ntf = std::stoi(path.substr(pos + 1));
} else {
kinefilename = path;
}
LOG(info) << "Using Kinematics input file: " << kinefilename << ", TimeFrame number: " << ntf;
TFile kinefile(kinefilename.c_str(), "READ");
if (kinefile.IsZombie()) {
LOG(fatal) << "Could not open Kinematics input file: " << kinefilename;
return 2;
}
TFile splitkinefile(Form("%s_Kine.root", conf.getOutPrefix().c_str()), "RECREATE");
TTree* kine = (TTree*)kinefile.Get("o2sim");
const int nentries = kine->GetEntries();
const int nevsim = conf.getNEvents();
TTree* kineout = kine->CloneTree(0);
ntf -= 1;
if ((ntf + 1) * nevsim > kine->GetEntries()) {
LOG(fatal) << "Not enough events in the input file to get the entries in the interval [" << ntf * nevsim << ',' << (ntf + 1) * nevsim << "]";
return 2;
}
for (int i = ntf * nevsim; i < (ntf + 1) * nevsim; ++i) {
kine->GetEntry(i);
kineout->Fill();
}
splitkinefile.Write();
kinefile.Close();
splitkinefile.Close();
LOG(info) << "Kinematics input file processed successfully";
LOG(info) << "Splitting time took " << timer.RealTime() << " s";
return 0;
}

gAskedEvents = conf.getNEvents();
if (conf.asService()) {
Expand Down
Loading