BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
Draw_L1_histo.C
Go to the documentation of this file.
1#include <unistd.h> // for dir navigation
2
3const int textFont = 22; // TNewRoman
4const bool divide = 0; // = 0 - each histo in separate file\screen. = 1 - all in one file\screen
5
6void FitHistoGaus(TH1* hist, float* sigma = 0)
7{
8 if (hist && (hist->GetEntries() != 0)) {
9 TF1* fit = new TF1("fit", "gaus");
10 fit->SetLineColor(2);
11 fit->SetLineWidth(3);
12 hist->Fit("fit", "", "", hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
13 if (sigma)
14 *sigma = fit->GetParameter(2);
15 } else {
16 std::cout << " E: Read hists error! " << std::endl;
17 }
18}
19
20void FitHistoLine(TH1* hist)
21{
22 if (hist && (hist->GetEntries() != 0)) {
23 TF1* fit = new TF1("fit", "[0]");
24 fit->SetLineColor(2);
25 fit->SetLineWidth(3);
26 hist->Fit("fit", "", "", hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
27 } else {
28 std::cout << " E: Read hists error! " << std::endl;
29 }
30}
31
32void makeUpHisto(TH1* hist, TString title)
33{
34 if (hist && (hist->GetEntries() != 0)) {
35
40
41 hist->GetXaxis()->SetTitle(title);
42 hist->GetXaxis()->SetTitleOffset(1);
43 hist->GetYaxis()->SetTitle("Entries");
44 hist->GetYaxis()->SetTitleOffset(1.05); // good then entries per bit <= 9999
45 } else {
46 std::cout << " E: Read hists error! " << std::endl;
47 }
48}
49
50void makeUpHisto(TH2* hist, TString title)
51{
52 if (hist && (hist->GetEntries() != 0)) {
53 // hist->GetXaxis()->SetLabelFont(textFont);
54 // hist->GetXaxis()->SetTitleFont(textFont);
55 // hist->GetYaxis()->SetLabelFont(textFont);
56 // hist->GetYaxis()->SetTitleFont(textFont);
57
58 // hist->GetXaxis()->SetTitle(title);
59 // hist->GetXaxis()->SetTitleOffset(1);
60 // hist->GetYaxis()->SetTitle("Entries");
61 // hist->GetYaxis()->SetTitleOffset(1.05); // good then entries per bit <= 9999
62
63 hist->SetOption("CONTZ");
64 } else {
65 std::cout << " E: Read hists error! " << std::endl;
66 }
67}
68
69void makeUpProfile(TProfile* prof, TString titleX, TString titleY)
70{
71 if (prof && (prof->GetEntries() != 0)) {
72 prof->SetMarkerColor(kRed);
73 prof->SetLineColor(kRed);
74
75 prof->GetXaxis()->SetTitle(titleX);
76 prof->GetXaxis()->SetTitleOffset(1);
77 prof->GetYaxis()->SetTitle(titleY);
78 prof->GetYaxis()->SetTitleOffset(0.85);
79
84 } else {
85 std::cout << " E: Read profile error! " << std::endl;
86 }
87}
88
90{
91
92 // ============================ Set Styles ============================
93 TStyle* histoStyle = new TStyle("histoStyle", "Plain Style(no colors/fill areas)");
94 // TStyle *histoStyle = gStyle;
95
96 histoStyle->SetTextFont(textFont);
97 histoStyle->SetPadColor(0);
98 histoStyle->SetCanvasColor(0);
99 histoStyle->SetTitleColor(0);
100 histoStyle->SetStatColor(0);
101
102 histoStyle->SetOptTitle(0); // without main up title
103 histoStyle->SetOptStat(1000111010);
104 // The parameter mode can be = ksiourmen (default = 000001111)
105 // k = 1; kurtosis printed
106 // k = 2; kurtosis and kurtosis error printed
107 // s = 1; skewness printed
108 // s = 2; skewness and skewness error printed
109 // i = 1; integral of bins printed
110 // o = 1; number of overflows printed
111 // u = 1; number of underflows printed
112 // r = 1; rms printed
113 // r = 2; rms and rms error printed
114 // m = 1; mean value printed
115 // m = 2; mean and mean error values printed
116 // e = 1; number of entries printed
117 // n = 1; name of histogram is printed
118
119 histoStyle->SetOptFit(10001);
120 // The parameter mode can be = pcev (default = 0111)
121 // p = 1; print Probability
122 // c = 1; print Chisquare/Number of degress of freedom
123 // e = 1; print errors (if e=1, v must be 1)
124 // v = 1; print name/values of parameters
125
126 histoStyle->SetStatW(0.175);
127 histoStyle->SetStatH(0.02);
128 histoStyle->SetStatX(0.95);
129 histoStyle->SetStatY(0.97);
130 histoStyle->SetStatFontSize(0.05);
131
132 histoStyle->SetStatFont(textFont);
133 histoStyle->SetPadBorderMode(0);
134 histoStyle->SetFrameBorderMode(0);
135
136 histoStyle->SetPalette(1); // for 2D
137
138 TStyle* profStyle = new TStyle("profStyle", "Plain Style(no colors/fill areas)");
139 // TStyle *profStyle = gStyle;
140
141 profStyle->SetTextFont(textFont);
142 profStyle->SetPadColor(0);
143 profStyle->SetCanvasColor(0);
144 profStyle->SetTitleColor(0);
145 profStyle->SetStatColor(0);
146
147 profStyle->SetOptTitle(0); // without main up title
148 profStyle->SetOptStat(0);
149 profStyle->SetOptFit(0);
150 profStyle->SetGridStyle(2);
151
152 profStyle->SetPadBorderMode(0);
153 profStyle->SetFrameBorderMode(0);
154
155 // ============================ Open file ============================
156
157 const TString fileName = "L1_histo.root";
158
159 TFile* fileIn = new TFile(fileName.Data(), "read");
160
161 FILE *ress, *pulls;
162 ress = fopen("resolution.txt", "w");
163 pulls = fopen("pull.txt", "w");
164
165 // ------------ make histos -----------
166
167 // ------------ tracks -----------
168
169 TString dirFitName = "/L1/Fit";
170 dirFitName = fileName + ":" + dirFitName;
171 TDirectory* dirFit = fileIn->Get(dirFitName);
172
173 const int nHisto = 40;
174
175 struct THistoData
176 {
177 char* name; // one, which used in input file
178 char* title; // for X-axis
179 };
180 const THistoData histoData[nHisto] = {
181 {"fst_x", "Residual (x^{reco}-x^{mc}) [#mum]"} {"fst_y", "Residual (y^{reco}-y^{mc}) [#mum]"} {
182 "fst_tx", "Residual (t_{x}^{reco}-t_{x}^{mc}) [10^{-3}]"} {
183 "fst_ty", "Residual (t_{y}^{reco}-t_{y}^{mc}) [10^{-3}]"} {"fst_P", "Resolution (p^{reco}-p^{mc})/p^{mc}"} {
184 "fst_px", "Pull x"} {"fst_py", "Pull y"} {"fst_ptx", "Pull t_{x}"} {"fst_pty", "Pull t_{y}"} {"fst_pQP",
185 "Pull q/p"}
186
187 {"lst_pQP", "Pull q/p"} {"lst_ptx", "Pull t_{x}"} {"lst_pty", "Pull t_{y}"} {"lst_px", "Pull x"} {"lst_py",
188 "Pull y"} {
189 "lst_P", "Resolution (p^{reco}-p^{mc})/p^{mc}"} {"lst_tx", "Residual (t_{x}^{reco}-t_{x}^{mc}) [mrad]"} {
190 "lst_ty", "Residual (t_{y}^{reco}-t_{y}^{mc}) [mrad]"} {"lst_x", "Residual (x^{reco}-x^{mc}) [#mum]"} {
191 "lst_y", "Residual (y^{reco}-y^{mc}) [#mum]"} {"svrt_pQP", "Pull q/p"} {"svrt_ptx", "Pull t_{x}"} {
192 "svrt_pty", "Pull t_{y}"} {"svrt_px", "Pull x"} {"svrt_py", "Pull y"} {
193 "svrt_P", "Resolution (p^{reco}-p^{mc})/p^{mc}"} {"svrt_tx", "Residual (t_{x}^{reco}-t_{x}^{mc}) [mrad]"} {
194 "svrt_ty", "Residual (t_{y}^{reco}-t_{y}^{mc}) [mrad]"} {"svrt_x", "Residual (x^{reco}-x^{mc}) [#mum]"} {
195 "svrt_y", "Residual (y^{reco}-y^{mc}) [#mum]"} {"pvrt_pQP", "Pull q/p"} {"pvrt_ptx", "Pull t_{x}"} {
196 "pvrt_pty", "Pull t_{y}"} {"pvrt_px", "Pull x"} {"pvrt_py", "Pull y"} {
197 "pvrt_P", "Resolution (p^{reco}-p^{mc})/p^{mc}"} {"pvrt_tx", "Residual (t_{x}^{reco}-t_{x}^{mc}) [mrad]"} {
198 "pvrt_ty", "Residual (t_{y}^{reco}-t_{y}^{mc}) [mrad]"} {"pvrt_x", "Residual (x^{reco}-x^{mc}) [#mum]"} {
199 "pvrt_y", "Residual (y^{reco}-y^{mc}) [#mum]"}};
200
201 TH1F* histo[nHisto];
202
203 float charat[nHisto][2]; // 0 - sigma, 1 - RMS
204 for (int i = 0; i < nHisto; i++) {
205 histo[i] = (TH1F*)dirFit->Get(histoData[i].name);
206 makeUpHisto(histo[i], histoData[i].title);
207 FitHistoGaus(histo[i], &(charat[i][0]));
208 charat[i][1] = histo[i]->GetRMS();
209 }
210
211 cout.setf(std::ios::scientific, std::ios::floatfield);
212 cout.precision(2);
213 cout << endl << "Name " << " \t" << " Sigma " << "\t" << " RMS " << endl;
214 for (int i = 0; i < nHisto; i++) {
215 cout << histoData[i].name << " \t" << charat[i][0] << "\t" << charat[i][1] << endl;
216 }
217 // ------------ hits, strips -----------
218
219 TString dirInputName = "/L1/Input";
220 dirInputName = fileName + ":" + dirInputName;
221 TDirectory* dirInput = fileIn->Get(dirInputName);
222
223 const int nHistoInput = 4;
224
225 const THistoData histoDataInput[nHisto] = {{"Px", "Pull x"} {"Py", "Pull y"} {
226 "x", "Residual (x^{hit}-x^{mc}) [#mum]"} {"y", "Residual (y^{hit}-y^{mc}) [#mum]"}};
227
228 TH1F* histoInput[nHistoInput];
229
230 for (int i = 0; i < nHistoInput; i++) {
231 histoInput[i] = (TH1F*)dirInput->Get(histoDataInput[i].name);
232 makeUpHisto(histoInput[i], histoDataInput[i].title);
233 FitHistoGaus(histoInput[i]);
234 }
235
236 // ------------ other histo -----------
237
238 TString dirOtherName = "/L1";
239 dirOtherName = fileName + ":" + dirOtherName;
240 TDirectory* dirOther = fileIn->Get(dirOtherName);
241
242 const int nHistoOther = 15;
243
244 const THistoData histoDataOther[nHisto] = {
245 {"h_acc_MCmom", "Momentum of tracks"} {"h_reco_MCmom", "Momentum of tracks"} {
246 "h_unreco_MCmom", "Momentum of tracks"} {"h_ghost_Rmom", "Momentum of tracks"} {
247 "h_acc_prim_MCmom", "Momentum of tracks"} {"h_reco_prim_MCmom", "Momentum of tracks"} {
248 "h_unreco_prim_MCmom", "Momentum of tracks"} {"h_ghost_Rmom", "Momentum of tracks"} {
249 "h_acc_sec_MCmom", "Momentum of tracks"} {"h_reco_sec_MCmom", "Momentum of tracks"} {
250 "h_unreco_sec_MCmom", "Momentum of tracks"} {"h_ghost_Rmom", "Momentum of tracks"}
251 // reg,acc,reco,ghost distribution always have to be first
252 {"h_reco_prob", "Prob of reco track"} {"h_ghost_prob", "Prob of ghost track"} {"h_rest_prob",
253 "Prob of reco rest track"}};
254
255 TH1F* histoOther[nHistoOther];
256
257 for (int i = 0; i < 12; i++) {
258 if (i % 4 != 2)
259 histoOther[i] = (TH1F*)dirOther->Get(histoDataOther[i].name);
260 else {
261 histoOther[i] = new TH1F(histoDataOther[i].name, "Not reconstructed tracks", 100, 0.0, 5.0);
262 for (j = 0; j < histoOther[i]->GetNbinsX(); j++) {
263 histoOther[i]->SetBinContent(j,
264 histoOther[i - 2]->GetBinContent(j) - histoOther[i - 1]->GetBinContent(j));
265 }
266 }
267 makeUpHisto(histoOther[i], histoDataOther[i].title);
268 }
269
270 for (int i = 12; i < nHistoOther; i++) {
271 histoOther[i] = (TH1F*)dirOther->Get(histoDataOther[i].name);
272 makeUpHisto(histoOther[i], histoDataOther[i].title);
273 FitHistoLine(histoOther[i]);
274 }
275
276 // ------------ other 2D histo -----------
277
278 TString dirOther2DName = "/L1";
279 dirOther2DName = fileName + ":" + dirOther2DName;
280 TDirectory* dirOther2D = fileIn->Get(dirOther2DName);
281
282 const int nHistoOther2D = 1;
283
284 const THistoData histoDataOther2D[nHisto] = {
285 {"h2_reco_nhits_vs_mom_prim", "NHits and momentum for primary"} // {"h2_reco_prob_ndf", "Prob and NDF" }
286 // {"h2_reco_prob_mom", "Prob and momentum" }
287 // {"h2_reco_prob_teta", "Prob and teta" }
288 // {"h2_teta_prob", "Prob" }
289 // {"h2_teta_probI", "ProbI" }
290 // {"h2_teta_probO", "ProbO" }
291 };
292
293 TH2F* histoOther2D[nHistoOther2D];
294
295 for (int i = 0; i < nHistoOther2D; i++) {
296 histoOther2D[i] = (TH2F*)dirOther2D->Get(histoDataOther2D[i].name);
297 makeUpHisto(histoOther2D[i], histoDataOther2D[i].title);
298 }
299
300 // ------------ make profiles -----------
301
302 TString dirName = "/L1";
303 dirName = fileName + ":" + dirName;
304 TDirectory* dir = fileIn->Get(dirName);
305
306 const int nProf = 4;
307 struct TProfData
308 {
309 char* name; // one, which used in input file
310 char* titleX; // for X-axis
311 char* titleY; // for Y-axis
312 };
313 const TProfData profData[nProf] = {
314 {"p_eff_all_vs_mom", "Momentum [GeV/c]", "Efficiency [%]"} {"p_eff_all_vs_nhits", "NMCHits", "Efficiency [%]"} {
315 "p_eff_prim_vs_nhits", "NMCHits", "Efficiency [%]"} {"p_eff_sec_vs_nhits", "NMCHits", "Efficiency [%]"}};
316
317 TProfile* profile[nProf];
318
319 for (int i = 0; i < nProf; i++) {
320 profile[i] = (TProfile*)dir->Get(profData[i].name);
321 makeUpProfile(profile[i], profData[i].titleX, profData[i].titleY);
322 }
323
324 // ============================ Draw ============================
325 // TCanvas *c1;
326 // c1 = new TCanvas("c1","c1",0,0,1200,800);
327 // c1 -> Divide(nHisto);
328 //
329 // c1->UseCurrentStyle();
330 //
331 // for (int i = 0; i < nHisto; i++){
332 // c1->cd(i+1);
333 // histo[i]->Draw();
334 // }
335
336 // c1->SaveAs("histo.png");
337
338 system("mkdir L1_histo -p");
339 chdir("L1_histo");
340
341 histoStyle->cd();
342 TCanvas *c2, *c3;
343 c2 = new TCanvas("c2", "c2", 0, 0, 900, 600);
344 c3 = new TCanvas("c3", "c3", 0, 0, 900, 600);
345 c3->Divide(5, 2);
346
347 int iPart = 1;
348 for (int i = 0; i < 10; i++) {
349 c3->cd(iPart++);
350 histo[i]->Draw();
351 }
352 c3->SaveAs("fst.pdf");
353
354 c2->cd();
355 for (int i = 0; i < nHisto; i++) {
356 histo[i]->Draw();
357 TString name = TString(histoData[i].name) + ".pdf";
358 c2->SaveAs(name);
359 }
360
361 for (int i = 0; i < nHistoInput; i++) {
362 histoInput[i]->Draw();
363 TString name = TString(histoDataInput[i].name) + ".pdf";
364 c2->SaveAs(name);
365 }
366
367 // draw reg,acc,reco,ghost distribution
368 histoStyle->SetOptStat(000000000);
369 for (int j = 0, iH = 0; j < 3; j++) {
370 TLegend* leg1 = new TLegend(0.2 + 0.3, .62, 0.55 + 0.3, .75);
371 leg1->SetFillColor(0);
372 leg1->SetLineWidth(0);
373 leg1->SetBorderSize(0);
374 leg1->SetTextFont(22);
375 for (int i = 0; i < 4; i++, iH++) {
376 switch (i) {
377 case 0:
378 histoOther[iH]->SetLineColor(kBlue);
379 break;
380 case 1:
381 histoOther[iH]->SetLineColor(kRed);
382 break;
383 case 2:
384 histoOther[iH]->SetLineColor(kBlue);
385 histoOther[iH]->SetLineStyle(2);
386 break;
387 case 3:
388 histoOther[iH]->SetLineColor(kBlack);
389 break;
390 }
391 if (i == 0)
392 histoOther[iH]->Draw();
393 else
394 histoOther[iH]->Draw("same");
395 leg1->AddEntry(histoOther[iH], histoOther[iH]->GetTitle());
396 }
397 leg1->Draw();
398 switch (j) {
399 case 0:
400 c2->SaveAs("MultiplicityMom.pdf");
401 break;
402 case 1:
403 c2->SaveAs("MultiplicityMomPrim.pdf");
404 break;
405 case 2:
406 c2->SaveAs("MultiplicityMomSec.pdf");
407 break;
408 }
409 }
410 histoStyle->SetOptStat(1000111010);
411
412 for (int i = 12; i < nHistoOther; i++) {
413 histoOther[i]->Draw();
414 TString name = TString(histoDataOther[i].name) + ".pdf";
415 c2->SaveAs(name);
416 }
417
418 histoStyle->SetOptStat(1000000010);
419 for (int i = 0; i < nHistoOther2D; i++) {
420 histoOther2D[i]->Draw();
421 TString name = TString(histoDataOther2D[i].name) + ".pdf";
422 c2->SaveAs(name);
423 }
424 histoStyle->SetOptStat(1000111010);
425
426 profStyle->cd();
427 c2->cd();
428 for (int i = 0; i < nProf; i++) {
429 c2->SetGridx();
430 c2->SetGridy();
431 profile[i]->Draw();
432 TString name = TString(profData[i].name) + ".pdf";
433 c2->SaveAs(name);
434 }
435
436 chdir("..");
437}
const int textFont
void makeUpProfile(TProfile *prof, TString titleX, TString titleY)
void FitHistoGaus(TH1 *hist, float *sigma=0)
void FitHistoLine(TH1 *hist)
const bool divide
void makeUpHisto(TH1 *hist, TString title)
void Draw_L1_histo()
int i
Definition P4_F32vec4.h:22
kRed
kBlack
kBlue
virtual void SetTitleOffset(Float_t offset=1)
virtual void SetTitleFont(Style_t font=62)
virtual void SetLabelFont(Style_t font=62)
virtual void SetFillColor(Color_t fcolor)
virtual void SetLineStyle(Style_t lstyle)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void SetTextFont(Font_t tfont=62)
Double_t GetXmax() const
Double_t GetXmin() const
TVirtualPad * cd(Int_t subpadnumber=0) override
T * Get(const char *namecycle)
virtual TObject * Get(const char *namecycle)
virtual Double_t GetParameter(const TString &name) const
TAxis * GetXaxis()
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Int_t GetNbinsX() const
TAxis * GetYaxis()
void Draw(Option_t *option="") override
Double_t GetRMS(Int_t axis=1) const
virtual void SetBinContent(Int_t bin, Double_t content)
virtual Double_t GetEntries() const
virtual void SetOption(Option_t *option=" ")
void Draw(Option_t *option="") override
TLegendEntry * AddEntry(const char *name, const char *label="", Option_t *option="lpf")
virtual void SetTitle(const char *title="")
void SetGridx(Int_t value=1) override
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
void SetGridy(Int_t value=1) override
void SaveAs(const char *filename="", Option_t *option="") const override
virtual void SetBorderSize(Int_t bordersize=4)
const char * Data() const
void SetPadBorderMode(Int_t mode=1)
void SetOptTitle(Int_t tit=1)
void SetOptStat(Int_t stat=1)
void SetStatFont(Style_t font=62)
void SetCanvasColor(Color_t color=19)
void SetStatX(Float_t x=0)
void SetFrameBorderMode(Int_t mode=1)
void SetPalette(Int_t ncolors=kBird, Int_t *colors=nullptr, Float_t alpha=1.)
void SetGridStyle(Style_t style=3)
void SetTitleColor(Color_t color=1, Option_t *axis="X")
void SetStatH(Float_t h=0.1)
virtual void cd()
void SetStatFontSize(Float_t size=0)
void SetStatColor(Color_t color=19)
void SetPadColor(Color_t color=19)
void SetStatW(Float_t w=0.19)
void SetStatY(Float_t y=0)
void SetOptFit(Int_t fit=1)