diff --git a/Modules/Common/include/Common/TH1Ratio.h b/Modules/Common/include/Common/TH1Ratio.h index bd869d4d50..d6b0d578b5 100644 --- a/Modules/Common/include/Common/TH1Ratio.h +++ b/Modules/Common/include/Common/TH1Ratio.h @@ -32,6 +32,8 @@ class TH1Ratio : public T, public o2::mergers::MergeInterface TH1Ratio(); TH1Ratio(TH1Ratio const& copymerge); TH1Ratio(const char* name, const char* title, int nbinsx, double xmin, double xmax, bool uniformScaling = false); + TH1Ratio(const char* name, const char* title, int nbinsx, float* xbins, bool uniformScaling = false); + TH1Ratio(const char* name, const char* title, int nbinsx, double* xbins, bool uniformScaling = false); TH1Ratio(const char* name, const char* title, bool uniformScaling = false); ~TH1Ratio(); diff --git a/Modules/Common/include/Common/TH1Ratio.inl b/Modules/Common/include/Common/TH1Ratio.inl index 13dff12960..1ce1605aab 100644 --- a/Modules/Common/include/Common/TH1Ratio.inl +++ b/Modules/Common/include/Common/TH1Ratio.inl @@ -105,6 +105,56 @@ TH1Ratio::TH1Ratio(const char* name, const char* title, int nbinsx, double xm init(); } +template +TH1Ratio::TH1Ratio(const char* name, const char* title, int nbinsx, float* xbins, bool uniformScaling) + : T(name, title, nbinsx, xbins), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xbins); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xbins); + } + } + + init(); +} + +template +TH1Ratio::TH1Ratio(const char* name, const char* title, int nbinsx, double* xbins, bool uniformScaling) + : T(name, title, nbinsx, xbins), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xbins); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xbins); + } + } + + init(); +} + template TH1Ratio::TH1Ratio(const char* name, const char* title, bool uniformScaling) : T(name, title, 10, 0, 10), @@ -168,7 +218,7 @@ void TH1Ratio::update() } T::Reset(); - T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax()); + mHistoNum->GetXaxis()->Copy(*T::GetXaxis()); T::SetBinsLength(); // Copy bin labels between histograms. diff --git a/Modules/Common/include/Common/TH2Ratio.h b/Modules/Common/include/Common/TH2Ratio.h index b40fe58ad4..53159b160c 100644 --- a/Modules/Common/include/Common/TH2Ratio.h +++ b/Modules/Common/include/Common/TH2Ratio.h @@ -32,6 +32,10 @@ class TH2Ratio : public T, public o2::mergers::MergeInterface TH2Ratio(); TH2Ratio(TH2Ratio const& copymerge); TH2Ratio(const char* name, const char* title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, bool uniformScaling = false); + TH2Ratio(const char* name, const char* title, int nbinsx, const float *xbins, int nbinsy, const float *ybins, bool uniformScaling = false); + TH2Ratio(const char* name, const char* title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, bool uniformScaling = false); + TH2Ratio(const char* name, const char* title, int nbinsx, const double *xbins, int nbinsy, double ymin, double ymax, bool uniformScaling = false); + TH2Ratio(const char* name, const char* title, int nbinsx, double xmin, double xmax, int nbinsy, const double *ybins, bool uniformScaling = false); TH2Ratio(const char* name, const char* title, bool uniformScaling = false); ~TH2Ratio(); diff --git a/Modules/Common/include/Common/TH2Ratio.inl b/Modules/Common/include/Common/TH2Ratio.inl index 4063db4f1a..a27e34b2c7 100644 --- a/Modules/Common/include/Common/TH2Ratio.inl +++ b/Modules/Common/include/Common/TH2Ratio.inl @@ -114,6 +114,106 @@ TH2Ratio::TH2Ratio(const char* name, const char* title, int nbinsx, double xm init(); } +template +TH2Ratio::TH2Ratio(const char* name, const char* title, int nbinsx, const float *xbins, int nbinsy, const float *ybins, bool uniformScaling) + : T(name, title, nbinsx, xbins, nbinsy, ybins), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xbins, nbinsy, ybins); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xbins, nbinsy, ybins); + } + } + + init(); +} + +template +TH2Ratio::TH2Ratio(const char* name, const char* title, int nbinsx, const double *xbins, int nbinsy, const double *ybins, bool uniformScaling) + : T(name, title, nbinsx, xbins, nbinsy, ybins), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xbins, nbinsy, ybins); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xbins, nbinsy, ybins); + } + } + + init(); +} + +template +TH2Ratio::TH2Ratio(const char* name, const char* title, int nbinsx, const double *xbins, int nbinsy, double ymin, double ymax, bool uniformScaling) + : T(name, title, nbinsx, xbins, nbinsy, ymin, ymax), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xbins, nbinsy, ymin, ymax); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xbins, nbinsy, ymin, ymax); + } + } + + init(); +} + +template +TH2Ratio::TH2Ratio(const char* name, const char* title, int nbinsx, double xmin, double xmax, int nbinsy, const double *ybins, bool uniformScaling) + : T(name, title, nbinsx, xmin, xmax, nbinsy, ybins), + o2::mergers::MergeInterface(), + mUniformScaling(uniformScaling) +{ + // do not add created histograms to gDirectory + // see https://root.cern.ch/doc/master/TEfficiency_8cxx.html + { + TString nameNum = T::GetName() + TString("_num"); + TString nameDen = T::GetName() + TString("_den"); + TString titleNum = T::GetTitle() + TString(" num"); + TString titleDen = T::GetTitle() + TString(" den"); + TDirectory::TContext ctx(nullptr); + mHistoNum = new T(nameNum, titleNum, nbinsx, xmin, xmax, nbinsy, ybins); + if (mUniformScaling) { + mHistoDen = new T(nameDen, titleDen, 1, -1, 1, 1, -1, 1); + } else { + mHistoDen = new T(nameDen, titleDen, nbinsx, xmin, xmax, nbinsy, ybins); + } + } + + init(); +} + template TH2Ratio::TH2Ratio(const char* name, const char* title, bool uniformScaling) : T(name, title, 10, 0, 10, 10, 0, 10), @@ -177,8 +277,8 @@ void TH2Ratio::update() } T::Reset(); - T::GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax()); - T::GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXmin(), mHistoNum->GetYaxis()->GetXmax()); + mHistoNum->GetXaxis()->Copy(*T::GetXaxis()); + mHistoNum->GetYaxis()->Copy(*T::GetYaxis()); T::SetBinsLength(); // Copy bin labels between histograms.