CbmRoot
Loading...
Searching...
No Matches
CbmStsRecoSetupUnitFactory.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 "CbmStsParSetModule.h"
13#include "CbmStsParSetSensor.h"
15#include "CbmStsSetup.h"
16#include "CbmStsStation.h"
18
19#include <FairRunAna.h>
20#include <FairRuntimeDb.h>
21#include <Logger.h>
22
23#include <TGeoManager.h>
24#include <TString.h>
25
26#include <set>
27#include <sstream>
28#include <utility>
29
33
34// ---------------------------------------------------------------------------------------------------------------------
35//
37try {
38 auto* stsSetup = CbmStsSetup::Instance();
39 if (!stsSetup->IsInit()) {
40 stsSetup->Init(nullptr);
41 }
42}
43catch (const std::exception& err) {
44 LOG(fatal) << "sts::RecoSetupUnitFactory cannot be constructed, because " << err.what() << ". Please ensure, if the "
45 << "required parameters are defined before the point of the sts::RecoSetupUnitFactory object construction";
46}
47
48// ---------------------------------------------------------------------------------------------------------------------
49//
51{
53 if (!res.IsValid()) {
54 LOG(fatal) << "sts::RecoSetupUnitFactory: creation of a valid STS reco-setup unit failed";
55 }
56 return res;
57}
58
59// ---------------------------------------------------------------------------------------------------------------------
60//
62{
64
65 auto* stsSetup = CbmStsSetup::Instance();
66
67 // Fill a set of (stationId, ladderId) pairs, corresponding to a given unit
68 std::vector<std::set<std::pair<int, uint32_t>>> units(stsSetup->GetNofDaughters());
69 for (int iSt = 0; iSt < stsSetup->GetNofStations(); ++iSt) {
70 CbmStsStation* station = stsSetup->GetStation(iSt);
71 for (int iLadder = 0; iLadder < station->GetNofLadders(); ++iLadder) {
72 const CbmStsElement* ladder = station->GetLadder(iLadder);
73 units[ladder->GetMother()->GetIndex()].insert({iSt, ladder->GetIndex()});
74 }
75 }
76
77 // Fill the stationId map
78 res.resize(units.size(), std::pair{std::numeric_limits<uint32_t>::max(), -1});
79 for (size_t iUnit = 0; iUnit < units.size(); ++iUnit) {
80 const auto& unit = units[iUnit];
81 if (!unit.size()) continue; // formally
82
83 auto& stationIdMapElement = res[iUnit];
84 stationIdMapElement.second = (*unit.begin()).first;
85 int curStationId = stationIdMapElement.second;
86 for (const auto& [stationId, ladderId] : unit) {
87 if (stationId != curStationId) {
88 stationIdMapElement.first = ladderId;
89 curStationId = stationId;
90 }
91 }
92
93 // A difference between the minimal and maximal station ID within a unit. It reflects the convention,
94 // that ladders are sorted in a unit by a station ID, and there are can be no more then two units attached
95 // to a single station, so the valid values are either 0 or 1.
96 int diffStationId = curStationId - stationIdMapElement.second;
97 if (diffStationId != 0 && diffStationId != 1) {
98 std::stringstream msg;
99 msg << "Failed to build a map of STS address to STS station index for unitId=" << iUnit << ". "
100 << "The convention for distribution ladders over units was corrupted, and the current mapping"
101 << "scheme cannot be initialized. "
102 << "NOTE: the current map implementation relies on the next points:\n"
103 << " (1) ladders on a unit are attached to a single or two neighboring stations;\n"
104 << " (2) ladders within a unit are ordered in stationId\n"
105 << "Ladders, attached to the unitId=" << iUnit << " : ";
106 for (const auto& p : units[iUnit]) {
107 msg << "(stationId=" << p.first << ", ladderId=" << p.second << ")";
108 }
109 throw std::logic_error(msg.str());
110 }
111 }
112 return res;
113}
114
115// ---------------------------------------------------------------------------------------------------------------------
116//
117std::pair<std::vector<GeoVolume>, std::vector<GeoVolume>> RecoSetupUnitFactory::CreateStationVolumes() const
118{
119 auto* stsSetup = CbmStsSetup::Instance();
120 int nStations = stsSetup->GetNofStations();
121 std::vector<GeoVolume> fullVolumes;
122 fullVolumes.reserve(nStations);
123 for (int iSt = 0; iSt < nStations; ++iSt) {
124 const auto* pStation{stsSetup->GetStation(iSt)};
125 fullVolumes.emplace_back(pStation->GetXmin(), pStation->GetXmax(), pStation->GetYmin(), pStation->GetYmax(),
126 pStation->GetZmin(), pStation->GetZmax());
127 }
128
129 std::vector<GeoVolume> activeVolumes = fullVolumes;
130 return {std::move(fullVolumes), std::move(activeVolumes)};
131}
A factory for the STS RecoSetupUnit.
A header for the reconstructed setup and reconstructed setup-units.
Class representing an element of the STS setup.
CbmStsElement * GetMother() const
Int_t GetIndex() const
static CbmStsSetup * Instance()
Class representing a station of the StsSystem.
Int_t GetNofLadders() const
const CbmStsElement * GetLadder(Int_t iLadder) const
RecoSetupUnitFactory()
Default constructor (check for parameter containers)
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.
StationIdMap_t CreateStationIdMap() const
Fills the tracking station ID mapping.
RecoSetupUnit_t Create() const
Creates a reconstruction setup unit.
typename RecoSetupUnit_t::StationIdMap_t StationIdMap_t