59 _refFile(refFile), _debug(false), _write(writeRef), _verb(
verbose)
66void RooUnitTest::regPlot(
RooPlot* frame,
const char* refName)
69 std::string refNameStr(refName) ;
77 _regPlots.emplace_back(frame,refNameStr);
86void RooUnitTest::regResult(std::unique_ptr<RooFitResult>
r,
const char* refName)
89 _regResults.emplace_back(
r.release(),refName);
96void RooUnitTest::regValue(
double d,
const char* refName)
99 _regValues.emplace_back(
d,refName);
106void RooUnitTest::regTable(
RooTable* t,
const char* refName)
109 _regTables.emplace_back(t,refName) ;
118void RooUnitTest::regWS(
RooWorkspace* ws,
const char* refName)
121 _regWS.emplace_back(ws,refName) ;
130void RooUnitTest::regTH(
TH1* th,
const char* refName)
133 _regTH.emplace_back(th,refName) ;
146 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooWorkspace " << refName
147 <<
" from reference file, skipping " << std::endl ;
157bool RooUnitTest::areTHidentical(
TH1* htest,
TH1* href)
170 if(_verb >= 0) std::cout <<
"KS distances = " << kmax << std::endl;
187 for (
Int_t i=0 ; i<ntest ; i++) {
189 if(_verb >= 0) std::cout <<
"htest[" << i <<
"] = " << htest->
GetBinContent(i) <<
" href[" << i <<
"] = " << href->
GetBinContent(i) << std::endl;
203bool RooUnitTest::runCompTests()
207 auto iter = _regPlots.begin() ;
208 while (iter!=_regPlots.end()) {
215 RooPlot* bmark =
dynamic_cast<RooPlot*
>(_refFile->Get(iter->second.c_str())) ;
217 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooPlot " << iter->second
218 <<
" from reference file, skipping " << std::endl;
225 std::cout <<
"comparing RooPlot " << iter->first <<
" to benchmark " << iter->second <<
" = " << bmark << std::endl ;
226 std::cout <<
"reference: " ; iter->first->Print() ;
227 std::cout <<
"benchmark: " ; bmark->
Print() ;
230 RooPlot* compPlot = _debug ? iter->first->
emptyClone(
Form(
"%s_comparison",iter->first->GetName())) : nullptr ;
233 Stat_t nItems = iter->first->numItems() ;
234 for (
Stat_t i=0 ; i<nItems ; i++) {
242 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve reference object " << obj->
GetName()
243 <<
" from benchmark RooPlot " << iter->second <<
", skipping" << std::endl;
252 if (!testHist->
isIdentical(*refHist,htol(),_verb >= 0)) {
253 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << obj->
ClassName() <<
"::" << obj->
GetName()
254 <<
" fails comparison with counterpart in reference RooPlot " << bmark->
GetName() << std::endl;
274 if (!testCurve->
isIdentical(*refCurve,ctol(),_verb >= 0)) {
275 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << obj->
ClassName() <<
"::" << obj->
GetName()
276 <<
" fails comparison with counterpart in reference RooPlot " << bmark->
GetName() << std::endl;
298 if (anyFail && compPlot) {
299 std::cout <<
"RooUnitTest INFO: writing comparison plot " << compPlot->
GetName() <<
" of failed test to RooUnitTest_DEBUG.root" << std::endl ;
300 TFile fdbg(
"RooUnitTest_DEBUG.root",
"UPDATE") ;
314 std::cout <<
"RooUnitTest: Writing reference RooPlot " << iter->first <<
" as benchmark " << iter->second << std::endl ;
316 iter->first->
Write(iter->second.c_str()) ;
324 auto iter2 = _regResults.begin() ;
325 while (iter2!=_regResults.end()) {
334 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooFitResult "
335 << iter2->second <<
" from reference file, skipping " << std::endl ;
342 std::cout <<
"comparing RooFitResult " << iter2->first <<
" to benchmark " << iter2->second <<
" = " << bmark << std::endl ;
345 if (!iter2->first->isIdentical(*bmark,fptol(),fctol(),_verb >= 0)) {
347 std::cout <<
"RooUnitTest ERROR: comparison of object " << iter2->first->
ClassName()
348 <<
"::" << iter2->first->GetName() <<
" from result " << iter2->second
349 <<
" fails comparison with counterpart in reference RooFitResult " << bmark->
GetName() << std::endl;
355 delete iter2->first ;
362 std::cout <<
"RooUnitTest: Writing reference RooFitResult " << iter2->first <<
" as benchmark " << iter2->second << std::endl ;
364 iter2->first->Write(iter2->second.c_str()) ;
371 auto iter3 = _regValues.begin() ;
372 while (iter3!=_regValues.end()) {
381 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooDouble " << iter3->second <<
" from reference file, skipping " << std::endl;
388 std::cout <<
"comparing value " << iter3->first <<
" to benchmark " << iter3->second <<
" = " << (
double)(*ref) << std::endl ;
391 if (std::abs(iter3->first - (
double)(*ref))>vtol() ) {
392 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of value " << iter3->first <<
" fails comparison with reference " << ref->
GetName() << std::endl ;
401 std::cout <<
"RooUnitTest: Writing reference double " << iter3->first <<
" as benchmark " << iter3->second << std::endl ;
404 rd->
Write(iter3->second.c_str()) ;
412 auto iter4 = _regTables.begin() ;
413 while (iter4!=_regTables.end()) {
420 RooTable* bmark =
dynamic_cast<RooTable*
>(_refFile->Get(iter4->second.c_str())) ;
422 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve RooTable " << iter4->second <<
" from reference file, skipping " << std::endl ;
429 std::cout <<
"comparing RooTable " << iter4->first <<
" to benchmark " << iter4->second <<
" = " << bmark << std::endl ;
432 if (!iter4->first->isIdentical(*bmark, _verb >= 0)) {
433 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << iter4->first->
ClassName() <<
"::" << iter4->first->GetName()
434 <<
" fails comparison with counterpart in reference RooTable " << bmark->
GetName() << std::endl ;
436 iter4->first->Print(
"V");
443 delete iter4->first ;
450 std::cout <<
"RooUnitTest: Writing reference RooTable " << iter4->first <<
" as benchmark " << iter4->second << std::endl ;
452 iter4->first->Write(iter4->second.c_str()) ;
460 auto iter5 = _regWS.begin() ;
461 while (iter5!=_regWS.end()) {
467 std::cout <<
"RooUnitTest: Writing reference RooWorkspace " << iter5->first <<
" as benchmark " << iter5->second << std::endl ;
469 iter5->first->Write(iter5->second.c_str()) ;
477 auto iter6 = _regTH.begin() ;
478 while (iter6!=_regTH.end()) {
485 TH1* bmark =
dynamic_cast<TH1*
>(_refFile->Get(iter6->second.c_str())) ;
487 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: cannot retrieve TH1 " << iter6->second <<
" from reference file, skipping " << std::endl ;
494 std::cout <<
"comparing TH1 " << iter6->first <<
" to benchmark " << iter6->second <<
" = " << bmark << std::endl ;
497 if (!areTHidentical(iter6->first,bmark)) {
499 if(_verb >= 0) std::cout <<
"RooUnitTest ERROR: comparison of object " << iter6->first->
ClassName() <<
"::" << iter6->first->GetName()
500 <<
" fails comparison with counterpart in reference TH1 " << bmark->
GetName() << std::endl ;
504 std::cout <<
"RooUnitTest INFO: writing THx " << iter6->first->GetName() <<
" and " << bmark->
GetName()
505 <<
" of failed test to RooUnitTest_DEBUG.root" << std::endl ;
506 TFile fdbg(
"RooUnitTest_DEBUG.root",
"UPDATE") ;
507 iter6->first->SetName(
Form(
"%s_test",iter6->first->GetName())) ;
508 iter6->first->Write() ;
518 delete iter6->first ;
525 std::cout <<
"RooUnitTest: Writing reference TH1 " << iter6->first <<
" as benchmark " << iter6->second << std::endl ;
527 iter6->first->Write(iter6->second.c_str()) ;
543void RooUnitTest::setSilentMode()
556void RooUnitTest::clearSilentMode()
568bool RooUnitTest::runTest()
575 std::cout <<
"*** Begin of output of Unit Test at normal verbosity *************" << std::endl ;
584 if (!testCode())
return false ;
589 std::cout <<
"*** End of output of Unit Test at normal verbosity ***************" << std::endl ;
593 if(_verb >= 0) std::cout <<
"RooUnitTest: ERROR messages were logged, failing test" << std::endl ;
597 return runCompTests() ;
604void RooUnitTest::setMemDir(
TDirectory* memDir) {
int Int_t
Signed integer 4 bytes (int)
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.
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 file, usually with extension .root, that stores data and code in the form of serialized objects in ...
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