CbmRoot
Loading...
Searching...
No Matches
CbmMuchRecoSetupUnitFactory.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 "CbmMuchAddress.h"
14#include "CbmMuchGeoScheme.h"
15#include "CbmMuchModuleGem.h"
16#include "CbmMuchPad.h"
17#include "CbmMuchStation.h"
18#include "CbmRecoSetupUtils.h"
19#include "CbmSetup.h"
20
21#include <Logger.h>
22
23#include <TGeoManager.h>
24#include <TString.h>
25#include <TSystem.h>
26
27#include <sstream>
28#include <utility>
29
33
34// ---------------------------------------------------------------------------------------------------------------------
35//
37try {
38 if (!CbmSetup::Instance()->IsActive(ECbmModuleId::kMuch)) {
39 throw std::runtime_error("MuCh is not in the setup, but the much::RecoSetupUnitFactory was called (this should "
40 "never happen!");
41 }
42
43 if (!CbmMuchGeoScheme::Instance()->IsInitialized()) {
44 TString geoTag;
46 TString parFile = gSystem->Getenv("VMCWORKDIR");
47 if (parFile.IsNull()) {
48 throw std::runtime_error("The VMCWORKDIR env. variable is required but not defined. Please, configure CbmRoot");
49 }
50 parFile += "/parameters/much/much_" + geoTag(0, 4) + "_digi_sector.root";
51 CbmMuchGeoScheme::Instance()->Init(parFile, static_cast<int>(geoTag.Contains("mcbm")));
52 }
53}
54catch (const std::exception& err) {
55 LOG(fatal)
56 << "much::RecoSetupUnitFactory cannot be constructed, because " << err.what() << ". Please ensure, if the "
57 << "required parameters are defined before the point of the much::RecoSetupUnitFactory object construction";
58}
59
60// ---------------------------------------------------------------------------------------------------------------------
61//
63{
65 if (!res.IsValid()) {
66 LOG(error) << res.TableOfTrackingStations();
67 LOG(fatal) << "much::RecoSetupUnitFactory: creation of a valid MuCh reco-setup unit failed";
68 }
69 return res;
70}
71
72// ---------------------------------------------------------------------------------------------------------------------
73//
75{
77 const auto* pGeoScheme = CbmMuchGeoScheme::Instance();
78 res.reserve(pGeoScheme->GetNStations() + 1);
79 res.push_back(0);
80 for (int iMuchSt = 0; iMuchSt < pGeoScheme->GetNStations(); ++iMuchSt) {
81 res.push_back(res.back() + pGeoScheme->GetStation(iMuchSt)->GetNLayers());
82 }
83 return res;
84}
85
86// ---------------------------------------------------------------------------------------------------------------------
87//
88std::pair<std::vector<GeoVolume>, std::vector<GeoVolume>> RecoSetupUnitFactory::CreateStationVolumes() const
89{
90 const auto* pGeoScheme = CbmMuchGeoScheme::Instance();
91
92 int nStations{0};
93 for (int iMuchSt = 0; iMuchSt < pGeoScheme->GetNStations(); ++iMuchSt) {
94 nStations += pGeoScheme->GetStation(iMuchSt)->GetNLayers();
95 }
96
97 std::vector<GeoVolume> fullVolumes(nStations);
98 std::vector<GeoVolume> activeVolumes(nStations);
99 std::regex rgxLayerPattern{"muchstation(\\d+)layer(\\d+)_(\\d+)"};
100 auto vLayerPaths{GeoHelper::CollectNodes("much", rgxLayerPattern, "", gGeoManager->GetTopNode())};
101
102 assert(static_cast<int>(vLayerPaths.size()) == nStations);
103 for (int iTrkSt = 0; iTrkSt < nStations; ++iTrkSt) {
104 const auto& layerPath = vLayerPaths[iTrkSt];
105 fullVolumes[iTrkSt] = RecoSetupUtils::ReadVolume(layerPath);
106 gGeoManager->cd(layerPath);
107 auto vActPaths{GeoHelper::CollectNodes("much", std::regex{"active"}, layerPath(0, layerPath.Last('/')),
108 gGeoManager->GetCurrentNode())};
109 if (vActPaths.empty()) {
110 throw std::runtime_error("Could not find nodes containing \"active\" in their paths");
111 }
112 for (const auto& activePath : vActPaths) {
113 activeVolumes[iTrkSt] += RecoSetupUtils::ReadVolume(activePath);
114 }
115 }
116
117 return {std::move(fullVolumes), std::move(activeVolumes)};
118}
@ kMuch
Muon detection system.
Definition CbmDefs.h:50
A multi-purpose class to access the geometrical information stored in a TGeoManager (source)
A factory for the MuCh RecoSetupUnit.
Different utilities for the CbmOfflineRecoSetup library (source)
static CbmMuchGeoScheme * Instance()
void Init(TObjArray *stations, Int_t flag)
Bool_t GetGeoTag(ECbmModuleId moduleId, TString &tag)
Definition CbmSetup.cxx:127
static CbmSetup * Instance()
Definition CbmSetup.cxx:160
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 MuCh RecoSetupUnit.
std::pair< std::vector< algo::GeoVolume >, std::vector< algo::GeoVolume > > CreateStationVolumes() const
Creates full and active volumes of the tracking stations.
OffsetContainer_t CreateStationIdOffsets() const
Creates tracking station offset container.
RecoSetupUnit_t Create() const
Creates a reconstruction setup unit.
typename RecoSetupUnit_t::OffsetContainer_t OffsetContainer_t
static algo::GeoVolume ReadVolume(const TString &path)
Creates a volume info from a geo node, provided by path.