ATLAS Offline Software
Loading...
Searching...
No Matches
TRootCompare Class Reference

Class to compare the histograms in two root files. More...

#include <TRootCompare.h>

Inheritance diagram for TRootCompare:
Collaboration diagram for TRootCompare:

Public Types

enum  ALG { BIN , CHI2 , AXIS }

Public Member Functions

 TRootCompare ()=default
virtual ~TRootCompare ()
virtual void processKey (TDirectory &dir, TKey &key)
 Method called for every key.
virtual void beginJob ()
virtual void endJob ()
Bool_t setReferenceFile (const char *filename, const char *baseDir=0)
Bool_t setOutputFile (const char *filename)
Bool_t setPsFile (const char *filename)
void setAlg (TRootCompare::ALG alg, Double_t threshold)
void drawNormalized (Bool_t norm=kTRUE)
void drawDiff (Bool_t diff=kTRUE)
void sortLabels (Bool_t sort=kTRUE)
Int_t matchingHist () const
Int_t totalHist () const
Int_t missingHist () const
virtual Int_t run (const char *filename, const char *rootDir=0)
 Start processing.

Private Member Functions

Bool_t compareHist (const TH1 &h, const TH1 &href)
void sortAndDeflate (TH1 &h)
void createDirectory (TFile *f, const char *dirpath)
void printCanvas (const char *filename)

Private Attributes

TFile * m_refFile {}
TFile * m_outFile {}
TString m_refRootDir {}
TString m_psFile {}
TCanvas * m_can {}
ALG m_alg {BIN}
Double_t m_threshold {1e-6}
Int_t m_histMatch {}
Int_t m_histTotal {}
Int_t m_histMissing {}
Bool_t m_drawNormalized {kFALSE}
Bool_t m_drawDiff {kTRUE}
Bool_t m_sortLabels {kTRUE}
std::vector< std::string > m_noMatch

Processing hooks

virtual void beforeFile ()
virtual void afterFile ()
virtual void beforeDir ()
virtual void afterDir ()
virtual void beforeObj ()
virtual void afterObj ()
void setDirsToSkip (const char *skipDirs)
 Skip this comma separated list of directories.
void addFailRegexp (const char *regexp)
 Skip keys that match this regexp.
void addPassRegexp (const char *regexp)
 Never skip keys that match this regexp.
void passBeforeFailRegexp (Bool_t passBeforeFail=kTRUE)
 Reverse pass/fail logic. First check on pass then on fail.
void setVerbose (Bool_t verbose=kTRUE)
 Set verbose mode.
Bool_t verbose () const
 Query verbose mode.
const TFile * file () const
 Current ROOT file.
TString rootDir () const
 Current directory.
TFile * m_file {nullptr}
TString m_rootDir
TString m_skipDirs
Bool_t m_verbose {kFALSE}
Bool_t m_passBeforeFail {kFALSE}
Int_t m_errorCode {0}
std::vector< TPRegexp > m_failRE
std::vector< TPRegexp > m_passRE
std::vector< std::string > m_skippedObjects
TString getPathFromDir (const TDirectory &dir)
TString getKeyPath (const TDirectory &dir, const TKey &key)
void processDir (TDirectory &dir)
void processFile (const char *filename, const char *rootDir=0)
Bool_t skipDir (const TDirectory &dir)
Bool_t skipObject (const char *name)
TString getDrawOptions (const TH1 &h)

Detailed Description

Class to compare the histograms in two root files.

Author
Frank Winklmeier

Compare histograms in two root files. Statistics of differences is printed as well as a PS file with histograms overlayed.

Definition at line 34 of file TRootCompare.h.

Member Enumeration Documentation

◆ ALG

Enumerator
BIN 
CHI2 
AXIS 

Definition at line 36 of file TRootCompare.h.

Constructor & Destructor Documentation

◆ TRootCompare()

TRootCompare::TRootCompare ( )
default

◆ ~TRootCompare()

TRootCompare::~TRootCompare ( )
virtual

Definition at line 38 of file TRootCompare.cxx.

39{
40 delete m_refFile;
41}
TFile * m_refFile

Member Function Documentation

◆ addFailRegexp()

void TFileLooper::addFailRegexp ( const char * regexp)
inherited

Skip keys that match this regexp.

Definition at line 160 of file TFileLooper.cxx.

161{
162 if (regexp) {
163 m_failRE.emplace_back(regexp);
164 }
165}
std::vector< TPRegexp > m_failRE
Definition TFileLooper.h:96

◆ addPassRegexp()

void TFileLooper::addPassRegexp ( const char * regexp)
inherited

