BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
compareA.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 Aligmnment quality evaluation macro
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 "BmnDataReader.h"
15#include "CbmStsTrack.h"
16#include "CbmVertex.h"
17#include "TCanvas.h"
18#include "TH1D.h"
19#include "TH2D.h"
20#include "TPad.h"
21#include "TPaveText.h"
22#include "TString.h"
23#include "TTreeReaderArray.h"
24#include "TTreeReaderValue.h"
25
26#include <iomanip>
27#include <iostream>
28#endif
29
30#define BMN_FILELIST_NA "cfg/dst_mini_fe.txt"
31#define BMN_FILELIST_A "cfg/dst_mini_re.txt"
32constexpr static const char* BMN_RESULT_PDF{
33 nullptr}; //{"/home/igor/DATA/bmn/dst/25.04.0/compare/cmp_ali-noa_7466_ev0_p4.pdf"};
34
35// canvas and pads configuration
36#define RES_X 3440
37#define RES_Y 1440
38#define PADS_X 4
39#define PADS_Y 2
40
42{ // aligned or not
43 kNA = 0,
44 kAL = 1
45};
46constexpr Int_t kDEF{kAL}, kSEC{kNA};
47
60
61// historgam positioning on pads
62constexpr const Int_t histPos[eCmpHists::kCount][2]{
63 {1, 1}, // kTracksCount
64 {1, 0}, // kVertexCount
65 {1, 2}, // kTracksChi2perNDF
66 {0, 0}, // kVertexX
67 {0, 1}, // kVertexY
68 {0, 2}, // kVertexZ
69 {1, 3}, // kVertexXYbefore
70 {0, 3} // kVertexXYafter
71};
72
73int compareA(int argc = 0, char** argv = nullptr)
74{
75 // prepare canvas and pads
76 TCanvas* pCnv = new TCanvas( // RAM is not released in macro mode
77 "canvas", "BM@N alignment");
78 pCnv->SetRealAspectRatio();
79 pCnv->SetFixedAspectRatio();
80 pCnv->SetCanvasSize(RES_X - 20, RES_Y - 96);
82 constexpr const Double_t padW{1.0 / PADS_X}, padH{1.0 / PADS_Y};
83 TPad* pPads[PADS_Y][PADS_X];
84 for (UInt_t i = 0; i < PADS_Y; i++) {
85 for (UInt_t j = 0; j < PADS_X; j++) {
86 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,
87 padW * (j + 1), padH * (i + 1));
88 pPads[i][j]->Draw();
89 }
90 }
91
92 // prepare ROOT file readers and histograms
93 TH1* pHist[2][eCmpHists::kCount];
94 BmnDataReader* pData[2];
97 for (Int_t al = kNA; al <= kAL; al++) {
98 pData[al] = new BmnDataReader(al ? BMN_FILELIST_A : BMN_FILELIST_NA);
99 pTracks[al] = new TTreeReaderArray<CbmStsTrack>(pData[al]->Reader(), "StsVector");
100 pVertex[al] = new TTreeReaderValue<CbmVertex>(pData[al]->Reader(), "MpdVertex.");
101 pHist[al][kVertexCount] = new TH1D(al ? "VC-AL" : "VC-NA", "Vertex count (tracks > 1)", 4, -1.0, 2.0);
102 pHist[al][kTracksChi2perNDF] =
103 new TH1D(al ? "TChi-AL" : "TChi-NA", "Tracks Chi2 per NDF (cut = 5.0)", 100, 0.0, 5.0);
104 pHist[al][kVertexX] = new TH1D(al ? "VX-AL" : "VX-NA", "Vertex X distribution", 100, -6.0, 6.0);
105 pHist[al][kVertexY] = new TH1D(al ? "VY-AL" : "VY-NA", "Vertex Y distribution", 100, -6.0, 6.0);
106 pHist[al][kVertexZ] = new TH1D(al ? "VZ-AL" : "VZ-NA", "Vertex Z distribution", 100, -2.0, 2.0);
107 }
108 pHist[kDEF][kVertexXYbefore] = new TH2D("VXY-NA", "Non-aligned vertex XY", 100, -2.0, 2.0, 100, -2.0, 2.0);
109 pHist[kDEF][kVertexXYafter] = new TH2D("VXY-AL", "Aligned vertex XY", 100, -2.0, 2.0, 100, -2.0, 2.0);
110 pHist[kDEF][kTracksCount] = new TH1D("TC", "Tracks count (hits > 1)", 4, -1.0, 2.0);
111 pHist[kSEC][kVertexXYbefore] = nullptr;
112 pHist[kSEC][kVertexXYafter] = nullptr;
113 pHist[kSEC][kTracksCount] = nullptr;
114
115 // fill histograms
116 TH1D::StatOverflows(kFALSE); // need to ignore overflows, otherwise
117 // vertex Z histogram may show increase of StdDev
118 Int_t vertexTotal[2]{0, 0}, tracksTotal[2]{0, 0};
119 for (Int_t al = kNA; al <= kAL; al++) {
120 Double_t dCounter{static_cast<Double_t>(al)};
121 TH2D* pHistVertexXY = (TH2D*)(al == kAL ? pHist[kDEF][kVertexXYafter] : pHist[kDEF][kVertexXYbefore]);
122 while (pData[al]->Reader().Next()) {
123 // vertex data
124 CbmVertex& vertex = **pVertex[al];
125 if (vertex.GetNTracks() < 2) // ignore vertices with less than 2 tracks
126 continue;
127 vertexTotal[al]++;
128 pHist[kDEF][kVertexCount]->Fill(dCounter);
129 pHist[al][kVertexX]->Fill(vertex.GetX());
130 pHist[al][kVertexY]->Fill(vertex.GetY());
131 pHist[al][kVertexZ]->Fill(vertex.GetZ());
132 pHistVertexXY->Fill(vertex.GetX(), vertex.GetY());
133 // tracks data
134 for (CbmStsTrack& track : *pTracks[al]) {
135 if (track.GetNStsHits() < 2) // ignore tracks with less than 2 hits
136 continue;
137 tracksTotal[al]++;
138 pHist[kDEF][kTracksCount]->Fill(dCounter);
139 pHist[al][kTracksChi2perNDF]->Fill(track.GetChi2() / track.GetNDF());
140 }
141 }
142 }
143
144 // rescale chi2/hit histogram
145 Double_t tracksIncrease{static_cast<Double_t>(tracksTotal[kAL]) / tracksTotal[kNA]};
146 pHist[kNA][kTracksChi2perNDF]->Scale(tracksIncrease);
147
148 // summarize results
149 Double_t rTracksIncrease{100.0 * tracksIncrease - 100.0},
150 rVertexIncrease{100.0 * vertexTotal[kAL] / vertexTotal[kNA] - 100.0},
151 rTracksChi2perNDFMeanDecrease{
152 100.0 * pHist[kAL][kTracksChi2perNDF]->GetMean() / pHist[kNA][kTracksChi2perNDF]->GetMean() - 100.0},
153 rVertexXStdDevDecrease{100.0 * pHist[kAL][kVertexX]->GetStdDev() / pHist[kNA][kVertexY]->GetStdDev() - 100.0},
154 rVertexYStdDevDecrease{100.0 * pHist[kAL][kVertexY]->GetStdDev() / pHist[kNA][kVertexY]->GetStdDev() - 100.0},
155 rVertexZStdDevDecrease{100.0 * pHist[kAL][kVertexZ]->GetStdDev() / pHist[kNA][kVertexZ]->GetStdDev() - 100.0};
156
157 // report to stdout
158 using namespace std;
159 cout << fixed << setprecision(1);
160 cout << "Tracks count increase ......................... " << rTracksIncrease << "%\n";
161 cout << "Vertex count increase ......................... " << rVertexIncrease << "%\n";
162 cout << "Mean tracks Chi2 per NDF decrease ............. " << rTracksChi2perNDFMeanDecrease << "%\n";
163 cout << "Vertex X distribution StdDev decrease ......... " << rVertexXStdDevDecrease << "%\n";
164 cout << "Vertex Y distribution StdDev decrease ......... " << rVertexYStdDevDecrease << "%\n";
165 cout << "Vertex Z distribution StdDev decrease ......... " << rVertexZStdDevDecrease << "%\n";
166 cout << "Vertex Z distribution StdDev before / after ..... " << setprecision(3) << pHist[kNA][kVertexZ]->GetStdDev()
167 << " / " << pHist[kAL][kVertexZ]->GetStdDev() << "\n";
168
169 // report to GUI
170 TH1* hst[2];
171 TPaveText* pave;
172 TString hstOpt[2];
173 EColor colorNA;
174 Double_t value;
175 for (Int_t hstEN = 0; hstEN < eCmpHists::kCount; hstEN++) {
176 pPads[histPos[hstEN][0]][histPos[hstEN][1]]->cd();
177 hst[kNA] = pHist[kNA][hstEN];
178 hst[kAL] = pHist[kAL][hstEN];
179 // default histogram configuration
180 hst[kDEF]->SetLineColor(kRed);
181 hst[kDEF]->SetLineWidth(2);
182 hst[kDEF]->SetStats(0);
183 if (hst[kSEC])
184 hst[kSEC]->SetStats(0);
185 hstOpt[kNA] = "HIST";
186 hstOpt[kAL] = "C SAME";
187 // every TPaveText object is left in heap due to ROOT macro drawing specifics
188 pave = new TPaveText(0.6, 0.85, 0.95, 0.92, "BR NDC");
189 switch (hstEN) {
190 case kTracksCount:
191 case kVertexCount:
192 hst[kDEF]->GetXaxis()->SetBinLabel(1, "");
193 hst[kDEF]->GetXaxis()->SetBinLabel(kNA + 2, "Not aligned");
194 hst[kDEF]->GetXaxis()->SetBinLabel(kAL + 2, "Aligned");
195 hst[kDEF]->GetXaxis()->SetBinLabel(4, "");
196 hst[kDEF]->SetFillColor(hstEN == kTracksCount ? kCyan : kTeal);
197 hst[kDEF]->SetBarWidth(0.8);
198 hst[kDEF]->SetBarOffset(0.1);
199 hstOpt[kDEF] = "BAR";
200 pave->AddText(hstEN == kTracksCount ? Form("Tracks increase: %+5.1f%%", rTracksIncrease)
201 : Form("Vertex increase: %+5.1f%%", rVertexIncrease));
202 break;
204 colorNA = kCyan;
205 pave->AddText(Form("Mean decrease: %+5.1f%%", rTracksChi2perNDFMeanDecrease));
206 break;
207 case kVertexX:
208 case kVertexY:
209 case kVertexZ:
210 colorNA = (hstEN == kVertexZ) ? kGreen : kTeal;
211 if (hstEN == kVertexX)
212 value = rVertexXStdDevDecrease;
213 else if (hstEN == kVertexY)
214 value = rVertexYStdDevDecrease;
215 else if (hstEN == kVertexZ)
216 value = rVertexZStdDevDecrease;
217 pave->AddText(Form("StdDev decrease: %+5.1f%%", value));
218 break;
219 case kVertexXYbefore:
220 case kVertexXYafter:
221 hstOpt[kDEF] = "CONTZ";
222 delete pave, pave = nullptr;
223 break;
224 default:
225 hst[kNA] = nullptr;
226 hst[kAL] = nullptr;
227 delete pave, pave = nullptr;
228 }
229 if (hst[kNA]) {
230 hst[kNA]->SetFillColor(colorNA);
231 hst[kNA]->SetLineColor(colorNA);
232 if (hstOpt[kNA] != "CONTZ")
233 hst[kNA]->GetYaxis()->SetRangeUser(0.0, hst[kAL]->GetMaximum() * 1.1);
234 hst[kNA]->Draw(hstOpt[kNA]);
235 }
236 if (hst[kAL])
237 hst[kAL]->Draw(hstOpt[kAL]);
238 if (pave)
239 pave->Draw();
240 }
241
242 // report to PDF
243 if (BMN_RESULT_PDF)
244 pCnv->SaveAs(BMN_RESULT_PDF);
245
246 // partial cleanup
247 for (UInt_t i = 0; i < 2; i++) {
248 delete pData[i];
249 delete pTracks[i];
250 delete pVertex[i];
251 }
252
253 return 0;
254}
int i
Definition P4_F32vec4.h:22
int Int_t
unsigned int UInt_t
constexpr Bool_t kFALSE
double Double_t
EColor
kTeal
kRed
kGreen
kCyan
char * Form(const char *fmt,...)
CbmVertex.h.
Definition CbmVertex.h:21
Double_t GetZ() const
Definition CbmVertex.h:60
Double_t GetX() const
Accessors.
Definition CbmVertex.h:58
Int_t GetNTracks() const
Definition CbmVertex.h:63
Double_t GetY() const
Definition CbmVertex.h:59
virtual void SetFillColor(Color_t fcolor)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetBinLabel(Int_t bin, const char *label)
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
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)
virtual void SetBarOffset(Float_t offset=0.25)
static void StatOverflows(Bool_t flag=kTRUE)
virtual Double_t GetStdDev(Int_t axis=1) const
virtual Double_t GetMean(Int_t axis=1) const
TAxis * GetXaxis()
TAxis * GetYaxis()
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual void Scale(Double_t c1=1, Option_t *option="")
virtual void SetBarWidth(Float_t width=0.5)
virtual void SetStats(Bool_t stats=kTRUE)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
void SaveAs(const char *filename="", Option_t *option="") const override
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
virtual TText * AddText(const char *label)
void Draw(Option_t *option="") override
#define PADS_Y
Definition compareA.C:39
#define RES_Y
Definition compareA.C:37
#define PADS_X
Definition compareA.C:38
eAligned
Definition compareA.C:42
@ kNA
Definition compareA.C:43
@ kAL
Definition compareA.C:44
constexpr Int_t kDEF
Definition compareA.C:46
int compareA(int argc=0, char **argv=nullptr)
Definition compareA.C:73
eCmpHists
Definition compareA.C:49
@ kVertexX
Definition compareA.C:53
@ kVertexXYafter
Definition compareA.C:57
@ kVertexY
Definition compareA.C:54
@ kVertexZ
Definition compareA.C:55
@ kCount
Definition compareA.C:58
@ kTracksCount
Definition compareA.C:50
@ kVertexCount
Definition compareA.C:51
@ kTracksChi2perNDF
Definition compareA.C:52
@ kVertexXYbefore
Definition compareA.C:56
static constexpr const char * BMN_RESULT_PDF
Definition compareA.C:32
constexpr Int_t kSEC
Definition compareA.C:46
#define RES_X
Definition compareA.C:36
#define BMN_FILELIST_A
Definition compareA.C:31
#define BMN_FILELIST_NA
Definition compareA.C:30
constexpr const Int_t histPos[eCmpHists::kCount][2]
Definition compareA.C:62
Definition json.hpp:4446