CbmRoot
Loading...
Searching...
No Matches
CbmCaIdealHitProducerDet.h
Go to the documentation of this file.
1/* Copyright (C) 2023-2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include "CaAlgoRandom.h"
13#include "CaDefs.h"
14#include "CaUvConverter.h"
15#include "CbmEvent.h"
16#include "CbmL1DetectorID.h"
17#include "CbmMCDataArray.h"
18#include "CbmMCDataManager.h"
19#include "CbmMCDataObject.h"
20#include "CbmMCEventList.h"
21#include "CbmMatch.h"
22#include "CbmMuchAddress.h"
23#include "CbmMuchPixelHit.h"
24#include "CbmMuchPoint.h"
25#include "CbmMvdHit.h"
26#include "CbmMvdPoint.h"
27#include "CbmRecoSetupManager.h"
28#include "CbmStsHit.h"
29#include "CbmStsPoint.h"
30#include "CbmTimeSlice.h"
31#include "CbmTofAddress.h"
32#include "CbmTofHit.h"
33#include "CbmTofPoint.h"
34#include "CbmTrdHit.h"
35#include "CbmTrdPoint.h"
36
37#include <FairRootManager.h>
38#include <FairTask.h>
39#include <Logger.h>
40
41#include <TClonesArray.h>
42#include <TVector3.h>
43
44#include <array>
45#include <optional>
46#include <sstream>
47#include <string>
48#include <tuple>
49#include <unordered_map>
50
51#include <yaml-cpp/yaml.h>
52
53// TODO: Refactor the class
54
55namespace cbm::ca
56{
57 namespace constants = cbm::algo::ca::constants;
58
62 // TODO: Replace ca::EDetectorID -> ECbmModuleId
63 template<ca::EDetectorID DetID>
65 public:
68
71
74
77
80
83
86
88 InitStatus Init();
89
91 InitStatus ReInit() { return Init(); }
92
94 void Exec(Option_t* option);
95
98 void SetRandomSeed(int seed) { fRandom.SetSeed(seed); }
99
102 void SetConfigName(const char* name) { fsConfigName = name; }
103
104 private:
105 static constexpr double kHitWSize = 3.5;
106
110 std::optional<CbmLink> GetMatchedPointLink(int iH);
111
113 void ParseConfig();
114
117 void PushBackHit(const Hit_t* pHit);
118
123 void SmearValue(double& value, double sigma, int opt);
124
126 void FillPointIsLegit(int iEvGlob);
127
130
131 double fPhiU{constants::Undef<double>};
132 double fPhiV{constants::Undef<double>};
133
134 double fDu{constants::Undef<double>};
135 double fDv{constants::Undef<double>};
136 double fDt{constants::Undef<double>};
137
141 short fPdfU = -1;
142 short fPdfV = -1;
143 short fPdfT = -1;
144
149 short fMode = 0;
150
154 bool fbSmear = false;
155 };
156
157 const cbm::algo::RecoSetupUnit_t<ToCbmModuleId(DetID)>* fpDetInterface = nullptr;
158
159 // ----- Input branches:
161 TClonesArray* fpRecoEvents = nullptr;
166
167 TClonesArray* fpBrHits = nullptr;
168 TClonesArray* fpBrHitMatches = nullptr;
169
170 TClonesArray* fpBrHitsTmp = nullptr;
171 TClonesArray* fpBrHitMatchesTmp = nullptr;
172
174
175 std::string fsConfigName = "";
176
177 std::vector<HitParameters> fvStationPars;
178
179 std::vector<unsigned char> fvbPointIsLegit;
180
181 std::unordered_map<uint32_t, double> fTofRpcZpos;
182
184
186 bool fbRunTheRoutine = true;
187
188
189 int fHitCounter = 0;
190 };
191
192
193 // **********************************************************
194 // ** Template and inline function implementations **
195 // **********************************************************
196
197 // -------------------------------------------------------------------------------------------------------------------
198 //
199 template<ca::EDetectorID DetID>
201 {
202 // Common fields for all the subsystems
203 auto pos = TVector3{};
204 auto dpos = TVector3{};
205 auto address = pHit->GetAddress();
206 pHit->Position(pos);
207 pHit->PositionError(dpos);
208
209 // Fields specific to each detector type
210 if constexpr (ca::EDetectorID::kMvd == DetID) {
211 auto statNr = pHit->GetStationNr();
212 auto iCentrX = pHit->GetIndexCentralX();
213 auto iCentrY = pHit->GetIndexCentralY();
214 auto iClust = pHit->GetClusterIndex();
215 auto flag = pHit->GetFlag();
216 new ((*fpBrHits)[fHitCounter]) CbmMvdHit(address, statNr, pos, dpos, iCentrX, iCentrY, iClust, flag);
217 }
218 else {
219 auto time = pHit->GetTime();
220 auto dtime = pHit->GetTimeError();
221 if constexpr (ca::EDetectorID::kSts == DetID) {
222 auto dxy = pHit->GetDxy();
223 auto iClustF = pHit->GetFrontClusterId();
224 auto iClustB = pHit->GetBackClusterId();
225 auto du = pHit->GetDu();
226 auto dv = pHit->GetDv();
227 new ((*fpBrHits)[fHitCounter]) CbmStsHit(address, pos, dpos, dxy, iClustF, iClustB, time, dtime, du, dv);
228 }
229 else if constexpr (ca::EDetectorID::kMuch == DetID) {
230 auto dxy = pHit->GetDxy();
231 auto refId = pHit->GetRefId();
232 auto planeId = pHit->GetPlaneId();
233 LOG(info) << "MUCH: " << pHit->GetRefId() << ' ' << pHit->GetPlaneId();
234 new ((*fpBrHits)[fHitCounter]) CbmMuchPixelHit(address, pos, dpos, dxy, refId, planeId, time, dtime);
235 }
236 else if constexpr (ca::EDetectorID::kTrd == DetID) {
237 auto dxy = pHit->GetDxy();
238 auto refId = pHit->GetRefId();
239 auto eLoss = pHit->GetELoss();
240 new ((*fpBrHits)[fHitCounter]) CbmTrdHit(address, pos, dpos, dxy, refId, eLoss, time, dtime);
241 }
242 else if constexpr (ca::EDetectorID::kTof == DetID) {
243 auto refId = -1; // pHit->GetRefId(); // -> deprecated
244 auto flag = pHit->GetFlag();
245 auto channel = pHit->GetCh();
246 new ((*fpBrHits)[fHitCounter]) CbmTofHit(address, pos, dpos, refId, time, dtime, flag, channel);
247 }
248 }
249 }
250
251 // -------------------------------------------------------------------------------------------------------------------
252 //
253 template<ca::EDetectorID DetID>
254 inline std::optional<CbmLink> IdealHitProducerDet<DetID>::GetMatchedPointLink(int iH)
255 {
256 const auto* pHitMatch = dynamic_cast<CbmMatch*>(fpBrHitMatchesTmp->At(iH));
257 assert(pHitMatch);
258 if (pHitMatch->GetNofLinks() > 0) {
259 const auto& link = pHitMatch->GetMatchedLink();
260 if (link.GetIndex() > -1) {
261 return std::make_optional(link);
262 }
263 }
264 return std::nullopt;
265 }
266
267 // -------------------------------------------------------------------------------------------------------------------
268 //
269 template<ca::EDetectorID DetID>
270 inline void IdealHitProducerDet<DetID>::SmearValue(double& value, double sigma, int opt)
271 {
272 switch (opt) {
273 case 0: value += fRandom.BoundedGaus<double>(0., sigma, kHitWSize); break;
274 case 1: value += fRandom.Uniform<double>(0., sigma); break;
275 default: LOG(fatal) << "IdealHitProducerDet::SmearValue: illegal option: opt = " << opt;
276 }
277 }
278
279
280} // namespace cbm::ca
Random generator utility class for CA tracking.
Compile-time constants definition for the CA tracking algorithm.
ECbmDataType
Enumerator for CBM data types.
Definition CbmDefs.h:122
Implementation of L1DetectorID enum class for CBM.
Class for pixel hits in MUCH detector.
TVector3 dpos
A manager for setup representation in CBM reconstruction.
Data class for a reconstructed hit in the STS.
Class for hits in TRD detector.
Access to a MC data branch for time-based analysis.
Access to a MC data branch for time-based analysis.
Container class for MC events with number, file and start time.
data class for a reconstructed 3-d hit in the STS
Definition CbmStsHit.h:35
Bookkeeping of time-slice content.
data class for a reconstructed Energy-4D measurement in the TRD
Definition CbmTrdHit.h:40
A class, providing ROOT-free access to randomly generated variables.
TClonesArray * fpRecoEvents
Array of reconstructed events.
std::vector< unsigned char > fvbPointIsLegit
Map of used point index.
void Exec(Option_t *option)
Execution of the task.
static constexpr double kHitWSize
half-width for the bounded gaussian [sigma]
TClonesArray * fpBrHitsTmp
Temporary array of hits.
ECbmDataType fHitDataType
Hit data type.
IdealHitProducerDet & operator=(IdealHitProducerDet &&)=delete
Move assignment operator.
PointTypes_t::at< DetID > Point_t
CbmMCEventList * fpMCEventList
MC event list.
TClonesArray * fpBrHitMatchesTmp
Temporary array of hit matches.
void SetRandomSeed(int seed)
Sets random seed (1 by default)
std::unordered_map< uint32_t, double > fTofRpcZpos
void SetConfigName(const char *name)
Sets YAML configuration file name.
std::vector< HitParameters > fvStationPars
Parameters, stored for each station.
const cbm::algo::RecoSetupUnit_t< ToCbmModuleId(DetID)> * fpDetInterface
Detector interface.
IdealHitProducerDet(IdealHitProducerDet &&)=delete
Move constructor.
IdealHitProducerDet & operator=(const IdealHitProducerDet &)=delete
Copy assignment operator.
CbmMCDataObject * fpMCEventHeader
MC event header.
int fHitCounter
Hit counter in a new branch.
CbmTimeSlice * fpTimeSlice
Current time slice.
void PushBackHit(const Hit_t *pHit)
Pushes back a hit into the hits branch.
std::optional< CbmLink > GetMatchedPointLink(int iH)
Gets pointer to matched MC point.
bool fbRunTheRoutine
Management flag, which does run the routine if there was a request.
void FillPointIsLegit(int iEvGlob)
Fills map of legit points (inside MC event!)
std::string fsConfigName
Name of configuration file.
InitStatus Init()
Initialization of the task.
CbmMCDataArray * fpBrMCTracks
Branch: array of MC tracks.
ca::Random fRandom
< z-position of TOF RPCs (filled only for TOF)
InitStatus ReInit()
Re-initialization of the task.
void ParseConfig()
Parses the YAML configuration file.
TClonesArray * fpBrHits
Branch: array of hits.
TClonesArray * fpBrHitMatches
Branch: array of hit matches.
void SmearValue(double &value, double sigma, int opt)
Smears the value by a given standard deviation with a selected function.
CbmMCDataArray * fpBrPoints
Branch: array of MC points.
IdealHitProducerDet(const IdealHitProducerDet &)=delete
Copy constructor.
typename detail::RecoSetupUnitMapper< ModuleId >::type RecoSetupUnit_t
Definition RecoSetup.h:50
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at
A structure to keep hit adjustment/creation settings for each station.
double fDu
Error of u-coordinate measurement [cm].
double fPhiU
Angle of the first independent measured coordinate [rad].
double fPhiV
Angle of the second independent measured coordinate [rad].
double fDt
Error of time measurement [ns].
double fDv
Error of v-coordinate measurement [cm].