CbmRoot
Loading...
Searching...
No Matches
TrackingSetupIfs.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#ifndef ALGO_TrackingSetupIfs_h
11#define ALGO_TrackingSetupIfs_h 1
12
15
16#include <boost/serialization/access.hpp>
17#include <boost/serialization/array.hpp>
18#include <boost/serialization/vector.hpp>
19
20#include <limits>
21#include <sstream>
22#include <string>
23#include <tuple>
24#include <utility>
25#include <vector>
26
27#include <fmt/format.h>
28
29namespace cbm::algo
30{
37 struct HitRange {
38 double x{0.};
39 double y{0.};
40 double t{0.};
41
43 constexpr HitRange() = default;
44
46 constexpr HitRange(double x_, double y_, double t_) : x(x_), y(y_), t(t_) {}
47
48 private:
51 template<class Archive>
52 void serialize(Archive& ar, const unsigned int /*version*/)
53 {
54 ar& x;
55 ar& y;
56 ar& t;
57 }
58 };
59
60
64 template<class ConcreteDetector>
66 public:
68 virtual ~TrackingSetupIfs() = default;
69
73 bool IsValid() const;
74
77 const GeoVolume& GetActiveVolume(int stationId) const { return fvStationActiveVolumes[stationId]; }
78
85 template<class HitType>
86 HitRange GetHitRange(const HitType& hit) const
87 {
88 return static_cast<const ConcreteDetector*>(this)->ImplGetHitRange(hit);
89 };
90
92 int GetNofTrackingStations() const { return fvStationFullVolumes.size(); }
93
96 int GetTrackingStationId(uint32_t address) const
97 {
98 return static_cast<const ConcreteDetector*>(this)->ImplGetTrackingStationId(address);
99 }
100
103 const GeoVolume& GetFullVolume(int stationId) const { return fvStationFullVolumes[stationId]; }
104
107 bool IsTimeInfoProvided(int stationId) const
108 {
109 return static_cast<const ConcreteDetector*>(this)->ImplIsTimeInfoProvided(stationId);
110 }
111
113 std::string TableOfTrackingStations() const;
114
115 protected:
116 TrackingSetupIfs() = default;
121
124 TrackingSetupIfs(std::pair<std::vector<GeoVolume>, std::vector<GeoVolume>>&& volumes)
125 : fvStationFullVolumes(std::move(volumes.first))
126 , fvStationActiveVolumes(std::move(volumes.second))
127 {
128 }
129
130 protected:
134 template<class HitType>
136 {
137 return HitRange{3.5 * hit.GetDx(), 3.5 * hit.GetDy(), 3.5 * hit.GetTimeError()};
138 }
139
140 private:
143 template<class Archive>
144 void serialize(Archive& ar, const unsigned int /*version*/)
145 {
148 }
149
150 std::vector<GeoVolume> fvStationFullVolumes{};
151 std::vector<GeoVolume> fvStationActiveVolumes{};
152 };
153
154
155 //* Method implementation
156
157 // -------------------------------------------------------------------------------------------------------------------
158 //
159 template<class ConcreteDetector>
161 {
162 std::stringstream msg;
163 msg << "Errors in the detector interface initialization for " << ConcreteDetector::GetDetectorName() << ':';
164
165 // 1. Number of stations
166 if (fvStationActiveVolumes.size() != fvStationFullVolumes.size() || fvStationActiveVolumes.size() == 0) {
167 msg << "\n\t number of active ( " << fvStationActiveVolumes.size() << " ) and passive ("
168 << fvStationFullVolumes.size() << ") volumes is different and(or) no active volumes provided";
169 LOG(error) << msg.str();
170 return false;
171 }
172
173 bool res = true;
174 // 2. Volume checks
175 for (int iSt{0}; iSt < GetNofTrackingStations(); ++iSt) {
176 const auto& activeVolume{fvStationActiveVolumes[iSt]};
177 const auto& fullVolume{fvStationFullVolumes[iSt]};
178
179 if (!activeVolume.IsValid()) {
180 msg << "\n\t - invalid active volume for station " << iSt << ": " << activeVolume.ToString();
181 res = false;
182 }
183
184 if (!fullVolume.IsValid()) {
185 msg << "\n\t - invalid active volume for station " << iSt << ": " << fullVolume.ToString();
186 res = false;
187 }
188 }
189
190 if (!res) {
191 LOG(error) << msg.str();
192 return false;
193 }
194
195 // 3. Active volume intersection check
196 // Check, if stations ordered in z-direction and check overlaps
197 for (int iSt{1}; iSt < GetNofTrackingStations(); ++iSt) {
198 const auto& prevVol = fvStationActiveVolumes[iSt - 1];
199 const auto& thisVol = fvStationActiveVolumes[iSt];
200 if (prevVol.GetCenterZ() > thisVol.GetCenterZ()) {
201 msg << "\n\t - stations " << iSt - 1 << " and " << iSt << " are not properly ordered in z-direction:";
202 msg << "\n\t\t previous station: " << prevVol.ToString();
203 msg << "\n\t\t this station: " << thisVol.ToString();
204 res = false;
205 }
206
207 if (thisVol.HasOverlapWith(prevVol)) {
208 msg << "\n\t - stations " << iSt - 1 << " and " << iSt << " have intersections:";
209 msg << "\n\t\t previous station: " << prevVol.ToString();
210 msg << "\n\t\t this station: " << thisVol.ToString();
211 res = false;
212 }
213 }
214
215 if (!res) {
216 LOG(error) << msg.str();
217 }
218
219 // 4. Check, if the derived class is valid
220 res = static_cast<const ConcreteDetector*>(this)->IsInitialized();
221
222 return res;
223 }
224
225 // -------------------------------------------------------------------------------------------------------------------
226 //
227 template<class ConcreteDetector>
229 {
230 // TODO: Add verbosity level, probably distribute properties into several tables
231 using fmt::format;
232 std::stringstream table;
233 table << "* Tracking stations for " << ConcreteDetector::GetDetectorName() << " *";
234 table << format(
235 "\n|{:>5}|{:>8}|{:>14}|{:>14}|{:>14}|{:>14}|{:>14}|{:>14}|{:>8}|{:>8}|{:>8}|{:>8}|{:>8}|{:>8}|{:>9}|\n", "st.No",
236 "zRef[cm]", "xMin(act.)[cm]", "xMax(act.)[cm]", "yMin(act.)[cm]", "yMax(act.)[cm]", "zMin(act.)[cm]",
237 "zMax(act.)[cm]", "xMin[cm]", "xMax[cm]", "yMin[cm]", "yMax[cm]", "zMin[cm]", "zMax[cm]", "time info");
238 table << format("|{0:->5}|{0:->8}|{0:->14}|{0:->14}|{0:->14}|{0:->14}|{0:->14}|{0:->14}|{0:->8}|{0:->8}"
239 "|{0:->8}|{0:->8}|{0:->8}|{0:->8}|{0:->9}|\n",
240 "");
241 for (int iSt = 0; iSt < GetNofTrackingStations(); ++iSt) {
242 const auto& volA = GetActiveVolume(iSt);
243 const auto& volF = GetFullVolume(iSt);
244 table << format(
245 "|{:>5d}|{:>8.2f}|{:>14.2f}|{:>14.2f}|{:>14.2f}|{:>14.2f}|{:>14.2f}|{:>14.2f}|{:>8.2f}|{:>8.2f}|{:>"
246 "8.2f}|{:>8.2f}|{:>8.2f}|"
247 "{:>8.2f}|{:>9}|\n",
248 iSt, volA.GetCenterZ(), volA.GetMinX(), volA.GetMaxX(), volA.GetMinY(), volA.GetMaxY(), volA.GetMinZ(),
249 volA.GetMaxZ(), volF.GetMinX(), volF.GetMaxX(), volF.GetMinY(), volF.GetMaxY(), volF.GetMinZ(), volF.GetMaxZ(),
250 IsTimeInfoProvided(iSt));
251 }
252 return table.str();
253 }
254} // namespace cbm::algo
255
256#endif // ALGO_RecoTrackingSetupIfs_h
HitType
Definition CbmHit.h:25
A class for a geometrical volume representation in the reconstruction setup.
bool first
A representation of a geometrical volume of different tracking stations.
Definition GeoVolume.h:25
virtual ~TrackingSetupIfs()=default
Destructor.
TrackingSetupIfs(TrackingSetupIfs &&)=default
const GeoVolume & GetActiveVolume(int stationId) const
Gets active volume for a tracking station.
std::vector< GeoVolume > fvStationFullVolumes
Geometric properties of each station passive volume.
int GetTrackingStationId(uint32_t address) const
Gets a local index of a tracking station by a hardware address.
int GetNofTrackingStations() const
Gets number of tracking stations.
std::string TableOfTrackingStations() const
Dumps table of tracking stations to string.
const GeoVolume & GetFullVolume(int stationId) const
Gets full volume for a tracking station.
HitRange ImplGetHitRange(const HitType &hit) const
Returns default hit range factor.
bool IsTimeInfoProvided(int stationId) const
Checks, if station provides time measurements.
TrackingSetupIfs(const TrackingSetupIfs &)=default
TrackingSetupIfs & operator=(TrackingSetupIfs &&)=default
void serialize(Archive &ar, const unsigned int)
HitRange GetHitRange(const HitType &hit) const
Returns default hit range for x, y and time measurements.
TrackingSetupIfs & operator=(const TrackingSetupIfs &)=default
TrackingSetupIfs(std::pair< std::vector< GeoVolume >, std::vector< GeoVolume > > &&volumes)
Constructor from parameters.
friend class boost::serialization::access
Serialization method.
std::vector< GeoVolume > fvStationActiveVolumes
Geometric properties of each station active volume.
bool IsValid() const
Validates the interface.
Hash for CbmL1LinkKey.
A structure to keep the ranges of the hit x, y and time measurements.
double t
range for a time measurement [ns]
double y
range for an y-measurement [cm]
constexpr HitRange(double x_, double y_, double t_)
Constructor from parameters.
void serialize(Archive &ar, const unsigned int)
double x
range for an x-measurement [cm]
friend class boost::serialization::access
serialization method
constexpr HitRange()=default
Default constructor.