83 double scaleFactor,
const RooArgSet *normVars,
double prec,
double resolution,
97 if(0 != strlen(
f.getUnit()) || 0 != strlen(
x.getUnit())) {
99 if(0 != strlen(
f.getUnit())) {
103 if(0 != strlen(
x.getUnit())) {
113 std::unique_ptr<RooAbsFunc> funcPtr{scaledFunc.
bindVars(
x, normVars,
true)};
118 std::unique_ptr<std::list<double>> hint{
f.plotSamplingHint(
x,xlo,xhi)};
119 addPoints(*funcPtr,xlo,xhi,xbins+1,prec,resolution,wmode,nEvalError,doEEVal,eeVal,hint.get());
121 ccoutP(Plotting) << endl ;
126 int nBinsX =
x.numBins();
127 for(
int i=0; i<nBinsX; ++i){
128 double xval =
x.getBinning().binCenter(i);
137 for (
int i=0 ; i<
GetN() ; i++) {
153 double xlo,
double xhi,
UInt_t minPoints,
double prec,
double resolution,
158 addPoints(func,xlo,xhi,minPoints+1,prec,resolution,wmode,nEvalError,doEEVal,eeVal);
163 for (
int i=0 ; i<
GetN() ; i++) {
191 deque<double> pointList ;
196 for (i1=0 ; i1<n1 ; i1++) {
197 c1.GetPoint(i1,
x,
y) ;
198 pointList.push_back(
x) ;
203 for (i2=0 ; i2<n2 ; i2++) {
204 c2.GetPoint(i2,
x,
y) ;
205 pointList.push_back(
x) ;
209 sort(pointList.begin(),pointList.end()) ;
213 for (
auto point : pointList) {
215 if ((point-last)>1
e-10) {
217 addPoint(point,scale1*
c1.interpolate(point)+scale2*
c2.interpolate(point)) ;
248 double minVal = std::numeric_limits<double>::infinity();
249 double maxVal = -std::numeric_limits<double>::infinity();
252 for (
int i = 1; i <
GetN() - 1; i++) {
256 minVal = std::min(
y, minVal);
257 maxVal = std::max(
y, maxVal);
261 for (
int i = 1; i <
GetN() - 1; i++) {
280 Int_t minPoints,
double prec,
double resolution,
WingMode wmode,
281 Int_t numee,
bool doEEVal,
double eeVal, list<double>* samplingHint)
285 coutE(InputArguments) <<
fName <<
"::addPoints: input function is not valid" << endl;
288 if(minPoints <= 0 || xhi <= xlo) {
289 coutE(InputArguments) <<
fName <<
"::addPoints: bad input (nothing added)" << endl;
298 minPoints = samplingHint->size() ;
301 double dx= (xhi-xlo)/(minPoints-1.);
303 std::vector<double> yval(minPoints);
307 std::vector<double> xval;
309 for(
int step= 0; step < minPoints; step++) {
310 xval.push_back(xlo + step*dx) ;
313 std::copy(samplingHint->begin(), samplingHint->end(), std::back_inserter(xval));
316 for (
unsigned int step=0; step < xval.size(); ++step) {
317 double xx = xval[step];
318 if (step ==
static_cast<unsigned int>(minPoints-1))
321 yval[step]= func(&xx);
329 coutW(Plotting) <<
"At observable [x]=" << xx <<
" " ;
339 const double ymax = *std::max_element(yval.begin(), yval.end());
340 const double ymin = *std::min_element(yval.begin(), yval.end());
344 double minDx= resolution*(xhi-xlo);
359 auto iter2 = xval.begin() ;
365 if (iter2==xval.end()) {
373 addRange(func,
x1,
x2,yval[step-1],yval[step],prec*yrangeEst,minDx,numee,doEEVal,eeVal,
epsilon);
382 addPoint(xhi+dx,yval[minPoints-1]) ;
397 double y1,
double y2,
double minDy,
double minDx,
398 int numee,
bool doEEVal,
double eeVal,
double epsilon)
406 double xmid= 0.5*(
x1+
x2);
407 double ymid= func(&xmid);
415 coutW(Plotting) <<
"At observable [x]=" << xmid <<
" " ;
425 double dy= ymid - 0.5*(
y1+
y2);
426 if((xmid -
x1 >= minDx) && std::abs(dy)>0 && std::abs(dy) >= minDy) {
428 addRange(func,
x1,xmid,
y1,ymid,minDy,minDx,numee,doEEVal,eeVal,
epsilon);
429 addRange(func,xmid,
x2,ymid,
y2,minDy,minDx,numee,doEEVal,eeVal,
epsilon);
513 os <<
indent <<
"--- RooCurve ---" << endl ;
515 os <<
indent <<
" Contains " <<
n <<
" points" << endl;
516 os <<
indent <<
" Graph points:" << endl;
517 for(
Int_t i= 0; i <
n; i++) {
518 os <<
indent << setw(3) << i <<
") x = " <<
fX[i] <<
" , y = " <<
fY[i] << endl;
532 double x,
y,eyl,eyh,exl,exh ;
535 double xstart,xstop ;
543 for (i=0 ; i<
np ; i++) {
549 if (x<xstart || x>xstop) continue ;
561 double pull = (
y>avg) ? ((
y-avg)/eyl) : ((
y-avg)/eyh) ;
568 return chisq.
Sum() / (nbin-nFitParam) ;
580 coutE(InputArguments) <<
"RooCurve::average(" <<
GetName()
581 <<
") invalid range (" << xFirst <<
"," << xLast <<
")" << endl ;
592 double xFirstPt,yFirstPt,xLastPt,yLastPt ;
593 GetPoint(ifirst,xFirstPt,yFirstPt) ;
596 double tolerance=1
e-3*(xLast-xFirst) ;
599 if (ilast-ifirst==1 &&(xFirstPt-xFirst)<-1*tolerance && (xLastPt-xLast)>tolerance) {
600 return 0.5*(yFirst+yLast) ;
605 if ((xFirstPt-xFirst)<-1*tolerance) {
612 if ((xLastPt-xLast)>tolerance) {
620 sum += (xFirstPt-xFirst)*(yFirst+yFirstPt)/2 ;
624 for (i=ifirst ; i<ilast ; i++) {
631 sum += (xLast-xLastPt)*(yLastPt+yLast)/2 ;
632 return sum/(xLast-xFirst) ;
643 double delta(std::numeric_limits<double>::max()),
x,
y ;
646 for (i=0 ; i<
n ; i++) {
648 if (std::abs(xvalue-
x)<delta) {
649 delta = std::abs(xvalue-
x) ;
654 return (delta<tolerance)?ibest:-1 ;
670 double xbest, ybest ;
674 if (std::abs(xbest-xvalue)<tolerance) {
679 double xother,yother, retVal(0) ;
686 if (xother==xbest)
return ybest ;
687 retVal = ybest + (yother-ybest)*(xvalue-xbest)/(xother-xbest) ;
695 if (xother==xbest)
return ybest ;
696 retVal = yother + (ybest-yother)*(xvalue-xother)/(xbest-xother) ;
718 vector<double> bandLo(
GetN()) ;
719 vector<double> bandHi(
GetN()) ;
720 for (
int i=0 ; i<
GetN() ; i++) {
724 for (
int i=0 ; i<
GetN() ; i++) {
727 for (
int i=
GetN()-1 ; i>=0 ; i--) {
758 vector<double> bandLo(
GetN()) ;
759 vector<double> bandHi(
GetN()) ;
760 for (
int i=0 ; i<
GetN() ; i++) {
764 for (
int i=0 ; i<
GetN() ; i++) {
767 for (
int i=
GetN()-1 ; i>=0 ; i--) {
791 vector<double> y_plus(plusVar.size()), y_minus(minusVar.size()) ;
793 for (vector<RooCurve*>::const_iterator iter=plusVar.begin() ; iter!=plusVar.end() ; ++iter) {
794 y_plus[j++] = (*iter)->interpolate(
GetX()[i]) ;
797 for (vector<RooCurve*>::const_iterator iter=minusVar.begin() ; iter!=minusVar.end() ; ++iter) {
798 y_minus[j++] = (*iter)->interpolate(
GetX()[i]) ;
800 double y_cen =
GetY()[i] ;
805 for (j=0 ; j<
n ; j++) {
806 F[j] = (y_plus[j]-y_minus[j])/2 ;
810 double sum =
F*(C*
F) ;
812 lo= y_cen + sqrt(
sum) ;
813 hi= y_cen - sqrt(
sum) ;
822 vector<double>
y(variations.size()) ;
824 for (vector<RooCurve*>::const_iterator iter=variations.begin() ; iter!=variations.end() ; ++iter) {
825 y[j++] = (*iter)->interpolate(
GetX()[i]) ;
832 sort(
y.begin(),
y.end()) ;
834 hi =
y[
y.size()-delta] ;
837 double sum_y(0), sum_ysq(0) ;
838 for (
unsigned int k=0 ; k<
y.size() ; k++) {
840 sum_ysq +=
y[k]*
y[k] ;
843 sum_ysq /=
y.size() ;
845 double rms = sqrt(sum_ysq - (sum_y*sum_y)) ;
846 lo =
GetY()[i] - Z*rms ;
863 for(
Int_t i= 0; i <
n; i++) {
872 for(
Int_t i= 2; i <
n-2; i++) {
874 double rdy = std::abs(yTest-other.
fY[i])/Yrange ;
877 if(!verbose)
continue;
878 cout <<
"RooCurve::isIdentical[" << std::setw(3) << i <<
"] Y tolerance exceeded (" << std::setprecision(5) << std::setw(10) << rdy <<
">" << tol <<
"),";
879 cout <<
" x,y=(" << std::right << std::setw(10) <<
fX[i] <<
"," << std::setw(10) <<
fY[i] <<
")\tref: y="
880 << std::setw(10) << other.
interpolate(
fX[i], 1.E-15) <<
". [Nearest point from ref: ";
882 std::cout <<
"j=" << j <<
"\tx,y=(" << std::setw(10) << other.
fX[j] <<
"," << std::setw(10) << other.
fY[j] <<
") ]" <<
"\trange=" << Yrange << std::endl;
899 auto hint =
new std::list<double>;
908 hint->push_back(xlo + delta);
909 hint->push_back(xhi - delta);
913 for (
const double x : boundaries) {
914 if (
x - xlo > delta && xhi -
x > delta) {
915 hint->push_back(
x - delta);
916 hint->push_back(
x + delta);
bool _showProgress
Show progress indication during evaluation if true.
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t SetLineWidth
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Abstract interface for evaluating a real-valued function of one real variable and performing numerica...
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
Abstract base class for objects that represent a real value and implements functionality common to al...
RooFit::OwningPtr< RooAbsFunc > bindVars(const RooArgSet &vars, const RooArgSet *nset=nullptr, bool clipInvalid=false) const
Create an interface adaptor f(vars) that binds us to the specified variables (in arbitrary order).
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
static void printEvalErrors(std::ostream &os=std::cout, Int_t maxPerNode=10000000)
Print all outstanding logged evaluation error on the given ostream.
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
A RooCurve is a one-dimensional graphical representation of a real-valued function.
void addPoints(const RooAbsFunc &func, double xlo, double xhi, Int_t minPoints, double prec, double resolution, WingMode wmode, Int_t numee=0, bool doEEVal=false, double eeVal=0.0, std::list< double > *samplingHint=nullptr)
Add points calculated with the specified function, over the range (xlo,xhi).
void printTitle(std::ostream &os) const override
Print the title of this curve.
void initialize()
Perform initialization that is common to all curves.
double getFitRangeBinW() const override
Get the bin width associated with this plotable object.
static constexpr double relativeXEpsilon()
The distance between two points x1 and x2 relative to the full plot range below which two points are ...
void addRange(const RooAbsFunc &func, double x1, double x2, double y1, double y2, double minDy, double minDx, int numee, bool doEEVal, double eeVal, double epsilon)
Fill the range (x1,x2) with points calculated using func(&x).
void printName(std::ostream &os) const override
Print name of object.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print the details of this curve.
double interpolate(double x, double tolerance=1e-10) const
Return linearly interpolated value of curve at xvalue.
static std::list< double > * plotSamplingHintForBinBoundaries(std::span< const double > boundaries, double xlo, double xhi)
Returns sampling hints for a histogram with given boundaries.
void printClassName(std::ostream &os) const override
Print the class name of this curve.
RooCurve()
Default constructor.
bool _showProgress
! Show progress indication when adding points
RooCurve * makeErrorBand(const std::vector< RooCurve * > &variations, double Z=1) const
Construct filled RooCurve represented error band that captures alpha% of the variations of the curves...
double chiSquare(const RooHist &hist, int nFitParam) const
Calculate the chi^2/NDOF of this curve with respect to the histogram 'hist' accounting nFitParam floa...
void calcBandInterval(const std::vector< RooCurve * > &variations, Int_t i, double Z, double &lo, double &hi, bool approxGauss) const
double getFitRangeNEvt() const override
Return the number of events associated with the plotable object, it is always 1 for curves.
void shiftCurveToZero()
Find lowest point in curve and move all points in curve so that lowest point will go exactly through ...
void addPoint(double x, double y)
Add a point with the specified coordinates. Update our y-axis limits.
bool isIdentical(const RooCurve &other, double tol=1e-6, bool verbose=true) const
Return true if curve is identical to other curve allowing for given absolute tolerance on each point ...
Int_t findPoint(double value, double tolerance=1e-10) const
Find the nearest point to xvalue.
double average(double lo, double hi) const
Return average curve value in [xFirst,xLast] by integrating curve between points and dividing by xLas...
A RooHist is a graphical representation of binned data based on the TGraphAsymmErrors class.
static constexpr double infinity()
Return internal infinity representation.
Class RooPotable is a base class for objects that can be inserted into RooPlots and take advantage of...
void updateYAxisLimits(double y)
void setYAxisLimits(double ymin, double ymax)
void setYAxisLabel(const char *label)
A RooProduct represents the product of a given set of RooAbsReal objects.
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Bool_t IsAlphanumeric() const
const char * GetBinLabel(Int_t bin) const
Return label for bin.
virtual void Set(Int_t nbins, Double_t xmin, Double_t xmax)
Initialize axis with fix bins.
Double_t * GetEXlow() const override
Double_t * GetEYhigh() const override
Double_t * GetEXhigh() const override
Double_t * GetEYlow() const override
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
Double_t * fY
[fNpoints] array of Y points
virtual void Sort(Bool_t(*greater)(const TGraph *, Int_t, Int_t)=&TGraph::CompareX, Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111)
Sorts the points of this TGraph using in-place quicksort (see e.g.
void SetName(const char *name="") override
Set graph name.
TAxis * GetXaxis() const
Get x axis of the graph.
Double_t * fX
[fNpoints] array of X points
void SetTitle(const char *title="") override
Change (i.e.
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
Get x and y values for point number i.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
const char * Data() const
TString & Append(const char *cs)
RooConstVar & RooConst(double val)
Double_t Erfc(Double_t x)
Computes the complementary error function erfc(x).
static uint64_t sum(uint64_t i)