From 0058b38a245261ab8dd553d20323fabf09ff73a5 Mon Sep 17 00:00:00 2001 From: Daniel Wielanek Date: Tue, 3 Dec 2024 17:27:12 +0100 Subject: [PATCH] CalculateNorm replaced by CalculateRawRatio --- features/hist/DividedHisto.cxx | 26 +++++++++++++++++++------- features/hist/DividedHisto.h | 19 ++++++++++++++----- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/features/hist/DividedHisto.cxx b/features/hist/DividedHisto.cxx index 2c363e7a..fe522f32 100644 --- a/features/hist/DividedHisto.cxx +++ b/features/hist/DividedHisto.cxx @@ -1446,19 +1446,22 @@ namespace Hal { DividedHisto3D::DividedHisto3D(const DividedHisto3D& other) : DividedHisto2D(other) {} - Double_t DividedHisto1D::CalculateNorm(Double_t min, Double_t max) const { + Double_t DividedHisto1D::CalculateRawRatio(Double_t min, Double_t max, Bool_t skip_empty) const { Int_t binA = fNum->GetXaxis()->FindBin(min); Int_t binB = fNum->GetXaxis()->FindBin(max); Double_t N = 0; Double_t D = 0; for (int i = binA; i <= binB; i++) { + if (skip_empty) + if (fNum->GetBinContent(i) == 0 || fDen->GetBinContent(i)) continue; N += fNum->GetBinContent(i); D += fDen->GetBinContent(i); } - return D / N; + return N / D; } - Double_t DividedHisto2D::CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY) const { + Double_t + DividedHisto2D::CalculateRawRatio(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY, Bool_t skip_empty) const { Int_t binXm = fNum->GetXaxis()->FindBin(minX); Int_t binXM = fNum->GetXaxis()->FindBin(maxX); Int_t binYm = fNum->GetYaxis()->FindBin(minY); @@ -1467,15 +1470,22 @@ namespace Hal { Double_t D = 0; for (int i = binXm; i <= binXM; i++) { for (int j = binYm; j <= binYM; j++) { + if (skip_empty) + if (fNum->GetBinContent(i, j) == 0 || fDen->GetBinContent(i, j)) continue; N += fNum->GetBinContent(i, j); D += fDen->GetBinContent(i, j); } } - return D / N; + return N / D; } - Double_t - DividedHisto3D::CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY, Double_t minZ, Double_t maxZ) const { + Double_t DividedHisto3D::CalculateRawRatio(Double_t minX, + Double_t maxX, + Double_t minY, + Double_t maxY, + Double_t minZ, + Double_t maxZ, + Bool_t skip_empty) const { Int_t binXm = fNum->GetXaxis()->FindBin(minX); Int_t binXM = fNum->GetXaxis()->FindBin(maxX); Int_t binYm = fNum->GetYaxis()->FindBin(minY); @@ -1487,12 +1497,14 @@ namespace Hal { for (int i = binXm; i <= binXM; i++) { for (int j = binYm; j <= binYM; j++) { for (int k = binZm; k <= binZM; k++) { + if (skip_empty) + if (fNum->GetBinContent(i, j, k) == 0 || fDen->GetBinContent(i, j, k)) continue; N += fNum->GetBinContent(i, j, k); D += fDen->GetBinContent(i, j, k); } } } - return D / N; + return N / D; } TH1D* DividedHisto2D::Projection2DTo1D(Double_t min, Double_t max, Option_t* opt) const { diff --git a/features/hist/DividedHisto.h b/features/hist/DividedHisto.h index acd698ca..37c4af27 100644 --- a/features/hist/DividedHisto.h +++ b/features/hist/DividedHisto.h @@ -348,12 +348,13 @@ namespace Hal { */ Double_t GetScale() const; /** - * calucalte denominator/numerator ratio at given range + * calculate numerator/denominator ratio at given range * @param min lower norm range * @param max upper norm range + * @param skip_empty - skip empty bins * @return */ - Double_t CalculateNorm(Double_t min, Double_t max) const; + Double_t CalculateRawRatio(Double_t min, Double_t max, Bool_t skip_emtpy = kFALSE) const; /** * used to merge similar objects * @param collection @@ -533,14 +534,15 @@ namespace Hal { */ TH1D* GetProjection1D(Double_t min, Double_t max, Option_t* opt) const { return Projection2DTo1D(min, max, opt); } /** - * calucalte denominator/numerator ratio at given range + * calucaltes numerator/denominrator ratio at given range * @param min lower norm range * @param max upper norm range * @param minY lower norm range * @param maxY upper norm range + * @param skip_empty - skip empty bins * @return */ - Double_t CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY) const; + Double_t CalculateRawRatio(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY, Bool_t skip_emtpy = kFALSE) const; virtual void Browse(TBrowser* b); /** * operator = @@ -703,9 +705,16 @@ namespace Hal { * @param maxY upper norm range * @param minZ lower norm range * @param maxZ upper norm range + * @param skip_emty - ignore emtpy bins * @return */ - Double_t CalculateNorm(Double_t minX, Double_t maxX, Double_t minY, Double_t maxY, Double_t minZ, Double_t maxZ) const; + Double_t CalculateRawRatio(Double_t minX, + Double_t maxX, + Double_t minY, + Double_t maxY, + Double_t minZ, + Double_t maxZ, + Bool_t skip_emtpy = kFALSE) const; /** * operator = * @param other