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{
37
40 class V0FinderTask : public FairTask {
41 public:
44 enum class ECounter : uint8_t
45 {
46 TracksTotal, //< Total number of tracks
47 TracksSelected, //< Tracks, which satisfy topology PID applicability
48 TracksInfiniteParam, //< Tracks, which have infinite parameters
49 TracksWoTofHits, //< Tracks, which have no TOF hits
50 TracksWNegativeTofHitTime, //< Tracks, the last TOF hit of which has a negative time (it's time is less then the t0)
51 TracksWoStsHits, //< Tracks, which have no STS hits
52 TracksWoPid, //< Tracks, which has undefined PID
53 TracksWoMomentum, //< Tracks, which has undefined PID
54 TracksWAtLeastOneTofHit, //< Tracks with at least one tof hit
55 TracksWAtLeastTwoTofHits, //< Tracks with at least two tof hits
56 TracksWithUnphysicalBeta, //< Tracks with beta > 1
57 TracksW2Sts2Tof, //< Tracks with at least two STS hits and two TOF hits
58 Pions, //< Number of pion-candidates
59 Protons, //< Number of proton-candidates
60 EventsTotal, //< Total number of events
61 EventsWoTzero, //< Number of events with undefined t-zero
62 EventsLambdaCand, //< Events with at least one pion and one proton candidate
63 KfpEventsLambdaCand, //< Events with lambda-candidates in KF-particle
64 KfpLambdaCandidates, //< Number of lambda-candidates
65 END
66 };
67
70 enum class EPidApproach : uint8_t
71 {
72 Topo, //< Topological PID (DCA calculation for a track)
73 Mc //< MC-truth PID
74 };
75
78 enum class EProcessingMode : uint8_t
79 {
80 TimeBased, //< Time based simulation or real data
81 EventBased //< Event based simulation
82 };
83
86 enum class EPvUsageMode : uint8_t
87 {
88 Target, //< Use target center as a primary vertex
89 Reconstructed, //< Use reconstructed primary vertex
90 ReconstructSingle, //< Reconstruct a single PV from given track vectors
91 ReconstructMultiple, //< Reconstruct multiple PVs (in case of pile-up)
92 Mc //< Use MC-true primary vertex
93 };
94
97 struct QpAndBeta {
98 double fQp{std::numeric_limits<double>::signaling_NaN()};
99 double fQpVar{std::numeric_limits<double>::signaling_NaN()};
100 double fBeta{std::numeric_limits<double>::signaling_NaN()};
101 double fBetaVar{std::numeric_limits<double>::signaling_NaN()};
102 };
103
106 struct DcaVector {
107 double fAbs{std::numeric_limits<double>::signaling_NaN()};
108 double fX{std::numeric_limits<double>::signaling_NaN()};
109 double fY{std::numeric_limits<double>::signaling_NaN()};
110 };
111
114 explicit V0FinderTask(int verbose = 1) : FairTask("V0FinderTask", verbose){};
115
117 ~V0FinderTask() = default;
118
119 // Eliminate copy and move
120 V0FinderTask(const V0FinderTask&) = delete;
124
125
126 //* FairTask overriden methods
127
129 void Exec(Option_t*) override;
130
132 void Finish() override;
133
135 InitStatus Init() override;
136
137
138 //* Accessors
139
141 KFParticleFinder* GetKFParticleFinder() { return fpTopoReconstructorRun->GetKFParticleFinder(); }
142
144 const KFParticleFinder* GetKFParticleFinder() const { return fpTopoReconstructorRun->GetKFParticleFinder(); }
145
147 const auto& GetTrackDcaToOrigin() const { return fvTrackDca; }
148
150 const std::shared_ptr<const KFParticleTopoReconstructor> GetTopoReconstructor() const
151 {
153 }
154
156 const std::vector<DcaVector>& GetTrackDca() { return fvTrackDca; }
157
158 //* Task logic and preliminary selection cut setters
159
162 void SetConfigName(const TString& fileName) { fsConfigName = fileName; }
163
166
169
172
174 void SetUseMc(bool bUseMc) { fbUseMc = bUseMc; }
175
177 void SetRunQa(bool bRunQa) { fbRunQa = bRunQa; }
178
182 void SetPionVelocityRange(double vMin, double vMax)
183 {
186 }
187
191 void SetProtonVelocityRange(double vMin, double vMax)
192 {
195 }
196
199 void SetMinPionDca(double dca) { fMinPionDca = dca; }
200
203 void SetMinProtonDca(double dca) { fMinProtonDca = dca; }
204
207 void SetQaOutputFileName(const TString& fileName) { fsQaOutputName = fileName; }
208
211 void SetQpAssignedUncertainty(double uncertainty) { fQpAssignedUncertainty = uncertainty; }
212
215 void SetTzeroOffset(double offset) { fTzeroOffset = offset; }
216
219 // NOTE: The KFParticleFinder has its internal mixed-event analysis mode, but was not used in mCBM Lambda-analysis
220 // the internal mixed-event mode can be selected using the following method:
221 // fpTopoReconstructorRun->SetMixedEventAnalysis()
222 void SetMixedEventMode(bool bMixedEvent) { fbMixedEventMode = bMixedEvent; }
223
224
225 //* KFParticleFinder setters
226
229 void AddDecayToReconstructionList(int pdg) { GetKFParticleFinder()->AddDecayToReconstructionList(pdg); }
230
233 void SetPrimaryProbCut(double pVal)
234 {
235 constexpr int Ndf{2};
237 }
238
241 void SetMaxDistanceBetweenParticlesCut(float cut) { GetKFParticleFinder()->SetMaxDistanceBetweenParticlesCut(cut); }
242
245 void SetLCut(float cut) { GetKFParticleFinder()->SetLCut(cut); }
246
249 void SetChiPrimaryCut2D(float cut) { GetKFParticleFinder()->SetChiPrimaryCut2D(cut); }
250
253 void SetChi2Cut2D(float cut) { GetKFParticleFinder()->SetChi2Cut2D(cut); }
254
257 void SetLdLCut2D(float cut) { GetKFParticleFinder()->SetLdLCut2D(cut); }
258
263 void SetSecondaryCuts(float sigmaMass, float chi2Topo, float ldl)
264 {
265 GetKFParticleFinder()->SetSecondaryCuts(sigmaMass, chi2Topo, ldl);
266 }
267
270 void SetLdLCutXiOmega(float cut) { GetKFParticleFinder()->SetLdLCutXiOmega(cut); }
271
274 void SetChi2TopoCutXiOmega(float cut) { GetKFParticleFinder()->SetChi2TopoCutXiOmega(cut); }
275
278 void SetChi2CutXiOmega(float cut) { GetKFParticleFinder()->SetChi2CutXiOmega(cut); }
279
282 void SetChi2TopoCutResonances(float cut) { GetKFParticleFinder()->SetChi2TopoCutResonances(cut); }
283
286 void SetChi2CutResonances(float cut) { GetKFParticleFinder()->SetChi2CutResonances(cut); }
287
290 void SetPtCutLMVM(float cut) { GetKFParticleFinder()->SetPtCutLMVM(cut); }
291
294 void SetPCutLMVM(float cut) { GetKFParticleFinder()->SetPCutLMVM(cut); }
295
298 void SetPtCutJPsi(float cut) { GetKFParticleFinder()->SetPtCutJPsi(cut); }
299
302 void SetPtCutCharm(float cut) { GetKFParticleFinder()->SetPtCutCharm(cut); }
303
306 void SetChiPrimaryCutCharm(float cut) { GetKFParticleFinder()->SetChiPrimaryCutCharm(cut); }
307
310 void SetLdLCutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetLdLCutCharmManybodyDecays(cut); }
311
314 void SetChi2TopoCutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetChi2TopoCutCharmManybodyDecays(cut); }
315
318 void SetChi2CutCharmManybodyDecays(float cut) { GetKFParticleFinder()->SetChi2CutCharmManybodyDecays(cut); }
319
322 void SetLdLCutCharm2D(float cut) { GetKFParticleFinder()->SetLdLCutCharm2D(cut); }
323
326 void SetChi2TopoCutCharm2D(float cut) { GetKFParticleFinder()->SetChi2TopoCutCharm2D(cut); }
327
330 void SetChi2CutCharm2D(float cut) { GetKFParticleFinder()->SetChi2CutCharm2D(cut); }
331
332
333 //* Static helper methods
334
337 static std::string ToString(EProcessingMode mode);
338
341 static std::string ToString(EPidApproach pid);
342
345 static std::string ToString(EPvUsageMode pvMode);
346
349 static std::string ToString(const FairTrackParam* pParam);
350
355 static bool CheckTrackParam(const FairTrackParam* pParam);
356
357 private:
358 //* Auxilary internal methods
359
361 void ApplyConfiguration();
362
368 bool AssignMomentum(CbmGlobalTrack* pTrack, int pdg);
369
373 DcaVector EstimateDcaToOrigin(const CbmStsTrack* pTrack) const;
374
379 QpAndBeta EstimateQp(const CbmTofHit* pTofHit, int pdg) const;
380
387 KFPTrackVector MakeKfpTrackVector(const std::vector<const CbmGlobalTrack*>& vpTracks,
388 const std::vector<int>& vTrackIds, const std::vector<float>& vChi2ToPv,
389 bool bAtFirstPoint) const;
390
395 KFVertex MakeKfpPrimaryVertex(float x, float y, float z) const;
396
401 int InferTrackPidTopo(double dca) const;
402
409 template<bool UseEvent>
410 bool ProcessEvent(const CbmEvent* pEvent);
411
427 // TODO: Replace with a functor (a function from a separate FairTask)
428 bool SelectTrack(CbmGlobalTrack* pTrack, int iTrk);
429
433 double ShiftTofHitsToTzero(const CbmEvent* pEvent);
434
436 void StoreParticles();
437
438
439 //* Task constants (To be moved to a configuration)
440 static constexpr int kPrimaryPdg{321};
441 static constexpr int kUndefPdg{-2};
442 static constexpr float kChi2PvPrimThrsh{3.};
443
444 //* Physical constants
445 static constexpr double kPionMass{0.13957039};
446 static constexpr double kProtonMass{0.938272088};
447 static constexpr double kSpeedOfLight{29.9792458};
448
449 //* Different run-time cuts and flags (TODO: define in a config)
450 double fTzeroOffset{0.};
451 double fMinPionDca{1.5};
452 double fMinProtonDca{0.5};
455 double fMinBetaProton{0.};
456 double fMaxBetaProton{1.};
457 double fMinBetaPion{0.};
458 double fMaxBetaPion{1.};
459
460 //* Input data branches
461 TClonesArray* fpBrRecoEvents{nullptr};
462 TClonesArray* fpBrGlobalTracks{nullptr};
463 TClonesArray* fpBrStsTracks{nullptr};
464 TClonesArray* fpBrTrdTracks{nullptr};
465 TClonesArray* fpBrTofTracks{nullptr};
466 TClonesArray* fpBrStsHits{nullptr};
467 TClonesArray* fpBrTrdHits{nullptr};
468 TClonesArray* fpBrTofHits{nullptr};
470
471 //* Output data branches
472 std::vector<CbmEventTriggers>* fpBrEventTriggers{nullptr}; //< Branch for event triggers
473 // TODO: in principle one can store the found KF particles and vertices as well
474
475 //* Temporary data and auxilary variables (per FairTask::Exec() call)
476 std::vector<DcaVector> fvTrackDca;
477 std::unique_ptr<CbmVertex> fpOrigin{
478 std::make_unique<CbmVertex>()};
479
480 //* KFParticleFinder utilities
482 // Main topology reconstructor
483 std::shared_ptr<KFParticleTopoReconstructor> fpTopoReconstructorRun{
484 std::make_shared<KFParticleTopoReconstructor>()};
485 std::unique_ptr<KFParticleTopoReconstructor> fpTopoReconstructorEvent{
486 std::make_unique<KFParticleTopoReconstructor>()};
487
488 //* Control flags
492 bool fbMixedEventMode{false};
493 bool fbUseMc{false};
494 bool fbRunQa{false};
496
497 //* QA and monitoring variables
499 std::unique_ptr<V0FinderQa> fpQa{nullptr};
500 TString fsQaOutputName{"./V0FinderQa.root"};
501 TString fsConfigName{""};
502
503
505 };
506} // 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 SetConfigName(const TString &fileName)
Sets name of the configuration file.
void SetChi2CutXiOmega(float cut)
Sets cut for and .
double fMinBetaPion
Minimal proton velocity (beta) [c].
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 global 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)
Sets processing mode (time-based/event-based)
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.
void ApplyConfiguration()
Applies configuration from fsConfigName.
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.
double fMaxBetaProton
Maximal proton velocity (beta) [c].
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
TString fsConfigName
Name of the config.
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 SetPionVelocityRange(double vMin, double vMax)
Sets pion velocity range.
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.
double fMaxBetaPion
Maximal proton velocity (beta) [c].
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 std::vector< DcaVector > & GetTrackDca()
Accessor to the track DCA.
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 SetProtonVelocityRange(double vMin, double vMax)
Sets proton velocity range.
void SetLdLCutXiOmega(float cut)
Sets cut for and .
double fMinBetaProton
Minimal proton velocity (beta) [c].
A vector representation of DCA to target.
double fY
Y-component of the unit-vector.
double fX
X-component of the unit-vector.