100 _hist->Sumw2(
false) ;
101 _hist->GetSumw2()->Set(0) ;
102 _hist->SetDirectory(
nullptr);
114 std::stringstream ss;
115 ss <<
"RooPlot::RooPlot: cannot create plot for variable without finite limits: " << var.
GetName();
116 oocoutE(
nullptr, InputArguments) << ss.str() << std::endl;
117 throw std::runtime_error(ss.str());
129 :
RooPlot{validateFiniteLimits(var1),
130 validateFiniteLimits(var2),
163 _hist->Sumw2(
false) ;
164 _hist->GetSumw2()->Set(0) ;
165 _hist->SetDirectory(
nullptr);
207 for(
int i=0; i<nbins; ++i){
218 TString title(
"A RooPlot of \"");
251 _hist->SetStats(
false);
252 _hist->SetDirectory(
nullptr);
266 return TString(
Form(
"frame_%zx",
reinterpret_cast<size_t>(
this))) ;
278 _dir->GetList()->RecursiveRemove(
this) ;
281 for(
auto& item :
_items)
delete item.first;
295 _dir->GetList()->RecursiveRemove(
this);
329 coutE(InputArguments) <<
fName <<
"::addObject: called with a null pointer" << std::endl;
347 if(
nullptr ==
hist) {
348 coutE(InputArguments) <<
fName <<
"::addTH1: called with a null pointer" << std::endl;
352 if(1 !=
hist->GetDimension()) {
353 coutE(InputArguments) <<
fName <<
"::addTH1: cannot plot histogram with "
354 <<
hist->GetDimension() <<
" dimensions" << std::endl;
385 std::vector<double>
x;
386 std::vector<double>
y;
397 for(
int i=0; i<
n; ++i){
403 std::map<int,double> minValues;
404 std::map<int,double> maxValues;
405 int n = graph->
GetN();
409 for(
int i=0; i<
n; ++i){
412 if(maxValues.find(bin)!=maxValues.end()){
413 maxValues[bin] = std::max(maxValues[bin],
y);
417 if(minValues.find(bin)!=minValues.end()){
418 minValues[bin] = std::min(minValues[bin],
y);
429 for(
auto it = maxValues.begin(); it != maxValues.end(); ++it){
433 for(
auto it = minValues.rbegin(); it != minValues.rend(); ++it){
448 int n = graph->
GetN();
455 for(
int i=0; i<
n; ++i){
487 coutE(InputArguments) <<
fName <<
"::add: cross-cast to TObject failed (nothing added)" << std::endl;
491 if(
_hist->GetXaxis()->IsAlphanumeric()){
527 if (!refreshNorm)
return ;
534 coutI(Plotting) <<
"RooPlot::updateFitRangeNorm: New event count of " << rp->
getFitRangeNEvt()/corFac
535 <<
" will supersede previous event count of " <<
_normNumEvts <<
" for normalization of PDF projections" << std::endl ;
588 if(0 == strlen(
_hist->GetYaxis()->GetTitle()))
_hist->SetYTitle(label);
605 _hist->Draw(
"FUNCSAME");
610 for(
auto const& item :
_items) {
612 DrawOpt opt(item.second.c_str()) ;
621 _hist->Draw(
"AXISSAME");
674 for(
auto const& item :
_items) {
707 os <<
indent <<
"RooPlot " <<
GetName() <<
" (" <<
GetTitle() <<
") has no associated plot variable" << std::endl ;
709 os <<
indent <<
" Plot frame contains " <<
_items.size() <<
" object(s):" << std::endl;
713 for(
auto const& item :
_items) {
715 os << deeper <<
"[" << i++ <<
"] (Options=\"" << item.second <<
"\") ";
739 coutE(InputArguments) <<
"RooPlot::nameOf(" <<
GetName() <<
") index " << idx <<
" out of range" << std::endl ;
755 coutE(InputArguments) <<
"RooPlot::getObject(" <<
GetName() <<
") index " << idx <<
" out of range" << std::endl ;
830 if(
name ==
nullptr) {
832 if(deleteToo)
delete _items.back().first;
835 coutE(InputArguments) <<
"RooPlot::remove(" <<
GetName() <<
") ERROR: plot frame is empty, cannot remove last object" << std::endl ;
839 if(item ==
_items.end()) {
840 coutE(InputArguments) <<
"RooPlot::remove(" <<
GetName() <<
") ERROR: no object found with name " <<
name << std::endl ;
842 if(deleteToo)
delete item->first;
852void moveBefore(Iter before, Iter target) {
853 auto d = std::distance(before, target);
854 if(
d > 0) std::rotate(before, target, target + 1);
855 else if(
d < 0) std::rotate(target, target+1, before);
870 if(iterBefore ==
_items.end() || iterTarget ==
_items.end())
return false;
871 moveBefore(iterBefore, iterTarget);
885 if(iterAfter ==
_items.end() || iterTarget ==
_items.end())
return false;
886 moveBefore(iterAfter + 1, iterTarget);
906 for (
auto const &item :
_items) {
913 if (
ret ==
nullptr) {
914 std::stringstream error;
915 error <<
"RooPlot::findObject(" <<
GetName() <<
") cannot find object " << (
name ?
name :
"<last>") <<
"\n"
916 <<
"Available objects are:\n";
917 for (
auto const &item :
_items) {
921 coutE(InputArguments) << error.str();
929 return std::find_if(
_items.begin(),
_items.end(), [&
name](
auto const& item){
930 return name == item.first->GetName();
936 return std::find_if(
_items.begin(),
_items.end(), [&
name](
auto const& item){
937 return name == item.first->GetName();
949 if(item ==
_items.end())
return "";
962 if(item ==
_items.end())
return false;
964 DrawOpt opt(item->second.c_str()) ;
966 item->second = opt.
rawOpt();
977 if(item ==
_items.end())
return false;
990 if(item !=
_items.end()) {
994 item->second = opt.
rawOpt();
1040 coutE(InputArguments) <<
"RooPlot::chiSquare(" <<
GetName() <<
") cannot find curve" << std::endl ;
1047 coutE(InputArguments) <<
"RooPlot::chiSquare(" <<
GetName() <<
") cannot find histogram" << std::endl ;
1071 std::vector<RooCurve *> curves;
1073 for(
auto it =
_items.rbegin(); it !=
_items.rend(); ++it) {
1078 if((!curvename || curvename[0] ==
'\0') || std::string(curvename) == obj.
GetName()) {
1080 curves.push_back(
static_cast<RooCurve*
>(&obj));
1085 if (curves.empty()) {
1086 coutE(InputArguments) <<
"RooPlot::residHist(" <<
GetName() <<
") cannot find curve" << std::endl;
1093 coutE(InputArguments) <<
"RooPlot::residHist(" <<
GetName() <<
") cannot find histogram" << std::endl;
1097 auto residHist =
hist->createEmptyResidHist(*curves.front(), normalize);
1101 std::vector<std::pair<double, double>> coveredRanges;
1103 const double xmin = curve->GetPointX(0);
1104 const double xmax = curve->GetPointX(curve->GetN() - 1);
1106 for(
auto const& prevRange : coveredRanges) {
1107 const double pxmin = prevRange.first;
1108 const double pxmax = prevRange.second;
1117 coveredRanges.emplace_back(
xmin,
xmax);
1119 hist->fillResidHist(*
residHist, *curve, normalize, useAverage);
1121 residHist->GetHistogram()->GetXaxis()->SetRangeUser(
_hist->GetXaxis()->GetXmin(),
_hist->GetXaxis()->GetXmax());
1122 residHist->GetHistogram()->GetXaxis()->SetTitle(
_hist->GetXaxis()->GetTitle());
1123 residHist->GetHistogram()->GetYaxis()->SetTitle(normalize ?
"(Data - curve) / #sigma_{data}" :
"Data - curve");
1141 const char* extraOpt = strtok(
nullptr,
":") ;
1153 static char buf[128] ;
1156 strlcat(buf,
":I",128) ;
1173 double scaleFactor = 1.0 ;
1175 scaleFactor =
_normObj->getFitRangeNEvt(xlo,xhi)/
_normObj->getFitRangeNEvt() ;
1177 coutW(Plotting) <<
"RooPlot::getFitRangeNEvt(" <<
GetName() <<
") WARNING: Unable to obtain event count in range "
1178 << xlo <<
" to " << xhi <<
", substituting full event count" << std::endl ;
1189 if (
_dir)
_dir->GetList()->Remove(
this);
1191 if (
_dir)
_dir->GetList()->Add(
this);
1200 if (
_dir)
_dir->GetList()->Remove(
this);
1202 if (
_dir)
_dir->GetList()->Add(
this);
1212 _hist->SetTitle(title) ;
1346 _hist->TH1::Streamer(R__b);
1377 auto leg = std::make_unique<TLegend>(0.5, 0.7, 0.9, 0.9);
1378 leg->SetBorderSize(0);
1379 leg->SetFillStyle(0);
1380 for (std::size_t i=0; i <
_items.size(); ++i) {
1390 items.emplace_back(obj, obj->GetOption());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
float Size_t
Attribute size (float).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
short Width_t
Line width (short).
short Color_t
Color number (short).
short Style_t
Style number (short).
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
static void indent(ostringstream &buf, int indent_level)
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
int binNumber(double x) const
Returns the bin number corresponding to the value x.
virtual double binCenter(Int_t bin) const =0
Int_t numBins() const
Return number of bins.
virtual double binLow(Int_t bin) const =0
virtual double binHigh(Int_t bin) const =0
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
bool hasMax(const char *name=nullptr) const
Check if variable has an upper bound.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
virtual const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false, bool shared=true) const =0
Retrieve binning configuration with given name or default binning.
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
TString getTitle(bool appendUnit=false) const
Return this variable's title string.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
One-dimensional graphical representation of a real-valued function.
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...
Graphical representation of binned data based on the TGraphAsymmErrors class.
void initialize(const char *_rawOpt)
Initialize the DrawOpt helper class.
const char * rawOpt() const
Return the raw draw options.
RooPlot()
Default constructor coverity[UNINIT_CTOR].
void SetName(const char *name) override
Set the name of the RooPlot to 'name'.
void SetAxisColor(Color_t color=1, Option_t *axis="X")
void remove(const char *name=nullptr, bool deleteToo=true)
Remove object with given name, or last object added if no name is given.
void SetDrawOption(Option_t *option="") override
void updateYAxis(double ymin, double ymax, const char *label="")
Update our y-axis limits to accommodate an object whose spread in y is (ymin,ymax).
Items _items
A list of the items we contain.
void SetMarkerSize(Size_t msize=1)
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
const RooPlotable * _normObj
! Pointer to normalization object ;
double _normNumEvts
Number of events in histogram (for normalization).
bool drawBefore(const char *before, const char *target)
Change the order in which our contained objects are drawn so that the target object is drawn just bef...
bool getInvisible(const char *name) const
Returns true of object with given name is set to be invisible.
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
RooArgSet * _normVars
Variables that PDF plots should be normalized over.
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
void addTH1(TH1 *hist, Option_t *drawOptions="", bool invisible=false)
Add a TH1 histogram object to this plot.
double _padFactor
Scale our y-axis to _padFactor of our maximum contents.
void SetMarkerColor(Color_t tcolor=1)
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Frame detailed printing.
void SetXTitle(const char *title)
void SetFillColor(Color_t fcolor)
RooArgSet * _plotVarSet
A list owning the cloned tree nodes of the plotVarClone.
void SetNdivisions(Int_t n=510, Option_t *axis="X")
TDirectory * _dir
! non-persistent
TString histName() const
Construct automatic name of internal TH1.
TH1 * _hist
Histogram that we uses as basis for drawing the content.
void SetMarkerStyle(Style_t mstyle=1)
void printName(std::ostream &os) const override
Print frame name.
TString getDrawOptions(const char *name) const
Return the Draw() options registered for the named object.
double _normBinWidth
Histogram bin width (for normalization).
void SetZTitle(const char *title)
void setInvisible(const char *name, bool flag=true)
If flag is true object with 'name' is set to be invisible i.e.
void Streamer(TBuffer &) override
Stream an object of class TObject.
void SetContour(Int_t nlevels, const double *levels=nullptr)
void printClassName(std::ostream &os) const override
Print frame class name.
bool setDrawOptions(const char *name, TString options)
Register the specified drawing options for the named object.
TObject * findObject(const char *name, const TClass *tClass=nullptr) const
Find the named object in our list of items and return a pointer to it.
void SetStats(bool stats=true)
Like TH1::SetStats(), but statistics boxes are off by default in RooFit.
double getFitRangeNEvt() const
Return the number of events in the fit range.
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
double GetMaximum(double maxval=FLT_MAX) const
TAttLine * getAttLine(const char *name=nullptr) const
Return a pointer to the line attributes of the named object in this plot, or zero if the named object...
bool drawAfter(const char *after, const char *target)
Change the order in which our contained objects are drawn so that the target object is drawn just aft...
RooAbsRealLValue * _plotVar
The variable we are plotting.
void SetDirectory(TDirectory *dir)
Set the directory that this plot is associated to.
~RooPlot() override
Destructor.
void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
TAttFill * getAttFill(const char *name=nullptr) const
Return a pointer to the fill attributes of the named object in this plot, or zero if the named object...
void printTitle(std::ostream &os) const override
Print frame title.
void SetLineWidth(Width_t lwidth)
void SetTickLength(Float_t length=0.02, Option_t *axis="X")
void SetContourLevel(Int_t level, double value)
static bool addDirectoryStatus()
Query whether new instances of RooPlot will add themselves to gDirectory.
void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
double chiSquare(int nFitParam=0) const
Shortcut for RooPlot::chiSquare(const char* pdfname, const char* histname, int nFitParam=nullptr).
Items::iterator findItem(std::string const &name)
void SetOption(Option_t *option=" ")
TObject * getObject(Int_t idx) const
Return the name of the object at slot 'idx' in this RooPlot.
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
void SetLabelFont(Style_t font=62, Option_t *axis="X")
void Browse(TBrowser *b) override
Plot RooPlot when double-clicked in browser.
double _defYmax
Default maximum for Yaxis (as calculated from contents).
void SetLineStyle(Style_t lstyle)
TAttMarker * getAttMarker(const char *name=nullptr) const
Return a pointer to the marker attributes of the named object in this plot, or zero if the named obje...
void SetTitleFont(Style_t font=62, Option_t *axis="X")
void SetAxisRange(double xmin, double xmax, Option_t *axis="X")
void SetLineColor(Color_t lcolor)
void SetFillStyle(Style_t fstyle)
const char * nameOf(Int_t idx) const
Return the name of the object at slot 'idx' in this RooPlot.
void updateNormVars(const RooArgSet &vars)
Install the given set of observables are reference normalization variables for this frame.
RooHist * residHist(const char *histname=nullptr, const char *pdfname=nullptr, bool normalize=false, bool useAverage=true) const
Return a RooHist (derives from TGraphAsymErrors) containing the residuals of a histogram.
RooPlot * emptyClone(const char *name)
Return empty clone of current RooPlot.
void SetMarkerAttributes()
void createInternalPlotVarClone()
Replaces the pointer to the plot variable with a pointer to a clone of the plot variable that is owne...
void SetNameTitle(const char *name, const char *title) override
Set the name and title of the RooPlot to 'name' and 'title'.
void setPadFactor(double factor)
std::vector< std::pair< TObject *, std::string > > Items
Int_t defaultPrintContents(Option_t *opt) const override
Define default print options, for a given print style.
RooCurve * getCurve(const char *name=nullptr) const
Return a RooCurve pointer of the named object in this plot, or zero if the named object does not exis...
static bool setAddDirectoryStatus(bool flag)
Configure whether new instances of RooPlot will add themselves to gDirectory.
TAttText * getAttText(const char *name=nullptr) const
Return a pointer to the text attributes of the named object in this plot, or zero if the named object...
void SetLabelColor(Color_t color=1, Option_t *axis="X")
TClass * IsA() const override
static void fillItemsFromTList(Items &items, TList const &tlist)
RooFit-internal function for backwards compatibility.
static bool _addDirStatus
static flag controlling AutoDirectoryAdd feature
void printValue(std::ostream &os) const override
Print frame arguments.
void SetYTitle(const char *title)
double getPadFactor() const
void printArgs(std::ostream &os) const override
Interface for printing of object arguments.
std::unique_ptr< TLegend > BuildLegend() const
Build a legend that contains all objects that have been drawn on the plot.
RooHist * getHist(const char *name=nullptr) const
Return a RooCurve pointer of the named object in this plot, or zero if the named object does not exis...
void updateFitRangeNorm(const TH1 *hist)
Update our plot normalization over our plot variable's fit range, which will be determined by the fir...
void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
double _defYmin
Default minimum for Yaxis (as calculated from contents).
TH1 * hist() const
Accessor to the TH1 histogram that is the basis for drawing the content.
void SetBarOffset(Float_t offset=0.25)
void SetBarWidth(Float_t width=0.5)
Int_t GetNdivisions(Option_t *axis="X") const
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
void initialize()
Perform initialization that is common to all constructors.
static RooPlot * frameWithLabels(const RooAbsRealLValue &var)
Create a new frame for a given variable in x, adding bin labels.
void SetTitleOffset(Float_t offset=1, Option_t *axis="X")
double GetMinimum(double minval=-FLT_MAX) const
Class RooPotable is a base class for objects that can be inserted into RooPlots and take advantage of...
virtual double getFitRangeNEvt() const =0
TObject * crossCast()
Return cast of RooPlotable as TObject.
double getYAxisMin() const
double getYAxisMax() const
const char * getYAxisLabel() const
virtual double getFitRangeBinW() const =0
virtual void Streamer(TBuffer &)
void Set(Int_t n) override
Set size of this array to n doubles.
Class to manage histogram axis.
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Bool_t IsAlphanumeric() const
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
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.
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Using a TBrowser one can browse all ROOT objects.
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
TDirectory::TContext keeps track and restore the current directory.
Describe directory structure in memory.
virtual void SetPointEXlow(Int_t i, Double_t exl)
virtual void SetPointEXhigh(Int_t i, Double_t exh)
@ kIsSortedX
Graph is sorted in X points.
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
virtual Double_t Eval(Double_t x, TSpline *spline=nullptr, Option_t *option="") const
virtual void Set(Int_t n)
virtual Int_t GetPoint(Int_t i, Double_t &x, Double_t &y) const
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)
1-D histogram with a double per channel (see TH1 documentation)
1-D histogram with a float per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
virtual void SetNdivisions(Int_t n=510, Option_t *axis="X")
Set the number of divisions to draw an axis.
virtual Int_t GetNbinsX() const
virtual TArrayD * GetSumw2()
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
void Streamer(TBuffer &) override
Stream all objects in the collection to or from the I/O buffer.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Bool_t TestBit(UInt_t f) const
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
virtual TClass * IsA() const
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
TObject()
TObject constructor.
void ToLower()
Change string to lower-case.
const char * Data() const
void ToUpper()
Change string to upper case.
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
bool ObjectAutoRegistrationEnabled()
Test whether objects in this thread auto-register themselves, e.g.