forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dt_RunDrawTest.C
199 lines (175 loc) · 5.69 KB
/
dt_RunDrawTest.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "TCanvas.h"
#include "TClassTable.h"
#include "TFile.h"
#include "TH1.h"
#include "TKey.h"
#include "TChain.h"
#include "TSystem.h"
#include "TBranchElement.h"
#include "Riostream.h"
#include "dt_DrawTest.C"
Bool_t gInteractiveTest = kTRUE;
Int_t gQuietLevel = 0;
//_______________________________________________________________
Int_t HistCompare(TH1 *ref, TH1 *comp)
{
// Compare histograms h1 and h2
// Check number of entries, mean and rms
// if means differ by more than 1/1000 of the range return -1
// if means differ by more than 1/100 of the original mean return -2
// if rms differs in percent by more than 1/1000 return -3
// Otherwise return difference of number of entries
Int_t n1 = (Int_t)ref->GetEntries();
Double_t mean1 = ref->GetMean();
Double_t rms1 = ref->GetRMS();
Int_t n2 = (Int_t)comp->GetEntries();
Double_t mean2 = comp->GetMean();
Double_t rms2 = comp->GetRMS();
Int_t factor = 1;
if (n2==2*n1) {
// we have a chain.
factor = 2;
}
Float_t xrange = ref->GetXaxis()->GetXmax() - ref->GetXaxis()->GetXmin();
if (xrange==0) { fprintf(stderr,"no range for %s\n",ref->GetName()); return -4; }
if (xrange>0.0001 && TMath::Abs((mean1-mean2)/xrange) > 0.001) {
printf("xrange=%g, mean1=%g, mean2=%g, abs=%g\n",xrange,mean1,mean2,TMath::Abs((mean1-mean2)/xrange));
return -1;
}
if (mean2> 0.0001 && TMath::Abs((mean1-mean2)/mean2) > 0.01) {
printf("mean1=%g, mean2=%g, abs=%g\n",mean1,mean2,TMath::Abs((mean1-mean2)/mean2));
return -2;
}
if (rms1 > 0.0001 && TMath::Abs((rms1-rms2)/rms1) > 0.0003) {
printf("rms1=%g, rms2=%g, abs=%g\n",rms1,rms2,TMath::Abs((rms1-rms2)/rms1));
return -3;
}
return n1*factor-n2;
}
Int_t Compare(TDirectory* from) {
TFile * reffile = new TFile("dt_reference.root");
TIter next(reffile->GetListOfKeys());
TH1 *ref, *draw;
const char* name;
Int_t comp;
Int_t fail = 0;
TKey* key;
while ((key=(TKey*)next())) {
if (strcmp(key->GetClassName(),"TH1F")
&& strcmp(key->GetClassName(),"TH2F") )
continue; //may be a TList of TStreamerInfo
ref = (TH1*)reffile->Get(key->GetName());
name = ref->GetName();
if (strncmp(name,"ref",3)) continue;
name += 3;
draw = (TH1*)from->Get(name);
if (!draw) {
if (!gSkipped.FindObject(name)) {
cerr << "Miss: " << name << endl;
fail++;
}
continue;
}
comp = HistCompare(ref,draw);
if (comp!=0) {
cerr << "Fail: " << name << ":" << comp << " " << ref->GetTitle() << endl;
fail++;
if (gInteractiveTest) {
TCanvas * canv = new TCanvas();
canv->Divide(2,1);
canv->cd(1);
TString reftitle = "Ref: ";
reftitle.Append(ref->GetTitle());
ref->SetTitle(reftitle);
ref->Draw();
canv->cd(2); draw->Draw();
return 1;
}
} else {
if (gQuietLevel<1) cerr << "Succ: " << name << ":" << comp << endl;
}
}
delete reffile;
return fail;
}
void SetVerboseLevel(Int_t verboseLevel) {
switch (verboseLevel) {
case 0: gInteractiveTest = kFALSE;
gQuietLevel = 2;
break;
case 1: gInteractiveTest = kFALSE;
gQuietLevel = 1;
break;
case 2: gInteractiveTest = kFALSE;
gQuietLevel = 0;
break;
case 3: gInteractiveTest = kTRUE;
gQuietLevel = 0;
break;
}
}
bool dt_RunDrawTest(const char* from, Int_t mode = 0, Int_t verboseLevel = 0) {
// This launch a test a TTree::Draw.
// The mode currently available are:
// 0: Do not load the shared library
// 1: Load the shared library before opening the file
// 2: Load the shared library after opening the file
// 3: Simple TChain test with shared library
// 4: Simple Friend test with shared library
// The verboseLeve currently available:
// 0: As silent as possible, only report errors and overall speed results.
// 1: Output 0 + label for the start of each phase
// 2: Output 1 + more details on the different phase being done
// 3: Output 2 + stop at the first and draw a canvas showing the differences
//gDebug = 5;
SetVerboseLevel(verboseLevel);
if (mode == 1) {
if (!TClassTable::GetDict("Event")) {
gSystem->Load("libEvent");
}
gHasLibrary = kTRUE;
}
TFile *hfile = 0;
TTree *tree = 0;
if (mode <3) {
hfile = new TFile(from);
tree = (TTree*)hfile->Get("T");
}
if (mode >= 2 && mode <= 4) {
if (!TClassTable::GetDict("Event")) {
gSystem->Load("libEvent");
} else {
cerr << "Since libEvent.so has already been loaded, mode 2 can not be tested!";
cerr << endl;
}
gHasLibrary = kTRUE;
}
if (mode == 3) {
// Test Chains.
TChain * chain = new TChain("T");
chain->Add(from);
chain->Add(from);
tree = chain;
}
if (mode == 4) {
// Test friends.
tree = new TTree("T","Base of friendship");
tree->AddFriend("T",from);
}
TBranch *eb = tree->GetBranch("event");
gBranchStyle = (int) eb->InheritsFrom(TBranchElement::Class());
// cerr << "Branch style is " << gBranchStyle << endl;
if (gQuietLevel<2) cout << "Generating histograms from TTree::Draw" << endl;
TDirectory* where = GenerateDrawHist(tree,gQuietLevel);
if (gQuietLevel<2) cout << "Comparing histograms" << endl;
if (Compare(where)>0) {
cout << "DrawTest: Comparison failed" << endl;
return false;
}
DrawMarks();
if (gQuietLevel<2) cout << "DrawTest: Comparison was successfull" << endl;
if (hfile) delete hfile;
else delete tree;
gROOT->GetList()->Delete();
return true;
}