Skip to content

Commit 7b93900

Browse files
committed
Fixing dependencies, wrong syntax and missing variables/functions
1 parent e603313 commit 7b93900

File tree

1 file changed

+185
-14
lines changed

1 file changed

+185
-14
lines changed

PWGLF/Tasks/Strangeness/lambdaInvMassTest.cxx

Lines changed: 185 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ struct lambdaInvMassTest{
138138
// Configurable<float> minInvMass{"minInvMass", 0.7f, "Lower bound of invariant mass axis"};
139139
// Configurable<float> maxInvMass{"maxInvMass", 1.3f, "Upper bound of invariant mass axis"};
140140
// From David's code:
141-
ConfigurableAxis axisLambdaMass{"axisLambdaMass", {200, 1.101f, 1.131f}, ""};
141+
// ConfigurableAxis axisLambdaMass{"axisLambdaMass", {200, 1.101f, 1.131f}, ""};
142142

143143
// Defining a configurable object group for the event selections:
144144
struct : ConfigurableGroup {
@@ -189,6 +189,8 @@ struct lambdaInvMassTest{
189189
Configurable<bool> useSPDTrackletsCent{"useSPDTrackletsCent", false, "Use SPD tracklets for estimating centrality? If not, use V0M-based centrality (Run 2 only)"};
190190
} eventSelections;
191191

192+
static constexpr float DefaultLifetimeCuts[1][2] = {{30., 20.}};
193+
192194
// Defining the configurable object that is going to be used: v0Selections, for selections later on
193195
struct : ConfigurableGroup {
194196
std::string prefix = "v0Selections"; // JSON group name
@@ -241,22 +243,34 @@ struct lambdaInvMassTest{
241243
Configurable<float> maxDeltaTimePion{"maxDeltaTimePion", 1e+9, "check maximum allowed time"};
242244
} v0Selections;
243245

244-
// Machine learning evaluation for pre-selection and corresponding information generation
245-
// o2::ml::OnnxModel mlCustomModelK0Short;
246+
TF1* fPhiCutLow = new TF1("fPhiCutLow", v0Selections.phiLowCut.value.data(), 0, 100);
247+
TF1* fPhiCutHigh = new TF1("fPhiCutHigh", v0Selections.phiHighCut.value.data(), 0, 100);
248+
249+
struct : ConfigurableGroup {
250+
std::string prefix = "rctConfigurations"; // JSON group name
251+
Configurable<std::string> cfgRCTLabel{"cfgRCTLabel", "", "Which detector condition requirements? (CBT, CBT_hadronPID, CBT_electronPID, CBT_calo, CBT_muon, CBT_muon_glo)"};
252+
Configurable<bool> cfgCheckZDC{"cfgCheckZDC", false, "Include ZDC flags in the bit selection (for Pb-Pb only)"};
253+
Configurable<bool> cfgTreatLimitedAcceptanceAsBad{"cfgTreatLimitedAcceptanceAsBad", false, "reject all events where the detectors relevant for the specified Runlist are flagged as LimitedAcceptance"};
254+
} rctConfigurations;
255+
256+
RCTFlagsChecker rctFlagsChecker{rctConfigurations.cfgRCTLabel.value};
257+
258+
// Machine learning evaluation for pre-selection and corresponding information generation
259+
o2::ml::OnnxModel mlCustomModelK0Short;
246260
o2::ml::OnnxModel mlCustomModelLambda;
247261
o2::ml::OnnxModel mlCustomModelAntiLambda;
248262
o2::ml::OnnxModel mlCustomModelGamma;
249263

250-
struct : ConfigurableGroup {
264+
struct : ConfigurableGroup { // Kept the original configurable scores for K0Short and all else due to the line "if (lambdaScore > mlConfigurations.thresholdK0Short.value) (...)"
251265
std::string prefix = "mlConfigurations"; // JSON group name
252266
// ML classifiers: master flags to control whether we should use custom ML classifiers or the scores in the derived data
253-
// Configurable<bool> useK0ShortScores{"useK0ShortScores", false, "use ML scores to select K0Short"};
267+
Configurable<bool> useK0ShortScores{"useK0ShortScores", false, "use ML scores to select K0Short"};
254268
Configurable<bool> useLambdaScores{"useLambdaScores", false, "use ML scores to select Lambda"};
255-
// Configurable<bool> useAntiLambdaScores{"useAntiLambdaScores", false, "use ML scores to select AntiLambda"};
269+
Configurable<bool> useAntiLambdaScores{"useAntiLambdaScores", false, "use ML scores to select AntiLambda"};
256270

257-
// Configurable<bool> calculateK0ShortScores{"calculateK0ShortScores", false, "calculate K0Short ML scores"};
271+
Configurable<bool> calculateK0ShortScores{"calculateK0ShortScores", false, "calculate K0Short ML scores"};
258272
Configurable<bool> calculateLambdaScores{"calculateLambdaScores", false, "calculate Lambda ML scores"};
259-
// Configurable<bool> calculateAntiLambdaScores{"calculateAntiLambdaScores", false, "calculate AntiLambda ML scores"};
273+
Configurable<bool> calculateAntiLambdaScores{"calculateAntiLambdaScores", false, "calculate AntiLambda ML scores"};
260274

261275
// ML input for ML calculation
262276
Configurable<std::string> customModelPathCCDB{"customModelPathCCDB", "", "Custom ML Model path in CCDB"};
@@ -266,13 +280,13 @@ struct lambdaInvMassTest{
266280

267281
// Local paths for test purposes
268282
Configurable<std::string> localModelPathLambda{"localModelPathLambda", "Lambda_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
269-
// Configurable<std::string> localModelPathAntiLambda{"localModelPathAntiLambda", "AntiLambda_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
270-
// Configurable<std::string> localModelPathK0Short{"localModelPathK0Short", "KZeroShort_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
283+
Configurable<std::string> localModelPathAntiLambda{"localModelPathAntiLambda", "AntiLambda_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
284+
Configurable<std::string> localModelPathK0Short{"localModelPathK0Short", "KZeroShort_BDTModel.onnx", "(std::string) Path to the local .onnx file."};
271285

272286
// Thresholds for choosing to populate V0Cores tables with pre-selections
273287
Configurable<float> thresholdLambda{"thresholdLambda", -1.0f, "Threshold to keep Lambda candidates"};
274-
// Configurable<float> thresholdAntiLambda{"thresholdAntiLambda", -1.0f, "Threshold to keep AntiLambda candidates"};
275-
// Configurable<float> thresholdK0Short{"thresholdK0Short", -1.0f, "Threshold to keep K0Short candidates"};
288+
Configurable<float> thresholdAntiLambda{"thresholdAntiLambda", -1.0f, "Threshold to keep AntiLambda candidates"};
289+
Configurable<float> thresholdK0Short{"thresholdK0Short", -1.0f, "Threshold to keep K0Short candidates"};
276290
} mlConfigurations;
277291

278292
// CCDB options
@@ -290,6 +304,14 @@ struct lambdaInvMassTest{
290304
Configurable<float> customMagField{"customMagField", 5.0f, "Manually set magnetic field"};
291305
} ccdbConfigurations;
292306

307+
o2::ccdb::CcdbApi ccdbApi;
308+
Service<o2::ccdb::BasicCCDBManager> ccdb;
309+
ctpRateFetcher rateFetcher;
310+
int mRunNumber;
311+
float magField;
312+
std::map<std::string, std::string> metadata;
313+
o2::parameters::GRPMagField* grpmag = nullptr;
314+
293315
// CCDB options
294316
struct : ConfigurableGroup {
295317
ConfigurableAxis axisPt{"axisPt", {VARIABLE_WIDTH, 0.0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1.0f, 1.1f, 1.2f, 1.3f, 1.4f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.2f, 2.4f, 2.6f, 2.8f, 3.0f, 3.2f, 3.4f, 3.6f, 3.8f, 4.0f, 4.4f, 4.8f, 5.2f, 5.6f, 6.0f, 6.5f, 7.0f, 7.5f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 17.0f, 19.0f, 21.0f, 23.0f, 25.0f, 30.0f, 35.0f, 40.0f, 50.0f}, "pt axis for analysis"};
@@ -345,6 +367,18 @@ struct lambdaInvMassTest{
345367
ConfigurableAxis axisMonteCarloNch{"axisMonteCarloNch", {300, 0.0f, 3000.0f}, "N_{ch} MC"};
346368
} axisConfigurations;
347369

370+
// These will not be used, but the variables were needed for some cut David did:
371+
// UPC selections
372+
SGSelector sgSelector;
373+
struct : ConfigurableGroup {
374+
std::string prefix = "upcCuts"; // JSON group name
375+
Configurable<float> fv0Cut{"fv0Cut", 100., "FV0A threshold"};
376+
Configurable<float> ft0Acut{"ft0Acut", 200., "FT0A threshold"};
377+
Configurable<float> ft0Ccut{"ft0Ccut", 100., "FT0C threshold"};
378+
Configurable<float> zdcCut{"zdcCut", 10., "ZDC threshold"};
379+
// Configurable<float> gapSel{"gapSel", 2, "Gap selection"};
380+
} upcCuts;
381+
348382

349383
// For manual sliceBy
350384
// Preslice<soa::Join<aod::StraCollisions, aod::StraCents, aod::StraEvSels, aod::StraCollLabels>> perMcCollision = aod::v0data::straMCCollisionId;
@@ -421,11 +455,11 @@ struct lambdaInvMassTest{
421455
// histos.add("eventCounter", "eventCounter", kTH1F, {axisCounter});
422456
// // histos.add("LambdaInvMass1D", "Test LambdaInvMass 1D", kTH1F, {axisLambdaMass});
423457
histos.add("hMassLambda", "hMassLambda", kTH1D, {axisConfigurations.axisLambdaMass});
424-
histos.add("ptQAHist", "ptQAHist", kTH1F, {axisPtQA});
458+
// histos.add("ptQAHist", "ptQAHist", kTH1F, {axisPtQA});
425459

426460
// From the analyseLambda flag:
427461
histos.add("h2dNbrOfLambdaVsCentrality", "h2dNbrOfLambdaVsCentrality", kTH2D, {axisConfigurations.axisCentrality, {10, -0.5f, 9.5f}});
428-
histos.add("h3dMassLambda", "h3dMassLambda", kTH3D, {axisConfigurations.axisCentrality, axisConfigurations.axisPtQA, axisConfigurations.axisLambdaMass});
462+
histos.add("h3dMassLambda", "h3dMassLambda", kTH3D, {axisConfigurations.axisCentrality, axisConfigurations.axisPt, axisConfigurations.axisLambdaMass});
429463
// Non-UPC info
430464
histos.add("h3dMassLambdaHadronic", "h3dMassLambdaHadronic", kTH3D, {axisConfigurations.axisCentrality, axisConfigurations.axisPt, axisConfigurations.axisLambdaMass});
431465
// Not doing ultra-peripheral!
@@ -502,6 +536,32 @@ struct lambdaInvMassTest{
502536
}
503537
}
504538

539+
double computePhiMod(double phi, int sign)
540+
// Compute phi wrt to a TPC sector
541+
// Calculation taken from CF: https://github.com/AliceO2Group/O2Physics/blob/376392cb87349886a300c75fa2492b50b7f46725/PWGCF/Flow/Tasks/flowAnalysisGF.cxx#L470
542+
{
543+
if (magField < 0) // for negative polarity field
544+
phi = o2::constants::math::TwoPI - phi;
545+
if (sign < 0) // for negative charge
546+
phi = o2::constants::math::TwoPI - phi;
547+
if (phi < 0)
548+
LOGF(warning, "phi < 0: %g", phi);
549+
550+
phi += o2::constants::math::PI / 18.0; // to center gap in the middle
551+
return fmod(phi, o2::constants::math::PI / 9.0);
552+
}
553+
554+
bool isTrackFarFromTPCBoundary(double trackPt, double trackPhi, int sign)
555+
// check whether the track passes close to a TPC sector boundary
556+
{
557+
double phiModn = computePhiMod(trackPhi, sign);
558+
if (phiModn > fPhiCutHigh->Eval(trackPt))
559+
return true; // keep track
560+
if (phiModn < fPhiCutLow->Eval(trackPt))
561+
return true; // keep track
562+
return false; // reject track
563+
}
564+
505565
template <typename TV0, typename TCollision>
506566
// uint64_t computeReconstructionBitmap(TV0 v0, TCollision collision, float rapidityLambda, float rapidityK0Short, float /*pT*/)
507567
uint64_t computeReconstructionBitmap(TV0 v0, TCollision collision, float rapidityLambda, float /*pT*/)
@@ -614,6 +674,117 @@ struct lambdaInvMassTest{
614674
return bitMap;
615675
}
616676

677+
bool verifyMask(uint64_t bitmap, uint64_t mask)
678+
{
679+
return (bitmap & mask) == mask;
680+
}
681+
682+
int computeITSclusBitmap(uint8_t itsClusMap, bool fromAfterburner)
683+
// Focus on the 12 dominant ITS cluster configurations
684+
{
685+
int bitMap = 0;
686+
687+
if (verifyMask(itsClusMap, ((uint8_t(1) << 0) | (uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
688+
// ITS : IB OB
689+
// ITS : L0 L1 L2 L3 L4 L5 L6
690+
// ITS : x x x x x x x
691+
bitMap = 12;
692+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
693+
// ITS : IB OB
694+
// ITS : L0 L1 L2 L3 L4 L5 L6
695+
// ITS : x x x x x x
696+
bitMap = 11;
697+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
698+
// ITS : IB OB
699+
// ITS : L0 L1 L2 L3 L4 L5 L6
700+
// ITS : x x x x x
701+
bitMap = 10;
702+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
703+
// ITS : IB OB
704+
// ITS : L0 L1 L2 L3 L4 L5 L6
705+
// ITS : x x x x
706+
bitMap = 9;
707+
if (fromAfterburner)
708+
bitMap = -3;
709+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 4) | (uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
710+
// ITS : IB OB
711+
// ITS : L0 L1 L2 L3 L4 L5 L6
712+
// ITS : x x x
713+
bitMap = 8;
714+
if (fromAfterburner)
715+
bitMap = -2;
716+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 5) | (uint8_t(1) << 6)))) {
717+
// ITS : IB OB
718+
// ITS : L0 L1 L2 L3 L4 L5 L6
719+
// ITS : x x
720+
bitMap = 7;
721+
if (fromAfterburner)
722+
bitMap = -1;
723+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 0) | (uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5)))) {
724+
// ITS : IB OB
725+
// ITS : L0 L1 L2 L3 L4 L5 L6
726+
// ITS : x x x x x x
727+
bitMap = 6;
728+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5)))) {
729+
// ITS : IB OB
730+
// ITS : L0 L1 L2 L3 L4 L5 L6
731+
// ITS : x x x x x
732+
bitMap = 5;
733+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4) | (uint8_t(1) << 5)))) {
734+
// ITS : IB OB
735+
// ITS : L0 L1 L2 L3 L4 L5 L6
736+
// ITS : x x x x
737+
bitMap = 4;
738+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 0) | (uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4)))) {
739+
// ITS : IB OB
740+
// ITS : L0 L1 L2 L3 L4 L5 L6
741+
// ITS : x x x x x
742+
bitMap = 3;
743+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3) | (uint8_t(1) << 4)))) {
744+
// ITS : IB OB
745+
// ITS : L0 L1 L2 L3 L4 L5 L6
746+
// ITS : x x x x
747+
bitMap = 2;
748+
} else if (verifyMask(itsClusMap, ((uint8_t(1) << 0) | (uint8_t(1) << 1) | (uint8_t(1) << 2) | (uint8_t(1) << 3)))) {
749+
// ITS : IB OB
750+
// ITS : L0 L1 L2 L3 L4 L5 L6
751+
// ITS : x x x x
752+
bitMap = 1;
753+
} else {
754+
// ITS : other configurations
755+
bitMap = 0;
756+
}
757+
758+
return bitMap;
759+
}
760+
761+
uint computeDetBitmap(uint8_t detMap)
762+
// Focus on the 4 dominant track configurations :
763+
// Others
764+
// ITS-TPC
765+
// ITS-TPC-TRD
766+
// ITS-TPC-TOF
767+
// ITS-TPC-TRD-TOF
768+
{
769+
uint bitMap = 0;
770+
771+
if (verifyMask(detMap, (o2::aod::track::ITS | o2::aod::track::TPC | o2::aod::track::TRD | o2::aod::track::TOF))) {
772+
// ITS-TPC-TRD-TOF
773+
bitMap = 4;
774+
} else if (verifyMask(detMap, (o2::aod::track::ITS | o2::aod::track::TPC | o2::aod::track::TOF))) {
775+
// ITS-TPC-TOF
776+
bitMap = 3;
777+
} else if (verifyMask(detMap, (o2::aod::track::ITS | o2::aod::track::TPC | o2::aod::track::TRD))) {
778+
// ITS-TPC-TRD
779+
bitMap = 2;
780+
} else if (verifyMask(detMap, (o2::aod::track::ITS | o2::aod::track::TPC))) {
781+
// ITS-TPC
782+
bitMap = 1;
783+
}
784+
785+
return bitMap;
786+
}
787+
617788
// function to load models for ML-based classifiers
618789
void loadMachines(int64_t timeStampML)
619790
{

0 commit comments

Comments
 (0)