BmnRoot
Loading...
Searching...
No Matches
BmnATestTrack.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 BmnATestTrack class header-only implementation
9 Minimalistic representation of random linear track
10 (for alignment algorithm test only)
11*/
12
13#ifndef BMNATESTTRACK_H
14#define BMNATESTTRACK_H
15
16#include "BmnATestHit.h"
17#include "BmnAlignDefines.h"
18#include "BmnAlignResult.h"
19#include "BmnAligner.h"
20#include "TPolyLine3D.h"
21
22#include <stdexcept>
23
24#define BMN_TEST_TRACK_SOLID_COLOR kBlack
25#define BMN_TEST_TRACK_NONSOLID_COLOR kMagenta
26#define BMN_TEST_TRACK_DEF_MAX_Z 500.0
27
29{
30 private:
31 // according to _VBCK_ line is defined as:
32 // x = AlphaX1 + AlphaX2 * z
33 // y = AlphaY1 + AlphaY2 * z
34 // see readme.md for details
35 SVectLC fAlpha;
36 SVect3 fVertex, fDirection;
37 Int_t fMaxHits, fHitsCnt{0};
38 BmnATestHit** fpHits;
39
40 protected:
42
43 public:
44 BmnATestTrack() = delete;
45 BmnATestTrack(SVectLC Alpha, Int_t nHits);
46 BmnATestTrack(Double_t Alpha1Sigma, Double_t Alpha2Min, Double_t Alpha2Max, Int_t nHits);
47 ~BmnATestTrack() { delete[] fpHits; }
48
49 const SVectLC& GetAlpha() const noexcept { return fAlpha; }
50 const SVect3& GetVertex() const noexcept { return fVertex; }
51 const SVect3& GetDirection() const noexcept { return fDirection; }
52
53 void AddHit(BmnATestHit& hit);
54 void AddMSE(BmnAlignerClass* pAligner, Bool_t withResiduals = kFALSE) const;
55
56 Double_t X(Double_t z) const noexcept { return fAlpha(iX0) + fAlpha(iX1) * z; }
57 Double_t Y(Double_t z) const noexcept { return fAlpha(iY0) + fAlpha(iY1) * z; }
58
59 // for ROOT macro mode only
60 void Draw(Bool_t solid = kTRUE, Double_t maxZ = BMN_TEST_TRACK_DEF_MAX_Z) const;
61};
62
63inline BmnATestTrack::BmnATestTrack(SVectLC Alpha, Int_t nHits)
64 : fAlpha(Alpha)
65 , fMaxHits(nHits)
66{
67 fVertex = SVect3({fAlpha(iX0), fAlpha(iY0), 0.0});
68 fDirection = SVect3({fAlpha(iX1), fAlpha(iY1), 1.0});
69
70 fpHits = new BmnATestHit*[fMaxHits];
71 for (Int_t i = 0; i < fMaxHits; i++)
72 fpHits[i] = nullptr;
73}
74
75inline BmnATestTrack::BmnATestTrack(Double_t Alpha1Sigma, Double_t Alpha2Min, Double_t Alpha2Max, Int_t nHits)
76 : fMaxHits(nHits)
77{
78 fAlpha(iX0) = BMN_RND.Gaus(0.0, Alpha1Sigma);
79 fAlpha(iY0) = BMN_RND.Gaus(0.0, Alpha1Sigma);
80 fAlpha(iX1) = BMN_RND.Uniform(Alpha2Min, Alpha2Max);
81 fAlpha(iY1) = BMN_RND.Uniform(Alpha2Min, Alpha2Max);
82 fVertex = SVect3({fAlpha(iX0), fAlpha(iY0), 0.0});
83 fDirection = SVect3({fAlpha(iX1), fAlpha(iY1), 1.0});
84
85 fpHits = new BmnATestHit*[fMaxHits];
86 for (Int_t i = 0; i < fMaxHits; i++)
87 fpHits[i] = nullptr;
88}
89
91{
92 if (fHitsCnt >= fMaxHits)
93 throw std::runtime_error("BmnATestTrack::AddHit: too many hits");
94 fpHits[fHitsCnt++] = &hit;
95}
96
97inline void BmnATestTrack::AddMSE(BmnAlignerClass* pAligner, Bool_t withResiduals) const
98{
99 if (!fpHits)
100 throw std::runtime_error("BmnATestTrack::AddResiduals: hits not registered");
101 Double_t z, delta, omega;
102 BmnAlignResult& result{*pAligner->GetCurrentResult()};
103
104 for (Int_t i = 0; i < fHitsCnt; i++) {
105 Int_t detectorIdx{static_cast<Int_t>(fpHits[i]->GetDetectorID())};
106 const SVectGL& A = result.A(detectorIdx);
107 z = fpHits[i]->GetZ() + A(iZ);
108
109 omega = pAligner->OmegaScaleFactor() * fpHits[i]->GetWx();
110 delta = fpHits[i]->GetX() + A(iX) - X(z);
111 result.AddValueMSE(detectorIdx, omega * delta * delta);
112 if (withResiduals)
113 result.ResidualsX().Fill(delta);
114
115 omega = pAligner->OmegaScaleFactor() * fpHits[i]->GetWy();
116 delta = fpHits[i]->GetY() + A(iY) - Y(z);
117 result.AddValueMSE(detectorIdx, omega * delta * delta);
118 if (withResiduals)
119 result.ResidualsY().Fill(delta);
120 }
121}
122
123// visualization works in ROOT macro mode only
124inline void BmnATestTrack::Draw(Bool_t solid, Double_t maxZ) const
125{
126 Double_t x[2]{X(0.0), X(maxZ)}, y[2]{Y(0.0), Y(maxZ)}, z[2]{0.0, maxZ};
127 // note: x and z axis are swapped
128 auto* line = new TPolyLine3D(2, z, y, x);
129 if (solid)
130 line->SetLineColor(BMN_TEST_TRACK_SOLID_COLOR);
131 else {
132 line->SetLineColor(BMN_TEST_TRACK_NONSOLID_COLOR);
133 line->SetLineStyle(2);
134 }
135 line->Draw();
136 // draw hits if known
137 if (fpHits)
138 for (Int_t i = 0; i < fHitsCnt; i++)
139 if (fpHits[i])
140 fpHits[i]->Draw();
141
142 // in macro mode we don't clean RAM, sorry
143}
144
145#endif // BMNATESTTRACK_H
#define BMN_TEST_TRACK_DEF_MAX_Z
#define BMN_TEST_TRACK_SOLID_COLOR
#define BMN_TEST_TRACK_NONSOLID_COLOR
@ iY1
@ iY0
@ iX1
@ iX0
ROOT::Math::SVector< Double_t, BMN_GLOBAL_PARAMS_PD > SVectGL
ROOT::Math::SVector< Double_t, 3 > SVect3
ROOT::Math::SVector< Double_t, BMN_LOCAL_PARAMS_PT > SVectLC
@ iZ
@ iX
@ iY
const Float_t delta
Distance between GEM-stations.
Definition BmnMwpcHit.cxx:8
int i
Definition P4_F32vec4.h:22
void Draw() const
Definition BmnATestHit.h:35
const SVect3 & GetVertex() const noexcept
const SVectLC & GetAlpha() const noexcept
void AddMSE(BmnAlignerClass *pAligner, Bool_t withResiduals=kFALSE) const
BmnATestTrack()=delete
Double_t Y(Double_t z) const noexcept
Double_t X(Double_t z) const noexcept
void Draw(Bool_t solid=kTRUE, Double_t maxZ=BMN_TEST_TRACK_DEF_MAX_Z) const
BmnAligner< BmnATestHit > BmnAlignerClass
const SVect3 & GetDirection() const noexcept
void AddHit(BmnATestHit &hit)
BmnAlignResult * GetCurrentResult() const noexcept
Definition BmnAligner.h:63
Double_t OmegaScaleFactor() const noexcept
Definition BmnAligner.h:62
Double_t GetWy() const noexcept
Double_t GetY() const noexcept
Double_t GetX() const noexcept
Int_t GetDetectorID() const noexcept
Double_t GetWx() const noexcept
Double_t GetZ() const noexcept