CbmRoot
Loading...
Searching...
No Matches
KfModuleIndexMap.cxx
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "KfModuleIndexMap.h"
11
12namespace cbm::algo::kf
13{
14 // -------------------------------------------------------------------------------------------------------------------
15 //
17 {
18 fvLocToGlb.clear();
19 fvGlbToLoc.clear();
20 fvDetLocOffset.clear();
21 fvDetIntToExt.clear();
22 fvDetExtToInt.clear();
23 }
24
25 // -------------------------------------------------------------------------------------------------------------------
26 //
27 std::string ModuleIndexMap::ToString(int indentLevel) const
28 {
29 using fmt::format;
30 constexpr char IndentCh = '\t';
31 std::string indent(indentLevel, IndentCh);
32 std::stringstream msg;
33 msg << indent << format("{:>8} {:>8} {:>8}\n", "det.ID", "loc.ID", "glob.ID");
34 for (int iGlb = 0; iGlb < GetNofLayers(); ++iGlb) {
35 const auto& [iDetExt, iLoc] = fvGlbToLoc[iGlb];
36 msg << indent << format("{:>8} {:>8} {:>8}\n", iDetExt, iLoc, iGlb);
37 }
38
39 return msg.str();
40 }
41
42 // -------------------------------------------------------------------------------------------------------------------
43 //
45 {
46 ModuleIndexMap indexMap;
47
48 auto& vDetIntToExt = indexMap.fvDetIntToExt;
49 auto& vDetExtToInt = indexMap.fvDetExtToInt;
50 auto& vDetLocOffset = indexMap.fvDetLocOffset;
51 auto& vLocToGlb = indexMap.fvLocToGlb;
52 auto& vGlbToLoc = indexMap.fvGlbToLoc;
53
54 // ------- Component layout
55 // Initialization of internal and external detector subsystem mapping
56 for (const auto& component : fvComponentLayers) {
57 auto iDetExt = component.fDetId;
58 if (iDetExt < 0) {
59 std::stringstream msg;
60 msg << "ModuleIndexMapFactory::MakeIndexMap: illegal detector subsystem enumeration: " << iDetExt
61 << " is out of range [0, " << defs::MaxNofDetSubsystems << "). Enties of the EDetID enumeration are "
62 << "required to be non-negative";
63 throw std::out_of_range(msg.str());
64 }
65 if (iDetExt >= static_cast<int>(vDetExtToInt.size())) {
66 vDetExtToInt.resize(iDetExt + 1, -1);
67 }
68
69 if (vDetExtToInt[iDetExt] == -1) { // Detector subsystem is not registered
70 // Assign an internal index to the detID:
71 vDetExtToInt[iDetExt] = static_cast<int>(vDetIntToExt.size());
72 vDetIntToExt.push_back(iDetExt);
73 }
74 }
75 { // Estimate offsets
76 int nDet = vDetIntToExt.size();
77 vDetLocOffset.resize(nDet + 1, 0);
78 for (const auto& component : fvComponentLayers) {
79 int pick = vDetExtToInt[component.fDetId] + 1;
80 vDetLocOffset[pick] = std::max(vDetLocOffset[pick], component.fLocId + 1);
81 }
82 for (int iDet{0}; iDet < nDet; ++iDet) {
83 vDetLocOffset[iDet + 1] += vDetLocOffset[iDet];
84 }
85 }
86
87 vLocToGlb.resize(vDetLocOffset.back(), -1);
88 vGlbToLoc.resize(fvComponentLayers.size());
89 for (auto itComp = fvComponentLayers.cbegin(); itComp != fvComponentLayers.cend(); ++itComp) {
90 const auto& component{*itComp};
91 int iDetInt = vDetExtToInt[component.fDetId];
92 int iLoc = component.fLocId;
93 int iGlb = std::distance(fvComponentLayers.begin(), itComp);
94 vLocToGlb[vDetLocOffset[iDetInt] + iLoc] = iGlb;
95 vGlbToLoc[iGlb] = std::pair(component.fDetId, iLoc);
96 }
97
98 return indexMap;
99 }
100
101 // -------------------------------------------------------------------------------------------------------------------
102 //
104} // namespace cbm::algo::kf
A helper class to map external indices with the ones of KF-setup.
ModuleIndexMap MakeIndexMap() const
Creates a module index map.
Maps local detector and station indices to the material maps and field slices.
void Reset()
Resets the instance.
std::vector< int > fvDetLocOffset
First index of component for det.
std::vector< int > fvDetIntToExt
Maps external detID to internal.
int GetNofLayers() const
Gets total number of components.
std::string ToString(int indentLevel=0) const
String representation of the instance.
std::vector< std::pair< int, int > > fvGlbToLoc
std::vector< int > fvDetExtToInt
Maps internal detID to external.
constexpr int MaxNofDetSubsystems
Max number of detector types (STS, TRD, RICH,...)
Definition KfDefs.h:75