CbmRoot
Loading...
Searching...
No Matches
CaMcData.h
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#ifndef CaMcData_h
11#define CaMcData_h 1
12
13#include "CaDefs.h"
14#include "CaMcHitInfo.h"
15#include "CaMcLinkKey.h"
16#include "CaMcMatch.h"
17#include "CaMcPoint.h"
18#include "CaMcTrack.h"
19#include "CaSimd.h"
20#include "CaVector.h"
21
22#include <numeric>
23#include <string>
24#include <unordered_map>
25
26
27namespace cbm::algo::ca
28{
29 enum class EDetectorID;
30 class McHitInfo;
31
33 class McData {
34 public:
35 // *********************************
36 // ** Constructors and destructor **
37 // *********************************
38
40 McData();
41
43 ~McData() = default;
44
46 McData(const McData& other);
47
49 McData(McData&& other) noexcept;
50
52 McData& operator=(const McData& other);
53
55 McData& operator=(McData&& other) noexcept;
56
58 void Swap(McData& other) noexcept;
59
62 void AddPoint(const McPoint& point);
63
66 void AddTrack(const McTrack& track);
67
69 void Clear();
70
78 int FindInternalPointIndex(ca::EDetectorID detID, int index, int event, int file) const
79 {
80 int indexGlob = GetPointGlobExtIndex(detID, index);
81 auto it = fmPointLinkMap.find(McLinkKey(indexGlob, event, file));
82 return (it != fmPointLinkMap.cend()) ? it->second : -1;
83 }
84
91 int FindInternalTrackIndex(int index, int event, int file) const
92 {
93 auto it = fmTrackLinkMap.find(McLinkKey(index, event, file));
94 return (it != fmTrackLinkMap.cend()) ? it->second : -1;
95 }
96
100 {
101 return std::accumulate(fvNofPointsUsed.cbegin(), fvNofPointsUsed.cbegin() + static_cast<int>(detID), 0);
102 }
103
107 {
108 return std::accumulate(fvNofPointsUsed.cbegin(), fvNofPointsUsed.cbegin() + static_cast<int>(detID) + 1, 0);
109 }
110
117 int GetPointGlobExtIndex(ca::EDetectorID detID, int iPointLocal) const
118 {
119 return iPointLocal + std::accumulate(fvNofPointsOrig.cbegin(), fvNofPointsOrig.cbegin() + int(detID), 0);
120 }
121
123 int GetNofTracks() const { return fvTracks.size(); }
124
126 int GetNofPoints() const { return fvPoints.size(); }
127
130 int GetNofPointsOrig(ca::EDetectorID detID) const { return fvNofPointsOrig[static_cast<int>(detID)]; }
131
134 int GetNofPointsUsed(ca::EDetectorID detID) const { return fvNofPointsUsed[static_cast<int>(detID)]; }
135
137 const auto& GetPoint(int idx) const { return fvPoints[idx]; }
138
140 // TODO: SZh 12.12.2022: Probably, the better solution is to write a specific accessor for
141 // setting indexes to MC points
142 auto& GetPoint(int idx) { return fvPoints[idx]; }
143
145 const auto& GetPointContainer() const { return fvPoints; }
146
148 const auto& GetTrack(int idx) const { return fvTracks[idx]; }
149
151 auto& GetTrack(int idx) { return fvTracks[idx]; }
152
154 const auto& GetTrackContainer() const { return fvTracks; }
155
157 auto& GetTrackContainer() { return fvTracks; }
158
165
167 void ReserveNofTracks(int nTracks) { fvTracks.reserve(nTracks); }
168
170 void ReserveNofPoints(int nPoints) { fvPoints.reserve(nPoints); }
171
175 void SetNofPointsOrig(ca::EDetectorID detID, int nPoints) { fvNofPointsOrig[static_cast<int>(detID)] = nPoints; }
176
179
180 int GetBestMcPointIdForCaHit(int iHit) const
181 {
182 if (fpMcHitInfos) {
183 return (*fpMcHitInfos)[iHit].GetBestMcPointId();
184 }
185 return -1;
186 }
187
188 int GetBestMcTrackIdForCaHit(int iHit) const
189 {
190 if (fpMcHitInfos) {
191 int iPoint = (*fpMcHitInfos)[iHit].GetBestMcPointId();
192 if (iPoint >= 0 && iPoint < GetNofPoints()) {
193 return GetPoint(iPoint).GetTrackId();
194 }
195 }
196 return -1;
197 }
198
200 {
201 McMatch match;
202 if (fpMcHitInfos) {
203 const auto& pointIds = (*fpMcHitInfos)[iHit].GetMcPointIds();
204 for (int iPoint : pointIds) {
205 if (iPoint >= 0 && iPoint < GetNofPoints()) {
206 const auto& point = GetPoint(iPoint);
207 match.AddLink(point.GetTrackId(), 1.0f); // TODO: Define a better weight
208 }
209 }
210 }
211 return match;
212 }
213
219 std::string ToString(int verbose = 1) const;
220
221 private:
222 // ******************************
223 // ** Member variables **
224 // ******************************
225
226 ca::Vector<McPoint> fvPoints = {"ca::algo::ca::McData::fvPoints"};
227 ca::Vector<McTrack> fvTracks = {"ca::algo::ca::McData::fvTracks"};
228
229 std::array<int, constants::size::MaxNdetectors> fvNofPointsOrig = {0};
230 std::array<int, constants::size::MaxNdetectors> fvNofPointsUsed = {0};
231
232 std::unordered_map<McLinkKey, int> fmPointLinkMap = {};
233 std::unordered_map<McLinkKey, int> fmTrackLinkMap = {};
234
236 };
237
238
239 // *********************************************************
240 // ** Template and inline function implementation **
241 // *********************************************************
242
243 // -------------------------------------------------------------------------------------------------------------------
244 //
245 inline void McData::AddPoint(const McPoint& point)
246 {
247 fmPointLinkMap[point.GetLinkKey()] = point.GetId();
248 fvPoints.push_back(point);
249 ++fvNofPointsUsed[static_cast<int>(point.GetDetectorId())];
250 }
251
252 // -------------------------------------------------------------------------------------------------------------------
253 //
254 inline void McData::AddTrack(const McTrack& track)
255 {
256 fmTrackLinkMap[track.GetLinkKey()] = track.GetId();
257 fvTracks.push_back(track);
258 }
259} // namespace cbm::algo::ca
260
261#endif // CaMcData_h
Compile-time constants definition for the CA tracking algorithm.
Data structure to represent a MC link in CA tracking MC module.
Data structure to represent a set of MC links in CA tracking MC module.
Internal class describing a MC point for CA tracking QA and performance (header)
Class represents a MC track for CA tracking QA and performance (implementation)
const auto & GetTrack(int idx) const
Gets a reference to MC track by its internal index.
Definition CaMcData.h:148
McData & operator=(const McData &other)
Copy assignment operator.
Definition CaMcData.cxx:42
int FindInternalTrackIndex(int index, int event, int file) const
Finds an index of MC track in internal track container.
Definition CaMcData.h:91
auto & GetTrack(int idx)
Gets a mutual reference to MC track by its internal index.
Definition CaMcData.h:151
int GetNofPointsUsed(ca::EDetectorID detID) const
Gets used number of MC points in different detectors.
Definition CaMcData.h:134
int GetNofPoints() const
Gets number of points in this event/TS.
Definition CaMcData.h:126
const auto & GetTrackContainer() const
Gets a reference to the vector of tracks.
Definition CaMcData.h:154
std::unordered_map< McLinkKey, int > fmPointLinkMap
MC point internal index vs. link.
Definition CaMcData.h:232
void Swap(McData &other) noexcept
Swap method.
Definition CaMcData.cxx:63
int GetPointGlobExtIndex(ca::EDetectorID detID, int iPointLocal) const
Calculates global index of MC point.
Definition CaMcData.h:117
void SetMcHitInfo(const ca::Vector< cbm::algo::ca::McHitInfo > &vHits)
Initialize information about points and hits association with MC track.
Definition CaMcData.cxx:86
int GetNofPointsOrig(ca::EDetectorID detID) const
Gets original number of MC points in different detectors.
Definition CaMcData.h:130
std::array< int, constants::size::MaxNdetectors > fvNofPointsUsed
Number of points used vs. detector.
Definition CaMcData.h:230
void Clear()
Clears contents.
Definition CaMcData.cxx:76
void AddTrack(const McTrack &track)
Definition CaMcData.h:254
const ca::Vector< cbm::algo::ca::McHitInfo > * fpMcHitInfos
Definition CaMcData.h:235
McData()
Default constructor.
Definition CaMcData.cxx:22
ca::Vector< McPoint > fvPoints
Container of points.
Definition CaMcData.h:226
McMatch GetMcMatchForCaHit(int iHit) const
Definition CaMcData.h:199
const auto & GetPoint(int idx) const
Gets a reference to MC point by its index.
Definition CaMcData.h:137
void AddPoint(const McPoint &point)
Definition CaMcData.h:245
int FindInternalPointIndex(ca::EDetectorID detID, int index, int event, int file) const
Finds an index of MC point in internal point container.
Definition CaMcData.h:78
int GetBestMcPointIdForCaHit(int iHit) const
Definition CaMcData.h:180
int GetNofTracks() const
Gets number of tracks in this event/TS.
Definition CaMcData.h:123
int GetBestMcTrackIdForCaHit(int iHit) const
Definition CaMcData.h:188
ca::Vector< McTrack > fvTracks
Container of tracks.
Definition CaMcData.h:227
auto & GetPoint(int idx)
Gets mutual reference to MC point by its index.
Definition CaMcData.h:142
const ca::Vector< cbm::algo::ca::McHitInfo > * GetMcHitInfo() const
Gets pointer to MC hit info container.
Definition CaMcData.h:178
~McData()=default
Destructor.
std::array< int, constants::size::MaxNdetectors > fvNofPointsOrig
Total number of points by detector.
Definition CaMcData.h:229
const auto & GetPointContainer() const
Gets a reference to the vector of points.
Definition CaMcData.h:145
void ReserveNofPoints(int nPoints)
Reserves memory for points to avoid extra allocations.
Definition CaMcData.h:170
std::unordered_map< McLinkKey, int > fmTrackLinkMap
MC track internal index vs. link.
Definition CaMcData.h:233
void SetNofPointsOrig(ca::EDetectorID detID, int nPoints)
Sets original number of MC points in different detectors.
Definition CaMcData.h:175
std::string ToString(int verbose=1) const
Definition CaMcData.cxx:109
void ReserveNofTracks(int nTracks)
Reserves memory for tracks to avoid extra allocations.
Definition CaMcData.h:167
auto & GetTrackContainer()
Gets a mutual reference to the vector of tracks.
Definition CaMcData.h:157
int GetFirstPointIndex(ca::EDetectorID detID) const
Gets the first point index for a given detector subsystem.
Definition CaMcData.h:99
int GetLastPointIndex(ca::EDetectorID detID) const
Gets the next index of point, which is expected being after the last one for a given detector.
Definition CaMcData.h:106
Class describes a unified MC-point, used in CA tracking QA analysis.
Definition CaMcPoint.h:33
ca::EDetectorID GetDetectorId() const
Gets detector ID.
Definition CaMcPoint.h:67
int GetId() const
Gets index of this point in internal CA container.
Definition CaMcPoint.h:87
McLinkKey GetLinkKey() const
Gets link key.
Definition CaMcPoint.h:111
int GetId() const
Gets index of track.
Definition CaMcTrack.h:109
ca::McLinkKey GetLinkKey() const
Gets link key.
Definition CaMcTrack.h:112
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
Definition CbmDefs.h:216
void AddLink(int linkIndex, float linkWeight)
Definition CaMcMatch.h:45