CbmRoot
Loading...
Searching...
No Matches
KfpV0FinderCutter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
11
12#include "KFParticleFinder.h"
13
14#include <iomanip>
15#include <set>
16#include <sstream>
17
21
22// ---------------------------------------------------------------------------------------------------------------------
23//
24template<EV0Type V0Type>
25V0FinderCutter<V0Type>::V0FinderCutter(const std::string& filename)
26 : fCuts(cbm::algo::yaml::ReadFromFile<CutValues>(filename))
27{
28 fCuts.Init();
29}
30
31// ---------------------------------------------------------------------------------------------------------------------
32//
33template<EV0Type V0Type>
34void V0FinderCutter<V0Type>::ApplyCutsToKFParticleFinder(KFParticleFinder* pFinder) const
35{
36 const auto& cuts = fCuts.kfpFinderCuts;
37 pFinder->SetChiPrimaryCut2D(cuts.maxChi2NdfPrim);
38 pFinder->SetLdLCut2D(cuts.minDecayLDL);
39 pFinder->SetLCut(cuts.minDecayLength);
40 pFinder->SetChi2Cut2D(cuts.maxChi2NdfGeo);
41}
42
43// ---------------------------------------------------------------------------------------------------------------------
44//
45template<EV0Type V0Type>
46void V0FinderCutter<V0Type>::ReadCutsFromYaml(const std::string& filename)
47{
49 fCuts.Init();
50}
51
52// ---------------------------------------------------------------------------------------------------------------------
53//
54template<EV0Type V0Type>
56{
57 constexpr auto SelectDaughter = [](const DaughterProperty& pr, const DaughterCuts& cut) constexpr->bool
58 {
59 if (pr.beta < cut.beta[0] || pr.beta > cut.beta[1]) return false;
60 if (pr.dcaRelToOrigin < cut.dcaRelToOrigin[0] || pr.dcaRelToOrigin > cut.dcaRelToOrigin[1]) return false;
61 return true;
62 };
63
64 const auto& cuts = fCuts.particleCuts;
65 if (!SelectDaughter(property.daughterA, cuts.daughterA)) return false;
66 if (!SelectDaughter(property.daughterB, cuts.daughterB)) return false;
67 if (property.dcaRelToPrimVertex > cuts.maxDcaRelToPrimVertex) return false;
68 if (property.dcaBetweenDaughters > cuts.maxDcaBetweenDaughters) return false;
69 if (property.decayLength < cuts.decayLength[0] || property.decayLength > cuts.decayLength[1]) return false;
70 if (property.daughterVtxZ < cuts.daughterVtxZ[0] || property.daughterVtxZ > cuts.daughterVtxZ[1]) return false;
71 if (property.openingAngle < cuts.minOpeningAngle) return false;
72 if (property.chi2NdfTopo < cuts.chi2NdfTopo[0] || property.chi2NdfTopo > cuts.chi2NdfTopo[1]) return false;
73 if (property.chi2NdfGeo < cuts.chi2NdfGeo[0] || property.chi2NdfGeo > cuts.chi2NdfGeo[1]) return false;
74
75 return true;
76}
77
78// ---------------------------------------------------------------------------------------------------------------------
79//
80template<EV0Type V0Type>
82{
83 // Check, if track has a defined PID
84 if (property.pid == ETrackPid::Undef) return false;
85
86 // Check, if DCA was defined (NOTE: equivalent to the previous cut, but only with TopoPid)
87 // (a) undefined => less then two STS hits
88 if (std::isnan(property.dcaRelToOrigin)) return false;
89
90 // Beta physical cuts
91 // (a) undefined => no TOF hits
92 // (b) < 0 or > 1 => miscalibration of TOF/BMON
93 if (std::isnan(property.beta) || property.beta <= 0 || property.beta >= 1) return false;
94
95 // Other cuts (depending on PID)
96 const auto& cuts = fCuts.trackCuts;
97
98 // Track selection depending on the PDG
99 // (a) track beta
100 auto Check = [&property, &cuts](ETrackPid trackPid) constexpr->bool
101 {
102 const auto& pidCuts = cuts.pidCuts[static_cast<size_t>(trackPid)];
103 if (property.beta < pidCuts.beta[0] || property.beta > pidCuts.beta[1]) return false;
104 return true;
105 };
106
107 if (!Check(property.pid)) return false;
108
109 return true;
110}
111
112// ---------------------------------------------------------------------------------------------------------------------
113//
114template<EV0Type V0Type>
116{
117 // Apply validity check here (maybe)
118 fCuts = cuts;
119 fCuts.Init();
120}
121
122// ---------------------------------------------------------------------------------------------------------------------
123//
124template<EV0Type V0Type>
126{
127 using std::setw;
128 std::stringstream msg;
129
130 std::string sV0{};
131 std::string sDaughterA{};
132 std::string sDaughterB{};
133 switch (V0Type) {
134 case EV0Type::Lambda:
135 sV0 = "Lambda";
136 sDaughterA = "pi-";
137 sDaughterB = "p";
138 break;
139 }
140
141 auto PrintTrackPidCuts = [&](int iPid) {
142 const auto& cuts = fCuts.trackCuts.pidCuts[iPid];
143 msg << "\n\t" << cbm::algo::kfp::ToString(static_cast<ETrackPid>(iPid)) << ':';
144 msg << "\n\t\tbeta: " << setw(12) << cuts.beta[0] << " -- " << setw(12) << cuts.beta[1];
145 };
146
147 msg << "======= V0-finder selector for " << sV0 << " -> " << sDaughterA << " + " << sDaughterB;
148
149 msg << "\nTRACK PRE-SELECTION CUTS:";
150 for (int iPid = 0; iPid < static_cast<int>(ETrackPid::Undef) + 1; ++iPid) {
151 PrintTrackPidCuts(iPid);
152 }
153
154 const auto& kfpFinderCuts = fCuts.kfpFinderCuts;
155 msg << "\nKFP-FINDER INTRINSIC CUTS:";
156 msg << "\n\tmin. decay length [cm]: " << setw(12) << kfpFinderCuts.minDecayLength;
157 msg << "\n\tmin. l / dl: " << setw(12) << kfpFinderCuts.minDecayLDL;
158 msg << "\n\tmax chi2/NDF primary: " << setw(12) << kfpFinderCuts.maxChi2NdfPrim;
159 msg << "\n\tmax chi2/NDF geo: " << setw(12) << kfpFinderCuts.maxChi2NdfGeo;
160
161 auto PrintDaughterCuts = [&](const DaughterCuts& cuts) {
162 msg << "\n\t\tDCA rel. to origin: [cm]" << setw(12) << cuts.dcaRelToOrigin[0] << " -- " << setw(12)
163 << cuts.dcaRelToOrigin[1];
164 msg << "\n\t\tbeta: " << setw(12) << cuts.beta[0] << " -- " << setw(12) << cuts.beta[1];
165 };
166
167 const auto& prtCuts = fCuts.particleCuts;
168 msg << "\nV0 SELECTION CUTS:";
169 msg << "\n\t" << sDaughterA << ':';
170 PrintDaughterCuts(prtCuts.daughterA);
171 msg << "\n\t" << sDaughterB << ':';
172 PrintDaughterCuts(prtCuts.daughterB);
173 msg << "\n\tmax DCA rel. to primary vertex [cm]: " << prtCuts.maxDcaRelToPrimVertex;
174 msg << "\n\tmax DCA between daughters [cm]: " << prtCuts.maxDcaBetweenDaughters;
175 msg << "\n\tdecay length [cm]: " << prtCuts.decayLength[0] << " -- " << prtCuts.decayLength[1];
176 msg << "\n\tdaughter z-vertex [cm]: " << prtCuts.daughterVtxZ[0] << " -- " << prtCuts.daughterVtxZ[1];
177 msg << "\n\tmin opening angle [radians]: " << prtCuts.minOpeningAngle;
178 msg << "\n\tchi2/NDF topology: " << prtCuts.chi2NdfTopo[0] << " -- " << prtCuts.chi2NdfTopo[1];
179 msg << "\n\tchi2/NDF geo: " << prtCuts.chi2NdfGeo[0] << " -- " << prtCuts.chi2NdfGeo[1];
180
181 return msg.str();
183
184// ---------------------------------------------------------------------------------------------------------------------
185//
186template<EV0Type V0Type>
188{
189 auto& trackPidCuts = trackCuts.pidCuts;
190 std::set<ETrackPid> knownPids;
191 for (const auto& entry : trackPidCuts) {
192 knownPids.insert(entry.pid);
193 }
194
195 if (knownPids.size() != static_cast<size_t>(ETrackPid::Undef) + 1) {
196 std::stringstream msg;
197 msg << "V0FinderCutter::CutValues::Init(): the node \"trackCuts/pidCuts\" must contain exactly the same amount ";
198 msg
199 << "of elements, as the ETrackPid enumerator. Each element must have a unique pid value. The pid values, which ";
200 msg << "were read from the parameter file, are: ";
201 for (const auto& p : knownPids) {
202 msg << cbm::algo::kfp::ToString(p) << ' ';
203 }
204 throw std::runtime_error(msg.str());
206
207 std::sort(trackPidCuts.begin(), trackPidCuts.end(), [](const auto& lhs, const auto& rhs) {
208 return static_cast<size_t>(lhs.pid) < static_cast<size_t>(rhs.pid);
209 });
210}
211
A selector class for V0-candidates in mCBM.
V0FinderCutter()=default
Default constructor.
A collection of cuts for V0 production analysis in mCBM.
void ReadCutsFromYaml(const std::string &filename)
Reads parameters from the YAML config.
CutValues fCuts
Cut values of the analysis.
void ApplyCutsToKFParticleFinder(KFParticleFinder *pFinder) const
Applies cuts to the KFParticleFinder instance.
bool SelectParticle(const ParticleProperty &particleProperty) const
Selects a particle within the cuts (after the KFParticleFinder stage)
bool SelectTrack(const TrackProperty &trackProperty) const
Selects a track (to pass it to the KFParticleFinder stage)
std::string ToString() const
String representation of the class.
void SetCuts(const CutValues &cuts)
Sets the cuts.
std::string ToString(ETrackPid trackPid)
String representation of ETrackPid.
ETrackPid
An enumeration for PID of global tracks.
EV0Type
Type of V0 decay.
T ReadFromFile(fs::path path)
Definition CbmYaml.h:66
void Init()
A method, which initializes the instance of the CutValues.
TrackCuts trackCuts
Cuts on tracks at pre-selection stage.
double dcaRelToOrigin
Distance of closest approach relative to origin [cm].
Properties of a track to perform track pre-selection.
ETrackPid pid
Identity of the particle.
double dcaRelToOrigin
Distanse of closest approach relative to origin [cm].