Never skip keys that match this regexp.

Definition at line 169 of file TFileLooper.cxx.

170{
171 if (regexp) {
172 m_passRE.emplace_back(regexp);
173 }
174}
std::vector< TPRegexp > m_passRE
Definition TFileLooper.h:97

◆ afterDir()

virtual void TFileLooper::afterDir ( )
inlinevirtualinherited

Definition at line 59 of file TFileLooper.h.

59{}

◆ afterFile()

virtual void TFileLooper::afterFile ( )
inlinevirtualinherited

Definition at line 57 of file TFileLooper.h.

57{}

◆ afterObj()

virtual void TFileLooper::afterObj ( )
inlinevirtualinherited

Definition at line 61 of file TFileLooper.h.

61{}

◆ beforeDir()

virtual void TFileLooper::beforeDir ( )
inlinevirtualinherited

Definition at line 58 of file TFileLooper.h.

58{}

◆ beforeFile()

virtual void TFileLooper::beforeFile ( )
inlinevirtualinherited

Definition at line 56 of file TFileLooper.h.

56{}

◆ beforeObj()

virtual void TFileLooper::beforeObj ( )
inlinevirtualinherited

Definition at line 60 of file TFileLooper.h.

60{}

◆ beginJob()

void TRootCompare::beginJob ( )
virtual

Reimplemented from TFileLooper.

Definition at line 43 of file TRootCompare.cxx.

44{
45 m_histMatch = 0;
46 m_histTotal = 0;
47 m_histMissing = 0;
48
49 Int_t canvasWidth = 1000;
50 Int_t canvasHeight = 580;
51
52 if (!m_drawDiff) canvasWidth = canvasHeight;
53
54 m_can = new TCanvas("can","can",canvasWidth,canvasHeight);
55 if (m_psFile!="") printCanvas(m_psFile+"[");
56}
void printCanvas(const char *filename)
Int_t m_histTotal
TCanvas * m_can
Int_t m_histMatch
Bool_t m_drawDiff
TString m_psFile
Int_t m_histMissing

◆ compareHist()

Bool_t TRootCompare::compareHist ( const TH1 & h,
const TH1 & href )
private

Definition at line 369 of file TRootCompare.cxx.

370{
371 Bool_t result = kTRUE;
372
373 if (verbose()) {
374 cout << "Comparing " << h.GetName() << " using ";
375 }
376
378 if (verbose()) cout << "BIN: ";
379
380 if (h.GetNbinsX()!=href.GetNbinsX() ||
381 h.GetNbinsY()!=href.GetNbinsY() ||
382 h.GetNbinsZ()!=href.GetNbinsZ()) {
383 cout << h.GetName() << " has different number of bins: ("
384 << h.GetNbinsX() << "," << h.GetNbinsY() << "," << h.GetNbinsZ() << ") vs ("
385 << href.GetNbinsX() << "," << href.GetNbinsY() << "," << href.GetNbinsZ() << ")" << endl;
386 }
387
388 // This will work for histograms of all dimensions
389 for (Int_t z=1; z<=h.GetNbinsZ() && result; z++) {
390 for (Int_t y=1; y<=h.GetNbinsY() && result; y++) {
391 for (Int_t x=1; x<=h.GetNbinsX() && result; x++) {
392 Double_t binDiff = fabs(h.GetBinContent(x,y,z)-href.GetBinContent(x,y,z));
393 if (binDiff>m_threshold) {
394 result = kFALSE;
395 }
396 }
397 }
398 }
399 }
400 else if (m_alg==TRootCompare::AXIS) {
401 if (verbose()) cout << "AXIS: ";
402 const TAxis *xa(h.GetXaxis()), *xaref(href.GetXaxis());
403 const TAxis *ya(h.GetXaxis()), *yaref(href.GetXaxis());
404 const TAxis *za(h.GetXaxis()), *zaref(href.GetXaxis());
405 if( xa->GetNbins() != xaref->GetNbins() ) result = kFALSE;
406 if( result && (ya->GetNbins() != yaref->GetNbins()) ) result = kFALSE;
407 if( result && (za->GetNbins() != zaref->GetNbins()) ) result = kFALSE;
408 if( result && (fabs( xa->GetBinLowEdge(0) - xaref->GetBinLowEdge(0) ) > m_threshold ) ) result = kFALSE;
409 if( result && (fabs( ya->GetBinLowEdge(0) - yaref->GetBinLowEdge(0) ) > m_threshold ) ) result = kFALSE;
410 if( result && (fabs( za->GetBinLowEdge(0) - zaref->GetBinLowEdge(0) ) > m_threshold ) ) result = kFALSE;
411 if( result ) for (Int_t i=0; i<=xa->GetNbins() && result; i++)
412 if( fabs (xa->GetBinUpEdge(i) - xaref->GetBinUpEdge(i)) > m_threshold ) result = kFALSE;
413 if( result ) for (Int_t i=0; i<=ya->GetNbins() && result; i++)
414 if( fabs (ya->GetBinUpEdge(i) - yaref->GetBinUpEdge(i)) > m_threshold ) result = kFALSE;
415 if( result ) for (Int_t i=0; i<=za->GetNbins() && result; i++)
416 if( fabs (za->GetBinUpEdge(i) - zaref->GetBinUpEdge(i)) > m_threshold ) result = kFALSE;
417 }
418 else if (m_alg==TRootCompare::CHI2) {
419 if (verbose()) cout << "CHI2: ";
420
421 // Don't compare empty histograms
422 if (h.GetEntries()==0 && href.GetEntries()==0) result = kTRUE; // both empty
423 else if (h.Integral()==0 && href.Integral()==0) result = kTRUE; // both empty
424 else if (h.Integral()*href.Integral()==0) result = kFALSE; // one empty
425 else {
426 Double_t chi2;
427 Int_t igood;
428 Int_t ndf;
429 Double_t p = h.Chi2TestX(&href,chi2,ndf,igood);
430 // this is because of a bug in root
431 if (ndf==0) result = kTRUE;
432 else if (p>m_threshold) result = kTRUE;
433 else result = kFALSE;
434 }
435 }
436 else {
437 cout << "ERROR: Invalid algorithm." << endl;
438 }
439
440 if (verbose()) cout << result << endl;
441 return result;
442}
#define y
#define x
#define z
Bool_t verbose() const
Query verbose mode.
Definition TFileLooper.h:80
Double_t m_threshold
double chi2(TH1 *h0, TH1 *h1)

