BmnRoot
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.ru
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 <array>
19#include <map>
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 private:
30 Bool_t fInitialized{false};
31 // encoded ID to index mapping (and vice versa)
32 std::map<Int_t, Int_t> fIDtoIdx;
33 std::array<Int_t, BMN_MODULE_COUNT> fIdxToID;
34
35 protected:
36 // detector modules enumeration interface
37 virtual void Reset() = 0; // set ID sequense BEFORE first element
38 virtual Int_t NextID() = 0; // return ID value for the next element in sequense
39 // or NEGATIVE value if sequence is over
40 public:
41 virtual Int_t MaxModulesInStation() const = 0; // maximum number of modules in one station
42 virtual Int_t Alignables() const = 0; // number of alignable elements
43 // re-encode DetectorID from hit into decector model ID
44 // value must correspond to hit DetectorID as much as possible
45 virtual Int_t IDfromHit(Int_t HitDetectorID) const = 0;
46
47 BmnDetectorModel() = default;
48 virtual ~BmnDetectorModel() = default;
49 inline Bool_t Init(); // must be called right after object creation
50 inline Int_t EncodedID(Int_t idx) const { return fInitialized ? fIdxToID.at(idx) : -1; };
51 inline Int_t Idx(Int_t ID) const { return fInitialized ? fIDtoIdx.at(ID) : -1; };
52 inline Int_t IdxFromHit(Int_t hitID) const { return fInitialized ? fIDtoIdx.at(IDfromHit(hitID)) : -1; };
53 inline Bool_t UnknownID(Int_t ID) const { return fInitialized ? fIDtoIdx.find(ID) == fIDtoIdx.end() : kTRUE; }
54};
55
57{
58 // check modules count
60 LOG(error) << " <!> BmnDetectorModel : wrong detector configuration"
61 << "\n modules expected: " << BMN_MODULE_COUNT << "\n modules provided: " << Alignables();
62 return kFALSE;
63 }
64 // build linear enumeration of detector modules
65 Reset();
66 Int_t ID{NextID()}, idx{0};
67 while (ID >= 0) { // negative values indicate end of sequense
68 fIDtoIdx[ID] = idx;
69 fIdxToID[idx++] = ID;
70 ID = NextID();
71 }
72 return fInitialized = kTRUE;
73};
74
75#endif // BMNDETECTORMODEL_H
#define BMN_MODULE_COUNT
virtual Int_t MaxModulesInStation() const =0
Int_t EncodedID(Int_t idx) const
virtual Int_t Alignables() const =0
BmnDetectorModel()=default
Bool_t UnknownID(Int_t ID) const
virtual Int_t NextID()=0
virtual Int_t IDfromHit(Int_t HitDetectorID) const =0
Int_t Idx(Int_t ID) const
virtual void Reset()=0
Int_t IdxFromHit(Int_t hitID) const
virtual ~BmnDetectorModel()=default