BmnRoot 26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnDetectorModel.h
Go to the documentation of this file.
1/*
2 BM@N alignment routine
3 BM@N experiment at NICA complex, JINR, 2025
4
5 Department: Math & Soft Group of HEP lab
6 Author: Igor Polev, polev@jinr.int
7
8 BmnDetectorModel abstract class header-only implementation
9 Representation of detector as enumerated elements ID
10*/
11
12#ifndef BMNDETECTORMODEL_H
13#define BMNDETECTORMODEL_H
14
15#include "BmnAlignDefines.h"
16#include "fairlogger/Logger.h"
17
18#include <map>
19#include <string>
20
21/*
22 * Due to usage of pure virtual mechanics it is not possible to
23 * implement object initialization in constructor.
24 * Therefore, Init() method is mandatory to call right after object creation.
25 */
26
28{
29 public:
30 // A grouping of alignable elements that moves as one rigid body. Models whose enumeration
31 // scheme implies such a grouping (half-stations, subsystems) declare it here.
32 struct Composite
33 {
34 std::string name; // unique, used to address the node in config files
35 std::string parent; // name of an earlier composite, empty for a root node
36 VecInt_t leaves; // element indices owned *directly*
37 };
38 // Sensitive area of one alignable element: an axis-aligned rectangle in the
39 // hit coordinate frame, at a fixed z. Rotated stations are not described.
40 struct Plane
41 {
43 };
44 // The collision target: a layer of fixed thickness, unbounded in xy.
45 struct Layer
46 {
48 };
49
50 private:
52 // encoded ID to index mapping (and vice versa)
53 std::map<Int_t, Int_t> fIDtoIdx;
54 VecInt_t fIdxToID; // sized by Alignables() in Init()
55 Double_t fTargetShift{0.0}; // cm, target z in use minus the one of the geometry file
56 protected:
57 std::string fDescription{"no description"};
58 std::vector<Plane> fPlanes; // indexed as the elements are, empty if unknown
59 Layer fTarget{0.0, 0.0}; // zero thickness while unknown
60 // detector modules enumeration interface
61 virtual void Reset() = 0; // set ID sequense BEFORE first element
62 virtual Int_t NextID() = 0; // return ID value for the next element in sequense
63 // or NEGATIVE value if sequence is over
64 // fill fPlanes with one entry per alignable element, in element index order,
65 // and fTarget from targetGeoFile (null when the macro named none).
66 // Called by Init() once the index mapping is ready, so EncodedID() works here.
67 virtual Bool_t LoadGeometry(const char* /*targetGeoFile*/) { return kTRUE; }
68 // a model without geometry keeps fPlanes empty
69 public:
70 virtual Int_t MaxModulesInStation() const = 0; // maximum number of modules in one station
71 virtual Int_t Alignables() const = 0; // number of alignable elements
72 // re-encode DetectorID from hit into detector model ID
73 // value must correspond to hit DetectorID as much as possible
74 virtual Int_t IDfromHit(Int_t HitDetectorID) const = 0;
75 // kTRUE if the hit must be excluded from ingest (not part of the alignable set)
76 virtual Bool_t IgnoreHit(Int_t /*HitDetectorID*/) const { return kFALSE; }
77 // kTRUE if there are some hits to be ignored in the model (for optimization)
78 virtual Bool_t IgnoresSome() const { return kFALSE; }
79 // composite nodes implied by the enumeration scheme, parents before children;
80 // empty (the default) means a flat model
81 virtual std::vector<Composite> Composites() const { return {}; }
82 // encoded ID of the target (TRG) element, which carries the synthetic vertex
83 // hit built from the beam line; negative when the model has no such element
84 virtual Int_t TargetID() const { return -1; }
85 // SystemID, StationID and ModuleID of an encoded ID as text for console output.
86 // Its width is fixed, so tables of elements stay aligned.
87 virtual std::string DecodeID(Int_t id) const = 0;
88
89 BmnDetectorModel() = default;
90 virtual ~BmnDetectorModel() = default;
91 // must be called right after object creation. targetGeoFile is the FairRoot
92 // ASCII geometry of the collision target installed in the run, see
93 // geometry/target_CsI.geo; models that describe no target ignore it
94 inline Bool_t Init(const char* targetGeoFile = nullptr);
95 inline Bool_t Initialized() const { return fInitialized; }
96 inline Int_t EncodedID(Int_t idx) const { return fInitialized ? fIdxToID.at(idx) : -1; };
97 inline Int_t Idx(Int_t ID) const { return fInitialized ? fIDtoIdx.at(ID) : -1; };
98 inline Int_t IdxFromHit(Int_t hitID) const { return fInitialized ? fIDtoIdx.at(IDfromHit(hitID)) : -1; };
99 inline Bool_t UnknownID(Int_t hitID) const
100 {
101 return fInitialized ? fIDtoIdx.find(hitID) == fIDtoIdx.end() : kTRUE;
102 };
103 inline const std::string& Description() const { return fDescription; }
104 inline const std::vector<Plane>& Geometry() const { return fPlanes; }
105 inline const Layer& Target() const { return fTarget; }
106 inline Double_t TargetShift() const noexcept { return fTargetShift; }
107 // moves the target along z, to where the data puts it (see BmnAligner::PrepareData)
108 inline void ShiftTarget(Double_t dz);
109};
110
112{
113 fTargetShift += dz;
114 fTarget.zStart += dz;
115 fTarget.zEnd += dz;
116 if (TargetID() >= 0 && !fPlanes.empty())
117 fPlanes[Idx(TargetID())].z += dz;
118}
119
120inline Bool_t BmnDetectorModel::Init(const char* targetGeoFile)
121{
122 // build linear enumeration of detector modules
123 fIdxToID.assign(Alignables(), -1);
124 fIDtoIdx.clear();
125 Reset();
126 Int_t ID{NextID()}, idx{0};
127 while (ID >= 0) { // negative values indicate end of sequense
128 // Alignables() and the NextID() sequence are two statements of the same
129 // count made in different places - a model whose enumeration outruns its
130 // own advertised size would corrupt every container sized from it.
131 if (idx >= Alignables()) {
132 LOG(error) << " <!> BmnDetectorModel : enumeration yields more than the " << Alignables()
133 << " element(s) Alignables() promises";
134 return kFALSE;
135 }
136 fIDtoIdx[ID] = idx;
137 fIdxToID[idx++] = ID;
138 ID = NextID();
139 }
140 if (idx != Alignables()) {
141 LOG(error) << " <!> BmnDetectorModel : enumeration yields " << idx << " element(s) while Alignables() promises "
142 << Alignables();
143 return kFALSE;
144 }
145 fInitialized = kTRUE; // EncodedID(), which LoadGeometry() walks, refuses to work before this
146 fTargetShift = 0.0;
147 if (!LoadGeometry(targetGeoFile)) {
148 fPlanes.clear();
149 fTarget = {0.0, 0.0};
151 }
152 return fInitialized;
153};
154
155#endif // BMNDETECTORMODEL_H
std::vector< Int_t > VecInt_t
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const Layer & Target() const
void ShiftTarget(Double_t dz)
const std::vector< Plane > & Geometry() const
virtual Int_t MaxModulesInStation() const =0
virtual Bool_t IgnoreHit(Int_t) const
Bool_t Initialized() const
Int_t EncodedID(Int_t idx) const
virtual std::string DecodeID(Int_t id) const =0
Bool_t Init(const char *targetGeoFile=nullptr)
virtual Int_t Alignables() const =0
virtual Bool_t IgnoresSome() const
BmnDetectorModel()=default
std::string fDescription
virtual std::vector< Composite > Composites() const
virtual Int_t NextID()=0
Bool_t UnknownID(Int_t hitID) const
std::map< Int_t, Int_t > fIDtoIdx
virtual Bool_t LoadGeometry(const char *)
virtual Int_t IDfromHit(Int_t HitDetectorID) const =0
const std::string & Description() const
virtual Int_t TargetID() const
Int_t Idx(Int_t ID) const
virtual void Reset()=0
Double_t TargetShift() const noexcept
std::vector< Plane > fPlanes
Int_t IdxFromHit(Int_t hitID) const
virtual ~BmnDetectorModel()=default