Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion Generators/include/Generators/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Generator : public FairGenerator
void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;

// loopers flag
Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
// collect an ID and a short description of sub-generator entities
std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
// the current ID of the sub-generator used in the current event (if applicable)
Expand Down
24 changes: 12 additions & 12 deletions Generators/include/Generators/TPCLoopersParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ namespace eventgen
** allow the user to modify them
**/
struct GenTPCLoopersParam : public o2::conf::ConfigurableParamHelper<GenTPCLoopersParam> {
bool loopersVeto = false; // if true, no loopers are generated
std::string model_pairs = "ccdb://Users/m/mgiacalo/WGAN_ExtGenPair"; // ONNX model for e+e- pair production
std::string model_compton = "ccdb://Users/m/mgiacalo/WGAN_ExtGenCompton"; // ONNX model for Compton scattering
std::string poisson = "${O2_ROOT}/share/Generators/egconfig/poisson_params.csv"; // file with Poissonian parameters
std::string gauss = "${O2_ROOT}/share/Generators/egconfig/gaussian_params.csv"; // file with Gaussian parameters
std::string scaler_pair = "${O2_ROOT}/share/Generators/egconfig/ScalerPairParams.json"; // file with scaler parameters for e+e- pair production
bool loopersVeto = false; // if true, no loopers are generated
std::string model_pairs = "ccdb://Users/m/mgiacalo/WGAN_ExtGenPair"; // ONNX model for e+e- pair production
std::string model_compton = "ccdb://Users/m/mgiacalo/WGAN_ExtGenCompton"; // ONNX model for Compton scattering
std::string poisson = "${O2_ROOT}/share/Generators/egconfig/poisson_params.csv"; // file with Poissonian parameters
std::string gauss = "${O2_ROOT}/share/Generators/egconfig/gaussian_params.csv"; // file with Gaussian parameters
std::string scaler_pair = "${O2_ROOT}/share/Generators/egconfig/ScalerPairParams.json"; // file with scaler parameters for e+e- pair production
std::string scaler_compton = "${O2_ROOT}/share/Generators/egconfig/ScalerComptonParams.json"; // file with scaler parameters for Compton scattering
std::string nclxrate = "ccdb://Users/m/mgiacalo/ClustersTrackRatio"; // file with clusters/rate information per orbit
std::string colsys = "PbPb"; // collision system (PbPb or pp)
int intrate = -1; // Automatic IR from collision context if -1, else user-defined interaction rate in Hz
bool flat_gas = true; // if true, the gas density is considered flat in the TPC volume
unsigned int nFlatGasLoopers = 500; // number of loopers to be generated per event in case of flat gas [currently unused, kept for possible future debug developments]
float fraction_pairs = 0.08; // fraction of loopers [currently unused, kept for possible future debug developments]
float multiplier[2] = {1., 1.}; // multiplier for pairs and compton loopers for Poissonian and Gaussian sampling
unsigned int fixedNLoopers[2] = {1, 1}; // fixed number of loopers coming from pairs and compton electrons - valid if flat gas is false and both Poisson and Gaussian params files are empty
float adjust_flatgas = 0.f; // adjustment for the number of flat gas loopers per orbit (in percentage, e.g. -0.1 = -10%) [-1, inf)]
bool flat_gas = true; // if true, the gas density is considered flat in the TPC volume
unsigned int nFlatGasLoopers = 500; // number of loopers to be generated per event in case of flat gas [currently unused, kept for possible future debug developments]
float fraction_pairs = 0.08; // fraction of loopers [currently unused, kept for possible future debug developments]
float multiplier[2] = {1., 1.}; // multiplier for pairs and compton loopers for Poissonian and Gaussian sampling
unsigned int fixedNLoopers[2] = {1, 1}; // fixed number of loopers coming from pairs and compton electrons - valid if flat gas is false and both Poisson and Gaussian params files are empty
float adjust_flatgas = 0.f; // adjustment for the number of flat gas loopers per orbit (in percentage, e.g. -0.1 = -10%) [-1, inf)]
O2ParamDef(GenTPCLoopersParam, "GenTPCLoopers");
};

