CbmRoot
Loading...
Searching...
No Matches
KfpV0FinderChain.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 "global/ParFiles.h"
15#include "yaml/Yaml.h"
16
17#include <sstream>
18
20
21// ---------------------------------------------------------------------------------------------------------------------
22//
23V0FinderChain::V0FinderChain(const std::unique_ptr<qa::Manager>& qaManager)
24 : fpFinderQa(qaManager != nullptr ? std::make_unique<kfp::V0FinderQa>(qaManager, "V0Finder") : nullptr)
25{
26}
27
28// ---------------------------------------------------------------------------------------------------------------------
29//
31{
32 GetMonitor(); // A hack to update the run monitor
33 L_(info) << fMonitorRun.ToString();
34}
35
36// ---------------------------------------------------------------------------------------------------------------------
37//
45
46// ---------------------------------------------------------------------------------------------------------------------
47//
49try {
50 L_(info) << "kfp::V0FinderChain: initializing the V0-finder chain ...";
51
52 // ----- Read configuration file
53 ParFiles parFiles(Opts().RunId());
54 auto config = yaml::ReadFromFile<kfp::V0FinderConfig>(Opts().ParamsDir() / parFiles.kfp.V0FinderConfig);
55 L_(info) << config.ToString();
56
57 //* Check the V0 type
58 if (config.reconstructPdg != 3122) { // At the moment only Lambda analysis is possible
59 std::stringstream msg;
60 msg << "kfp::V0FinderChain: at the moment only lambda finding is possible. Provided PDG: " << config.reconstructPdg;
61 throw std::runtime_error(msg.str());
62 }
63
64 //* Define daughter particles
65 auto& particles{config.cuts.particles};
66 int iPion{-1};
67 int iProton{-1};
68 for (int iParticle = 0; iParticle < int(particles.size()); ++iParticle) {
69 const auto& particle = particles[iParticle];
70 auto CheckOutParticle = [&](int pdg, int& iParticleToFind) {
71 if (particle.pdg == pdg) {
72 if (iParticleToFind == -1) {
73 iParticleToFind = iParticle;
74 }
75 else {
76 std::stringstream msg;
77 msg << "kfp::V0FinderChain: entry for pdg= " << pdg << " is defined more then one time in the ";
78 msg << "config.cuts.particles";
79 throw std::runtime_error(msg.str());
80 }
81 }
82 };
83 CheckOutParticle(-211, iPion);
84 CheckOutParticle(2212, iProton);
85 }
86 if (iProton == -1 || iPion == -1) {
87 std::stringstream msg;
88 msg << "kfp::V0FinderChain: config cuts/particles: either pion or proton settings are not found";
89 throw std::runtime_error(msg.str());
90 }
91 const auto& pion{particles[iPion]};
92 const auto& proton{particles[iProton]};
93
94 // ----- Define a BMON diamond
95 if (fBmonDefinedAddresses.empty()) {
96 throw std::runtime_error("kfp::V0FinderChain: BMON available addresses were not set");
97 }
98 int iBmonPartitionSelect = -1;
99 for (int iPart = 0; iPart < static_cast<int>(fBmonDefinedAddresses.size()); ++iPart) {
100 if (config.bmonAddress == fBmonDefinedAddresses[iPart]) {
101 iBmonPartitionSelect = iPart;
102 break;
103 }
104 }
105 if (iBmonPartitionSelect < 0) {
106 std::stringstream msg;
107 msg << "kfp::V0FinderChain: a reference BMON address ( " << std::hex << config.bmonAddress << std::dec
108 << " ) differs from ones, provided by hitfinder. Please check your configuration";
109 throw std::runtime_error(msg.str());
110 }
111
112 // ----- Set the V0-finder properties
113 // TODO: In future, there are will be a several instances of the V0Finder, each for a particular thread
114 {
115 //* Set particle PID properties
116 fFinder.SetBmonPartitionIndex(iBmonPartitionSelect);
117 fFinder.SetMinPionDca(pion.minDca);
118 fFinder.SetMinProtonDca(proton.minDca);
119 fFinder.SetPionVelocityRange(pion.minVelocity, pion.maxVelocity);
120 fFinder.SetProtonVelocityRange(proton.minVelocity, proton.maxVelocity);
121
122 //* Set KFParticleFinder properties
123 auto& kfpCuts{config.cuts.kfp};
124 fFinder.SetLdLCut2D(kfpCuts.minDecayLDL);
125 fFinder.SetLCut(kfpCuts.minDecayLength);
126 fFinder.SetChi2Cut2D(kfpCuts.maxChi2NdfGeo);
127 fFinder.SetChiPrimaryCut2D(kfpCuts.maxChi2NdfPrim);
128
129 //* Set other properties
130 fFinder.SetTzeroOffset(config.tZeroOffset);
131 fFinder.SetQpAssignedUncertainty(config.qpAssignedUncertainty);
132 fFinder.AddDecayToReconstructionList(config.reconstructPdg);
133 fFinder.SetPrimaryAssignedPdg(config.primaryAssignedPdg);
134
135 //* Init the V0 finder
136 fFinder.Init();
137 }
138
139 if (fpFinderQa != nullptr) {
140 fpFinderQa->Init();
141 }
142
143 L_(info) << "kfp::V0FinderChain: initializing the V0-finder chain ... done";
144}
145catch (const std::exception& err) {
146 L_(info) << "kfp::V0FinderChain: initializing the V0-finder chain ... failed. Reason: " << err.what();
147 throw std::runtime_error("initialization of V0-finder chain failed");
148}
149
150// ---------------------------------------------------------------------------------------------------------------------
151//
153{
154 EventOutput res = fFinder.Process(recoEvent);
155 if (fpFinderQa != nullptr) {
156 fpFinderQa->Exec(recoEvent, fFinder);
157 }
159 return res;
160}
#define L_(level)
A chain for V0 finding.
Configuration structure for V0 selector in mCBM.
This file contains the definition of the ParFiles class.
Class to store different triggers for a given event.
const Options & Opts() const
Definition SubChain.h:20
A chain for the V0 finder.
V0FinderChain()=default
Default constructor.
EventOutput ProcessEvent(const RecoResults &recoEvent)
Processes an event, returns a collection of fired triggers.
void Finalize()
Finalizes the instance (called in the end of the run)
PODVector< uint32_t > fBmonDefinedAddresses
Available addresses of BMON.
kfp::V0FinderMonitor fMonitorRun
Monitor per run.
kfp::V0FinderMonitorData_t fMonitorTimeslice
Monitor per timeslice.
kfp::V0Finder fFinder
Instance of the V0-finding algorithm.
void Init()
Initializes the instance (called in the beginning of the run)
kfp::V0FinderMonitorData_t GetMonitor()
Gets a monitor.
std::unique_ptr< kfp::V0FinderQa > fpFinderQa
QA module.
void Reset()
Resets all the counters and timers.
void AddMonitorData(const MonitorData &other, bool parallel=false)
Adds the other monitor data to this.
std::string ToString() const
Prints counters summary to string.
Definition CaMonitor.h:167
void AddMonitorData(const MonitorData< ECounterKey, ETimerKey > &data, bool parallel=false)
Adds the other monitor data to this.
Definition CaMonitor.h:70
const V0FinderMonitorData_t & GetEventMonitor() const
Gets monitor data.
Definition KfpV0Finder.h:68
void SetLdLCut2D(float cut)
Sets cut on for 2-daughter decays.
void SetChiPrimaryCut2D(float cut)
Sets cut on of each track for 2-daughter decays.
CbmEventTriggers Process(const RecoResults &recoEvent)
Processes a reconstructed data sample, returns a collection of fired triggers.
void SetMinPionDca(double dca)
void AddDecayToReconstructionList(int pdg)
Adds particle to reconstruction list.
Definition KfpV0Finder.h:65
void SetTzeroOffset(double offset)
Sets an offset to t0.
void SetPrimaryAssignedPdg(int pdg)
Sets the assigned PDG for primary particles.
void SetBmonPartitionIndex(int iPartition)
Sets an address of a reference BMON diamond.
void SetLCut(float cut)
Sets cut on the distance to the primary vertex from the decay vertex.
void SetQpAssignedUncertainty(double uncertainty)
Assignes an uncertainty to the momentum measurement.
void SetMinProtonDca(double dca)
Sets minimal proton DCA to primary vertex.
void SetProtonVelocityRange(double vMin, double vMax)
Sets proton velocity range.
void SetChi2Cut2D(float cut)
Sets cut on for 2-daughter decays.
void SetPionVelocityRange(double vMin, double vMax)
Sets minimal pion DCA to primary vertex.
void Init()
Initializes the instance (called in the beginning of the run)
T ReadFromFile(fs::path path)
Definition Yaml.h:51
Hash for CbmL1LinkKey.
Class to hold the paths to the parameter files for the different detectors.
Definition ParFiles.h:21
fs::path V0FinderConfig
Definition ParFiles.h:59
struct cbm::algo::ParFiles::@5 kfp