Skip to content
Snippets Groups Projects

Update of tracking detector interfaces

Merged Sergei Zharko requested to merge s.zharko/cbmroot:bugfix-det-ifs into master

Files

/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
/* Copyright (C) 2022-2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Sergey Gorbunov, Sergei Zharko [committer] */
@@ -11,11 +11,17 @@
#include <Logger.h>
#include <TGeoManager.h>
#include <TGeoNode.h>
#include <TString.h>
#include <iomanip>
#include <limits>
#include <set>
#include <vector>
#include <fmt/format.h>
// ---------------------------------------------------------------------------------------------------------------------
//
bool CbmTrackingDetectorInterfaceBase::Check() const
@@ -94,32 +100,87 @@ bool CbmTrackingDetectorInterfaceBase::Check() const
//
std::string CbmTrackingDetectorInterfaceBase::ToString() const
{
using std::setfill;
using std::setw;
// TODO: Add verbosity level, probably distribute properties into several tables
using fmt::format;
std::stringstream table;
table << std::boolalpha;
table << "\nTracking detector interface: " << setw(5) << GetDetectorName() << '\n';
table << setw(5) << "st.No" << ' ';
table << setw(10) << "z_ref[cm]" << ' ';
table << setw(10) << "z_min[cm]" << ' ';
table << setw(10) << "z_max[cm]" << ' ';
table << setw(10) << "x_min[cm]" << ' ';
table << setw(10) << "x_max[cm]" << ' ';
table << setw(10) << "y_min[cm]" << ' ';
table << setw(10) << "y_max[cm]" << ' ';
table << setw(10) << "time info" << ' ';
table << '\n';
table << format("|{:>5}|{:>9}|{:>17}|{:>17}|{:>17}|{:>17}|{:>17}|{:>17}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|{:>9}|\n",
"st.No", "z_ref[cm]", "x_min(active)[cm]", "x_max(active)[cm]", "y_min(active)[cm]",
"y_max(active)[cm]", "z_min(active)[cm]", "z_max(active)[cm]", "x_min[cm]", "x_max[cm]", "y_min[cm]",
"y_max[cm]", "z_min[cm]", "z_max[cm]", "time info");
table << format("|{0:->5}|{0:->9}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->17}|{0:->9}|{0:->9}"
"|{0:->9}|{0:->9}|{0:->9}|{0:->9}|{0:->9}|\n",
"");
for (int iSt = 0; iSt < GetNtrackingStations(); ++iSt) {
table << setw(5) << iSt << ' ';
table << setw(10) << GetZref(iSt) << ' ';
table << setw(10) << GetZmin(iSt) << ' ';
table << setw(10) << GetZmax(iSt) << ' ';
table << setw(10) << GetXmin(iSt) << ' ';
table << setw(10) << GetXmax(iSt) << ' ';
table << setw(10) << GetYmin(iSt) << ' ';
table << setw(10) << GetYmax(iSt) << ' ';
table << setw(10) << IsTimeInfoProvided(iSt) << ' ';
table << '\n';
table << format("|{:>5d}|{:>9f}|{:>17f}|{:>17f}|{:>17f}|{:>17f}|{:>17f}|{:>17f}|{:>9f}|{:>9f}|{:>9f}|{:>9f}|{:>9f}|"
"{:>9f}|{:>9}|\n",
iSt, GetZref(iSt), GetActiveXmin(iSt), GetActiveXmax(iSt), GetActiveYmin(iSt), GetActiveYmax(iSt),
GetActiveZmin(iSt), GetActiveZmax(iSt), GetXmin(iSt), GetXmax(iSt), GetYmin(iSt), GetYmax(iSt),
GetZmin(iSt), GetZmax(iSt), IsTimeInfoProvided(iSt));
}
return table.str();
}
// ---------------------------------------------------------------------------------------------------------------------
//
std::vector<TString> CbmTrackingDetectorInterfaceBase::CollectNodes(const TString& detector, const TString& component,
const TString& path, TGeoNode* pNode)
{
std::vector<TString> vPaths;
if (!pNode) {
return vPaths;
}
TString nodePath = path + (path.IsNull() ? "" : "/") + pNode->GetName();
if (TString(pNode->GetName()).Contains(component, TString::kIgnoreCase)) {
if (nodePath.Contains(detector, TString::kIgnoreCase)) {
vPaths.push_back(nodePath);
}
}
for (int iNode = 0; iNode < pNode->GetNdaughters(); ++iNode) {
TGeoNode* pDaughter = pNode->GetDaughter(iNode);
auto daughterPaths = CollectNodes(detector, component, nodePath, pDaughter);
vPaths.insert(vPaths.end(), daughterPaths.begin(), daughterPaths.end());
}
return vPaths;
}
// ---------------------------------------------------------------------------------------------------------------------
//
CbmTrackingDetectorInterfaceBase::VolumeInfo CbmTrackingDetectorInterfaceBase::ReadVolume(const TString& path)
{
VolumeInfo res;
if (!gGeoManager->cd(path)) {
std::stringstream msg;
msg << "Node with path " << path << " is not found in the geo manager";
throw std::runtime_error(msg.str());
}
auto* matrix{gGeoManager->GetCurrentMatrix()};
const double* translation{matrix->GetTranslation()};
auto* volume{gGeoManager->GetCurrentVolume()};
auto* shape{volume->GetShape()};
auto GetDimension = [&](int iD) {
double min;
double max;
shape->GetAxisRange(iD + 1, min, max);
return std::make_pair<double, double>(min + translation[iD], max + translation[iD]);
};
std::tie(res.fXmin, res.fXmax) = GetDimension(0);
std::tie(res.fYmin, res.fYmax) = GetDimension(1);
std::tie(res.fZmin, res.fZmax) = GetDimension(2);
return res;
}
// ---------------------------------------------------------------------------------------------------------------------
//
std::string CbmTrackingDetectorInterfaceBase::VolumeInfo::ToString() const
{
std::stringstream msg;
msg << "zRef = " << 0.5 * (fZmin + fZmax) << "zMin = " << fZmin << ", zMax = " << fZmax << ", xMin = " << fXmin
<< ", xMax = " << fXmax << ", yMin = " << fYmin << ", yMax = " << fYmax;
return msg.str();
}
Loading