Skip to content

Commit ba6a1a7

Browse files
committed
Corrected include folder
1 parent 797f283 commit ba6a1a7

File tree

11 files changed

+172
-78
lines changed

11 files changed

+172
-78
lines changed

Generators/CMakeLists.txt

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ o2_add_library(Generators
4141
src/GeneratorTParticleParam.cxx
4242
src/GeneratorService.cxx
4343
src/FlowMapper.cxx
44-
$<$<BOOL:${onnxruntime_FOUND}>:src/TPCLoopers.cxx>
45-
$<$<BOOL:${onnxruntime_FOUND}>:src/TPCLoopersParam.cxx>
44+
src/TPCLoopers.cxx
45+
src/TPCLoopersParam.cxx
4646
$<$<BOOL:${pythia_FOUND}>:src/GeneratorPythia8.cxx>
4747
$<$<BOOL:${pythia_FOUND}>:src/DecayerPythia8.cxx>
4848
$<$<BOOL:${pythia_FOUND}>:src/GeneratorPythia8Param.cxx>
@@ -55,7 +55,7 @@ o2_add_library(Generators
5555
PUBLIC_LINK_LIBRARIES FairRoot::Base O2::SimConfig O2::CommonUtils O2::DetectorsBase O2::ZDCBase
5656
O2::SimulationDataFormat ${pythiaTarget} ${hepmcTarget}
5757
FairRoot::Gen
58-
$<$<BOOL:${onnxruntime_FOUND}>:onnxruntime::onnxruntime>
58+
onnxruntime::onnxruntime
5959
TARGETVARNAME targetName)
6060

6161
if(pythia_FOUND)
@@ -66,9 +66,7 @@ if(HepMC3_FOUND)
6666
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_HEPMC3)
6767
endif()
6868

69-
if(onnxruntime_FOUND)
70-
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_TPCLOOPERS)
71-
endif()
69+
target_compile_definitions(${targetName} PUBLIC GENERATORS_WITH_TPCLOOPERS)
7270

