CbmRoot
Loading...
Searching...
No Matches
CbmKFV0FinderTask.h
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
10// TODO: Provide a configurator to the class
11
12#pragma once
13
14#include "CbmEnumArray.h"
15#include "CbmKFParticleFinder.h" // for the CbmKFParticleFinder::InverseChi2Prob()
16#include "CbmKFV0FinderQa.h"
17#include "CbmKFVertex.h"
18#include "CbmVertex.h"
19#include "FairTask.h"
20#include "KFParticleTopoReconstructor.h"
21
22#include <memory>
23
24class CbmEvent;
25class CbmGlobalTrack;
26class CbmStsTrack;
27class CbmTofHit;
28class TClonesArray;
29class FairTrackParam;
30class KFPTrackVector;
31class KFVertex;
32class KFParticleFinder;
34
35namespace cbm::kfp
36{
39 class V0FinderTask : public FairTask {
40 public:
43 struct QpAndBeta {
44 double fQp{std::numeric_limits<double>::signaling_NaN()};
45 double fQpVar{std::numeric_limits<double>::signaling_NaN()};
46 double fBeta{std::numeric_limits<double>::signaling_NaN()};
47 double fBetaVar{std::numeric_limits<double>::signaling_NaN()};
48 };
49
52 struct DcaVector {
53 double fAbs{std::numeric_limits<double>::signaling_NaN()};
54 double fX{std::numeric_limits<double>::signaling_NaN()};
55 double fY{std::numeric_limits<double>::signaling_NaN()};
56 };
57
60 enum class ECounter : uint8_t
61 {
62 TracksTotal, //< Total number of tracks
63 TracksSelected, //< Tracks, which satisfy topology PID applicability
64 TracksInfiniteParam, //< Tracks, which have infinite parameters
65 TracksWoTofHits, //< Tracks, which have no TOF hits
66 TracksWNegativeTofHitTime, //< Tracks, the last TOF hit of which has a negative time (it's time is less then the t0)
67 TracksWoStsHits, //< Tracks, which have no STS hits
68 TracksWoPid, //< Tracks, which has undefined PID
69 TracksWoMomentum, //< Tracks, which has undefined PID
70 TracksWAtLeastOneTofHit, //< Tracks with at least one tof hit
71 TracksWAtLeastTwoTofHits, //< Tracks with at least two tof hits
72 TracksWithUnphysicalBeta, //< Tracks with beta > 1
73 TracksW2Sts2Tof, //< Tracks with at least two STS hits and two TOF hits
74 Pions, //< Number of pion-candidates
75 Protons, //< Number of proton-candidates
76 EventsTotal, //< Total number of events
77 EventsWoTzero, //< Number of events with undefined t-zero
78 EventsLambdaCand, //< Events with at least one pion and one proton candidate
79 KfpEventsLambdaCand, //< Events with lambda-candidates in KF-particle
80 KfpLambdaCandidates, //< Number of lambda-candidates
81 END
82 };
83
86 enum class EPidApproach : uint8_t
87 {
88 Topo, //< Topological PID (DCA calculation for a track)
89 Mc //< MC-truth PID
90 };
91
94 enum class EProcessingMode : uint8_t
95 {
96 TimeBased, //< Time based simulation or real data
97 EventBased //< Event based simulation
98 };
99
102 enum class EPvUsageMode : uint8_t
103 {
104 Target, //< Use target center as a primary vertex
105 Reconstructed, //< Use reconstructed primary vertex
106 ReconstructSingle, //< Reconstruct a single PV from given track vectors
107 ReconstructMultiple, //< Reconstruct multiple PVs (in case of pile-up)
108 Mc //< Use MC-true primary vertex
109 };
110
113 explicit V0FinderTask(int verbose = 1) : FairTask("V0FinderTask", verbose){};
114
116 ~V0FinderTask() = default;
117
118 // Eliminate copy and move
119 V0FinderTask(const V0FinderTask&) = delete;
123
124
125 //* FairTask overriden methods
126
128 void Exec(Option_t*) override;
129
131 void Finish() override;
132
134 InitStatus Init() override;
135
136
137 //* Accessors
138
140 KFParticleFinder* GetKFParticleFinder() { return fpTopoReconstructorRun->GetKFParticleFinder(); }
141
143 const KFParticleFinder* GetKFParticleFinder() const { return fpTopoReconstructorRun->GetKFParticleFinder(); }
144
146 const auto& GetTrackDcaToOrigin() const { return fvTrackDca; }
147
149 const std::shared_ptr<const KFParticleTopoReconstructor> GetTopoReconstructor() const
150 {
152 }
153
155 //const
156
157 //* Task logic and preliminary selection cut setters
158
161
164
167
169 void SetUseMc(bool bUseMc) { fbUseMc = bUseMc; }
170
172 void SetRunQa(bool bRunQa) { fbRunQa = bRunQa; }
173
176 void SetMinPionDca(double dca) { fMinPionDca = dca; }
177
180 void SetMinProtonDca(double dca) { fMinProtonDca = dca; }
181
184 void SetQaOutputFileName(const TString& fileName) { fsQaOutputName = fileName; }
185
188 void SetQpAssignedUncertainty(double uncertainty) { fQpAssignedUncertainty = uncertainty; }
189
192 void SetTzeroOffset(double offset) { fTzeroOffset = offset; }
193
196 // NOTE: The KFParticleFinder has its internal mixed-event analysis mode, but was not used in mCBM Lambda-analysis
197 // the internal mixed-event mode can be selected using the following method:
198 // fpTopoReconstructorRun->SetMixedEventAnalysis()
199 void SetMixedEventMode(bool bMixedEvent) { fbMixedEventMode = bMixedEvent; }
200
201
202 //* KFParticleFinder setters
203
206 void AddDecayToReconstructionList(int pdg) { GetKFParticleFinder()->AddDecayToReconstructionList(pdg); }
207
210 void SetPrimaryProbCut(double pVal)
211 {
212 constexpr int Ndf{2};
214 }
215
218 void SetMaxDistanceBetweenParticlesCut(float cut) { GetKFParticleFinder()->SetMaxDistanceBetweenParticlesCut(cut); }
219
222 void SetLCut(float cut) { GetKFParticleFinder()->SetLCut(cut); }
223
226 void SetChiPrimaryCut2D(float cut) { GetKFParticleFinder()->SetChiPrimaryCut2D(cut); }
227
230 void SetChi2Cut2D(float cut) { GetKFParticleFinder()->SetChi2Cut2D(cut); }
231
234 void SetLdLCut2D(float cut) { GetKFParticleFinder()->SetLdLCut2D(cut); }
235
240 void SetSecondaryCuts(float sigmaMass, float chi2Topo, float ldl)
241 {
242 GetKFParticleFinder()->SetSecondaryCuts(sigmaMass, chi2Topo, ldl);
243 }
244
247 void SetLdLCutXiOmega(float cut) { GetKFParticleFinder()->SetLdLCutXiOmega(cut); }
248
251 void SetChi2TopoCutXiOmega(float cut) { GetKFParticleFinder()->SetChi2TopoCutXiOmega(cut); }
252
255 void SetChi2CutXiOmega(float cut) { GetKFParticleFinder()->SetChi2CutXiOmega(cut); }
256
259 void SetChi2TopoCutResonances(float cut) { GetKFParticleFinder()->SetChi2TopoCutResonances(cut); }
260
263 void SetChi2CutResonances(float cut) { GetKFParticleFinder()->SetChi2CutResonances(cut); }
264
267 void SetPtCutLMVM(float cut) { GetKFParticleFinder()->SetPtCutLMVM(cut); }
268
271 void SetPCutLMVM(float cut) { GetKFParticleFinder()->SetPCutLMVM(cut); }
272
275 void SetPtCutJPsi(float cut) { GetKFParticleFinder()->SetPtCutJPsi(cut); }
276
279 void SetPtCutCharm(float cut) { GetKFParticleFinder()->SetPtCutCharm(cut); }
280
283 void SetChiPrimaryCutCharm(float cut) { GetKFParticleFinder()->SetChiPrimaryCutCharm(cut); }
284
287 void SetLdLCutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetLdLCutCharmManybodyDecays(cut); }
288
291 void SetChi2TopoCutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetChi2TopoCutCharmManybodyDecays(cut); }
292
295 void SetChi2CutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetChi2CutCharmManybodyDecays(cut); }
296
299 void SetLdLCutCharm2D(float cut) { GetKFParticleFinder()->SetLdLCutCharm2D(cut); }
300
303 void SetChi2TopoCutCharm2D(float cut) { GetKFParticleFinder()->SetChi2TopoCutCharm2D(cut); }
304
307 void SetChi2CutCharm2D(float cut) { GetKFParticleFinder()->SetChi2CutCharm2D(cut); }
308
309
310 //* Static helper methods
311
314 static std::string ToString(EProcessingMode mode);
315
318 static std::string ToString(EPidApproach pid);
319
322 static std::string ToString(EPvUsageMode pvMode);
323
326 static std::string ToString(const FairTrackParam* pParam);
327
332 static bool CheckTrackParam(const FairTrackParam* pParam);
333
334 private:
335 //* Auxilary internal methods
336
342 bool AssignMomentum(CbmGlobalTrack* pTrack, int pdg);
343
347 DcaVector EstimateDcaToOrigin(const CbmStsTrack* pTrack) const;
348
353 QpAndBeta EstimateQp(const CbmTofHit* pTofHit, int pdg) const;
354
361 KFPTrackVector MakeKfpTrackVector(const std::vector<const CbmGlobalTrack*>& vpTracks,
362 const std::vector<int>& vTrackIds, const std::vector<float>& vChi2ToPv,
363 bool bAtFirstPoint) const;
364
369 KFVertex MakeKfpPrimaryVertex(float x, float y, float z) const;
370
375 int InferTrackPidTopo(double dca) const;
376
383 template<bool UseEvent>
384 bool ProcessEvent(const CbmEvent* pEvent);
385
401 // TODO: Replace with a functor (a function from a separate FairTask)
402 bool SelectTrack(CbmGlobalTrack* pTrack, int iTrk);
403
407 double ShiftTofHitsToTzero(const CbmEvent* pEvent);
408
410 void StoreParticles();
411
412
413 //* Task constants (To be moved to a configuration)
414 static constexpr int kPrimaryPdg{321};
415 static constexpr int kUndefPdg{-2};
416 static constexpr float kChi2PvPrimThrsh{3.};
417
418 //* Physical constants
419 static constexpr double kPionMass{0.13957039};
420 static constexpr double kProtonMass{0.938272088};
421 static constexpr double kSpeedOfLight{29.9792458};
422
423 //* Different run-time flags;
424 double fTzeroOffset{0.};
425 double fMinPionDca{1.5};
426 double fMinProtonDca{0.5};
429
430 //* Input data branches
431 TClonesArray* fpBrRecoEvents{nullptr};
432 TClonesArray* fpBrGlobalTracks{nullptr};
433 TClonesArray* fpBrStsTracks{nullptr};
434 TClonesArray* fpBrTrdTracks{nullptr};
435 TClonesArray* fpBrTofTracks{nullptr};
436 TClonesArray* fpBrStsHits{nullptr};
437 TClonesArray* fpBrTrdHits{nullptr};
438 TClonesArray* fpBrTofHits{nullptr};
440
441 //* Output data branches
442 std::vector<CbmEventTriggers>* fpBrEventTriggers{nullptr}; //< Branch for event triggers
443 // TODO: in principle one can store the found KF particles and vertices as well
444
445 //* Temporary data and auxilary variables (per FairTask::Exec() call)
446 std::vector<DcaVector> fvTrackDca;
447 std::unique_ptr<CbmVertex> fpOrigin{
448 std::make_unique<CbmVertex>()};
449
450 //* KFParticleFinder utilities
452 // Main topology reconstructor
453 std::shared_ptr<KFParticleTopoReconstructor> fpTopoReconstructorRun{
454 std::make_shared<KFParticleTopoReconstructor>()};
455 std::unique_ptr<KFParticleTopoReconstructor> fpTopoReconstructorEvent{
456 std::make_unique<KFParticleTopoReconstructor>()};
457
458 //* Control flags
462 bool fbMixedEventMode{false};
463 bool fbUseMc{false};
464 bool fbRunQa{false};
466
467 //* QA and monitoring variables
469 std::unique_ptr<V0FinderQa> fpQa{nullptr};
470 TString fsQaOutputName{"./V0FinderQa.root"};
471
472
474 };
475} // namespace cbm::kfp
A simple QA for the V0 finder class (runs together with the finder task)
Class to store different triggers for a given event.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
static double InversedChi2Prob(double p, int ndf)
A class to find V0 candidates in mCBM.
static constexpr float kChi2PvPrimThrsh
Chi2 threshold of assigning tracks as primaries in PV reco.
bool AssignMomentum(CbmGlobalTrack *pTrack, int pdg)
Assigns momentum to a global track.
~V0FinderTask()=default
Destructor.
void SetPrimaryProbCut(double pVal)
Sets P-value cut to the topology reconstructor.
void SetChi2CutXiOmega(float cut)
Sets cut for and .
EPvUsageMode
Primary vertex finding/handling mode.
void SetSecondaryCuts(float sigmaMass, float chi2Topo, float ldl)
Sets cuts on selection of secondary and primary candidates.
std::unique_ptr< V0FinderQa > fpQa
If QA is processed.
KFVertex MakeKfpPrimaryVertex(float x, float y, float z) const
Makes a KF vertex.
DcaVector EstimateDcaToOrigin(const CbmStsTrack *pTrack) const
Estimates distance to the origin.
void Finish() override
Action on the end of the run.
double fMinProtonDca
Minimum DCA to PV for protons.
void SetChi2TopoCutCharm2D(float cut)
Sets cut for open charm with 2 daughters.
V0FinderTask(V0FinderTask &&)=delete
static bool CheckTrackParam(const FairTrackParam *pParam)
Checks track parameter validity.
cbm::core::EnumArray< ECounter, size_t > fCounters
Counters per run.
std::vector< CbmEventTriggers > * fpBrEventTriggers
InitStatus Init() override
Initializes the task.
void SetPtCutJPsi(float cut)
Sets the cut on transverse momentum of each daughter track of .
EProcessingMode fProcessingMode
Processing mode.
void SetPvFindingMode(EPvUsageMode mode)
Sets PV finding mode.
std::vector< DcaVector > fvTrackDca
Track DCA vector [n selected tracks].
KFParticleFinder * GetKFParticleFinder()
Mutable access to the KfParticleFinder of the run topology reconstructor.
void SetChiPrimaryCutCharm(float cut)
Sets cut on of each track for open charm particles.
const auto & GetTrackDcaToOrigin() const
Gets DCA to origin.
void StoreParticles()
Stores particles, reconstructed in event to the run topology reconstructor.
void SetTzeroOffset(double offset)
Sets an offset to t0.
QpAndBeta EstimateQp(const CbmTofHit *pTofHit, int pdg) const
Estimates q/p of the track, using one TOF hit (Norbert's method)
const std::shared_ptr< const KFParticleTopoReconstructor > GetTopoReconstructor() const
Accessor to the topology reconstructor.
TString fsQaOutputName
Output QA name.
void SetQaOutputFileName(const TString &fileName)
Sets a file name for the QA.
static constexpr double kProtonMass
Proton mass [GeV/c2].
void SetProcessingMode(EProcessingMode mode)
Accessor to the track DCA.
static constexpr int kPrimaryPdg
PID hypothesis of primary tracks (kaons?)
double ShiftTofHitsToTzero(const CbmEvent *pEvent)
Shifts TOF hits to the t0 estimation.
KFPTrackVector MakeKfpTrackVector(const std::vector< const CbmGlobalTrack * > &vpTracks, const std::vector< int > &vTrackIds, const std::vector< float > &vChi2ToPv, bool bAtFirstPoint) const
Makes a KF-particle track vector.
void SetChi2TopoCutCharmManybodyDecays(float cut)
Sets cut for open charm with >=3 daughters.
static constexpr double kSpeedOfLight
Speed of light [cm/ns].
bool ProcessEvent(const CbmEvent *pEvent)
Processes one event.
void SetChiPrimaryCut2D(float cut)
Sets cut on of each track for 2-daughter decays.
void SetChi2CutCharm2D(float cut)
Sets cut for open charm with 2 daughters.
void SetUseMc(bool bUseMc)
Sets the MC flag (if MC information required)
void SetMaxDistanceBetweenParticlesCut(float cut)
Sets cut on the distance between secondary tracks at the DCA point.
bool fbUseMc
Run using MC-information.
void AddDecayToReconstructionList(int pdg)
Adds particle to reconstruction list.
void SetPtCutLMVM(float cut)
Sets the cut on transverse momentum of each daughter track of low mass vector mesons.
void SetQpAssignedUncertainty(double uncertainty)
Assignes an uncertainty to the momentum measurement.
ClassDefOverride(V0FinderTask, 0)
void SetLdLCutCharmManybodyDecays(float cut)
Sets cut for open charm with >=3 daughters.
void SetMinPionDca(double dca)
Sets minimal pion DCA to primary vertex.
void SetChi2Cut2D(float cut)
Sets cut on for 2-daughter decays.
bool SelectTrack(CbmGlobalTrack *pTrack, int iTrk)
Selects/rejects a track.
V0FinderTask & operator=(V0FinderTask &&)=delete
V0FinderTask & operator=(const V0FinderTask &)=delete
void SetMixedEventMode(bool bMixedEvent)
Special settings in the mixed-event analysis mode.
std::unique_ptr< KFParticleTopoReconstructor > fpTopoReconstructorEvent
void SetChi2TopoCutXiOmega(float cut)
Sets cut for and .
void SetChi2TopoCutResonances(float cut)
Sets cut for resonances.
void SetLCut(float cut)
Sets cut on the distance to the primary vertex from the decay vertex.
EProcessingMode
Data processing mode.
static constexpr double kPionMass
Pion mass [GeV/c2].
double fTzeroOffset
Offset for T0.
static constexpr int kUndefPdg
Undefined value, such tracks will be skipped.
int InferTrackPidTopo(double dca) const
Infers PID hypothesis for a track using track topology.
static std::string ToString(EProcessingMode mode)
String representation of processing mode.
V0FinderTask(const V0FinderTask &)=delete
TClonesArray * fpBrGlobalTracks
std::unique_ptr< CbmVertex > fpOrigin
Origin (e.g., can be either reconstructed PV or target)
void SetLdLCutCharm2D(float cut)
Sets cut for open charm with 2 daughters.
void SetPCutLMVM(float cut)
Sets the cut on momentum of each daughter track of low mass vector mesons in dimuon channel.
EPidApproach
PID approach used.
void Exec(Option_t *) override
Executes the task.
void SetPtCutCharm(float cut)
Sets the cut on transverse momentum of each daughter track of open charm particles.
std::shared_ptr< KFParticleTopoReconstructor > fpTopoReconstructorRun
Main topology reconstructor.
void SetMinProtonDca(double dca)
Sets minimal proton DCA to primary vertex.
void SetLdLCut2D(float cut)
Sets cut on for 2-daughter decays.
double fMinPionDca
Minimum DCA to PV for pions.
const KFParticleFinder * GetKFParticleFinder() const
Constant access to the KfParticleFinder of the run topology reconstructor.
double fQpAssignedUncertainty
Assigned relative uncertainty for q/p estimation.
EPvUsageMode fPvUsageMode
Primary vertex mode.
V0FinderTask(int verbose=1)
Constructor.
void SetChi2CutCharmManybodyDecays(float cut)
Sets cut for open charm with >=3 daughters.
bool fbMixedEventMode
Run in a mix-event mode.
void SetRunQa(bool bRunQa)
Sets the flag: if the QA should be executed.
EPidApproach fPidApproach
PID approach used.
int fPrimaryAssignedPdg
Assigned PDG hypothesis for primary particles.
void SetPidApproach(EPidApproach pid)
Sets PID approach.
void SetChi2CutResonances(float cut)
Sets cut for resonances.
void SetLdLCutXiOmega(float cut)
Sets cut for and .
A vector representation of DCA to target.
double fY
Y-component of the unit-vector.
double fX
X-component of the unit-vector.