14 const std::string& file2,
int testOnly = 127,
15 int*
result = 0,
float eps = 1e-5) {
16 std::unique_ptr<TFile> f1( TFile::Open(file1.c_str()) );
17 std::unique_ptr<TFile> f2( TFile::Open(file2.c_str()) );
19 if (!f1 || f1->IsZombie() || !f2 || f2->IsZombie()) {
20 if (!f1 || f1->IsZombie()) {
21 std::cout <<
"could not open file1 " << file1 << std::endl;
23 if (!f2 || f2->IsZombie()) {
24 std::cout <<
"could not open file2 " << file2 << std::endl;
34 const char hnames[hnum][100] = {
35 "h3_w",
"h3_eta",
"h3_phi",
"h3_R",
36 "h3_eta_phi_response",
"h3_eta_phi_offset",
46 char hresult[hnum][30] = {
47 "same",
"not found",
"different dimensions",
48 "different axes",
"different bins",
"different bin content"};
50 for (
int h = 0;
h < hnum;
h++) {
51 if (!(testOnly & (1 <<
h))) {
56 TH1* h1 = (TH1*)f1->Get(hnames[
h]);
59 h1->SetName(Form(
"%s_h1", hnames[
h]));
62 TH1* h2 = (TH1*)f2->Get(hnames[
h]);
65 h2->SetName(Form(
"%s_h2", hnames[
h]));
70 std::cout <<
"could not find histogram " << hnames[
h] <<
" in file1 "
71 << file1 << std::endl;
74 std::cout <<
"could not find histogram " << hnames[
h] <<
" in file2 "
75 << file2 << std::endl;
83 int dim1 = h1->GetDimension();
84 int dim2 = h2->GetDimension();
86 std::cout <<
"h1 " << h1->GetName() <<
" has dimension " << dim1
87 <<
", h2 " << h2->GetName() <<
" has dimension " << dim2
94 if (h1->GetNbinsX() != h2->GetNbinsX() ||
95 (dim1 > 1 && h1->GetNbinsY() != h2->GetNbinsY()) ||
96 (dim1 > 2 && h1->GetNbinsZ() != h2->GetNbinsZ())) {
97 if (h1->GetNbinsX() != h2->GetNbinsX()) {
98 std::cout <<
"h1 " << h1->GetName() <<
" has " << h1->GetNbinsX()
99 <<
" bins in X, h2 " << h2->GetName() <<
" has "
100 << h2->GetNbinsX() <<
" bins in X" << std::endl;
102 if (h1->GetNbinsY() != h2->GetNbinsY()) {
103 std::cout <<
"h1 " << h1->GetName() <<
" has " << h1->GetNbinsY()
104 <<
" bins in Y, h2 " << h2->GetName() <<
" has "
105 << h2->GetNbinsY() <<
" bins in Y" << std::endl;
107 if (h1->GetNbinsZ() != h2->GetNbinsZ()) {
108 std::cout <<
"h1 " << h1->GetName() <<
" has " << h1->GetNbinsZ()
109 <<
" bins in Z, h2 " << h2->GetName() <<
" has "
110 << h2->GetNbinsZ() <<
" bins in Z" << std::endl;
119 int dim = h1->GetDimension();
120 for (
int d = 1; d <= dim; d++) {
135 if((not a1) or (not a2)) {
136 std::cout <<
"h1 " << h1->GetName() <<
" has pointer to " << char(
'W'+d)
137 <<
"-axis = " << a1 <<
", h2 " << h2->GetName()
138 <<
" has pointer to " << char(
'W'+d) <<
"-axis = " << a2
145 for (
int b = 1; b <= a1->GetNbins() + 1; ++b) {
146 if (a1->GetBinLowEdge(b) != a2->GetBinLowEdge(b)) {
149 std::cout <<
"h1 " << h1->GetName() <<
" has bin " << b
150 <<
" with low edge " << a1->GetBinLowEdge(b) <<
", h2 "
151 << h2->GetName() <<
" has bin " << b <<
" with low edge "
152 << a2->GetBinLowEdge(b) << std::endl;
165 for (
int bx = 1; bx <= h1->GetNbinsX(); ++bx) {
166 for (
int by = 1; by <= h1->GetNbinsY(); ++by) {
167 for (
int bz = 1; bz <= h1->GetNbinsZ(); ++bz) {
168 if (TMath::Abs(h1->GetBinContent(bx, by, bz) - h2->GetBinContent(bx, by, bz)) > eps) {
171 std::cout <<
"h1 " << h1->GetName() <<
" has "
172 << h1->GetBinContent(bx, by, bz) <<
" in bin " << bx
173 <<
"," << by <<
"," << bz <<
", h2 " << h2->GetName()
174 <<
" has " << h2->GetBinContent(bx, by, bz) << std::endl;
175 std::cout <<
"skipping the rest of bins" << std::endl;
196 for (
int h = 0;
h < hnum;
h++) {
197 if (!(testOnly & (1 <<
h))) {
200 std::cout << hnames[
h] <<
": " << hresult[hdiff[
h]] << std::endl;
209int main(
int argc,
char** argv) {
210 if (argc < 3 || argc > 5) {
211 std::cout <<
"Syntax: " << argv[0] <<
" file1 file2 [testOnly [epsilon]]"
217 int testOnly = (argc > 3 ? std::stoi(argv[3]) : 127);
218 if (testOnly > 127) {
219 std::cout <<
"Warning: testOnly should be an integer between 1 and 127, it "
221 << testOnly <<
", changing to " << testOnly <<
"%128 = ";
223 std::cout << testOnly << std::endl;
226 std::cout <<
"Warning: testOnly should be an integer between 1 and 127, it "
228 << testOnly <<
", nothing to do here" << std::endl;
232 float epsilon = (argc > 4 ? std::stof(argv[4]) : 1e-5);
234 std::cout <<
"Warning: epsilon should be a possitive number, it is now "
235 << epsilon <<
", changing to 0.0" << std::endl;