CbmRoot
Loading...
Searching...
No Matches
LmvmHist.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2021 UGiessen, JINR-LIT
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Elena Lebedeva, Semen Lebedev [committer], Cornelius Feier-Riesen */
4
5#include "LmvmHist.h"
6
7#include "CbmDrawHist.h"
8#include "CbmHistManager.h"
9#include "LmvmUtils.h"
10#include "Logger.h"
11#include "TLatex.h"
12#include "TLegend.h"
13#include "TStyle.h"
14#include "TText.h"
15#include "utils/CbmUtils.h"
16
17
18using std::string;
19using std::vector;
20
23const vector<std::string> LmvmHist::fSrcNames = {"signal", "bg", "pi0", "gamma", "eta"};
24const vector<std::string> LmvmHist::fSrcLatex = {"S", "BG_{oth}", "#pi^{0}", "#gamma", "#eta"};
25const vector<int> LmvmHist::fSrcColors = {kRed, kBlue, kGreen, kOrange, kMagenta};
26
31const vector<std::string> LmvmHist::fAnaStepNames = {"mc", "reco", "acc", "chi2prim", "elid", "gammacut",
32 "mvd1cut", "mvd2cut", "stcut", "rtcut", "ttcut", "ptcut"};
34 "MC", "REC", "ACC", "#chi^{2}_{prim}", "ID", "m_{#gamma}", "mvd1", "mvd2", "ST", "RT", "TT", "P_{t}"};
35
37 ELmvmAnaStep::ElId}; //, ELmvmAnaStep::GammaCut, ELmvmAnaStep::TtCut};
38
39const vector<int> LmvmHist::fAnaStepColors = {kBlack, kOrange + 3, kGreen + 3, kOrange + 7, kRed, kPink - 6,
40 kGreen, kOrange - 3, kViolet + 10, kGreen - 3, kMagenta, kYellow + 1};
41
42const vector<std::string> LmvmHist::fSignalNames = {"inmed", "qgp", "omegaepem", "phi",
43 "omegadalitz"}; // changed omega names on 25.4.24
46
47const vector<std::string> LmvmHist::fBgPairSrcNames = {"GG", "PP", "OO", "GP", "GO", "PO"};
48const vector<std::string> LmvmHist::fBgPairSrcLatex = {"#gamma-#gamma", "#pi^{0}-#pi^{0}", "o.-o.",
49 "#gamma-#pi^{0}", "#gamma-o.", "#pi^{0}-o."};
50
51// the following candidates and global track vectors are mainly set up to investigate misidentifications
52const vector<std::string> LmvmHist::fGTrackNames = { // TODO: rearange order: put primaries before secondaries
53 "el+_sec", "el+_prim", "el-_sec", "el-_prim", "pion+_sec", "pion+_prim", "pion-_sec", "pion-_prim",
54 "proton_sec", "proton_prim", "kaon+_sec", "kaon+_prim", "kaon-_sec", "kaon-_prim", "other"};
56 "e^{+}_{sec}", "e^{+}_{prim}", "e^{-}_{sec}", "e^{-}_{prim}", "#pi^{+}_{sec}",
57 "#pi^{+}_{prim}", "#pi^{-}_{sec}", "#pi^{-}_{prim}", "p_{sec}", "p_{prim}",
58 "K^{+}_{sec}", "K^{+}_{prim}", "K^{-}_{sec}", "K^{-}_{prim}", "other"};
59
60const vector<std::string> LmvmHist::fCandNames = {"plutoEl+", "plutoEl-", "urqmdEl+", "urqmdEl-", "pion+",
61 "pion-", "proton", "kaon+", "kaon-", "other"};
62const vector<std::string> LmvmHist::fCandLatex = {"e^{+}_{PLUTO}",
63 "e^{-}_{PLUTO}",
64 "e^{+}_{UrQMD}",
65 "e^{-}_{UrQMD}",
66 "#pi^{+}",
67 "#pi^{-}",
68 "p",
69 "K^{+}",
70 "K^{-}",
71 "o."};
72
73const vector<std::string> LmvmHist::fFSCandNames = {"pi0El", "gammaEl", "etaEl", "otherEl",
74 "pion", "proton", "kaon", "other"};
75const vector<std::string> LmvmHist::fFSCandLatex = {"e_{#pi^{0}}", "e_{#gamma}", "e_{#eta}", "e_{o.}",
76 "pion", "proton", "kaon", "other"};
77
79
80vector<string> LmvmHist::CombineNames(const string& name, const vector<string>& subNames)
81{
82 vector<string> result;
83 for (const auto& subName : subNames) {
84 result.push_back(name + "_" + subName);
85 }
86 return result;
87}
88
89vector<string> LmvmHist::CombineNames(const string& name, const vector<string>& subNames1,
90 const vector<string>& subNames2)
91{
92 vector<string> result;
93 for (const auto& subName1 : subNames1) {
94 for (const auto& subName2 : subNames2) {
95 result.push_back(name + "_" + subName1 + "_" + subName2);
96 }
97 }
98 return result;
99}
100
101void LmvmHist::CreateH1(const string& name, const string& axisX, const string& axisY, double nBins, double min,
102 double max)
103{
104 string title = name + ";" + axisX + ";" + axisY;
105 fHM.Create1<TH1D>(name, title, nBins, min, max);
106}
107
108void LmvmHist::CreateH1(const string& name, const string& axisX, const string& axisY, double nBins, double min,
109 double max, bool doSumw2)
110{
111 string title = name + ";" + axisX + ";" + axisY;
112 fHM.Create1<TH1D>(name, title, nBins, min, max);
113 if (doSumw2) fHM.H1(name)->Sumw2();
114}
115
116void LmvmHist::CreateH1(const string& name, const vector<string>& subNames, const string& axisX, const string& axisY,
117 double nBins, double min, double max)
118{
119 vector<string> names = CombineNames(name, subNames);
120 for (const auto& curName : names) {
121 string title = curName + ";" + axisX + ";" + axisY;
122 fHM.Create1<TH1D>(curName, title, nBins, min, max);
123 }
124}
125
126void LmvmHist::CreateH1(const string& name, const vector<string>& subNames, const string& axisX, const string& axisY,
127 double nBins, double min, double max, bool doSumw2)
128{
129 vector<string> names = CombineNames(name, subNames);
130 for (const auto& curName : names) {
131 string title = curName + ";" + axisX + ";" + axisY;
132 fHM.Create1<TH1D>(curName, title, nBins, min, max);
133 if (doSumw2) fHM.H1(curName)->Sumw2();
134 }
135}
136
137void LmvmHist::CreateH1(const string& name, const vector<string>& subNames1, const vector<string>& subNames2,
138 const string& axisX, const string& axisY, double nBins, double min, double max)
139{
140 vector<string> names = CombineNames(name, subNames1, subNames2);
141 for (const auto& curName : names) {
142 string title = curName + ";" + axisX + ";" + axisY;
143 fHM.Create1<TH1D>(curName, title, nBins, min, max);
144 }
145}
146
147void LmvmHist::CreateH1(const string& name, const vector<string>& subNames1, const vector<string>& subNames2,
148 const string& axisX, const string& axisY, double nBins, double min, double max, bool doSumw2)
149{
150 vector<string> names = CombineNames(name, subNames1, subNames2);
151 for (const auto& curName : names) {
152 string title = curName + ";" + axisX + ";" + axisY;
153 fHM.Create1<TH1D>(curName, title, nBins, min, max);
154 if (doSumw2) fHM.H1(curName)->Sumw2();
155 }
156}
157
158void LmvmHist::CreateH2(const string& name, const string& axisX, const string& axisY, const string& axisZ,
159 double nBinsX, double minX, double maxX, double nBinsY, double minY, double maxY)
160{
161 string title = name + ";" + axisX + ";" + axisY + ";" + axisZ;
162 fHM.Create2<TH2D>(name, title, nBinsX, minX, maxX, nBinsY, minY, maxY);
163}
164
165void LmvmHist::CreateH2(const string& name, const vector<string>& subNames, const string& axisX, const string& axisY,
166 const string& axisZ, double nBinsX, double minX, double maxX, double nBinsY, double minY,
167 double maxY)
168{
169 vector<string> names = CombineNames(name, subNames);
170 for (const auto& curName : names) {
171 string title = curName + ";" + axisX + ";" + axisY + ";" + axisZ;
172 fHM.Create2<TH2D>(curName, title, nBinsX, minX, maxX, nBinsY, minY, maxY);
173 }
174}
175
176void LmvmHist::CreateH2(const string& name, const vector<string>& subNames1, const vector<string>& subNames2,
177 const string& axisX, const string& axisY, const string& axisZ, double nBinsX, double minX,
178 double maxX, double nBinsY, double minY, double maxY)
179{
180 vector<string> names = CombineNames(name, subNames1, subNames2);
181 for (const auto& curName : names) {
182 string title = curName + ";" + axisX + ";" + axisY + ";" + axisZ;
183 fHM.Create2<TH2D>(curName, title, nBinsX, minX, maxX, nBinsY, minY, maxY);
184 }
185}
186
187void LmvmHist::FillH1(const string& name, double x, double w) { H1(name)->Fill(x, w); }
188
189void LmvmHist::FillH2(const string& name, double x, double y, double w) { H2(name)->Fill(x, y, w); }
190
191void LmvmHist::FillH1(const string& name, ELmvmSrc src, double x, double wSignal)
192{
193 if (src == ELmvmSrc::Undefined) return;
194 //double myWeight = (src == ELmvmSrc::Signal) ? wSignal : 1.; // TODO: delete commented lines
195 //H1(name, src)->Fill(x, myWeight);
196 H1(name, src)->Fill(x, wSignal);
197}
198
199void LmvmHist::FillH2(const string& name, ELmvmSrc src, double x, double y, double wSignal)
200{
201 if (src == ELmvmSrc::Undefined) return;
202 //double myWeight = (src == ELmvmSrc::Signal) ? wSignal : 1.; // TODO: delete commented lines
203 //H2(name, src)->Fill(x, y, myWeight);
204 H2(name, src)->Fill(x, y, wSignal);
205}
206
207void LmvmHist::FillH1(const string& name, ELmvmAnaStep step, double x, double w) { H1(name, step)->Fill(x, w); }
208
209void LmvmHist::FillH2(const string& name, ELmvmAnaStep step, double x, double y, double w)
210{
211 H2(name, step)->Fill(x, y, w);
212}
213
214void LmvmHist::FillH1(const string& name, ELmvmSrc src, ELmvmAnaStep step, double x, double wSignal)
215{
216 if (src == ELmvmSrc::Undefined || step == ELmvmAnaStep::Undefined) return;
217 //double myWeight = (src == ELmvmSrc::Signal) ? wSignal : 1.; // TODO: delete commented lines
218 //FillH1(GetName(name, src, step), x, myWeight);
219 FillH1(GetName(name, src, step), x, wSignal);
220}
221
222void LmvmHist::FillH2(const string& name, ELmvmSrc src, ELmvmAnaStep step, double x, double y, double wSignal)
223{
224 if (src == ELmvmSrc::Undefined || step == ELmvmAnaStep::Undefined) return;
225 //double myWeight = (src == ELmvmSrc::Signal) ? wSignal : 1.; // TODO: delete commented lines
226 //FillH2(GetName(name, src, step), x, y, myWeight);
227 FillH2(GetName(name, src, step), x, y, wSignal);
228}
229
230
231string LmvmHist::GetName(const string& name, ELmvmAnaStep step)
232{
233 if (step == ELmvmAnaStep::Undefined) {
234 LOG(error) << "LmvmHist::GetName step == ELmvmAnaStep::Undefined";
235 return name;
236 }
237 return name + "_" + fAnaStepNames[static_cast<int>(step)];
238}
239
240string LmvmHist::GetName(const string& name, ELmvmSrc src)
241{
242 if (src == ELmvmSrc::Undefined) {
243 LOG(error) << "LmvmHist::GetName src == ELmvmSrc::Undefined";
244 return name;
245 }
246 return name + "_" + fSrcNames[static_cast<int>(src)];
247}
248
249string LmvmHist::GetName(const string& name, ELmvmSrc src, ELmvmAnaStep step)
250{
251 return GetName(GetName(name, src), step);
252}
253
254void LmvmHist::SetOptH1(TH1D* hist, TString xAxisTitle = " ", TString yAxisTitle = " ", Int_t Ndevision = 510,
255 Int_t style = 1, Float_t size = 2, Int_t color = 1, string opt)
256{
257 hist->GetXaxis()->SetTitle(xAxisTitle);
258 hist->GetYaxis()->SetTitle(yAxisTitle);
259 hist->GetXaxis()->SetTitleSize(0.05);
260 hist->GetYaxis()->SetTitleSize(0.05);
261 hist->GetXaxis()->SetTitleFont(42);
262 hist->GetYaxis()->SetTitleFont(42);
263 hist->GetXaxis()->SetNdivisions(Ndevision);
264 hist->GetYaxis()->SetTitleOffset(1.4);
265 hist->GetXaxis()->SetTitleOffset(1.);
266 //hist->GetXaxis()->CenterTitle();
267 //hist->GetYaxis()->CenterTitle();
268 hist->GetXaxis()->SetLabelFont(42);
269 hist->GetYaxis()->SetLabelFont(42);
270 hist->GetXaxis()->SetLabelSize(0.04);
271 hist->GetYaxis()->SetLabelSize(0.04);
272 if (opt == "marker") {
273 hist->SetMarkerStyle(style);
274 hist->SetMarkerSize(size);
275 hist->SetMarkerColor(color);
276 hist->SetLineColor(color);
277 hist->SetLineWidth(2);
278 hist->SetTitle("");
279 //hist->SetLineWidth(2);
280 //hist->SetMinimum(0.1);
281 //hist->SetMaximum(1e5);
282 hist->GetXaxis()->SetLabelColor(1);
283 hist->GetYaxis()->SetLabelColor(1);
284 hist->GetXaxis()->SetTitleColor(1);
285 hist->GetYaxis()->SetTitleColor(1);
286 hist->SetFillColor(1);
287 }
288 else if (opt == "line") {
289 hist->SetLineStyle(style);
290 hist->SetLineColor(color);
291 hist->SetTitle(""); // TODO: with ""?
292 hist->SetLineWidth(size);
293 }
294 else
295 LOG(error) << "Option '" << opt << "' undefined. Choose 'marker' or 'line'." << std::endl;
296}
297
298void LmvmHist::SetOptCanvas(TCanvas* canvas)
299{
300 gStyle->SetOptStat(0);
301 gStyle->SetEndErrorSize(5);
302 //gStyle->SetErrorX(0); // X errors of the data points set to be 0
303 gStyle->SetLineStyleString(22, "80 18 12 18 12 12"); // special style for the line
304 gStyle->SetEndErrorSize(5); // define end width of error bars
305 gStyle->SetCanvasColor(10);
306 gStyle->SetPadColor(10);
307 canvas->SetLeftMargin(0.15);
308 canvas->SetRightMargin(0.04);
309 canvas->SetTopMargin(0.05);
310 canvas->SetBottomMargin(0.12);
311 canvas->ToggleEventStatus();
312 canvas->Range(-200, -10, 1000, -2);
313 canvas->SetFillColor(0);
314 canvas->SetBorderMode(0);
315 canvas->SetBorderSize(0);
316 canvas->SetTickx();
317 canvas->SetTicky();
318 canvas->SetLogy();
319 canvas->SetFrameLineWidth(2);
320 canvas->SetFrameBorderMode(0);
321 canvas->SetFrameBorderSize(0);
322}
323
324void LmvmHist::SetLegend(vector<LmvmLegend> legendV, double textsize, Double_t x1, Double_t y1, Double_t x2,
325 Double_t y2)
326{
327 auto leg = new TLegend(x1, y1, x2, y2);
328 leg->SetLineColor(10);
329 leg->SetLineStyle(1);
330 leg->SetLineWidth(1);
331 leg->SetFillColor(10);
332 leg->SetTextSize(textsize);
333 leg->SetTextFont(42);
334 leg->SetMargin(0.4);
335 leg->SetBorderSize(0);
336 for (size_t i = 0; i < legendV.size(); i++) {
337 const auto& l = legendV[i];
338 leg->AddEntry(l.fH, l.fName, l.fOpt);
339 }
340 leg->Draw("same");
341}
342
343void LmvmHist::DrawSimDataLabel(double xPos, double yPos) { DrawSimDataLabel(xPos, yPos, 0.035); }
344
345void LmvmHist::DrawSimDataLabel(double xPos, double yPos, double textSize)
346{
347 TLatex* tex = new TLatex(xPos, yPos, "#splitline{CBM Simulations}{Au+Au #sqrt{#it{s}_{NN}}=4.1 GeV, #it{b}=0 fm}");
348 tex->SetTextColor(1);
349 tex->SetTextFont(42);
350 tex->SetTextSize(textSize);
351 tex->Draw();
352}
353
355{
356 int rangeMax = fNofAnaSteps;
357 h->GetXaxis()->SetRange(static_cast<int>(ELmvmAnaStep::Reco) + 1, rangeMax);
358 h->GetXaxis()->SetLabelSize(0.05);
359 int x = 1;
360 for (const auto step : fAnaSteps) {
361 h->GetXaxis()->SetBinLabel(x, fAnaStepLatex[static_cast<int>(step)].c_str());
362 x++;
363 }
364}
365
366void LmvmHist::Rebin(const string& name, int nGroup) { fHM.Rebin(name, nGroup); }
367
368void LmvmHist::Rebin(const string& name, const vector<string>& subNames, int nGroup)
369{
370 vector<string> names = CombineNames(name, subNames);
371 for (const auto& curName : names) {
372 fHM.Rebin(curName, nGroup);
373 }
374}
375
376void LmvmHist::Rebin(const string& name, const vector<string>& subNames1, const vector<string>& subNames2, int nGroup)
377{
378 vector<string> names = CombineNames(name, subNames1, subNames2);
379 for (const auto& curName : names) {
380 fHM.Rebin(curName, nGroup);
381 }
382}
383
384TH1D* LmvmHist::CreateSignificanceH1(TH1D* s, TH1D* bg, const string& name, const string& option)
385{
386 int nBins = s->GetNbinsX();
387 TH1D* hsig = new TH1D(name.c_str(), name.c_str(), nBins, s->GetXaxis()->GetXmin(), s->GetXaxis()->GetXmax());
388 hsig->GetXaxis()->SetTitle(s->GetXaxis()->GetTitle());
389
390 // "right" - reject right part of the histogram. value > cut -> reject
391 if (option == "right") {
392 for (int i = 1; i <= nBins; i++) {
393 double sumSignal = s->Integral(1, i, "width");
394 double sumBg = bg->Integral(1, i, "width");
395 double sign = (sumSignal + sumBg != 0.) ? sumSignal / std::sqrt(sumSignal + sumBg) : 0.;
396 hsig->SetBinContent(i, sign);
397 hsig->GetYaxis()->SetTitle("Significance");
398 }
399 }
400 // "left" - reject left part of the histogram. value < cut -> reject
401 else if (option == "left") {
402 for (int i = nBins; i >= 1; i--) {
403 double sumSignal = s->Integral(i, nBins, "width");
404 double sumBg = bg->Integral(i, nBins, "width");
405 double sign = (sumSignal + sumBg != 0.) ? sumSignal / std::sqrt(sumSignal + sumBg) : 0.;
406 hsig->SetBinContent(i, sign);
407 hsig->GetYaxis()->SetTitle("Significance");
408 }
409 }
410 return hsig;
411}
412
413TH2D* LmvmHist::CreateSignificanceH2(TH2D* signal, TH2D* bg, const string& name, const string& title)
414{
415 double xmin = 1.0;
416 double xmax = 5.0;
417 double ymin = 1.0;
418 double ymax = 5.0;
419 double delta = 0.1;
420 int nStepsX = (int) ((xmax - xmin) / delta);
421 int nStepsY = (int) ((ymax - ymin) / delta);
422
423 TH2D* hsig = new TH2D(name.c_str(), title.c_str(), nStepsX, xmin, xmax, nStepsY, ymin, ymax);
424
425 int binX = 1;
426 for (double xcut = xmin; xcut <= xmax; xcut += delta, binX++) {
427 int binY = 1;
428 for (double ycut = ymin; ycut <= ymax; ycut += delta, binY++) {
429 double sumSignal = 0;
430 double sumBg = 0;
431 for (int ix = 1; ix <= signal->GetNbinsX(); ix++) {
432 for (int iy = 1; iy <= signal->GetNbinsY(); iy++) {
433 double xc = signal->GetXaxis()->GetBinCenter(ix);
434 double yc = signal->GetYaxis()->GetBinCenter(iy);
435 double val = -1 * (ycut / xcut) * xc + ycut;
436
437 if (!(xc < xcut && yc < val)) {
438 sumSignal += signal->GetBinContent(ix, iy);
439 sumBg += bg->GetBinContent(ix, iy);
440 }
441 }
442 }
443 double sign = (sumSignal + sumBg != 0.) ? sumSignal / std::sqrt(sumSignal + sumBg) : 0.;
444 hsig->SetBinContent(binX, binY, sign);
445 }
446 }
447 return hsig;
448}
449
450void LmvmHist::DrawAllGTracks(int dim, const string& cName, const string& hName, vector<string> xLabel,
451 vector<string> yLabel, bool logX, bool logY, double min, double max)
452{
453 TCanvas* c = fHM.CreateCanvas(cName, cName, 2400, 2400);
454 c->Divide(4, 4);
455 int i = 1;
456 for (const string& ptcl : fGTrackNames) {
457 c->cd(i++);
458 string hFullname = hName + "_" + ptcl;
459 DrawAll(dim, hFullname, fGTrackLatex[i - 2], xLabel, yLabel, logX, logY, min, max);
460 }
461}
462
463void LmvmHist::DrawAllCands(int dim, const string& cName, const string& hName, vector<string> xLabel,
464 vector<string> yLabel, bool logX, bool logY, double min, double max)
465{
466 TCanvas* c = fHM.CreateCanvas(cName, cName, 2400, 1800);
467 c->Divide(4, 3);
468 int i = 1;
469 for (const string& ptcl : fCandNames) {
470 c->cd(i++);
471 string hFullname = hName + "_" + ptcl;
472 DrawAll(dim, hFullname, fCandLatex[i - 2], xLabel, yLabel, logX, logY, min, max);
473 }
474}
475
476void LmvmHist::DrawAllCandsAndSteps(int dim, const string& cName, const string& hName, vector<string> xLabel,
477 vector<string> yLabel, bool logX, bool logY, double min, double max)
478{
479 for (auto step : fAnaSteps) {
480 TCanvas* c = fHM.CreateCanvas(cName + "Steps/" + fAnaStepNames[static_cast<int>(step)],
481 cName + "Steps/" + fAnaStepNames[static_cast<int>(step)], 2400, 1800);
482 c->Divide(4, 3);
483 int i = 1;
484 for (const string& ptcl : fCandNames) {
485 c->cd(i++);
486 string hFullname = GetName(hName + "_" + ptcl, step);
487 DrawAll(dim, hFullname.c_str(), fCandLatex[i - 2], xLabel, yLabel, logX, logY, min, max);
488 }
489 }
490
491 for (const string& ptcl : fCandNames) {
492 TCanvas* c = fHM.CreateCanvas(cName + "Candidates/" + ptcl, cName + "Candidates/" + ptcl, 2400, 1800);
493 c->Divide(4, 3);
494 int i = 1;
495 for (auto step : fAnaSteps) {
496 c->cd(i++);
497 string hFullname = GetName(hName + "_" + ptcl, step);
498 DrawAll(dim, hFullname.c_str(), fAnaStepNames[static_cast<int>(step)], xLabel, yLabel, logX, logY, min, max);
499 }
500 }
501
502 if (dim == 2) DrawRatioElectronsOthers(cName, hName);
503}
504
505void LmvmHist::DrawAll(int dim, const string& hFullname, const string& text, vector<string> xLabel,
506 vector<string> yLabel, bool logX, bool logY, double min, double max)
507{
508 if (dim == 1) {
509 TH1D* h = H1Clone(hFullname.c_str());
510 h->GetYaxis()->SetRangeUser(min, max);
511 if (logX == false)
512 DrawH1(h, kLinear, kLog, "hist");
513 else
514 DrawH1(h, kLog, kLog, "hist");
515 if (xLabel.size() > 1) {
516 for (size_t iL = 0; iL < xLabel.size(); iL++) {
517 h->GetXaxis()->SetBinLabel(iL + 1, xLabel[iL].c_str());
518 }
519 }
520 }
521 else if (dim == 2) {
522 TH2D* h = H2Clone(hFullname.c_str());
523 h->GetZaxis()->SetRangeUser(min, max);
524
525 if (logX == false && logY == false)
526 DrawH2(h, kLinear, kLinear, kLog, "colz");
527 else if (logX == false && logY == true)
528 DrawH2(h, kLinear, kLog, kLog, "colz");
529 else if (logX == true && logY == false)
530 DrawH2(h, kLog, kLinear, kLog, "colz");
531 else if (logX == true && logY == true)
532 DrawH2(h, kLog, kLog, kLog, "colz");
533
534 if (xLabel.size() > 1) {
535 for (size_t iL = 0; iL < xLabel.size(); iL++) {
536 h->GetXaxis()->SetBinLabel(iL + 1, xLabel[iL].c_str());
537 }
538 }
539 if (yLabel.size() > 1) {
540 for (size_t iL = 0; iL < yLabel.size(); iL++) {
541 h->GetYaxis()->SetBinLabel(iL + 1, yLabel[iL].c_str());
542 }
543 }
544 }
545 else
546 LOG(error) << "LmvmHist::DrawAll: Choose dimension 1 or 2!";
547
548 DrawTextOnPad(text, 0.25, 0.9, 0.75, 0.999);
549}
550
551TH2D* LmvmHist::GetRatioElectronsOthers(const string& hName, ELmvmAnaStep step)
552{
553 TH2D* el = H2Clone(hName + "_" + fCandNames[0], step);
554 el->Add(H2(hName + "_" + fCandNames[1], step));
555 el->Add(H2(hName + "_" + fCandNames[2], step));
556 el->Add(H2(hName + "_" + fCandNames[3], step));
557 TH2D* ratio = H2Clone(hName + "_" + fCandNames[4], step);
558 for (size_t iC = 5; iC < fCandNames.size(); iC++) {
559 ratio->Add(H2(hName + "_" + fCandNames[iC], step));
560 }
561 ratio->Divide(el);
562 ratio->GetZaxis()->SetTitle("Others/Electrons");
563 return ratio;
564}
565
566
567void LmvmHist::DrawRatioElectronsOthers(const string& cName, const string& hName)
568{
569 TCanvas* c = fHM.CreateCanvas(cName + "Ratio", cName + "Ratio", 2400, 1800);
570 c->Divide(4, 3);
571 int i = 1;
572 for (auto step : fAnaSteps) {
573 TH2D* ratio = GetRatioElectronsOthers(hName, step);
574 ratio->GetYaxis()->SetTitle("Value");
575 ratio->GetZaxis()->SetTitle("Ratio Electrons/Others");
576 ratio->GetZaxis()->SetRangeUser(1e-7, 100.);
577 c->cd(i++);
578 DrawH2(ratio, kLinear, kLinear, kLog, "colz");
579 DrawAnaStepOnPad(step);
580 }
581}
582
583void LmvmHist::WriteToFile() { fHM.WriteToFile(); }
584
585void LmvmHist::DrawEfficiency(TH1* h1, TH1* h2, double xPos, double yPos)
586{
587 string effTxt =
588 (h2->GetEntries() != 0.) ? Cbm::NumberToString<double>((h1->GetEntries() / h2->GetEntries() * 100.), 1) : "";
589 TText* t = new TText(xPos, yPos, effTxt.c_str());
590 t->SetTextSize(0.1);
591 t->Draw();
592}
593
595{
596 DrawTextOnPad(LmvmHist::fAnaStepLatex[static_cast<int>(step)], 0.4, 0.9, 0.6, 0.999);
597}
598
void DrawTextOnPad(const string &text, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
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)
static constexpr size_t size()
Definition KfSimdPseudo.h:2
ELmvmSrc
Definition LmvmDef.h:23
@ Signal
Definition LmvmDef.h:24
@ Gamma
Definition LmvmDef.h:27
@ Undefined
Definition LmvmDef.h:29
ELmvmAnaStep
Definition LmvmDef.h:34
ClassImp(LmvmHist)
float Float_t
int Int_t
void Rebin(const std::string &histName, Int_t ngroup)
Rebin histogram.
Data class with information on a STS local track.
void CreateH1(const std::string &name, const std::string &axisX, const std::string &axisY, double nBins, double min, double max)
static const std::vector< int > fAnaStepColors
Definition LmvmHist.h:39
static const std::vector< ELmvmSrc > fSrcs
Definition LmvmHist.h:21
static const std::vector< std::string > fCandNames
Definition LmvmHist.h:60
static const std::vector< std::string > fAnaStepLatex
Definition LmvmHist.h:33
void DrawEfficiency(TH1 *h1, TH1 *h2, double xPos, double yPos)
Definition LmvmHist.cxx:585
void DrawSimDataLabel(double xPos, double yPos)
Definition LmvmHist.cxx:343
TH1D * CreateSignificanceH1(TH1D *s, TH1D *bg, const std::string &name, const std::string &option)
Definition LmvmHist.cxx:384
void FillH1(const std::string &name, double x, double w=1.)
TH2D * GetRatioElectronsOthers(const std::string &hName, ELmvmAnaStep step)
Definition LmvmHist.cxx:551
CbmHistManager fHM
Definition LmvmHist.h:195
TH2D * H2Clone(const std::string &name)
Definition LmvmHist.h:142
TH2D * H2(const std::string &name)
Definition LmvmHist.h:133
void SetOptH1(TH1D *hist, TString xAxisTitle, TString yAxisTitle, Int_t Ndevision, Int_t style, Float_t size, Int_t color, std::string opt="")
Definition LmvmHist.cxx:254
static const std::vector< int > fSrcColors
Definition LmvmHist.h:25
static const std::vector< std::string > fBgPairSrcNames
Definition LmvmHist.h:47
static const std::vector< ELmvmSignal > fSignals
Definition LmvmHist.h:44
std::vector< std::string > CombineNames(const std::string &name, const std::vector< std::string > &subNames)
static const std::vector< std::string > fFSCandLatex
Definition LmvmHist.h:75
void SetOptCanvas(TCanvas *canvas)
Definition LmvmHist.cxx:298
void CreateH2(const std::string &name, const std::string &axisX, const std::string &axisY, const std::string &axisZ, double nBinsX, double minX, double maxX, double nBinsY, double minY, double maxY)
static const std::vector< std::string > fSrcNames
Definition LmvmHist.h:23
static const std::vector< std::string > fCandLatex
Definition LmvmHist.h:62
static const std::vector< ELmvmAnaStep > fAnaStepsFS
Definition LmvmHist.h:36
std::string GetName(const std::string &name, ELmvmAnaStep step)
void FillH2(const std::string &name, double x, double y, double w=1.)
void DrawAll(int dim, const std::string &hFullname, const std::string &padText, std::vector< std::string > xLabel, std::vector< std::string > yLabel, bool logX, bool logY, double min, double max)
Definition LmvmHist.cxx:505
static const std::vector< std::string > fGTrackNames
Definition LmvmHist.h:52
void DrawAllCandsAndSteps(int dim, const std::string &cName, const std::string &hName, std::vector< std::string > xLabel, std::vector< std::string > yLabel, bool logX, bool logY, double min, double max)
Definition LmvmHist.cxx:476
static const std::vector< std::string > fSrcLatex
Definition LmvmHist.h:24
void Rebin(const std::string &name, int nGroup)
TH2D * CreateSignificanceH2(TH2D *signal, TH2D *bg, const std::string &name, const std::string &title)
Definition LmvmHist.cxx:413
static const std::vector< std::string > fGTrackLatex
Definition LmvmHist.h:55
static const std::vector< ELmvmAnaStep > fAnaSteps
Definition LmvmHist.h:27
void DrawAllGTracks(int dim, const std::string &cName, const std::string &hName, std::vector< std::string > xLabel, std::vector< std::string > yLabel, bool logX, bool logY, double min, double max)
Definition LmvmHist.cxx:450
static const std::vector< std::string > fSignalNames
Definition LmvmHist.h:42
void DrawAllCands(int dim, const std::string &cName, const std::string &hName, std::vector< std::string > xLabel, std::vector< std::string > yLabel, bool logX, bool logY, double min, double max)
Definition LmvmHist.cxx:463
static const std::vector< std::string > fFSCandNames
Definition LmvmHist.h:73
static const int fNofAnaSteps
Definition LmvmHist.h:31
void SetAnalysisStepAxis(TH1 *hist)
Definition LmvmHist.cxx:354
TH1D * H1Clone(const std::string &name)
Definition LmvmHist.h:141
TH1D * H1(const std::string &name)
Definition LmvmHist.h:132
void DrawRatioElectronsOthers(const std::string &cName, const std::string &hName)
Definition LmvmHist.cxx:567
static const std::vector< std::string > fBgPairSrcLatex
Definition LmvmHist.h:48
static const std::vector< std::string > fAnaStepNames
Definition LmvmHist.h:31
void SetLegend(std::vector< LmvmLegend >, double textsize, double x1, double y1, double x2, double y2)
Definition LmvmHist.cxx:324
void WriteToFile()
Definition LmvmHist.cxx:583
static void DrawAnaStepOnPad(ELmvmAnaStep step)
Definition LmvmHist.cxx:594
std::string NumberToString(const T &value, int precision=1)
Definition CbmUtils.h:34