◆ createDirectory()

void TRootCompare::createDirectory ( TFile * f,
const char * dirpath )
private

Definition at line 458 of file TRootCompare.cxx.

459{
460 if ((f==0) || (dirpath==0)) return;
461
462 f->cd();
463 TString s(dirpath);
464 TObjArray* a = s.Tokenize("/");
465 for (int i=0; i<a->GetEntries(); i++) {
466 const char* dir = a->At(i)->GetName();
467 if (gDirectory->GetDirectory(dir)==0) gDirectory->mkdir(dir); // create if it doesn't exist
468 gDirectory->cd(dir);
469 }
470
471}
static Double_t a

◆ drawDiff()

void TRootCompare::drawDiff ( Bool_t diff = kTRUE)
inline

Definition at line 53 of file TRootCompare.h.

53{ m_drawDiff = diff; }
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631

◆ drawNormalized()

void TRootCompare::drawNormalized ( Bool_t norm = kTRUE)
inline

Definition at line 52 of file TRootCompare.h.

◆ endJob()

void TRootCompare::endJob ( )
virtual

Reimplemented from TFileLooper.

Definition at line 58 of file TRootCompare.cxx.

59{
60 cout << endl;
61 cout << "Summary:" << endl;
62 cout << "========" << endl;
63 cout << "Total histograms compared: " << m_histTotal << endl;
64 cout << "Missing references: " << m_histMissing << endl;
65 cout << "Matching histograms: " << m_histMatch << endl;
66 cout << "Different histograms: " << m_histTotal-m_histMatch << endl;
67 cout << "Ignored histograms: " << m_skippedObjects.size() << endl;
68
70 cout << "List of different histograms:" << endl;
71 vector<string>::iterator iter;
72 int i = 0;
73 for (iter=m_noMatch.begin(); iter!=m_noMatch.end(); ++iter) {
74 i++;
75 cout << setw(2) << i << ") " << *iter << endl;
76 }
77 }
78
79 if (verbose() && !m_skippedObjects.empty()) {
80 cout << endl << "List of ignored histograms:" << endl;
81 vector<string>::iterator iter;
82 int i = 0;
83 for (iter=m_skippedObjects.begin(); iter!=m_skippedObjects.end(); ++iter) {
84 i++;
85 cout << setw(2) << i << ") " << *iter << endl;
86 }
87 }
88 cout << endl;
89
90 if (m_outFile) {
91 cout << "Comparison results written to " << m_outFile->GetName() << endl;
92 delete m_outFile;
93 }
94
95 if (m_psFile!="") {
97 cout << "Comparison results written to " << m_psFile << endl;
98 }
99
100 delete m_can;
101}
std::vector< std::string > m_skippedObjects
Definition TFileLooper.h:99
std::vector< std::string > m_noMatch
TFile * m_outFile

