BmnRoot
26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Toggle main menu visibility
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
27
class
BmnDetectorModel
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
{
42
Double_t
xMin
,
xMax
,
yMin
,
yMax
,
z
;
43
};
44
// The collision target: a layer of fixed thickness, unbounded in xy.
45
struct
Layer
46
{
47
Double_t
zStart
,
zEnd
;
48
};
49
50
private
:
51
Bool_t
fInitialized
{
kFALSE
};
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
111
inline
void
BmnDetectorModel::ShiftTarget
(
Double_t
dz)
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
120
inline
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};
150
fInitialized
=
kFALSE
;
151
}
152
return
fInitialized
;
153
};
154
155
#endif
// BMNDETECTORMODEL_H
BmnAlignDefines.h
VecInt_t
std::vector< Int_t > VecInt_t
Definition
BmnAlignDefines.h:51
Bool_t
bool Bool_t
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
BmnDetectorModel::Target
const Layer & Target() const
Definition
BmnDetectorModel.h:105
BmnDetectorModel::ShiftTarget
void ShiftTarget(Double_t dz)
Definition
BmnDetectorModel.h:111
BmnDetectorModel::Geometry
const std::vector< Plane > & Geometry() const
Definition
BmnDetectorModel.h:104
BmnDetectorModel::fTarget
Layer fTarget
Definition
BmnDetectorModel.h:59
BmnDetectorModel::MaxModulesInStation
virtual Int_t MaxModulesInStation() const =0
BmnDetectorModel::IgnoreHit
virtual Bool_t IgnoreHit(Int_t) const
Definition
BmnDetectorModel.h:76
BmnDetectorModel::fIdxToID
VecInt_t fIdxToID
Definition
BmnDetectorModel.h:54
BmnDetectorModel::Initialized
Bool_t Initialized() const
Definition
BmnDetectorModel.h:95
BmnDetectorModel::EncodedID
Int_t EncodedID(Int_t idx) const
Definition
BmnDetectorModel.h:96
BmnDetectorModel::DecodeID
virtual std::string DecodeID(Int_t id) const =0
BmnDetectorModel::fTargetShift
Double_t fTargetShift
Definition
BmnDetectorModel.h:55
BmnDetectorModel::Init
Bool_t Init(const char *targetGeoFile=nullptr)
Definition
BmnDetectorModel.h:120
BmnDetectorModel::Alignables
virtual Int_t Alignables() const =0
BmnDetectorModel::IgnoresSome
virtual Bool_t IgnoresSome() const
Definition
BmnDetectorModel.h:78
BmnDetectorModel::BmnDetectorModel
BmnDetectorModel()=default
BmnDetectorModel::fDescription
std::string fDescription
Definition
BmnDetectorModel.h:57
BmnDetectorModel::fInitialized
Bool_t fInitialized
Definition
BmnDetectorModel.h:51
BmnDetectorModel::Composites
virtual std::vector< Composite > Composites() const
Definition
BmnDetectorModel.h:81
BmnDetectorModel::NextID
virtual Int_t NextID()=0
BmnDetectorModel::UnknownID
Bool_t UnknownID(Int_t hitID) const
Definition
BmnDetectorModel.h:99
BmnDetectorModel::fIDtoIdx
std::map< Int_t, Int_t > fIDtoIdx
Definition
BmnDetectorModel.h:53
BmnDetectorModel::LoadGeometry
virtual Bool_t LoadGeometry(const char *)
Definition
BmnDetectorModel.h:67
BmnDetectorModel::IDfromHit
virtual Int_t IDfromHit(Int_t HitDetectorID) const =0
BmnDetectorModel::Description
const std::string & Description() const
Definition
BmnDetectorModel.h:103
BmnDetectorModel::TargetID
virtual Int_t TargetID() const
Definition
BmnDetectorModel.h:84
BmnDetectorModel::Idx
Int_t Idx(Int_t ID) const
Definition
BmnDetectorModel.h:97
BmnDetectorModel::Reset
virtual void Reset()=0
BmnDetectorModel::TargetShift
Double_t TargetShift() const noexcept
Definition
BmnDetectorModel.h:106
BmnDetectorModel::fPlanes
std::vector< Plane > fPlanes
Definition
BmnDetectorModel.h:58
BmnDetectorModel::IdxFromHit
Int_t IdxFromHit(Int_t hitID) const
Definition
BmnDetectorModel.h:98
BmnDetectorModel::~BmnDetectorModel
virtual ~BmnDetectorModel()=default
BmnDetectorModel::Composite
Definition
BmnDetectorModel.h:33
BmnDetectorModel::Composite::leaves
VecInt_t leaves
Definition
BmnDetectorModel.h:36
BmnDetectorModel::Composite::parent
std::string parent
Definition
BmnDetectorModel.h:35
BmnDetectorModel::Composite::name
std::string name
Definition
BmnDetectorModel.h:34
BmnDetectorModel::Layer
Definition
BmnDetectorModel.h:46
BmnDetectorModel::Layer::zEnd
Double_t zEnd
Definition
BmnDetectorModel.h:47
BmnDetectorModel::Layer::zStart
Double_t zStart
Definition
BmnDetectorModel.h:47
BmnDetectorModel::Plane
Definition
BmnDetectorModel.h:41
BmnDetectorModel::Plane::xMin
Double_t xMin
Definition
BmnDetectorModel.h:42
BmnDetectorModel::Plane::z
Double_t z
Definition
BmnDetectorModel.h:42
BmnDetectorModel::Plane::xMax
Double_t xMax
Definition
BmnDetectorModel.h:42
BmnDetectorModel::Plane::yMax
Double_t yMax
Definition
BmnDetectorModel.h:42
BmnDetectorModel::Plane::yMin
Double_t yMin
Definition
BmnDetectorModel.h:42
align_new
models
BmnDetectorModel.h
Generated on
for BmnRoot by
1.17.0