CbmRoot
Loading...
Searching...
No Matches
CbmTrackingDetectorInterfaceBase.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
11
12#include <Logger.h>
13
14#include <TGeoManager.h>
15#include <TGeoNode.h>
16#include <TString.h>
17
18#include <iomanip>
19#include <limits>
20#include <set>
21#include <vector>
22
23#include <fmt/format.h>
24
25// ---------------------------------------------------------------------------------------------------------------------
26//
28{
29 bool res = true;
30 LOG(info) << ToString();
31 std::stringstream msg;
32 msg << "Errors in the detector interface initialization for " << this->GetDetectorName() << ":\n";
33
34 // Number of stations
35 if (this->GetNtrackingStations() < 1) {
36 msg << "\t- Number of stations is less then 1(" << this->GetNtrackingStations() << ")";
37 res = false && res;
38 }
39 else {
40 // Station individual parameters check
41 for (int iSt = 0; iSt < this->GetNtrackingStations(); ++iSt) {
42 std::string prefix = std::string("\t- Station ") + std::to_string(iSt) + " has ";
43
44 { // Position along Z-axis
45 double z0 = this->GetZmin(iSt);
46 double z1 = this->GetZref(iSt);
47 double z2 = this->GetZmax(iSt);
48 if (!std::isfinite(z0) || !std::isfinite(z1) || !std::isfinite(z2) || !(z0 < z1 && z1 < z2)) {
49 msg << prefix << " wrong Z position (" << z0 << " < " << z1 << " < " << z2 << " cm)\n";
50 res = false && res;
51 }
52 }
53
54 { // Size along X-axis
55 auto xMax = this->GetXmax(iSt);
56 auto xMin = this->GetXmin(iSt);
57 if (!(xMax > xMin) || std::isnan(xMax) || std::isnan(xMin)) {
58 msg << prefix << " zero, negative or NaN X-size (xMin = " << xMin << ", xMax = " << xMax << " cm)\n";
59 res = false && res;
60 }
61 }
62
63 { // Size along Y-axis
64 auto yMax = this->GetYmax(iSt);
65 auto yMin = this->GetYmin(iSt);
66 if (!(yMax > yMin) || std::isnan(yMax) || std::isnan(yMin)) {
67 msg << prefix << " zero, negative or NaN Y-size (yMin = " << yMin << ", yMax = " << yMax << " cm)\n";
68 res = false && res;
69 }
70 }
71 }
72
73 { // Position along beam axis
74 std::vector<double> zPositions(this->GetNtrackingStations());
75 for (int iSt = 0; iSt < this->GetNtrackingStations(); ++iSt) {
76 zPositions[iSt] = this->GetZref(iSt);
77 }
78 std::set<double> zPositionSet(zPositions.begin(), zPositions.end());
79 if (zPositions.size() != zPositionSet.size()) {
80 msg << "\t- Some of stations have the same z position component:\n";
81 for (size_t iSt = 0; iSt < zPositions.size(); ++iSt) {
82 msg << "\t\tstation " << iSt << ", z = " << zPositions[iSt] << " cm\n";
83 }
84 res = false && res;
85 }
86 }
87 }
88
89 if (!res) {
90 LOG(error) << msg.str()
91 << "\033[4mErrors above mean that the CA tracking cannot be used with the current version of "
92 << this->GetDetectorName() << " setup. Please, check if the " << this->GetDetectorName()
93 << " setup parameters and the corresponding tracking detector interface are initialized properly\033[0m";
94 }
95
96 return res;
97}
98
99// ---------------------------------------------------------------------------------------------------------------------
100//
102{
103 // TODO: Add verbosity level, probably distribute properties into several tables
104 using fmt::format;
105 std::stringstream table;
106 table << format(
107 "\n|{:>5}|{:>9}|{:>17}|{:>17}|{:>17}|{:>17}|{:>17}|{:>17}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|\n", "st.No",
108 "z_ref[cm]", "x_min(active)[cm]", "x_max(active)[cm]", "y_min(active)[cm]", "y_max(active)[cm]",
109 "z_min(active)[cm]", "z_max(active)[cm]", "x_min[cm]", "x_max[cm]", "y_min[cm]", "y_max[cm]", "z_min[cm]",
110 "z_max[cm]", "time info");
111 table << format("|{0:->5}|{0:->9}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->9}|{0:->9}"
112 "|{0:->9}|{0:->9}|{0:->9}|{0:->9}|{0:->9}|\n",
113 "");
114 for (int iSt = 0; iSt < GetNtrackingStations(); ++iSt) {
115 table << format("|{:>5d}|{:>9.2f}|{:>17.2f}|{:>17.2f}|{:>17.2f}|{:>17.2f}|{:>17.2f}|{:>17.2f}|{:>9.2f}|{:>9.2f}|{:>"
116 "9.2f}|{:>9.2f}|{:>9.2f}|"
117 "{:>9.2f}|{:>9}|\n",
118 iSt, GetZref(iSt), GetActiveXmin(iSt), GetActiveXmax(iSt), GetActiveYmin(iSt), GetActiveYmax(iSt),
119 GetActiveZmin(iSt), GetActiveZmax(iSt), GetXmin(iSt), GetXmax(iSt), GetYmin(iSt), GetYmax(iSt),
120 GetZmin(iSt), GetZmax(iSt), IsTimeInfoProvided(iSt));
121 }
122 return table.str();
123}
124
125// ---------------------------------------------------------------------------------------------------------------------
126//
127std::vector<TString> CbmTrackingDetectorInterfaceBase::CollectNodes(const TString& detector, const TString& component,
128 const TString& path, TGeoNode* pNode)
129{
130 std::vector<TString> vPaths;
131
132 if (!pNode) {
133 return vPaths;
134 }
135
136 TString nodePath = path + (path.IsNull() ? "" : "/") + pNode->GetName();
137
138 if (TString(pNode->GetName()).Contains(component, TString::kIgnoreCase)) {
139 if (nodePath.Contains(detector, TString::kIgnoreCase)) {
140 vPaths.push_back(nodePath);
141 }
142 }
143
144 for (int iNode = 0; iNode < pNode->GetNdaughters(); ++iNode) {
145 TGeoNode* pDaughter = pNode->GetDaughter(iNode);
146 auto daughterPaths = CollectNodes(detector, component, nodePath, pDaughter);
147 vPaths.insert(vPaths.end(), daughterPaths.begin(), daughterPaths.end());
148 }
149 return vPaths;
150}
151
152// ---------------------------------------------------------------------------------------------------------------------
153//
155{
156 VolumeInfo res;
157 if (!gGeoManager->cd(path)) {
158 std::stringstream msg;
159 msg << "Node with path " << path << " is not found in the geo manager";
160 throw std::runtime_error(msg.str());
161 }
162
163 auto* matrix{gGeoManager->GetCurrentMatrix()};
164 const double* translation{matrix->GetTranslation()};
165 auto* volume{gGeoManager->GetCurrentVolume()};
166 auto* shape{volume->GetShape()};
167 auto GetDimension = [&](int iD) {
168 double min;
169 double max;
170 shape->GetAxisRange(iD + 1, min, max);
171 return std::make_pair<double, double>(min + translation[iD], max + translation[iD]);
172 };
173 std::tie(res.fXmin, res.fXmax) = GetDimension(0);
174 std::tie(res.fYmin, res.fYmax) = GetDimension(1);
175 std::tie(res.fZmin, res.fZmax) = GetDimension(2);
176 return res;
177}
178
179
180// ---------------------------------------------------------------------------------------------------------------------
181//
183{
184 std::stringstream msg;
185 msg << "zRef = " << 0.5 * (fZmin + fZmax) << "zMin = " << fZmin << ", zMax = " << fZmax << ", xMin = " << fXmin
186 << ", xMax = " << fXmax << ", yMin = " << fYmin << ", yMax = " << fYmax;
187 return msg.str();
188}
Base abstract class for tracking detector interface to L1 (implementation of Checker)
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
double GetYmin(int stationId) const
Gets lower bound of a station passive volume along the Y-axis.
int GetNtrackingStations() const
Gets actual number of stations, provided by the current geometry setup.
double GetZref(int stationId) const
Gets reference z of the station passive volume.
virtual std::string GetDetectorName() const =0
Returns the name of the detector subsystem.
double GetActiveXmin(int stationId) const
Gets lower bound of the station active volume along x-axis.
double GetActiveZmax(int stationId) const
Gets upper bound of the station active volume along z-axis.
std::string ToString() const
Prints all the parameters into table and saves the table as a string.
double GetActiveYmax(int stationId) const
Gets upper bound of the station active volume along y-axis.
double GetZmax(int stationId) const
Gets max z of the station passive volume.
virtual bool IsTimeInfoProvided(int stationId) const =0
Check if station provides time measurements.
VolumeInfo ReadVolume(const TString &path)
Creates volume info from a geo node provided by path.
std::vector< TString > CollectNodes(const TString &detector, const TString &component, const TString &path, TGeoNode *pNode)
Collects paths of the components.
double GetActiveYmin(int stationId) const
Gets lower bound of the station active volume along y-axis.
double GetXmin(int stationId) const
Gets lower bound of a station passive volume along the X-axis.
double GetYmax(int stationId) const
Gets upper bound of a station passive volume along the Y-axis.
double GetXmax(int stationId) const
Gets upper bound of a station passive volume along the X-axis.
double GetActiveZmin(int stationId) const
Gets lower bound of the station active volume along z-axis.
bool Check() const
Checks detector interface: boundary conditions of the parameters.
double GetActiveXmax(int stationId) const
Gets upper bound of the station active volume along x-axis.
double GetZmin(int stationId) const
Gets min z of the station passive volume.
Structure to store geometry information of each station.
std::string ToString() const
String representation of the structure.