◆ file()

const TFile * TFileLooper::file ( ) const
inlineinherited

Current ROOT file.

Definition at line 83 of file TFileLooper.h.

83{ return m_file; }
TFile * m_file
Definition TFileLooper.h:89

◆ getDrawOptions()

TString TFileLooper::getDrawOptions ( const TH1 & h)
protectedinherited

◆ getKeyPath()

TString TFileLooper::getKeyPath ( const TDirectory & dir,
const TKey & key )
protectedinherited

Definition at line 188 of file TFileLooper.cxx.

189{
190 TString s(dir.GetPath()+TString("/")+key.GetName());
191 // Remove all chars from beginning including ":/"
192 s.Replace(0,s.First(":")+2,0);
193
194 return s;
195}

◆ getPathFromDir()

TString TFileLooper::getPathFromDir ( const TDirectory & dir)
protectedinherited

Definition at line 178 of file TFileLooper.cxx.

179{
180 TString s(dir.GetPath());
181 if (s.Index("../")==0) s.Remove(0,3);
182 s.ReplaceAll(":","");
183 return s;
184}

◆ matchingHist()

Int_t TRootCompare::matchingHist ( ) const
inline

Definition at line 56 of file TRootCompare.h.

56{ return m_histMatch; }

◆ missingHist()

Int_t TRootCompare::missingHist ( ) const
inline

Definition at line 58 of file TRootCompare.h.

58{ return m_histMissing; }

◆ passBeforeFailRegexp()

void TFileLooper::passBeforeFailRegexp ( Bool_t passBeforeFail = kTRUE)
inlineinherited

Reverse pass/fail logic. First check on pass then on fail.

Definition at line 74 of file TFileLooper.h.

74{ m_passBeforeFail = passBeforeFail; }
Bool_t m_passBeforeFail
Definition TFileLooper.h:93

◆ printCanvas()

void TRootCompare::printCanvas ( const char * filename)
private

Definition at line 357 of file TRootCompare.cxx.

358{
359 if (m_can==0) return;
360 if (filename==0) return;
361
362 if (TString(filename).EndsWith(".ps"))
363 m_can->Print(filename,"Landscape");
364 else
365 m_can->Print(filename);
366}

◆ processDir()

void TFileLooper::processDir ( TDirectory & dir)
protectedinherited

Definition at line 73 of file TFileLooper.cxx.

74{
75 TString s(getPathFromDir(dir));
76
77 if (skipDir(dir)) {
78 cout << "Skipping " << s << endl;
79 return;
80 }
81
82 if (m_verbose) cout << "Reading directory "<< dir.GetPath() << endl;
83
84 // Sort directory content
85 TList* dirList = dir.GetListOfKeys();
86 dirList->Sort();
87
88 TIter next(dirList);
89 TKey* key;
90 while ((key = (TKey*)next())) {
91 // if (skipObject(getKeyPath(dir,*key))) continue;
92
93 TString className(key->GetClassName());
94 if (className=="TDirectoryFile" || className=="TDirectory") {
95 dir.cd(key->GetName());
96 beforeDir();
97 processDir(*gDirectory);
98 afterDir();
99 }
100 else {
101 if (skipObject(getKeyPath(dir,*key))) {
102 m_skippedObjects.push_back(getKeyPath(dir,*key).Data());
103 continue;
104 }
105 processKey(dir, *key);
106 }
107 }
108}
@ Data
Definition BaseObject.h:11
void processDir(TDirectory &dir)
TString getKeyPath(const TDirectory &dir, const TKey &key)
Bool_t m_verbose
Definition TFileLooper.h:92
virtual void beforeDir()
Definition TFileLooper.h:58
Bool_t skipObject(const char *name)
Bool_t skipDir(const TDirectory &dir)
TString getPathFromDir(const TDirectory &dir)
virtual void afterDir()
Definition TFileLooper.h:59
virtual void processKey(TDirectory &dir, TKey &key)
Method called for every key.

◆ processFile()

void TFileLooper::processFile ( const char * filename,
const char * rootDir = 0 )
protectedinherited

Definition at line 44 of file TFileLooper.cxx.