Expand Down
155 changes: 77 additions & 78 deletions Generators/include/TPCLoopers.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef ALICEO2_EVENTGEN_TPCLOOPERS_H_
#define ALICEO2_EVENTGEN_TPCLOOPERS_H_

#ifdef GENERATORS_WITH_TPCLOOPERS
#include <onnxruntime_cxx_api.h>
#endif
#include <iostream>
#include <vector>
#include <fstream>
#include <rapidjson/document.h>

Check failure on line 10 in Generators/include/TPCLoopers.h

View workflow job for this annotation

GitHub Actions / PR formatting / copyright headers

Missing or malformed copyright notice

This source file is missing the correct copyright notice.
#include "CCDB/CCDBTimeStampUtils.h"
#include "CCDB/CcdbApi.h"
#include "DetectorsRaw/HBFUtils.h"
Expand All @@ -26,33 +26,32 @@

// This class is responsible for loading the scaler parameters from a JSON file
// and applying the inverse transformation to the generated data.
struct Scaler
{
std::vector<double> normal_min;
std::vector<double> normal_max;
std::vector<double> outlier_center;
std::vector<double> outlier_scale;
struct Scaler {
std::vector<double> normal_min;
std::vector<double> normal_max;
std::vector<double> outlier_center;
std::vector<double> outlier_scale;

void load(const std::string &filename);
void load(const std::string& filename);

std::vector<double> inverse_transform(const std::vector<double> &input);
std::vector<double> inverse_transform(const std::vector<double>& input);

private:
std::vector<double> jsonArrayToVector(const rapidjson::Value &jsonArray);
private:
std::vector<double> jsonArrayToVector(const rapidjson::Value& jsonArray);
};

// This class loads the ONNX model and generates samples using it.
class ONNXGenerator
{
public:
ONNXGenerator(Ort::Env &shared_env, const std::string &model_path);
public:
ONNXGenerator(Ort::Env& shared_env, const std::string& model_path);

std::vector<double> generate_sample();
std::vector<double> generate_sample();

private:
Ort::Env &env;
Ort::Session session;
TRandom3 rand_gen;
private:
Ort::Env& env;
Ort::Session session;
TRandom3 rand_gen;
};
#endif // GENERATORS_WITH_TPCLOOPERS

Expand All @@ -64,67 +63,67 @@
#ifdef GENERATORS_WITH_TPCLOOPERS
class GenTPCLoopers
{
public:
GenTPCLoopers(std::string model_pairs = "tpcloopmodel.onnx", std::string model_compton = "tpcloopmodelcompton.onnx",
std::string poisson = "poisson.csv", std::string gauss = "gauss.csv", std::string scaler_pair = "scaler_pair.json",
std::string scaler_compton = "scaler_compton.json");
Bool_t generateEvent();

Bool_t generateEvent(double &time_limit);

std::vector<TParticle> importParticles();

unsigned int PoissonPairs();

unsigned int GaussianElectrons();

void SetNLoopers(unsigned int &nsig_pair, unsigned int &nsig_compton);

void SetMultiplier(std::array<float, 2> &mult);

void setFlatGas(Bool_t& flat, const Int_t& number, const Int_t& nloopers_orbit);

void setFractionPairs(float &fractionPairs);

void SetRate(const std::string &rateFile, const bool &isPbPb, const int &intRate);

void SetAdjust(const float &adjust);

unsigned int getNLoopers() const { return (mNLoopersPairs + mNLoopersCompton); }

private:
std::unique_ptr<ONNXGenerator> mONNX_pair = nullptr;
std::unique_ptr<ONNXGenerator> mONNX_compton = nullptr;
std::unique_ptr<Scaler> mScaler_pair = nullptr;
std::unique_ptr<Scaler> mScaler_compton = nullptr;
double mPoisson[3] = {0.0, 0.0, 0.0}; // Mu, Min and Max of Poissonian
double mGauss[4] = {0.0, 0.0, 0.0, 0.0}; // Mean, Std, Min, Max
std::vector<std::vector<double>> mGenPairs;
std::vector<std::vector<double>> mGenElectrons;
unsigned int mNLoopersPairs = -1;
unsigned int mNLoopersCompton = -1;
std::array<float, 2> mMultiplier = {1., 1.};
bool mPoissonSet = false;
bool mGaussSet = false;
// Random number generator
TRandom3 mRandGen;
// Masses of the electrons and positrons
TDatabasePDG *mPDG = TDatabasePDG::Instance();
double mMass_e = mPDG->GetParticle(11)->Mass();
double mMass_p = mPDG->GetParticle(-11)->Mass();
int mCurrentEvent = 0; // Current event number, used for adaptive loopers
TFile *mContextFile = nullptr; // Input collision context file
o2::steer::DigitizationContext *mCollisionContext = nullptr; // Pointer to the digitization context
std::vector<o2::InteractionTimeRecord> mInteractionTimeRecords; // Interaction time records from collision context
Bool_t mFlatGas = false; // Flag to indicate if flat gas loopers are used
Bool_t mFlatGasOrbit = false; // Flag to indicate if flat gas loopers are per orbit
Int_t mFlatGasNumber = -1; // Number of flat gas loopers per event
double mIntTimeRecMean = 1.0; // Average interaction time record used for the reference
double mTimeLimit = 0.0; // Time limit for the current event
double mTimeEnd = 0.0; // Time limit for the last event
float mLoopsFractionPairs = 0.08; // Fraction of loopers from Pairs
int mInteractionRate = 50000; // Interaction rate in Hz
public:
GenTPCLoopers(std::string model_pairs = "tpcloopmodel.onnx", std::string model_compton = "tpcloopmodelcompton.onnx",
std::string poisson = "poisson.csv", std::string gauss = "gauss.csv", std::string scaler_pair = "scaler_pair.json",
std::string scaler_compton = "scaler_compton.json");

Bool_t generateEvent();

Bool_t generateEvent(double& time_limit);

std::vector<TParticle> importParticles();

unsigned int PoissonPairs();

unsigned int GaussianElectrons();

void SetNLoopers(unsigned int& nsig_pair, unsigned int& nsig_compton);

void SetMultiplier(std::array<float, 2>& mult);

void setFlatGas(Bool_t& flat, const Int_t& number, const Int_t& nloopers_orbit);

void setFractionPairs(float& fractionPairs);

void SetRate(const std::string& rateFile, const bool& isPbPb, const int& intRate);

void SetAdjust(const float& adjust);

unsigned int getNLoopers() const { return (mNLoopersPairs + mNLoopersCompton); }

private:
std::unique_ptr<ONNXGenerator> mONNX_pair = nullptr;
std::unique_ptr<ONNXGenerator> mONNX_compton = nullptr;
std::unique_ptr<Scaler> mScaler_pair = nullptr;
std::unique_ptr<Scaler> mScaler_compton = nullptr;
double mPoisson[3] = {0.0, 0.0, 0.0}; // Mu, Min and Max of Poissonian
double mGauss[4] = {0.0, 0.0, 0.0, 0.0}; // Mean, Std, Min, Max
std::vector<std::vector<double>> mGenPairs;
std::vector<std::vector<double>> mGenElectrons;
unsigned int mNLoopersPairs = -1;
unsigned int mNLoopersCompton = -1;
std::array<float, 2> mMultiplier = {1., 1.};
bool mPoissonSet = false;
bool mGaussSet = false;
// Random number generator
TRandom3 mRandGen;
// Masses of the electrons and positrons
TDatabasePDG* mPDG = TDatabasePDG::Instance();
double mMass_e = mPDG->GetParticle(11)->Mass();
double mMass_p = mPDG->GetParticle(-11)->Mass();
int mCurrentEvent = 0; // Current event number, used for adaptive loopers
TFile* mContextFile = nullptr; // Input collision context file
o2::steer::DigitizationContext* mCollisionContext = nullptr; // Pointer to the digitization context
std::vector<o2::InteractionTimeRecord> mInteractionTimeRecords; // Interaction time records from collision context
Bool_t mFlatGas = false; // Flag to indicate if flat gas loopers are used
Bool_t mFlatGasOrbit = false; // Flag to indicate if flat gas loopers are per orbit
Int_t mFlatGasNumber = -1; // Number of flat gas loopers per event
double mIntTimeRecMean = 1.0; // Average interaction time record used for the reference
double mTimeLimit = 0.0; // Time limit for the current event
double mTimeEnd = 0.0; // Time limit for the last event
float mLoopsFractionPairs = 0.08; // Fraction of loopers from Pairs
int mInteractionRate = 50000; // Interaction rate in Hz
};
#endif // GENERATORS_WITH_TPCLOOPERS

Expand Down
52 changes: 26 additions & 26 deletions Generators/share/egconfig/ScalerComptonParams.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"normal": {
"min": [
-0.0108811147511005,
-0.0098758740350604,
-0.0103233363479375,
-260.0542297363281,
-259.80059814453125
],
"max": [
0.0108060473576188,
0.0103057539090514,
0.0106524610891938,
260.0343933105469,
259.62890625
]
},
"outlier": {
"center": [
-71.39387130737305,
96791.23828125
],
"scale": [
265.9389114379883,
230762.30981445312
]
}
"normal": {
"min": [
-0.0108811147511005,
-0.0098758740350604,
-0.0103233363479375,
-260.0542297363281,
-259.80059814453125
],
"max": [
0.0108060473576188,
0.0103057539090514,
0.0106524610891938,
260.0343933105469,
259.62890625
]
},
"outlier": {
"center": [
-71.39387130737305,
96791.23828125
],
"scale": [
265.9389114379883,
230762.30981445312
]
}
}
64 changes: 32 additions & 32 deletions Generators/share/egconfig/ScalerPairParams.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"normal": {
"min": [
-0.0073022879660129,
-0.0077305701561272,
-0.0076750442385673,
-0.0082916170358657,
-0.0079681202769279,
-0.0077468422241508,
-255.6164093017578,
-252.9441680908203
],
"max": [
0.007688719779253,
0.0077241472899913,
0.0075828479602932,
0.00813714787364,
0.0083825681358575,
0.0073839174583554,
256.2904968261719,
253.4925842285156
]
},
"outlier": {
"center": [
-79.66580963134766,
141535.640625
],
"scale": [
250.8921127319336,
222363.16015625
]
}
"normal": {
"min": [
-0.0073022879660129,
-0.0077305701561272,
-0.0076750442385673,
-0.0082916170358657,
-0.0079681202769279,
-0.0077468422241508,
-255.6164093017578,
-252.9441680908203
],
"max": [
0.007688719779253,
0.0077241472899913,
0.0075828479602932,
0.00813714787364,
0.0083825681358575,
0.0073839174583554,
256.2904968261719,
253.4925842285156
]
},
"outlier": {
"center": [
-79.66580963134766,
141535.640625
],
"scale": [
250.8921127319336,
222363.16015625
]
}
}
6 changes: 3 additions & 3 deletions Generators/src/Generator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ bool Generator::initLoopersGen()
try {
// Create the TPC loopers generator with the provided parameters
mLoopersGen = std::make_unique<o2::eventgen::GenTPCLoopers>(model_pairs, model_compton, poisson, gauss, scaler_pair, scaler_compton);
const auto &intrate = loopersParam.intrate;
const auto& intrate = loopersParam.intrate;
// Configure the generator with flat gas loopers defined per orbit with clusters/track info
// If intrate is negative (default), automatic IR from collisioncontext.root will be used
if (flat_gas) {
Expand Down Expand Up @@ -209,7 +209,7 @@ Bool_t
Generator::finalizeEvent()
{
#ifdef GENERATORS_WITH_TPCLOOPERS
if(mAddTPCLoopers) {
if (mAddTPCLoopers) {
if (!mLoopersGen) {
LOG(error) << "Loopers generator not initialized";
return kFALSE;
Expand Down Expand Up @@ -268,7 +268,7 @@ Bool_t
}

/** Event finalization**/
if(!finalizeEvent()) {
if (!finalizeEvent()) {
LOG(error) << "ReadEvent failed in finalizeEvent";
return kFALSE;
}
Expand Down
Loading
Loading