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 "CbmKFVertex.h"
17#include "CbmVertex.h"
18#include "FairTask.h"
19#include "KFParticle/KFParticleTopoReconstructor.h"
22
23#include <memory>
24
25class CbmEvent;
26class CbmGlobalTrack;
27class CbmStsTrack;
28class CbmTofHit;
29class TClonesArray;
30class FairTrackParam;
31class KFPTrackVector;
32class KFVertex;
33class KFParticleFinder;
35
36
37namespace cbm::kfp
38{
39 using namespace cbm::algo::kfp;
40
43 class V0FinderTask : public FairTask {
44 public:
46
49 enum class ECounter : uint8_t
50 {
51 TracksTotal, //< Total number of tracks
52 TracksSelected, //< Tracks, which satisfy topology PID applicability
53 TracksInfiniteParam, //< Tracks, which have infinite parameters
54 TracksWoTofHits, //< Tracks, which have no TOF hits
55 TracksWNegativeTofHitTime, //< Tracks, the last TOF hit of which has a negative time (it's time is less then the t0)
56 TracksWoStsHits, //< Tracks, which have no STS hits
57 TracksWoPid, //< Tracks, which has undefined PID
58 TracksWoMomentum, //< Tracks, which has undefined PID
59 TracksWAtLeastOneTofHit, //< Tracks with at least one tof hit
60 TracksWAtLeastTwoTofHits, //< Tracks with at least two tof hits
61 TracksWithUnphysicalBeta, //< Tracks with beta > 1
62 TracksW2Sts2Tof, //< Tracks with at least two STS hits and two TOF hits
63 Pions, //< Number of pion-candidates
64 Protons, //< Number of proton-candidates
65 EventsTotal, //< Total number of events
66 EventsWoTzero, //< Number of events with undefined t-zero
67 EventsLambdaCand, //< Events with at least one pion and one proton candidate
68 KfpEventsLambdaCand, //< Events with lambda-candidates in KF-particle
69 KfpLambdaCandidates, //< Number of lambda-candidates
71 };
72
75 enum class EPidApproach : uint8_t
76 {
77 Topo, //< Topological PID (DCA calculation for a track)
78 Mc //< MC-truth PID
79 };
80
83 enum class EProcessingMode : uint8_t
84 {
85 TimeBased, //< Time based simulation or real data
86 EventBased //< Event based simulation
87 };
88
91 enum class EPvUsageMode : uint8_t
92 {
93 Target, //< Use target center as a primary vertex
94 Reconstructed, //< Use reconstructed primary vertex
95 ReconstructSingle, //< Reconstruct a single PV from given track vectors
96 ReconstructMultiple, //< Reconstruct multiple PVs (in case of pile-up)
97 Mc //< Use MC-true primary vertex
98 };
99
102 struct DcaVector {
103 double fAbs{std::numeric_limits<double>::quiet_NaN()};
104 double fX{std::numeric_limits<double>::quiet_NaN()};
105 double fY{std::numeric_limits<double>::quiet_NaN()};
106 };
107
110 struct TrackInfo {
111 double dca{std::numeric_limits<double>::quiet_NaN()};
112 double beta{std::numeric_limits<double>::quiet_NaN()};
113 const CbmTofHit* pTofHit{nullptr};
114 };
115
119 double dca{std::numeric_limits<double>::quiet_NaN()};
120 double beta{std::numeric_limits<double>::quiet_NaN()};
121 const CbmTofHit* pTofHit{nullptr};
122 int32_t eventID{-1};
123 };
124
127 explicit V0FinderTask(int verbose = 1) : FairTask("V0FinderTask", verbose){};
128
130 ~V0FinderTask() = default;
131
132 // Eliminate copy and move
133 V0FinderTask(const V0FinderTask&) = delete;
137
138
139 //* FairTask overriden methods
140
142 void Exec(Option_t*) override;
143
145 void Finish() override;
146
148 InitStatus Init() override;
149
150
151 //* Accessors
152
154 KFParticleFinder* GetKFParticleFinder() { return fpTopoReconstructorTs->GetKFParticleFinder(); }
155
157 const KFParticleFinder* GetKFParticleFinder() const { return fpTopoReconstructorTs->GetKFParticleFinder(); }
158
160 const auto& GetTrackDcaToOrigin() const { return fvTrackDca; }
161
163 std::shared_ptr<const KFParticleTopoReconstructor> GetTopoReconstructor() const { return fpTopoReconstructorTs; }
164
166 std::shared_ptr<const Cutter_t> GetCutter() const { return fpCutter; }
167
169 const std::vector<DcaVector>& GetTrackDca() const { return fvTrackDca; }
170
174 const std::vector<TrackInfo>& GetTrackInfo() const { return fvTrackInfo; }
175
179 const std::vector<ParticleInfo>& GetParticleInfo() const { return fvParticleInfo; }
180
181 //* Task logic and preliminary selection cut setters
182
185 void SetConfigName(const TString& fileName) { fsConfigName = fileName; }
186
189 void SetCutsConfigName(const TString& fileName) { fsCutsConfigName = fileName; }
190
193
196
199
201 void SetUseMc(bool bUseMc) { fbUseMc = bUseMc; }
202
205 void SetMinPionDca(double dca) { fMinPionDca = dca; }
206
209 void SetMinProtonDca(double dca) { fMinProtonDca = dca; }
210
213 void SetQaOutputFileName(const TString& fileName) { fsQaOutputName = fileName; }
214
217 void SetQpAssignedUncertainty(double uncertainty) { fQpAssignedUncertainty = uncertainty; }
218
221 void SetTzeroOffset(double offset) { fTzeroOffset = offset; }
222
225 // NOTE: The KFParticleFinder has its internal mixed-event analysis mode, but was not used in mCBM Lambda-analysis
226 // the internal mixed-event mode can be selected using the following method:
227 // fpTopoReconstructorTs->SetMixedEventAnalysis()
228 void SetMixedEventMode(bool bMixedEvent) { fbMixedEventMode = bMixedEvent; }
229
230
231 //* KFParticleFinder setters
232
235 void AddDecayToReconstructionList(int pdg) { GetKFParticleFinder()->AddDecayToReconstructionList(pdg); }
236
237 //* Static helper methods
238
241 static std::string ToString(EProcessingMode mode);
242
245 static std::string ToString(EPidApproach pid);
246
249 static std::string ToString(EPvUsageMode pvMode);
250
253 static std::string ToString(const FairTrackParam* pParam);
254
259 static bool CheckTrackParam(const FairTrackParam* pParam);
260
261 private:
262 //* Auxilary internal methods
263
265 void ApplyConfiguration();
266
271 template<int PdgCode>
272 void AssignMomentum(CbmGlobalTrack* pTrack, double beta);
273
278 void AssignMomentum(CbmGlobalTrack* pTrack, double qp, double qpVar);
279
283 DcaVector EstimateDcaToOrigin(const CbmStsTrack* pTrack) const;
284
289 double EstimateBeta(const CbmTofHit* pTofHit) const;
290
294 TrackInfo CollectTrackInfo(const CbmGlobalTrack* pTrack) const;
295
302 KFPTrackVector MakeKfpTrackVector(const std::vector<const CbmGlobalTrack*>& vpTracks,
303 const std::vector<int>& vTrackIds, const std::vector<float>& vChi2ToPv,
304 bool bAtFirstPoint) const;
305
310 KFVertex MakeKfpPrimaryVertex(float x, float y, float z) const;
311
316
323 template<bool UseEvent>
324 bool ProcessEvent(const CbmEvent* pEvent);
325
329 double ShiftTofHitsToTzero(const CbmEvent* pEvent);
330
334 void StoreParticles(const CbmEvent* pEvent);
335
336 public:
337 //* Task constants (To be moved to a configuration)
338 static constexpr int kPrimaryPdg{321};
339 static constexpr int kUndefPdg{-2};
340 static constexpr float kChi2PvPrimThrsh{3.};
341
342 //* Physical constants
343 static constexpr double kPionMass{0.13957039};
344 static constexpr double kProtonMass{0.938272088};
345 static constexpr double kSpeedOfLight{29.9792458};
346
347 private:
348 //* Different run-time cuts and flags
349 double fTzeroOffset{0.};
350 double fMinPionDca{1.5};
351 double fMinProtonDca{0.5};
354 double fMinBetaProton{0.};
355 double fMaxBetaProton{1.};
356 double fMinBetaPion{0.};
357 double fMaxBetaPion{1.};
358
359 //* Cutter
360 std::shared_ptr<Cutter_t> fpCutter{std::make_shared<Cutter_t>()};
361
362 //* Input data branches
363 TClonesArray* fpBrRecoEvents{nullptr};
364 TClonesArray* fpBrGlobalTracks{nullptr};
365 TClonesArray* fpBrStsTracks{nullptr};
366 TClonesArray* fpBrTrdTracks{nullptr};
367 TClonesArray* fpBrTofTracks{nullptr};
368 TClonesArray* fpBrStsHits{nullptr};
369 TClonesArray* fpBrTrdHits{nullptr};
370 TClonesArray* fpBrTofHits{nullptr};
372
373 //* Output data branches
374 std::vector<CbmEventTriggers>* fpBrEventTriggers{nullptr}; //< Branch for event triggers
375 // TODO: in principle one can store the found KF particles and vertices as well
376
377 //* Temporary data and auxilary variables (per FairTask::Exec() call)
378 std::vector<DcaVector> fvTrackDca;
379 std::vector<TrackInfo> fvTrackInfo;
380 std::vector<ParticleInfo> fvParticleInfo;
381 std::unique_ptr<CbmVertex> fpOrigin{
382 std::make_unique<CbmVertex>()};
383
384 //* KFParticleFinder utilities
386 // Main topology reconstructor
387 std::shared_ptr<KFParticleTopoReconstructor> fpTopoReconstructorTs{std::make_shared<KFParticleTopoReconstructor>()};
388 std::unique_ptr<KFParticleTopoReconstructor> fpTopoReconstructorEvent{
389 std::make_unique<KFParticleTopoReconstructor>()};
390
391 //* Control flags
395 bool fbMixedEventMode{false};
396 bool fbUseMc{false};
398
399 //* QA and monitoring variables
401 TString fsQaOutputName{"./V0FinderQa.root"};
402 TString fsConfigName{""};
403 TString fsCutsConfigName{""};
404
405
407 };
408} // namespace cbm::kfp
A selector class for V0-candidates in mCBM.
Different definitions for V0 candidates finding in mCBM.
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
A collection of cuts for V0 production analysis in mCBM.
static constexpr float kChi2PvPrimThrsh
Chi2 threshold of assigning tracks as primaries in PV reco.
~V0FinderTask()=default
Destructor.
void SetConfigName(const TString &fileName)
Sets name of the configuration file.
double fMinBetaPion
Minimal proton velocity (beta) [c].
EPvUsageMode
Primary vertex finding/handling mode.
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.
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
std::shared_ptr< KFParticleTopoReconstructor > fpTopoReconstructorTs
Main topology reconstructor.
InitStatus Init() override
Initializes the task.
TString fsCutsConfigName
Name of the config.
EProcessingMode fProcessingMode
Processing mode.
void SetPvFindingMode(EPvUsageMode mode)
Sets PV finding mode.
std::vector< DcaVector > fvTrackDca
Track DCA vector [n global tracks].
cbm::algo::kfp::ETrackPid InferTrackPidTopo(double dca) const
Infers PID hypothesis for a track using track topology.
KFParticleFinder * GetKFParticleFinder()
Mutable access to the KfParticleFinder of the run topology reconstructor.
TrackInfo CollectTrackInfo(const CbmGlobalTrack *pTrack) const
Fill track extra info.
const auto & GetTrackDcaToOrigin() const
Gets DCA to origin.
void SetTzeroOffset(double offset)
Sets an offset to t0.
void StoreParticles(const CbmEvent *pEvent)
Stores particles, reconstructed in event to the run 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.
const std::vector< TrackInfo > & GetTrackInfo() const
Accessor to the track extra info.
std::shared_ptr< const Cutter_t > GetCutter() const
Accessor to the cutter.
void AssignMomentum(CbmGlobalTrack *pTrack, double beta)
Assigns momentum to a global track.
static constexpr double kSpeedOfLight
Speed of light [cm/ns].
std::shared_ptr< Cutter_t > fpCutter
void SetUseMc(bool bUseMc)
Sets the MC flag (if MC information required)
void ApplyConfiguration()
Applies configuration from fsConfigName.
bool fbUseMc
Run using MC-information.
void AddDecayToReconstructionList(int pdg)
Adds particle to reconstruction list.
double fMaxBetaProton
Maximal proton velocity (beta) [c].
void SetQpAssignedUncertainty(double uncertainty)
Assignes an uncertainty to the momentum measurement.
ClassDefOverride(V0FinderTask, 0)
void SetMinPionDca(double dca)
Sets minimal pion DCA to primary vertex.
std::shared_ptr< const KFParticleTopoReconstructor > GetTopoReconstructor() const
Accessor to the topology reconstructor.
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
const std::vector< DcaVector > & GetTrackDca() const
Accessor to the track DCA.
V0FinderCutter< EV0Type::Lambda > Cutter_t
std::vector< TrackInfo > fvTrackInfo
Track info vector [n global tracks].
EProcessingMode
Data processing mode.
std::vector< ParticleInfo > fvParticleInfo
Extra information on particles [n particles in TS].
void SetCutsConfigName(const TString &fileName)
Sets name of the configuration file for cuts.
static constexpr double kPionMass
Pion mass [GeV/c2].
double EstimateBeta(const CbmTofHit *pTofHit) const
Estimates beta of the track, using one TOF hit.
double fTzeroOffset
Offset for T0.
static constexpr int kUndefPdg
Undefined value, such tracks will be skipped.
double fMaxBetaPion
Maximal proton velocity (beta) [c].
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)
EPidApproach
PID approach used.
void Exec(Option_t *) override
Executes the task.
void SetMinProtonDca(double dca)
Sets minimal proton DCA to primary vertex.
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.
bool fbMixedEventMode
Run in a mix-event mode.
EPidApproach fPidApproach
PID approach used.
const std::vector< ParticleInfo > & GetParticleInfo() const
Accessor to the particle extra info.
int fPrimaryAssignedPdg
Assigned PDG hypothesis for primary particles.
void SetPidApproach(EPidApproach pid)
Sets PID approach.
double fMinBetaProton
Minimal proton velocity (beta) [c].
ETrackPid
An enumeration for PID of global tracks.
@ ProcessEvent
Processing of a single event.
A vector representation of DCA to target.
double fY
Y-component of the unit-vector.
double fX
X-component of the unit-vector.
Extra information on KFParticle, required by the V0 analysis.
double beta
Speed of particle [c] (from TOF hit info)
double dca
DCA to origin [cm] (from STS hit info)
const CbmTofHit * pTofHit
Pointer to TOF hit.
Extra information on track, required by the V0 analysis.
double beta
Speed of particle [c].
const CbmTofHit * pTofHit
Pointer to TOF hit.