Skip to content

Commit c156a31

Browse files
committed
Set automatic interaction rate from collision context
1 parent 883bc8e commit c156a31

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

Generators/include/Generators/TPCLoopersParam.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ struct GenTPCLoopersParam : public o2::conf::ConfigurableParamHelper<GenTPCLoope
3737
std::string scaler_compton = "${O2_ROOT}/share/Generators/egconfig/ScalerComptonParams.json"; // file with scaler parameters for Compton scattering
3838
std::string nclxrate = "ccdb://Users/m/mgiacalo/ClustersTrackRatio"; // file with clusters/rate information per orbit
3939
std::string colsys = "PbPb"; // collision system (PbPb or pp)
40-
int intrate = 50000; // interaction rate
40+
int intrate = -1; // Automatic IR from collision context if -1, else user-defined interaction rate in Hz
4141
bool flat_gas = true; // if true, the gas density is considered flat in the TPC volume
42-
int nFlatGasLoopers = 500; // number of loopers to be generated per event in case of flat gas
42+
unsigned int nFlatGasLoopers = 500; // number of loopers to be generated per event in case of flat gas
4343
float fraction_pairs = 0.08; // fraction of loopers
4444
float multiplier[2] = {1., 1.}; // multiplier for pairs and compton loopers for Poissonian and Gaussian sampling
4545
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

Generators/include/TPCLoopers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class GenTPCLoopers
9191

9292
void SetAdjust(const float &adjust);
9393

94+
unsigned int getNLoopers() const { return (mNLoopersPairs + mNLoopersCompton); }
95+
9496
private:
9597
std::unique_ptr<ONNXGenerator> mONNX_pair = nullptr;
9698
std::unique_ptr<ONNXGenerator> mONNX_compton = nullptr;
@@ -122,6 +124,7 @@ class GenTPCLoopers
122124
double mTimeLimit = 0.0; // Time limit for the current event
123125
double mTimeEnd = 0.0; // Time limit for the last event
124126
float mLoopsFractionPairs = 0.08; // Fraction of loopers from Pairs
127+
int mInteractionRate = 50000; // Interaction rate in Hz
125128
};
126129
#endif // GENERATORS_WITH_TPCLOOPERS
127130

Generators/src/Generator.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ bool Generator::initLoopersGen()
107107
}
108108
}
109109
const auto& nFlatGasLoopers = loopersParam.nFlatGasLoopers;
110-
auto fraction_pairs = loopersParam.fraction_pairs;
110+
const auto& fraction_pairs = loopersParam.fraction_pairs;
111111
std::array<float, 2> multiplier = {loopersParam.multiplier[0], loopersParam.multiplier[1]};
112112
unsigned int nLoopersPairs = loopersParam.fixedNLoopers[0];
113113
unsigned int nLoopersCompton = loopersParam.fixedNLoopers[1];
@@ -166,10 +166,6 @@ bool Generator::initLoopersGen()
166166
LOG(fatal) << "Error: collision system must be either 'PbPb' or 'pp'";
167167
exit(1);
168168
} else {
169-
if (intrate <= 0) {
170-
LOG(fatal) << "Error: interaction rate must be positive!";
171-
exit(1);
172-
}
173169
mLoopersGen->SetRate(nclxrate, (colsys == "PbPb") ? true : false, intrate);
174170
mLoopersGen->SetAdjust(loopersParam.adjust_flatgas);
175171
}
@@ -217,6 +213,10 @@ Bool_t
217213
LOG(error) << "Failed to generate loopers event";
218214
return kFALSE;
219215
}
216+
if (mLoopersGen->getNLoopers() == 0) {
217+
LOG(warning) << "No loopers generated for this event";
218+
return kTRUE;
219+
}
220220
const auto& looperParticles = mLoopersGen->importParticles();
221221
if (looperParticles.empty()) {
222222
LOG(error) << "Failed to import loopers particles";

Generators/src/TPCLoopers.cxx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,28 @@ void GenTPCLoopers::SetRate(const std::string &rateFile, const bool &isPbPb = tr
437437
LOG(fatal) << "Error: Could not find fit function '" << fitName << "' in rate file!";
438438
exit(1);
439439
}
440-
auto ref = static_cast<int>(std::floor(fit->Eval(intRate / 1000.))); // fit expects rate in kHz
440+
mInteractionRate = intRate;
441+
if (mInteractionRate < 0) {
442+
mContextFile = std::filesystem::exists("collisioncontext.root") ? TFile::Open("collisioncontext.root") : nullptr;
443+
if (!mContextFile || mContextFile->IsZombie()) {
444+
LOG(fatal) << "Error: Interaction rate not provided and collision context file not found!";
445+
exit(1);
446+
}
447+
mCollisionContext = (o2::steer::DigitizationContext*)mContextFile->Get("DigitizationContext");
448+
mInteractionRate = std::floor(mCollisionContext->getDigitizerInteractionRate());
449+
LOG(info) << "Interaction rate retrieved from collision context: " << mInteractionRate << " Hz";
450+
if (mInteractionRate < 0) {
451+
LOG(fatal) << "Error: Invalid interaction rate retrieved from collision context!";
452+
exit(1);
453+
}
454+
}
455+
auto ref = static_cast<int>(std::floor(fit->Eval(mInteractionRate / 1000.))); // fit expects rate in kHz
441456
rate_file.Close();
442457
if (ref <= 0) {
443458
LOG(fatal) << "Computed flat gas number reference per orbit is <=0";
444459
exit(1);
445460
} else {
446-
LOG(info) << "Set flat gas number to " << ref << " loopers per orbit using " << fitName << " from " << intRate << " Hz interaction rate.";
461+
LOG(info) << "Set flat gas number to " << ref << " loopers per orbit using " << fitName << " from " << mInteractionRate << " Hz interaction rate.";
447462
auto flat = true;
448463
setFlatGas(flat, -1, ref);
449464
}

0 commit comments

Comments
 (0)