From 42c290b19b7bc4ad4e2fce63fb352d197648b251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 16:22:06 +0100 Subject: [PATCH 01/18] Refactor utilities --- codeHF/Compare.C | 12 ++-------- codeHF/PlotEfficiency.C | 2 +- codeHF/RunHFTaskLocal.C | 33 +--------------------------- exec/convertAO2D.C | 41 +---------------------------------- exec/utils_ali.h | 37 +++++++++++++++++++++++++++++++ {codeHF => exec}/utils_plot.h | 0 exec/utils_validation.h | 10 +++++++++ 7 files changed, 52 insertions(+), 83 deletions(-) create mode 100644 exec/utils_ali.h rename {codeHF => exec}/utils_plot.h (100%) create mode 100644 exec/utils_validation.h diff --git a/codeHF/Compare.C b/codeHF/Compare.C index 0a64b549..4ee01bfb 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -1,15 +1,7 @@ // Comparison of AliPhysics and O2 histograms -#include "utils_plot.h" - -// vectors of histogram specifications -using VecSpecHis = std::vector>; - -// Add histogram specification in the vector. -void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO2, int rebin, bool logH, bool logR, TString proj = "x") -{ - vec.push_back(std::make_tuple(label, nameAli, nameO2, rebin, logH, logR, proj)); -} +#include "../exec/utils_plot.h" +#include "../exec/utils_validation.h" Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) { diff --git a/codeHF/PlotEfficiency.C b/codeHF/PlotEfficiency.C index 6e4171f5..06353c8f 100644 --- a/codeHF/PlotEfficiency.C +++ b/codeHF/PlotEfficiency.C @@ -1,6 +1,6 @@ // Plotting of reconstruction efficiency -#include "utils_plot.h" +#include "../exec/utils_plot.h" Int_t PlotEfficiency(TString pathFile = "AnalysisResults.root", TString particles = "d0") { diff --git a/codeHF/RunHFTaskLocal.C b/codeHF/RunHFTaskLocal.C index b4edb1b4..f8e671fc 100644 --- a/codeHF/RunHFTaskLocal.C +++ b/codeHF/RunHFTaskLocal.C @@ -1,4 +1,4 @@ -TChain* CreateLocalChain(const char* txtfile); +#include "../exec/utils_ali.h" Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", TString jsonfilename = "dpl-config_std.json", @@ -60,34 +60,3 @@ Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", mgr->PrintStatus(); return mgr->StartAnalysis("local", chainESD); }; - -TChain* CreateLocalChain(const char* txtfile) -{ - // Open the file - ifstream in; - in.open(txtfile); - Int_t count = 0; - // Read the input list of files and add them to the chain - TString line; - TChain* chain = new TChain("esdTree"); - while (in.good()) { - in >> line; - if (line.IsNull() || line.BeginsWith("#")) - continue; - TString esdFile(line); - TFile* file = TFile::Open(esdFile); - if (file && !file->IsZombie()) { - chain->Add(esdFile); - file->Close(); - } else { - Error("CreateLocalChain", "Skipping un-openable file: %s", esdFile.Data()); - } - } - in.close(); - if (!chain->GetListOfFiles()->GetEntries()) { - Error("CreateLocalChain", "No file from %s could be opened", txtfile); - delete chain; - return nullptr; - } - return chain; -} diff --git a/exec/convertAO2D.C b/exec/convertAO2D.C index 7a031316..f932709e 100644 --- a/exec/convertAO2D.C +++ b/exec/convertAO2D.C @@ -8,7 +8,7 @@ R__ADD_INCLUDE_PATH($ALICE_PHYSICS) #include #include -TChain* CreateLocalChain(const char* txtfile, const char* type, int nfiles); +#include "utils_ali.h" Long64_t convertAO2D(TString listoffiles, bool isMC = 1, bool useAliEvCuts = false, bool isESD = 1, int nmaxevents = -1) { @@ -57,42 +57,3 @@ Long64_t convertAO2D(TString listoffiles, bool isMC = 1, bool useAliEvCuts = fal mgr->SetDebugLevel(1); return mgr->StartAnalysis("localfile", chain, nentries, 0); } - -TChain* CreateLocalChain(const char* txtfile, const char* type, int nfiles) -{ - TString treename = type; - treename.ToLower(); - treename += "Tree"; - printf("***************************************\n"); - printf(" Getting chain of trees %s\n", treename.Data()); - printf("***************************************\n"); - // Open the file - ifstream in; - in.open(txtfile); - Int_t count = 0; - // Read the input list of files and add them to the chain - TString line; - TChain* chain = new TChain(treename); - while (in.good()) { - in >> line; - if (line.IsNull() || line.BeginsWith("#")) - continue; - if (count++ == nfiles) - break; - TString esdFile(line); - TFile* file = TFile::Open(esdFile); - if (file && !file->IsZombie()) { - chain->Add(esdFile); - file->Close(); - } else { - Error("GetChainforTestMode", "Skipping un-openable file: %s", esdFile.Data()); - } - } - in.close(); - if (!chain->GetListOfFiles()->GetEntries()) { - Error("CreateLocalChain", "No file from %s could be opened", txtfile); - delete chain; - return nullptr; - } - return chain; -} diff --git a/exec/utils_ali.h b/exec/utils_ali.h new file mode 100644 index 00000000..3de34f97 --- /dev/null +++ b/exec/utils_ali.h @@ -0,0 +1,37 @@ +// AliPhysics utilities + +TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfiles = -1) +{ + TString treename = type; + treename.ToLower(); + treename += "Tree"; + // Open the file + ifstream in; + in.open(txtfile); + Int_t count = 0; + // Read the input list of files and add them to the chain + TString line; + TChain* chain = new TChain(treename); + while (in.good()) { + in >> line; + if (line.IsNull() || line.BeginsWith("#")) + continue; + if (count++ == nfiles) + break; + TString esdFile(line); + TFile* file = TFile::Open(esdFile); + if (file && !file->IsZombie()) { + chain->Add(esdFile); + file->Close(); + } else { + Error("CreateLocalChain", "Skipping un-openable file: %s", esdFile.Data()); + } + } + in.close(); + if (!chain->GetListOfFiles()->GetEntries()) { + Error("CreateLocalChain", "No file from %s could be opened", txtfile); + delete chain; + return nullptr; + } + return chain; +} diff --git a/codeHF/utils_plot.h b/exec/utils_plot.h similarity index 100% rename from codeHF/utils_plot.h rename to exec/utils_plot.h diff --git a/exec/utils_validation.h b/exec/utils_validation.h new file mode 100644 index 00000000..c7d9c092 --- /dev/null +++ b/exec/utils_validation.h @@ -0,0 +1,10 @@ +// Validation utilities + +// vectors of histogram specifications +using VecSpecHis = std::vector>; + +// Add histogram specification in the vector. +void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO2, int rebin, bool logH, bool logR, TString proj = "x") +{ + vec.push_back(std::make_tuple(label, nameAli, nameO2, rebin, logH, logR, proj)); +} From b58d2e6104805d2795b54d48d0b4062fd8bd09d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 16:44:56 +0100 Subject: [PATCH 02/18] Add copyright. Add tuple header. Fix path. --- codeHF/Compare.C | 11 +++++++++++ codeHF/PlotEfficiency.C | 11 +++++++++++ codeHF/PlotEfficiencyRecoStep.C | 13 ++++++++++++- codeHF/RunHFTaskLocal.C | 13 +++++++++++++ exec/convertAO2D.C | 11 +++++++++++ exec/utils_ali.h | 11 +++++++++++ exec/utils_plot.h | 11 +++++++++++ exec/utils_validation.h | 13 +++++++++++++ 8 files changed, 93 insertions(+), 1 deletion(-) diff --git a/codeHF/Compare.C b/codeHF/Compare.C index 4ee01bfb..9361ce85 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Comparison of AliPhysics and O2 histograms #include "../exec/utils_plot.h" diff --git a/codeHF/PlotEfficiency.C b/codeHF/PlotEfficiency.C index 06353c8f..f1b873e3 100644 --- a/codeHF/PlotEfficiency.C +++ b/codeHF/PlotEfficiency.C @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Plotting of reconstruction efficiency #include "../exec/utils_plot.h" diff --git a/codeHF/PlotEfficiencyRecoStep.C b/codeHF/PlotEfficiencyRecoStep.C index e4045203..0d803945 100644 --- a/codeHF/PlotEfficiencyRecoStep.C +++ b/codeHF/PlotEfficiencyRecoStep.C @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Computation and plotting of reconstruction efficiency step-by-step // Four steps defined: RecoHFFlag, RecoTopol, RecoCand, RecoPID // RecoHFFlag: candidates properly flagged (e.g. in HFD0CandidateSelector --> hfflag() is D0ToPiK) @@ -10,7 +21,7 @@ // .L PlotEfficiencyRecoStep.C // PlotEfficiencyRecoStep("InputName.root","particlename",true); -#include "utils_plot.h" +#include "../exec/utils_plot.h" void SetProperAxisRange(TH1F** histo, int NIteration, float marginHigh, float marginLow, bool logScaleH); diff --git a/codeHF/RunHFTaskLocal.C b/codeHF/RunHFTaskLocal.C index f8e671fc..a80d6aa1 100644 --- a/codeHF/RunHFTaskLocal.C +++ b/codeHF/RunHFTaskLocal.C @@ -1,3 +1,16 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +// + #include "../exec/utils_ali.h" Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", diff --git a/exec/convertAO2D.C b/exec/convertAO2D.C index f932709e..86612374 100644 --- a/exec/convertAO2D.C +++ b/exec/convertAO2D.C @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + R__ADD_INCLUDE_PATH($ALICE_ROOT) R__ADD_INCLUDE_PATH($ALICE_PHYSICS) #include diff --git a/exec/utils_ali.h b/exec/utils_ali.h index 3de34f97..cffd4a21 100644 --- a/exec/utils_ali.h +++ b/exec/utils_ali.h @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // AliPhysics utilities TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfiles = -1) diff --git a/exec/utils_plot.h b/exec/utils_plot.h index 94f98bf3..3cf74c2d 100644 --- a/exec/utils_plot.h +++ b/exec/utils_plot.h @@ -1,3 +1,14 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Plotting utilities void SetCanvas(TCanvas* can, int nPadsX, int nPadsY) diff --git a/exec/utils_validation.h b/exec/utils_validation.h index c7d9c092..5df1014b 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -1,5 +1,18 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + // Validation utilities +#include + // vectors of histogram specifications using VecSpecHis = std::vector>; From efb9b816cb61526fbe0e37f34e5108cc2071bf43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 16:53:06 +0100 Subject: [PATCH 03/18] Add header guards --- exec/utils_ali.h | 5 +++++ exec/utils_plot.h | 5 +++++ exec/utils_validation.h | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/exec/utils_ali.h b/exec/utils_ali.h index cffd4a21..e2efbe06 100644 --- a/exec/utils_ali.h +++ b/exec/utils_ali.h @@ -11,6 +11,9 @@ // AliPhysics utilities +#ifndef EXEC_UTILS_ALI_H_ +#define EXEC_UTILS_ALI_H_ + TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfiles = -1) { TString treename = type; @@ -46,3 +49,5 @@ TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfil } return chain; } + +#endif // EXEC_UTILS_ALI_H_ diff --git a/exec/utils_plot.h b/exec/utils_plot.h index 3cf74c2d..c67e89d9 100644 --- a/exec/utils_plot.h +++ b/exec/utils_plot.h @@ -11,6 +11,9 @@ // Plotting utilities +#ifndef EXEC_UTILS_PLOT_H_ +#define EXEC_UTILS_PLOT_H_ + void SetCanvas(TCanvas* can, int nPadsX, int nPadsY) { can->Divide(nPadsX, nPadsY, 0.005, 0.005); @@ -54,3 +57,5 @@ void SetHistogramStyle(TH1* his, Int_t colour = 1, Int_t markerStyle = 1, Float_ his->SetMarkerStyle(markerStyle); his->SetMarkerSize(markerSize); } + +#endif // EXEC_UTILS_PLOT_H_ diff --git a/exec/utils_validation.h b/exec/utils_validation.h index 5df1014b..a739775d 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -11,7 +11,11 @@ // Validation utilities +#ifndef EXEC_UTILS_VALIDATION_H_ +#define EXEC_UTILS_VALIDATION_H_ + #include +#include // vectors of histogram specifications using VecSpecHis = std::vector>; @@ -21,3 +25,5 @@ void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO { vec.push_back(std::make_tuple(label, nameAli, nameO2, rebin, logH, logR, proj)); } + +#endif // EXEC_UTILS_VALIDATION_H_ From 6ccd9c8457d127544effc864e3e01c4abcac4f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 17:25:47 +0100 Subject: [PATCH 04/18] Move compare.py --- {codeHF => exec}/compare.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {codeHF => exec}/compare.py (100%) diff --git a/codeHF/compare.py b/exec/compare.py similarity index 100% rename from codeHF/compare.py rename to exec/compare.py From 42c72de499f23e0acbe1a235e6d3ad1f34659272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 17:26:23 +0100 Subject: [PATCH 05/18] Factor out plotting part of validation --- codeHF/Compare.C | 278 ++++++++++++++++++++++++----------------------- 1 file changed, 141 insertions(+), 137 deletions(-) diff --git a/codeHF/Compare.C b/codeHF/Compare.C index 9361ce85..543af272 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -14,8 +14,7 @@ #include "../exec/utils_plot.h" #include "../exec/utils_validation.h" -Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) -{ +Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", bool doRatio = false) { gStyle->SetOptStat(0); gStyle->SetPalette(0); gStyle->SetCanvasColor(0); @@ -40,6 +39,144 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana return 1; } + // Histogram plot vertical margins + Float_t marginHigh = 0.05; + Float_t marginLow = 0.05; + bool logScaleH = false; + // Ratio plot vertical margins + Float_t marginRHigh = 0.05; + Float_t marginRLow = 0.05; + bool logScaleR = false; + Float_t yMin, yMax; + Int_t nAli, nO2, rebin; + + TH1F* hAli = nullptr; + TH1D* hO2 = nullptr; + TH1F* hRatio = nullptr; + TString labelAxis = ""; + TString nameHisAli = ""; + TString nameHisO2 = ""; + TString projAx = ""; + TCanvas* canHis = nullptr; + TCanvas* canRat = nullptr; + + // loop over lists + for (const auto& specVecSpec : vecSpecVecSpec) { + auto nameSpec = std::get<0>(specVecSpec); // list name + auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. + int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads + int nPadsY = std::get<3>(specVecSpec); // number of vertical pads + Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); + if (nPadsX * nPadsY < vecSpec.size()) { + Printf("Not enough pads (%d)", nPadsX * nPadsY); + return 1; + } + + canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); + SetCanvas(canHis, nPadsX, nPadsY); + if (doRatio) { + canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); + SetCanvas(canRat, nPadsX, nPadsY); + } + + // loop over histograms + for (int index = 0; index < vecSpec.size(); index++) { + auto spec = vecSpec[index]; + labelAxis = std::get<0>(spec); + nameHisAli = std::get<1>(spec); + nameHisO2 = std::get<2>(spec); + rebin = std::get<3>(spec); + logScaleH = std::get<4>(spec); + logScaleR = std::get<5>(spec); + projAx = std::get<6>(spec); + + // Get AliPhysics histogram. + hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); + if (!hAli) { + printf("Failed to load %s from %s\n", nameHisAli.Data(), fileAli.Data()); + return 1; + } + + // Get O2 histogram. + auto oO2 = fO2->Get(nameHisO2.Data()); + if (!oO2) { + printf("Failed to load %s from %s\n", nameHisO2.Data(), fileO2.Data()); + return 1; + } + + if (oO2->InheritsFrom("TH3")) { + if (projAx == "x") { + hO2 = ((TH3D*)oO2)->ProjectionX(); + } else if (projAx == "y") { + hO2 = ((TH3D*)oO2)->ProjectionY(); + } + } else if (oO2->InheritsFrom("TH2")) { + if (projAx == "x") { + hO2 = ((TH2D*)oO2)->ProjectionX(); + } else if (projAx == "y") { + hO2 = ((TH2D*)oO2)->ProjectionY(); + } + } else { + hO2 = (TH1D*)oO2; + } + + Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", + index, nameHisAli.Data(), nameHisO2.Data(), + hAli->GetNbinsX(), hO2->GetNbinsX(), + hAli->GetXaxis()->GetBinLowEdge(1), hAli->GetXaxis()->GetBinUpEdge(hAli->GetNbinsX()), + hO2->GetXaxis()->GetBinLowEdge(1), hO2->GetXaxis()->GetBinUpEdge(hO2->GetNbinsX())); + + nAli = hAli->GetEntries(); + nO2 = hO2->GetEntries(); + + // Histograms + auto padH = canHis->cd(index + 1); + hAli->Rebin(rebin); + hO2->Rebin(rebin); + hAli->SetLineColor(1); + hAli->SetLineWidth(2); + hO2->SetLineColor(2); + hO2->SetLineWidth(1); + hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); + hAli->GetYaxis()->SetMaxDigits(3); + yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); + yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); + SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); + SetPad(padH, logScaleH); + hAli->Draw(); + hO2->Draw("same"); + TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); + legend->AddEntry(hAli, "Ali", "L"); + legend->AddEntry(hO2, "O^{2}", "L"); + legend->Draw(); + + // Ratio + if (doRatio) { + auto padR = canRat->cd(index + 1); + hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); + hRatio->Divide(hAli); + hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); + yMin = hRatio->GetMinimum(0); + yMax = hRatio->GetMaximum(); + SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); + SetPad(padR, logScaleR); + hRatio->Draw(); + } + } + canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); + canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); + if (doRatio) { + canRat->SaveAs(Form("comparison_ratios_%s.pdf", nameSpec.Data())); + canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); + } + delete canHis; + delete canRat; + } + return 0; +} + +Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) +{ TString labelParticle = ""; // Histogram specification: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis @@ -254,7 +391,7 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana AddHistogram(vecHisJetSubstructureMC, "#it{n}_{SD,gen}", "fHistJetNsd_Part", "jet-substructure-hf-mcp/h_jet_nsd", 1, 0, 0); // vector of specifications of vectors: name, VecSpecHis, pads X, pads Y - std::vector> vecSpecVecSpec; + VecSpecVecSpec vecSpecVecSpec; // Add vector specifications in the vector. if (options.Contains(" events ")) @@ -298,138 +435,5 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana if (options.Contains(" jets-substructure-mc ")) vecSpecVecSpec.push_back(std::make_tuple("jets-substructure-mc", vecHisJetSubstructureMC, 5, 3)); - // Histogram plot vertical margins - Float_t marginHigh = 0.05; - Float_t marginLow = 0.05; - bool logScaleH = false; - // Ratio plot vertical margins - Float_t marginRHigh = 0.05; - Float_t marginRLow = 0.05; - bool logScaleR = false; - Float_t yMin, yMax; - Int_t nAli, nO2, rebin; - - TH1F* hAli = nullptr; - TH1D* hO2 = nullptr; - TH1F* hRatio = nullptr; - TString labelAxis = ""; - TString nameHisAli = ""; - TString nameHisO2 = ""; - TString projAx = ""; - TCanvas* canHis = nullptr; - TCanvas* canRat = nullptr; - - // loop over lists - for (const auto& specVecSpec : vecSpecVecSpec) { - auto nameSpec = std::get<0>(specVecSpec); // list name - auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. - int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads - int nPadsY = std::get<3>(specVecSpec); // number of vertical pads - Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); - if (nPadsX * nPadsY < vecSpec.size()) { - Printf("Not enough pads (%d)", nPadsX * nPadsY); - return 1; - } - - canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canHis, nPadsX, nPadsY); - if (doRatio) { - canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canRat, nPadsX, nPadsY); - } - - // loop over histograms - for (int index = 0; index < vecSpec.size(); index++) { - auto spec = vecSpec[index]; - labelAxis = std::get<0>(spec); - nameHisAli = std::get<1>(spec); - nameHisO2 = std::get<2>(spec); - rebin = std::get<3>(spec); - logScaleH = std::get<4>(spec); - logScaleR = std::get<5>(spec); - projAx = std::get<6>(spec); - - // Get AliPhysics histogram. - hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); - if (!hAli) { - printf("Failed to load %s from %s\n", nameHisAli.Data(), fileAli.Data()); - return 1; - } - - // Get O2 histogram. - auto oO2 = fO2->Get(nameHisO2.Data()); - if (!oO2) { - printf("Failed to load %s from %s\n", nameHisO2.Data(), fileO2.Data()); - return 1; - } - - if (oO2->InheritsFrom("TH3")) { - if (projAx == "x") { - hO2 = ((TH3D*)oO2)->ProjectionX(); - } else if (projAx == "y") { - hO2 = ((TH3D*)oO2)->ProjectionY(); - } - } else if (oO2->InheritsFrom("TH2")) { - if (projAx == "x") { - hO2 = ((TH2D*)oO2)->ProjectionX(); - } else if (projAx == "y") { - hO2 = ((TH2D*)oO2)->ProjectionY(); - } - } else { - hO2 = (TH1D*)oO2; - } - - Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", - index, nameHisAli.Data(), nameHisO2.Data(), - hAli->GetNbinsX(), hO2->GetNbinsX(), - hAli->GetXaxis()->GetBinLowEdge(1), hAli->GetXaxis()->GetBinUpEdge(hAli->GetNbinsX()), - hO2->GetXaxis()->GetBinLowEdge(1), hO2->GetXaxis()->GetBinUpEdge(hO2->GetNbinsX())); - - nAli = hAli->GetEntries(); - nO2 = hO2->GetEntries(); - - // Histograms - auto padH = canHis->cd(index + 1); - hAli->Rebin(rebin); - hO2->Rebin(rebin); - hAli->SetLineColor(1); - hAli->SetLineWidth(2); - hO2->SetLineColor(2); - hO2->SetLineWidth(1); - hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); - hAli->GetYaxis()->SetMaxDigits(3); - yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); - yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); - SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); - SetPad(padH, logScaleH); - hAli->Draw(); - hO2->Draw("same"); - TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); - legend->AddEntry(hAli, "Ali", "L"); - legend->AddEntry(hO2, "O^{2}", "L"); - legend->Draw(); - - // Ratio - if (doRatio) { - auto padR = canRat->cd(index + 1); - hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); - hRatio->Divide(hAli); - hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); - yMin = hRatio->GetMinimum(0); - yMax = hRatio->GetMaximum(); - SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); - SetPad(padR, logScaleR); - hRatio->Draw(); - } - } - canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); - canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); - if (doRatio) { - canRat->SaveAs(Form("comparison_ratios_%s.pdf", nameSpec.Data())); - canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); - } - delete canHis; - delete canRat; - } - return 0; + return MakePlots(vecSpecVecSpec, fileO2, fileAli, doRatio); } From fab4d659627f2d2b8c7770c5fb3be845c2155606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 17:55:16 +0100 Subject: [PATCH 06/18] Fix plotting factorisation --- codeHF/Compare.C | 6 +++--- exec/utils_validation.h | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/codeHF/Compare.C b/codeHF/Compare.C index 543af272..fd34bcc6 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -14,7 +14,7 @@ #include "../exec/utils_plot.h" #include "../exec/utils_validation.h" -Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", bool doRatio = false) { +Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString pathListAli = "list", bool doRatio = false) { gStyle->SetOptStat(0); gStyle->SetPalette(0); gStyle->SetCanvasColor(0); @@ -31,7 +31,6 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "Analysis return 1; } - TString pathListAli = "HFVertices/clistHFVertices"; TList* lAli = nullptr; fAli->GetObject(pathListAli.Data(), lAli); if (!lAli) { @@ -177,6 +176,7 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "Analysis Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) { + TString pathListAli = "HFVertices/clistHFVertices"; TString labelParticle = ""; // Histogram specification: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis @@ -435,5 +435,5 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana if (options.Contains(" jets-substructure-mc ")) vecSpecVecSpec.push_back(std::make_tuple("jets-substructure-mc", vecHisJetSubstructureMC, 5, 3)); - return MakePlots(vecSpecVecSpec, fileO2, fileAli, doRatio); + return MakePlots(vecSpecVecSpec, fileO2, fileAli, pathListAli, doRatio); } diff --git a/exec/utils_validation.h b/exec/utils_validation.h index a739775d..a6972fce 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -17,9 +17,12 @@ #include #include -// vectors of histogram specifications +// vectors of histogram specifications: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis using VecSpecHis = std::vector>; +// vector of specifications of vectors: name, VecSpecHis, pads X, pads Y +using VecSpecVecSpec = std::vector>; + // Add histogram specification in the vector. void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO2, int rebin, bool logH, bool logR, TString proj = "x") { From 5849e9eba3eaee1b967f7c37696af8050dc4853d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 18:04:03 +0100 Subject: [PATCH 07/18] Factor out MakePlots into a header file. --- codeHF/Compare.C | 165 +--------------------------------------- exec/utils_validation.h | 164 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+), 163 deletions(-) diff --git a/codeHF/Compare.C b/codeHF/Compare.C index fd34bcc6..023aca9b 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -11,170 +11,9 @@ // Comparison of AliPhysics and O2 histograms -#include "../exec/utils_plot.h" #include "../exec/utils_validation.h" -Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString pathListAli = "list", bool doRatio = false) { - gStyle->SetOptStat(0); - gStyle->SetPalette(0); - gStyle->SetCanvasColor(0); - gStyle->SetFrameFillColor(0); - - TFile* fO2 = new TFile(fileO2.Data()); - if (fO2->IsZombie()) { - printf("Failed to open file %s\n", fileO2.Data()); - return 1; - } - TFile* fAli = new TFile(fileAli.Data()); - if (fAli->IsZombie()) { - printf("Failed to open file %s\n", fileAli.Data()); - return 1; - } - - TList* lAli = nullptr; - fAli->GetObject(pathListAli.Data(), lAli); - if (!lAli) { - printf("Failed to load list %s from %s\n", pathListAli.Data(), fileAli.Data()); - return 1; - } - - // Histogram plot vertical margins - Float_t marginHigh = 0.05; - Float_t marginLow = 0.05; - bool logScaleH = false; - // Ratio plot vertical margins - Float_t marginRHigh = 0.05; - Float_t marginRLow = 0.05; - bool logScaleR = false; - Float_t yMin, yMax; - Int_t nAli, nO2, rebin; - - TH1F* hAli = nullptr; - TH1D* hO2 = nullptr; - TH1F* hRatio = nullptr; - TString labelAxis = ""; - TString nameHisAli = ""; - TString nameHisO2 = ""; - TString projAx = ""; - TCanvas* canHis = nullptr; - TCanvas* canRat = nullptr; - - // loop over lists - for (const auto& specVecSpec : vecSpecVecSpec) { - auto nameSpec = std::get<0>(specVecSpec); // list name - auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. - int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads - int nPadsY = std::get<3>(specVecSpec); // number of vertical pads - Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); - if (nPadsX * nPadsY < vecSpec.size()) { - Printf("Not enough pads (%d)", nPadsX * nPadsY); - return 1; - } - - canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canHis, nPadsX, nPadsY); - if (doRatio) { - canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canRat, nPadsX, nPadsY); - } - - // loop over histograms - for (int index = 0; index < vecSpec.size(); index++) { - auto spec = vecSpec[index]; - labelAxis = std::get<0>(spec); - nameHisAli = std::get<1>(spec); - nameHisO2 = std::get<2>(spec); - rebin = std::get<3>(spec); - logScaleH = std::get<4>(spec); - logScaleR = std::get<5>(spec); - projAx = std::get<6>(spec); - - // Get AliPhysics histogram. - hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); - if (!hAli) { - printf("Failed to load %s from %s\n", nameHisAli.Data(), fileAli.Data()); - return 1; - } - - // Get O2 histogram. - auto oO2 = fO2->Get(nameHisO2.Data()); - if (!oO2) { - printf("Failed to load %s from %s\n", nameHisO2.Data(), fileO2.Data()); - return 1; - } - - if (oO2->InheritsFrom("TH3")) { - if (projAx == "x") { - hO2 = ((TH3D*)oO2)->ProjectionX(); - } else if (projAx == "y") { - hO2 = ((TH3D*)oO2)->ProjectionY(); - } - } else if (oO2->InheritsFrom("TH2")) { - if (projAx == "x") { - hO2 = ((TH2D*)oO2)->ProjectionX(); - } else if (projAx == "y") { - hO2 = ((TH2D*)oO2)->ProjectionY(); - } - } else { - hO2 = (TH1D*)oO2; - } - - Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", - index, nameHisAli.Data(), nameHisO2.Data(), - hAli->GetNbinsX(), hO2->GetNbinsX(), - hAli->GetXaxis()->GetBinLowEdge(1), hAli->GetXaxis()->GetBinUpEdge(hAli->GetNbinsX()), - hO2->GetXaxis()->GetBinLowEdge(1), hO2->GetXaxis()->GetBinUpEdge(hO2->GetNbinsX())); - - nAli = hAli->GetEntries(); - nO2 = hO2->GetEntries(); - - // Histograms - auto padH = canHis->cd(index + 1); - hAli->Rebin(rebin); - hO2->Rebin(rebin); - hAli->SetLineColor(1); - hAli->SetLineWidth(2); - hO2->SetLineColor(2); - hO2->SetLineWidth(1); - hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); - hAli->GetYaxis()->SetMaxDigits(3); - yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); - yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); - SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); - SetPad(padH, logScaleH); - hAli->Draw(); - hO2->Draw("same"); - TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); - legend->AddEntry(hAli, "Ali", "L"); - legend->AddEntry(hO2, "O^{2}", "L"); - legend->Draw(); - - // Ratio - if (doRatio) { - auto padR = canRat->cd(index + 1); - hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); - hRatio->Divide(hAli); - hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); - yMin = hRatio->GetMinimum(0); - yMax = hRatio->GetMaximum(); - SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); - SetPad(padR, logScaleR); - hRatio->Draw(); - } - } - canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); - canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); - if (doRatio) { - canRat->SaveAs(Form("comparison_ratios_%s.pdf", nameSpec.Data())); - canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); - } - delete canHis; - delete canRat; - } - return 0; -} - -Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) +Int_t Compare(TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) { TString pathListAli = "HFVertices/clistHFVertices"; TString labelParticle = ""; @@ -435,5 +274,5 @@ Int_t Compare(TString fileO2 = "AnalysisResults_O2.root", TString fileAli = "Ana if (options.Contains(" jets-substructure-mc ")) vecSpecVecSpec.push_back(std::make_tuple("jets-substructure-mc", vecHisJetSubstructureMC, 5, 3)); - return MakePlots(vecSpecVecSpec, fileO2, fileAli, pathListAli, doRatio); + return MakePlots(vecSpecVecSpec, pathFileO2, pathFileAli, pathListAli, doRatio); } diff --git a/exec/utils_validation.h b/exec/utils_validation.h index a6972fce..5127bad0 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -17,6 +17,8 @@ #include #include +#include "../exec/utils_plot.h" + // vectors of histogram specifications: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis using VecSpecHis = std::vector>; @@ -29,4 +31,166 @@ void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO vec.push_back(std::make_tuple(label, nameAli, nameO2, rebin, logH, logR, proj)); } +// Make validation plots. +Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString pathListAli = "list", bool doRatio = false) +{ + gStyle->SetOptStat(0); + gStyle->SetPalette(0); + gStyle->SetCanvasColor(0); + gStyle->SetFrameFillColor(0); + + TFile* fO2 = new TFile(pathFileO2.Data()); + if (fO2->IsZombie()) { + printf("Failed to open file %s\n", pathFileO2.Data()); + return 1; + } + TFile* fAli = new TFile(pathFileAli.Data()); + if (fAli->IsZombie()) { + printf("Failed to open file %s\n", pathFileAli.Data()); + return 1; + } + + TList* lAli = nullptr; + fAli->GetObject(pathListAli.Data(), lAli); + if (!lAli) { + printf("Failed to load list %s from %s\n", pathListAli.Data(), pathFileAli.Data()); + return 1; + } + + // Histogram plot vertical margins + Float_t marginHigh = 0.05; + Float_t marginLow = 0.05; + bool logScaleH = false; + // Ratio plot vertical margins + Float_t marginRHigh = 0.05; + Float_t marginRLow = 0.05; + bool logScaleR = false; + Float_t yMin, yMax; + Int_t nAli, nO2, rebin; + + TH1F* hAli = nullptr; + TH1D* hO2 = nullptr; + TH1F* hRatio = nullptr; + TString labelAxis = ""; + TString nameHisAli = ""; + TString nameHisO2 = ""; + TString projAx = ""; + TCanvas* canHis = nullptr; + TCanvas* canRat = nullptr; + + // loop over lists + for (const auto& specVecSpec : vecSpecVecSpec) { + auto nameSpec = std::get<0>(specVecSpec); // list name + auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. + int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads + int nPadsY = std::get<3>(specVecSpec); // number of vertical pads + Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); + if (nPadsX * nPadsY < vecSpec.size()) { + Printf("Not enough pads (%d)", nPadsX * nPadsY); + return 1; + } + + canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); + SetCanvas(canHis, nPadsX, nPadsY); + if (doRatio) { + canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); + SetCanvas(canRat, nPadsX, nPadsY); + } + + // loop over histograms + for (int index = 0; index < vecSpec.size(); index++) { + auto spec = vecSpec[index]; + labelAxis = std::get<0>(spec); + nameHisAli = std::get<1>(spec); + nameHisO2 = std::get<2>(spec); + rebin = std::get<3>(spec); + logScaleH = std::get<4>(spec); + logScaleR = std::get<5>(spec); + projAx = std::get<6>(spec); + + // Get AliPhysics histogram. + hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); + if (!hAli) { + printf("Failed to load %s from %s\n", nameHisAli.Data(), pathFileAli.Data()); + return 1; + } + + // Get O2 histogram. + auto oO2 = fO2->Get(nameHisO2.Data()); + if (!oO2) { + printf("Failed to load %s from %s\n", nameHisO2.Data(), pathFileO2.Data()); + return 1; + } + + if (oO2->InheritsFrom("TH3")) { + if (projAx == "x") { + hO2 = ((TH3D*)oO2)->ProjectionX(); + } else if (projAx == "y") { + hO2 = ((TH3D*)oO2)->ProjectionY(); + } + } else if (oO2->InheritsFrom("TH2")) { + if (projAx == "x") { + hO2 = ((TH2D*)oO2)->ProjectionX(); + } else if (projAx == "y") { + hO2 = ((TH2D*)oO2)->ProjectionY(); + } + } else { + hO2 = (TH1D*)oO2; + } + + Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", + index, nameHisAli.Data(), nameHisO2.Data(), + hAli->GetNbinsX(), hO2->GetNbinsX(), + hAli->GetXaxis()->GetBinLowEdge(1), hAli->GetXaxis()->GetBinUpEdge(hAli->GetNbinsX()), + hO2->GetXaxis()->GetBinLowEdge(1), hO2->GetXaxis()->GetBinUpEdge(hO2->GetNbinsX())); + + nAli = hAli->GetEntries(); + nO2 = hO2->GetEntries(); + + // Histograms + auto padH = canHis->cd(index + 1); + hAli->Rebin(rebin); + hO2->Rebin(rebin); + hAli->SetLineColor(1); + hAli->SetLineWidth(2); + hO2->SetLineColor(2); + hO2->SetLineWidth(1); + hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); + hAli->GetYaxis()->SetMaxDigits(3); + yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); + yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); + SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); + SetPad(padH, logScaleH); + hAli->Draw(); + hO2->Draw("same"); + TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); + legend->AddEntry(hAli, "Ali", "L"); + legend->AddEntry(hO2, "O^{2}", "L"); + legend->Draw(); + + // Ratio + if (doRatio) { + auto padR = canRat->cd(index + 1); + hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); + hRatio->Divide(hAli); + hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); + yMin = hRatio->GetMinimum(0); + yMax = hRatio->GetMaximum(); + SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); + SetPad(padR, logScaleR); + hRatio->Draw(); + } + } + canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); + canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); + if (doRatio) { + canRat->SaveAs(Form("comparison_ratios_%s.pdf", nameSpec.Data())); + canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); + } + delete canHis; + delete canRat; + } + return 0; +} + #endif // EXEC_UTILS_VALIDATION_H_ From fc3f0b6cf3579b738c31fd551a63b2f637e96ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 18:22:53 +0100 Subject: [PATCH 08/18] Fix casting --- exec/utils_validation.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exec/utils_validation.h b/exec/utils_validation.h index 5127bad0..6b019008 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -84,7 +84,7 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "Anal auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads int nPadsY = std::get<3>(specVecSpec); // number of vertical pads - Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); + Printf("\nProcessing histogram list: %s (%lu)", nameSpec.Data(), vecSpec.size()); if (nPadsX * nPadsY < vecSpec.size()) { Printf("Not enough pads (%d)", nPadsX * nPadsY); return 1; @@ -109,7 +109,7 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "Anal projAx = std::get<6>(spec); // Get AliPhysics histogram. - hAli = (TH1F*)lAli->FindObject(nameHisAli.Data()); + hAli = reinterpret_cast(lAli->FindObject(nameHisAli.Data())); if (!hAli) { printf("Failed to load %s from %s\n", nameHisAli.Data(), pathFileAli.Data()); return 1; @@ -124,18 +124,18 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "Anal if (oO2->InheritsFrom("TH3")) { if (projAx == "x") { - hO2 = ((TH3D*)oO2)->ProjectionX(); + hO2 = (reinterpret_cast(oO2))->ProjectionX(); } else if (projAx == "y") { - hO2 = ((TH3D*)oO2)->ProjectionY(); + hO2 = (reinterpret_cast(oO2))->ProjectionY(); } } else if (oO2->InheritsFrom("TH2")) { if (projAx == "x") { - hO2 = ((TH2D*)oO2)->ProjectionX(); + hO2 = (reinterpret_cast(oO2))->ProjectionX(); } else if (projAx == "y") { - hO2 = ((TH2D*)oO2)->ProjectionY(); + hO2 = (reinterpret_cast(oO2))->ProjectionY(); } } else { - hO2 = (TH1D*)oO2; + hO2 = reinterpret_cast(oO2); } Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", @@ -171,9 +171,9 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "Anal // Ratio if (doRatio) { auto padR = canRat->cd(index + 1); - hRatio = (TH1F*)hO2->Clone(Form("hRatio%d", index)); + hRatio = reinterpret_cast(hO2->Clone(Form("hRatio%d", index))); hRatio->Divide(hAli); - hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", (double)nO2 / (double)nAli, labelAxis.Data())); + hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", static_cast(nO2) / static_cast(nAli), labelAxis.Data())); yMin = hRatio->GetMinimum(0); yMax = hRatio->GetMaximum(); SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); From 85fa8fc401b1957b295632124a4f3d676cbe7a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 18:44:39 +0100 Subject: [PATCH 09/18] Break line --- exec/utils_validation.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exec/utils_validation.h b/exec/utils_validation.h index 6b019008..9b981030 100644 --- a/exec/utils_validation.h +++ b/exec/utils_validation.h @@ -32,7 +32,11 @@ void AddHistogram(VecSpecHis& vec, TString label, TString nameAli, TString nameO } // Make validation plots. -Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString pathListAli = "list", bool doRatio = false) +Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, + TString pathFileO2 = "AnalysisResults_O2.root", + TString pathFileAli = "AnalysisResults_ALI.root", + TString pathListAli = "list", + bool doRatio = false) { gStyle->SetOptStat(0); gStyle->SetPalette(0); From fa67ce7a3eb56fbe6d032b881ef8b306010f379d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 19:31:26 +0100 Subject: [PATCH 10/18] Rename headers --- codeHF/Compare.C | 2 +- codeHF/PlotEfficiency.C | 2 +- codeHF/PlotEfficiencyRecoStep.C | 2 +- codeHF/RunHFTaskLocal.C | 2 +- exec/convertAO2D.C | 2 +- exec/{utils_ali.h => utilitiesAli.h} | 0 exec/{utils_plot.h => utilitiesPlot.h} | 0 exec/{utils_validation.h => utilitiesValidation.h} | 2 +- 8 files changed, 6 insertions(+), 6 deletions(-) rename exec/{utils_ali.h => utilitiesAli.h} (100%) rename exec/{utils_plot.h => utilitiesPlot.h} (100%) rename exec/{utils_validation.h => utilitiesValidation.h} (99%) diff --git a/codeHF/Compare.C b/codeHF/Compare.C index 023aca9b..f5953338 100644 --- a/codeHF/Compare.C +++ b/codeHF/Compare.C @@ -11,7 +11,7 @@ // Comparison of AliPhysics and O2 histograms -#include "../exec/utils_validation.h" +#include "../exec/utilitiesValidation.h" Int_t Compare(TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) { diff --git a/codeHF/PlotEfficiency.C b/codeHF/PlotEfficiency.C index f1b873e3..86343f1b 100644 --- a/codeHF/PlotEfficiency.C +++ b/codeHF/PlotEfficiency.C @@ -11,7 +11,7 @@ // Plotting of reconstruction efficiency -#include "../exec/utils_plot.h" +#include "../exec/utilitiesPlot.h" Int_t PlotEfficiency(TString pathFile = "AnalysisResults.root", TString particles = "d0") { diff --git a/codeHF/PlotEfficiencyRecoStep.C b/codeHF/PlotEfficiencyRecoStep.C index 0d803945..dd279634 100644 --- a/codeHF/PlotEfficiencyRecoStep.C +++ b/codeHF/PlotEfficiencyRecoStep.C @@ -21,7 +21,7 @@ // .L PlotEfficiencyRecoStep.C // PlotEfficiencyRecoStep("InputName.root","particlename",true); -#include "../exec/utils_plot.h" +#include "../exec/utilitiesPlot.h" void SetProperAxisRange(TH1F** histo, int NIteration, float marginHigh, float marginLow, bool logScaleH); diff --git a/codeHF/RunHFTaskLocal.C b/codeHF/RunHFTaskLocal.C index a80d6aa1..c15a5156 100644 --- a/codeHF/RunHFTaskLocal.C +++ b/codeHF/RunHFTaskLocal.C @@ -11,7 +11,7 @@ // -#include "../exec/utils_ali.h" +#include "../exec/utilitiesAli.h" Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", TString jsonfilename = "dpl-config_std.json", diff --git a/exec/convertAO2D.C b/exec/convertAO2D.C index 86612374..e7b602d3 100644 --- a/exec/convertAO2D.C +++ b/exec/convertAO2D.C @@ -19,7 +19,7 @@ R__ADD_INCLUDE_PATH($ALICE_PHYSICS) #include #include -#include "utils_ali.h" +#include "utilitiesAli.h" Long64_t convertAO2D(TString listoffiles, bool isMC = 1, bool useAliEvCuts = false, bool isESD = 1, int nmaxevents = -1) { diff --git a/exec/utils_ali.h b/exec/utilitiesAli.h similarity index 100% rename from exec/utils_ali.h rename to exec/utilitiesAli.h diff --git a/exec/utils_plot.h b/exec/utilitiesPlot.h similarity index 100% rename from exec/utils_plot.h rename to exec/utilitiesPlot.h diff --git a/exec/utils_validation.h b/exec/utilitiesValidation.h similarity index 99% rename from exec/utils_validation.h rename to exec/utilitiesValidation.h index 9b981030..6ae65962 100644 --- a/exec/utils_validation.h +++ b/exec/utilitiesValidation.h @@ -17,7 +17,7 @@ #include #include -#include "../exec/utils_plot.h" +#include "utilitiesPlot.h" // vectors of histogram specifications: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis using VecSpecHis = std::vector>; From 18c5f1140a6bcf80e38e11b2a0168bdc74089e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 15 Nov 2023 19:38:39 +0100 Subject: [PATCH 11/18] Fix header guards --- exec/utilitiesAli.h | 6 +++--- exec/utilitiesPlot.h | 6 +++--- exec/utilitiesValidation.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/exec/utilitiesAli.h b/exec/utilitiesAli.h index e2efbe06..c2e4e81f 100644 --- a/exec/utilitiesAli.h +++ b/exec/utilitiesAli.h @@ -11,8 +11,8 @@ // AliPhysics utilities -#ifndef EXEC_UTILS_ALI_H_ -#define EXEC_UTILS_ALI_H_ +#ifndef EXEC_UTILITIESALI_H_ +#define EXEC_UTILITIESALI_H_ TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfiles = -1) { @@ -50,4 +50,4 @@ TChain* CreateLocalChain(const char* txtfile, const char* type = "esd", int nfil return chain; } -#endif // EXEC_UTILS_ALI_H_ +#endif // EXEC_UTILITIESALI_H_ diff --git a/exec/utilitiesPlot.h b/exec/utilitiesPlot.h index c67e89d9..91f8fdc3 100644 --- a/exec/utilitiesPlot.h +++ b/exec/utilitiesPlot.h @@ -11,8 +11,8 @@ // Plotting utilities -#ifndef EXEC_UTILS_PLOT_H_ -#define EXEC_UTILS_PLOT_H_ +#ifndef EXEC_UTILITIESPLOT_H_ +#define EXEC_UTILITIESPLOT_H_ void SetCanvas(TCanvas* can, int nPadsX, int nPadsY) { @@ -58,4 +58,4 @@ void SetHistogramStyle(TH1* his, Int_t colour = 1, Int_t markerStyle = 1, Float_ his->SetMarkerSize(markerSize); } -#endif // EXEC_UTILS_PLOT_H_ +#endif // EXEC_UTILITIESPLOT_H_ diff --git a/exec/utilitiesValidation.h b/exec/utilitiesValidation.h index 6ae65962..dbc4be23 100644 --- a/exec/utilitiesValidation.h +++ b/exec/utilitiesValidation.h @@ -11,8 +11,8 @@ // Validation utilities -#ifndef EXEC_UTILS_VALIDATION_H_ -#define EXEC_UTILS_VALIDATION_H_ +#ifndef EXEC_UTILITIESVALIDATION_H_ +#define EXEC_UTILITIESVALIDATION_H_ #include #include @@ -197,4 +197,4 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, return 0; } -#endif // EXEC_UTILS_VALIDATION_H_ +#endif // EXEC_UTILITIESVALIDATION_H_ From de0b3bae7c37134cf89a525b7cdd197f0c6d7559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Fri, 17 Nov 2023 18:31:31 +0100 Subject: [PATCH 12/18] Improve logging --- codeHF/PlotEfficiency.C | 8 ++++---- exec/utilitiesValidation.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codeHF/PlotEfficiency.C b/codeHF/PlotEfficiency.C index 86343f1b..dfdda396 100644 --- a/codeHF/PlotEfficiency.C +++ b/codeHF/PlotEfficiency.C @@ -99,12 +99,12 @@ Int_t PlotEfficiency(TString pathFile = "AnalysisResults.root", TString particle bool okPrompt = true; TH1F* hPtRecPrompt = (TH1F*)file->Get(nameHistRec.Data()); if (!hPtRecPrompt) { - Printf("Warning: Failed to load %s from %s", nameHistRec.Data(), pathFile.Data()); + Warning("PlotEfficiency", "Failed to load %s from %s", nameHistRec.Data(), pathFile.Data()); okPrompt = false; } TH1F* hPtGenPrompt = (TH1F*)file->Get(nameHistgen.Data()); if (!hPtGenPrompt) { - Printf("Warning: Failed to load %s from %s", nameHistgen.Data(), pathFile.Data()); + Warning("PlotEfficiency", "Failed to load %s from %s", nameHistgen.Data(), pathFile.Data()); okPrompt = false; } @@ -120,12 +120,12 @@ Int_t PlotEfficiency(TString pathFile = "AnalysisResults.root", TString particle bool okNonPrompt = true; TH1F* hPtRecNonPrompt = (TH1F*)file->Get(nameHistRec.Data()); if (!hPtRecNonPrompt) { - Printf("Warning: Failed to load %s from %s", nameHistRec.Data(), pathFile.Data()); + Warning("PlotEfficiency", "Failed to load %s from %s", nameHistRec.Data(), pathFile.Data()); okNonPrompt = false; } TH1F* hPtGenNonPrompt = (TH1F*)file->Get(nameHistgen.Data()); if (!hPtGenNonPrompt) { - Printf("Warning: Failed to load %s from %s", nameHistgen.Data(), pathFile.Data()); + Warning("PlotEfficiency", "Failed to load %s from %s", nameHistgen.Data(), pathFile.Data()); okNonPrompt = false; } diff --git a/exec/utilitiesValidation.h b/exec/utilitiesValidation.h index dbc4be23..dba483ea 100644 --- a/exec/utilitiesValidation.h +++ b/exec/utilitiesValidation.h @@ -45,19 +45,19 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, TFile* fO2 = new TFile(pathFileO2.Data()); if (fO2->IsZombie()) { - printf("Failed to open file %s\n", pathFileO2.Data()); + Fatal("MakePlots", "Failed to open file %s\n", pathFileO2.Data()); return 1; } TFile* fAli = new TFile(pathFileAli.Data()); if (fAli->IsZombie()) { - printf("Failed to open file %s\n", pathFileAli.Data()); + Fatal("MakePlots", "Failed to open file %s\n", pathFileAli.Data()); return 1; } TList* lAli = nullptr; fAli->GetObject(pathListAli.Data(), lAli); if (!lAli) { - printf("Failed to load list %s from %s\n", pathListAli.Data(), pathFileAli.Data()); + Fatal("MakePlots", "Failed to load list %s from %s\n", pathListAli.Data(), pathFileAli.Data()); return 1; } @@ -115,14 +115,14 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, // Get AliPhysics histogram. hAli = reinterpret_cast(lAli->FindObject(nameHisAli.Data())); if (!hAli) { - printf("Failed to load %s from %s\n", nameHisAli.Data(), pathFileAli.Data()); + Fatal("MakePlots", "Failed to load %s from %s\n", nameHisAli.Data(), pathFileAli.Data()); return 1; } // Get O2 histogram. auto oO2 = fO2->Get(nameHisO2.Data()); if (!oO2) { - printf("Failed to load %s from %s\n", nameHisO2.Data(), pathFileO2.Data()); + Fatal("MakePlots", "Failed to load %s from %s\n", nameHisO2.Data(), pathFileO2.Data()); return 1; } From 953da086a68f98b9457bba61a381df7341354dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 02:14:56 +0100 Subject: [PATCH 13/18] Improve legends in validation plots --- exec/utilitiesValidation.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/exec/utilitiesValidation.h b/exec/utilitiesValidation.h index dba483ea..538099c5 100644 --- a/exec/utilitiesValidation.h +++ b/exec/utilitiesValidation.h @@ -159,7 +159,7 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, hAli->SetLineWidth(2); hO2->SetLineColor(2); hO2->SetLineWidth(1); - hAli->SetTitle(Form("Entries: Ali: %d, O^{2}: %d;%s;Entries", nAli, nO2, labelAxis.Data())); + hAli->SetTitle(Form(";%s;Entries", labelAxis.Data())); hAli->GetYaxis()->SetMaxDigits(3); yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); @@ -167,9 +167,11 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, SetPad(padH, logScaleH); hAli->Draw(); hO2->Draw("same"); - TLegend* legend = new TLegend(0.8, 0.72, 1., 0.92); - legend->AddEntry(hAli, "Ali", "L"); - legend->AddEntry(hO2, "O^{2}", "L"); + TLegend* legend = new TLegend(0.2, 0.92, 0.82, 1.0); + legend->SetNColumns(2); + legend->SetBorderSize(0); + legend->AddEntry(hAli, Form("Ali: %d", nAli), "L"); + legend->AddEntry(hO2, Form("O^{2}: %d", nO2), "L"); legend->Draw(); // Ratio From 5f6de12fa6a8e51429eb85552755bd9393a860cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 02:15:45 +0100 Subject: [PATCH 14/18] Fix JE validation plots and factor out code --- codeJE/Compare.C | 218 +++++------------------------------------------ 1 file changed, 23 insertions(+), 195 deletions(-) diff --git a/codeJE/Compare.C b/codeJE/Compare.C index f681a132..90c43a6d 100644 --- a/codeJE/Compare.C +++ b/codeJE/Compare.C @@ -1,214 +1,42 @@ -// Comparison of AliPhysics and O2 histograms - -#include "utils_plot.h" +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. -// vectors of histogram specifications -using VecSpecHis = std::vector>; +// Comparison of AliPhysics and O2 histograms -// Add histogram specification in the vector. -void AddHistogram(VecSpecHis& vec, TString label, TString nameRun2, TString nameRun3, int rebin, bool logH, bool logR, TString proj = "x") -{ - vec.push_back(std::make_tuple(label, nameRun2, nameRun3, rebin, logH, logR, proj)); -} +#include "../exec/utilitiesValidation.h" -Int_t Compare(TString filerun3 = "AnalysisResults_O2.root", TString filerun2 = "AnalysisResults_ALI.root", TString options = "jets", bool doRatio = true) +Int_t Compare(TString pathFileO2 = "AnalysisResults_O2.root", TString pathFileAli = "AnalysisResults_ALI.root", TString options = "", bool doRatio = false) { - gStyle->SetOptStat(0); - gStyle->SetPalette(0); - gStyle->SetCanvasColor(0); - gStyle->SetFrameFillColor(0); - - TFile* fRun3 = new TFile(filerun3.Data()); - if (fRun3->IsZombie()) { - printf("Failed to open file %s\n", filerun3.Data()); - return 1; - } - TFile* fRun2 = new TFile(filerun2.Data()); - if (fRun2->IsZombie()) { - printf("Failed to open file %s\n", filerun2.Data()); - return 1; - } - - TString pathListRun2 = Form("ChJetSpectraAliAnalysisTaskEmcalJetValidation/AliAnalysisTaskEmcalJetValidation"); // - TList* lRun2 = nullptr; - fRun2->GetObject(pathListRun2.Data(), lRun2); - if (!lRun2) { - printf("Failed to load list %s from %s\n", pathListRun2.Data(), filerun2.Data()); - return 1; - } + TString pathListAli = "ChJetSpectraAliAnalysisTaskEmcalJetValidation/AliAnalysisTaskEmcalJetValidation"; // Histogram specification: axis label, AliPhysics name, O2Physics path/name, rebin, log scale histogram, log scale ratio, projection axis VecSpecHis vecHisEvents; - VecSpecHis vecHisJets; //X axis , Hist Name Run2, Hist Name in Run3, rebin, logScaleH , logScaleR - AddHistogram(vecHisJets, "#it{p}_{T,ch jet} (GeV/#it{c}", "jetPt", "jet-validation-track-collision-qa/jetPt", 1, 1, 0); // - AddHistogram(vecHisJets, "#varphi_{jet}", "jetPhi", "jet-validation-track-collision-qa/jetPhi", 1, 0, 0); - AddHistogram(vecHisJets, "#eta_{jet}", "jetEta", "jet-validation-track-collision-qa/jetEta", 1, 0, 0); - AddHistogram(vecHisJets, "#it{p}_{T,track} (GeV/#it{c}", "jetTrackPt", "jet-validation-track-collision-qa/selectedTrackPt", 1, 1, 0); // - AddHistogram(vecHisJets, "#varphi_{track}", "jetTrackPhi", "jet-validation-track-collision-qa/selectedTrackPhi", 1, 0, 0); - AddHistogram(vecHisJets, "#eta_{track}", "jetTrackEta", "jet-validation-track-collision-qa/selectedTrackEta", 1, 0, 0); + VecSpecHis vecHisJets; + AddHistogram(vecHisJets, "#it{p}_{T, ch jet} (GeV/#it{c})", "jetPt", "jet-validation-track-collision-qa/jetPt", 1, 1, 0); + AddHistogram(vecHisJets, "#it{#varphi}_{jet}", "jetPhi", "jet-validation-track-collision-qa/jetPhi", 1, 0, 0); + AddHistogram(vecHisJets, "#it{#eta}_{jet}", "jetEta", "jet-validation-track-collision-qa/jetEta", 1, 0, 0); + AddHistogram(vecHisJets, "#it{p}_{T, track} (GeV/#it{c})", "jetTrackPt", "jet-validation-track-collision-qa/selectedTrackPt", 1, 1, 0); + AddHistogram(vecHisJets, "#it{#varphi}_{track}", "jetTrackPhi", "jet-validation-track-collision-qa/selectedTrackPhi", 1, 0, 0); + AddHistogram(vecHisJets, "#it{#eta}_{track}", "jetTrackEta", "jet-validation-track-collision-qa/selectedTrackEta", 1, 0, 0); // vector of specifications of vectors: name, VecSpecHis, pads X, pads Y - std::vector> vecSpecVecSpec; + VecSpecVecSpec vecSpecVecSpec; // Add vector specifications in the vector. // if (options.Contains(" events ")) // vecSpecVecSpec.push_back(std::make_tuple("events", vecHisEvents, 4, 2)); if (options.Contains("jets")) vecSpecVecSpec.push_back(std::make_tuple("jets", vecHisJets, 3, 2)); - // if (options.Contains(" skim ")) - // vecSpecVecSpec.push_back(std::make_tuple("skim", vecHisSkim, 5, 3)); - - // Histogram plot vertical margins - Float_t marginHigh = 0.05; - Float_t marginLow = 0.05; - bool logScaleH = false; - // Ratio plot vertical margins - Float_t marginRHigh = 0.05; - Float_t marginRLow = 0.05; - bool logScaleR = false; - Float_t yMin, yMax; - Int_t nRun2, nRun3, rebin; - - TH1F* hRun2 = nullptr; - TH1D* hRun3 = nullptr; - TH1F* hRatio = nullptr; - TString labelAxis = ""; - TString nameHisRun2 = ""; - TString nameHisRun3 = ""; - TString projAx = ""; - TCanvas* canHis = nullptr; - TCanvas* canRat = nullptr; - - // loop over lists - for (const auto& specVecSpec : vecSpecVecSpec) { - auto nameSpec = std::get<0>(specVecSpec); // list name - auto vecSpec = std::get<1>(specVecSpec); // list of histogram specs. - int nPadsX = std::get<2>(specVecSpec); // number of horizontal pads - int nPadsY = std::get<3>(specVecSpec); // number of vertical pads - Printf("\nProcessing histogram list: %s (%d)", nameSpec.Data(), (int)vecSpec.size()); - if (nPadsX * nPadsY < vecSpec.size()) { - Printf("Not enough pads (%d)", nPadsX * nPadsY); - return 1; - } - - canHis = new TCanvas(Form("canHis_%s", nameSpec.Data()), Form("Histos_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canHis, nPadsX, nPadsY); - if (doRatio) { - canRat = new TCanvas(Form("canRat_%s", nameSpec.Data()), Form("Ratios_%s", nameSpec.Data()), 3000, 1600); - SetCanvas(canRat, nPadsX, nPadsY); - } - - // loop over histograms - for (int index = 0; index < vecSpec.size(); index++) { - auto spec = vecSpec[index]; - labelAxis = std::get<0>(spec); - nameHisRun2 = std::get<1>(spec); - nameHisRun3 = std::get<2>(spec); - rebin = std::get<3>(spec); - logScaleH = std::get<4>(spec); - logScaleR = std::get<5>(spec); - projAx = std::get<6>(spec); - - // Get AliPhysics histogram. - hRun2 = (TH1F*)lRun2->FindObject(nameHisRun2.Data()); - if (!hRun2) { - printf("Failed to load %s from %s\n", nameHisRun2.Data(), filerun2.Data()); - return 1; - } - - // Get O2 histogram. - auto oRun3 = fRun3->Get(nameHisRun3.Data()); - if (!oRun3) { - printf("Failed to load %s from %s\n", nameHisRun3.Data(), filerun3.Data()); - return 1; - } - - if (oRun3->InheritsFrom("TH3")) { - if (projAx == "x") { - hRun3 = ((TH3D*)oRun3)->ProjectionX(); - } else if (projAx == "y") { - hRun3 = ((TH3D*)oRun3)->ProjectionY(); - } - } else if (oRun3->InheritsFrom("TH2")) { - if (projAx == "x") { - hRun3 = ((TH2D*)oRun3)->ProjectionX(); - } else if (projAx == "y") { - hRun3 = ((TH2D*)oRun3)->ProjectionY(); - } - } else { - hRun3 = (TH1D*)oRun3; - } - - Printf("%d (%s, %s): bins: %d, %d, ranges: %g-%g, %g-%g", - index, nameHisRun2.Data(), nameHisRun3.Data(), - hRun2->GetNbinsX(), hRun3->GetNbinsX(), - hRun2->GetXaxis()->GetBinLowEdge(1), hRun2->GetXaxis()->GetBinUpEdge(hRun2->GetNbinsX()), - hRun3->GetXaxis()->GetBinLowEdge(1), hRun3->GetXaxis()->GetBinUpEdge(hRun3->GetNbinsX())); - - nRun2 = hRun2->GetEntries(); - nRun3 = hRun3->GetEntries(); - // Histograms - auto padH = canHis->cd(index + 1); - - Printf("histo name: %s", hRun2->GetName()); - hRun2->Rebin(rebin); - hRun3->Rebin(rebin); - hRun2->SetLineColor(1); - hRun2->SetLineWidth(2); - hRun2->SetMarkerStyle(22); - hRun2->SetMarkerColor(1); - hRun3->SetLineColor(2); - hRun3->SetLineWidth(2); - hRun3->SetMarkerStyle(22); - hRun3->SetMarkerColor(2); - hRun2->SetTitle(" "); - hRun2->GetYaxis()->SetTitle("number of entries"); - hRun2->GetYaxis()->SetMaxDigits(3); - yMin = TMath::Min(hRun3->GetMinimum(0), hRun2->GetMinimum(0)); - yMax = TMath::Max(hRun3->GetMaximum(), hRun2->GetMaximum()); - SetHistogram(hRun2, yMin, yMax, marginLow, marginHigh, logScaleH); - SetPad(padH, logScaleH); - hRun2->Draw(""); - hRun3->Draw("Esame"); - - if (std::string(hRun2->GetName()) == "jetPt" || std::string(hRun2->GetName()) == "jetTrackPt") { - TLegend* legend = new TLegend(0.2, 0.84, 0.82, 0.92); - legend->SetNColumns(2); - legend->AddEntry(hRun2, Form("AliPhysics: %d", nRun2), "L"); - legend->AddEntry(hRun3, Form("O2Physics: %d", nRun3), "L"); - legend->Draw(); - } else { - TLegend* legend = new TLegend(0.2, 0.92, 0.82, 1.0); - legend->SetNColumns(2); - legend->SetBorderSize(0); - legend->AddEntry(hRun2, Form("AliPhysics: %d", nRun2), "L"); - legend->AddEntry(hRun3, Form("O2Physics: %d", nRun3), "L"); - legend->Draw(); - } - - // Ratio - if (doRatio) { - auto padR = canRat->cd(index + 1); - hRatio = (TH1F*)hRun3->Clone(Form("hRatio%d", index)); - hRatio->Divide(hRun2); - hRatio->SetTitle(""); - hRatio->GetYaxis()->SetTitle("O2Physics/AliPhysics"); - yMin = hRatio->GetMinimum(0) * 0.3; - yMax = hRatio->GetMaximum() * 1.3; - SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); - SetPad(padR, logScaleR); - hRatio->Draw(); - } - } - canHis->SaveAs(Form("comparison_histos_%s.png", nameSpec.Data())); - if (doRatio) { - canRat->SaveAs(Form("comparison_ratios_%s.png", nameSpec.Data())); - } - // delete canHis; - delete canRat; - } - return 0; + return MakePlots(vecSpecVecSpec, pathFileO2, pathFileAli, pathListAli, doRatio); } From b7839106ee73371e1ea91aea669635e53db626bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 02:17:44 +0100 Subject: [PATCH 15/18] Remove link to utils_plot.h --- codeJE/utils_plot.h | 1 - 1 file changed, 1 deletion(-) delete mode 120000 codeJE/utils_plot.h diff --git a/codeJE/utils_plot.h b/codeJE/utils_plot.h deleted file mode 120000 index 04a6f997..00000000 --- a/codeJE/utils_plot.h +++ /dev/null @@ -1 +0,0 @@ -../codeHF/utils_plot.h \ No newline at end of file From 6bae2cecee2e0c4a880bbaab70be43250e90f9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 13:04:11 +0100 Subject: [PATCH 16/18] Improve y-range calculation and plotting, add protections --- exec/utilitiesPlot.h | 65 ++++++++++++++++++++++++++++++++++++++ exec/utilitiesValidation.h | 21 ++++++------ 2 files changed, 77 insertions(+), 9 deletions(-) diff --git a/exec/utilitiesPlot.h b/exec/utilitiesPlot.h index 91f8fdc3..250362ed 100644 --- a/exec/utilitiesPlot.h +++ b/exec/utilitiesPlot.h @@ -14,13 +14,23 @@ #ifndef EXEC_UTILITIESPLOT_H_ #define EXEC_UTILITIESPLOT_H_ +#include // std::min, std::max + void SetCanvas(TCanvas* can, int nPadsX, int nPadsY) { + if (!can) { + Fatal("SetCanvas", "Invalid canvas"); + return; + } can->Divide(nPadsX, nPadsY, 0.005, 0.005); } void SetPad(TVirtualPad* pad, bool logScale) { + if (!pad) { + Fatal("SetPad", "Invalid pad"); + return; + } pad->SetBottomMargin(0.11); pad->SetLeftMargin(0.1); pad->SetTopMargin(0.08); @@ -30,8 +40,59 @@ void SetPad(TVirtualPad* pad, bool logScale) } } +/// @brief Get maximum and minimum of a histograms with non-negative bin contents and errors +/// @param his histogram +/// @param yMin variable to set minimum +/// @param yMax variable to set maximum +/// @param onlyPositive make sure that yMin, yMax are positive +/// @param includeErrors consider heights of error bars +void GetYRange(TH1* his, Float_t& yMin, Float_t& yMax, bool onlyPositive = true, bool includeErrors = true) +{ + if (!his) { + Fatal("GetYRange", "Invalid histogram"); + return; + } + yMin = his->GetMinimum(0); + yMax = his->GetMaximum(); + if (onlyPositive) { + if (yMin <= 0.) { + yMin = 1.; + } + if (yMax <= 0.) { + yMax = 1.; + } + } + if (includeErrors) { + Float_t cont, err, yLow; + for (Int_t i = 0; i < his->GetNbinsX(); i++) { + cont = his->GetBinContent(i + 1); + if (cont <= 0.) { + continue; + } + err = his->GetBinError(i + 1); + yLow = cont - err; + if (onlyPositive && yLow <= 0.) { + yLow = cont; + } + yMin = std::min(yMin, yLow); + yMax = std::max(yMax, cont + err); + } + } +} + +/// @brief Set plotting properties of a histogram +/// @param his histogram +/// @param yMin minimum y value to display +/// @param yMax maximum y value to display +/// @param marginLow margin to keep below yMin (expressed as a fraction of the full y-axis plotting range) +/// @param marginHigh margin to keep above yMax (expressed as a fraction of the full y-axis plotting range) +/// @note The full y-axis plotting range is calculated from yMin, yMax, marginLow, marginHigh, logScale. void SetHistogram(TH1* his, Float_t yMin, Float_t yMax, Float_t marginLow, Float_t marginHigh, bool& logScale) { + if (!his) { + Fatal("SetHistogram", "Invalid histogram"); + return; + } Float_t textsize = 0.05; his->GetYaxis()->SetTitleSize(textsize); his->GetXaxis()->SetTitleSize(textsize); @@ -51,6 +112,10 @@ void SetHistogram(TH1* his, Float_t yMin, Float_t yMax, Float_t marginLow, Float void SetHistogramStyle(TH1* his, Int_t colour = 1, Int_t markerStyle = 1, Float_t markerSize = 1, Float_t lineWidth = 1) { + if (!his) { + Fatal("SetHistogramStyle", "Invalid histogram"); + return; + } his->SetLineColor(colour); his->SetLineWidth(lineWidth); his->SetMarkerColor(colour); diff --git a/exec/utilitiesValidation.h b/exec/utilitiesValidation.h index 538099c5..3da415e4 100644 --- a/exec/utilitiesValidation.h +++ b/exec/utilitiesValidation.h @@ -14,8 +14,9 @@ #ifndef EXEC_UTILITIESVALIDATION_H_ #define EXEC_UTILITIESVALIDATION_H_ -#include -#include +#include // std::min, std::max +#include // std::tuple, std::make_tuple +#include // std::vector #include "utilitiesPlot.h" @@ -161,12 +162,15 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, hO2->SetLineWidth(1); hAli->SetTitle(Form(";%s;Entries", labelAxis.Data())); hAli->GetYaxis()->SetMaxDigits(3); - yMin = TMath::Min(hO2->GetMinimum(0), hAli->GetMinimum(0)); - yMax = TMath::Max(hO2->GetMaximum(), hAli->GetMaximum()); + Float_t yMinO2, yMaxO2; + GetYRange(hO2, yMinO2, yMaxO2, logScaleH, false); + GetYRange(hAli, yMin, yMax, logScaleH, false); + yMin = std::min(yMinO2, yMin); + yMax = std::max(yMaxO2, yMax); SetHistogram(hAli, yMin, yMax, marginLow, marginHigh, logScaleH); SetPad(padH, logScaleH); - hAli->Draw(); - hO2->Draw("same"); + hAli->Draw("hist"); + hO2->Draw("hist same"); TLegend* legend = new TLegend(0.2, 0.92, 0.82, 1.0); legend->SetNColumns(2); legend->SetBorderSize(0); @@ -180,11 +184,10 @@ Int_t MakePlots(const VecSpecVecSpec& vecSpecVecSpec, hRatio = reinterpret_cast(hO2->Clone(Form("hRatio%d", index))); hRatio->Divide(hAli); hRatio->SetTitle(Form("Entries ratio: %g;%s;O^{2}/Ali", static_cast(nO2) / static_cast(nAli), labelAxis.Data())); - yMin = hRatio->GetMinimum(0); - yMax = hRatio->GetMaximum(); + GetYRange(hRatio, yMin, yMax, logScaleR, false); SetHistogram(hRatio, yMin, yMax, marginRLow, marginRHigh, logScaleR); SetPad(padR, logScaleR); - hRatio->Draw(); + hRatio->Draw("hist"); } } canHis->SaveAs(Form("comparison_histos_%s.pdf", nameSpec.Data())); From 2cc330d3f2356d7139110a8f525c2b2ad4396072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 13:49:21 +0100 Subject: [PATCH 17/18] Improve AliPhysics task macros --- codeHF/RunHFTaskLocal.C | 4 +--- codeJE/RunJetTaskLocal.C | 48 ++++++++++++---------------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/codeHF/RunHFTaskLocal.C b/codeHF/RunHFTaskLocal.C index c15a5156..9a23cba6 100644 --- a/codeHF/RunHFTaskLocal.C +++ b/codeHF/RunHFTaskLocal.C @@ -9,8 +9,6 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -// - #include "../exec/utilitiesAli.h" Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", @@ -39,7 +37,7 @@ Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", TChain* chainESD = CreateLocalChain(txtfile.Data()); if (!chainESD) { - Error("CreateLocalChain", "Failed to create chain from file %s", txtfile.Data()); + Fatal("CreateLocalChain", "Failed to create chain from file %s", txtfile.Data()); return -1; } diff --git a/codeJE/RunJetTaskLocal.C b/codeJE/RunJetTaskLocal.C index 02388459..3f6210c6 100644 --- a/codeJE/RunJetTaskLocal.C +++ b/codeJE/RunJetTaskLocal.C @@ -1,3 +1,16 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +#include "../exec/utilitiesAli.h" + #ifdef __CLING__ // Tell ROOT where to find AliRoot headers R__ADD_INCLUDE_PATH($ALICE_ROOT) @@ -8,8 +21,6 @@ R__ADD_INCLUDE_PATH($ALICE_PHYSICS) #endif -TChain* CreateLocalChain(const char* txtfile); - Long64_t RunJetTaskLocal(TString txtfile = "./list_ali.txt", TString jsonfilename = "dpl-config_std.json", Bool_t isMC = kFALSE, @@ -33,7 +44,7 @@ Long64_t RunJetTaskLocal(TString txtfile = "./list_ali.txt", TChain* chainESD = CreateLocalChain(txtfile.Data()); if (!chainESD) { - Error("CreateLocalChain", "Failed to create chain from file %s", txtfile.Data()); + Fatal("CreateLocalChain", "Failed to create chain from file %s", txtfile.Data()); return -1; } @@ -67,34 +78,3 @@ Long64_t RunJetTaskLocal(TString txtfile = "./list_ali.txt", mgr->PrintStatus(); return mgr->StartAnalysis("local", chainESD); }; - -TChain* CreateLocalChain(const char* txtfile) -{ - // Open the file - ifstream in; - in.open(txtfile); - Int_t count = 0; - // Read the input list of files and add them to the chain - TString line; - TChain* chain = new TChain("esdTree"); - while (in.good()) { - in >> line; - if (line.IsNull() || line.BeginsWith("#")) - continue; - TString esdFile(line); - TFile* file = TFile::Open(esdFile); - if (file && !file->IsZombie()) { - chain->Add(esdFile); - file->Close(); - } else { - Error("CreateLocalChain", "Skipping un-openable file: %s", esdFile.Data()); - } - } - in.close(); - if (!chain->GetListOfFiles()->GetEntries()) { - Error("CreateLocalChain", "No file from %s could be opened", txtfile); - delete chain; - return nullptr; - } - return chain; -} From cc1d8ef05092d64d460d802e8f43f290a3c6dc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= Date: Wed, 22 Nov 2023 13:54:08 +0100 Subject: [PATCH 18/18] Add documentation comments in AliPhysics macros --- codeHF/RunHFTaskLocal.C | 2 ++ codeJE/RunJetTaskLocal.C | 2 ++ 2 files changed, 4 insertions(+) diff --git a/codeHF/RunHFTaskLocal.C b/codeHF/RunHFTaskLocal.C index 9a23cba6..49bbfb33 100644 --- a/codeHF/RunHFTaskLocal.C +++ b/codeHF/RunHFTaskLocal.C @@ -9,6 +9,8 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +// Macro to run the HF AliPhysics task that produces validation histograms + #include "../exec/utilitiesAli.h" Long64_t RunHFTaskLocal(TString txtfile = "./list_ali.txt", diff --git a/codeJE/RunJetTaskLocal.C b/codeJE/RunJetTaskLocal.C index 3f6210c6..fe1e5588 100644 --- a/codeJE/RunJetTaskLocal.C +++ b/codeJE/RunJetTaskLocal.C @@ -9,6 +9,8 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. +// Macro to run the JE AliPhysics task that produces validation histograms + #include "../exec/utilitiesAli.h" #ifdef __CLING__