BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
review.C
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 Preliminary data review
9*/
10
11// headers below are for IDE syntax to work and they will be
12// turned off during execution in ROOT macro mode
13#ifndef __CLING__
14#include "BmnRootIterator.h"
15#include "BmnRun8cgDetModel.h"
16#include "TCanvas.h"
17#include "TH1D.h"
18#include "TH2D.h"
19#include "TStopwatch.h"
20
21#include <array>
22#include <fstream>
23#include <map>
24#include <vector>
25#endif
26
27#define BMN_FILELIST "cfg/dst7466noa-full.txt"
28
29#define XHIST_WIDTH 0.06
30#define YHIST_WIDTH 0.6
31
32// canvas and pads configuration
33#define RES_X 3440
34#define RES_Y 1440
35#define PADS_X 4
36#define PADS_Y 2
37
38// filter tracks by detector element (must have hit in it)
39#define DET_FILTER 201392146 // -1 to disable filtering
40
41static const std::vector<Int_t> detIDs = {201588754, 201588770};
42static const Double_t detMinMax[2][6] = {{-27.0, 27.0, 0.0, 16.0}, {-27.0, 27.0, -16.0, 0.0}};
43
44enum
45{
50};
51
52std::map<Int_t, std::array<Double_t, 6>> detPos;
53
54int review(int argc = 0, char** argv = nullptr)
55{
56 TStopwatch timer;
57
58 // prepare canvas and pads
59 TCanvas* pCnv = new TCanvas( // RAM is not released in macro mode
60 "canvas", "BM@N alignment");
61 pCnv->SetRealAspectRatio();
62 pCnv->SetFixedAspectRatio();
63 pCnv->SetCanvasSize(RES_X - 20, RES_Y - 96);
65 constexpr const Double_t padW{1.0 / PADS_X}, padH{1.0 / PADS_Y};
66 TPad* pPads[PADS_Y][PADS_X];
67 for (Int_t i = 0; i < PADS_Y; i++) {
68 for (Int_t j = 0; j < PADS_X; j++) {
69 pPads[i][j] = new TPad(Form("pad%d%d", i + 1, j + 1), Form("pad%d%d", i + 1, j + 1), padW * j, padH * i,
70 padW * (j + 1), padH * (i + 1));
71 pPads[i][j]->Draw();
72 }
73 }
74
75 // prepare ROOT file readers and histograms
76 BmnRun8cgDetModel detModel;
77 detModel.Init();
78 BmnRootIterator data(BMN_FILELIST, detModel);
79
81 TH1* hist[PADS_Y][PADS_X];
82 for (Int_t i = 0; i < PADS_Y; i++)
83 for (Int_t j = 0; j < PADS_X; j++)
84 hist[i][j] = nullptr;
85
86 // process ROOT data
88 while (!data.EndOfTracks()) {
89 Bool_t filterOK{kFALSE};
90 Int_t detIdx{-1};
91 Double_t xSum{0.0}, ySum{0.0}, zSum{0.0}, z2Sum{0.0}, zxSum{0.0}, zySum{0.0};
92 while (!data.EndOfHits()) {
93 Int_t detID{data.HitDetectorID()};
94 filterOK |= (detID == DET_FILTER);
95 auto found{std::find(detIDs.begin(), detIDs.end(), detID)};
96 if (found != detIDs.end()) {
97 // hit is in one of investigated detector elements
98 detHit = *data.GetHit();
99 detIdx = std::distance(detIDs.begin(), found);
100 } else {
101 // linear regression terms
102 xSum += data.HitX();
103 ySum += data.HitY();
104 zSum += data.HitZ();
105 z2Sum += data.HitZ() * data.HitZ();
106 zxSum += data.HitZ() * data.HitX();
107 zySum += data.HitZ() * data.HitY();
108 }
109 data.NextHit();
110 }
111
112 if (detIdx == -1 || (!filterOK && DET_FILTER != -1)) {
113 // no hits in investigated detector elements
114 data.NextTrack();
115 continue;
116 }
117 // init histograms if not yet
118 if (!hist[detIdx][hResX]) {
119 hist[detIdx][hResX] =
120 new TH1D(Form("resX_%d", detIDs[detIdx]), "Residuals in X", 101, -XHIST_WIDTH, XHIST_WIDTH);
121 hist[detIdx][hResY] =
122 new TH1D(Form("resY_%d", detIDs[detIdx]), "Residuals in Y", 101, -YHIST_WIDTH, YHIST_WIDTH);
123 hist[detIdx][hXresX] = new TH2D(Form("XresX_%d", detIDs[detIdx]), "Residuals in X over X", 101,
124 detMinMax[detIdx][0], detMinMax[detIdx][1], 101, -XHIST_WIDTH, XHIST_WIDTH);
125 hist[detIdx][hYresX] = new TH2D(Form("YresX_%d", detIDs[detIdx]), "Residuals in X over Y", 101,
126 detMinMax[detIdx][2], detMinMax[detIdx][3], 101, -XHIST_WIDTH, XHIST_WIDTH);
127 }
128 // linear regression fit
129 Double_t hitCnt{static_cast<Double_t>(data.HitsInTrack()) - 1.0}, factor{1.0 / (hitCnt * z2Sum - zSum * zSum)},
130 xA{(xSum * z2Sum - zSum * zxSum) * factor}, yA{(ySum * z2Sum - zSum * zySum) * factor},
131 xB{(hitCnt * zxSum - zSum * xSum) * factor}, yB{(hitCnt * zySum - zSum * ySum) * factor},
132 resX{detHit.GetX() - xA - xB * detHit.GetZ()}, resY{detHit.GetY() - yA - yB * detHit.GetZ()};
133 // residuals in target detector
134 hist[detIdx][hResX]->Fill(resX);
135 hist[detIdx][hResY]->Fill(resY);
136 ((TH2D*)hist[detIdx][hXresX])->Fill(detHit.GetX(), resX);
137 ((TH2D*)hist[detIdx][hYresX])->Fill(detHit.GetY(), resX);
138
139 data.NextTrack();
140 }
141
142 std::ofstream f("positions.csv", std::ofstream::out);
143 for (auto i = detPos.begin(); i != detPos.end(); i++) {
144 std::cout << i->first << ",";
145 f << i->first << ",";
146 for (Int_t j = 0; j < 6; j++) {
147 std::cout << i->second[j] << ",";
148 f << i->second[j] << ",";
149 }
150 std::cout << "\n";
151 f << "\n";
152 }
153 f.close();
154
155 // draw histograms
156 TH1D* h1;
157 TH2D* h2;
158 for (Int_t i = 0; i < PADS_Y; i++) {
159 if (!hist[i][0])
160 continue;
161 pPads[i][hResX]->cd();
162 h1 = (TH1D*)hist[i][hResX];
163 h1->SetFillColor(kCyan);
164 h1->Draw("HIST");
165 pPads[i][hResY]->cd();
166 h1 = (TH1D*)hist[i][hResY];
167 h1->SetFillColor(kTeal);
168 h1->Draw("HIST");
169 pPads[i][hXresX]->cd();
170 h2 = (TH2D*)hist[i][hXresX];
171 h2->SetStats(1);
172 h2->Draw("CONTZ");
173 pPads[i][hYresX]->cd();
174 h2 = (TH2D*)hist[i][hYresX];
175 h2->SetStats(1);
176 h2->Draw("CONTZ");
177 }
178
179 // no memory cleanup in ROOT macro mode
180 std::cout << "Done in " << timer.RealTime() << "s" << std::endl;
181 return 0;
182}
int i
Definition P4_F32vec4.h:22
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
kTeal
kCyan
char * Form(const char *fmt,...)
Bool_t EndOfTracks() const noexcept
Bool_t EndOfHits() const noexcept
virtual Double_t HitY() const override
virtual Int_t HitDetectorID() const override
const Hit_t * GetHit() const noexcept
virtual Double_t HitZ() const override
virtual Double_t HitX() const override
virtual Int_t HitsInTrack() const override
virtual void NextTrack() override
virtual void NextHit() override
virtual void SetFillColor(Color_t fcolor)
void SetWindowSize(UInt_t ww, UInt_t wh)
void SetFixedAspectRatio(Bool_t fixed=kTRUE) override
void SetCanvasSize(UInt_t ww, UInt_t wh) override
bool SetRealAspectRatio(const Int_t axis=1)
static void StatOverflows(Bool_t flag=kTRUE)
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void SetStats(Bool_t stats=kTRUE)
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
Double_t RealTime()
#define PADS_Y
Definition review.C:36
#define RES_Y
Definition review.C:34
#define PADS_X
Definition review.C:35
#define RES_X
Definition review.C:33
#define DET_FILTER
Definition review.C:39
@ hResX
Definition review.C:46
@ hXresX
Definition review.C:48
@ hResY
Definition review.C:47
@ hYresX
Definition review.C:49
std::map< Int_t, std::array< Double_t, 6 > > detPos
Definition review.C:52
static const std::vector< Int_t > detIDs
Definition review.C:41
static const Double_t detMinMax[2][6]
Definition review.C:42
#define YHIST_WIDTH
Definition review.C:30
#define BMN_FILELIST
Definition review.C:27
#define XHIST_WIDTH
Definition review.C:29
int review(int argc=0, char **argv=nullptr)
Definition review.C:54