|
1 | | -// Comparison of AliPhysics and O2 histograms |
2 | | - |
3 | | -#include "utils_plot.h" |
| 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. |
4 | 11 |
|
5 | | -// vectors of histogram specifications |
6 | | -using VecSpecHis = std::vector<std::tuple<TString, TString, TString, int, bool, bool, TString>>; |
| 12 | +// Comparison of AliPhysics and O2 histograms |
7 | 13 |
|
8 | | -// Add histogram specification in the vector. |
9 | | -void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO2, int rebin, bool logH, bool logR, TString proj = "x") |
10 | | -{ |
11 | | - vec.push_back(std::make_tuple(label, nameAli, nameO2, rebin, logH, logR, proj)); |
12 | | -} |
| 14 | +#include "../exec/utilitiesValidation.h" |
13 | 15 |
|
14 | | -Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) |
| 16 | +Int_t Compare(TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) |
15 | 17 | { |
16 | | - gStyle->SetOptStat(0); |
17 | | - gStyle->SetPalette(0); |
18 | | - gStyle->SetCanvasColor(0); |
19 | | - gStyle->SetFrameFillColor(0); |
20 | | - |
21 | | - TFile* fO2 = new TFile(fileO2.Data()); |
22 | | - if (fO2->IsZombie()) { |
23 | | - printf("Failed to open file %s\n", fileO2.Data()); |
24 | | - return 1; |
25 | | - } |
26 | | - TFile* fAli = new TFile(fileAli.Data()); |
27 | | - if (fAli->IsZombie()) { |
28 | | - printf("Failed to open file %s\n", fileAli.Data()); |
29 | | - return 1; |
30 | | - } |
31 | | - |
32 | 18 | TString pathListAli = "HFVertices/clistHFVertices"; |
33 | | - TList* lAli = nullptr; |
34 | | - fAli->GetObject(pathListAli.Data(), lAli); |
35 | | - if (!lAli) { |
36 | | - printf("Failed to load list %s from %s\n", pathListAli.Data(), fileAli.Data()); |
37 | | - return 1; |
38 | | - } |
39 | | - |
40 | 19 | TString labelParticle = ""; |
41 | 20 |
|
42 | 21 | // Histogram specification: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis |
@@ -251,7 +230,7 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana |
251 | 230 | AddHistogram(vecHisJetSubstructureMC, "#it{n}_{SD,gen}", "fHistJetNsd_Part", "jet-substructure-hf-mcp/h_jet_nsd", 1, 0, 0); |
252 | 231 |
|
253 | 232 | // vector of specifications of vectors: name, VecSpecHis, pads X, pads Y |
254 | | - std::vector<std::tuple<TString, VecSpecHis, int, int>> vecSpecVecSpec; |
| 233 | + VecSpecVecSpec vecSpecVecSpec; |
255 | 234 |
|
256 | 235 | // Add vector specifications in the vector. |
257 | 236 | if (options.Contains(" events ")) |
@@ -295,138 +274,5 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana |
295 | 274 | if (options.Contains(" jets-substructure-mc ")) |
296 | 275 | vecSpecVecSpec.push_back(std::make_tuple("jets-substructure-mc", vecHisJetSubstructureMC, 5, 3)); |
297 | 276 |
|
298 | | - // Histogram plot vertical margins |
299 | | - Float_t marginHigh = 0.05; |
300 | | - Float_t marginLow = 0.05; |
301 | | - bool logScaleH = false; |
302 | | - // Ratio plot vertical margins |
303 | | - Float_t marginRHigh = 0.05; |
304 | | - Float_t marginRLow = 0.05; |
305 | | - bool logScaleR = false; |
306 | | - Float_t yMin, yMax; |
307 | | - Int_t nAli, nO2, rebin; |
308 | | - |
309 | | - TH1F* hAli = nullptr; |
310 | | - TH1D* hO2 = nullptr; |
311 | | - TH1F* hRatio = nullptr; |
312 | | - TString labelAxis = ""; |
313 | | - TString nameHisAli = ""; |
314 | | - TString nameHisO2 = ""; |
315 | | - TString projAx = ""; |
316 | | - TCanvas* canHis = nullptr; |
317 | | - TCanvas* canRat = nullptr; |
318 | | - |
319 | | - // loop over lists |
320 | | - for (const auto& specVecSpec : vecSpecVecSpec) { |
321 | | - auto nameSpec = std::get<0>(specVecSpec); // list name |
322 | | - auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. |
323 | | - int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads |
324 | | - int nPadsY = std::get<3>(specVecSpec); // number of vertical pads |
325 | | - Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); |
326 | | - if (nPadsX * nPadsY < vecSpec.size()) { |
327 | | - Printf("Not enough pads (%d)", nPadsX * nPadsY); |
328 | | - return 1; |
329 | | - } |
330 | | - |
331 | | - canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); |
332 | | - SetCanvas(canHis, nPadsX, nPadsY); |
333 | | - if (doRatio) { |
334 | | - canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); |
335 | | - SetCanvas(canRat, nPadsX, nPadsY); |
336 | | - } |
337 | | - |
338 | | - // loop over histograms |
339 | | - for (int index = 0; index < vecSpec.size(); index++) { |
340 | | - auto spec = vecSpec[index]; |
341 | | - labelAxis = std::get<0>(spec); |
342 | | - nameHisAli = std::get<1>(spec); |
343 | | - nameHisO2 = std::get<2>(spec); |
344 | | - rebin = std::get<3>(spec); |
345 | | - logScaleH = std::get<4>(spec); |
346 | | - logScaleR = std::get<5>(spec); |
347 | | - projAx = std::get<6>(spec); |
348 | | - |
349 | | - // Get AliPhysics histogram. |
350 | | - hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); |
351 | | - if (!hAli) { |
352 | | - printf("Failed to load %s from %s\n", nameHisAli.Data(), fileAli.Data()); |
353 | | - return 1; |
354 | | - } |
355 | | - |
356 | | - // Get O2 histogram. |
357 | | - auto oO2 = fO2->Get(nameHisO2.Data()); |
358 | | - if (!oO2) { |
359 | | - printf("Failed to load %s from %s\n", nameHisO2.Data(), fileO2.Data()); |
360 | | - return 1; |
361 | | - } |
362 | | - |
363 | | - if (oO2->InheritsFrom("TH3")) { |
364 | | - if (projAx == "x") { |
365 | | - hO2 = ((TH3D*)oO2)->ProjectionX(); |
366 | | - } else if (projAx == "y") { |
367 | | - hO2 = ((TH3D*)oO2)->ProjectionY(); |
368 | | - } |
369 | | - } else if (oO2->InheritsFrom("TH2")) { |
370 | | - if (projAx == "x") { |
371 | | - hO2 = ((TH2D*)oO2)->ProjectionX(); |
372 | | - } else if (projAx == "y") { |
373 | | - hO2 = ((TH2D*)oO2)->ProjectionY(); |
374 | | - } |
375 | | - } else { |
376 | | - hO2 = (TH1D*)oO2; |
377 | | - } |
378 | | - |
379 | | - Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", |
380 | | - index, nameHisAli.Data(), nameHisO2.Data(), |
381 | | - hAli->GetNbinsX(), hO2->GetNbinsX(), |
382 | | - hAli->GetXaxis()->GetBinLowEdge(1), hAli->GetXaxis()->GetBinUpEdge(hAli->GetNbinsX()), |
383 | | - hO2->GetXaxis()->GetBinLowEdge(1), hO2->GetXaxis()->GetBinUpEdge(hO2->GetNbinsX())); |
384 | | - |
385 | | - nAli = hAli->GetEntries(); |
386 | | - nO2 = hO2->GetEntries(); |
387 | | - |
388 | | - // Histograms |
389 | | - auto padH = canHis->cd(index + 1); |
390 | | - hAli->Rebin(rebin); |
391 | | - hO2->Rebin(rebin); |
392 | | - hAli->SetLineColor(1); |
393 | | - hAli->SetLineWidth(2); |
394 | | - hO2->SetLineColor(2); |
395 | | - hO2->SetLineWidth(1); |
396 | | - hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); |
397 | | - hAli->GetYaxis()->SetMaxDigits(3); |
398 | | - yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); |
399 | | - yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); |
400 | | - SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); |
401 | | - SetPad(padH, logScaleH); |
402 | | - hAli->Draw(); |
403 | | - hO2->Draw("same"); |
404 | | - TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); |
405 | | - legend->AddEntry(hAli, "Ali", "L"); |
406 | | - legend->AddEntry(hO2, "O^{2}", "L"); |
407 | | - legend->Draw(); |
408 | | - |
409 | | - // Ratio |
410 | | - if (doRatio) { |
411 | | - auto padR = canRat->cd(index + 1); |
412 | | - hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); |
413 | | - hRatio->Divide(hAli); |
414 | | - hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); |
415 | | - yMin = hRatio->GetMinimum(0); |
416 | | - yMax = hRatio->GetMaximum(); |
417 | | - SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); |
418 | | - SetPad(padR, logScaleR); |
419 | | - hRatio->Draw(); |
420 | | - } |
421 | | - } |
422 | | - canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); |
423 | | - canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); |
424 | | - if (doRatio) { |
425 | | - canRat->SaveAs(Form("comparison_ratios_%s.pdf", nameSpec.Data())); |
426 | | - canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); |
427 | | - } |
428 | | - delete canHis; |
429 | | - delete canRat; |
430 | | - } |
431 | | - return 0; |
| 277 | + return MakePlots(vecSpecVecSpec, pathFileO2, pathFileAli, pathListAli, doRatio); |
432 | 278 | } |
0 commit comments