forked from cms-analysis/HiggsAnalysis-HiggsToTauTau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateInput.C
67 lines (60 loc) · 1.92 KB
/
validateInput.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <string>
#include <vector>
#include <iostream>
#include <regex.h>
#include <sys/types.h>
#include <TKey.h>
#include <TH1F.h>
#include <TFile.h>
#include <TROOT.h>
#include <TString.h>
#include <TLegend.h>
#include <TPaveText.h>
#include <TCollection.h>
/**
\class validateInput validateInput.C "HiggsAnalysis/HiggsToTauTau/macros/validateInput.C"
\brief macro to perform some minimal validation of the histograms in a root input file.
*/
void
validateFolder(TFile* file, const char* folder="", int level=-1)
{
TIter next(gDirectory->GetListOfKeys());
TKey* iobj;
unsigned int idx=0;
while((iobj = (TKey*)next())){
if(iobj->IsFolder()) continue;
if(level>1){ std::cout << "[" << ++idx << "] ...Found object: " << iobj->GetName() << " of type: " << iobj->GetClassName() << std::endl; }
std::string fullpath(folder);
fullpath += (fullpath == std::string("")) ? "" : "/"; fullpath += iobj->GetName();
TH1F* h = (TH1F*)file->Get(fullpath.c_str());
if(h->Integral() == 0){
std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << fullpath << std::endl;
}
}
return;
}
void validateInput(const char* filename, int level=0)
{
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
TKey* idir;
while((idir = (TKey*)nextDirectory())){
file->cd();
if( idir->IsFolder() ){
if( level>-1 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
file->cd(idir->GetName());
validateFolder(file, idir->GetName(), level);
}
else{
if( level> 0 ){ std::cout << "Found histogram: " << idir->GetName() << std::endl; }
if( level>-1 ){
TH1F* h = (TH1F*)file->Get(idir->GetName());
if(h->Integral() == 0){
std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << idir->GetName() << std::endl;
}
}
}
}
file->Close();
return;
}