Skip to content

Commit ff08913

Browse files
committed
Added decreasing mechanism and fixed nLoopers bug
1 parent e3fbd3a commit ff08913

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,18 @@ class GenLoopersInjector : public Generator
450450
LOG(info) << "Time constraint: " << (mTimeConstraint ? "ON" : "OFF");
451451
}
452452

453+
void setDecreasingLoopers(Bool_t &decreasing)
454+
{
455+
mDecreasingLoopers = decreasing;
456+
LOG(info) << "Decreasing loopers: " << (mDecreasingLoopers ? "ON" : "OFF");
457+
auto steps = Generator::getTotalNEvents();
458+
if (mDecreasingLoopers && steps > 0)
459+
{
460+
mSlopeStep = (mLoopsFraction - mSlopeMinimum) / steps;
461+
LOG(info) << "Slope step set to: " << mSlopeStep;
462+
}
463+
}
464+
453465
void setLoopsFractions(float &fraction, float &fractionPairs)
454466
{
455467
if (fraction < 0 || fraction >= 1)
@@ -560,11 +572,14 @@ class GenLoopersInjector : public Generator
560572
if (nParticles > 0)
561573
{
562574
// Calculate the number of loopers to inject adaptively
563-
short int nLoopers = static_cast<short int>(std::round((nParticles * mLoopsFraction) / (1 - mLoopsFractionPairs)));
575+
short int nLoopers = static_cast<short int>(std::round((nParticles * mLoopsFraction) / (1 - mLoopsFraction)));
564576
short int nLoopersPairs = static_cast<short int>(std::round(nLoopers * mLoopsFractionPairs));
565577
short int nLoopersCompton = nLoopers - nLoopersPairs;
566578
mGenTPCLoopers->SetNLoopers(nLoopersPairs, nLoopersCompton);
567579
LOG(info) << "Adaptive loopers: " << nLoopers << " (pairs: " << nLoopersPairs << ", compton: " << nLoopersCompton << ")";
580+
if (mDecreasingLoopers) {
581+
mLoopsFraction = mLoopsFraction - mSlopeStep;
582+
}
568583
} else {
569584
LOG(info) << "No particles found in O2 Kinematics, no loopers will be generated";
570585
return false;
@@ -602,6 +617,9 @@ class GenLoopersInjector : public Generator
602617
float mLoopsFractionPairs = 0.08; // Fraction of loopers from Pairs
603618
Bool_t mTimeConstraint = true; // Flag to indicate if time constraint is applied
604619
double mTimeConstraintValue = 0.0; // Time constraint value, adaptively set based on the maximum time of the main generator events
620+
Bool_t mDecreasingLoopers = false; // Flag to indicate if decreasing loopers are used
621+
float mSlopeMinimum = 0.02; // Fraction of loopers to be injected adaptively
622+
float mSlopeStep = 0.01; // Step of decreasing slope
605623
};
606624

607625
} // namespace eventgen
@@ -684,7 +702,7 @@ FairGenerator *
684702
// Loopers are considered adaptive by default, meaning that the number of loopers is determined by the number of particles in the kinematics file per event
685703
FairGenerator *
686704
GeneratorLoopersInjector(std::string kineFileName = "genevents_Kine.root", std::string model_pairs = "tpcloopmodel.onnx", std::string model_compton = "tpcloopmodelcompton.onnx",
687-
std::string scaler_pair = "scaler_pair.json", std::string scaler_compton = "scaler_compton.json", bool time_constraint = true, float loopers_fraction = 0.05, float fraction_pairs = 0.08)
705+
std::string scaler_pair = "scaler_pair.json", std::string scaler_compton = "scaler_compton.json", bool time_constraint = false, bool decreasing_loopers = true, float loopers_fraction = 0.05, float fraction_pairs = 0.08)
688706
{
689707
// Expand all environment paths
690708
model_pairs = gSystem->ExpandPathName(model_pairs.c_str());
@@ -780,5 +798,7 @@ GeneratorLoopersInjector(std::string kineFileName = "genevents_Kine.root", std::
780798
}
781799
// Set adaptive time constraint flag
782800
generator->setTimeConstraint(time_constraint);
801+
// set decreasing loopers distribution
802+
generator->setDecreasingLoopers(decreasing_loopers);
783803
return generator;
784804
}

0 commit comments

Comments
 (0)