Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooPlot.cxx
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * @(#)root/roofitcore:$Id$
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2005, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17/**
18\file RooPlot.cxx
19\class RooPlot
20\ingroup Roofitcore
21
22Plot frame and a container for graphics objects
23within that frame. As a frame, it provides the TH1-style public interface
24for setting plot ranges, configuring axes, etc. As a container, it
25holds an arbitrary set of objects that might be histograms of data,
26curves representing a fit model, or text labels. Use the Draw()
27method to draw a frame and the objects it contains. Use the various
28add...() methods to add objects to be drawn. In general, the
29add...() methods create a private copy of the object you pass them
30and return a pointer to this copy. The caller owns the input object
31and this class owns the returned object.
32All RooAbsReal and RooAbsData derived classes implement plotOn()
33functions that facilitate to plot themselves on a given RooPlot, e.g.
34~~~ {.cpp}
35RooPlot *frame = x.frame() ;
36data.plotOn(frame) ;
37pdf.plotOn(frame) ;
38~~~
39These high level functions also take care of any projections
40or other mappings that need to be made to plot a multi-dimensional
41object onto a one-dimensional plot.
42**/
43
44#include "RooPlot.h"
45
46#include "RooAbsReal.h"
47#include "RooAbsRealLValue.h"
48#include "RooPlotable.h"
49#include "RooArgSet.h"
50#include "RooCurve.h"
51#include "RooHist.h"
52#include "RooMsgService.h"
53
54#include "TClass.h"
55#include "TBuffer.h"
56#include "TH1D.h"
57#include "TBrowser.h"
58#include "TVirtualPad.h"
59
60#include "TAttLine.h"
61#include "TAttFill.h"
62#include "TAttMarker.h"
63#include "TAttText.h"
64#include "TDirectoryFile.h"
65#include "TLegend.h"
66#include "strlcpy.h"
67
68#include <algorithm>
69#include <cstring>
70#include <iostream>
71
72using std::endl, std::ostream;
73
75
76
77bool RooPlot::_addDirStatus = true ;
78
80bool RooPlot::setAddDirectoryStatus(bool flag) { bool ret = flag ; _addDirStatus = flag ; return ret ; }
81
82
83////////////////////////////////////////////////////////////////////////////////
84/// Default constructor
85/// coverity[UNINIT_CTOR]
86
88{
91 }
92}
93
94
95////////////////////////////////////////////////////////////////////////////////
96/// Constructor of RooPlot with range [xmin,xmax]
97
98RooPlot::RooPlot(double xmin, double xmax)
99{
100 _hist = new TH1D(histName(),"A RooPlot",100,xmin,xmax) ;
101 _hist->Sumw2(false) ;
102 _hist->GetSumw2()->Set(0) ;
103 _hist->SetDirectory(nullptr);
104
105 // Create an empty frame with the specified x-axis limits.
106 initialize();
107
108}
109
110
111
112////////////////////////////////////////////////////////////////////////////////
113/// Construct of a two-dimensional RooPlot with ranges [xmin,xmax] x [ymin,ymax]
114
115RooPlot::RooPlot(double xmin, double xmax, double ymin, double ymax) :
116 _defYmax(0)
117{
118 _hist = new TH1D(histName(),"A RooPlot",100,xmin,xmax) ;
119 _hist->Sumw2(false) ;
120 _hist->GetSumw2()->Set(0) ;
121 _hist->SetDirectory(nullptr);
122
125 initialize();
126}
127
128
129////////////////////////////////////////////////////////////////////////////////
130/// Construct a two-dimensional RooPlot with ranges and properties taken
131/// from variables var1 and var2
132
134 _defYmax(0)
135{
136 _hist = new TH1D(histName(),"A RooPlot",100,var1.getMin(),var1.getMax()) ;
137 _hist->Sumw2(false) ;
138 _hist->GetSumw2()->Set(0) ;
139 _hist->SetDirectory(nullptr);
140
141 if(!var1.hasMin() || !var1.hasMax()) {
142 coutE(InputArguments) << "RooPlot::RooPlot: cannot create plot for variable without finite limits: "
143 << var1.GetName() << endl;
144 return;
145 }
146 if(!var2.hasMin() || !var2.hasMax()) {
147 coutE(InputArguments) << "RooPlot::RooPlot: cannot create plot for variable without finite limits: "
148 << var1.GetName() << endl;
149 return;
150 }
151 SetMinimum(var2.getMin());
152 SetMaximum(var2.getMax());
153 SetXTitle(var1.getTitle(true));
154 SetYTitle(var2.getTitle(true));
155 initialize();
156}
157
158
159////////////////////////////////////////////////////////////////////////////////
160/// Construct a two-dimensional RooPlot with ranges and properties taken
161/// from variables var1 and var2 but with an overriding range definition
162/// of [xmin,xmax] x [ymin,ymax]
163
165 double xmin, double xmax, double ymin, double ymax) :
166 _defYmax(0)
167{
168 _hist = new TH1D(histName(),"A RooPlot",100,xmin,xmax) ;
169 _hist->Sumw2(false) ;
170 _hist->GetSumw2()->Set(0) ;
171 _hist->SetDirectory(nullptr);
172
175 SetXTitle(var1.getTitle(true));
176 SetYTitle(var2.getTitle(true));
177 initialize();
178}
179
180
181////////////////////////////////////////////////////////////////////////////////
182/// Create an 1-dimensional with all properties taken from 'var', but
183/// with an explicit range [xmin,xmax] and a default binning of 'nbins'
184
185RooPlot::RooPlot(const char *name, const char *title, const RooAbsRealLValue &var, double xmin, double xmax,
186 Int_t nbins)
187 : _hist(new TH1D(name, title, nbins, xmin, xmax)),
188 _plotVar(const_cast<RooAbsRealLValue *>(&var)),
189 _normBinWidth((xmax - xmin) / nbins)
190{
191 _hist->Sumw2(false) ;
192 _hist->GetSumw2()->Set(0) ;
193 _hist->SetDirectory(nullptr);
194
195 // In the past, the plot variable was cloned, but there was no apparent reason for doing so.
196
197 TString xtitle= var.getTitle(true);
198 SetXTitle(xtitle.Data());
199
200 initialize();
201}
202
203
204////////////////////////////////////////////////////////////////////////////////
205/// Create an 1-dimensional with all properties taken from 'var', but
206/// with an explicit range [xmin,xmax] and a default binning of 'nbins'
207
208RooPlot::RooPlot(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nbins)
209 : _plotVar(const_cast<RooAbsRealLValue *>(&var)), _normBinWidth((xmax - xmin) / nbins)
210{
211 _hist = new TH1D(histName(),"RooPlot",nbins,xmin,xmax) ;
212 _hist->Sumw2(false) ;
213 _hist->GetSumw2()->Set(0) ;
214 _hist->SetDirectory(nullptr);
215
216 // In the past, the plot variable was cloned, but there was no apparent reason for doing so.
217
218 TString xtitle= var.getTitle(true);
219 SetXTitle(xtitle.Data());
220
221 TString title("A RooPlot of \"");
222 title.Append(var.getTitle());
223 title.Append("\"");
224 SetTitle(title.Data());
225 initialize();
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Create a new frame for a given variable in x. This is just a
230/// wrapper for the RooPlot constructor with the same interface.
231///
232/// More details.
233/// \param[in] var The variable on the x-axis
234/// \param[in] xmin Left edge of the x-axis
235/// \param[in] xmax Right edge of the x-axis
236/// \param[in] nBins number of bins on the x-axis
237RooPlot* RooPlot::frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins){
238 return new RooPlot(var,xmin,xmax,nBins);
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Create a new frame for a given variable in x, adding bin labels.
243/// The binning will be extracted from the variable given. The bin
244/// labels will be set as "%g-%g" for the left and right edges of each
245/// bin of the given variable.
246///
247/// More details.
248/// \param[in] var The variable on the x-axis
250 RooPlot* pl = new RooPlot();
251 int nbins = var.getBinning().numBins();
252
253 pl->_hist = new TH1D(pl->histName(),"RooPlot",nbins,var.getMin(),var.getMax()) ;
254 pl->_hist->Sumw2(false) ;
255 pl->_hist->GetSumw2()->Set(0) ;
256 pl->_hist->SetDirectory(nullptr);
257
258 pl->_hist->SetNdivisions(-nbins);
259 for(int i=0; i<nbins; ++i){
260 TString s = TString::Format("%g-%g",var.getBinning().binLow(i),var.getBinning().binHigh(i));
261 pl->_hist->GetXaxis()->SetBinLabel(i+1,s);
262 }
263
264 // In the past, the plot variable was cloned, but there was no apparent reason for doing so.
265 pl->_plotVar = const_cast<RooAbsRealLValue*>(&var);
266
267 TString xtitle= var.getTitle(true);
268 pl->SetXTitle(xtitle.Data());
269
270 TString title("A RooPlot of \"");
271 title.Append(var.getTitle());
272 title.Append("\"");
273 pl->SetTitle(title.Data());
274 pl->initialize();
275
276 pl->_normBinWidth = 1.;
277 return pl;
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Return empty clone of current RooPlot
282
284{
286 clone->SetName(name) ;
287 return clone ;
288}
289
290
291////////////////////////////////////////////////////////////////////////////////
292/// Perform initialization that is common to all constructors.
293
295{
296 SetName(histName()) ;
297
300 }
301
302 // We do not have useful stats of our own
303 _hist->SetStats(false);
304 _hist->SetDirectory(nullptr);
305 // Default vertical padding of our enclosed objects
306 setPadFactor(0.05);
307}
308
309
310////////////////////////////////////////////////////////////////////////////////
311/// Construct automatic name of internal TH1
312
314{
315 if (_plotVar) {
316 return TString(Form("frame_%s_%zx",_plotVar->GetName(),reinterpret_cast<size_t>(this))) ;
317 } else {
318 return TString(Form("frame_%zx",reinterpret_cast<size_t>(this))) ;
319 }
320}
321
322
323////////////////////////////////////////////////////////////////////////////////
324/// Destructor
325
327{
328 // Delete the items in our container and our iterator.
329 if (_dir) {
330 _dir->GetList()->RecursiveRemove(this) ;
331 }
332
333 for(auto& item : _items) delete item.first;
334 if(_plotVarSet) delete _plotVarSet;
335 if(_normVars) delete _normVars;
336 delete _hist ;
337
338}
339
340
341////////////////////////////////////////////////////////////////////////////////
342/// Set the directory that this plot is associated to.
343/// Setting it to `nullptr` will remove the object from all directories.
344/// Like TH1::SetDirectory.
346 if (_dir) {
347 _dir->GetList()->RecursiveRemove(this);
348 }
349 _dir = dir;
350 if (_dir) {
351 _dir->Append(this);
352 }
353}
354
355
356////////////////////////////////////////////////////////////////////////////////
357/// Install the given set of observables are reference normalization
358/// variables for this frame. These observables are e.g. later used
359/// to automatically project out observables when plotting functions
360/// on this frame. This function is only effective when called the
361/// first time on a frame
362
364{
365 if(_normVars == nullptr) {
366 _normVars = new RooArgSet;
367 vars.snapshot(*_normVars, true);
368 }
369}
370
371
372////////////////////////////////////////////////////////////////////////////////
373/// Add a generic object to this plot. The specified options will be
374/// used to Draw() this object later. The caller transfers ownership
375/// of the object with this call, and the object will be deleted
376/// when its containing plot object is destroyed.
377
378void RooPlot::addObject(TObject *obj, Option_t *drawOptions, bool invisible)
379{
380 if(nullptr == obj) {
381 coutE(InputArguments) << fName << "::addObject: called with a null pointer" << endl;
382 return;
383 }
384 DrawOpt opt(drawOptions) ;
385 opt.invisible = invisible ;
386 _items.emplace_back(obj,opt.rawOpt());
387}
388
389
390////////////////////////////////////////////////////////////////////////////////
391/// Add a TH1 histogram object to this plot. The specified options
392/// will be used to Draw() this object later. "SAME" will be added to
393/// the options if they are not already present. The caller transfers
394/// ownership of the object with this call, and the object will be
395/// deleted when its containing plot object is destroyed.
396
397void RooPlot::addTH1(TH1 *hist, Option_t *drawOptions, bool invisible)
398{
399 if(nullptr == hist) {
400 coutE(InputArguments) << fName << "::addTH1: called with a null pointer" << endl;
401 return;
402 }
403 // check that this histogram is really 1D
404 if(1 != hist->GetDimension()) {
405 coutE(InputArguments) << fName << "::addTH1: cannot plot histogram with "
406 << hist->GetDimension() << " dimensions" << endl;
407 return;
408 }
409
410 // add option "SAME" if necessary
411 TString options(drawOptions);
412 options.ToUpper();
413 if(!options.Contains("SAME")) options.Append("SAME");
414
415 // update our y-axis label and limits
416 updateYAxis(hist->GetMinimum(),hist->GetMaximum(),hist->GetYaxis()->GetTitle());
417
418 // use this histogram's normalization if necessary
419 updateFitRangeNorm(hist);
420
421 // add the histogram to our list
422 addObject(hist,options.Data(),invisible);
423}
424
425
426namespace {
427 // this helper function is intended to translate a graph from a regular axis to a labelled axis
428 // this version uses TGraph, which is a parent of RooCurve
429 void translateGraph(TH1* hist, RooAbsRealLValue* xvar, TGraph* graph){
430 // if the graph already has a labelled axis, don't do anything
431 if(graph->GetXaxis()->IsAlphanumeric()) return;
432 double xmin = hist->GetXaxis()->GetXmin();
433 double xmax = hist->GetXaxis()->GetXmax();
434 if(graph->TestBit(TGraph::kIsSortedX)){
435 // sorted graphs are "line graphs"
436 // evaluate the graph at the lower and upper edge as well as the center of each bin
437 std::vector<double> x;
438 std::vector<double> y;
439 x.push_back(xmin);
440 y.push_back(graph->Eval(xvar->getBinning().binLow(0)));
441 for(int i=0; i<hist->GetNbinsX(); ++i){
442 x.push_back(hist->GetXaxis()->GetBinUpEdge(i+1));
443 y.push_back(graph->Eval(xvar->getBinning().binHigh(i)));
444 x.push_back(hist->GetXaxis()->GetBinCenter(i+1));
445 y.push_back(graph->Eval(xvar->getBinning().binCenter(i)));
446 }
447 int n = x.size();
448 graph->Set(n);
449 for(int i=0; i<n; ++i){
450 graph->SetPoint(i,x[i],y[i]);
451 }
452 graph->Sort();
453 } else {
454 // unsorted graphs are "area graphs"
455 std::map<int,double> minValues;
456 std::map<int,double> maxValues;
457 int n = graph->GetN();
458 double x;
459 double y;
460 // for each bin, find the min and max points to form an envelope
461 for(int i=0; i<n; ++i){
462 graph->GetPoint(i,x,y);
463 int bin = xvar->getBinning().binNumber(x)+1;
464 if(maxValues.find(bin)!=maxValues.end()){
465 maxValues[bin] = std::max(maxValues[bin],y);
466 } else {
467 maxValues[bin] = y;
468 }
469 if(minValues.find(bin)!=minValues.end()){
470 minValues[bin] = std::min(minValues[bin],y);
471 } else {
472 minValues[bin] = y;
473 }
474 }
475 double xminY = graph->Eval(xmin);
476 double xmaxY = graph->Eval(xmax);
477 graph->Set(hist->GetNbinsX()+2);
478 int np=0;
479 graph->SetPoint(np,xmin,xminY);
480 // assign the calculated envelope boundaries to the bin centers of the bins
481 for(auto it = maxValues.begin(); it != maxValues.end(); ++it){
482 graph->SetPoint(++np,hist->GetXaxis()->GetBinCenter(it->first),it->second);
483 }
484 graph->SetPoint(++np,xmax,xmaxY);
485 for(auto it = minValues.rbegin(); it != minValues.rend(); ++it){
486 graph->SetPoint(++np,hist->GetXaxis()->GetBinCenter(it->first),it->second);
487 }
488 graph->SetPoint(++np,xmin,xminY);
489 }
490 // make sure that the graph also has the labels set, such that subsequent calls to translate this graph will not do anything
491 graph->GetXaxis()->Set(hist->GetNbinsX(),xmin,xmax);
492 for(int i=0; i<hist->GetNbinsX(); ++i){
493 graph->GetXaxis()->SetBinLabel(i+1,hist->GetXaxis()->GetBinLabel(i+1));
494 }
495 }
496 // this version uses TGraphErrors, which is a parent of RooHist
497 void translateGraph(TH1* hist, RooAbsRealLValue* xvar, TGraphAsymmErrors* graph){
498 // if the graph already has a labelled axis, don't do anything
499 if(graph->GetXaxis()->IsAlphanumeric()) return;
500 int n = graph->GetN();
501 double xmin = hist->GetXaxis()->GetXmin();
502 double xmax = hist->GetXaxis()->GetXmax();
503 double x;
504 double y;
505 // as this graph is histogram-like, we expect there to be one point per bin
506 // we just move these points to the respective bin centers
507 for(int i=0; i<n; ++i){
508 if(graph->GetPoint(i,x,y)!=i) break;
509 int bin = xvar->getBinning().binNumber(x);
510 graph->SetPoint(i,hist->GetXaxis()->GetBinCenter(bin+1),y);
511 graph->SetPointEXhigh(i,0.5*hist->GetXaxis()->GetBinWidth(bin+1));
512 graph->SetPointEXlow(i,0.5*hist->GetXaxis()->GetBinWidth(bin+1));
513 }
514 graph->GetXaxis()->Set(hist->GetNbinsX(),xmin,xmax);
515 // make sure that the graph also has the labels set, such that subsequent calls to translate this graph will not do anything
516 for(int i=0; i<hist->GetNbinsX(); ++i){
517 graph->GetXaxis()->SetBinLabel(i+1,hist->GetXaxis()->GetBinLabel(i+1));
518 }
519 }
520}
521
522////////////////////////////////////////////////////////////////////////////////
523/// Add the specified plotable object to our plot. Increase our y-axis
524/// limits to fit this object if necessary. The default lower-limit
525/// is zero unless we are plotting an object that takes on negative values.
526/// This call transfers ownership of the plotable object to this class.
527/// The plotable object will be deleted when this plot object is deleted.
528void RooPlot::addPlotable(RooPlotable *plotable, Option_t *drawOptions, bool invisible, bool refreshNorm)
529{
530 // update our y-axis label and limits
531 updateYAxis(plotable->getYAxisMin(),plotable->getYAxisMax(),plotable->getYAxisLabel());
532
533 // use this object's normalization if necessary
534 updateFitRangeNorm(plotable,refreshNorm) ;
535
536 // add this element to our list and remember its drawing option
537 TObject *obj= plotable->crossCast();
538 if(nullptr == obj) {
539 coutE(InputArguments) << fName << "::add: cross-cast to TObject failed (nothing added)" << endl;
540 }
541 else {
542 // if the frame axis is alphanumeric, the coordinates of the graph need to be translated to this binning
543 if(_hist->GetXaxis()->IsAlphanumeric()){
544 if(obj->InheritsFrom(RooCurve::Class())){
545 ::translateGraph(_hist,_plotVar,static_cast<RooCurve*>(obj));
546 } else if(obj->InheritsFrom(RooHist::Class())){
547 ::translateGraph(_hist,_plotVar,static_cast<RooHist*>(obj));
548 }
549 }
550
551 DrawOpt opt(drawOptions) ;
552 opt.invisible = invisible ;
553 _items.emplace_back(obj,opt.rawOpt());
554 }
555}
556
557
558////////////////////////////////////////////////////////////////////////////////
559/// Update our plot normalization over our plot variable's fit range,
560/// which will be determined by the first suitable object added to our plot.
561
563{
564 const TAxis* xa = const_cast<TH1 *>(hist)->GetXaxis() ;
565 _normBinWidth = (xa->GetXmax()-xa->GetXmin())/hist->GetNbinsX() ;
567}
568
569
570////////////////////////////////////////////////////////////////////////////////
571/// Update our plot normalization over our plot variable's fit range,
572/// which will be determined by the first suitable object added to our plot.
573
574void RooPlot::updateFitRangeNorm(const RooPlotable* rp, bool refreshNorm)
575{
576 if (_normNumEvts != 0) {
577
578 // If refresh feature is disabled stop here
579 if (!refreshNorm) return ;
580
581 double corFac(1.0) ;
582 if (dynamic_cast<const RooHist*>(rp)) corFac = _normBinWidth/rp->getFitRangeBinW() ;
583
584
585 if (std::abs(rp->getFitRangeNEvt()/corFac-_normNumEvts)>1e-6) {
586 coutI(Plotting) << "RooPlot::updateFitRangeNorm: New event count of " << rp->getFitRangeNEvt()/corFac
587 << " will supersede previous event count of " << _normNumEvts << " for normalization of PDF projections" << endl ;
588 }
589
590 // Nominal bin width (i.e event density) is already locked in by previously drawn histogram
591 // scale this histogram to match that density
592 _normNumEvts = rp->getFitRangeNEvt()/corFac ;
593 _normObj = rp ;
594 // cout << "correction factor = " << _normBinWidth << "/" << rp->getFitRangeBinW() << endl ;
595 // cout << "updating numevts to " << _normNumEvts << endl ;
596
597 } else {
598
599 _normObj = rp ;
601 if (rp->getFitRangeBinW()) {
603 }
604
605 // cout << "updating numevts to " << _normNumEvts << endl ;
606 }
607
608}
609
610
611
612////////////////////////////////////////////////////////////////////////////////
613/// Update our y-axis limits to accommodate an object whose spread
614/// in y is (ymin,ymax). Use the specified y-axis label if we don't
615/// have one assigned already.
616
617void RooPlot::updateYAxis(double ymin, double ymax, const char *label)
618{
619 // force an implicit lower limit of zero if appropriate
620 if(GetMinimum() == 0 && ymin > 0) ymin= 0;
621
622 // calculate padded values
623 double ypad= getPadFactor()*(ymax-ymin);
624 ymax+= ypad;
625 if(ymin < 0) ymin-= ypad;
626
627 // update our limits if necessary
628 if(GetMaximum() < ymax) {
629 _defYmax = ymax ;
631 // if we don't do this - Unzoom on y-axis will reset upper bound to 1
633 }
634 if(GetMinimum() > ymin) {
635 _defYmin = ymin ;
637 }
638
639 // use the specified y-axis label if we don't have one already
640 if(0 == strlen(_hist->GetYaxis()->GetTitle())) _hist->SetYTitle(label);
641}
642
643
644////////////////////////////////////////////////////////////////////////////////
645/// Draw this plot and all of the elements it contains. The specified options
646/// only apply to the drawing of our frame. The options specified in our add...()
647/// methods will be used to draw each object we contain.
648
650{
651 TString optArg = option ;
652 optArg.ToLower() ;
653
654 // This draw options prevents the histogram with one dummy entry
655 // to be drawn
656 if (optArg.Contains("same")) {
657 _hist->Draw("FUNCSAME");
658 } else {
659 _hist->Draw("FUNC");
660 }
661
662 for(auto const& item : _items) {
663 TObject &obj = *item.first;
664 DrawOpt opt(item.second.c_str()) ;
665 if (!opt.invisible) {
666 //LM: in case of a TGraph derived object, do not use default "" option
667 // which is "ALP" from 5.34.10 (and will then redrawn the axis) but use "LP"
668 if (!strlen(opt.drawOptions) && obj.IsA()->InheritsFrom(TGraph::Class()) ) strlcpy(opt.drawOptions,"LP",3);
669 obj.Draw(opt.drawOptions);
670 }
671 }
672
673 _hist->Draw("AXISSAME");
674}
675
676
677
678////////////////////////////////////////////////////////////////////////////////
679/// Print frame name
680
681void RooPlot::printName(ostream& os) const
682{
683 os << GetName() ;
684}
685
686
687////////////////////////////////////////////////////////////////////////////////
688/// Print frame title
689
690void RooPlot::printTitle(ostream& os) const
691{
692 os << GetTitle() ;
693}
694
695
696////////////////////////////////////////////////////////////////////////////////
697/// Print frame class name
698
699void RooPlot::printClassName(ostream& os) const
700{
701 os << ClassName() ;
702}
703
704
705
706////////////////////////////////////////////////////////////////////////////////
707
708void RooPlot::printArgs(ostream& os) const
709{
710 if (_plotVar) {
711 os << "[" ;
713 os << "]" ;
714 }
715}
716
717
718
719////////////////////////////////////////////////////////////////////////////////
720/// Print frame arguments
721
722void RooPlot::printValue(ostream& os) const
723{
724 os << "(" ;
725 bool first(true) ;
726 for(auto const& item : _items) {
727 TObject &obj = *item.first;
728 if (first) {
729 first=false ;
730 } else {
731 os << "," ;
732 }
733 if(obj.IsA()->InheritsFrom(RooPrintable::Class())) {
734 auto po = dynamic_cast<RooPrintable&>(obj) ;
735 // coverity[FORWARD_NULL]
737 }
738 // is it a TNamed subclass?
739 else {
740 os << obj.ClassName() << "::" << obj.GetName() ;
741 }
742 }
743 os << ")" ;
744}
745
746
747////////////////////////////////////////////////////////////////////////////////
748/// Frame detailed printing
749
750void RooPlot::printMultiline(ostream& os, Int_t /*content*/, bool verbose, TString indent) const
751{
752 TString deeper(indent);
753 deeper.Append(" ");
754 if(nullptr != _plotVar) {
755 os << indent << "RooPlot " << GetName() << " (" << GetTitle() << ") plots variable ";
757 }
758 else {
759 os << indent << "RooPlot " << GetName() << " (" << GetTitle() << ") has no associated plot variable" << endl ;
760 }
761 os << indent << " Plot frame contains " << _items.size() << " object(s):" << endl;
762
763 if(verbose) {
764 Int_t i=0 ;
765 for(auto const& item : _items) {
766 TObject &obj = *item.first;
767 os << deeper << "[" << i++ << "] (Options=\"" << item.second << "\") ";
768 // Is this a printable object?
769 if(obj.IsA()->InheritsFrom(RooPrintable::Class())) {
770 auto po = dynamic_cast<RooPrintable&>(obj) ;
772 }
773 // is it a TNamed subclass?
774 else {
775 os << obj.ClassName() << "::" << obj.GetName() << endl;
776 }
777 }
778 }
779}
780
781
782
783////////////////////////////////////////////////////////////////////////////////
784/// Return the name of the object at slot 'idx' in this RooPlot.
785/// If the given index is out of range, return a null pointer
786
787const char* RooPlot::nameOf(Int_t idx) const
788{
789 TObject* obj = _items.at(idx).first;
790 if (!obj) {
791 coutE(InputArguments) << "RooPlot::nameOf(" << GetName() << ") index " << idx << " out of range" << endl ;
792 return nullptr ;
793 }
794 return obj->GetName() ;
795}
796
797
798
799////////////////////////////////////////////////////////////////////////////////
800/// Return the name of the object at slot 'idx' in this RooPlot.
801/// If the given index is out of range, return a null pointer
802
804{
805 TObject* obj = _items.at(idx).first;
806 if (!obj) {
807 coutE(InputArguments) << "RooPlot::getObject(" << GetName() << ") index " << idx << " out of range" << endl ;
808 return nullptr ;
809 }
810 return obj ;
811}
812
813
814
815////////////////////////////////////////////////////////////////////////////////
816/// Return a pointer to the line attributes of the named object in this plot,
817/// or zero if the named object does not exist or does not have line attributes.
818
820{
821 return dynamic_cast<TAttLine*>(findObject(name));
822}
823
824
825////////////////////////////////////////////////////////////////////////////////
826/// Return a pointer to the fill attributes of the named object in this plot,
827/// or zero if the named object does not exist or does not have fill attributes.
828
830{
831 return dynamic_cast<TAttFill*>(findObject(name));
832}
833
834
835////////////////////////////////////////////////////////////////////////////////
836/// Return a pointer to the marker attributes of the named object in this plot,
837/// or zero if the named object does not exist or does not have marker attributes.
838
840{
841 return dynamic_cast<TAttMarker*>(findObject(name));
842}
843
844
845////////////////////////////////////////////////////////////////////////////////
846/// Return a pointer to the text attributes of the named object in this plot,
847/// or zero if the named object does not exist or does not have text attributes.
848
850{
851 return dynamic_cast<TAttText*>(findObject(name));
852}
853
854
855
856////////////////////////////////////////////////////////////////////////////////
857/// Return a RooCurve pointer of the named object in this plot,
858/// or zero if the named object does not exist or is not a RooCurve
859
860RooCurve* RooPlot::getCurve(const char* name) const
861{
862 return dynamic_cast<RooCurve*>(findObject(name)) ;
863}
864
865
866////////////////////////////////////////////////////////////////////////////////
867/// Return a RooCurve pointer of the named object in this plot,
868/// or zero if the named object does not exist or is not a RooCurve
869
870RooHist* RooPlot::getHist(const char* name) const
871{
872 return dynamic_cast<RooHist*>(findObject(name)) ;
873}
874
875
876
877////////////////////////////////////////////////////////////////////////////////
878/// Remove object with given name, or last object added if no name is given.
879
880void RooPlot::remove(const char* name, bool deleteToo)
881{
882 if(name == nullptr) {
883 if(!_items.empty()) {
884 if(deleteToo) delete _items.back().first;
885 _items.pop_back();
886 } else {
887 coutE(InputArguments) << "RooPlot::remove(" << GetName() << ") ERROR: plot frame is empty, cannot remove last object" << endl ;
888 }
889 } else {
890 auto item = findItem(name);
891 if(item == _items.end()) {
892 coutE(InputArguments) << "RooPlot::remove(" << GetName() << ") ERROR: no object found with name " << name << endl ;
893 } else {
894 if(deleteToo) delete item->first;
895 _items.erase(item);
896 }
897 }
898}
899
900
901namespace {
902
903template<class Iter>
904void moveBefore(Iter before, Iter target) {
905 auto d = std::distance(before, target);
906 if(d > 0) std::rotate(before, target, target + 1);
907 else if(d < 0) std::rotate(target, target+1, before);
908}
909
910} // namespace
911
912
913////////////////////////////////////////////////////////////////////////////////
914/// Change the order in which our contained objects are drawn so that
915/// the target object is drawn just before the specified object.
916/// Returns false if either object does not exist.
917
918bool RooPlot::drawBefore(const char *before, const char *target)
919{
920 auto iterBefore = findItem(before);
921 auto iterTarget = findItem(target);
922 if(iterBefore == _items.end() || iterTarget == _items.end()) return false;
923 moveBefore(iterBefore, iterTarget);
924 return true;
925}
926
927
928////////////////////////////////////////////////////////////////////////////////
929/// Change the order in which our contained objects are drawn so that
930/// the target object is drawn just after the specified object.
931/// Returns false if either object does not exist.
932
933bool RooPlot::drawAfter(const char *after, const char *target)
934{
935 auto iterAfter = findItem(after);
936 auto iterTarget = findItem(target);
937 if(iterAfter == _items.end() || iterTarget == _items.end()) return false;
938 moveBefore(iterAfter + 1, iterTarget);
939 return true;
940}
941
942
943////////////////////////////////////////////////////////////////////////////////
944/// Find the named object in our list of items and return a pointer
945/// to it. Return zero and print a warning message if the named
946/// object cannot be found. If no name is supplied the last object
947/// added is returned.
948///
949/// Note that the returned pointer is to a
950/// TObject and so will generally need casting. Use the getAtt...()
951/// methods to change the drawing style attributes of a contained
952/// object directly.
953
954TObject *RooPlot::findObject(const char *name, const TClass* tClass) const
955{
956 TObject *ret = nullptr;
957
958 for(auto const& item : _items) {
959 TObject &obj = *item.first;
960 if ((!name || name[0] == '\0' || !TString(name).CompareTo(obj.GetName()))
961 && (!tClass || (obj.IsA()==tClass))) {
962 ret = &obj ;
963 }
964 }
965
966 if (ret == nullptr) {
967 coutE(InputArguments) << "RooPlot::findObject(" << GetName() << ") cannot find object " << (name?name:"<last>") << endl ;
968 }
969 return ret ;
970}
971
972
973RooPlot::Items::iterator RooPlot::findItem(std::string const& name)
974{
975 return std::find_if(_items.begin(), _items.end(), [&name](auto const& item){
976 return name == item.first->GetName();
977 });
978}
979
980RooPlot::Items::const_iterator RooPlot::findItem(std::string const& name) const
981{
982 return std::find_if(_items.begin(), _items.end(), [&name](auto const& item){
983 return name == item.first->GetName();
984 });
985}
986
987
988////////////////////////////////////////////////////////////////////////////////
989/// Return the Draw() options registered for the named object. Return
990/// an empty string if the named object cannot be found.
991
993{
994 auto item = findItem(name);
995 if(item == _items.end()) return "";
996
997 return DrawOpt{item->second.c_str()}.drawOptions;
998}
999
1000
1001////////////////////////////////////////////////////////////////////////////////
1002/// Register the specified drawing options for the named object.
1003/// Return false if the named object cannot be found.
1004
1005bool RooPlot::setDrawOptions(const char *name, TString options)
1006{
1007 auto item = findItem(name);
1008 if(item == _items.end()) return false;
1009
1010 DrawOpt opt(item->second.c_str()) ;
1011 strlcpy(opt.drawOptions,options,128) ;
1012 item->second = opt.rawOpt();
1013 return true;
1014}
1015
1016
1017////////////////////////////////////////////////////////////////////////////////
1018/// Returns true of object with given name is set to be invisible
1019
1020bool RooPlot::getInvisible(const char* name) const
1021{
1022 auto item = findItem(name);
1023 if(item == _items.end()) return false;
1024
1025 return DrawOpt{item->second.c_str()}.invisible ;
1026}
1027
1028
1029////////////////////////////////////////////////////////////////////////////////
1030/// If flag is true object with 'name' is set to be invisible
1031/// i.e. it is not drawn when Draw() is called
1032
1033void RooPlot::setInvisible(const char* name, bool flag)
1034{
1035 auto item = findItem(name);
1036 if(item != _items.end()) {
1037 DrawOpt opt;
1038 opt.initialize(item->second.c_str());
1039 opt.invisible = flag;
1040 item->second = opt.rawOpt();
1041 }
1042
1043}
1044
1045
1046////////////////////////////////////////////////////////////////////////////////
1047/// Set maximum value of Y axis
1048
1049void RooPlot::SetMaximum(double maximum)
1050{
1051 _hist->SetMaximum(maximum==-1111?_defYmax:maximum) ;
1052}
1053
1054
1055
1056////////////////////////////////////////////////////////////////////////////////
1057/// Set minimum value of Y axis
1058
1059void RooPlot::SetMinimum(double minimum)
1060{
1061 _hist->SetMinimum(minimum==-1111?_defYmin:minimum) ;
1062}
1063
1064
1065
1066////////////////////////////////////////////////////////////////////////////////
1067/// Calculate and return reduced chi-squared between a curve and a histogram.
1068///
1069/// \param[in] curvename Name of the curve or nullptr for last curve
1070/// \param[in] histname Name of the histogram to compare to or nullptr for last added histogram
1071/// \param[in] nFitParam If non-zero, reduce the number of degrees of freedom by this
1072/// number. This means that the curve was fitted to the data with nFitParam floating
1073/// parameters, which needs to be reflected in the calculation of \f$\chi^2 / \mathrm{ndf}\f$.
1074///
1075/// \return \f$ \chi^2 / \mathrm{ndf} \f$ between the plotted curve and the data.
1076///
1077/// \note The \f$ \chi^2 \f$ is calculated between a *plot of the original distribution* and the data.
1078/// It therefore has more rounding errors than directly calculating the \f$ \chi^2 \f$ from a PDF or
1079/// function. To do this, use RooAbsReal::createChi2(RooDataHist&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&, const RooCmdArg&).
1080double RooPlot::chiSquare(const char* curvename, const char* histname, int nFitParam) const
1081{
1082
1083 // Find curve object
1084 RooCurve* curve = static_cast<RooCurve*>(findObject(curvename,RooCurve::Class())) ;
1085 if (!curve) {
1086 coutE(InputArguments) << "RooPlot::chiSquare(" << GetName() << ") cannot find curve" << endl ;
1087 return -1. ;
1088 }
1089
1090 // Find histogram object
1091 RooHist* hist = static_cast<RooHist*>(findObject(histname,RooHist::Class())) ;
1092 if (!hist) {
1093 coutE(InputArguments) << "RooPlot::chiSquare(" << GetName() << ") cannot find histogram" << endl ;
1094 return -1. ;
1095 }
1096
1097 return curve->chiSquare(*hist,nFitParam) ;
1098}
1099
1100
1101////////////////////////////////////////////////////////////////////////////////
1102/// Return a RooHist (derives from TGraphAsymErrors) containing the residuals of a histogram.
1103/// The plotting range of the graph is adapted to the plotting range of the current plot.
1104///
1105/// \param histname Name of the data histogram.
1106/// Passing an empty string or `nullptr` will create residuals of the last-plotted histogram.
1107/// \param curvename Name of the curve to compare to data.
1108/// Passing an empty string or `nullptr` will create residuals of the last-plotted curve.
1109/// \param normalize If true, the residuals are divided by the error
1110/// of the histogram, effectively returning a pull histogram.
1111/// \param useAverage If true, the histogram is compared with the curve averaged in each bin.
1112/// Otherwise, the curve is evaluated at the bin centres, which is not accurate for strongly curved distributions.
1113RooHist* RooPlot::residHist(const char* histname, const char* curvename, bool normalize, bool useAverage) const
1114{
1115 // Find all curve objects with the name "curvename" or the name of the last
1116 // plotted curve (there might be multiple in the case of multi-range fits).
1117 std::vector<RooCurve *> curves;
1118
1119 for(auto it = _items.rbegin(); it != _items.rend(); ++it) {
1120 TObject &obj = *it->first;
1121 if(obj.IsA() == RooCurve::Class()) {
1122 // If no curvename was passed, we take by default the last curve and all
1123 // other curves that have the same name
1124 if((!curvename || curvename[0] == '\0') || std::string(curvename) == obj.GetName()) {
1125 curvename = obj.GetName();
1126 curves.push_back(static_cast<RooCurve*>(&obj));
1127 }
1128 }
1129 }
1130
1131 if (curves.empty()) {
1132 coutE(InputArguments) << "RooPlot::residHist(" << GetName() << ") cannot find curve" << std::endl;
1133 return nullptr;
1134 }
1135
1136 // Find histogram object
1137 auto hist = static_cast<RooHist*>(findObject(histname,RooHist::Class()));
1138 if (!hist) {
1139 coutE(InputArguments) << "RooPlot::residHist(" << GetName() << ") cannot find histogram" << std::endl;
1140 return nullptr;
1141 }
1142
1143 auto residHist = hist->createEmptyResidHist(*curves.front(), normalize);
1144
1145 // We consider all curves with the same name as long as the ranges don't
1146 // overlap, to create also the full residual plot in multi-range fits.
1147 std::vector<std::pair<double, double>> coveredRanges;
1148 for(RooCurve * curve : curves) {
1149 const double xmin = curve->GetPointX(0);
1150 const double xmax = curve->GetPointX(curve->GetN() - 1);
1151
1152 for(auto const& prevRange : coveredRanges) {
1153 const double pxmin = prevRange.first;
1154 const double pxmax = prevRange.second;
1155 // If either xmin or xmax is within any previous range, the ranges
1156 // overloap and it makes to sense to also consider this curve for the
1157 // residuals (i.e., they can't come from a multi-range fit).
1158 if((pxmax > xmin && pxmin <= xmin) || (pxmax > xmax && pxmin <= xmax)) {
1159 continue;
1160 }
1161 }
1162
1163 coveredRanges.emplace_back(xmin, xmax);
1164
1165 hist->fillResidHist(*residHist, *curve, normalize, useAverage);
1166 }
1169 residHist->GetHistogram()->GetYaxis()->SetTitle(normalize ? "(Data - curve) / #sigma_{data}" : "Data - curve");
1170 return residHist.release();
1171}
1172
1173
1174
1175////////////////////////////////////////////////////////////////////////////////
1176/// Initialize the DrawOpt helper class
1177
1178void RooPlot::DrawOpt::initialize(const char* inRawOpt)
1179{
1180 if (!inRawOpt) {
1181 drawOptions[0] = 0 ;
1182 invisible=false ;
1183 return ;
1184 }
1185 strlcpy(drawOptions,inRawOpt,128) ;
1186 strtok(drawOptions,":") ;
1187 const char* extraOpt = strtok(nullptr,":") ;
1188 if (extraOpt) {
1189 invisible = (extraOpt[0]=='I') ;
1190 }
1191}
1192
1193
1194////////////////////////////////////////////////////////////////////////////////
1195/// Return the raw draw options
1196
1197const char* RooPlot::DrawOpt::rawOpt() const
1198{
1199 static char buf[128] ;
1200 strlcpy(buf,drawOptions,128) ;
1201 if (invisible) {
1202 strlcat(buf,":I",128) ;
1203 }
1204 return buf ;
1205}
1206
1207
1208
1209////////////////////////////////////////////////////////////////////////////////
1210/// Return the number of events that is associated with the range [xlo,xhi]
1211/// This method is only fully functional for ranges not equal to the full
1212/// range if the object that inserted the normalization data provided
1213/// a link to an external object that can calculate the event count in
1214/// in sub ranges. An error will be printed if this function is used
1215/// on sub-ranges while that information is not available
1216
1217double RooPlot::getFitRangeNEvt(double xlo, double xhi) const
1218{
1219 double scaleFactor = 1.0 ;
1220 if (_normObj) {
1221 scaleFactor = _normObj->getFitRangeNEvt(xlo,xhi)/_normObj->getFitRangeNEvt() ;
1222 } else {
1223 coutW(Plotting) << "RooPlot::getFitRangeNEvt(" << GetName() << ") WARNING: Unable to obtain event count in range "
1224 << xlo << " to " << xhi << ", substituting full event count" << endl ;
1225 }
1226 return getFitRangeNEvt()*scaleFactor ;
1227}
1228
1229
1230////////////////////////////////////////////////////////////////////////////////
1231/// Set the name of the RooPlot to 'name'
1232
1233void RooPlot::SetName(const char *name)
1234{
1235 if (_dir) _dir->GetList()->Remove(this);
1237 if (_dir) _dir->GetList()->Add(this);
1238}
1239
1240
1241////////////////////////////////////////////////////////////////////////////////
1242/// Set the name and title of the RooPlot to 'name' and 'title'
1243
1244void RooPlot::SetNameTitle(const char *name, const char* title)
1245{
1246 if (_dir) _dir->GetList()->Remove(this);
1247 TNamed::SetNameTitle(name,title) ;
1248 if (_dir) _dir->GetList()->Add(this);
1249}
1250
1251
1252////////////////////////////////////////////////////////////////////////////////
1253/// Set the title of the RooPlot to 'title'
1254
1255void RooPlot::SetTitle(const char* title)
1256{
1257 TNamed::SetTitle(title) ;
1258 _hist->SetTitle(title) ;
1259}
1260
1261
1262
1263////////////////////////////////////////////////////////////////////////////////
1264/// Define default print options, for a given print style
1265
1267{
1268 return kName|kArgs|kValue ;
1269}
1270
1271
1272
1273/// \see TH1::GetXaxis()
1274TAxis* RooPlot::GetXaxis() const { return _hist->GetXaxis() ; }
1275/// \see TH1::GetYaxis()
1276TAxis* RooPlot::GetYaxis() const { return _hist->GetYaxis() ; }
1277/// \see TH1::GetNbinsX()
1279/// \see TH1::GetNdivisions()
1281/// \see TH1::GetMinimum()
1282double RooPlot::GetMinimum(double minval) const { return _hist->GetMinimum(minval) ; }
1283/// \see TH1::GetMaximum()
1284double RooPlot::GetMaximum(double maxval) const { return _hist->GetMaximum(maxval) ; }
1285
1286
1287/// \see TH1::SetAxisColor()
1288void RooPlot::SetAxisColor(Color_t color, Option_t* axis) { _hist->SetAxisColor(color,axis) ; }
1289/// \see TH1::SetAxisRange()
1290void RooPlot::SetAxisRange(double xmin, double xmax, Option_t* axis) { _hist->SetAxisRange(xmin,xmax,axis) ; }
1291/// \see TH1::SetBarOffset()
1293/// \see TH1::SetBarWidth()
1295/// \see TH1::SetContour()
1296void RooPlot::SetContour(Int_t nlevels, const double* levels) { _hist->SetContour(nlevels,levels) ; }
1297/// \see TH1::SetContourLevel()
1299/// \see TH1::SetDrawOption()
1301/// \see TH1::SetFillAttributes()
1303/// \see TH1::SetFillColor()
1305/// \see TH1::SetFillStyle()
1307/// \see TH1::SetLabelColor()
1308void RooPlot::SetLabelColor(Color_t color, Option_t* axis) { _hist->SetLabelColor(color,axis) ; }
1309/// \see TH1::SetLabelFont()
1310void RooPlot::SetLabelFont(Style_t font, Option_t* axis) { _hist->SetLabelFont(font,axis) ; }
1311/// \see TH1::SetLabelOffset()
1313/// \see TH1::SetLabelSize()
1315/// \see TH1::SetLineAttributes()
1317/// \see TH1::SetLineColor()
1319/// \see TH1::SetLineStyle()
1321/// \see TH1::SetLineWidth()
1323/// \see TH1::SetMarkerAttributes()
1325/// \see TH1::SetMarkerColor()
1327/// \see TH1::SetMarkerSize()
1329/// \see TH1::SetMarkerStyle()
1331/// \see TH1::SetNdivisions()
1333/// \see TH1::SetOption()
1335/// Like TH1::SetStats(), but statistics boxes are *off* by default in RooFit.
1336void RooPlot::SetStats(bool stats) { _hist->SetStats(stats) ; }
1337/// \see TH1::SetTickLength()
1339/// \see TH1::SetTitleFont()
1340void RooPlot::SetTitleFont(Style_t font, Option_t* axis) { _hist->SetTitleFont(font,axis) ; }
1341/// \see TH1::SetTitleOffset()
1343/// \see TH1::SetTitleSize()
1345/// \see TH1::SetXTitle()
1346void RooPlot::SetXTitle(const char *title) { _hist->SetXTitle(title) ; }
1347/// \see TH1::SetYTitle()
1348void RooPlot::SetYTitle(const char *title) { _hist->SetYTitle(title) ; }
1349/// \see TH1::SetZTitle()
1350void RooPlot::SetZTitle(const char *title) { _hist->SetZTitle(title) ; }
1351
1352
1353
1354
1355////////////////////////////////////////////////////////////////////////////////
1356/// Plot RooPlot when double-clicked in browser
1357
1359{
1360 Draw();
1361 gPad->Update();
1362}
1363
1364
1365
1366
1367////////////////////////////////////////////////////////////////////////////////
1368
1370{
1371 // Custom streamer, needed for backward compatibility
1372
1373 if (R__b.IsReading()) {
1374 const bool oldAddDir = TH1::AddDirectoryStatus();
1375 TH1::AddDirectory(false);
1376
1377 // The default c'tor might have registered this with a TDirectory.
1378 // Streaming the TNamed will make this not retrievable anymore, so
1379 // unregister first.
1380 if (_dir)
1381 _dir->Remove(this);
1382
1383 UInt_t R__s;
1384 UInt_t R__c;
1385 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1386 if (R__v > 1) {
1387 R__b.ReadClassBuffer(RooPlot::Class(),this,R__v,R__s,R__c);
1388 } else {
1389 // backward compatible streamer code here
1390 // Version 1 of RooPlot was deriving from TH1 and RooPrintable
1391 // Version 2 derives instead from TNamed and RooPrintable
1392 _hist = new TH1F();
1393 _hist->TH1::Streamer(R__b);
1394 SetName(_hist->GetName());
1397 {
1398 TList itemsList;
1399 itemsList.Streamer(R__b);
1401 }
1402 R__b >> _padFactor;
1403 R__b >> _plotVar;
1404 R__b >> _plotVarSet;
1405 R__b >> _normVars;
1406 R__b >> _normNumEvts;
1407 R__b >> _normBinWidth;
1408 R__b >> _defYmin;
1409 R__b >> _defYmax;
1410 R__b.CheckByteCount(R__s, R__c, RooPlot::IsA());
1411 }
1412
1413 TH1::AddDirectory(oldAddDir);
1414 if (_dir)
1415 _dir->Append(this);
1416
1417 } else {
1418 R__b.WriteClassBuffer(RooPlot::Class(),this);
1419 }
1420}
1421
1422////////////////////////////////////////////////////////////////////////////////
1423/// Build a legend that contains all objects that have been drawn on the plot.
1424std::unique_ptr<TLegend> RooPlot::BuildLegend() const {
1425 auto leg = std::make_unique<TLegend>(0.5, 0.7, 0.9, 0.9);
1426 leg->SetBorderSize(0);
1427 leg->SetFillStyle(0);
1428 for (std::size_t i=0; i < _items.size(); ++i) {
1429 leg->AddEntry(getObject(i));
1430 }
1431
1432 return leg;
1433}
1434
1435/// RooFit-internal function for backwards compatibility.
1437 for(TObject * obj : tlist) {
1438 items.emplace_back(obj, obj->GetOption());
1439 }
1440}
1441
1442/// Replaces the pointer to the plot variable with a pointer to a clone of the
1443/// plot variable that is owned by this RooPlot. The RooPlot references the
1444/// plotted variable by non-owning pointer by default since ROOT 6.28, which
1445/// resulted in a big speedup when plotting complicated pdfs that are expensive
1446/// to clone. However, going back to an owned clone is useful in rare cases.
1447/// For example in the RooUnitTest, where the registered plots need to live
1448/// longer than the scope of the unit test.
1450 // If the plot variable is already cloned, we don't need to do anything.
1451 if(_plotVarSet) return;
1452 _plotVarSet = static_cast<RooArgSet*>(RooArgSet(*_plotVar).snapshot());
1454}
#define d(i)
Definition RSha256.hxx:102
#define e(i)
Definition RSha256.hxx:103
TObject * clone(const char *newname) const override
Definition RooChi2Var.h:9
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define coutI(a)
#define coutW(a)
#define coutE(a)
short Style_t
Definition RtypesCore.h:89
short Color_t
Definition RtypesCore.h:92
float Size_t
Definition RtypesCore.h:96
short Version_t
Definition RtypesCore.h:65
short Width_t
Definition RtypesCore.h:91
float Float_t
Definition RtypesCore.h:57
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
static void indent(ostringstream &buf, int indent_level)
#define gDirectory
Definition TDirectory.h:384
Option_t Option_t option
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
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 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 winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t width
char name[80]
Definition TGX11.cxx:110
float xmin
float ymin
float xmax
float ymax
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
#define gPad
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
RooAbsArg * find(const char *name) const
Find object with given name in list.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual const RooAbsBinning & getBinning(const char *name=nullptr, bool verbose=true, bool createOnTheFly=false) const =0
Retrieve binning configuration with given name or default binning.
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.
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.
Definition RooArgSet.h:55
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Definition RooArgSet.h:178
One-dimensional graphical representation of a real-valued function.
Definition RooCurve.h:36
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...
Definition RooCurve.cxx:528
static TClass * Class()
Graphical representation of binned data based on the TGraphAsymmErrors class.
Definition RooHist.h:29
static TClass * Class()
char drawOptions[128]
Definition RooPlot.h:220
void initialize(const char *_rawOpt)
Initialize the DrawOpt helper class.
Definition RooPlot.cxx:1178
const char * rawOpt() const
Return the raw draw options.
Definition RooPlot.cxx:1197
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
RooPlot()
Default constructor coverity[UNINIT_CTOR].
Definition RooPlot.cxx:87
void SetName(const char *name) override
Set the name of the RooPlot to 'name'.
Definition RooPlot.cxx:1233
void SetAxisColor(Color_t color=1, Option_t *axis="X")
Definition RooPlot.cxx:1288
void remove(const char *name=nullptr, bool deleteToo=true)
Remove object with given name, or last object added if no name is given.
Definition RooPlot.cxx:880
void SetDrawOption(Option_t *option="") override
Definition RooPlot.cxx:1300
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).
Definition RooPlot.cxx:617
Items _items
A list of the items we contain.
Definition RooPlot.h:235
void SetMarkerSize(Size_t msize=1)
Definition RooPlot.cxx:1328
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:237
const RooPlotable * _normObj
! Pointer to normalization object ;
Definition RooPlot.h:241
double _normNumEvts
Number of events in histogram (for normalization)
Definition RooPlot.h:242
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...
Definition RooPlot.cxx:918
bool getInvisible(const char *name) const
Returns true of object with given name is set to be invisible.
Definition RooPlot.cxx:1020
void SetTitle(const char *name) override
Set the title of the RooPlot to 'title'.
Definition RooPlot.cxx:1255
RooArgSet * _normVars
Variables that PDF plots should be normalized over.
Definition RooPlot.h:239
void addObject(TObject *obj, Option_t *drawOptions="", bool invisible=false)
Add a generic object to this plot.
Definition RooPlot.cxx:378
void addTH1(TH1 *hist, Option_t *drawOptions="", bool invisible=false)
Add a TH1 histogram object to this plot.
Definition RooPlot.cxx:397
double _padFactor
Scale our y-axis to _padFactor of our maximum contents.
Definition RooPlot.h:236
void SetMarkerColor(Color_t tcolor=1)
Definition RooPlot.cxx:1326
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Frame detailed printing.
Definition RooPlot.cxx:750
void SetXTitle(const char *title)
Definition RooPlot.cxx:1346
void SetFillColor(Color_t fcolor)
Definition RooPlot.cxx:1304
RooArgSet * _plotVarSet
A list owning the cloned tree nodes of the plotVarClone.
Definition RooPlot.h:238
void SetNdivisions(Int_t n=510, Option_t *axis="X")
Definition RooPlot.cxx:1332
TDirectory * _dir
! non-persistent
Definition RooPlot.h:248
TString histName() const
Construct automatic name of internal TH1.
Definition RooPlot.cxx:313
TH1 * _hist
Histogram that we uses as basis for drawing the content.
Definition RooPlot.h:234
void SetMarkerStyle(Style_t mstyle=1)
Definition RooPlot.cxx:1330
void printName(std::ostream &os) const override
Print frame name.
Definition RooPlot.cxx:681
TString getDrawOptions(const char *name) const
Return the Draw() options registered for the named object.
Definition RooPlot.cxx:992
double _normBinWidth
Histogram bin width (for normalization)
Definition RooPlot.h:243
void SetZTitle(const char *title)
Definition RooPlot.cxx:1350
void setInvisible(const char *name, bool flag=true)
If flag is true object with 'name' is set to be invisible i.e.
Definition RooPlot.cxx:1033
void Streamer(TBuffer &) override
Stream an object of class TObject.
Definition RooPlot.cxx:1369
void SetContour(Int_t nlevels, const double *levels=nullptr)
Definition RooPlot.cxx:1296
void printClassName(std::ostream &os) const override
Print frame class name.
Definition RooPlot.cxx:699
bool setDrawOptions(const char *name, TString options)
Register the specified drawing options for the named object.
Definition RooPlot.cxx:1005
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.
Definition RooPlot.cxx:954
void SetStats(bool stats=true)
Like TH1::SetStats(), but statistics boxes are off by default in RooFit.
Definition RooPlot.cxx:1336
double getFitRangeNEvt() const
Return the number of events in the fit range.
Definition RooPlot.h:141
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition RooPlot.cxx:1059
std::vector< std::pair< TObject *, std::string > > Items
Definition RooPlot.h:45
double GetMaximum(double maxval=FLT_MAX) const
Definition RooPlot.cxx:1284
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...
Definition RooPlot.cxx:819
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...
Definition RooPlot.cxx:933
RooAbsRealLValue * _plotVar
The variable we are plotting.
Definition RooPlot.h:237
void SetDirectory(TDirectory *dir)
Set the directory that this plot is associated to.
Definition RooPlot.cxx:345
~RooPlot() override
Destructor.
Definition RooPlot.cxx:326
void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Definition RooPlot.cxx:1312
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...
Definition RooPlot.cxx:829
void printTitle(std::ostream &os) const override
Print frame title.
Definition RooPlot.cxx:690
void SetLineWidth(Width_t lwidth)
Definition RooPlot.cxx:1322
void SetTickLength(Float_t length=0.02, Option_t *axis="X")
Definition RooPlot.cxx:1338
void SetFillAttributes()
Definition RooPlot.cxx:1302
void SetContourLevel(Int_t level, double value)
Definition RooPlot.cxx:1298
static bool addDirectoryStatus()
Query whether new instances of RooPlot will add themselves to gDirectory.
Definition RooPlot.cxx:79
void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
Definition RooPlot.cxx:1314
double chiSquare(int nFitParam=0) const
Shortcut for RooPlot::chiSquare(const char* pdfname, const char* histname, int nFitParam=nullptr)
Definition RooPlot.h:176
Items::iterator findItem(std::string const &name)
Definition RooPlot.cxx:973
void SetOption(Option_t *option=" ")
Definition RooPlot.cxx:1334
TObject * getObject(Int_t idx) const
Return the name of the object at slot 'idx' in this RooPlot.
Definition RooPlot.cxx:803
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
Definition RooPlot.cxx:1049
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
void SetLabelFont(Style_t font=62, Option_t *axis="X")
Definition RooPlot.cxx:1310
void Browse(TBrowser *b) override
Plot RooPlot when double-clicked in browser.
Definition RooPlot.cxx:1358
double _defYmax
Default maximum for Yaxis (as calculated from contents)
Definition RooPlot.h:246
void SetLineStyle(Style_t lstyle)
Definition RooPlot.cxx:1320
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...
Definition RooPlot.cxx:839
void SetTitleFont(Style_t font=62, Option_t *axis="X")
Definition RooPlot.cxx:1340
void SetAxisRange(double xmin, double xmax, Option_t *axis="X")
Definition RooPlot.cxx:1290
TAxis * GetXaxis() const
Definition RooPlot.cxx:1274
void SetLineColor(Color_t lcolor)
Definition RooPlot.cxx:1318
void SetFillStyle(Style_t fstyle)
Definition RooPlot.cxx:1306
const char * nameOf(Int_t idx) const
Return the name of the object at slot 'idx' in this RooPlot.
Definition RooPlot.cxx:787
void updateNormVars(const RooArgSet &vars)
Install the given set of observables are reference normalization variables for this frame.
Definition RooPlot.cxx:363
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.
Definition RooPlot.cxx:1113
RooPlot * emptyClone(const char *name)
Return empty clone of current RooPlot.
Definition RooPlot.cxx:283
void SetMarkerAttributes()
Definition RooPlot.cxx:1324
void createInternalPlotVarClone()
Replaces the pointer to the plot variable with a pointer to a clone of the plot variable that is owne...
Definition RooPlot.cxx:1449
void SetNameTitle(const char *name, const char *title) override
Set the name and title of the RooPlot to 'name' and 'title'.
Definition RooPlot.cxx:1244
void setPadFactor(double factor)
Definition RooPlot.h:146
Int_t defaultPrintContents(Option_t *opt) const override
Define default print options, for a given print style.
Definition RooPlot.cxx:1266
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...
Definition RooPlot.cxx:860
static bool setAddDirectoryStatus(bool flag)
Configure whether new instances of RooPlot will add themselves to gDirectory.
Definition RooPlot.cxx:80
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...
Definition RooPlot.cxx:849
void SetLabelColor(Color_t color=1, Option_t *axis="X")
Definition RooPlot.cxx:1308
TClass * IsA() const override
Definition RooPlot.h:252
Int_t GetNbinsX() const
Definition RooPlot.cxx:1278
static void fillItemsFromTList(Items &items, TList const &tlist)
RooFit-internal function for backwards compatibility.
Definition RooPlot.cxx:1436
void SetLineAttributes()
Definition RooPlot.cxx:1316
static bool _addDirStatus
static flag controlling AutoDirectoryAdd feature
Definition RooPlot.h:250
void printValue(std::ostream &os) const override
Print frame arguments.
Definition RooPlot.cxx:722
void SetYTitle(const char *title)
Definition RooPlot.cxx:1348
double getPadFactor() const
Definition RooPlot.h:145
void printArgs(std::ostream &os) const override
Interface for printing of object arguments.
Definition RooPlot.cxx:708
std::unique_ptr< TLegend > BuildLegend() const
Build a legend that contains all objects that have been drawn on the plot.
Definition RooPlot.cxx:1424
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...
Definition RooPlot.cxx:870
void updateFitRangeNorm(const TH1 *hist)
Update our plot normalization over our plot variable's fit range, which will be determined by the fir...
Definition RooPlot.cxx:562
void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Definition RooPlot.cxx:1344
double _defYmin
Default minimum for Yaxis (as calculated from contents)
Definition RooPlot.h:245
static TClass * Class()
void SetBarOffset(Float_t offset=0.25)
Definition RooPlot.cxx:1292
void SetBarWidth(Float_t width=0.5)
Definition RooPlot.cxx:1294
Int_t GetNdivisions(Option_t *axis="X") const
Definition RooPlot.cxx:1280
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
Definition RooPlot.cxx:528
void initialize()
Perform initialization that is common to all constructors.
Definition RooPlot.cxx:294
static RooPlot * frameWithLabels(const RooAbsRealLValue &var)
Create a new frame for a given variable in x, adding bin labels.
Definition RooPlot.cxx:249
void SetTitleOffset(Float_t offset=1, Option_t *axis="X")
Definition RooPlot.cxx:1342
double GetMinimum(double minval=-FLT_MAX) const
Definition RooPlot.cxx:1282
Class RooPotable is a base class for objects that can be inserted into RooPlots and take advantage of...
Definition RooPlotable.h:26
virtual double getFitRangeNEvt() const =0
TObject * crossCast()
Return cast of RooPlotable as TObject.
double getYAxisMin() const
Definition RooPlotable.h:38
double getYAxisMax() const
Definition RooPlotable.h:39
const char * getYAxisLabel() const
Definition RooPlotable.h:28
virtual double getFitRangeBinW() const =0
A 'mix-in' base class that define the standard RooFit plotting and printing methods.
static TClass * Class()
virtual void Streamer(TBuffer &)
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
void Set(Int_t n) override
Set size of this array to n doubles.
Definition TArrayD.cxx:106
Fill Area Attributes class.
Definition TAttFill.h:19
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
Definition TAttFill.cxx:254
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:39
Line Attributes class.
Definition TAttLine.h:18
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual void SetLineAttributes()
Invoke the DialogCanvas Line attributes.
Definition TAttLine.cxx:294
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
Marker Attributes class.
Definition TAttMarker.h:19
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerAttributes()
Invoke the DialogCanvas Marker attributes.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:45
Text Attributes class.
Definition TAttText.h:18
Class to manage histogram axis.
Definition TAxis.h:31
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition TAxis.cxx:886
Bool_t IsAlphanumeric() const
Definition TAxis.h:88
const char * GetTitle() const override
Returns title of object.
Definition TAxis.h:135
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition TAxis.cxx:478
Double_t GetXmax() const
Definition TAxis.h:140
const char * GetBinLabel(Int_t bin) const
Return label for bin.
Definition TAxis.cxx:440
Double_t GetXmin() const
Definition TAxis.h:139
virtual void SetRangeUser(Double_t ufirst, Double_t ulast)
Set the viewing range for the axis from ufirst to ulast (in user coordinates, that is,...
Definition TAxis.cxx:1080
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition TAxis.cxx:540
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition TAxis.cxx:528
Using a TBrowser one can browse all ROOT objects.
Definition TBrowser.h:37
Buffer base class used for serializing objects.
Definition TBuffer.h:43
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
Bool_t IsReading() const
Definition TBuffer.h:86
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4874
Describe directory structure in memory.
Definition TDirectory.h:45
virtual TList * GetList() const
Definition TDirectory.h:222
virtual void Append(TObject *obj, Bool_t replace=kFALSE)
Append object to this directory.
virtual TObject * Remove(TObject *)
Remove an object from the in-memory list.
TGraph with asymmetric error bars.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
@ kIsSortedX
Graph is sorted in X points.
Definition TGraph.h:79
virtual TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
Definition TGraph.cxx:1406
1-D histogram with a double per channel (see TH1 documentation)
Definition TH1.h:664
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
virtual void SetLabelFont(Style_t font=62, Option_t *axis="X")
Set font number used to draw axis labels.
Definition Haxis.cxx:249
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8901
virtual void SetBarOffset(Float_t offset=0.25)
Set the bar offset as fraction of the bin width for drawing mode "B".
Definition TH1.h:364
virtual void SetTitleSize(Float_t size=0.02, Option_t *axis="X")
Set the axis' title size.
Definition Haxis.cxx:365
virtual void SetLabelOffset(Float_t offset=0.005, Option_t *axis="X")
Set offset between axis and axis' labels.
Definition Haxis.cxx:267
void SetTitle(const char *title) override
Change/set the title.
Definition TH1.cxx:6682
virtual void SetXTitle(const char *title)
Definition TH1.h:418
virtual Int_t GetDimension() const
Definition TH1.h:283
static void AddDirectory(Bool_t add=kTRUE)
Sets the flag controlling the automatic add of histograms in memory.
Definition TH1.cxx:1292
virtual void SetContourLevel(Int_t level, Double_t value)
Set value for one contour level.
Definition TH1.cxx:8486
TAxis * GetXaxis()
Definition TH1.h:324
virtual void SetNdivisions(Int_t n=510, Option_t *axis="X")
Set the number of divisions to draw an axis.
Definition Haxis.cxx:170
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition TH1.cxx:8509
virtual Int_t GetNbinsX() const
Definition TH1.h:297
virtual void SetMaximum(Double_t maximum=-1111)
Definition TH1.h:403
TAxis * GetYaxis()
Definition TH1.h:325
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3062
virtual Int_t GetNdivisions(Option_t *axis="X") const
Return the number of divisions for "axis".
Definition Haxis.cxx:27
virtual void SetMinimum(Double_t minimum=-1111)
Definition TH1.h:404
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
Definition TH1.cxx:9186
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4419
virtual void SetZTitle(const char *title)
Definition TH1.h:420
virtual TArrayD * GetSumw2()
Definition TH1.h:313
virtual void SetTitleOffset(Float_t offset=1, Option_t *axis="X")
Specify a parameter offset to control the distance between the axis and the axis' title.
Definition Haxis.cxx:345
virtual void SetLabelColor(Color_t color=1, Option_t *axis="X")
Set axis labels color.
Definition Haxis.cxx:226
virtual void SetAxisColor(Color_t color=1, Option_t *axis="X")
Set color to draw the axis line and tick marks.
Definition Haxis.cxx:187
virtual void SetOption(Option_t *option=" ")
Definition TH1.h:411
virtual void SetContour(Int_t nlevels, const Double_t *levels=nullptr)
Set the number and values of contour levels.
Definition TH1.cxx:8447
virtual void SetAxisRange(Double_t xmin, Double_t xmax, Option_t *axis="X")
Set the "axis" range.
Definition Haxis.cxx:201
virtual void SetYTitle(const char *title)
Definition TH1.h:419
virtual void SetTitleFont(Style_t font=62, Option_t *axis="X")
Set the axis' title font.
Definition Haxis.cxx:323
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition TH1.cxx:8599
virtual void SetLabelSize(Float_t size=0.02, Option_t *axis="X")
Set size of axis' labels.
Definition Haxis.cxx:285
virtual void Sumw2(Bool_t flag=kTRUE)
Create structure to store sum of squares of weights.
Definition TH1.cxx:8984
static Bool_t AddDirectoryStatus()
Static function: cannot be inlined on Windows/NT.
Definition TH1.cxx:752
virtual void SetBarWidth(Float_t width=0.5)
Set the width of bars as fraction of the bin width for drawing mode "B".
Definition TH1.h:365
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8954
virtual void SetTickLength(Float_t length=0.02, Option_t *axis="X")
Set the axis' tick marks length.
Definition Haxis.cxx:302
A doubly linked list.
Definition TList.h:38
void Streamer(TBuffer &) override
Stream all objects in the collection to or from the I/O buffer.
Definition TList.cxx:1189
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition TList.cxx:762
void Add(TObject *obj) override
Definition TList.h:81
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition TList.cxx:820
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
const char * GetTitle() const override
Returns title of object.
Definition TNamed.h:48
TString fName
Definition TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:140
virtual void SetNameTitle(const char *name, const char *title)
Set all the TNamed parameters (name and title).
Definition TNamed.cxx:154
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void SetDrawOption(Option_t *option="")
Set drawing option for object.
Definition TObject.cxx:764
virtual TClass * IsA() const
Definition TObject.h:245
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
Basic string class.
Definition TString.h:139
void ToLower()
Change string to lower-case.
Definition TString.cxx:1182
const char * Data() const
Definition TString.h:376
void ToUpper()
Change string to upper case.
Definition TString.cxx:1195
TString & Append(const char *cs)
Definition TString.h:572
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
leg
Definition legend1.C:34
Definition graph.py:1
th1 Draw()