60 _refFile(refFile), _debug(false), _write(writeRef), _verb(
verbose)
67void RooUnitTest::regPlot(
RooPlot* frame,
const char* refName)
70 std::string refNameStr(refName) ;
78 _regPlots.emplace_back(frame,refNameStr);
87void RooUnitTest::regResult(std::unique_ptr<RooFitResult>
r,
const char* refName)
90 _regResults.emplace_back(
r.release(),refName);
97void RooUnitTest::regValue(
double d,
const char* refName)
100 _regValues.emplace_back(
d,refName);
107void RooUnitTest::regTable(
RooTable* t,
const char* refName)
110 _regTables.emplace_back(t,refName) ;
119void RooUnitTest::regWS(
RooWorkspace* ws,
const char* refName)
122 _regWS.emplace_back(ws,refName) ;
131void RooUnitTest::regTH(
TH1* th,
const char* refName)
134 _regTH.emplace_back(th,refName) ;
147 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooWorkspace " << refName
148 <<
" from reference file, skipping " << std::endl ;
158bool RooUnitTest::areTHidentical(
TH1* htest,
TH1* href)
171 if(_verb >= 0) std::cout <<
"KS distances = " << kmax << std::endl;
188 for (
Int_t i=0 ; i<ntest ; i++) {
190 if(_verb >= 0) std::cout <<
"htest[" << i <<
"] = " << htest->
GetBinContent(i) <<
" href[" << i <<
"] = " << href->
GetBinContent(i) << std::endl;
204bool RooUnitTest::runCompTests()
208 auto iter = _regPlots.begin() ;
209 while (iter!=_regPlots.end()) {
216 RooPlot* bmark =
dynamic_cast<RooPlot*
>(_refFile->Get(iter->second.c_str())) ;
218 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooPlot " << iter->second
219 <<
" from reference file, skipping " << std::endl;
226 std::cout <<
"comparing RooPlot " << iter->first <<
" to benchmark " << iter->second <<
" = " << bmark << std::endl ;
227 std::cout <<
"reference: " ; iter->first->
Print() ;
228 std::cout <<
"benchmark: " ; bmark->
Print() ;
231 RooPlot* compPlot = _debug ? iter->first->
emptyClone(
Form(
"%s_comparison",iter->first->GetName())) : nullptr ;
234 Stat_t nItems = iter->first->numItems() ;
235 for (
Stat_t i=0 ; i<nItems ; i++) {
243 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve reference object " << obj->
GetName()
244 <<
" from benchmark RooPlot " << iter->second <<
", skipping" << std::endl;
253 if (!testHist->
isIdentical(*refHist,htol(),_verb >= 0)) {
254 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << obj->
ClassName() <<
"::" << obj->
GetName()
255 <<
" fails comparison with counterpart in reference RooPlot " << bmark->
GetName() << std::endl;
275 if (!testCurve->
isIdentical(*refCurve,ctol(),_verb >= 0)) {
276 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << obj->
ClassName() <<
"::" << obj->
GetName()
277 <<
" fails comparison with counterpart in reference RooPlot " << bmark->
GetName() << std::endl;
299 if (anyFail && compPlot) {
300 std::cout <<
"RooUnitTest INFO: writing comparison plot " << compPlot->
GetName() <<
" of failed test to RooUnitTest_DEBUG.root" << std::endl ;
301 TFile fdbg(
"RooUnitTest_DEBUG.root",
"UPDATE") ;
315 std::cout <<
"RooUnitTest: Writing reference RooPlot " << iter->first <<
" as benchmark " << iter->second << std::endl ;
317 iter->first->
Write(iter->second.c_str()) ;
325 auto iter2 = _regResults.begin() ;
326 while (iter2!=_regResults.end()) {
335 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooFitResult "
336 << iter2->second <<
" from reference file, skipping " << std::endl ;
343 std::cout <<
"comparing RooFitResult " << iter2->first <<
" to benchmark " << iter2->second <<
" = " << bmark << std::endl ;
346 if (!iter2->first->isIdentical(*bmark,fptol(),fctol(),_verb >= 0)) {
348 std::cout <<
"RooUnitTest ERROR: comparison of object " << iter2->first->
ClassName()
349 <<
"::" << iter2->first->GetName() <<
" from result " << iter2->second
350 <<
" fails comparison with counterpart in reference RooFitResult " << bmark->
GetName() << std::endl;
356 delete iter2->first ;
363 std::cout <<
"RooUnitTest: Writing reference RooFitResult " << iter2->first <<
" as benchmark " << iter2->second << std::endl ;
365 iter2->first->Write(iter2->second.c_str()) ;
372 auto iter3 = _regValues.begin() ;
373 while (iter3!=_regValues.end()) {
382 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooDouble " << iter3->second <<
" from reference file, skipping " << std::endl;
389 std::cout <<
"comparing value " << iter3->first <<
" to benchmark " << iter3->second <<
" = " << (
double)(*ref) << std::endl ;
392 if (std::abs(iter3->first - (
double)(*ref))>vtol() ) {
393 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of value " << iter3->first <<
" fails comparison with reference " << ref->
GetName() << std::endl ;
402 std::cout <<
"RooUnitTest: Writing reference double " << iter3->first <<
" as benchmark " << iter3->second << std::endl ;
405 rd->
Write(iter3->second.c_str()) ;
413 auto iter4 = _regTables.begin() ;
414 while (iter4!=_regTables.end()) {
421 RooTable* bmark =
dynamic_cast<RooTable*
>(_refFile->Get(iter4->second.c_str())) ;
423 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooTable " << iter4->second <<
" from reference file, skipping " << std::endl ;
430 std::cout <<
"comparing RooTable " << iter4->first <<
" to benchmark " << iter4->second <<
" = " << bmark << std::endl ;
433 if (!iter4->first->isIdentical(*bmark, _verb >= 0)) {
434 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << iter4->first->
ClassName() <<
"::" << iter4->first->GetName()
435 <<
" fails comparison with counterpart in reference RooTable " << bmark->
GetName() << std::endl ;
437 iter4->first->Print(
"V");
444 delete iter4->first ;
451 std::cout <<
"RooUnitTest: Writing reference RooTable " << iter4->first <<
" as benchmark " << iter4->second << std::endl ;
453 iter4->first->Write(iter4->second.c_str()) ;
461 auto iter5 = _regWS.begin() ;
462 while (iter5!=_regWS.end()) {
468 std::cout <<
"RooUnitTest: Writing reference RooWorkspace " << iter5->first <<
" as benchmark " << iter5->second << std::endl ;
470 iter5->first->Write(iter5->second.c_str()) ;
478 auto iter6 = _regTH.begin() ;
479 while (iter6!=_regTH.end()) {
486 TH1* bmark =
dynamic_cast<TH1*
>(_refFile->Get(iter6->second.c_str())) ;
488 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve TH1 " << iter6->second <<
" from reference file, skipping " << std::endl ;
495 std::cout <<
"comparing TH1 " << iter6->first <<
" to benchmark " << iter6->second <<
" = " << bmark << std::endl ;
498 if (!areTHidentical(iter6->first,bmark)) {
500 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << iter6->first->
ClassName() <<
"::" << iter6->first->GetName()
501 <<
" fails comparison with counterpart in reference TH1 " << bmark->
GetName() << std::endl ;
505 std::cout <<
"RooUnitTest INFO: writing THx " << iter6->first->GetName() <<
" and " << bmark->
GetName()
506 <<
" of failed test to RooUnitTest_DEBUG.root" << std::endl ;
507 TFile fdbg(
"RooUnitTest_DEBUG.root",
"UPDATE") ;
508 iter6->first->SetName(
Form(
"%s_test",iter6->first->GetName())) ;
509 iter6->first->Write() ;
519 delete iter6->first ;
526 std::cout <<
"RooUnitTest: Writing reference TH1 " << iter6->first <<
" as benchmark " << iter6->second << std::endl ;
528 iter6->first->Write(iter6->second.c_str()) ;
544void RooUnitTest::setSilentMode()
557void RooUnitTest::clearSilentMode()
569bool RooUnitTest::runTest()
576 std::cout <<
"*** Begin of output of Unit Test at normal verbosity *************" << std::endl ;
586 if (!testCode())
return false ;
592 std::cout <<
"*** End of output of Unit Test at normal verbosity ***************" << std::endl ;
596 if(_verb >= 0) std::cout <<
"RooUnitTest: ERROR messages were logged, failing test" << std::endl ;
600 return runCompTests() ;
607void RooUnitTest::setMemDir(
TDirectory* memDir) {
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 r
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
One-dimensional graphical representation of a real-valued function.
bool isIdentical(const RooCurve &other, double tol=1e-6, bool verbose=true) const
Return true if curve is identical to other curve allowing for given absolute tolerance on each point ...
Minimal implementation of a TObject holding a double value.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Graphical representation of binned data based on the TGraphAsymmErrors class.
bool isIdentical(const RooHist &other, double tol=1e-6, bool verbose=true) const
Return true if contents of this RooHist is identical within given relative tolerance to that of 'othe...
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
void setStreamStatus(Int_t id, bool active)
(De)Activate stream with given unique ID
void setSilentMode(bool flag)
Plot frame and a container for graphics objects within that frame.
void SetName(const char *name) override
Set the name of the RooPlot to 'name'.
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 Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
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...
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...
RooPlot * emptyClone(const char *name)
Return empty clone of current RooPlot.
void createInternalPlotVarClone()
Replaces the pointer to the plot variable with a pointer to a clone of the plot variable that is owne...
void addPlotable(RooPlotable *plotable, Option_t *drawOptions="", bool invisible=false, bool refreshNorm=false)
Add the specified plotable object to our plot.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Abstract interface for table objects.
static void callgrind_zero()
Utility function to trigger zeroing of callgrind counters.
static void callgrind_dump()
Utility function to trigger dumping of callgrind counters.
Persistable container for RooFit projects.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Describe directory structure in memory.
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t GetNbinsY() const
virtual Int_t GetNbinsZ() const
virtual Int_t GetDimension() const
virtual Int_t GetNbinsX() const
void SetName(const char *name) override
Change the name of this histogram.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual Double_t KolmogorovTest(const TH1 *h2, Option_t *option="") const
Statistical test of compatibility in shape between this histogram and h2, using Kolmogorov test.
The TNamed class is the base class for all named ROOT classes.
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
const char * GetName() const override
Returns name of object.
void Print(Option_t *option="") const override
Print TNamed name and title.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual const char * ClassName() const
Returns name of class to which the object belongs.
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
virtual TClass * IsA() const
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
RooFit::MsgLevel minLevel