@@ -86,11 +86,23 @@ struct F0phiproxy {
8686 Configurable<float > trackEtaMax{" trackEtaMax" , 0 .8f , " Maximum track |eta|" };
8787 Configurable<bool > requireGlobalTrack{" requireGlobalTrack" , true , " Require global track selection" };
8888 Configurable<bool > requirePVContributor{" requirePVContributor" , true , " Require PV contributor" };
89- Configurable<float > pionTPC{" pionTPC" , 3 .f , " Pion TPC nSigma cut" };
90- Configurable<float > pionTOF{" pionTOF" , 3 .f , " Pion TOF veto when matched" };
91- Configurable<float > kaonTPC{" kaonTPC" , 3 .f , " Kaon TPC nSigma cut" };
92- Configurable<float > kaonTOF{" kaonTOF" , 3 .f , " Kaon TOF veto when matched" };
93- Configurable<bool > requireTOF{" requireTOF" , false , " Require TOF for both species instead of veto-only" };
89+ Configurable<float > pionTPC{" pionTPC" , 3 .f , " Pion TPC base/fallback cut; also the matched TPC cap except in uncapped radial mode" };
90+ Configurable<float > pionTOF{" pionTOF" , 3 .f , " Pion rectangular TOF cut in modes 0, 1 and 2; radial modes use pionCombined" };
91+ Configurable<float > kaonTPC{" kaonTPC" , 3 .f , " Kaon TPC base/fallback cut; also the matched TPC cap except in uncapped radial mode" };
92+ Configurable<float > kaonTOF{" kaonTOF" , 3 .f , " Kaon rectangular TOF cut in modes 0, 1 and 2; radial modes use kaonCombined" };
93+ Configurable<bool > requireTOF{" requireTOF" , false , " Legacy PID mode 0 only: require TOF rather than use a conditional veto" };
94+ Configurable<int > pionPIDMode{" pionPIDMode" , 0 , " 0=legacy requireTOF, 1=TPC+TOF veto, 2=TPC+TOF required, 3=TPC only, 4=radial TOF veto, 5=radial veto with TPC cap" };
95+ Configurable<int > kaonPIDMode{" kaonPIDMode" , 0 , " 0=legacy requireTOF, 1=TPC+TOF veto, 2=TPC+TOF required, 3=TPC only, 4=radial TOF veto, 5=radial veto with TPC cap" };
96+ Configurable<float > pionCombined{" pionCombined" , 3 .f , " Pion sqrt(nSigmaTPC^2+nSigmaTOF^2) cut in radial modes" };
97+ Configurable<float > kaonCombined{" kaonCombined" , 3 .f , " Kaon sqrt(nSigmaTPC^2+nSigmaTOF^2) cut in radial modes" };
98+ Configurable<float > pionTPCWithTOF{" pionTPCWithTOF" , -1 .f , " Matched pion TPC cut; -1 inherits pionTPC or momentum profile; unused in TPC-only and uncapped radial modes" };
99+ Configurable<float > kaonTPCWithTOF{" kaonTPCWithTOF" , -1 .f , " Matched kaon TPC cut; -1 inherits kaonTPC or momentum profile; unused in TPC-only and uncapped radial modes" };
100+ Configurable<std::vector<float >> pionTPCMomentumEdges{" pionTPCMomentumEdges" , std::vector<float >{}, " Optional increasing total track p boundaries (GeV/c), not pT" };
101+ Configurable<std::vector<float >> pionTPCMomentumCuts{" pionTPCMomentumCuts" , std::vector<float >{}, " Pion TPC cuts in total-p intervals; one more cut than edges; empty uses pionTPC" };
102+ Configurable<std::vector<float >> kaonTPCMomentumEdges{" kaonTPCMomentumEdges" , std::vector<float >{}, " Optional increasing total track p boundaries (GeV/c), not pT" };
103+ Configurable<std::vector<float >> kaonTPCMomentumCuts{" kaonTPCMomentumCuts" , std::vector<float >{}, " Kaon TPC cuts in total-p intervals; one more cut than edges; empty uses kaonTPC" };
104+ Configurable<bool > pionRejectKaonCompatible{" pionRejectKaonCompatible" , false , " Optional reflection control: reject a pion if it also passes the configured kaon PID before overlap vetoes" };
105+ Configurable<bool > kaonRejectPionCompatible{" kaonRejectPionCompatible" , false , " Optional reflection control: reject a kaon if it also passes the configured pion PID before overlap vetoes" };
94106 Configurable<float > dipionYMax{" dipionYMax" , 0 .5f , " Maximum dipion |y|" };
95107 Configurable<float > proxyYMax{" proxyYMax" , 0 .5f , " Maximum proxy+bachelor and standard-control |y|" };
96108 Configurable<float > dipionMassMin{" dipionMassMin" , 0 .6f , " Lower dipion mass for proxy construction" };
@@ -107,6 +119,7 @@ struct F0phiproxy {
107119 Configurable<bool > enableCompactProxy{" enableCompactProxy" , true , " Proxy maps retaining mass, pT, dipion mass, grouped multiplicity, charges and TOF" };
108120 Configurable<bool > enableFullProxySparse{" enableFullProxySparse" , false , " Diagnostic 7D maps including multiplicity, bachelor charge and TOF; expensive to merge" };
109121 Configurable<bool > enablePidQA{" enablePidQA" , false , " Book/fill the four PID QA histograms" };
122+ Configurable<bool > enablePidSelectionQA{" enablePidSelectionQA" , false , " Joint before/after PID, selected marginals and decision overlap; enable once per shared track sample" };
110123 Configurable<int > multiplicityBins{" multiplicityBins" , 100 , " Multiplicity bins in dipion/control and full diagnostic maps; identical settings required for merging" };
111124 Configurable<int > proxyDipionMassBins{" proxyDipionMassBins" , 300 , " Dipion mass bins in compact proxy maps; default preserves original 5 MeV resolution" };
112125 ConfigurableAxis proxyMultiplicityAxis{" proxyMultiplicityAxis" , {0 ., 0 ., 20 ., 50 ., 200 ., 1000000 .}, " Compact proxy NPV intervals; first zero selects variable-width bins" };
@@ -136,6 +149,105 @@ struct F0phiproxy {
136149 int resolvedF0Code = 0 ;
137150 std::vector<double > ft0mEdges{};
138151
152+ // BEGIN PID selection helpers: also compiled verbatim by the standalone regression test.
153+ enum class PIDMode : int {
154+ Legacy = 0 ,
155+ TPCWithTOFVeto = 1 ,
156+ TPCWithTOFRequired = 2 ,
157+ TPCOnly = 3 ,
158+ RadialWithTPCFallback = 4 ,
159+ RadialWithTPCCap = 5
160+ };
161+ struct PIDSelection {
162+ int mode = 0 ;
163+ float tpc = 3 .f;
164+ float tof = 3 .f;
165+ float combined = 3 .f;
166+ float tpcWithTOF = -1 .f;
167+ bool requireTOF = false ;
168+ std::vector<float > momentumEdges{};
169+ std::vector<float > momentumCuts{};
170+ };
171+
172+ static void validatePID (PIDSelection const & selection)
173+ {
174+ auto positive = [](float value) { return std::isfinite (value) && value > 0 .f ; };
175+ if (selection.mode < static_cast <int >(PIDMode::Legacy) || selection.mode > static_cast <int >(PIDMode::RadialWithTPCCap) ||
176+ !positive (selection.tpc ) || !positive (selection.tof ) || !positive (selection.combined ) ||
177+ (selection.tpcWithTOF != -1 .f && !positive (selection.tpcWithTOF ))) {
178+ throw std::runtime_error (" Invalid PID mode or nSigma threshold" );
179+ }
180+ if (!selection.momentumEdges .empty () || !selection.momentumCuts .empty ()) {
181+ if (selection.momentumCuts .size () != selection.momentumEdges .size () + 1 ||
182+ !std::all_of (selection.momentumEdges .begin (), selection.momentumEdges .end (), positive) ||
183+ !std::all_of (selection.momentumCuts .begin (), selection.momentumCuts .end (), positive) ||
184+ std::adjacent_find (selection.momentumEdges .begin (), selection.momentumEdges .end (), [](float a, float b) { return a >= b; }) != selection.momentumEdges .end ()) {
185+ throw std::runtime_error (" Invalid total-momentum PID profile: increasing positive edges and one more positive cut are required" );
186+ }
187+ }
188+ }
189+
190+ static PIDMode resolvedPIDMode (PIDSelection const & selection)
191+ {
192+ const auto mode = static_cast <PIDMode>(selection.mode );
193+ return mode == PIDMode::Legacy ? (selection.requireTOF ? PIDMode::TPCWithTOFRequired : PIDMode::TPCWithTOFVeto) : mode;
194+ }
195+
196+ static float tpcPIDThreshold (PIDSelection const & selection, bool useMatchedCut, float momentum)
197+ {
198+ if (useMatchedCut && selection.tpcWithTOF > 0 .f ) {
199+ return selection.tpcWithTOF ;
200+ }
201+ if (selection.momentumCuts .empty ()) {
202+ return selection.tpc ;
203+ }
204+ if (!std::isfinite (momentum) || momentum < 0 .f ) {
205+ return std::numeric_limits<float >::quiet_NaN ();
206+ }
207+ const auto interval = static_cast <size_t >(std::upper_bound (selection.momentumEdges .begin (), selection.momentumEdges .end (), momentum) - selection.momentumEdges .begin ());
208+ return selection.momentumCuts [interval];
209+ }
210+
211+ static bool acceptPID (PIDSelection const & selection, float tpc, float tof, bool matched, float momentum)
212+ {
213+ if (!std::isfinite (tpc)) {
214+ return false ;
215+ }
216+ const auto mode = resolvedPIDMode (selection);
217+ if (mode == PIDMode::TPCWithTOFRequired && !matched) {
218+ return false ;
219+ }
220+ if (mode == PIDMode::TPCOnly) {
221+ return std::abs (tpc) < tpcPIDThreshold (selection, false , momentum);
222+ }
223+ if (mode == PIDMode::RadialWithTPCFallback && matched) {
224+ // This ALICE alternative deliberately has no separate TPC cap for matched tracks.
225+ return std::isfinite (tof) && static_cast <double >(tpc) * tpc + static_cast <double >(tof) * tof < static_cast <double >(selection.combined ) * selection.combined ;
226+ }
227+ if (!(std::abs (tpc) < tpcPIDThreshold (selection, matched, momentum))) {
228+ return false ;
229+ }
230+ if (!matched) {
231+ return mode == PIDMode::TPCWithTOFVeto || mode == PIDMode::RadialWithTPCFallback || mode == PIDMode::RadialWithTPCCap;
232+ }
233+ if (!std::isfinite (tof)) {
234+ return false ;
235+ }
236+ if (mode == PIDMode::RadialWithTPCCap) {
237+ // November-9 K* note: TPC cap AND radial cut; unmatched tracks use TPC only.
238+ return static_cast <double >(tpc) * tpc + static_cast <double >(tof) * tof < static_cast <double >(selection.combined ) * selection.combined ;
239+ }
240+ return (mode == PIDMode::TPCWithTOFVeto || mode == PIDMode::TPCWithTOFRequired) && std::abs (tof) < selection.tof ;
241+ }
242+
243+ static std::pair<bool , bool > resolvePIDOverlap (bool pionPass, bool kaonPass, bool rejectKaonCompatiblePion, bool rejectPionCompatibleKaon)
244+ {
245+ // Use both original decisions, so enabling both vetoes removes both ambiguous assignments.
246+ return {pionPass && !(rejectKaonCompatiblePion && kaonPass), kaonPass && !(rejectPionCompatibleKaon && pionPass)};
247+ }
248+ // END PID selection helpers.
249+ PIDSelection pionSelection{}, kaonSelection{};
250+
139251 struct TruthInfo {
140252 int64_t id = -1 ;
141253 int collisionId = -1 ;
@@ -168,6 +280,12 @@ struct F0phiproxy {
168280 std::shared_ptr<TH2 > eventStagesByActivity{}, activityVsNPV{}, activityVsVertex{}, mixPartnersByActivity{};
169281 std::array<std::shared_ptr<TH2 >, 4 > pidQA{};
170282 std::array<std::shared_ptr<TH3 >, 4 > pidQAByActivity{};
283+ // Joint maps are matched-track only; post-TPC marginals also include accepted unmatched tracks.
284+ std::array<std::array<std::shared_ptr<TH3 >, 2 >, 2 > pidSelectionJoint{};
285+ std::array<std::shared_ptr<TH2 >, 4 > pidSelectionAfter{};
286+ std::array<std::shared_ptr<TH3 >, 4 > pidSelectionAfterByActivity{};
287+ std::shared_ptr<TH3 > pidSelectionByActivity{};
288+ std::shared_ptr<TH1 > pidSelectionNonfinite{};
171289
172290 std::array<std::shared_ptr<THnSparse>, NMixClasses> dipionSpectra{};
173291 std::array<std::array<std::shared_ptr<THnSparse>, NMixClasses>, NChannels> compactProxy{}, fullProxy{};
@@ -273,6 +391,10 @@ struct F0phiproxy {
273391
274392 void init (InitContext const &)
275393 {
394+ pionSelection = {pionPIDMode.value , pionTPC.value , pionTOF.value , pionCombined.value , pionTPCWithTOF.value , requireTOF.value , pionTPCMomentumEdges.value , pionTPCMomentumCuts.value };
395+ kaonSelection = {kaonPIDMode.value , kaonTPC.value , kaonTOF.value , kaonCombined.value , kaonTPCWithTOF.value , requireTOF.value , kaonTPCMomentumEdges.value , kaonTPCMomentumCuts.value };
396+ validatePID (pionSelection);
397+ validatePID (kaonSelection);
276398 if (doprocess && doprocessMCReco) {
277399 throw std::runtime_error (" Enable either process (data) or processMCReco, never both" );
278400 }
@@ -357,6 +479,42 @@ struct F0phiproxy {
357479 }
358480 }
359481 }
482+ if (enablePidSelectionQA.value ) {
483+ const AxisSpec pidPt{std::vector<double >{0 ., 0.15 , 0.3 , 0.5 , 0.8 , 1 ., 1.5 , 2 ., 3 ., 4 ., 6 ., 10 ., 20 .}, " track p_{T} (GeV/c); overflow retained" };
484+ const AxisSpec pidNSigmaTPC{60 , -6 ., 6 ., " TPC n#sigma; flow retained" };
485+ const AxisSpec pidNSigmaTOF{60 , -6 ., 6 ., " TOF n#sigma; flow retained" };
486+ const std::array<std::array<const char *, 2 >, 2 > jointNames{{{" hPionTPCvsTOFBeforePID" , " hPionTPCvsTOFAfterPID" }, {" hKaonTPCvsTOFBeforePID" , " hKaonTPCvsTOFAfterPID" }}};
487+ for (size_t species = 0 ; species < jointNames.size (); ++species) {
488+ for (size_t stage = 0 ; stage < jointNames[species].size (); ++stage) {
489+ pidSelectionJoint[species][stage] = histos.add <TH3 >(recoName (jointNames[species][stage]).c_str (), stage == 0 ? " Matched quality tracks with finite TPC/TOF, before species PID" : " Matched accepted tracks with finite TPC/TOF, after species PID" , HistType::kTH3F , {pidPt, pidNSigmaTPC, pidNSigmaTOF});
490+ pidSelectionJoint[species][stage]->Sumw2 ();
491+ }
492+ }
493+ const std::array<const char *, 4 > afterNames{" hPionTPCAfterPID" , " hPionTOFAfterPID" , " hKaonTPCAfterPID" , " hKaonTOFAfterPID" };
494+ for (size_t index = 0 ; index < afterNames.size (); ++index) {
495+ const AxisSpec& response = index % 2 == 0 ? pidNSigmaTPC : pidNSigmaTOF;
496+ pidSelectionAfter[index] = histos.add <TH2 >(recoName (afterNames[index]).c_str (), " After final species PID; TPC all accepted, TOF matched accepted;track pT;nSigma" , HistType::kTH2F , {pidPt, response});
497+ pidSelectionAfter[index]->Sumw2 ();
498+ if (useFT0M.value ) {
499+ const std::string name = std::string (afterNames[index]).append (" ByMultiplicity" );
500+ pidSelectionAfterByActivity[index] = histos.add <TH3 >(recoName (name).c_str (), " After final species PID; TPC all accepted, TOF matched accepted" , HistType::kTH3F , {pidPt, response, compactMult});
501+ pidSelectionAfterByActivity[index]->Sumw2 ();
502+ }
503+ }
504+ const AxisSpec selectionStage{7 , -0.5 , 6.5 , " PID decision category (not exclusive)" };
505+ pidSelectionByActivity = histos.add <TH3 >(recoName (" hPIDSelectionByActivity" ).c_str (), " Track-level PID decisions;track pT;activity;decision category" , HistType::kTH3D , {pidPt, compactMult, selectionStage});
506+ pidSelectionByActivity->Sumw2 ();
507+ const std::array<const char *, 7 > selectionNames{" Quality" , " TOF matched" , " Pion accepted (final)" , " Kaon accepted (final)" , " Both accepted (final)" , " Neither accepted (final)" , " Both accepted before ambiguity veto" };
508+ for (size_t index = 0 ; index < selectionNames.size (); ++index) {
509+ pidSelectionByActivity->GetZaxis ()->SetBinLabel (static_cast <int >(index + 1 ), selectionNames[index]);
510+ }
511+ pidSelectionNonfinite = histos.add <TH1 >(recoName (" hPIDSelectionNonfinite" ).c_str (), " Nonfinite responses excluded from numerical PID QA;response;Tracks" , HistType::kTH1D , {{5 , -0.5 , 4.5 }});
512+ pidSelectionNonfinite->Sumw2 ();
513+ const std::array<const char *, 5 > nonfiniteNames{" Track pT" , " Pion TPC" , " Pion TOF (matched)" , " Kaon TPC" , " Kaon TOF (matched)" };
514+ for (size_t index = 0 ; index < nonfiniteNames.size (); ++index) {
515+ pidSelectionNonfinite->GetXaxis ()->SetBinLabel (static_cast <int >(index + 1 ), nonfiniteNames[index]);
516+ }
517+ }
360518 const std::array<const char *, NMixClasses> dipionNames{" hDipionSE" , " hDipionME" };
361519 for (size_t mix = 0 ; mix < dipionNames.size (); ++mix) {
362520 if (mix != 0 && !mixingEnabled ()) {
@@ -392,6 +550,74 @@ struct F0phiproxy {
392550 }
393551 }
394552
553+ void fillPIDSelectionQA (float trackPt, float activity, bool matched,
554+ float pionTPCValue, float pionTOFValue, float kaonTPCValue, float kaonTOFValue,
555+ bool pionPIDAccepted, bool kaonPIDAccepted, bool pionAccepted, bool kaonAccepted)
556+ {
557+ if (!enablePidSelectionQA.value ) {
558+ return ;
559+ }
560+ if (!std::isfinite (trackPt)) {
561+ pidSelectionNonfinite->Fill (0 .);
562+ return ;
563+ }
564+ pidSelectionByActivity->Fill (trackPt, activity, 0 .);
565+ if (matched) {
566+ pidSelectionByActivity->Fill (trackPt, activity, 1 .);
567+ }
568+ if (pionAccepted) {
569+ pidSelectionByActivity->Fill (trackPt, activity, 2 .);
570+ }
571+ if (kaonAccepted) {
572+ pidSelectionByActivity->Fill (trackPt, activity, 3 .);
573+ }
574+ if (pionAccepted && kaonAccepted) {
575+ pidSelectionByActivity->Fill (trackPt, activity, 4 .);
576+ }
577+ if (!pionAccepted && !kaonAccepted) {
578+ pidSelectionByActivity->Fill (trackPt, activity, 5 .);
579+ }
580+ if (pionPIDAccepted && kaonPIDAccepted) {
581+ pidSelectionByActivity->Fill (trackPt, activity, 6 .);
582+ }
583+ const std::array<float , 2 > tpcValues{pionTPCValue, kaonTPCValue};
584+ const std::array<float , 2 > tofValues{pionTOFValue, kaonTOFValue};
585+ const std::array<bool , 2 > accepted{pionAccepted, kaonAccepted};
586+ for (size_t species = 0 ; species < accepted.size (); ++species) {
587+ const bool finiteTPC = std::isfinite (tpcValues[species]);
588+ const bool finiteTOF = matched && std::isfinite (tofValues[species]);
589+ const size_t tpcIndex = 2 * species;
590+ const size_t tofIndex = tpcIndex + 1 ;
591+ if (!finiteTPC) {
592+ pidSelectionNonfinite->Fill (static_cast <double >(tpcIndex + 1 ));
593+ }
594+ if (matched && !finiteTOF) {
595+ pidSelectionNonfinite->Fill (static_cast <double >(tofIndex + 1 ));
596+ }
597+ if (finiteTPC && finiteTOF) {
598+ pidSelectionJoint[species][0 ]->Fill (trackPt, tpcValues[species], tofValues[species]);
599+ if (accepted[species]) {
600+ pidSelectionJoint[species][1 ]->Fill (trackPt, tpcValues[species], tofValues[species]);
601+ }
602+ }
603+ if (!accepted[species]) {
604+ continue ;
605+ }
606+ auto fillAfter = [&](size_t index, float value) {
607+ pidSelectionAfter[index]->Fill (trackPt, value);
608+ if (pidSelectionAfterByActivity[index]) {
609+ pidSelectionAfterByActivity[index]->Fill (trackPt, value, activity);
610+ }
611+ };
612+ if (finiteTPC) {
613+ fillAfter (tpcIndex, tpcValues[species]);
614+ }
615+ if (finiteTOF) {
616+ fillAfter (tofIndex, tofValues[species]);
617+ }
618+ }
619+ }
620+
395621 void bookMC ()
396622 {
397623 const AxisSpec pt{100 , 0 ., 10 ., " pair pT (GeV/c)" };
@@ -448,11 +674,6 @@ struct F0phiproxy {
448674 }
449675 }
450676
451- bool passPID (float tpc, float tof, bool matched, float tpcCut, float tofCut) const
452- {
453- return std::isfinite (tpc) && std::abs (tpc) < tpcCut && (!requireTOF.value || matched) &&
454- (!matched || (std::isfinite (tof) && std::abs (tof) < tofCut));
455- }
456677 static int chargeCategory (int a, int b) { return a != b ? 0 : (a > 0 ? 1 : 2 ); }
457678 static FourVector constituent (FourVector const & dipion)
458679 {
@@ -701,10 +922,17 @@ struct F0phiproxy {
701922 if constexpr (IsMC) {
702923 candidate.truth = trackTruth (track, collision.mcCollisionId ());
703924 }
704- if (passPID (track.tpcNSigmaPi (), track.tofNSigmaPi (), tof, pionTPC.value , pionTOF.value )) {
925+ const float momentum = track.p ();
926+ const bool pionPIDAccepted = acceptPID (pionSelection, track.tpcNSigmaPi (), track.tofNSigmaPi (), tof, momentum);
927+ const bool kaonPIDAccepted = acceptPID (kaonSelection, track.tpcNSigmaKa (), track.tofNSigmaKa (), tof, momentum);
928+ const auto accepted = resolvePIDOverlap (pionPIDAccepted, kaonPIDAccepted, pionRejectKaonCompatible.value , kaonRejectPionCompatible.value );
929+ const bool pionAccepted = accepted.first ;
930+ const bool kaonAccepted = accepted.second ;
931+ fillPIDSelectionQA (track.pt (), mult, tof, track.tpcNSigmaPi (), track.tofNSigmaPi (), track.tpcNSigmaKa (), track.tofNSigmaKa (), pionPIDAccepted, kaonPIDAccepted, pionAccepted, kaonAccepted);
932+ if (pionAccepted) {
705933 event.pions .push_back (candidate);
706934 }
707- if (passPID (track. tpcNSigmaKa (), track. tofNSigmaKa (), tof, kaonTPC. value , kaonTOF. value ) ) {
935+ if (kaonAccepted ) {
708936 event.kaons .push_back (candidate);
709937 }
710938 }
0 commit comments