CbmRoot
Loading...
Searching...
No Matches
LmvmDraw.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2021 UGiessen, JINR-LIT
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Semen Lebedev [committer], Elena Lebedeva */
4
5#include "LmvmDraw.h"
6
7#include "CbmDrawHist.h"
8#include "CbmHistManager.h"
9#include "TCanvas.h"
10#include "TClass.h"
11#include "TEllipse.h"
12#include "TF1.h"
13#include "TFile.h"
14#include "TH1.h"
15#include "TH1D.h"
16#include "TH2D.h"
17#include "TKey.h"
18#include "TLine.h"
19#include "TMath.h"
20#include "TPad.h"
21#include "TStyle.h"
22#include "TSystem.h"
23#include "TText.h"
25#include "utils/CbmUtils.h"
26
27#include <TLegend.h>
28
29#include <iomanip>
30#include <iostream>
31#include <sstream>
32#include <string>
33
35
36using namespace std;
37using namespace Cbm;
39
40void LmvmDraw::DrawHistFromFile(const string& fileName, const string& outputDir, bool useMvd)
41{
43 fOutputDir = outputDir;
44 fUseMvd = useMvd;
45
47 TFile* oldFile = gFile;
48 TDirectory* oldDir = gDirectory;
49
50 TFile* file = new TFile(fileName.c_str());
51 fH.fHM.ReadFromFile(file);
52 fNofEvents = (int) fH.fHM.H1("hEventNumber")->GetEntries();
53 cout << "File name = " << fileName << endl;
54 cout << "Number of events = " << fNofEvents << endl;
55
56 fH.fHM.ScaleByPattern(".*", 1. / fNofEvents);
58
59 DrawAnaStepMany("pty_pair_signal", [this](ELmvmAnaStep step) { DrawPtY("hPtYPairSignal", step); });
60 for (const auto& cand : fH.fCandNames) {
61 const string& cName = "hPtY_cands/" + cand;
62 const string& hName = "hPtY_" + cand;
63 DrawAnaStepMany(cName, [this, hName](ELmvmAnaStep step) { DrawPtY(hName, step); });
64 }
65 DrawAnaStepMany("pair_rapidity", [this](ELmvmAnaStep step) { DrawRapidity(step); });
66 DrawAnaStepMany("minv_pt", [this](ELmvmAnaStep step) { DrawMinvPt(step); });
67 DrawAnaStepMany("anglePair", [this](ELmvmAnaStep step) { DrawSrcAnaStepH1("hAnglePair", step); });
68
69 // draw momentum histograms
70 for (const string hName : {"hMom", "hMomPx", "hMomPy", "hMomPz", "hPt", "hRapidity"}) {
71 DrawAnaStepMany(hName, [this, hName](ELmvmAnaStep step) { DrawSrcAnaStepH1(hName, step); });
72 DrawAnaStepMany(hName + "EpEm", [this, hName](ELmvmAnaStep step) { DrawSrcAnaStepEpEmH1(hName, step); });
73 }
75 DrawMisc();
77 DrawCuts();
83 DrawAccRecVsMom(); // TODO: finish this method!
84 DrawPmtXY();
85 DrawMinvBg(); // TODO: do not extra method
88
90 gFile = oldFile;
91 gDirectory = oldDir;
92}
93
95{
96 return (!fUseMvd && (step == ELmvmAnaStep::Mvd1Cut || step == ELmvmAnaStep::Mvd2Cut));
97}
98
100{
101 int nGroup = 25;
102 int nGroupMatch = 50;
103 int nGroupBgSrc = 50;
104 fH.Rebin("hMinv", fH.fSrcNames, fH.fAnaStepNames, nGroup);
105 fH.Rebin("hMinvBgMatch", {"trueMatch", "trueMatchEl", "trueMatchNotEl", "mismatch"}, fH.fAnaStepNames, nGroupMatch);
106 fH.Rebin("hMinvBgSource", fH.fBgPairSrcNames, fH.fAnaStepNames, nGroupBgSrc);
107}
108
110{
111 TH2D* hPos = fH.H2Clone("hBetaMom_plutoEl+");
112 TH2D* hEl = fH.H2Clone("hBetaMom_plutoEl-");
113 TCanvas* c = fH.fHM.CreateCanvas("betaMom/", "betaMom/", 1600, 800);
114 c->Divide(2, 1);
115 c->cd(1);
116 DrawH2(hEl, kLinear, kLinear, kLog, "colz");
117 c->cd(2);
118 DrawH2(hPos, kLinear, kLinear, kLog, "colz");
119}
120
121void LmvmDraw::DrawCutEffH1(const string& hist, const string& option)
122{
123 vector<TH1*> effHist;
124 for (ELmvmSrc src : fH.fSrcs) {
125 TH1D* eff = fH.H1Clone(hist, src);
126 int nBins = eff->GetNbinsX();
127 double integralTotal = fH.H1(hist, src)->Integral(1, nBins, "width");
128
129 if (option == "right") {
130 for (int iB = 1; iB <= nBins; iB++) {
131 eff->SetBinContent(iB, fH.H1(hist, src)->Integral(1, iB, "width") / integralTotal);
132 eff->GetYaxis()->SetTitle("Cut Efficiency");
133 }
134 }
135 else if (option == "left") {
136 for (int iB = nBins; iB >= 1; iB--) {
137 eff->SetBinContent(iB, fH.H1(hist, src)->Integral(iB, nBins, "width") / integralTotal);
138 eff->GetYaxis()->SetTitle("Cut Efficiency");
139 }
140 }
141 effHist.push_back(eff);
142 }
143 DrawH1(effHist, fH.fSrcLatex, kLinear, kLinear, true, 0.8, 0.8, 0.99, 0.99, "hist");
144}
145
146void LmvmDraw::DrawAnaStepMany(const string& cName, function<void(ELmvmAnaStep)> drawFunc)
147{
148 int hi = 1;
149 string newCName = cName + "/" + cName + "_all";
150 TCanvas* c = fH.fHM.CreateCanvas(newCName.c_str(), newCName.c_str(), 1600, 1200);
151 c->Divide(4, 3);
152 for (const auto step : fH.fAnaSteps) {
153 if (SkipMvd(step)) continue;
154 c->cd(hi++);
155 drawFunc(step);
156 }
157
158 for (const auto step : fH.fAnaSteps) {
159 if (SkipMvd(step)) continue;
160 newCName = cName + "/" + cName + "_" + fH.fAnaStepNames[static_cast<int>(step)];
161 fH.fHM.CreateCanvas(newCName.c_str(), newCName.c_str(), 800, 800);
162 drawFunc(step);
163 }
164}
165
166void LmvmDraw::DrawPtY(const string& hist, ELmvmAnaStep step)
167{
168 TH2D* h = fH.H2(hist.c_str(), step);
169 TH2D* hmc = fH.H2(hist.c_str(), ELmvmAnaStep::Mc);
170 DrawH2(h, kLinear, kLinear, kLinear, "COLZ");
171 bool drawAnaStep = true;
172 if (drawAnaStep) fH.DrawEfficiency(h, hmc, 0.2, 1.8);
173 if (drawAnaStep) fH.DrawAnaStepOnPad(step);
174}
175
177{
178 DrawH1(fH.H2("hPtYPairSignal", step)->ProjectionX(), kLinear, kLinear, "hist");
179 fH.DrawAnaStepOnPad(step);
180}
181
183{
184 TH2D* h = fH.H2("hPtYPairSignal", step);
185 TH2D* hmc = fH.H2("hPtYPairSignal", ELmvmAnaStep::Mc);
186 TH2D* eff = Cbm::DivideH2(h, hmc, "", 100., "Efficiency [%]");
187 DrawH2(eff);
188 eff->SetMaximum(10.);
189 bool drawAnaStep = true;
190 if (drawAnaStep) fH.DrawEfficiency(h, hmc, 0.2, 1.8);
191 if (drawAnaStep) fH.DrawAnaStepOnPad(step);
192}
193
195{
196 TH2D* h = fH.H2("hMinvPt", ELmvmSrc::Signal, step);
197 DrawH2(h, kLinear, kLinear, kLinear, "COLZ");
198 fH.DrawAnaStepOnPad(step);
199}
200
201void LmvmDraw::DrawSrcAnaStepH1(const string& hName, ELmvmAnaStep step)
202{
203 DrawSrcH1(hName, step, false);
204 fH.DrawAnaStepOnPad(step);
205}
206
207void LmvmDraw::DrawSrcAnaStepEpEmH1(const string& hName, ELmvmAnaStep step)
208{
209 vector<TH1*> hVec;
210 vector<string> latex;
212 for (const string pm : {"+", "-"}) {
213 hVec.push_back(fH.H1(hName + pm, src, step));
214 latex.push_back(fH.fSrcLatex[static_cast<int>(src)] + " (e" + pm + ")");
215 }
216 }
217 DrawH1(hVec, latex, kLinear, kLog, true, 0.90, 0.7, 0.99, 0.99, "hist");
218 fH.DrawAnaStepOnPad(step);
219}
220
222{
223 fH.fHM.CreateCanvas("mom_pairSignal", "mom_pairSignal", 800, 800);
224 DrawAnaStepH1("hMomPairSignal", true);
225
226 fH.fHM.CreateCanvas("mother_pdg", "mother_pdg", 800, 800);
227 DrawH1({fH.H1("hMotherPdg_mc")}, {"MC"}, kLinear, kLog, true, 0.7, 0.7, 0.99, 0.99, "hist");
228
229 fH.fHM.CreateCanvas("momVsAngle_pairSignal", "momVsAngle_pairSignal", 800, 800);
230 DrawH2(fH.H2("hMomVsAnglePairSignalMc"));
231}
232
234{
235 TCanvas* c = fH.fHM.CreateCanvas("pmtXY", "pmtXY", 1800, 600);
236 c->Divide(3, 1);
237 vector<ELmvmSrc> src{ELmvmSrc::Signal, ELmvmSrc::Pi0, ELmvmSrc::Gamma};
238 for (size_t i = 0; i < src.size(); i++) {
239 c->cd(i + 1);
240 DrawH2(fH.H2("hPmtXY", src[i]));
241 gPad->SetLogz(true);
242 DrawTextOnPad(fH.fSrcLatex[static_cast<int>(src[i])], 0.40, 0.9, 0.60, 0.99);
243 }
244}
245
246void LmvmDraw::DrawSrcH1(const string& hName, ELmvmAnaStep step, bool doScale)
247{
248 vector<TH1*> hVec;
249 for (const ELmvmSrc src : fH.fSrcs) {
250 TH1D* h = (step == ELmvmAnaStep::Undefined) ? fH.H1(hName, src) : fH.H1(hName, src, step);
251 h->SetLineWidth(2);
252 h->SetLineColor(fH.fSrcColors[static_cast<int>(src)]);
253 if (doScale) h->Scale(1. / h->Integral());
254 hVec.push_back(h);
255 }
256 DrawH1(hVec, fH.fSrcLatex, kLinear, kLog, true, 0.90, 0.7, 0.99, 0.99, "hist");
257}
258
259void LmvmDraw::Draw1DCut(const string& hist, const string& sigOption, double cut)
260{
261 int w = 2400;
262 int h = 800;
263 TCanvas* c = fH.fHM.CreateCanvas(("cuts/" + hist).c_str(), ("cuts/" + hist).c_str(), w, h);
264 c->Divide(3, 1);
265
266 c->cd(1);
267 DrawSrcH1(hist);
268 if (cut != -999999.) {
269 TLine* cutLine = new TLine(cut, 0.0, cut, 1.0);
270 cutLine->SetLineWidth(2);
271 cutLine->Draw();
272 }
273
274 c->cd(2);
275 DrawCutEffH1(hist, sigOption);
276
277 c->cd(3);
278 TH1D* sign = fH.CreateSignificanceH1(fH.H1(hist, ELmvmSrc::Signal), fH.H1(hist, ELmvmSrc::Bg), hist + "_significance",
279 sigOption);
280 DrawH1(sign, kLinear, kLinear, "hist");
281}
282
284{
285 Draw1DCut("hChi2PrimVertex", "right", fCuts.fChi2PrimCut);
286 //Draw1DCut("hPt", "left", fCuts.fPtCut);
287 //Draw1DCut("hMom", "left");
288 Draw1DCut("hChi2Sts", "right");
289
290 for (const string type : {"all", "pion", "truePair"}) {
291 Draw2DCut("hStCut_" + type, fCuts.fStCutPP, fCuts.fStCutAngle);
292 Draw2DCut("hTtCut_" + type, fCuts.fTtCutPP, fCuts.fTtCutAngle);
293 Draw2DCut("hRtCut_" + type, fCuts.fRtCutPP, fCuts.fRtCutAngle);
294 }
295
296 if (fUseMvd) {
297 Draw2DCut("hMvdCut_1", fCuts.fMvd1CutD, fCuts.fMvd1CutP);
298 Draw2DCut("hMvdCut_2", fCuts.fMvd2CutD, fCuts.fMvd2CutP);
299 }
300}
301
302
303void LmvmDraw::DrawBgSourcePairs(ELmvmAnaStep step, bool inPercent, bool drawAnaStep)
304{
305 TH2D* h = fH.H2Clone("hSrcBgPairsEpEm", step);
306 gStyle->SetPaintTextFormat("4.1f");
307 string labels[4] = {"#gamma", "#pi^{0}", "#pi^{#pm}", "oth"};
308 for (int i = 1; i <= 4; i++) {
309 h->GetYaxis()->SetBinLabel(i, labels[i - 1].c_str());
310 h->GetXaxis()->SetBinLabel(i, labels[i - 1].c_str());
311 }
312 h->SetMarkerSize(2.5);
313 if (inPercent) {
314 h->Scale(100. / h->Integral());
315 h->GetZaxis()->SetTitle("[%]");
316 }
317 else {
318 h->Scale(1000.);
319 h->GetZaxis()->SetTitle("Number of pairs/event x10^{3}");
320 }
321 DrawH2(h, kLinear, kLinear, kLinear, "text COLZ");
322 h->GetXaxis()->SetLabelSize(0.1);
323 h->GetYaxis()->SetLabelSize(0.1);
324 if (drawAnaStep) fH.DrawAnaStepOnPad(step);
325}
326
328{
329 int hi = 1;
330 TCanvas* c1 = fH.fHM.CreateCanvas("bg/srcPairs_abs", "bg/srcPairs_abs", 1500, 1500);
331 c1->Divide(3, 3);
332 for (ELmvmAnaStep step : fH.fAnaSteps) {
333 if (step == ELmvmAnaStep::Mc || step == ELmvmAnaStep::Acc || SkipMvd(step)) continue;
334 c1->cd(hi++);
335 DrawBgSourcePairs(step, false);
336 }
337
338 hi = 1;
339 TCanvas* c2 = fH.fHM.CreateCanvas("bg/srcPairs_perc", "bg/srcPairs_perc", 1500, 1500);
340 c2->Divide(3, 3);
341 for (ELmvmAnaStep step : fH.fAnaSteps) {
342 if (step == ELmvmAnaStep::Mc || step == ELmvmAnaStep::Acc || SkipMvd(step)) continue;
343 c2->cd(hi++);
344 DrawBgSourcePairs(step, true);
345 }
346
347 string elidCutName = fH.fAnaStepNames[static_cast<int>(ELmvmAnaStep::ElId)];
348 fH.fHM.CreateCanvas("bg/srcPairs_abs_" + elidCutName, "bg/srcPairs_abs_" + elidCutName, 1100, 800);
350
351 fH.fHM.CreateCanvas("bg/srcPairs_perc_" + elidCutName, "bg/srcPairs_perc_" + elidCutName, 1100, 800);
353
354 DrawSource2D("bg/srcPairs_2d", "hSrcBgPairs", fH.fBgPairSrcLatex, 1000., "Pairs per event x10^{3}");
355}
356
357void LmvmDraw::Draw2DCutTriangle(double xCr, double yCr)
358{
359 if (xCr == -999999. || yCr == -999999.) return;
360 vector<TLine*> lines{new TLine(0., 0., xCr, 0.), new TLine(0., 0., 0., yCr), new TLine(xCr, 0., 0., yCr)};
361 for (size_t i = 0; i < lines.size(); i++) {
362 lines[i]->SetLineWidth(2.);
363 lines[i]->Draw();
364 }
365}
366
368{
369 TH1D* gg = fH.H1Clone("hMinvBgSource2_elid_gg");
370 //TH1D* pipi = fH.H1Clone("hMinvBgSource2_elid_pipi");
371 TH1D* pi0pi0 = fH.H1Clone("hMinvBgSource2_elid_pi0pi0");
372 //TH1D* oo = fH.H1Clone("hMinvBgSource2_elid_oo");
373 //TH1D* gpi = fH.H1Clone("hMinvBgSource2_elid_gpi");
374 TH1D* gpi0 = fH.H1Clone("hMinvBgSource2_elid_gpi0");
375 TH1D* go = fH.H1Clone("hMinvBgSource2_elid_go");
376 //TH1D* pipi0 = fH.H1Clone("hMinvBgSource2_elid_pipi0");
377 //TH1D* pio = fH.H1Clone("hMinvBgSource2_elid_pio");
378 TH1D* pi0o = fH.H1Clone("hMinvBgSource2_elid_pi0o");
379
380 int reb = 50;
381
382 gg->Rebin(reb);
383 pi0pi0->Rebin(reb);
384 gpi0->Rebin(reb);
385 go->Rebin(reb);
386 pi0o->Rebin(reb);
387
388 gg->Scale(1. / reb);
389 pi0pi0->Scale(1. / reb);
390 gpi0->Scale(1. / reb);
391 go->Scale(1. / reb);
392 pi0o->Scale(1. / reb);
393
394 string cName = "minvBgSrc/minvBgSrc";
395 //vector<string> names = {"#gamma-#gamma", "#pi^{#pm}-#pi^{#pm}", "#pi^{0}-#pi^{0}", "o.-o.", "#gamma-#pi^{#pm}", "#gamma-#pi^{0}", "#gamma-o.", "#pi^{#pm}-#pi^{0}", "#pi^{#pm}-o.", "#pi^{0}-o.", "misid. #pi^{#pm}"};
396 vector<string> names = {"#gamma-#gamma", "#pi^{0}-#pi^{0}", "#gamma-#pi^{0}", "#gamma-o.", "#pi^{0}-o."};
397 fH.fHM.CreateCanvas(cName.c_str(), cName.c_str(), 1000, 1000);
398 //DrawH1({gg, pipi, pi0pi0, oo, gpi, gpi0, go, pipi0, pio, pi0o}, names, kLinear, kLog, true, 0.85, 0.7, 0.99, 0.99, "hist");
399 DrawH1({gg, pi0pi0, gpi0, go, pi0o}, names, kLinear, kLog, true, 0.85, 0.7, 0.99, 0.99, "hist");
400}
401
403{
404 // All occuring PIDs
405 for (ELmvmAnaStep step : fH.fAnaSteps) {
406 if (step == ELmvmAnaStep::Mc || step == ELmvmAnaStep::Acc) continue;
407 TCanvas* c = fH.fHM.CreateCanvas("purity/pid_" + fH.fAnaStepNames[static_cast<int>(step)],
408 "purity/pid_" + fH.fAnaStepNames[static_cast<int>(step)], 1600, 800);
409 c->Divide(2, 1);
410 c->cd(1);
411 DrawH1(fH.H1("hCandPdg_" + fH.fAnaStepNames[static_cast<int>(step)]), kLinear, kLog, "hist text40");
412 c->cd(2);
413 TH1D* pdgZoom = fH.H1Clone("hCandPdg_" + fH.fAnaStepNames[static_cast<int>(step)]);
414 pdgZoom->GetXaxis()->SetRangeUser(-20., 20.);
415 DrawH1(pdgZoom, kLinear, kLog, "hist text40");
416 }
417
418 // PID vs momentum
419 vector<string> yLabel = {"e^{#pm}_{PLUTO}", "e^{#pm}_{UrQMD}", "#pi^{#pm}", "p", "K^{+}", "o."};
420 for (ELmvmAnaStep step : fH.fAnaSteps) {
421 if (step == ELmvmAnaStep::Mc || step == ELmvmAnaStep::Acc) continue;
422 fH.fHM.CreateCanvas("purity/PidVsMom_" + fH.fAnaStepNames[static_cast<int>(step)],
423 "purity/PidVsMom_" + fH.fAnaStepNames[static_cast<int>(step)], 800, 600);
424 TH2D* hPidMom = fH.H2("hCandPdgVsMom_" + fH.fAnaStepNames[static_cast<int>(step)]);
425 hPidMom->SetMinimum(5e-7);
426 DrawH2(hPidMom, kLinear, kLinear, kLog, "COLZ");
427 for (size_t y = 1; y <= yLabel.size(); y++) {
428 hPidMom->GetYaxis()->SetBinLabel(y, yLabel[y - 1].c_str());
429 }
430 double nEl = hPidMom->Integral(1, hPidMom->GetXaxis()->GetNbins(), 2, 2); // do not count PLUTO particles
431 double purity =
432 (nEl / hPidMom->Integral(1, hPidMom->GetXaxis()->GetNbins(), 2, hPidMom->GetYaxis()->GetNbins())) * 100;
433 DrawTextOnPad("Purity: " + Cbm::NumberToString(purity, 1) + " %", 0.1, 0.9, 0.45, 0.99);
434 }
435
436 // Purity vs momentum
437 int nBins = fH.H2("hCandPdgVsMom_elid")->GetXaxis()->GetNbins();
438 double xMin = fH.H2("hCandPdgVsMom_elid")->GetXaxis()->GetXmin();
439 double xMax = fH.H2("hCandPdgVsMom_elid")->GetXaxis()->GetXmax();
440 TH1D* purity = new TH1D("purity_Mom", "purity_Mom; P [GeV/c]; Purity [%]", nBins, xMin, xMax);
441 for (int i = 1; i <= purity->GetNbinsX(); i++) {
442 double nEl = fH.H2("hCandPdgVsMom", ELmvmAnaStep::ElId)->GetBinContent(i, 2);
443 double nAll = fH.H2("hCandPdgVsMom", ELmvmAnaStep::ElId)
444 ->Integral(i, i, 2, fH.H2("hCandPdgVsMom_elid")->GetYaxis()->GetNbins());
445 double val = (nAll != 0) ? 100 * nEl / nAll : 0.;
446 purity->SetBinContent(i, val);
447 }
448 purity->Rebin(5);
449 purity->Scale(1. / 5.);
450 fH.fHM.CreateCanvas("purity/purity_mom_elid", "purity/purity_mom_elid", 800, 800);
451 DrawH1(purity, kLinear, kLinear, "pe");
452
453 // Source of electron (PDG = +-11) candidates
454 DrawSource2D("purity/SrcTracksEl_2d", "hCandElSrc",
455 {"#gamma", "#pi^{0}", "#pi^{#pm}", "p", "K", "e^{#pm}_{sec}", "oth.", "signal"}, 1000.,
456 "Tracks per event x10^{3}");
457}
458
459void LmvmDraw::Draw2DCut(const string& hist, double cutCrossX, double cutCrossY)
460{
461 TCanvas* c = fH.fHM.CreateCanvas(("cuts/" + hist).c_str(), ("cuts/" + hist).c_str(), 1000, 1500);
462 c->Divide(2, 3);
463 vector<TH1*> projX, projY;
464 projX.clear(); // TODO: clearing needed?
465 projY.clear();
466 vector<string> latex;
468 int srcInt = static_cast<int>(src);
469 c->cd(srcInt + 1);
470 DrawH2(fH.H2(hist, src));
471 double nofPerEvent = fH.H2(hist, src)->GetEntries() / (double) fNofEvents;
472 DrawTextOnPad((Cbm::NumberToString(nofPerEvent, 2) + "/ev."), 0.1, 0.9, 0.5, 0.99);
473 DrawTextOnPad(fH.fSrcLatex[srcInt], 0.6, 0.89, 0.7, 0.99);
474 Draw2DCutTriangle(cutCrossX, cutCrossY);
475 projX.push_back(fH.H2(hist, src)->ProjectionX((hist + fH.fSrcLatex[static_cast<int>(src)]).c_str(), 1,
476 fH.H2(hist, src)->GetYaxis()->GetNbins(), ""));
477 projY.push_back(fH.H2(hist, src)->ProjectionY());
478 latex.push_back(fH.fSrcLatex[srcInt]);
479 }
480
481 c->cd(5);
482 DrawH1(projX, latex, kLinear, kLog, true, 0.8, 0.8, 0.99, 0.99, "hist");
483
484 c->cd(6);
485 DrawH1(projY, latex, kLinear, kLog, true, 0.8, 0.8, 0.99, 0.99, "hist");
486}
487
489{
490 vector<TH2D*> xyz{fH.H2("hVertexGammaXZ", ELmvmAnaStep::Mc), fH.H2("hVertexGammaYZ", ELmvmAnaStep::Mc),
491 fH.H2("hVertexGammaXY", ELmvmAnaStep::Mc)};
492
493 TCanvas* c = fH.fHM.CreateCanvas("vertexGamma_mc", "vertexGamma_mc", 1800, 600);
494 c->Divide(3, 1);
495 for (size_t i = 0; i < xyz.size(); i++) {
496 c->cd(i + 1);
497 DrawH2(xyz[i]);
498 xyz[i]->SetMinimum(1e-3);
499 gPad->SetLogz(true);
500 }
501
502 TCanvas* cZ = fH.fHM.CreateCanvas("vertexGamma_z", "vertexGamma_z", 1500, 750);
503 cZ->Divide(2, 1);
504 int counter = 1;
506 cZ->cd(counter++);
507 string name = fH.GetName("hVertexGammaXZ", step);
508 TH1D* zProj = (TH1D*) fH.H2(name)->ProjectionX((name + "pz").c_str())->Clone();
509 zProj->GetYaxis()->SetTitle("Counter per event");
510 zProj->GetXaxis()->SetRangeUser(-2., 17.);
511 DrawH1(zProj, kLinear, kLinear, "hist");
512 fH.DrawAnaStepOnPad(step);
513 }
514
515 TCanvas* cZoom = fH.fHM.CreateCanvas("vertexGamma_mc_zoom", "vertexGamma_mc_zoom", 1800, 600);
516 cZoom->Divide(3, 1);
517 for (size_t i = 0; i < xyz.size(); i++) {
518 TH2D* hZoom = (TH2D*) xyz[i]->Clone();
519 cZoom->cd(i + 1);
520 hZoom->GetXaxis()->SetRangeUser(-1., 11.);
521 hZoom->GetYaxis()->SetRangeUser(-10., 10.);
522 DrawH2(hZoom);
523 hZoom->SetMinimum(1e-3);
524 gPad->SetLogz(true);
525 }
526
527 fH.fHM.CreateCanvas("vertexGamma_rz_mc", "vertexGamma_rz_mc", 900, 900);
528 DrawH2(fH.H2("hVertexGammaRZ", ELmvmAnaStep::Mc));
529 fH.H2("hVertexGammaRZ", ELmvmAnaStep::Mc)->SetMinimum(1e-3);
530 gPad->SetLogz(true);
531}
532
533void LmvmDraw::DrawAnaStepH1(const string& name, bool logy)
534{
535 double min = std::numeric_limits<Double_t>::max();
536 double max = std::numeric_limits<Double_t>::min();
537 TH1D* h0 = nullptr;
538 TLegend* leg = new TLegend(0.80, 0.32, 0.99, 0.99);
539 for (const auto step : fH.fAnaSteps) {
540 if (SkipMvd(step)) continue;
541 TH1D* h = fH.H1(name, step);
542 LOG(info) << name << " " << h->GetEntries();
543 if (h == nullptr || h->GetEntries() <= 0) continue;
544 leg->AddEntry(h, fH.fAnaStepLatex[static_cast<int>(step)].c_str(), "l");
545 DrawH1(h, kLinear, kLinear, (h0 == nullptr) ? "hist" : "hist,same", fH.fAnaStepColors[static_cast<int>(step)]);
546 if (h0 == nullptr) h0 = h;
547 min = std::min(h->GetMinimum(), min);
548 max = std::max(h->GetMaximum(), max);
549 }
550 if (min == 0.) min = std::min(1e-8, max * 1e-6);
551 if (h0 != nullptr) h0->SetMinimum(min);
552 if (h0 != nullptr) h0->SetMaximum(1.1 * max);
553
554 leg->SetFillColor(kWhite);
555 leg->Draw();
556
557 gPad->SetGridx(true);
558 gPad->SetGridy(true);
559 gPad->SetLogy(logy);
560}
561
563{
564 TH1D* s = fH.H1Clone("hMinv", ELmvmSrc::Signal, step);
565 TH1D* bg = fH.H1Clone("hMinv", ELmvmSrc::Bg, step);
566 TH1D* sbg = static_cast<TH1D*>(bg->Clone());
567 sbg->Add(s);
568 sbg->SetMinimum(1e-8);
569
570 DrawH1({sbg, bg, s}, {"", "", ""}, kLinear, kLog, false, 0, 0, 0, 0, "Hist L");
571 s->SetFillColor(kRed);
572 s->SetLineColor(kBlack);
573 s->SetLineWidth(1);
574 s->SetLineStyle(CbmDrawingOptions::MarkerStyle(1));
575 bg->SetFillColor(kYellow - 10);
576 bg->SetLineColor(kBlack);
577 bg->SetLineWidth(2);
578 bg->SetLineStyle(CbmDrawingOptions::MarkerStyle(1));
579 sbg->SetFillColor(kBlue);
580 sbg->SetLineColor(kBlack);
581 sbg->SetLineWidth(1);
582 sbg->SetLineStyle(CbmDrawingOptions::MarkerStyle(1));
583 s->SetMarkerStyle(1);
584 bg->SetMarkerStyle(1);
585 sbg->SetMarkerStyle(1);
586
587 fH.DrawAnaStepOnPad(step);
588}
589
591{
592 double nofBg = fH.H1("hMinv", ELmvmSrc::Bg, step)->GetEntries();
593 vector<TH1*> hists;
594 vector<string> latex;
595 for (int i = 0; i < fH.fNofBgPairSrc; i++) {
596 hists.push_back(
597 fH.H1("hMinvBgSource_" + fH.fBgPairSrcNames[i] + "_"
598 + fH.fAnaStepNames[static_cast<int>(
599 step)])); // segmentation violation error is caused by this specific histogram; works with others
600 string perc = Cbm::NumberToString(100. * hists[i]->GetEntries() / nofBg, 1);
601 latex.push_back(fH.fBgPairSrcLatex[i] + "(" + perc + "%)");
602 }
603 DrawH1(hists, latex, kLinear, kLinear, true, 0.7, 0.45, 0.99, 0.9, "hist");
604 bool drawAnaStep = true;
605 if (drawAnaStep) fH.DrawAnaStepOnPad(step);
606}
607
609{
610 double nofBg = fH.H1("hMinv", ELmvmSrc::Bg, step)->GetEntries();
611 vector<TH1*> hists;
612 vector<string> latex{"true match", "true match (e^{#pm})", "true match (not e^{#pm})", "mismatch "};
613 int i = 0;
614 for (const string subName : {"trueMatch", "trueMatchEl", "trueMatchNotEl", "mismatch"}) {
615 TH1D* h = fH.H1("hMinvBgMatch_" + subName, step);
616 latex[i] = latex[i] + " (" + Cbm::NumberToString(100. * h->GetEntries() / nofBg, 1) + "%)";
617 hists.push_back(h);
618 i++;
619 }
620 DrawH1(hists, latex, kLinear, kLinear, true, 0.4, 0.6, 0.99, 0.9, "hist");
621 fH.DrawAnaStepOnPad(step);
622}
623
625{
626 // Acceptance and reconstruction yields cs. momentum for various detector combinations
627 for (const int& pdg : {11, 211, 2212, 321}) {
628 vector<string> subNames{"mc", "acc", "recSts", "recStsRich", "recStsRichTrd", "recStsRichTrdTof"};
629 vector<string> latex{
630 "MC", "Acc", "Rec in STS", "Rec in STS-RICH", "Rec in STS-RICH-TRD", "Rec in STS-RICH-TRD-TOF"};
631 vector<string> latexAll(latex.size()), latexPrim(latex.size());
632 string ptcl = (pdg == 11) ? "hEl" : (pdg == 211) ? "hPi" : (pdg == 2212) ? "hProton" : "hKaon";
633
634 vector<TH1*> histsAll, histsPrim;
635 int i = 0;
636
637 for (const string& subName : subNames) {
638 TH1D* hAll = fH.H1(ptcl + "Mom_all_" + subName);
639 hAll->SetMinimum(3e-6);
640 hAll->SetMaximum(50);
641 latexAll[i] = latex[i] + " (" + Cbm::NumberToString(hAll->GetEntries() / fNofEvents, 2) + "/ev.)";
642 histsAll.push_back(hAll);
643
644 TH1D* hPrim = fH.H1(ptcl + "Mom_prim_" + subName);
645 hPrim->SetMinimum(3e-6);
646 hPrim->SetMaximum(50);
647 latexPrim[i] = latex[i] + " (" + Cbm::NumberToString(hPrim->GetEntries() / fNofEvents, 2) + "/ev.)";
648 histsPrim.push_back(hPrim);
649 i++;
650 }
651
652 //if (pdg == 321) continue; TODO: with kaons?
653 double y1 = 0.17; //(pdg == 211) ? 0.20 : 0.74;
654 double y2 = 0.42; //(pdg == 211) ? 0.45 : 0.99;
655 string cName = "AccRecMom/" + ptcl + "Mom";
656 fH.fHM.CreateCanvas(cName, cName, 900, 900);
657 DrawH1(histsAll, latexAll, kLinear, kLog, true, 0.4, y1, 0.95, y2, "hist");
658
659 fH.fHM.CreateCanvas(cName + "_prime", cName + "_prime", 900, 900);
660 DrawH1(histsPrim, latexPrim, kLinear, kLog, true, 0.4, y1, 0.95, y2, "hist");
661 }
662
663 // Acceptance in single detectors
664 for (const string det : {"sts", "rich", "trd", "tof"}) {
665 vector<TH1*> hVec;
666 vector<string> latex;
668 for (const string pm : {"+", "-"}) {
669 hVec.push_back(fH.H1("hMomAcc" + pm + "_" + det, src));
670 latex.push_back(fH.fSrcLatex[static_cast<int>(src)] + " (e" + pm + ")");
671 }
672 }
673 fH.fHM.CreateCanvas("AccRecMom/momDetAcc_" + det, "AccRecMom/momDetAcc_" + det, 800, 800);
674 DrawH1(hVec, latex, kLinear, kLog, true, 0.90, 0.7, 0.99, 0.99, "hist");
675 DrawTextOnPad(det, 0.4, 0.9, 0.6, 0.999);
676 }
677}
678
679void LmvmDraw::DrawSource2D(const string& cName, const string& hName, const vector<string>& yLabels, double scale,
680 const string& zTitle)
681{
682 fH.fHM.CreateCanvas((cName + "_abs").c_str(), (cName + "_abs").c_str(), 900, 600);
683 TH2D* habs = fH.H2Clone(hName);
684 habs->SetStats(false);
685 habs->Scale(scale);
686 habs->SetMinimum(1e-2);
687 habs->GetZaxis()->SetTitle(zTitle.c_str());
688 habs->SetMarkerSize(1.4);
689 DrawH2(habs, kLinear, kLinear, kLog, "text COLZ");
690
691 fH.fHM.CreateCanvas((cName + "_perc").c_str(), (cName + "_perc").c_str(), 900, 600);
692 TH2D* hperc = fH.H2Clone(hName);
693 hperc->SetStats(false);
694 for (int x = 1; x <= hperc->GetNbinsX(); x++) {
695 // calculate total number of BG tracks (pairs) for a current step
696 double nbg = 0.;
697 for (int y = 1; y <= hperc->GetNbinsY(); y++) {
698 nbg += habs->GetBinContent(x, y);
699 }
700 double sc = 100. / (nbg / scale);
701 for (int y = 1; y <= hperc->GetNbinsY(); y++) {
702 double val = sc * hperc->GetBinContent(x, y);
703 hperc->SetBinContent(x, y, val);
704 }
705 }
706 hperc->GetZaxis()->SetTitle("[%]");
707 hperc->GetYaxis()->SetLabelSize(0.06);
708 hperc->SetMarkerColor(kBlack);
709 hperc->SetMarkerSize(1.4);
710 DrawH2(hperc, kLinear, kLinear, kLinear, "text COLZ");
711
712 for (size_t y = 1; y <= yLabels.size(); y++) {
713 hperc->GetYaxis()->SetBinLabel(y, yLabels[y - 1].c_str());
714 habs->GetYaxis()->SetBinLabel(y, yLabels[y - 1].c_str());
715 }
716
717 SetAnalysisStepAxis(hperc);
719}
720
722{
723 gStyle->SetPaintTextFormat("4.1f");
724
725 fH.fHM.CreateCanvas("bg/nofBgTracks", "bg/nofBgTracks", 900, 900);
726 TH1D* hbg = fH.H1Clone("hNofBgTracks");
727 hbg->Scale(10);
728 hbg->GetYaxis()->SetTitle("Tracks/event x10");
729 DrawH1(hbg, kLinear, kLog, "hist text0");
730 hbg->SetMarkerSize(2.);
731
732 fH.fHM.CreateCanvas("signal/nofSignalTracks", "signal/nofSignalTracks", 900, 900);
733 TH1D* hel = fH.H1("hNofSignalTracks");
734 DrawH1(hel, kLinear, kLog, "hist");
735
736 fH.fHM.CreateCanvas("purity", "purity", 900, 900);
737 TH1D* purity = new TH1D("purity", "Purity;Analysis steps;Purity", fH.fNofAnaSteps, 0., fH.fNofAnaSteps);
738 purity->Divide(fH.H1("hNofBgTracks"), fH.H1("hNofSignalTracks"));
739 DrawH1(purity, kLinear, kLog, "hist text30");
740 purity->SetMarkerSize(1.9);
741
744 SetAnalysisStepAxis(purity);
745
746 DrawSource2D("bg/SrcTracksBg_2d", "hBgSrcTracks",
747 {"#gamma", "#pi^{0}", "#pi^{#pm}", "p", "K", "e^{#pm}_{sec}", "oth.", "signal"}, 1000.,
748 "Tracks per event x10^{3}");
749
750 TCanvas* c = fH.fHM.CreateCanvas("nofTopoPairs", "nofTopoPairs", 1600, 800);
751 c->Divide(2, 1);
752 int i = 1;
753 for (const string p : {"gamma", "pi0"}) {
754 c->cd(i++);
755 TH1D* hTopo = fH.H1Clone("hNofTopoPairs_" + p);
756 hTopo->Scale(1. / hTopo->Integral());
757 DrawH1(hTopo, kLinear, kLinear, "hist");
758 hTopo->SetMarkerSize(1.);
759 }
760}
761
763{
764 gStyle->SetPaintTextFormat("4.1f");
765 TCanvas* c1 = fH.fHM.CreateCanvas("nofMismatches", "nofMismatches", 1500, 1500);
766 c1->Divide(2, 2);
767 vector<string> dets{"all", "rich", "trd", "tof"};
768 for (size_t i = 0; i < dets.size(); i++) {
769 c1->cd(i + 1);
770 TH1D* h = fH.H1Clone("hNofMismatches_" + dets[i]);
771 h->Scale(10);
772 h->GetYaxis()->SetTitle(("Mismatch tracks (" + dets[i] + ")/event x10").c_str());
773 DrawH1(h, kLinear, kLog, "hist text0");
774 h->SetMarkerSize(2.);
776 }
777
778 fH.fHM.CreateCanvas("nofGhosts", "nofGhosts", 900, 900);
779 DrawH1(fH.H1("hNofGhosts"), kLinear, kLog, "hist");
780 SetAnalysisStepAxis(fH.H1("hNofGhosts"));
781}
782
784{
785 // Shift histogram content by 2 bins if MVD was not used
786 if (!fUseMvd) {
787 for (int step = static_cast<int>(ELmvmAnaStep::Mvd1Cut) + 1; step <= fH.fNofAnaSteps - 2; step++) {
788 if (h->IsA() == TH2D::Class()) {
789 for (int y = 1; y <= h->GetYaxis()->GetNbins(); y++) {
790 h->SetBinContent(step, y, h->GetBinContent(step + 2, y));
791 }
792 }
793 else if (h->IsA() == TH1D::Class()) {
794 h->SetBinContent(step, h->GetBinContent(step + 2));
795 }
796 }
797 }
798
799 int rangeMax = fH.fNofAnaSteps;
800 if (!fUseMvd) {
801 rangeMax = rangeMax - 2;
802 }
803 h->GetXaxis()->SetRange(static_cast<int>(ELmvmAnaStep::Reco) + 1, rangeMax);
804 h->GetXaxis()->SetLabelSize(0.06);
805 int x = 1;
806 for (const auto step : fH.fAnaSteps) {
807 if (SkipMvd(step)) continue;
808 h->GetXaxis()->SetBinLabel(x, fH.fAnaStepLatex[static_cast<int>(step)].c_str());
809 x++;
810 }
811}
812
814{
815 if (!fUseMvd) return;
816 TCanvas* c = fH.fHM.CreateCanvas("cuts/mvdCutQa", "cuts/mvd1cut_qa", 1600, 800);
817 c->Divide(2, 1);
818 int i = 1;
819 for (const string num : {"1", "2"}) {
820 c->cd(i++);
821 DrawSrcH1("hMvdCutQa_" + num);
822 TH1D* h1 = fH.H1("hMvdCutQa_" + num + "_" + fH.fSrcNames[0]);
823 h1->GetXaxis()->SetLabelSize(0.06);
824 h1->GetXaxis()->SetBinLabel(1, "Correct");
825 h1->GetXaxis()->SetBinLabel(2, "Wrong");
826 gPad->SetLogy(false);
827 DrawTextOnPad("MVD " + num, 0.50, 0.90, 0.70, 0.99);
828 }
829}
830
832{
833 if (!fUseMvd) return;
834 TCanvas* c1 = fH.fHM.CreateCanvas("nofHitsMvdSts", "nofHitsMvdSts", 1600, 800);
835 c1->Divide(2, 1);
836 c1->cd(1);
837 DrawSrcH1("hNofMvdHits");
838 c1->cd(2);
839 DrawSrcH1("hNofStsHits");
840
841 Draw2DCut("hMvdXY_1");
842 fH.fHM.CreateCanvas("mvd1", "mvd1", 900, 900);
843 DrawSrcH1("hMvdR_1");
844
845 Draw2DCut("hMvdXY_2");
846 fH.fHM.CreateCanvas("mvd2", "mvd2", 900, 900);
847 DrawSrcH1("hMvdR_2");
848}
849
851{
852 fH.fHM.SaveCanvasToImage(fOutputDir, "png"); // fHM->SaveCanvasToImage(fOutputDir, "png;eps");
853}
void DrawTextOnPad(const string &text, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
void SetDefaultDrawStyle()
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
void DrawH2(TH2 *hist, HistScale logx, HistScale logy, HistScale logz, const string &drawOpt)
Helper functions for drawing 1D and 2D histograms and graphs.
@ kLinear
Definition CbmDrawHist.h:69
@ kLog
Definition CbmDrawHist.h:68
Histogram manager.
friend fscal max(fscal x, fscal y)
friend fscal min(fscal x, fscal y)
ELmvmSrc
Definition LmvmDef.h:23
@ Signal
Definition LmvmDef.h:24
@ Gamma
Definition LmvmDef.h:27
ELmvmAnaStep
Definition LmvmDef.h:34
ClassImp(LmvmDraw)
Generates beam ions for transport simulation.
static Int_t MarkerStyle(Int_t markerIndex)
Definition CbmDrawHist.h:51
void DrawMinvBgPairSrc(ELmvmAnaStep step)
Definition LmvmDraw.cxx:590
void DrawPtY(const std::string &hist, ELmvmAnaStep step)
Definition LmvmDraw.cxx:166
void DrawMisc()
Definition LmvmDraw.cxx:221
void DrawHistFromFile(const std::string &fileName, const std::string &outputDir="", bool useMvd=true)
Implement functionality of drawing histograms in the macro from the specified file,...
Definition LmvmDraw.cxx:40
void DrawSource2D(const std::string &cName, const std::string &hName, const std::vector< std::string > &yLabels, double scale, const std::string &zTitle)
Definition LmvmDraw.cxx:679
void DrawMvdCutQa()
Definition LmvmDraw.cxx:813
void DrawCutEffH1(const std::string &hist, const std::string &option)
Definition LmvmDraw.cxx:121
void Draw2DCutTriangle(double xCr, double yCr)
Definition LmvmDraw.cxx:357
void DrawAnaStepH1(const std::string &hist, bool logy=false)
Definition LmvmDraw.cxx:533
void DrawBgSourcePairsAll()
Definition LmvmDraw.cxx:327
void Draw2DCut(const std::string &hist, double cutCrossX=-999999., double cutCrossY=-999999.)
Definition LmvmDraw.cxx:459
bool fUseMvd
Definition LmvmDraw.h:47
void DrawMinvMatching(ELmvmAnaStep step)
Definition LmvmDraw.cxx:608
void SetAnalysisStepAxis(TH1 *h)
Definition LmvmDraw.cxx:783
LmvmHist fH
Definition LmvmDraw.h:51
void DrawMinvSBg(ELmvmAnaStep step)
Definition LmvmDraw.cxx:562
bool SkipMvd(ELmvmAnaStep step)
Definition LmvmDraw.cxx:94
Int_t fNofEvents
Definition LmvmDraw.h:45
void Draw1DCut(const std::string &hist, const std::string &sigOption, double cut=-999999.)
Definition LmvmDraw.cxx:259
void DrawMinvPt(ELmvmAnaStep step)
Definition LmvmDraw.cxx:194
void DrawMvdAndStsHist()
Definition LmvmDraw.cxx:831
void DrawSrcH1(const std::string &hist, ELmvmAnaStep step=ELmvmAnaStep::Undefined, bool doScale=true)
Definition LmvmDraw.cxx:246
void DrawBgSourcePairs(ELmvmAnaStep step, bool inPercent, bool drawAnaStep=true)
Definition LmvmDraw.cxx:303
void DrawMismatchesAndGhosts()
Definition LmvmDraw.cxx:762
void DrawMinvBg()
Definition LmvmDraw.cxx:367
void DrawAccRecVsMom()
Definition LmvmDraw.cxx:624
void DrawGammaVertex()
Definition LmvmDraw.cxx:488
void SaveCanvasToImage()
Save all created canvases to images.
Definition LmvmDraw.cxx:850
void DrawPmtXY()
Definition LmvmDraw.cxx:233
void DrawElPurity()
Definition LmvmDraw.cxx:402
void DrawBgSourceTracks()
Definition LmvmDraw.cxx:721
void DrawRapidity(ELmvmAnaStep step)
Definition LmvmDraw.cxx:176
void DrawCuts()
Definition LmvmDraw.cxx:283
void DrawAnaStepMany(const std::string &cName, std::function< void(ELmvmAnaStep)> drawFunc)
Definition LmvmDraw.cxx:146
void RebinMinvHist()
Rebin minv histograms for better drawing. Should be called after calculation of S/BG ratios.
Definition LmvmDraw.cxx:99
void DrawBetaMomSpectra()
Definition LmvmDraw.cxx:109
LmvmCuts fCuts
Definition LmvmDraw.h:49
void DrawSrcAnaStepH1(const std::string &hName, ELmvmAnaStep step)
Definition LmvmDraw.cxx:201
std::string fOutputDir
Definition LmvmDraw.h:52
void DrawSrcAnaStepEpEmH1(const std::string &cName, ELmvmAnaStep step)
Definition LmvmDraw.cxx:207
void DrawPtYEfficiency(ELmvmAnaStep step)
Definition LmvmDraw.cxx:182
TH2D * DivideH2(TH2 *h1, TH2 *h2, const string &histName, double scale, const string &titleZaxis)
Definition CbmUtils.cxx:102
std::string NumberToString(const T &value, int precision=1)
Definition CbmUtils.h:34
Hash for CbmL1LinkKey.