CbmRoot
Loading...
Searching...
No Matches
CaToolsMCData.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 CaToolsMCData_h
11#define CaToolsMCData_h 1
12
13#include "CaSimd.h"
14#include "CaToolsDef.h"
15#include "CaToolsLinkKey.h"
16#include "CaToolsMCPoint.h"
17#include "CaToolsMCTrack.h"
18#include "CaVector.h"
19
20#include <numeric>
21#include <string>
22#include <unordered_map>
23
24namespace cbm::algo::ca
25{
26 enum class EDetectorID;
27}
28
29using namespace cbm::algo::ca; //TODO: remove
30
31namespace cbm::ca::tools
32{
34 class MCData {
35 public:
36 // *********************************
37 // ** Constructors and destructor **
38 // *********************************
39
41 MCData();
42
44 ~MCData() = default;
45
47 MCData(const MCData& other);
48
50 MCData(MCData&& other) noexcept;
51
53 MCData& operator=(const MCData& other);
54
56 MCData& operator=(MCData&& other) noexcept;
57
59 void Swap(MCData& other) noexcept;
60
63 void AddPoint(const MCPoint& point);
64
67 void AddTrack(const MCTrack& track);
68
70 void Clear();
71
79 int FindInternalPointIndex(ca::EDetectorID detID, int index, int event, int file) const
80 {
81 int indexGlob = GetPointGlobExtIndex(detID, index);
82 auto it = fmPointLinkMap.find(LinkKey(indexGlob, event, file));
83 return (it != fmPointLinkMap.cend()) ? it->second : -1;
84 }
85
92 int FindInternalTrackIndex(int index, int event, int file) const
93 {
94 auto it = fmTrackLinkMap.find(LinkKey(index, event, file));
95 return (it != fmTrackLinkMap.cend()) ? it->second : -1;
96 }
97
101 {
102 return std::accumulate(fvNofPointsUsed.cbegin(), fvNofPointsUsed.cbegin() + static_cast<int>(detID), 0);
103 }
104
108 {
109 return std::accumulate(fvNofPointsUsed.cbegin(), fvNofPointsUsed.cbegin() + static_cast<int>(detID) + 1, 0);
110 }
111
118 int GetPointGlobExtIndex(ca::EDetectorID detID, int iPointLocal) const
119 {
120 return iPointLocal + std::accumulate(fvNofPointsOrig.cbegin(), fvNofPointsOrig.cbegin() + int(detID), 0);
121 }
122
124 int GetNofTracks() const { return fvTracks.size(); }
125
127 int GetNofPoints() const { return fvPoints.size(); }
128
131 int GetNofPointsOrig(ca::EDetectorID detID) const { return fvNofPointsOrig[static_cast<int>(detID)]; }
132
135 int GetNofPointsUsed(ca::EDetectorID detID) const { return fvNofPointsUsed[static_cast<int>(detID)]; }
136
138 const auto& GetPoint(int idx) const { return fvPoints[idx]; }
139
141 // TODO: SZh 12.12.2022: Probably, the better solution is to write a specific accessor for
142 // setting indexes to MC points
143 auto& GetPoint(int idx) { return fvPoints[idx]; }
144
146 const auto& GetPointContainer() const { return fvPoints; }
147
149 const auto& GetTrack(int idx) const { return fvTracks[idx]; }
150
152 auto& GetTrack(int idx) { return fvTracks[idx]; }
153
155 const auto& GetTrackContainer() const { return fvTracks; }
156
158 auto& GetTrackContainer() { return fvTracks; }
159
166
168 void ReserveNofTracks(int nTracks) { fvTracks.reserve(nTracks); }
169
171 void ReserveNofPoints(int nPoints) { fvPoints.reserve(nPoints); }
172
176 void SetNofPointsOrig(ca::EDetectorID detID, int nPoints) { fvNofPointsOrig[static_cast<int>(detID)] = nPoints; }
177
183 std::string ToString(int verbose = 1) const;
184
185 private:
186 // ******************************
187 // ** Member variables **
188 // ******************************
189
190 ca::Vector<MCPoint> fvPoints = {"ca::tools::MCData::fvPoints"};
191 ca::Vector<MCTrack> fvTracks = {"ca::tools::MCData::fvTracks"};
192
193 std::array<int, constants::size::MaxNdetectors> fvNofPointsOrig = {0};
194 std::array<int, constants::size::MaxNdetectors> fvNofPointsUsed = {0};
195
196 std::unordered_map<LinkKey, int> fmPointLinkMap = {};
197 std::unordered_map<LinkKey, int> fmTrackLinkMap = {};
198 };
199
200
201 // *********************************************************
202 // ** Template and inline function implementation **
203 // *********************************************************
204
205 // -------------------------------------------------------------------------------------------------------------------
206 //
207 inline void MCData::AddPoint(const MCPoint& point)
208 {
209 fmPointLinkMap[point.GetLinkKey()] = point.GetId();
210 fvPoints.push_back(point);
211 ++fvNofPointsUsed[static_cast<int>(point.GetDetectorId())];
212 }
213
214 // -------------------------------------------------------------------------------------------------------------------
215 //
216 inline void MCData::AddTrack(const MCTrack& track)
217 {
218 fmTrackLinkMap[track.GetLinkKey()] = track.GetId();
219 fvTracks.push_back(track);
220 }
221} // namespace cbm::ca::tools
222
223#endif // CaToolsMCData_h
Definitions for ca::tools namespace.
Data structure to represent a MC link 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 (header)
This class represents a package for tracking-related data.
void AddPoint(const MCPoint &point)
std::string ToString(int verbose=1) const
int GetNofPoints() const
Gets number of points in this event/TS.
void InitTrackInfo(const ca::Vector< CbmL1HitDebugInfo > &vHits)
Initialize information about points and hits association with MC track.
int GetFirstPointIndex(ca::EDetectorID detID) const
Gets the first point index for a given detector subsystem.
auto & GetTrack(int idx)
Gets a mutual reference to MC track by its internal index.
std::array< int, constants::size::MaxNdetectors > fvNofPointsUsed
Number of points used vs. detector.
auto & GetTrackContainer()
Gets a mutual reference to the vector of tracks.
MCData()
Default constructor.
const auto & GetTrack(int idx) const
Gets a reference to MC track by its internal index.
void ReserveNofPoints(int nPoints)
Reserves memory for points to avoid extra allocations.
MCData & operator=(const MCData &other)
Copy assignment operator.
int GetNofPointsUsed(ca::EDetectorID detID) const
Gets used number of MC points in different detectors.
const auto & GetPointContainer() const
Gets a reference to the vector of points.
ca::Vector< MCPoint > fvPoints
Container of points.
int GetPointGlobExtIndex(ca::EDetectorID detID, int iPointLocal) const
Calculates global index of MC point.
std::array< int, constants::size::MaxNdetectors > fvNofPointsOrig
Total number of points by detector.
int GetNofTracks() const
Gets number of tracks in this event/TS.
int GetNofPointsOrig(ca::EDetectorID detID) const
Gets original number of MC points in different detectors.
int FindInternalTrackIndex(int index, int event, int file) const
Finds an index of MC track in internal track container.
void AddTrack(const MCTrack &track)
ca::Vector< MCTrack > fvTracks
Container of tracks.
std::unordered_map< LinkKey, int > fmTrackLinkMap
MC track internal index vs. link.
std::unordered_map< LinkKey, int > fmPointLinkMap
MC point internal index vs. link.
auto & GetPoint(int idx)
Gets mutual reference to MC point by its index.
void ReserveNofTracks(int nTracks)
Reserves memory for tracks to avoid extra allocations.
int FindInternalPointIndex(ca::EDetectorID detID, int index, int event, int file) const
Finds an index of MC point in internal point container.
const auto & GetTrackContainer() const
Gets a reference to the vector of tracks.
void Swap(MCData &other) noexcept
Swap method.
~MCData()=default
Destructor.
int GetLastPointIndex(ca::EDetectorID detID) const
Gets the next index of point, which is expected being after the last one for a given detector.
const auto & GetPoint(int idx) const
Gets a reference to MC point by its index.
void SetNofPointsOrig(ca::EDetectorID detID, int nPoints)
Sets original number of MC points in different detectors.
void Clear()
Clears contents.
Class describes a unified MC-point, used in CA tracking QA analysis.
int GetId() const
Gets index of this point in internal CA container.
LinkKey GetLinkKey() const
Gets link key.
ca::EDetectorID GetDetectorId() const
Gets detector ID.
int GetId() const
Gets index of track.
LinkKey GetLinkKey() const
Gets link key.
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:176