82 double scaleFactor,
const RooArgSet *normVars,
double prec,
double resolution,
87 _showProgress(showProg)
96 if(0 != strlen(
f.getUnit()) || 0 != strlen(
x.getUnit())) {
98 if(0 != strlen(
f.getUnit())) {
102 if(0 != strlen(
x.getUnit())) {
113 funcPtr=
f.bindVars(
x,normVars,
true);
116 if(scaleFactor != 1) {
120 assert(0 != funcPtr);
126 std::unique_ptr<std::list<double>> hint{
f.plotSamplingHint(
x,xlo,xhi)};
127 addPoints(*funcPtr,xlo,xhi,xbins+1,prec,resolution,wmode,nEvalError,doEEVal,eeVal,hint.get());
129 ccoutP(Plotting) << endl ;
134 int nBinsX =
x.numBins();
135 for(
int i=0; i<nBinsX; ++i){
136 double xval =
x.getBinning().binCenter(i);
144 if(rawPtr)
delete rawPtr;
148 for (
int i=0 ; i<
GetN() ; i++) {
164 double xlo,
double xhi,
UInt_t minPoints,
double prec,
double resolution,
170 addPoints(func,xlo,xhi,minPoints+1,prec,resolution,wmode,nEvalError,doEEVal,eeVal);
175 for (
int i=0 ; i<
GetN() ; i++) {
203 deque<double> pointList ;
208 for (i1=0 ; i1<n1 ; i1++) {
209 c1.GetPoint(i1,
x,
y) ;
210 pointList.push_back(
x) ;
215 for (i2=0 ; i2<n2 ; i2++) {
216 c2.GetPoint(i2,
x,
y) ;
217 pointList.push_back(
x) ;
221 sort(pointList.begin(),pointList.end()) ;
225 for (
auto point : pointList) {
227 if ((point-last)>1
e-10) {
229 addPoint(point,scale1*
c1.interpolate(point)+scale2*
c2.interpolate(point)) ;
268 double minVal(1e30) ;
269 double maxVal(-1e30) ;
272 for (i=1 ; i<
GetN()-1 ; i++) {
275 if (
y<minVal) minVal=
y ;
276 if (
y>maxVal) maxVal=
y ;
280 for (i=1 ; i<
GetN()-1 ; i++) {
288 double newMax = maxVal - minVal ;
302 Int_t minPoints,
double prec,
double resolution,
WingMode wmode,
303 Int_t numee,
bool doEEVal,
double eeVal, list<double>* samplingHint)
307 coutE(InputArguments) <<
fName <<
"::addPoints: input function is not valid" << endl;
310 if(minPoints <= 0 || xhi <= xlo) {
311 coutE(InputArguments) <<
fName <<
"::addPoints: bad input (nothing added)" << endl;
320 minPoints = samplingHint->size() ;
323 double dx= (xhi-xlo)/(minPoints-1.);
324 std::vector<double> yval(minPoints);
328 std::vector<double> xval;
330 for(
int step= 0; step < minPoints; step++) {
331 xval.push_back(xlo + step*dx) ;
334 std::copy(samplingHint->begin(), samplingHint->end(), std::back_inserter(xval));
337 for (
unsigned int step=0; step < xval.size(); ++step) {
338 double xx = xval[step];
339 if (step ==
static_cast<unsigned int>(minPoints-1))
342 yval[step]= func(&xx);
350 coutW(Plotting) <<
"At observable [x]=" << xx <<
" " ;
360 const double ymax = *std::max_element(yval.begin(), yval.end());
361 const double ymin = *std::min_element(yval.begin(), yval.end());
365 double minDx= resolution*(xhi-xlo);
380 auto iter2 = xval.begin() ;
386 if (iter2==xval.end()) {
394 addRange(func,
x1,
x2,yval[step-1],yval[step],prec*yrangeEst,minDx,numee,doEEVal,eeVal);
403 addPoint(xhi+dx,yval[minPoints-1]) ;
418 double y1,
double y2,
double minDy,
double minDx,
419 Int_t numee,
bool doEEVal,
double eeVal)
422 if (std::abs(
x2-
x1)<1
e-20) {
427 double xmid= 0.5*(
x1+
x2);
428 double ymid= func(&xmid);
436 coutW(Plotting) <<
"At observable [x]=" << xmid <<
" " ;
446 double dy= ymid - 0.5*(
y1+
y2);
447 if((xmid -
x1 >= minDx) && std::abs(dy)>0 && std::abs(dy) >= minDy) {
449 addRange(func,
x1,xmid,
y1,ymid,minDy,minDx,numee,doEEVal,eeVal);
450 addRange(func,xmid,
x2,ymid,
y2,minDy,minDx,numee,doEEVal,eeVal);
534 os <<
indent <<
"--- RooCurve ---" << endl ;
536 os <<
indent <<
" Contains " <<
n <<
" points" << endl;
537 os <<
indent <<
" Graph points:" << endl;
538 for(
Int_t i= 0; i <
n; i++) {
539 os <<
indent << setw(3) << i <<
") x = " <<
fX[i] <<
" , y = " <<
fY[i] << endl;
553 double x,
y,eyl,eyh,exl,exh ;
556 double xstart,xstop ;
564 for (i=0 ; i<
np ; i++) {
570 if (x<xstart || x>xstop) continue ;
582 double pull = (
y>avg) ? ((
y-avg)/eyl) : ((
y-avg)/eyh) ;
589 return chisq.
Sum() / (nbin-nFitParam) ;
601 coutE(InputArguments) <<
"RooCurve::average(" <<
GetName()
602 <<
") invalid range (" << xFirst <<
"," << xLast <<
")" << endl ;
613 double xFirstPt,yFirstPt,xLastPt,yLastPt ;
614 GetPoint(ifirst,xFirstPt,yFirstPt) ;
617 double tolerance=1
e-3*(xLast-xFirst) ;
620 if (ilast-ifirst==1 &&(xFirstPt-xFirst)<-1*tolerance && (xLastPt-xLast)>tolerance) {
621 return 0.5*(yFirst+yLast) ;
626 if ((xFirstPt-xFirst)<-1*tolerance) {
633 if ((xLastPt-xLast)>tolerance) {
641 sum += (xFirstPt-xFirst)*(yFirst+yFirstPt)/2 ;
645 for (i=ifirst ; i<ilast ; i++) {
652 sum += (xLast-xLastPt)*(yLastPt+yLast)/2 ;
653 return sum/(xLast-xFirst) ;
664 double delta(std::numeric_limits<double>::max()),
x,
y ;
667 for (i=0 ; i<
n ; i++) {
669 if (std::abs(xvalue-
x)<delta) {
670 delta = std::abs(xvalue-
x) ;
675 return (delta<tolerance)?ibest:-1 ;
691 double xbest, ybest ;
695 if (std::abs(xbest-xvalue)<tolerance) {
700 double xother,yother, retVal(0) ;
707 if (xother==xbest)
return ybest ;
708 retVal = ybest + (yother-ybest)*(xvalue-xbest)/(xother-xbest) ;
716 if (xother==xbest)
return ybest ;
717 retVal = yother + (ybest-yother)*(xvalue-xother)/(xbest-xother) ;
739 vector<double> bandLo(
GetN()) ;
740 vector<double> bandHi(
GetN()) ;
741 for (
int i=0 ; i<
GetN() ; i++) {
745 for (
int i=0 ; i<
GetN() ; i++) {
748 for (
int i=
GetN()-1 ; i>=0 ; i--) {
779 vector<double> bandLo(
GetN()) ;
780 vector<double> bandHi(
GetN()) ;
781 for (
int i=0 ; i<
GetN() ; i++) {
785 for (
int i=0 ; i<
GetN() ; i++) {
788 for (
int i=
GetN()-1 ; i>=0 ; i--) {
812 vector<double> y_plus(plusVar.size()), y_minus(minusVar.size()) ;
814 for (vector<RooCurve*>::const_iterator iter=plusVar.begin() ; iter!=plusVar.end() ; ++iter) {
815 y_plus[j++] = (*iter)->interpolate(
GetX()[i]) ;
818 for (vector<RooCurve*>::const_iterator iter=minusVar.begin() ; iter!=minusVar.end() ; ++iter) {
819 y_minus[j++] = (*iter)->interpolate(
GetX()[i]) ;
821 double y_cen =
GetY()[i] ;
826 for (j=0 ; j<
n ; j++) {
827 F[j] = (y_plus[j]-y_minus[j])/2 ;
831 double sum =
F*(C*
F) ;
833 lo= y_cen + sqrt(
sum) ;
834 hi= y_cen - sqrt(
sum) ;
843 vector<double>
y(variations.size()) ;
845 for (vector<RooCurve*>::const_iterator iter=variations.begin() ; iter!=variations.end() ; ++iter) {
846 y[j++] = (*iter)->interpolate(
GetX()[i]) ;
853 sort(
y.begin(),
y.end()) ;
855 hi =
y[
y.size()-delta] ;
858 double sum_y(0), sum_ysq(0) ;
859 for (
unsigned int k=0 ; k<
y.size() ; k++) {
861 sum_ysq +=
y[k]*
y[k] ;
864 sum_ysq /=
y.size() ;
866 double rms = sqrt(sum_ysq - (sum_y*sum_y)) ;
867 lo =
GetY()[i] - Z*rms ;
884 for(
Int_t i= 0; i <
n; i++) {
893 for(
Int_t i= 2; i <
n-2; i++) {
895 double rdy = std::abs(yTest-other.
fY[i])/Yrange ;
898 if(!verbose)
continue;
899 cout <<
"RooCurve::isIdentical[" << std::setw(3) << i <<
"] Y tolerance exceeded (" << std::setprecision(5) << std::setw(10) << rdy <<
">" << tol <<
"),";
900 cout <<
" x,y=(" << std::right << std::setw(10) <<
fX[i] <<
"," << std::setw(10) <<
fY[i] <<
")\tref: y="
901 << std::setw(10) << other.
interpolate(
fX[i], 1.E-15) <<
". [Nearest point from ref: ";
903 std::cout <<
"j=" << j <<
"\tx,y=(" << std::setw(10) << other.
fX[j] <<
"," << std::setw(10) << other.
fY[j] <<
") ]" <<
"\trange=" << Yrange << std::endl;
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
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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...
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
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.
~RooCurve() override
Destructor.
double getFitRangeBinW() const override
Get the bin width associated with this plotable object.
void shiftCurveToZero(double prevYMax)
Find lowest point in curve and move all points in curve so that lowest point will go exactly through ...
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.
void printClassName(std::ostream &os) const override
Print the class name of this curve.
void addRange(const RooAbsFunc &func, double x1, double x2, double y1, double y2, double minDy, double minDx, Int_t numee=0, bool doEEVal=false, double eeVal=0.0)
Fill the range (x1,x2) with points calculated using func(&x).
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 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)
double getYAxisMin() const
void setYAxisLimits(double ymin, double ymax)
double getYAxisMax() const
void setYAxisLabel(const char *label)
Lightweight RooAbsFunction implementation that applies a constant scale factor to another RooAbsFunc.
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)
Double_t Erfc(Double_t x)
Computes the complementary error function erfc(x).
static uint64_t sum(uint64_t i)