Skip to content

Commit eb866f3

Browse files
authored
Automatic IR (#2184)
1 parent 63d61be commit eb866f3

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

MC/config/common/external/generator/TPCLoopers.C

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,15 @@ class GenTPCLoopers : public Generator
420420
}
421421
}
422422
if (mFlatGas){
423-
mContextFile = std::filesystem::exists("collisioncontext.root") ? TFile::Open("collisioncontext.root") : nullptr;
424-
mCollisionContext = mContextFile ? (o2::steer::DigitizationContext *)mContextFile->Get("DigitizationContext") : nullptr;
423+
// Check if mContextFile is already opened
424+
if(!mContextFile)
425+
{
426+
mContextFile = std::filesystem::exists("collisioncontext.root") ? TFile::Open("collisioncontext.root") : nullptr;
427+
}
428+
if(!mCollisionContext)
429+
{
430+
mCollisionContext = mContextFile ? (o2::steer::DigitizationContext *)mContextFile->Get("DigitizationContext") : nullptr;
431+
}
425432
mInteractionTimeRecords = mCollisionContext ? mCollisionContext->getEventRecords() : std::vector<o2::InteractionTimeRecord>{};
426433
if (mInteractionTimeRecords.empty())
427434
{
@@ -476,14 +483,32 @@ class GenTPCLoopers : public Generator
476483
LOG(fatal) << "Error: Could not find fit function '" << fitName << "' in rate file!";
477484
exit(1);
478485
}
479-
auto ref = static_cast<int>(std::floor(fit->Eval(intRate / 1000.))); // fit expects rate in kHz
486+
mInteractionRate = intRate;
487+
if(mInteractionRate < 0)
488+
{
489+
mContextFile = std::filesystem::exists("collisioncontext.root") ? TFile::Open("collisioncontext.root") : nullptr;
490+
if(!mContextFile || mContextFile->IsZombie())
491+
{
492+
LOG(fatal) << "Error: Interaction rate not provided and collision context file not found!";
493+
exit(1);
494+
}
495+
mCollisionContext = (o2::steer::DigitizationContext *)mContextFile->Get("DigitizationContext");
496+
mInteractionRate = std::floor(mCollisionContext->getDigitizerInteractionRate());
497+
LOG(info) << "Interaction rate retrieved from collision context: " << mInteractionRate << " Hz";
498+
if (mInteractionRate < 0)
499+
{
500+
LOG(fatal) << "Error: Invalid interaction rate retrieved from collision context!";
501+
exit(1);
502+
}
503+
}
504+
auto ref = static_cast<int>(std::floor(fit->Eval(mInteractionRate / 1000.))); // fit expects rate in kHz
480505
rate_file.Close();
481506
if (ref <= 0)
482507
{
483508
LOG(fatal) << "Computed flat gas number reference per orbit is <=0";
484509
exit(1);
485510
} else {
486-
LOG(info) << "Set flat gas number to " << ref << " loopers per orbit using " << fitName << " from " << intRate << " Hz interaction rate.";
511+
LOG(info) << "Set flat gas number to " << ref << " loopers per orbit using " << fitName << " from " << mInteractionRate << " Hz interaction rate.";
487512
auto flat = true;
488513
setFlatGas(flat, -1, ref);
489514
}
@@ -531,6 +556,7 @@ class GenTPCLoopers : public Generator
531556
double mTimeEnd = 0.0; // Time limit for the last event
532557
float mLoopsFractionPairs = 0.08; // Fraction of loopers from Pairs
533558
std::string mRateFile = ""; // File with clusters/rate information per orbit
559+
int mInteractionRate = 38000; // Interaction rate in Hz
534560
};
535561

536562
} // namespace eventgen
@@ -684,7 +710,7 @@ Generator_TPCLoopersFlat(std::string model_pairs = "tpcloopmodel.onnx", std::str
684710
FairGenerator *
685711
Generator_TPCLoopersOrbitRef(std::string model_pairs = "tpcloopmodel.onnx", std::string model_compton = "tpcloopmodelcompton.onnx",
686712
std::string scaler_pair = "scaler_pair.json", std::string scaler_compton = "scaler_compton.json",
687-
std::string nclxrate = "nclxrate.root", bool isPbPb = true, const int intrate = 38000, const float adjust = 0.f)
713+
std::string nclxrate = "nclxrate.root", bool isPbPb = true, const int intrate = -1, const float adjust = 0.f)
688714
{
689715
// Expand all environment paths
690716
model_pairs = gSystem->ExpandPathName(model_pairs.c_str());

MC/config/common/ini/GeneratorLoopersFlatFile.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TPC loopers injector using fit to calculate reference loopers number per orbit. File with fit function is pulled from the CCDB.
2-
# Three additional parameters are available in the function: (isPbPb = true, intRate = 38000, adjust = 0.)
3-
# isPbPb and intRate must be set in case the collision system is not PbPb at 38 kHz, while adjust can be used to decrease/increase
2+
# Three additional parameters are available in the function: (isPbPb = true, intRate = -1, adjust = 0.)
3+
# isPbPb and intRate must be set in case the collision system is not PbPb and the IR is not taken from collisioncontext, while adjust can be used to decrease/increase
44
# the number of loopers per orbit obtained from the reference (e.g. -0.1 reduces the loopers by 10%)
55
#---> GeneratorTPCloopers
66
[GeneratorExternal]

0 commit comments

Comments
 (0)