Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hist] Make abstract TH1,2,3 methods truly abstract and add missing implementations #17480

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions hist/hist/inc/TH1.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
virtual Bool_t Add(TF1 *h1, Double_t c1=1, Option_t *option="");
virtual Bool_t Add(const TH1 *h1, Double_t c1=1);
virtual Bool_t Add(const TH1 *h, const TH1 *h2, Double_t c1=1, Double_t c2=1);
virtual void AddBinContent(Int_t bin);
virtual void AddBinContent(Int_t bin, Double_t w);
/// Increment bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior
virtual void AddBinContent(Int_t bin) = 0;
/// Increment bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior
pcanal marked this conversation as resolved.
Show resolved Hide resolved
virtual void AddBinContent(Int_t bin, Double_t w) = 0;
static void AddDirectory(Bool_t add=kTRUE);
static Bool_t AddDirectoryStatus();
void Browse(TBrowser *b) override;
Expand Down Expand Up @@ -456,8 +460,15 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
ClassDefOverride(TH1,8) //1-Dim histogram base class

protected:
virtual Double_t RetrieveBinContent(Int_t bin) const;
virtual void UpdateBinContent(Int_t bin, Double_t content);

/// Raw retrieval of bin content on internal data structure
/// see convention for numbering bins in TH1::GetBin
virtual Double_t RetrieveBinContent(Int_t bin) const = 0;

/// Raw update of bin content on internal data structure
/// see convention for numbering bins in TH1::GetBin
virtual void UpdateBinContent(Int_t bin, Double_t content) = 0;

virtual Double_t GetBinErrorSqUnchecked(Int_t bin) const { return fSumw2.fN ? fSumw2.fArray[bin] : RetrieveBinContent(bin); }
};

Expand Down
19 changes: 14 additions & 5 deletions hist/hist/inc/TH1K.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ class TH1K : public TH1, public TArrayF {
private:
void Sort();
protected:
Int_t fReady; //!
Int_t fNIn;
Int_t fKOrd; //!
Int_t fKCur; //!
Int_t fReady = 0; //!
Int_t fNIn = 0;
Int_t fKOrd = 3; //!
Int_t fKCur = 0; //!

Double_t RetrieveBinContent(Int_t bin) const override { return GetBinContent(bin); }
void UpdateBinContent(Int_t bin, Double_t content) override { fArray[bin] = Float_t (content); }

public:
TH1K();
TH1K(const char *name,const char *title,Int_t nbinsx,Double_t xlow,Double_t xup,Int_t k=0);
~TH1K() override;

/// Increment bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin) override {++fArray[bin];}
/// Increment bin content by a weight w.
/// \warning The value of w is cast to `Float_t` before being added.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{ fArray[bin] += Float_t (w); }

void Copy(TObject &obj) const override;
Int_t Fill(Double_t x) override;
Expand Down
23 changes: 7 additions & 16 deletions hist/hist/inc/TH2.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ class TH2 : public TH1 {

public:
~TH2() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
virtual void AddBinContent(Int_t binx, Int_t biny);
virtual void AddBinContent(Int_t binx, Int_t biny, Double_t w);
using TH1::AddBinContent;
/// Increment 2D bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t binx, Int_t biny) { AddBinContent(GetBin(binx, biny)); }
/// Increment 2D bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t binx, Int_t biny, Double_t w) { AddBinContent(GetBin(binx, biny), w); }
Int_t BufferEmpty(Int_t action=0) override;
void Copy(TObject &hnew) const override;
Int_t Fill(Double_t x, Double_t y) override;
Expand Down Expand Up @@ -156,8 +159,6 @@ class TH2C : public TH2, public TArrayC {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -199,8 +200,6 @@ class TH2S : public TH2, public TArrayS {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -242,8 +241,6 @@ class TH2I : public TH2, public TArrayI {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -283,8 +280,6 @@ class TH2L : public TH2, public TArrayL64 {
~TH2L() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -331,8 +326,6 @@ class TH2F : public TH2, public TArrayF {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Float_t (w);}
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -380,8 +373,6 @@ class TH2D : public TH2, public TArrayD {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Double_t (w);}
void AddBinContent(Int_t binx, Int_t biny) override { AddBinContent(GetBin(binx, biny)); }
void AddBinContent(Int_t binx, Int_t biny, Double_t w) override { AddBinContent(GetBin(binx, biny), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down
3 changes: 3 additions & 0 deletions hist/hist/inc/TH2Poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class TH2Poly : public TH2 {

//functions not to be used for TH2Poly

void AddBinContent(Int_t) override; ///< NOT IMPLEMENTED for TH2Poly
void AddBinContent(Int_t, Double_t) override; ///< NOT IMPLEMENTED for TH2Poly

Int_t Fill(Double_t) override{return -1;} ///< NOT IMPLEMENTED for TH2Poly
Int_t Fill(Double_t , const char *, Double_t) override{return -1;} ///< NOT IMPLEMENTED for TH2Poly
Int_t Fill(const char *, Double_t , Double_t ) override{return -1;} ///< NOT IMPLEMENTED for TH2Poly
Expand Down
23 changes: 7 additions & 16 deletions hist/hist/inc/TH3.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ class TH3 : public TH1, public TAtt3D {

public:
~TH3() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
virtual void AddBinContent(Int_t binx, Int_t biny, Int_t binz);
virtual void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w);
using TH1::AddBinContent;
/// Increment 3D bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) { AddBinContent(GetBin(binx, biny, binz)); }
/// Increment 3D bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) { AddBinContent(GetBin(binx, biny, binz), w); }
Int_t BufferEmpty(Int_t action = 0) override;
void Copy(TObject &hnew) const override;
virtual Int_t Fill(Double_t x, Double_t y, Double_t z);
Expand Down Expand Up @@ -172,8 +175,6 @@ class TH3C : public TH3, public TArrayC {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -212,8 +213,6 @@ class TH3S : public TH3, public TArrayS {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -252,8 +251,6 @@ class TH3I : public TH3, public TArrayI {

void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -292,8 +289,6 @@ class TH3L : public TH3, public TArrayL64 {
~TH3L() override;
void AddBinContent(Int_t bin) override;
void AddBinContent(Int_t bin, Double_t w) override;
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -338,8 +333,6 @@ class TH3F : public TH3, public TArrayF {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Float_t (w);}
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down Expand Up @@ -383,8 +376,6 @@ class TH3D : public TH3, public TArrayD {
/// Passing an out-of-range bin leads to undefined behavior
void AddBinContent(Int_t bin, Double_t w) override
{fArray[bin] += Double_t (w);}
void AddBinContent(Int_t binx, Int_t biny, Int_t binz) override { AddBinContent(GetBin(binx, biny, binz)); }
void AddBinContent(Int_t binx, Int_t biny, Int_t binz, Double_t w) override { AddBinContent(GetBin(binx, biny, binz), w); }
void Copy(TObject &hnew) const override;
void Reset(Option_t *option="") override;
void SetBinsLength(Int_t n=-1) override;
Expand Down
37 changes: 0 additions & 37 deletions hist/hist/src/TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1248,24 +1248,6 @@ Bool_t TH1::Add(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2)
return kTRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// Increment bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior

void TH1::AddBinContent(Int_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Increment bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior

void TH1::AddBinContent(Int_t, Double_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Sets the flag controlling the automatic add of histograms in memory
///
Expand Down Expand Up @@ -9454,25 +9436,6 @@ TH1* TH1::TransformHisto(TVirtualFFT *fft, TH1* h_output, Option_t *option)
return hout;
}

////////////////////////////////////////////////////////////////////////////////
/// Raw retrieval of bin content on internal data structure
/// see convention for numbering bins in TH1::GetBin

Double_t TH1::RetrieveBinContent(Int_t) const
{
AbstractMethod("RetrieveBinContent");
return 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Raw update of bin content on internal data structure
/// see convention for numbering bins in TH1::GetBin

void TH1::UpdateBinContent(Int_t, Double_t)
{
AbstractMethod("UpdateBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Print value overload

Expand Down
15 changes: 0 additions & 15 deletions hist/hist/src/TH1K.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ ClassImp(TH1K);
TH1K::TH1K()
{
fDimension = 1;
fNIn = 0;
fReady = 0;
fKOrd = 3;
fKCur = 0;
}


Expand All @@ -54,18 +50,7 @@ TH1K::TH1K(const char *name,const char *title,Int_t nbins,Double_t xlow,Double_t
: TH1(name,title,nbins,xlow,xup), TArrayF(100)
{
fDimension = 1;
fNIn = 0;
fReady = 0;
fKOrd = k;
fKCur = 0;
}


////////////////////////////////////////////////////////////////////////////////
/// Destructor.

TH1K::~TH1K()
{
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
36 changes: 0 additions & 36 deletions hist/hist/src/TH2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,42 +231,6 @@ TH2::~TH2()
{
}

////////////////////////////////////////////////////////////////////////////////
/// Increment bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior

void TH2::AddBinContent(Int_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Increment bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior

void TH2::AddBinContent(Int_t, Double_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Increment 2D bin content by 1.
/// Passing an out-of-range bin leads to undefined behavior

void TH2::AddBinContent(Int_t, Int_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Increment 2D bin content by a weight w.
/// Passing an out-of-range bin leads to undefined behavior

void TH2::AddBinContent(Int_t, Int_t, Double_t)
{
AbstractMethod("AddBinContent");
}

////////////////////////////////////////////////////////////////////////////////
/// Fill histogram with all entries in the buffer.
/// - action = -1 histogram is reset and refilled from the buffer (called by THistPainter::Paint)
Expand Down
12 changes: 12 additions & 0 deletions hist/hist/src/TH2Poly.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1751,3 +1751,15 @@ Double_t TH2Poly::Interpolate(Double_t, Double_t)
Error("Interpolate", "Not implemented for TH2Poly");
return TMath::QuietNaN();
}
////////////////////////////////////////////////////////////////////////////////
/// NOT IMPLEMENTED for TH2Poly
void TH2Poly::AddBinContent(Int_t)
{
Error("AddBinContent", "Not implemented for TH2Poly");
}
////////////////////////////////////////////////////////////////////////////////
/// NOT IMPLEMENTED for TH2Poly
void TH2Poly::AddBinContent(Int_t, Double_t)
{
Error("AddBinContent", "Not implemented for TH2Poly");
}
Loading
Loading