CbmRoot
Loading...
Searching...
No Matches
CbmTofRecoSetupUnitFactory.cxx
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
11
12#include "CbmGeoHelper.h"
13#include "CbmRecoSetupUtils.h"
14#include "CbmTofDigiBdfPar.h"
15
16#include <FairRunAna.h>
17#include <FairRuntimeDb.h>
18#include <Logger.h>
19
20#include <TGeoManager.h>
21#include <TString.h>
22
23#include <iomanip>
24#include <limits>
25#include <regex>
26#include <set>
27#include <sstream>
28#include <unordered_set>
29#include <utility>
30
34
35
36// ---------------------------------------------------------------------------------------------------------------------
37//
39try {
40 //* Get the TOF digi parameters
41 // NOTE: add a task CbmTofCreateDigiPar, if the parameters appear to be corrupted. But in the use-cases of the
42 // builder it should not be so.
43 auto* runtimeDb = FairRunAna::Instance()->GetRuntimeDb();
44 if (!runtimeDb) {
45 throw std::runtime_error("the runtime database is not defined");
46 }
47
48 fDigiBdfPar = dynamic_cast<CbmTofDigiBdfPar*>(runtimeDb->getContainer("CbmTofDigiBdfPar"));
49 if (!fDigiBdfPar) {
50 throw std::runtime_error("TOF Digi BDF par. instance was not found in the runtime database");
51 }
52
53 if (fDigiBdfPar->GetNbSmTypes() == 0) {
54 throw std::runtime_error("TOF Digi BDF par. instance was not initialized (NbSmTypes = 0)");
55 }
56}
57catch (const std::exception& err) {
58 LOG(fatal) << "tof::RecoSetupUnitFactory cannot be constructed, because " << err.what() << ". Please ensure, if the "
59 << "required parameters are defined before the point of the sts::RecoSetupUnitFactory object construction";
60}
61
62// ---------------------------------------------------------------------------------------------------------------------
63//
65{
67 if (!res.IsValid()) {
68 LOG(fatal) << "tof::RecoSetupUnitFactory: creation of a valid TOF reco-setup unit failed";
69 }
70 return res;
71}
72
73// ---------------------------------------------------------------------------------------------------------------------
74//
76{
77 using SmTypeInfo_t = algo::tof::TrkStationIdMap::SmTypeInfo;
78
79 // 1. Fill the smTypeRpcMap
80 std::vector<SmTypeInfo_t> smTypeRpcMap(fDigiBdfPar->GetNbSmTypes());
81 uint16_t nRpcTot = 0;
82 for (uint16_t iSmType = 0; iSmType < smTypeRpcMap.size(); ++iSmType) {
83 auto& smt = smTypeRpcMap[iSmType];
84 smt.nSm = fDigiBdfPar->GetNbSm(iSmType);
85 smt.nRpc = fDigiBdfPar->GetNbRpc(iSmType);
86 nRpcTot += smt.nSm * smt.nRpc;
87 }
88
89 // 2. Fill the offsets in smTypeRpcMap
90 for (uint16_t iSmtThis = 0, iSmtNext = iSmtThis + 1; iSmtNext < smTypeRpcMap.size(); ++iSmtThis, ++iSmtNext) {
91 const auto smtThis{smTypeRpcMap[iSmtThis]};
92 smTypeRpcMap[iSmtNext].offset = smtThis.offset + smtThis.nSm * smtThis.nRpc;
93 }
94
95 // 3. Fill the tracking staiton indices
96 // NOTE: it is important to nest the loop in this direction: iSmType -> iSm -> iRpc!
97 std::vector<int> trkStationId;
98 trkStationId.reserve(nRpcTot);
99 for (uint16_t iSmType = 0; iSmType < smTypeRpcMap.size(); ++iSmType) {
100 const auto smt{smTypeRpcMap[iSmType]};
101 for (uint16_t iSm = 0; iSm < smt.nSm; ++iSm) {
102 for (uint16_t iRpc = 0; iRpc < smt.nRpc; ++iRpc) {
103 trkStationId.push_back(fDigiBdfPar->GetTrackingStation(iSmType, iSm, iRpc));
104 }
105 }
106 }
107
108 return algo::tof::TrkStationIdMap(std::move(smTypeRpcMap), std::move(trkStationId));
109}
110
111// ---------------------------------------------------------------------------------------------------------------------
112//
113std::pair<std::vector<GeoVolume>, std::vector<GeoVolume>> RecoSetupUnitFactory::CreateStationVolumes() const
114{
115 int nStations = fDigiBdfPar->GetNbTrackingStations();
116 if (nStations == 0) {
117 return {};
118 }
119
120 std::vector<algo::GeoVolume> fullVolumes(nStations);
121 std::vector<algo::GeoVolume> activeVolumes(nStations);
122 auto vRpcPaths{GeoHelper::CollectNodes("tof", std::regex{"counter"}, "", gGeoManager->GetTopNode())};
123 std::regex rpcPattern{"module_(\\d+)_(\\d+)/gas_box_(\\d+)/counter_(\\d+)"};
124
125 for (const auto& rpcPath : vRpcPaths) {
126 std::smatch match;
127 std::string line{rpcPath.Data()};
128 if (std::regex_search(line, match, rpcPattern)) {
129 int iSmType{std::stoi(match[1])};
130 int iSm{std::stoi(match[2])};
131 int iRpc{std::stoi(match[4])};
132 int iStation{fDigiBdfPar->GetTrackingStation(iSmType, iSm, iRpc)};
133 if (iStation > -1) {
134 auto rpcVol = RecoSetupUtils::ReadVolume(rpcPath); // Adding RPC as a passive volume
135 fullVolumes[iStation] += rpcVol; // Adding RPC as a passive volume
136 gGeoManager->cd(rpcPath);
137 auto vCellPaths{GeoHelper::CollectNodes("tof", std::regex{"Cell_(\\d+)"}, rpcPath(0, rpcPath.Last('/')),
138 gGeoManager->GetCurrentNode())};
139 if (vCellPaths.empty()) {
140 throw std::runtime_error("Could not find nodes containing \"Cell\" in their paths");
141 }
142
143 for (const auto& cellPath : vCellPaths) {
144 activeVolumes[iStation] += RecoSetupUtils::ReadVolume(cellPath);
145 }
146 }
147 }
148 }
149
150 return {std::move(fullVolumes), std::move(activeVolumes)};
151}
A multi-purpose class to access the geometrical information stored in a TGeoManager (source)
Different utilities for the CbmOfflineRecoSetup library (source)
A factory for the TOF RecoSetupUnit.
Parameters class for the CBM ToF digitizer using beam data distributions.
RecoSetupUnitFactory()
Default constructor (check for parameter containers)
static std::vector< TString > CollectNodes(const TString &detector, const std::regex &component, const TString &path, TGeoNode *pNode)
Collects paths of the components.
A representation of a geometrical volume of different tracking stations.
Definition GeoVolume.h:25
TOF detector representation in online/offline reconstruction.
A mapper for TOF tracking stations.
A builder class for the STS RecoSetupUnit.
std::pair< std::vector< algo::GeoVolume >, std::vector< algo::GeoVolume > > CreateStationVolumes() const
Creates full and active volumes of the tracking stations.
algo::tof::TrkStationIdMap TrkStationIdMap_t
TrkStationIdMap_t CreateStationIdMap() const
Creates the tracking station ID map.
RecoSetupUnit_t Create() const
Creates a reconstruction setup unit.
static algo::GeoVolume ReadVolume(const TString &path)
Creates a volume info from a geo node, provided by path.
Information on RPC offsets for each SM type.