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#include <cmath>
14
15// o2 includes
16#include "ITSStudies/Helpers.h"
17#include "TLegend.h"
18
19using namespace o2::its::study;
20
21//______________________________________________________________________________
22std::vector<double> helpers::makeLogBinning(const int nbins, const double min, const double max)
23{
24 assert(min > 0);
25 assert(min < max);
26
27 std::vector<double> binLim(nbins + 1);
28
29 const double expMax = std::log(max / min);
30 const double binWidth = expMax / nbins;
31
32 binLim[0] = min;
33 binLim[nbins] = max;
34
35 for (Int_t i = 1; i < nbins; ++i) {
36 binLim[i] = min * std::exp(i * binWidth);
37 }
38
39 return binLim;
40}
41
42//______________________________________________________________________________
43void helpers::setStyleHistogram1D(TH1F& histo, int color)
44{
45 // common and 1D case
46 histo.SetStats(0);
47 histo.SetMinimum(20);
48 histo.SetMaximum(300);
49 histo.SetLineColor(color);
50 histo.SetLineWidth(1);
51 histo.SetMarkerColor(color);
52 histo.SetMarkerSize(0.05);
53 histo.SetMarkerStyle(1);
54 histo.SetTitle("");
55}
56
57//______________________________________________________________________________
58void helpers::setStyleHistogram1D(TH1F& histo, int color, TString title, TString titleYaxis, TString titleXaxis)
59{
60 // common and 1D case
62 histo.GetXaxis()->SetTitle(titleXaxis.Data());
63 histo.GetYaxis()->SetTitle(titleYaxis.Data());
64 histo.GetXaxis()->SetTitleOffset(1.4);
65 histo.GetYaxis()->SetTitleOffset(1.2);
66}
67
68//______________________________________________________________________________
70{
71 // common and 1D case
73 histo.SetMinimum(-15.);
74 histo.SetMaximum(15.);
75 histo.GetXaxis()->SetTitleOffset(1.4);
76 histo.GetYaxis()->SetTitleOffset(1.2);
77}
78
79//______________________________________________________________________________
81{
82 // common and 1D case
83 histo.SetStats(0);
84 histo.GetYaxis()->SetRangeUser(-600, 600);
85 histo.GetXaxis()->SetTitleOffset(1.2);
86 histo.GetYaxis()->SetTitleOffset(1.2);
87}
88
89//______________________________________________________________________________
90TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TH1F& h2, int color2)
91{
92 TCanvas* c1 = new TCanvas();
93 c1->SetLogy();
94 c1->SetGridy();
95 c1->SetLogx();
96 c1->SetGridx();
97 setStyleHistogram1D(h1, color1);
99 h1.Draw();
100 h2.Draw("same");
101 return c1;
102}
103
104//______________________________________________________________________________
105TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2, bool logScale)
106{
107 TCanvas* c1 = new TCanvas();
108 if (logScale) {
109 c1->SetLogy(); // c1->SetGridy();
110 c1->SetLogx(); // c1->SetGridx();
111 }
112 TString direction = "";
113 TString histoName1 = h1.GetName();
114 TString histoName2 = h2.GetName();
115 if (histoName1.Contains("Xy")) {
116 direction = "XY";
117 }
118 if (histoName1.Contains("Z")) {
119 direction = "Z";
120 }
121 if ((histoName1.Contains("Xy")) && (histoName2.Contains("Z"))) {
122 direction = "";
123 }
124 helpers::setStyleHistogram1D(h1, color1, "", Form("Pointing Resolution %s (#mum)", direction.Data()), h1.GetXaxis()->GetName());
125 helpers::setStyleHistogram1D(h2, color2, "", Form("Pointing Resolution %s (#mum)", direction.Data()), h2.GetXaxis()->GetName());
126 TLegend* leg = new TLegend(0.6, 0.3, 0.8, 0.5);
127 leg->SetBorderSize(0);
128 leg->SetFillStyle(0);
129 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
130 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
131 h1.Draw();
132 h2.Draw("same");
133 leg->Draw("same");
134 return c1;
135}
136
137//______________________________________________________________________________
138TCanvas* helpers::prepareSimpleCanvas2Histograms(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2, TString intRate)
139{
140 TCanvas* c1 = new TCanvas();
141 c1->SetLogy(); // c1->SetGridy();
142 c1->SetLogx(); // c1->SetGridx();
145 TLegend* leg = new TLegend(0.2, 0.3, 0.5, 0.5);
146 leg->SetBorderSize(0);
147 leg->SetFillStyle(0);
148 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
149 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
150 h1.Draw();
151 h2.Draw("same");
152 leg->Draw("same");
153 TPaveText* paveText;
154 if (!intRate) {
155 helpers::paveTextITS(paveText, intRate);
156 }
157 return c1;
158}
159
160//______________________________________________________________________________
161TCanvas* helpers::prepareSimpleCanvas2DcaMeanValues(TH1F& h1, int color1, TString nameHisto1, TH1F& h2, int color2, TString nameHisto2)
162{
163 TCanvas* c1 = new TCanvas();
164 c1->SetLogx();
167 TLegend* leg = new TLegend(0.2, 0.15, 0.5, 0.35);
168 leg->SetBorderSize(0);
169 leg->SetFillStyle(0);
170 leg->AddEntry(&h1, nameHisto1.Data(), "lp");
171 leg->AddEntry(&h2, nameHisto2.Data(), "lp");
172 h1.Draw();
173 h2.Draw("same");
174 leg->Draw("same");
175 return c1;
176}
177
178//______________________________________________________________________________
179TCanvas* helpers::plot2DwithMeanAndSigma(TH2F& h2D, TH1F& hMean, TH1F& hSigma, int color)
180{
181 TCanvas* c1 = new TCanvas();
184 h2D.Draw("colz");
185 hMean.Draw("same");
186 TGraphAsymmErrors* gSigma;
187 ConvertTH1ToTGraphAsymmError(hMean, hSigma, gSigma);
188 gSigma->SetLineColor(kRed);
189 gSigma->SetFillStyle(0);
190 gSigma->Draw("E2same");
191 return c1;
192}
193
194//______________________________________________________________________________
195void helpers::paveTextITS(TPaveText* pave, TString intRate)
196{
197 pave->SetFillStyle(0);
198 pave->SetBorderSize(0);
199 pave->SetFillColor(0);
200 pave->SetTextFont(53);
201 pave->SetTextSize(12);
202 pave->AddText("ALICE");
203 pave->AddText("Run3 ITS Performaces");
204 pave->AddText(Form("Interaction Rate = %s", intRate.Data()));
205}
206
207//______________________________________________________________________________
208void helpers::ConvertTH1ToTGraphAsymmError(TH1F& hMean, TH1F& hSigma, TGraphAsymmErrors*& gr)
209{
210 const Int_t nbinsxx = hMean.GetNbinsX() + 1;
211 Double_t x[nbinsxx], y[nbinsxx], ex1[nbinsxx], ex2[nbinsxx], ey1[nbinsxx], ey2[nbinsxx];
212
213 for (int i = 0; i < nbinsxx; i++) {
214 x[i] = hMean.GetBinCenter(i);
215 y[i] = hMean.GetBinContent(i);
216 ex1[i] = hMean.GetBinCenter(i) - hMean.GetBinLowEdge(i);
217 ex2[i] = ex1[i];
218 ey1[i] = hSigma.GetBinContent(i);
219 ey2[i] = hSigma.GetBinContent(i);
220 }
221
222 gr = new TGraphAsymmErrors(nbinsxx, x, y, ex1, ex2, ey1, ey2);
223 return;
224}
int32_t i
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:22
void paveTextITS(TPaveText *pave, TString intRate)
prepare TPaveText with labels
Definition Helpers.cxx:195
TCanvas * prepareSimpleCanvas2Histograms(TH1F &h1, int color1, TH1F &h2, int color2)
prepare canvas with two TH1F plots
Definition Helpers.cxx:90
TCanvas * prepareSimpleCanvas2DcaMeanValues(TH1F &h1, int color1, TString nameHisto1, TH1F &h2, int color2, TString nameHisto2)
Definition Helpers.cxx:161
void setStyleHistogram1DMeanValues(TH1F &histo, int color)
Definition Helpers.cxx:69
TCanvas * plot2DwithMeanAndSigma(TH2F &h2D, TH1F &hMean, TH1F &hSigma, int color)
plot canvas with TH2D + TH1D(Mean and Sigma) from slice
Definition Helpers.cxx:179
void setStyleHistogram2D(TH2F &histo)
Definition Helpers.cxx:80
void ConvertTH1ToTGraphAsymmError(TH1F &hMean, TH1F &hSigma, TGraphAsymmErrors *&gr)
Convert TH1F in TGraphAsymmetricError.
Definition Helpers.cxx:208
void setStyleHistogram1D(TH1F &histo, int color)
Set nice style for single 1D histograms.
Definition Helpers.cxx:43
constexpr size_t min
constexpr size_t max