Project
Loading...
Searching...
No Matches
Helpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#include <cassert>
13
14// o2 includes
15#include "ITSStudies/Helpers.h"
16#include "TLegend.h"
17
18using namespace o2::its::study;
19
20//______________________________________________________________________________
21std::vector<double> helpers::makeLogBinning(const int nbins, const double min, const double max)
22{
23 assert(min > 0);
24 assert(min < max);
25
26 std::vector<double> binLim(nbins + 1);
27
28 const double expMax = std::log(max / min);
29 const double binWidth = expMax / nbins;
30
31 binLim[0] = min;
32 binLim[nbins] = max;
33
34 for (Int_t i = 1; i < nbins; ++i) {
35 binLim[i] = min * std::exp(i * binWidth);
36 }
37
38 return binLim;
39}
40
41//______________________________________________________________________________
42void helpers::setStyleHistogram1D(TH1F& histo, int color)
43{
44 // common and 1D case
45 histo.SetStats(0);
46 histo.SetMinimum(20);
47 histo.SetMaximum(300);
48 histo.SetLineColor(color);
49 histo.SetLineWidth(1);
50 histo.SetMarkerColor(color);
51 histo.SetMarkerSize(0.05);
52 histo.SetMarkerStyle(1);
53 histo.SetTitle("");
54}
55
56//______________________________________________________________________________
57void helpers::setStyleHistogram1D(TH1F& histo, int color, TString title, TString titleYaxis, TString titleXaxis)
58{
59 // common and 1D case
61 histo.GetXaxis()->SetTitle(titleXaxis.Data());
62 histo.GetYaxis()->SetTitle(titleYaxis.Data());
63 histo.GetXaxis()->SetTitleOffset(1.4);
64 histo.GetYaxis()->SetTitleOffset(1.2);
65}
66
67//______________________________________________________________________________
69{
70 // common and 1D case
72 histo.SetMinimum(-15.);
73 histo.SetMaximum(15.);
74 histo.GetXaxis()->SetTitleOffset(1.4);
75 histo.GetYaxis()->SetTitleOffset(1.2);
76}
77
78//______________________________________________________________________________
80{
81 // common and 1D case
82 histo.SetStats(0);
83 histo.GetYaxis()->SetRangeUser(-600, 600);
84 histo.GetXaxis()->SetTitleOffset(1.2);
85 histo.GetYaxis()->SetTitleOffset(1.2);
86}
87
88//______________________________________________________________________________
89TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TH1F& h2, int color2)
90{
91 TCanvas* c1 = new TCanvas();
92 c1->SetLogy();
93 c1->SetGridy();
94 c1->SetLogx();
95 c1->SetGridx();
96 setStyleHistogram1D(h1, color1);
98 h1.Draw();
99 h2.Draw("same");
100 return c1;
101}
102
103//______________________________________________________________________________
104TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2, bool logScale)
105{
106 TCanvas* c1 = new TCanvas();
107 if (logScale) {
108 c1->SetLogy(); // c1->SetGridy();
109 c1->SetLogx(); // c1->SetGridx();
110 }
111 TString direction = "";
112 TString histoName1 = h1.GetName();
113 TString histoName2 = h2.GetName();
114 if (histoName1.Contains("Xy")) {
115 direction = "XY";
116 }
117 if (histoName1.Contains("Z")) {
118 direction = "Z";
119 }
120 if ((histoName1.Contains("Xy")) && (histoName2.Contains("Z"))) {
121 direction = "";
122 }
123 helpers::setStyleHistogram1D(h1, color1, "", Form("Pointing Resolution %s (#mum)", direction.Data()), h1.GetXaxis()->GetName());
124 helpers::setStyleHistogram1D(h2, color2, "", Form("Pointing Resolution %s (#mum)", direction.Data()), h2.GetXaxis()->GetName());
125 TLegend* leg = new TLegend(0.6, 0.3, 0.8, 0.5);
126 leg->SetBorderSize(0);
127 leg->SetFillStyle(0);
128 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
129 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
130 h1.Draw();
131 h2.Draw("same");
132 leg->Draw("same");
133 return c1;
134}
135
136//______________________________________________________________________________
137TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2, TString intRate)
138{
139 TCanvas* c1 = new TCanvas();
140 c1->SetLogy(); // c1->SetGridy();
141 c1->SetLogx(); // c1->SetGridx();
144 TLegend* leg = new TLegend(0.2, 0.3, 0.5, 0.5);
145 leg->SetBorderSize(0);
146 leg->SetFillStyle(0);
147 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
148 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
149 h1.Draw();
150 h2.Draw("same");
151 leg->Draw("same");
152 TPaveText* paveText;
153 if (!intRate) {
154 helpers::paveTextITS(paveText, intRate);
155 }
156 return c1;
157}
158
159//______________________________________________________________________________
160TCanvas* helpers::prepareSimpleCanvas2DcaMeanValues(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2)
161{
162 TCanvas* c1 = new TCanvas();
163 c1->SetLogx();
166 TLegend* leg = new TLegend(0.2, 0.15, 0.5, 0.35);
167 leg->SetBorderSize(0);
168 leg->SetFillStyle(0);
169 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
170 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
171 h1.Draw();
172 h2.Draw("same");
173 leg->Draw("same");
174 return c1;
175}
176
177//______________________________________________________________________________
178TCanvas* helpers::plot2DwithMeanAndSigma(TH2F& h2D, TH1F& hMean, TH1F& hSigma, int color)
179{
180 TCanvas* c1 = new TCanvas();
183 h2D.Draw("colz");
184 hMean.Draw("same");
185 TGraphAsymmErrors* gSigma;
186 ConvertTH1ToTGraphAsymmError(hMean, hSigma, gSigma);
187 gSigma->SetLineColor(kRed);
188 gSigma->SetFillStyle(0);
189 gSigma->Draw("E2same");
190 return c1;
191}
192
193//______________________________________________________________________________
194void helpers::paveTextITS(TPaveText* pave, TString intRate)
195{
196 pave->SetFillStyle(0);
197 pave->SetBorderSize(0);
198 pave->SetFillColor(0);
199 pave->SetTextFont(53);
200 pave->SetTextSize(12);
201 pave->AddText("ALICE");
202 pave->AddText("Run3 ITS Performaces");
203 pave->AddText(Form("Interaction Rate = %s", intRate.Data()));
204}
205
206//______________________________________________________________________________
207void helpers::ConvertTH1ToTGraphAsymmError(TH1F& hMean, TH1F& hSigma, TGraphAsymmErrors*& gr)
208{
209 const Int_t nbinsxx = hMean.GetNbinsX() + 1;
210 Double_t x[nbinsxx], y[nbinsxx], ex1[nbinsxx], ex2[nbinsxx], ey1[nbinsxx], ey2[nbinsxx];
211
212 for (int i = 0; i < nbinsxx; i++) {
213 x[i] = hMean.GetBinCenter(i);
214 y[i] = hMean.GetBinContent(i);
215 ex1[i] = hMean.GetBinCenter(i) - hMean.GetBinLowEdge(i);
216 ex2[i] = ex1[i];
217 ey1[i] = hSigma.GetBinContent(i);
218 ey2[i] = hSigma.GetBinContent(i);
219 }
220
221 gr = new TGraphAsymmErrors(nbinsxx, x, y, ex1, ex2, ey1, ey2);
222 return;
223}
int32_t i
uint8_t leg
bool const GPUTPCGMMerger::trackCluster * c1
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint color
Definition glcorearb.h:1272
Definition A.h:18
std::vector< double > makeLogBinning(const int nbins, const double min, const double max)
get a vector containing binning info for constant sized bins on a log axis
Definition Helpers.cxx:21
void paveTextITS(TPaveText *pave, TString intRate)
prepare TPaveText with labels
Definition Helpers.cxx:194
TCanvas * prepareSimpleCanvas2Histograms(TH1F &h1, int color1, TH1F &h2, int color2)
prepare canvas with two TH1F plots
Definition Helpers.cxx:89
TCanvas * prepareSimpleCanvas2DcaMeanValues(TH1F &h1, int color1, TString nameHisto1, TH1F &h2, int color2, TString nameHisto2)
Definition Helpers.cxx:160
void setStyleHistogram1DMeanValues(TH1F &histo, int color)
Definition Helpers.cxx:68
TCanvas * plot2DwithMeanAndSigma(TH2F &h2D, TH1F &hMean, TH1F &hSigma, int color)
plot canvas with TH2D + TH1D(Mean and Sigma) from slice
Definition Helpers.cxx:178
void setStyleHistogram2D(TH2F &histo)
Definition Helpers.cxx:79
void ConvertTH1ToTGraphAsymmError(TH1F &hMean, TH1F &hSigma, TGraphAsymmErrors *&gr)
Convert TH1F in TGraphAsymmetricError.
Definition Helpers.cxx:207
void setStyleHistogram1D(TH1F &histo, int color)
Set nice style for single 1D histograms.
Definition Helpers.cxx:42
constexpr size_t min
constexpr size_t max