Skip to content

Commit d319f15

Browse files
authored
[PWGCF] Update femto framework (#14612)
1 parent 0fdf7a1 commit d319f15

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

PWGCF/Femto/Core/closePairRejection.h

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include "Framework/HistogramSpec.h"
2626

2727
#include <array>
28+
#include <chrono>
2829
#include <cmath>
2930
#include <cstddef>
3031
#include <map>
3132
#include <numeric>
33+
#include <random>
3234
#include <string>
3335
#include <vector>
3436

@@ -68,6 +70,7 @@ struct ConfCpr : o2::framework::ConfigurableGroup {
6870
o2::framework::Configurable<float> kinematicMax{"kinematicMax", -1.f, "Maximum kstar/Q3 of pair/triplet for plotting (Set to negative value to turn off the cut)"};
6971
o2::framework::ConfigurableAxis binningDeta{"binningDeta", {{250, -0.5, 0.5}}, "deta"};
7072
o2::framework::ConfigurableAxis binningDphistar{"binningDphistar", {{250, -0.5, 0.5}}, "dphi"};
73+
o2::framework::Configurable<int> seed{"seed", -1, "Seed to randomize particle 1 and particle 2. Set to negative value to deactivate. Set to 0 to generate unique seed in time."};
7174
};
7275

7376
constexpr const char PrefixCprTrackTrack[] = "CprTrackTrack";
@@ -174,6 +177,17 @@ class CloseTrackRejection
174177
mPlotAverage = confCpr.plotAverage.value;
175178
mPlotAllRadii = confCpr.plotAllRadii.value;
176179

180+
if (confCpr.seed.value >= 0) {
181+
uint64_t randomSeed;
182+
mRandomizeTracks = true;
183+
if (confCpr.seed.value == 0) {
184+
randomSeed = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
185+
} else {
186+
randomSeed = static_cast<uint64_t>(confCpr.seed.value);
187+
}
188+
mRng = std::mt19937(randomSeed);
189+
}
190+
177191
// check if we need to apply any cut a plot is requested
178192
mIsActivated = mCutAverage || mCutAnyRadius || mPlotAverage || mPlotAllRadii;
179193

@@ -210,11 +224,19 @@ class CloseTrackRejection
210224
mDphistar.fill(0.f);
211225
mDphistarMask.fill(false);
212226

213-
mDeta = track1.eta() - track2.eta();
227+
bool swapTracks = false;
228+
if (mRandomizeTracks) {
229+
swapTracks = (mSwapDist(mRng) == 1);
230+
}
231+
232+
auto const& t1 = swapTracks ? track2 : track1;
233+
auto const& t2 = swapTracks ? track1 : track2;
234+
235+
mDeta = t1.eta() - t2.eta();
214236

215237
for (size_t i = 0; i < TpcRadii.size(); i++) {
216-
auto phistar1 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack1 * track1.signedPt(), track1.phi());
217-
auto phistar2 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack2 * track2.signedPt(), track2.phi());
238+
auto phistar1 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack1 * t1.signedPt(), t1.phi());
239+
auto phistar2 = phistar(mMagField, TpcRadii[i], mChargeAbsTrack2 * t2.signedPt(), t2.phi());
218240
if (phistar1 && phistar2) {
219241
mDphistar.at(i) = RecoDecay::constrainAngle(phistar1.value() - phistar2.value(), -o2::constants::math::PI); // constrain angular difference between -pi and pi
220242
mDphistarMask.at(i) = true;
@@ -342,6 +364,10 @@ class CloseTrackRejection
342364
float mDeta = 0.f;
343365
std::array<float, Nradii> mDphistar = {0.f};
344366
std::array<bool, Nradii> mDphistarMask = {false};
367+
368+
bool mRandomizeTracks = false;
369+
std::mt19937 mRng;
370+
std::uniform_int_distribution<int> mSwapDist{0, 1};
345371
};
346372

347373
template <const char* prefix>

0 commit comments

Comments
 (0)