45{
46 m_file = new TFile(filename);
47 if (m_file->IsZombie()) {
48 cout << "Cannot open "<<filename << endl;
49 m_errorCode = 1;
50 delete m_file;
51 return;
52 }
53
54 if (rootDir) {
55 if (!m_file->cd(rootDir)) {
56 cout << "Cannot change to directory " << rootDir << endl;
57 m_errorCode = 1;
58 return;
59 }
61 }
62 else m_file->cd();
63
64 beforeFile();
65 processDir(*gDirectory);
66 afterFile();
67
68 delete m_file; // calls Close()
69}
virtual void afterFile()
Definition TFileLooper.h:57
TString m_rootDir
Definition TFileLooper.h:90
TString rootDir() const
Current directory.
Definition TFileLooper.h:86
virtual void beforeFile()
Definition TFileLooper.h:56
Int_t m_errorCode
Definition TFileLooper.h:94

◆ processKey()

void TRootCompare::processKey ( TDirectory & dir,
TKey & key )
virtual

Method called for every key.

Only dummy implementation. Needs to be implemented in derived classes.

Reimplemented from TFileLooper.

Definition at line 103 of file TRootCompare.cxx.

104{
105 dir.cd();
106
107 if (m_refFile==0) return;
108
109 if (TString(key.GetName()).Contains("/")) {
110 cout << "IGNORE: " << key.GetName() << " contains '/'" << endl;
111 return;
112 }
113
114 std::unique_ptr<TObject> obj(key.ReadObj());
115
116 // Extract directory name
117 TString dirName(dir.GetPath());
118 dirName.Replace(0,dirName.First(":")+2,0);
119 if (rootDir()!="") dirName.ReplaceAll(rootDir(),m_refRootDir);
120 else dirName = m_refRootDir+"/"+dirName;
121 TString keyPath(dirName+"/"+key.GetName());
122
123 if (!m_refFile->cd(dirName)) { // could not cd() into directory of histogram
125 return;
126 }
127
128 TObject* refObj = m_refFile->Get(keyPath);
129 if (!refObj) { // histogram not found
130 cout << "Cannot find " << keyPath << " in reference file" << endl;
132 return;
133 }
134
135 if (obj->Class()!=refObj->Class()) { // class types do not agree
136 cout << key.GetName() << " is of different type in file and reference file." << endl;
137 return;
138 }
139
140 if (obj->IsA()->InheritsFrom("TH1")) {
141 TH1& h = *static_cast<TH1*>(obj.get());
142 TH1& href = *static_cast<TH1*>(refObj);
143
144 // For alphanumeric axes, sort and deflate
145 if (m_sortLabels) {
147 sortAndDeflate(href);
148 }
149
150 Bool_t match = compareHist(h,href);
151 m_histTotal++;
152 if (match) {
153 m_histMatch++;
154 }
155 else { // histograms do not match
156 m_noMatch.push_back(keyPath.Data());
157
158 // Skip drawing if no output was requested
159 if (!m_outFile && m_psFile.Length()==0) return;
160
161 m_can->Clear();
162 m_can->Divide(2,1);
163 m_can->cd(1)->SetPad(0,1,1,0.90);
164 m_can->cd(2)->SetPad(0,0.90,1,0);
165 TVirtualPad* pad = m_can->cd(2);
166
167 if (m_drawDiff) pad->Divide(2,1);
168 m_can->SetName(h.GetName());
169 m_can->SetTitle(h.GetTitle());
170 // Overlayed
171 pad->cd(1);
172 if (m_drawNormalized) {
173 if (href.Integral()) href.Scale(1/href.Integral());
174 if (h.Integral()) h.Scale(1/h.Integral());
175 }
176
177 Double_t ymax = 1.05*max(h.GetMaximum(),href.GetMaximum());
178 h.SetMaximum(ymax);
179 h.SetLineColor(kBlue);
180 h.Draw();
181 m_can->Update();
182 TPaveStats* st1 = (TPaveStats*)gPad->GetPrimitive("stats");
183 if (st1) {
184 st1->SetName("stats1");
185 st1->SetLineColor(kBlue);
186 }
187
188 href.SetLineColor(kRed);
189 href.Draw("sames");
190 m_can->Update();
191 TPaveStats* st2 = (TPaveStats*)gPad->GetPrimitive("stats");
192 if (st1 && st2) {
193 // Move stat box
194 Double_t x1 = st1->GetX1NDC()-0.01;
195 st2->SetName("stats2");
196 Double_t w = st2->GetX2NDC()-st2->GetX1NDC();
197 st2->SetX1NDC(x1-w);
198 st2->SetX2NDC(x1);
199 st2->SetLineColor(kRed);
200 m_can->Modified();
201 }
202
203 TH1* hdiff = 0;
204 if (m_drawDiff) {
205 hdiff = (TH1*)h.Clone();
206 // Too many problems with difference of 2D histograms
207 if (hdiff->GetDimension()==1 &&
208 hdiff->GetNbinsX()==href.GetNbinsX()) {
209 // Difference
210 pad->cd(2);
211 hdiff->SetName(TString(href.GetName())+" (diff)");
212 hdiff->SetTitle(TString(href.GetTitle())+" (diff)");
213 hdiff->SetLineColor(kBlack);
214 hdiff->Add(&href,-1);
215 hdiff->Draw();
216 TPaveStats* st = (TPaveStats*)gPad->GetPrimitive("stats1");
217 if (st) st->SetLineColor(kBlack);
218 }
219 if(hdiff->GetDimension()==2 &&
220 hdiff->GetNbinsX()==href.GetNbinsX() &&
221 hdiff->GetNbinsY()==href.GetNbinsY()) {
222 pad->cd(2);
223 hdiff->SetName(TString(href.GetName())+" (diff)");
224 hdiff->SetTitle(TString(href.GetTitle())+" (diff)");
225 hdiff->SetLineColor(kBlack);
226 hdiff->Add(&href,-1);
227 if(hdiff->GetXaxis()->GetLabels()!=0 && hdiff->GetNbinsX()>100) {
228 TH1 * hdiffred = (TH1*)hdiff->Clone();
229 hdiffred->GetXaxis()->GetLabels()->Delete();
230 hdiffred->Reset();
231 hdiffred->SetName(TString(href.GetName())+" (diff reduced)");
232 hdiffred->SetTitle(TString(href.GetTitle())+" (diff reduced)");
233 int targetbin=1;
234 for(int x=1; x<=hdiff->GetNbinsX(); ++x) {
235 bool isEmpty(true);
236 for(int y=1;y<=hdiff->GetNbinsY();++y) {
237 if(hdiff->GetBinContent(x,y)!=0) { isEmpty=false; break; }
238 }
239 if(!isEmpty) {
240 for(int y=1;y<=hdiff->GetNbinsY();++y) {
241 if(hdiff->GetBinContent(x,y)!=0)
242 hdiffred->SetBinContent(targetbin,y,hdiff->GetBinContent(x,y));
243 }
244 hdiffred->GetXaxis()->SetBinLabel(targetbin,hdiff->GetXaxis()->GetBinLabel(x));
245 targetbin++;
246 }
247 }
248 hdiffred->LabelsDeflate();
249 hdiffred->Draw("text");
250 } else {
251 hdiff->Draw("text");
252 }
253 TPaveStats* st = (TPaveStats*)gPad->GetPrimitive("stats1");
254 if (st) st->SetLineColor(kBlack);
255 }
256 }
257
258 // Some more cosmetics before saving to ps file
259 m_can->cd(0);
260 TText text;
261 text.SetTextSize(0.03);
262 text.SetTextAlign(22);
263 TString page("page ");
264 page += m_noMatch.size();
265 text.DrawTextNDC(0.5,0.03,page);
266
267 TString title(dir.GetName());
268 title+="/";
269 title+=href.GetName();
270 text.DrawTextNDC(0.5,0.99,title);
271
272 const int maxchars = 120; // max #chars for title
273 if (m_file) {
274 text.SetTextColor(kBlue);
275 string s(m_file->GetName());
276 text.DrawTextNDC(0.5,0.93,s.substr(max(0,int(s.size()-maxchars))).c_str());
277 }
278 if (m_refFile) {
279 text.SetTextColor(kRed);
280 string s(m_refFile->GetName());
281 text.DrawTextNDC(0.5,0.96,s.substr(max(0,int(s.size()-maxchars))).c_str());
282 }
283
284 if (m_psFile!="") printCanvas(m_psFile);
285
286 // Save canvas to root file
287 if (m_outFile) {
288 createDirectory(m_outFile,dirName); // now we are in dirName
289 m_can->Write();
290 }
291
292 if (hdiff) delete hdiff;
293 }
294 }
295 else if (obj->IsA()->InheritsFrom("TEfficiency")) {
296 auto h = static_cast<TEfficiency*>(obj.get());
297 auto href = static_cast<TEfficiency*>(refObj);
298 Bool_t match = compareHist(*h->GetTotalHistogram(),*href->GetTotalHistogram()) &&
299 compareHist(*h->GetPassedHistogram(),*href->GetPassedHistogram());
300 m_histTotal++;
301
302 // We only count (mis)matches but do not draw the difference for TEfficiency (yet)
303 if (match) m_histMatch++;
304 else m_noMatch.push_back(keyPath.Data());
305 }
306}
#define max(a, b)
Definition cfImp.cxx:41
TString m_refRootDir
void createDirectory(TFile *f, const char *dirpath)
Bool_t compareHist(const TH1 &h, const TH1 &href)
void sortAndDeflate(TH1 &h)
Bool_t m_sortLabels
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357
double ymax
Definition listroot.cxx:64

