ATLAS Offline Software
Loading...
Searching...
No Matches
PixelChargeInterpolationPlot.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef PixelChargeInterpolationPlot_cxx
6#define PixelChargeInterpolationPlot_cxx
7
8#include <vector>
9#include <string>
10#include <sstream>
11#include <atomic>
12
13#include <TH1.h>
14#include <TCanvas.h>
15#include <TLatex.h>
16#include <TMarker.h>
17#include <TGaxis.h>
18
22
23namespace PixelCalib{
24
25// number of layers in barrel & disks
27
29 const PixelChargeInterpolationParameters &parameters, bool oneconst):
33 m_referenceDrawOpt(0), m_oneconst(oneconst){
34
35// std::cout << "===============================================" << std::endl;
36// std::cout << "What we get to plot..." << std::endl;
37// std::cout << "x constants: " << parameters.getNumberOfXbins() << std::endl;
38// std::cout << "x constants: " << parameters.getAngleBins().size() << " "
39// << parameters.getClusterSizeXBins().size() << std::endl;
40// for(unsigned int i = 0; i < parameters.getAngleBins().size(); i++){
41// std::cout << (parameters.getAngleBins())[i] << std::endl;
42// }
43// std::cout << "y constants: " << parameters.getNumberOfYbins() << std::endl;
44// std::cout << "y constants: " << parameters.getEtaBins().size() << " "
45// << parameters.getClusterSizeYBins().size() << std::endl;
46// std::cout << "===============================================" << std::endl;
47
48
50 m_referenceDrawOpt = new std::vector<std::string>();
51 m_RefHistosX = new std::vector < std::vector < TH1F* > >();
52 m_RefHistosY = new std::vector < std::vector < TH1F* > >();
53 m_histogramsX = HistogramsFromConstants(parameters,"phi",2);
54 m_histogramsY = HistogramsFromConstants(parameters,"eta",2);
55
56}
57
59
61
62 delete m_histogramsX;
63 delete m_histogramsY;
64 delete m_referenceDrawOpt;
65 delete m_RefHistosX;
66 delete m_RefHistosY;
67 delete[] m_etabins;
68 delete[] m_phibins;
69
70 m_histogramsX = 0;
71 m_histogramsY = 0;
72 m_RefHistosX = 0;
73 m_RefHistosY = 0;
74 m_etabins = 0;
75 m_phibins = 0;
76
77}
78
80
82 const PixelChargeInterpolationParameters &parameters,
83 const std::string& title, int color, const std::string& drawopt){
84
85 std::vector < TH1F* > *histoX = HistogramsFromConstants(parameters,"phi",color,title);
86 std::vector < TH1F* > *histoY = HistogramsFromConstants(parameters,"eta",color,title);
87
88 m_referenceDrawOpt->push_back( drawopt + std::string("same") );
89 m_RefHistosX->push_back(*histoX);
90 m_RefHistosY->push_back(*histoY);
91
92 delete histoX;
93 delete histoY;
94
95}
96
98
99void PixelChargeInterpolationPlot::Plot(const std::string& output){
100
101
102 PlotDirection(output, "phi");
103 PlotDirection(output, "eta");
104
105}
106
108
110 const PixelChargeInterpolationParameters &parameters,
111 const std::string& direction, int color, const std::string& title){
112
113 std::vector <TH1F*> *histo = new std::vector <TH1F*>();
114 std::vector<float> anglebins;
115 std::vector<float> csbins;
116 int nConstants = 0;
117 std::string xory, colorrow;
118
119 if(direction == "phi"){
120 anglebins = parameters.getAngleBins();
121 csbins = parameters.getClusterSizeXBins();
122 nConstants = parameters.getNumberOfXbins();
123 if(m_phibins == 0 && m_nphibins == 0){
124 m_nphibins = anglebins.size();
125 m_phibins = new double[m_nphibins];
126 for(int i = 0; i < m_nphibins; i++)
127 m_phibins[i] = anglebins[i];
128 }
129 xory = "x";
130 colorrow = "row";
131
132 }else{
133 anglebins = parameters.getEtaBins();
134 csbins = parameters.getClusterSizeYBins();
135 nConstants = parameters.getNumberOfYbins();
136 if(m_etabins == 0 && m_netabins == 0){
137 m_netabins = anglebins.size();
138 m_etabins = new double[m_netabins];
139 for(int i = 0; i < m_netabins; i++)
140 m_etabins[i] = anglebins[i];
141 }
142 xory = "y";
143 colorrow = "col";
144 }
145
146 int nangleBins = anglebins.size() - 1;
147 int nCsBins = csbins.size() - 1;
148 int nLayerBins = nConstants / (nangleBins * nCsBins);
149
150 int nhisto = nCsBins;
151 int nbinhisto = nLayerBins * nangleBins;
152
153// std::cout << "===============================================" << std::endl;
154// std::cout << "PixelChargeInterpolationPlot" << std::endl;
155// std::cout << "The histogram... " << direction << std::endl;
156// std::cout << "Parameters version: " << parameters.getVersion() << std::endl;
157// std::cout << "n constants: " << nConstants << std::endl;
158// std::cout << "n angle bins: " << nangleBins << std::endl;
159// std::cout << "n cs bins: " << nCsBins << std::endl;
160// std::cout << "n layer bins: " << nLayerBins << std::endl;
161// std::cout << "n histos: " << nhisto << std::endl;
162// std::cout << "n bins: " << nbinhisto << std::endl;
163// std::cout << "===============================================" << std::endl;
164
165 static std::atomic<int> pass = 0;
166 int p = pass++;
167 for(int i = 0; i < nhisto; i++){
168 std::ostringstream NameString, TitleString;
169 NameString << csbins[i] << "_" << direction << p
170 << "clustersize_ " << csbins[i+1];
171 if(title != "") TitleString << title;
172 else TitleString << "Local " + xory + " - "
173 << (csbins[i] + csbins[i+1]) /2 << "-" << colorrow << " clusters";
174 TH1F *currentPlot = new TH1F(NameString.str().c_str(),
175 TitleString.str().c_str(),nbinhisto,0,nbinhisto);
176 currentPlot->UseCurrentStyle();
177 currentPlot->GetYaxis()->SetTitle( "Charge sharing correction [#mum]");
178
179 currentPlot->SetLineColor(color);
180 currentPlot->SetMarkerColor(color);
181 for(int j = 0; j < nangleBins; j++ ){
182 for(int k = 0; k < nLayerBins; k++){
183 float constant = 0;
184 float error = 0;
185 if(direction == "phi"){
186 constant = parameters.getDeltaX(j,i,k);
187 error = parameters.getErrDeltaX(j,i,k);
188 }else{
189 constant = parameters.getDeltaY(j,i,k);
190 error = parameters.getErrDeltaY(j,i,k);
191 }
192 int iBin = (nLayerBins*j)+k+1;
193 currentPlot->SetBinContent(iBin,constant*1000);
194 if(error == 0 && m_oneconst) error = 1e-6;
195 currentPlot->SetBinError(iBin,error*1000);
196 }
197 }
198// std::cout << "===============================================" << std::endl;
199// std::cout << "The histogram..." << std::endl;
200// std::cout << "title: " << currentPlot->GetTitle() << std::endl;
201// std::cout << "n constants: " << currentPlot->GetNbinsX() << std::endl;
202// std::cout << "===============================================" << std::endl;
203 histo->push_back(currentPlot);
204 }
205
206 return histo;
207}
208
210
211void PixelChargeInterpolationPlot::PlotDirection( const std::string& filename,
212 const std::string& direction){
213
214 std::vector < std::vector < TH1F* > > *RefHistos = 0;
215 std::vector < TH1F* > *histograms = 0;
216
217 if(direction == "phi"){
218 histograms = m_histogramsX;
219 RefHistos = m_RefHistosX;
220 }else{
221 histograms = m_histogramsY;
222 RefHistos = m_RefHistosY;
223 }
224
225 unsigned int nhistos_all = histograms->size();
226 unsigned int nhistos = 0;
227 if(!m_oneconst) nhistos = nhistos_all; // plot all histograms for shifter checks!
228 else{ // only filled histos for "official" plots
229 for(unsigned int i = 0; i < nhistos_all; i++){
230 if((*histograms)[i]->GetMean() == 0 &&
231 (*histograms)[i]->GetRMS() == 0) continue;
232 nhistos++;
233 }
234 }
235 std::vector<TCanvas*> canvases;
236 for(unsigned int i = 0; i < nhistos; i++){
237 TCanvas* c1 = new TCanvas();
238 canvases.push_back(c1);
239 float maximum = (*histograms)[i]->GetMaximum();
240 for(unsigned int j = 0; j < RefHistos->size(); j++){
241 float newmax = ((*RefHistos)[j])[i]->GetMaximum();
242 if(maximum < newmax) maximum = newmax;
243 }
244 if( int((*histograms)[i]->GetNbinsX()/(2*m_nlayers)) > 20)
245 c1->SetBottomMargin(0.18);
246 DrawOneHisto((*histograms)[i], direction, maximum);
247 DrawHistoMarkers((*histograms)[i]);
248 std::string title = filename;
249 size_t found = title.find("PixelChargeInterpolationData");
250 if(found != std::string::npos) title = "PixelOfflineReco" + title.substr(title.find('-'));
251 if(m_oneconst) DrawLegendLatex(title.c_str(), 21 ,0.20, 0.83,
252 (*histograms)[i]->GetMarkerColor(),0.05);
253 else DrawTitleLatex(title.c_str(),0.15, 0.83,
254 (*histograms)[i]->GetMarkerColor());
255 //}
256
257 unsigned int nreferences = RefHistos->size();
258 //for(unsigned int i = 0; i < nhistos; i++){
259 canvases[i]->cd();
260 for(unsigned int j = 0; j < nreferences; j++){
261 DrawHistoMarkers(((*RefHistos)[j])[i],(*m_referenceDrawOpt)[j],j+1);
262 std::string title = ((*RefHistos)[j])[i]->GetTitle();
263 size_t found = title.find("PixelChargeInterpolationData");
264 if(found != std::string::npos) title = "PixelOfflineReco" + title.substr(title.find('-'));
265 if(m_oneconst) DrawLegendLatex(title.c_str(),
266 21+5*(j+1) ,
267 0.20, 0.83 - (j+1)*0.06,
268 ((*RefHistos)[j])[i]->GetMarkerColor(),0.05);
269 else DrawTitleLatex(title.c_str(),
270 0.15, 0.83 - (j+1)*0.05,
271 ((*RefHistos)[j])[i]->GetMarkerColor());
272
273 }
274 //DrawOneHisto((*histograms)[i], direction, maximum);
275 DrawHistoMarkers((*histograms)[i]);
276 }
277
278 for(unsigned int i = 0; i < nhistos; i++){
279 std::ostringstream name;
280 name << filename << direction << i+2 << ".pdf";
281 canvases[i]->Print(name.str().c_str());
282 }
283
284 //delete axis;
285 //delete c1;
286 //axis = 0;
287 //c1 = 0;
288
289}
290
291
293
294void PixelChargeInterpolationPlot::DrawOneHisto(TH1F* histo, const std::string& direction, float maximum){
295
296
297 // play with the histo
298 //float ymaximum = 1.5 * histo->GetMaximum();
299 float ymaximum = 1.5 * maximum;
300 float yminimum = - 0.1 * histo->GetMaximum();
301 histo->SetMaximum(ymaximum);
302 histo->SetMinimum(yminimum);
303 histo->GetXaxis()->SetLabelOffset(10);
304 histo->GetXaxis()->SetNdivisions(0);
305 // resizing the histo!!
306// bool notfound = true;
307 int xmaximum = histo->GetNbinsX();
308 int xminimum = 1;
309// for(int j = xminimum; j < xmaximum && notfound; j+=2*m_nlayers){
310// for(int k = j ; k < j+2*m_nlayers; k++){
311// if(histo->GetBinContent(k) != 0){
312// xminimum = j;
313// notfound = false;
314// break;
315// }
316// }
317// }
318// notfound = true;
319// for(int j = xmaximum; j > xminimum && notfound; j-=2*m_nlayers){
320// for(int k = j ; k > j-2*m_nlayers; k--){
321// if(histo->GetBinContent(k) != 0){
322// xmaximum = j;
323// notfound = false;
324// break;
325// }
326// }
327// }
328 histo->GetXaxis()->SetRange(xminimum,xmaximum);
329 histo->DrawCopy("AXIS");
330
331 DrawAxis(yminimum, ymaximum, xminimum, xmaximum, direction);
332 if(!m_oneconst) DrawLayerLegend(0.65, 0.9);
333 else DrawATLASLabel(0.15,0.9, 0.05,true);
334 DrawTitleLatex(histo->GetTitle(), 0.73, 0.85,1,0.05);
335}
336
337
339
340void PixelChargeInterpolationPlot::DrawHistoMarkers(TH1F* histo, const std::string& options, int goodj){
341
342 int startmarker = 21;
343 TH1F *markers = (TH1F *)histo->Clone();
344 markers->SetMarkerStyle(startmarker+5*goodj);
345 if(m_oneconst){
346 markers->Rebin(2*m_nlayers);
347 for (int j = 1; j < markers->GetNbinsX(); j++){
348 markers->SetBinContent(j,histo->GetBinContent((j-1)*2*m_nlayers +1));
349 }
350 markers->DrawCopy(options.c_str());
351 }else{
352 for (int j = 0; j < markers->GetNbinsX(); j++){
353 int period = j%(2*m_nlayers);
354 markers->SetMarkerStyle(startmarker+period);
355 markers->GetXaxis()->SetRange(j+1,j+1);
356 if(period == goodj || !m_oneconst)
357 markers->DrawCopy(options.c_str());
358 }
359 }
360
361 delete markers;
362 markers = 0;
363
364}
365
366
368
369
370void PixelChargeInterpolationPlot::DrawLayerLegend(float xlegend,float ylegend){
371
372 int startmarker = 21;
373 float textsize = 0.03;
374 int color = 2;
375
376 std::vector<std::string> names;
377 names.push_back("b-layer");
378 names.push_back("Layer 1");
379 names.push_back("Layer 2");
380 names.push_back("Disk 1");
381 names.push_back("Disk 2");
382 names.push_back("Disk 3");
383
384 for(int i = 0; i < 2*m_nlayers; i++ )
385 DrawLegendLatex(names[i].c_str(), startmarker+i,
386 xlegend, ylegend - i*textsize,
387 color, textsize);
388
389}
390
391
393
394
395void PixelChargeInterpolationPlot::DrawAxis(float y1, float y2, float x1, float x2, const std::string& direction){
396
397 float stdtextsize = 0.05;
398 int stdfont = 42;
399 int firstbin = int(x1/(2*m_nlayers));
400 int lastbin = int(x2/(2*m_nlayers));
401 int naxbins = lastbin - firstbin;
402
403 std::string axtitle = "";
404 double* axbins = 0;
405
406 if(direction == "phi"){
407 axbins = m_phibins;
408 axtitle = "Track incident angle (#phi_{i}) [#circ]";
409 }else if(direction == "eta"){
410 axbins = m_etabins;
411 axtitle = "Track incident pseudorapidity (#eta_{i})";
412 }
413 if (!axbins) { return; }
414
415 //std::cout << naxbins << std::endl;
416
417 TGaxis *axis = new TGaxis(x1-1, y1, x2, y1, axbins[firstbin], axbins[lastbin], naxbins);
418 axis->UseCurrentStyle();
419 axis->SetName(direction.c_str());
420 axis->SetTitle(axtitle.c_str());
421 axis->SetTitleFont(stdfont);
422 axis->SetTitleSize(stdtextsize);
423 float offset = 1.4;
424 if(naxbins > 20) offset = 1.8;
425 axis->SetTitleOffset(offset);
426 std::string opt = "UNW+-";
427 if(m_oneconst) opt = "UN+-";
428 axis->DrawAxis(x1-1, y1, x2, y1,
429 axbins[firstbin], axbins[lastbin], naxbins,opt.c_str());
430 axis->DrawAxis(x1-1, y2, x2, y2,
431 axbins[firstbin], axbins[lastbin], naxbins,"UN-");
432
433 TLatex label;
434 label.SetTextSize(stdtextsize);
435 label.SetTextFont(stdfont);
436 label.SetTextAlign(23);
437 double pass = ( axis->GetX2()-axis->GetX1() ) / double( naxbins);
438 double ylabel = y1 - 0.05 * (y2 - y1);
439 double distance = - 0.05 * (y2 - y1);
440 for(int i = 0 ; i <= naxbins; i++){
441 std::ostringstream LabelString;
442 LabelString << axbins[firstbin+i];
443 float ylabel2 = ylabel;
444 if(naxbins > 20) ylabel2 = ylabel + i%2 * distance;
445 label.DrawLatex( axis->GetX1() + i * pass, ylabel2,
446 LabelString.str().c_str());
447 }
448
449
450}
451
452
454
455
457
458 for(unsigned int i = 0; i < m_histogramsX->size(); i++)
459 (*m_histogramsX)[i]->Write();
460 for(unsigned int i = 0; i < m_histogramsY->size(); i++)
461 (*m_histogramsY)[i]->Write();
462
463
464
465}
466
467
468} // end of namespace PixelCalib
469
470#endif
void DrawATLASLabel(float x, float y, bool pre=false, float textsize=0.05)
void DrawLegendLatex(const char *chartitle, int markertype, float x, float y, int color=1, float textsize=0.034)
void DrawTitleLatex(const char *chartitle, float x, float y, int color=1, float textsize=0.04)
TGraphErrors * GetMean(TH2F *histo)
void AddReference(const PixelChargeInterpolationParameters &parameters, const std::string &title="Reference", int color=0, const std::string &drawopt="HIST")
void DrawHistoMarkers(TH1F *histo, const std::string &options="P0same", int goodj=0)
PixelChargeInterpolationPlot(const PixelChargeInterpolationParameters &parameters, bool oneconst=false)
std::vector< std::vector< TH1F * > > * m_RefHistosX
void DrawAxis(float y1, float y2, float x1, float x2, const std::string &direction="phi")
void PlotDirection(const std::string &filename, const std::string &direction="phi")
std::vector< TH1F * > * HistogramsFromConstants(const PixelChargeInterpolationParameters &parameters, const std::string &direction="phi", int color=1, const std::string &title="")
std::vector< std::vector< TH1F * > > * m_RefHistosY
void DrawOneHisto(TH1F *histo, const std::string &direction="phi", float maximum=0)
int markers[6]
Definition computils.cxx:47
std::string label(const std::string &format, int i)
Definition label.h:19