7371
set(headers
7472
include/Generators/Generator.h
@@ -95,11 +93,9 @@ set(headers
9593
include/Generators/FlowMapper.h
9694
)
9795

98-
if(onnxruntime_FOUND)
99-
list(APPEND headers
100-
include/Generators/TPCLoopers.h
101-
include/Generators/TPCLoopersParam.h)
102-
endif()
96+
list(APPEND headers
97+
include/Generators/TPCLoopers.h
98+
include/Generators/TPCLoopersParam.h)
10399

104100
if(pythia_FOUND)
105101
list(APPEND headers
@@ -171,4 +167,5 @@ endif()
171167

172168
o2_data_file(COPY share/external DESTINATION Generators)
173169
o2_data_file(COPY share/egconfig DESTINATION Generators)
170+
o2_data_file(COPY share/TPCLoopers DESTINATION Generators)
174171
o2_data_file(COPY share/pythia8 DESTINATION Generators)

Generators/include/Generators/Generator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "FairGenerator.h"
1818
#include "TParticle.h"
1919
#include "Generators/Trigger.h"
20-
#include "CCDB/BasicCCDBManager.h"
2120
#ifdef GENERATORS_WITH_TPCLOOPERS
2221
#include "Generators/TPCLoopers.h"
2322
#include "Generators/TPCLoopersParam.h"
@@ -172,8 +171,8 @@ class Generator : public FairGenerator
172171

173172
#ifdef GENERATORS_WITH_TPCLOOPERS
174173
// Loopers generator instance
175-
std::unique_ptr<o2::eventgen::GenTPCLoopers> mLoopersGen = nullptr;
176-
bool initLoopersGen();
174+
std::unique_ptr<o2::eventgen::GenTPCLoopers> mTPCLoopersGen = nullptr;
175+
bool initTPCLoopersGen();
177176
#endif
178177

179178
ClassDefOverride(Generator, 2);

Generators/include/TPCLoopers.h renamed to Generators/include/Generators/TPCLoopers.h

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@
1717
#ifdef GENERATORS_WITH_TPCLOOPERS
1818
#include <onnxruntime_cxx_api.h>
1919
#endif
20-
#include <iostream>
2120
#include <vector>
22-
#include <fstream>
2321
#include <rapidjson/document.h>
24-
#include "CCDB/CCDBTimeStampUtils.h"
25-
#include "CCDB/CcdbApi.h"
26-
#include "DetectorsRaw/HBFUtils.h"
2722
#include "TRandom3.h"
28-
#include "TDatabasePDG.h"
2923
#include <SimulationDataFormat/DigitizationContext.h>
30-
#include <SimulationDataFormat/ParticleStatus.h>
31-
#include "SimulationDataFormat/MCGenProperties.h"
3224
#include "TParticle.h"
33-
#include "TF1.h"
34-
#include <filesystem>
3525

3626
#ifdef GENERATORS_WITH_TPCLOOPERS
3727
// Static Ort::Env instance for multiple onnx model loading
3828
extern Ort::Env global_env;
3929

4030
// This class is responsible for loading the scaler parameters from a JSON file
4131
// and applying the inverse transformation to the generated data.
32+
// Inferenced output is scaled (min-max normalization or robust scaling for outlier features) during training,
33+
// so we need to revert this transformation to get physical values.
4234
struct Scaler {
4335
std::vector<double> normal_min;
4436
std::vector<double> normal_max;
@@ -74,6 +66,20 @@ namespace eventgen
7466
{
7567

7668
#ifdef GENERATORS_WITH_TPCLOOPERS
69+
/**
70+
* Generator for TPC Loopers based on pre-trained ONNX models.
71+
* Currently it generates loopers as electron-positron pairs and Compton electrons
72+
* according to specified distributions and parameters.
73+
* This can be extended to other types of background processes in the future (e.g. slow neutron spallation products, saturation tail).
74+
* Multiple configuration options are available:
75+
* - Flat gas: loopers are generated uniformly per event taking a reference value which can be either the LHC orbit time or the average interaction time record interval from the collision context.
76+
* ==> Current automatic setup (default) sets the interaction rate automatically from the collision context and the reference value per orbit is calculated from an external file.
77+
* ==> Number of loopers per orbit can be adjusted via a specific parameter.
78+
* - Poisson + Gaussian sampling: number of loopers are sampled from Poissonian (for pairs) and Gaussian (for Compton electrons) distributions based on provided parameters.
79+
* ==> flat gas must be disabled to use this option.
80+
* - Fixed number of loopers per event
81+
* ==> flat gas must be disabled to use this option and Poissonian/Gaussian parameters file should be set to None
82+
*/
7783
class GenTPCLoopers
7884
{
7985
public:
@@ -83,25 +89,25 @@ class GenTPCLoopers
8389

8490
Bool_t generateEvent();
8591

86-
Bool_t generateEvent(double& time_limit);
92+
Bool_t generateEvent(double time_limit);
8793

8894
std::vector<TParticle> importParticles();
8995

9096
unsigned int PoissonPairs();
9197

9298
unsigned int GaussianElectrons();
9399

94-
void SetNLoopers(unsigned int& nsig_pair, unsigned int& nsig_compton);
100+
void SetNLoopers(unsigned int nsig_pair, unsigned int nsig_compton);
95101

96-
void SetMultiplier(std::array<float, 2>& mult);
102+
void SetMultiplier(const std::array<float, 2>& mult);
97103

98-
void setFlatGas(Bool_t& flat, const Int_t& number, const Int_t& nloopers_orbit);
104+
void setFlatGas(Bool_t flat, Int_t number = -1, Int_t nloopers_orbit = -1);
99105

100-
void setFractionPairs(float& fractionPairs);
106+
void setFractionPairs(float fractionPairs);
101107

102-
void SetRate(const std::string& rateFile, const bool& isPbPb, const int& intRate);
108+
void SetRate(const std::string& rateFile, bool isPbPb, int intRate = 50000);
103109

104-
void SetAdjust(const float& adjust);
110+
void SetAdjust(float adjust = 0.f);
105111

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

@@ -121,10 +127,6 @@ class GenTPCLoopers
121127
bool mGaussSet = false;
122128
// Random number generator
123129
TRandom3 mRandGen;
124-
// Masses of the electrons and positrons
125-
TDatabasePDG* mPDG = TDatabasePDG::Instance();
126-
double mMass_e = mPDG->GetParticle(11)->Mass();
127-
double mMass_p = mPDG->GetParticle(-11)->Mass();
128130
int mCurrentEvent = 0; // Current event number, used for adaptive loopers
129131
TFile* mContextFile = nullptr; // Input collision context file
130132
o2::steer::DigitizationContext* mCollisionContext = nullptr; // Pointer to the digitization context

Generators/include/Generators/TPCLoopersParam.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@ namespace eventgen
2424

2525
/**
2626
** a parameter class/struct to keep the settings of
27-
** the tpc loopers event-generator and
27+
** the TPC loopers event-generator and
2828
** allow the user to modify them
2929
**/
3030
struct GenTPCLoopersParam : public o2::conf::ConfigurableParamHelper<GenTPCLoopersParam> {
31-
bool loopersVeto = false; // if true, no loopers are generated
32-
std::string model_pairs = "ccdb://Users/m/mgiacalo/WGAN_ExtGenPair"; // ONNX model for e+e- pair production
33-
std::string model_compton = "ccdb://Users/m/mgiacalo/WGAN_ExtGenCompton"; // ONNX model for Compton scattering
34-
std::string poisson = "${O2_ROOT}/share/Generators/egconfig/poisson_params.csv"; // file with Poissonian parameters
35-
std::string gauss = "${O2_ROOT}/share/Generators/egconfig/gaussian_params.csv"; // file with Gaussian parameters
36-
std::string scaler_pair = "${O2_ROOT}/share/Generators/egconfig/ScalerPairParams.json"; // file with scaler parameters for e+e- pair production
37-
std::string scaler_compton = "${O2_ROOT}/share/Generators/egconfig/ScalerComptonParams.json"; // file with scaler parameters for Compton scattering
38-
std::string nclxrate = "ccdb://Users/m/mgiacalo/ClustersTrackRatio"; // file with clusters/rate information per orbit
39-
std::string colsys = "PbPb"; // collision system (PbPb or pp)
40-
int intrate = -1; // Automatic IR from collision context if -1, else user-defined interaction rate in Hz
41-
bool flat_gas = true; // if true, the gas density is considered flat in the TPC volume
42-
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]
43-
float fraction_pairs = 0.08; // fraction of loopers [currently unused, kept for possible future debug developments]
44-
float multiplier[2] = {1., 1.}; // multiplier for pairs and compton loopers for Poissonian and Gaussian sampling
45-
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
46-
float adjust_flatgas = 0.f; // adjustment for the number of flat gas loopers per orbit (in percentage, e.g. -0.1 = -10%) [-1, inf)]
31+
bool loopersVeto = false; // if true, no loopers are generated
32+
// Current files are set to custom user CCDB paths, TO BE CHANGED
33+
std::string model_pairs = "ccdb://Users/m/mgiacalo/WGAN_ExtGenPair"; // ONNX model for e+e- pair production
34+
std::string model_compton = "ccdb://Users/m/mgiacalo/WGAN_ExtGenCompton"; // ONNX model for Compton scattering
35+
std::string poisson = "${O2_ROOT}/share/Generators/TPCLoopers/poisson_params.csv"; // file with Poissonian parameters
36+
std::string gauss = "${O2_ROOT}/share/Generators/TPCLoopers/gaussian_params.csv"; // file with Gaussian parameters
37+
std::string scaler_pair = "${O2_ROOT}/share/Generators/TPCLoopers/ScalerPairParams.json"; // file with scaler parameters for e+e- pair production
38+
std::string scaler_compton = "${O2_ROOT}/share/Generators/TPCLoopers/ScalerComptonParams.json"; // file with scaler parameters for Compton scattering
39+
std::string nclxrate = "ccdb://Users/m/mgiacalo/ClustersTrackRatio"; // file with clusters/rate information per orbit
40+
std::string colsys = "PbPb"; // collision system (PbPb or pp)
41+
int intrate = -1; // Automatic IR from collision context if -1, else user-defined interaction rate in Hz
42+
bool flat_gas = true; // if true, the gas density is considered flat in the TPC volume
43+
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]
44+
float fraction_pairs = 0.08; // fraction of loopers [currently unused, kept for possible future debug developments]
45+
float multiplier[2] = {1., 1.}; // multiplier for pairs and compton loopers for Poissonian and Gaussian sampling
46+
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
47+
float adjust_flatgas = 0.f; // adjustment for the number of flat gas loopers per orbit (in percentage, e.g. -0.1 = -10%) [-1, inf)]
4748
O2ParamDef(GenTPCLoopersParam, "GenTPCLoopers");
4849
};
4950

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# TPC Loopers Generator - Parameter Files
2+
3+
This directory contains parameter files used by the TPC Loopers event generator in ALICE O2.
4+
5+
## Overview
6+
7+
The TPC Loopers generator uses pre-trained ONNX models to generate realistic looper particles based on machine learning models trained on full GEANT4 slow neutron transport simulations. The parameter files in this directory provide:
8+
- Example statistical distribution parameters for sampling the number of loopers per event
9+
- **Mandatory** scaling parameters for transforming the ONNX model outputs to physical values
10+
11+
## Files Description
12+
13+
### Statistical Sampling Parameters
14+
15+
The files provided in the folder are examples based on the training dataset.
16+
17+
#### `gaussian_params.csv`
18+
Parameters for Gaussian distribution used to sample the number of Compton electrons per event.
19+
20+
**Format:** Four values (one per line)
21+
1. Mean (μ)
22+
2. Standard deviation (σ)
23+
3. Minimum value
24+
4. Maximum value
25+
26+
#### `poisson_params.csv`
27+
Parameters for Poisson distribution used to sample the number of electron-positron pairs per event.
28+
29+
**Format:** Three values (one per line)
30+
1. Lambda (λ) parameter
31+
2. Minimum value
32+
3. Maximum value
33+
34+
### Scaler Parameters
35+
36+
These JSON files contain the parameters for inverse transformation of the ONNX models output. They should be kept as they are
37+
unless a new version of the models is released.
38+
39+
#### `ScalerComptonParams.json`
40+
Scaler parameters for Compton electron generation model.
41+
42+
**Structure:**
43+
```json
44+
{
45+
"normal": {
46+
"min": [array of 5 min values for min-max normalization],
47+
"max": [array of 5 max values for min-max normalization]
48+
},
49+
"outlier": {
50+
"center": [array of 2 center values for robust scaling],
51+
"scale": [array of 2 scale values for robust scaling]
52+
}
53+
}
54+
```
55+
56+
- **normal**: Min-max normalization parameters for standard features (`Px`, `Py`, `Pz`, `VertexCoordinatesX`, `VertexCoordinatesY`)
57+
- **outlier**: Robust scaler parameters (center and scale) for outlier features (`VertexCoordinatesZ`,`time`)
58+
59+
#### `ScalerPairParams.json`
60+
Scaler parameters for electron-positron pair generation model.
61+
62+
**Structure:**
63+
```json
64+
{
65+
"normal": {
66+
"min": [array of 8 min values for min-max normalization],
67+
"max": [array of 8 max values for min-max normalization]
68+
},
69+
"outlier": {
70+
"center": [array of 2 center values for robust scaling],
71+
"scale": [array of 2 scale values for robust scaling]
72+
}
73+
}
74+
```
75+
76+
- **normal**: Min-max normalization parameters for standard features (`Px_e`, `Py_e`, `Pz_e`,`Px_p`, `Py_p`, `Pz_p`, `VertexCoordinatesX`, `VertexCoordinatesY`)
77+
- **outlier**: Robust scaler parameters (center and scale) for outlier features (`VertexCoordinatesZ`,`time`)
78+
---
79+
*Author: M. Giacalone - September 2025*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Generators/src/Generator.cxx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "TParticle.h"
2626
#include "TSystem.h"
2727
#include "TGrid.h"
28+
#include "CCDB/BasicCCDBManager.h"
29+
#include <filesystem>
2830

2931
namespace o2
3032
{
@@ -50,7 +52,7 @@ Generator::Generator() : FairGenerator("ALICEo2", "ALICEo2 Generator"),
5052
if (transport) {
5153
bool tpcActive = (std::find(simConfig.getReadoutDetectors().begin(), simConfig.getReadoutDetectors().end(), "TPC") != simConfig.getReadoutDetectors().end());
5254
if (tpcActive) {
53-
if (initLoopersGen()) {
55+
if (initTPCLoopersGen()) {
5456
mAddTPCLoopers = kTRUE;
5557
}
5658
} else {
@@ -79,7 +81,7 @@ Generator::Generator(const Char_t* name, const Char_t* title) : FairGenerator(na
7981
if (transport) {
8082
bool tpcActive = (std::find(simConfig.getReadoutDetectors().begin(), simConfig.getReadoutDetectors().end(), "TPC") != simConfig.getReadoutDetectors().end());
8183
if (tpcActive) {
82-
if (initLoopersGen()) {
84+
if (initTPCLoopersGen()) {
8385
mAddTPCLoopers = kTRUE;
8486
}
8587
} else {
@@ -94,7 +96,7 @@ Generator::Generator(const Char_t* name, const Char_t* title) : FairGenerator(na
9496

9597
/*****************************************************************/
9698
#ifdef GENERATORS_WITH_TPCLOOPERS
97-
bool Generator::initLoopersGen()
99+
bool Generator::initTPCLoopersGen()
98100
{
99101
// Expand all environment paths
100102
const auto& loopersParam = o2::eventgen::GenTPCLoopersParam::Instance();
@@ -169,24 +171,24 @@ bool Generator::initLoopersGen()
169171
nclxrate = isAlien[2] || isCCDB[2] ? local_names[2] : nclxrate;
170172
try {
171173
// Create the TPC loopers generator with the provided parameters
172-
mLoopersGen = std::make_unique<o2::eventgen::GenTPCLoopers>(model_pairs, model_compton, poisson, gauss, scaler_pair, scaler_compton);
174+
mTPCLoopersGen = std::make_unique<o2::eventgen::GenTPCLoopers>(model_pairs, model_compton, poisson, gauss, scaler_pair, scaler_compton);
173175
const auto& intrate = loopersParam.intrate;
174176
// Configure the generator with flat gas loopers defined per orbit with clusters/track info
175177
// If intrate is negative (default), automatic IR from collisioncontext.root will be used
176178
if (flat_gas) {
177-
mLoopersGen->SetRate(nclxrate, (colsys == "PbPb") ? true : false, intrate);
178-
mLoopersGen->SetAdjust(loopersParam.adjust_flatgas);
179+
mTPCLoopersGen->SetRate(nclxrate, (colsys == "PbPb") ? true : false, intrate);
180+
mTPCLoopersGen->SetAdjust(loopersParam.adjust_flatgas);
179181
} else {
180182
// Otherwise, Poisson+Gauss sampling or fixed number of loopers per event will be used
181183
// Multiplier is applied only with distribution sampling
182184
// This configuration can be used for testing purposes, in all other cases flat gas is recommended
183-
mLoopersGen->SetNLoopers(nLoopersPairs, nLoopersCompton);
184-
mLoopersGen->SetMultiplier(multiplier);
185+
mTPCLoopersGen->SetNLoopers(nLoopersPairs, nLoopersCompton);
186+
mTPCLoopersGen->SetMultiplier(multiplier);
185187
}
186188
LOG(info) << "TPC Loopers generator initialized successfully";
187189
} catch (const std::exception& e) {
188190
LOG(error) << "Failed to initialize TPC Loopers generator: " << e.what();
189-
mLoopersGen.reset();
191+
mTPCLoopersGen.reset();
190192
}
191193
return kTRUE;
192194
}
@@ -210,21 +212,21 @@ Bool_t
210212
{
211213
#ifdef GENERATORS_WITH_TPCLOOPERS
212214
if (mAddTPCLoopers) {
213-
if (!mLoopersGen) {
215+
if (!mTPCLoopersGen) {
214216
LOG(error) << "Loopers generator not initialized";
215217
return kFALSE;
216218
}
217219

218220
// Generate loopers using the initialized TPC loopers generator
219-
if (!mLoopersGen->generateEvent()) {
221+
if (!mTPCLoopersGen->generateEvent()) {
220222
LOG(error) << "Failed to generate loopers event";
221223
return kFALSE;
222224
}
223-
if (mLoopersGen->getNLoopers() == 0) {
225+
if (mTPCLoopersGen->getNLoopers() == 0) {
224226
LOG(warning) << "No loopers generated for this event";
225227
return kTRUE;
226228
}
227-
const auto& looperParticles = mLoopersGen->importParticles();
229+
const auto& looperParticles = mTPCLoopersGen->importParticles();
228230
if (looperParticles.empty()) {
229231
LOG(error) << "Failed to import loopers particles";
230232
return kFALSE;

0 commit comments

Comments
 (0)