◆ rootDir()

TString TFileLooper::rootDir ( ) const
inlineinherited

Current directory.

Definition at line 86 of file TFileLooper.h.

86{ return m_rootDir; }

◆ run()

Int_t TFileLooper::run ( const char * filename,
const char * rootDir = 0 )
virtualinherited

Start processing.

Reimplemented in TMultiFileLooper.

Definition at line 26 of file TFileLooper.cxx.

27{
28 m_errorCode = 0;
29
30 if (filename==0) {
31 cout << "Invalid file name (0)" << endl;
32 m_errorCode = 1;
33 return m_errorCode;
34 }
35
36 beginJob();
37 processFile(filename,rootDir);
38 endJob();
39 return m_errorCode;
40}
virtual void beginJob()
Definition TFileLooper.h:54
virtual void endJob()
Definition TFileLooper.h:55
void processFile(const char *filename, const char *rootDir=0)

◆ setAlg()

void TRootCompare::setAlg ( TRootCompare::ALG alg,
Double_t threshold )
inline

◆ setDirsToSkip()

void TFileLooper::setDirsToSkip ( const char * skipDirs)
inlineinherited

Skip this comma separated list of directories.

Definition at line 65 of file TFileLooper.h.

65{if (skipDirs) m_skipDirs = skipDirs;}
TString m_skipDirs
Definition TFileLooper.h:91

