BmnRoot 26.10.0-233-gb9bbe585
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.int
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 "BmnAlignModels.h" // IWYU pragma: keep
15#include "BmnRootIterator.h"
16#include "BmnWeightedLine.h"
17
18#include <TCanvas.h>
19#include <TH1D.h>
20#include <TH2D.h>
21#include <TStopwatch.h>
22#include <array>
23#include <map>
24#endif
25
26#define BMN_FILELIST "/home/igor/bmnroot/align_new/cfg/run8/7466ev0p3.noa_rlerr.list"
27
28#define XHIST_WIDTH 0.06
29#define YHIST_WIDTH 0.6
30
31// canvas and pads configuration
32#define RES_X 3440
33#define RES_Y 1440
34#define PADS_X 4
35#define PADS_Y 2
36
37// filter tracks by detector element (must have hit in it)
38#define DET_FILTER -1 // -1 to disable filtering
39
40static const VecInt_t detIDs = {201588754, 201588770};
41static const Double_t detMinMax[2][6] = {{-27.0, 27.0, 0.0, 16.0}, {-27.0, 27.0, -16.0, 0.0}};
42
43enum
44{
49};
50
51std::map<Int_t, std::array<Double_t, 6>> detPos;
52
53/**
54 * @brief Preliminary review of the input data, before any alignment.
55 *
56 * Fills residual and hit-position histograms for the detector elements listed
57 * in detIDs and draws them on a pad grid. Meant for spotting dead or misencoded
58 * elements and judging whether a dataset is worth aligning at all.
59 *
60 * Configuration is compile-time, through the defines at the top of the file
61 * (BMN_FILELIST, the histogram widths, the pad grid, DET_FILTER).
62 *
63 * @param argc unused, kept so the macro can be invoked with ROOT's argument
64 * passing convention
65 * @param argv unused, see argc
66 *
67 * @return 0 on success, non-zero if the input data could not be read
68 */
69int review(int argc = 0, char** argv = nullptr)
70{
71 TStopwatch timer;
72
73 // prepare canvas and pads
74 TCanvas* pCnv = new TCanvas( // RAM is not released in macro mode
75 "canvas", "BM@N alignment", RES_X, RES_Y);
76 pCnv->SetCanvasSize(RES_X - 20, RES_Y - 96);
77 constexpr const Double_t padW{1.0 / PADS_X}, padH{1.0 / PADS_Y};
78 TPad* pPads[PADS_Y][PADS_X];
79 for (Int_t i = 0; i < PADS_Y; i++) {
80 for (Int_t j = 0; j < PADS_X; j++) {
81 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,
82 padW * (j + 1), padH * (i + 1));
83 pPads[i][j]->Draw();
84 }
85 }
86
87 // prepare ROOT file readers and histograms
88 BmnRun8cgDM detModel;
89 detModel.Init();
91
93 TH1* hist[PADS_Y][PADS_X];
94 for (Int_t i = 0; i < PADS_Y; i++)
95 for (Int_t j = 0; j < PADS_X; j++)
96 hist[i][j] = nullptr;
97
98 // process ROOT data
100 while (!data.EndOfTracks()) {
101 Bool_t filterOK{kFALSE};
102 Int_t detIdx{-1};
103 BmnWeightedLine lineX, lineY; // unweighted: default unit weights
104 while (!data.EndOfHits()) {
105 Int_t detID{data.HitDetectorID()};
106 filterOK |= (detID == DET_FILTER);
107 auto found{std::find(detIDs.begin(), detIDs.end(), detID)};
108 if (found != detIDs.end()) {
109 // hit is in one of investigated detector elements
110 detHit = *data.GetHit();
111 detIdx = std::distance(detIDs.begin(), found);
112 } else {
113 lineX.Add(data.HitZ(), data.HitX());
114 lineY.Add(data.HitZ(), data.HitY());
115 }
116 data.NextHit();
117 }
118
119 if (detIdx == -1 || (!filterOK && DET_FILTER != -1)) {
120 // no hits in investigated detector elements
121 data.NextTrack();
122 continue;
123 }
124 // init histograms if not yet
125 if (!hist[detIdx][hResX]) {
126 hist[detIdx][hResX] =
127 new TH1D(Form("resX_%d", detIDs[detIdx]), "Residuals in X", 101, -XHIST_WIDTH, XHIST_WIDTH);
128 hist[detIdx][hResY] =
129 new TH1D(Form("resY_%d", detIDs[detIdx]), "Residuals in Y", 101, -YHIST_WIDTH, YHIST_WIDTH);
130 hist[detIdx][hXresX] = new TH2D(Form("XresX_%d", detIDs[detIdx]), "Residuals in X over X", 101,
131 detMinMax[detIdx][0], detMinMax[detIdx][1], 101, -XHIST_WIDTH, XHIST_WIDTH);
132 hist[detIdx][hYresX] = new TH2D(Form("YresX_%d", detIDs[detIdx]), "Residuals in X over Y", 101,
133 detMinMax[detIdx][2], detMinMax[detIdx][3], 101, -XHIST_WIDTH, XHIST_WIDTH);
134 }
135 Double_t resX{detHit.GetX() - lineX.At(detHit.GetZ())}, resY{detHit.GetY() - lineY.At(detHit.GetZ())};
136 // residuals in target detector
137 hist[detIdx][hResX]->Fill(resX);
138 hist[detIdx][hResY]->Fill(resY);
139 ((TH2D*)hist[detIdx][hXresX])->Fill(detHit.GetX(), resX);
140 ((TH2D*)hist[detIdx][hYresX])->Fill(detHit.GetY(), resX);
141
142 data.NextTrack();
143 }
144
145 /*
146 std::ofstream f("positions.csv", std::ofstream::out);
147 for (auto i = detPos.begin(); i != detPos.end(); i++) {
148 std::cout << i->first << ",";
149 f << i->first << ",";
150 for (Int_t j = 0; j < 6; j++) {
151 std::cout << i->second[j] << ",";
152 f << i->second[j] << ",";
153 }
154 std::cout << "\n";
155 f << "\n";
156 }
157 f.close();
158 */
159
160 // draw histograms
161 TH1D* h1;
162 TH2D* h2;
163 for (Int_t i = 0; i < PADS_Y; i++) {
164 if (!hist[i][0])
165 continue;
166 pPads[i][hResX]->cd();
167 h1 = (TH1D*)hist[i][hResX];
168 h1->SetFillColor(kCyan);
169 h1->Draw("HIST");
170 pPads[i][hResY]->cd();
171 h1 = (TH1D*)hist[i][hResY];
172 h1->SetFillColor(kTeal);
173 h1->Draw("HIST");
174 pPads[i][hXresX]->cd();
175 h2 = (TH2D*)hist[i][hXresX];
176 h2->SetStats(1);
177 h2->Draw("CONTZ");
178 pPads[i][hYresX]->cd();
179 h2 = (TH2D*)hist[i][hYresX];
180 h2->SetStats(1);
181 h2->Draw("CONTZ");
182 }
183
184 // no memory cleanup in ROOT macro mode
185 std::cout << "Done in " << timer.RealTime() << "s" << std::endl;
186 return 0;
187}
std::vector< Int_t > VecInt_t
TrackFilter_t BmnDefaultTrackFilter(Bool_t wholeTrackOnly=kTRUE)
HitFilter_t BmnDefaultHitFilter(const BmnDetectorModel &model)
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
Bool_t Init(const char *targetGeoFile=nullptr)
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 void NextTrack() override
virtual void NextHit() override
Double_t At(Double_t z) const noexcept
void Add(Double_t z, Double_t v, Double_t w=1.0) noexcept
virtual void SetFillColor(Color_t fcolor)
void SetCanvasSize(UInt_t ww, UInt_t wh) override
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:35
#define RES_Y
Definition review.C:33
#define PADS_X
Definition review.C:34
#define RES_X
Definition review.C:32
#define DET_FILTER
Definition review.C:38
std::map< Int_t, std::array< Double_t, 6 > > detPos
Definition review.C:51
static const Double_t detMinMax[2][6]
Definition review.C:41
#define YHIST_WIDTH
Definition review.C:29
#define BMN_FILELIST
Definition review.C:26
static const VecInt_t detIDs
Definition review.C:40
#define XHIST_WIDTH
Definition review.C:28
@ hResX
Definition review.C:45
@ hXresX
Definition review.C:47
@ hResY
Definition review.C:46
@ hYresX
Definition review.C:48
int review(int argc=0, char **argv=nullptr)
Preliminary review of the input data, before any alignment.
Definition review.C:69