Skip to content

Commit

Permalink
[hist] implement Add and Apply in TGraph2D as in TGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdymercury authored and couet committed Aug 13, 2024
1 parent 40221a1 commit 9669d42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hist/hist/inc/TGraph2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TGraph2D : public TNamed, public TAttLine, public TAttFill, public TAttMar
TGraph2D& operator=(const TGraph2D &);

virtual void AddPoint(Double_t x, Double_t y, Double_t z) { SetPoint(fNpoints, x, y, z); } ///< Append a new point to the graph.
virtual void Add(TF2 *f, Double_t c1=1);
virtual void Apply(TF2 *f);
void Browse(TBrowser *) override;
void Clear(Option_t *option="") override;
virtual void DirectoryAutoAdd(TDirectory *);
Expand Down
32 changes: 32 additions & 0 deletions hist/hist/src/TGraph2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,38 @@ void TGraph2D::Build(Int_t n)
}
}

////////////////////////////////////////////////////////////////////////////////
/// Performs the operation: `z = z + c1*f(x,y,z)`
/// Errors are not recalculated.
///
/// \param f may be a 2-D function TF2 or 3-d function TF3
/// \param c1 a scaling factor, 1 by default

void TGraph2D::Add(TF2 *f, Double_t c1)
{
//if (fHistogram) SetBit(kResetHisto);

for (Int_t i = 0; i < fNpoints; i++) {
fZ[i] += c1*f->Eval(fX[i], fY[i], fZ[i]);
}
if (gPad) gPad->Modified();
}

////////////////////////////////////////////////////////////////////////////////
/// Apply function f to all the data points
/// f may be a 2-D function TF2 or 3-d function TF3
/// The Z values of the 2D graph are replaced by the new values computed
/// using the function

void TGraph2D::Apply(TF2 *f)
{
//if (fHistogram) SetBit(kResetHisto);

for (Int_t i = 0; i < fNpoints; i++) {
fZ[i] = f->Eval(fX[i], fY[i], fZ[i]);
}
if (gPad) gPad->Modified();
}

////////////////////////////////////////////////////////////////////////////////
/// Browse
Expand Down

0 comments on commit 9669d42

Please sign in to comment.