◆ setOutputFile()

Bool_t TRootCompare::setOutputFile ( const char * filename)

Definition at line 330 of file TRootCompare.cxx.

331{
332 if (filename==0) {
333 cout << "Invalid file name" << endl;
334 return kFALSE;
335 }
336
337 m_outFile = new TFile(filename,"recreate");
338 if (m_outFile->IsZombie()) {
339 cout << "Cannot open file " << filename << endl;
340 delete m_outFile;
341 m_outFile = 0;
342 return kFALSE;
343 }
344 return kTRUE;
345}

◆ setPsFile()

Bool_t TRootCompare::setPsFile ( const char * filename)

Definition at line 347 of file TRootCompare.cxx.

348{
349 if (filename==0) {
350 cout << "Invalid file name" << endl;
351 return kFALSE;
352 }
354 return kTRUE;
355}

◆ setReferenceFile()

Bool_t TRootCompare::setReferenceFile ( const char * filename,
const char * baseDir = 0 )

Definition at line 309 of file TRootCompare.cxx.

311{
312 if (filename==0) {
313 cout << "Invalid file name" << endl;
314 return kFALSE;
315 }
316
317 m_refFile = new TFile(filename);
318 if (m_refFile->IsZombie()) {
319 cout << "Cannot open reference file " << filename << endl;
320 delete m_refFile;
321 m_refFile = 0;
322 return kFALSE;
323 }
324
326 return kTRUE;
327}

◆ setVerbose()

void TFileLooper::setVerbose ( Bool_t verbose = kTRUE)
inlineinherited

Set verbose mode.

Definition at line 77 of file TFileLooper.h.

◆ skipDir()

Bool_t TFileLooper::skipDir ( const TDirectory & dir)
protectedinherited

Definition at line 118 of file TFileLooper.cxx.

119{
120 if (m_skipDirs.Contains(dir.GetName())) return kTRUE;
121 else return kFALSE;
122}

◆ skipObject()

Bool_t TFileLooper::skipObject ( const char * name)
protectedinherited

Definition at line 129 of file TFileLooper.cxx.

130{
131 Bool_t failMatch(kFALSE);
132 Bool_t passMatch(kFALSE);
133
134 for (auto& re : m_failRE) {
135 if (re.Match(name)>0) {
136 failMatch = kTRUE;
137 break;
138 }
139 }
140
141 // give object another chance to match any of the m_passRE
142 for (auto& re : m_passRE) {
143 if (re.Match(name)>0) {
144 passMatch = kTRUE;
145 break;
146 }
147 }
148
149 bool result;
150 if (m_passBeforeFail) result = (!passMatch || failMatch);
151 else result = (failMatch && !passMatch);
152
153 if (m_verbose && result) cout << "Skipping " << name << endl;
154 return result;
155
156}
const boost::regex re(r_e)

◆ sortAndDeflate()

