CbmRoot
Loading...
Searching...
No Matches
CbmTrdRecoSetupUnitFactory.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 "CbmTrdParModDigi.h"
15#include "CbmTrdParSetDigi.h"
16
17#include <FairRunAna.h>
18#include <FairRuntimeDb.h>
19#include <Logger.h>
20
21#include <TGeoManager.h>
22#include <TString.h>
23
24#include <limits>
25#include <regex>
26#include <set>
27#include <sstream>
28#include <utility>
29
30
34
35// ---------------------------------------------------------------------------------------------------------------------
36//
38try {
39 //* Get the TOF digi parameters
40 // NOTE: add a task CbmTofCreateDigiPar, if the parameters appear to be corrupted. But in the use-cases of the
41 // builder it should not be so.
42 auto* runtimeDb = FairRunAna::Instance()->GetRuntimeDb();
43 if (!runtimeDb) {
44 throw std::runtime_error("the runtime database is not defined");
45 }
46 fTrdDigiPar = dynamic_cast<CbmTrdParSetDigi*>(runtimeDb->getContainer("CbmTrdParSetDigi"));
47}
48catch (const std::exception& err) {
49 LOG(fatal) << "trd::RecoSetupUnitFactory cannot be constructed, because " << err.what() << ". Please ensure, if the "
50 << "required parameters are defined before the point of the sts::RecoSetupUnitFactory object construction";
51}
52
53// ---------------------------------------------------------------------------------------------------------------------
54//
56{
58 if (!res.IsValid()) {
59 LOG(fatal) << "trd::RecoSetupUnitFactory: creation of a valid TRD reco-setup unit failed";
60 }
61 return res;
62}
63
64// ---------------------------------------------------------------------------------------------------------------------
65//
67{
69
70 //* 1st loop: calculate total number of layers, check the assumption about the same number of modules in a layer
71 auto& nModulesPerLayer = res.second;
72 {
73 std::unordered_map<int, uint32_t> nModulesInLayer;
74 for (int iModule = 0; iModule < fTrdDigiPar->GetNrOfModules(); ++iModule) {
75 ++nModulesInLayer[CbmTrdAddress::GetLayerId(fTrdDigiPar->GetModuleId(iModule))];
76 }
77 nModulesPerLayer = nModulesInLayer.begin()->second;
78 if (std::any_of(nModulesInLayer.begin(), nModulesInLayer.end(),
79 [nModulesPerLayer](const auto& entry) -> bool { return entry.second != nModulesPerLayer; })) {
80 LOG(fatal) << "trd::RecoSetupUnitFactory: TRD layers have different number of modules (assumption failure)";
81 }
82 }
83
84 //* 2nd loop: Collect module info
85 auto& modules = res.first;
86 modules.resize(fTrdDigiPar->GetNrOfModules());
87
88 for (int iModule = 0; iModule < fTrdDigiPar->GetNrOfModules(); ++iModule) {
89 uint32_t address = fTrdDigiPar->GetModuleId(iModule);
90 if (const auto* pDigiPar = dynamic_cast<const CbmTrdParModDigi*>(fTrdDigiPar->GetModulePar(address))) {
91 uint32_t moduleId = CbmTrdAddress::GetModuleId(address);
92 uint32_t layerId = CbmTrdAddress::GetLayerId(address);
93 modules[layerId * nModulesPerLayer + moduleId] =
94 RecoSetupUnit_t::ModuleInfo{pDigiPar->GetOrientation(), pDigiPar->GetPadPlaneType()};
95 }
96 else {
97 LOG(fatal) << "trd::RecoSetupUnitFactory: undefined digi parameters for module 0x" << std::hex << address;
98 }
99 }
100
101 return res;
102}
103
104// ---------------------------------------------------------------------------------------------------------------------
105//
106std::pair<std::vector<GeoVolume>, std::vector<GeoVolume>> RecoSetupUnitFactory::CreateStationVolumes() const
107{
108 auto vLayerPaths{GeoHelper::CollectNodes("trd", std::regex{"layer"}, "", gGeoManager->GetTopNode())};
109 std::vector<GeoVolume> fullVolumes(vLayerPaths.size());
110 std::vector<GeoVolume> activeVolumes(vLayerPaths.size());
111 std::regex stationPattern{"layer(\\d+)_(\\d+)"};
112 for (const auto& layerPath : vLayerPaths) {
113 std::smatch match;
114 std::string line{layerPath.Data()};
115 if (std::regex_search(line, match, stationPattern)) {
116 int iStation{std::stoi(match[1]) - 1}; // the tracking station is a TRD layer
117 fullVolumes[iStation] = RecoSetupUtils::ReadVolume(layerPath);
118 gGeoManager->cd(layerPath);
119 auto vGasPaths{GeoHelper::CollectNodes("trd", std::regex{"gas"}, layerPath(0, layerPath.Last('/')),
120 gGeoManager->GetCurrentNode())};
121 for (const auto& gasPath : vGasPaths) {
122 activeVolumes[iStation] += RecoSetupUtils::ReadVolume(gasPath);
123 }
124 }
125 }
126 return {std::move(fullVolumes), std::move(activeVolumes)};
127}
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.
static uint32_t GetModuleId(uint32_t address)
Return module ID from address.
static uint32_t GetLayerId(uint32_t address)
Return layer ID from address.
Definition of chamber gain conversion for one TRD module.
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
A factory 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.
ModuleInfoMap_t CreateModuleMap() const
Creates TRD module type map.
CbmTrdParSetDigi * fTrdDigiPar
TRD digitization parameters.
RecoSetupUnit_t Create() const
Creates a reconstruction setup unit.
typename RecoSetupUnit_t::ModuleInfoMap_t ModuleInfoMap_t
static algo::GeoVolume ReadVolume(const TString &path)
Creates a volume info from a geo node, provided by path.
Different characteristics of TRD module.