void TRootCompare::sortAndDeflate ( TH1 & h)
private

Definition at line 445 of file TRootCompare.cxx.

446{
447 if (h.GetXaxis()->IsAlphanumeric()) {
448 h.GetXaxis()->LabelsOption("a");
449 h.LabelsDeflate("X");
450 }
451 if (h.GetYaxis()->IsAlphanumeric()) {
452 h.GetYaxis()->LabelsOption("a");
453 h.LabelsDeflate("Y");
454 }
455}

◆ sortLabels()

void TRootCompare::sortLabels ( Bool_t sort = kTRUE)
inline

Definition at line 54 of file TRootCompare.h.

54{ m_sortLabels = sort; }
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ totalHist()

Int_t TRootCompare::totalHist ( ) const
inline

Definition at line 57 of file TRootCompare.h.

57{ return m_histTotal; }

◆ verbose()

Bool_t TFileLooper::verbose ( ) const
inlineinherited

Query verbose mode.

Definition at line 80 of file TFileLooper.h.

80{return m_verbose;}

Member Data Documentation

◆ m_alg

ALG TRootCompare::m_alg {BIN}
private

Definition at line 73 of file TRootCompare.h.

73{BIN};

◆ m_can

TCanvas* TRootCompare::m_can {}
private

Definition at line 71 of file TRootCompare.h.

71{};

◆ m_drawDiff

Bool_t TRootCompare::m_drawDiff {kTRUE}
private

Definition at line 79 of file TRootCompare.h.

79{kTRUE};

◆ m_drawNormalized

Bool_t TRootCompare::m_drawNormalized {kFALSE}
private

Definition at line 78 of file TRootCompare.h.

78{kFALSE};

◆ m_errorCode

Int_t TFileLooper::m_errorCode {0}
protectedinherited

Definition at line 94 of file TFileLooper.h.

94{0};

◆ m_failRE

std::vector<TPRegexp> TFileLooper::m_failRE
protectedinherited

Definition at line 96 of file TFileLooper.h.

◆ m_file

TFile* TFileLooper::m_file {nullptr}
protectedinherited

Definition at line 89 of file TFileLooper.h.

89{nullptr};

◆ m_histMatch

Int_t TRootCompare::m_histMatch {}
private

Definition at line 75 of file TRootCompare.h.

75{};

◆ m_histMissing

Int_t TRootCompare::m_histMissing {}
private

Definition at line 77 of file TRootCompare.h.

77{};

◆ m_histTotal

Int_t TRootCompare::m_histTotal {}
private

Definition at line 76 of file TRootCompare.h.

76{};

◆ m_noMatch

std::vector<std::string> TRootCompare::m_noMatch
private

Definition at line 82 of file TRootCompare.h.

◆ m_outFile

TFile* TRootCompare::m_outFile {}
private

Definition at line 68 of file TRootCompare.h.

68{};

◆ m_passBeforeFail

Bool_t TFileLooper::m_passBeforeFail {kFALSE}
protectedinherited

Definition at line 93 of file TFileLooper.h.

93{kFALSE};

◆ m_passRE

std::vector<TPRegexp> TFileLooper::m_passRE
protectedinherited

Definition at line 97 of file TFileLooper.h.

◆ m_psFile

TString TRootCompare::m_psFile {}
private

Definition at line 70 of file TRootCompare.h.

70{};

◆ m_refFile

TFile* TRootCompare::m_refFile {}
private

Definition at line 67 of file TRootCompare.h.

67{};

◆ m_refRootDir

TString TRootCompare::m_refRootDir {}
private

Definition at line 69 of file TRootCompare.h.

69{};

◆ m_rootDir

TString TFileLooper::m_rootDir
protectedinherited

Definition at line 90 of file TFileLooper.h.

◆ m_skipDirs

TString TFileLooper::m_skipDirs
protectedinherited

Definition at line 91 of file TFileLooper.h.

◆ m_skippedObjects

std::vector<std::string> TFileLooper::m_skippedObjects
protectedinherited

Definition at line 99 of file TFileLooper.h.

◆ m_sortLabels

Bool_t TRootCompare::m_sortLabels {kTRUE}
private

Definition at line 80 of file TRootCompare.h.

80{kTRUE};

◆ m_threshold

Double_t TRootCompare::m_threshold {1e-6}
private

Definition at line 74 of file TRootCompare.h.

◆ m_verbose

Bool_t TFileLooper::m_verbose {kFALSE}
protectedinherited

Definition at line 92 of file TFileLooper.h.

92{kFALSE};

The documentation for this class was generated from the following files: