ATLAS Offline Software
Macros | Functions
comphistpars.h File Reference
#include "rootincludes.h"
#include "jobflags.h"
#include <cmath>
Include dependency graph for comphistpars.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define xstringify(s)   str(s)
 
#define stringify(s)   #s
 
#define REPORT(x)   { std::cout << " -> ERROR: "<<x<<std::endl; }
 
#define TESTSIMPLEVAR(varname)
 
#define TESTSIMPLEEXTVAR(var1, var2, varname)
 
#define TESTSIMPLEUNSUPPORTEDSTYLEVAR(varname)   { if (!cfg_ignore_unsupported_style_vars) { TESTSIMPLEVAR(varname); } }
 
#define ACTUALTESTARRAY(a, b, name)
 
#define TESTASARRAY()   {ACTUALTESTARRAY(h1,h2,"")}
 
#define TESTARRAY(varname)   {ACTUALTESTARRAY(&(h1->varname),&(h2->varname),stringify(varname))}
 
#define TESTARRAYPTR(varname)   {ACTUALTESTARRAY((h1->varname),(h2->varname),stringify(varname))}
 

Functions

template<class T >
bool checkParameters (T *h1, T *h2)
 
template<class T >
bool varCompatible (const T var1, const T var2)
 
bool floatingpointcompat (double var1, double var2, const double &epsilon)
 
template<>
bool varCompatible (const double var1, const double var2)
 
template<>
bool varCompatible (const float var1, const float var2)
 
template<>
bool varCompatible (const char *var1, const char *var2)
 
template<>
bool varCompatible (TString var1, TString var2)
 
template<class TContainedType >
bool tlistsCompatible (const TList *h1, const TList *h2)
 
template<>
bool varCompatible (TFunction var1, TFunction var2)
 
template<class TArrayX >
bool arrayCompatible (const TArrayX *a1, const TArrayX *a2, const char *name)
 
bool axisCompatible (const TAxis *h1, const TAxis *h2)
 
template<>
bool checkParameters (TH1 *h1, TH1 *h2)
 
template<>
bool checkParameters (TH1F *h1, TH1F *h2)
 
template<>
bool checkParameters (TH1D *h1, TH1D *h2)
 
template<>
bool checkParameters (TH1I *h1, TH1I *h2)
 
template<>
bool checkParameters (TH1C *h1, TH1C *h2)
 
template<>
bool checkParameters (TH1S *h1, TH1S *h2)
 
template<>
bool checkParameters (TH2 *h1, TH2 *h2)
 
template<>
bool checkParameters (TH2F *h1, TH2F *h2)
 
template<>
bool checkParameters (TH2D *h1, TH2D *h2)
 
template<>
bool checkParameters (TH2I *h1, TH2I *h2)
 
template<>
bool checkParameters (TH2C *h1, TH2C *h2)
 
template<>
bool checkParameters (TH2S *h1, TH2S *h2)
 
template<>
bool checkParameters (TProfile *h1, TProfile *h2)
 
template<>
bool checkParameters (TProfile2D *h1, TProfile2D *h2)
 

Macro Definition Documentation

◆ ACTUALTESTARRAY

#define ACTUALTESTARRAY (   a,
  b,
  name 
)
Value:
{ if (!arrayCompatible(a,b,name)) { \
return false; } }

Definition at line 118 of file comphistpars.h.

◆ REPORT

#define REPORT (   x)    { std::cout << " -> ERROR: "<<x<<std::endl; }

Definition at line 25 of file comphistpars.h.

◆ stringify

#define stringify (   s)    #s

Definition at line 23 of file comphistpars.h.

◆ TESTARRAY

#define TESTARRAY (   varname)    {ACTUALTESTARRAY(&(h1->varname),&(h2->varname),stringify(varname))}

Definition at line 123 of file comphistpars.h.

◆ TESTARRAYPTR

#define TESTARRAYPTR (   varname)    {ACTUALTESTARRAY((h1->varname),(h2->varname),stringify(varname))}

Definition at line 124 of file comphistpars.h.

◆ TESTASARRAY

#define TESTASARRAY ( )    {ACTUALTESTARRAY(h1,h2,"")}

Definition at line 122 of file comphistpars.h.

◆ TESTSIMPLEEXTVAR

#define TESTSIMPLEEXTVAR (   var1,
  var2,
  varname 
)
Value:
{ if (!varCompatible(var1,var2)) { \
REPORT("Incompatible values of "<<stringify(varname)<<" ("<<var1<<" vs. "<<var2<<")"); \
return false; } }

Definition at line 90 of file comphistpars.h.

◆ TESTSIMPLEUNSUPPORTEDSTYLEVAR

#define TESTSIMPLEUNSUPPORTEDSTYLEVAR (   varname)    { if (!cfg_ignore_unsupported_style_vars) { TESTSIMPLEVAR(varname); } }

Definition at line 95 of file comphistpars.h.

◆ TESTSIMPLEVAR

#define TESTSIMPLEVAR (   varname)
Value:
{ if (!varCompatible(h1->varname,h2->varname)) { \
REPORT("Incompatible values of "<<stringify(varname)<<" ("<<h1->varname<<" vs. "<<h2->varname<<")"); \
return false; } }

Definition at line 85 of file comphistpars.h.

◆ xstringify

#define xstringify (   s)    str(s)

Definition at line 22 of file comphistpars.h.

Function Documentation

◆ arrayCompatible()

template<class TArrayX >
bool arrayCompatible ( const TArrayX *  a1,
const TArrayX *  a2,
const char *  name 
)

Definition at line 98 of file comphistpars.h.

98  {
99  if (!varCompatible(a1->fN,a2->fN)) {
100  REPORT("Incompatible arrays "<<name<<" (number of entries)");
101  return false;
102  }
103  if (a1->fArray==0&&a2->fArray==0)
104  return true;
105  if (a1->fArray==0||a2->fArray==0) {
106  REPORT("Incompatible arrays "<<name<<" (one NULL, one not NULL)"); \
107  return false;
108  }
109  for (int i = 0; i < a1->fN; ++i)
110  if (!varCompatible(a1->fArray[i],a2->fArray[i])) {
111  REPORT("Incompatible arrays "<<name<<" (at least one entry incompatible)"); \
112  return false;
113  }
114  return true;
115 }

◆ axisCompatible()

bool axisCompatible ( const TAxis *  h1,
const TAxis *  h2 
)

Definition at line 125 of file comphistpars.h.

125  {
126  //TAxis:
127  TESTSIMPLEVAR(GetNbins());
128  TESTSIMPLEVAR(GetXmin());
129  TESTSIMPLEVAR(GetXmax());
130  TESTSIMPLEVAR(GetFirst());
131  TESTSIMPLEVAR(GetLast());
132  //TESTSIMPLEVAR(IsAlphanumeric());
133  //TESTSIMPLEVAR(CanBeAlphanumeric());
134  TESTSIMPLEVAR(CanExtend());
135  TESTSIMPLEVAR(GetTimeDisplay());
136  TESTSIMPLEVAR(GetTimeFormat());
137  TESTARRAYPTR(GetXbins());
138  if (!tlistsCompatible<TString>((TList*)(h1->GetLabels()),(TList*)(h2->GetLabels()))) {
139  REPORT("Incompatible fLabels");
140  return false;
141  }
142  //TAttAxis:
143  TESTSIMPLEUNSUPPORTEDSTYLEVAR(GetNdivisions());
144  TESTSIMPLEUNSUPPORTEDSTYLEVAR(GetAxisColor());
145  TESTSIMPLEVAR(GetLabelColor());
146  TESTSIMPLEVAR(GetLabelFont());
147  TESTSIMPLEVAR(GetLabelOffset());
148  TESTSIMPLEVAR(GetLabelSize());
149  TESTSIMPLEUNSUPPORTEDSTYLEVAR(GetTickLength());
150  TESTSIMPLEUNSUPPORTEDSTYLEVAR(GetTitleOffset());
151  TESTSIMPLEVAR(GetTitleSize());
152  TESTSIMPLEVAR(GetTitleColor());
153  TESTSIMPLEVAR(GetTitleFont());
154  //TNamed:
155  TESTSIMPLEVAR(GetName());
156  TESTSIMPLEVAR(GetTitle());
157  return true;
158 }

◆ checkParameters() [1/15]

template<class T >
bool checkParameters ( T *  h1,
T *  h2 
)

◆ checkParameters() [2/15]

template<>
bool checkParameters ( TH1 h1,
TH1 h2 
)

Definition at line 192 of file comphistpars.h.

193 {
194  assert(h1!=h2);
195  assert(h1&&h2);
196  //TH1:
197  //Ignore fDirectory and buffer related methods.
199  TESTSIMPLEVAR(GetMaximumStored());
200  TESTSIMPLEVAR(GetMinimumStored());
201  TESTSIMPLEVAR(GetNormFactor());
202  Double_t stats1[20], stats2[20];
203  h1->GetStats(stats1);
204  h2->GetStats(stats2);
205  TESTSIMPLEEXTVAR(stats1[0], stats2[0], fTsumw);
206  TESTSIMPLEEXTVAR(stats1[1], stats2[1], fTsumw2);
207  TESTSIMPLEEXTVAR(stats1[2], stats2[2], fTsumwx);
208  TESTSIMPLEEXTVAR(stats1[3], stats2[3], fTsumwx2);
209  TESTSIMPLEVAR(GetDimension());
210  TESTSIMPLEVAR(GetNcells());
211  TESTSIMPLEVAR(GetBarOffset());
212  TESTSIMPLEVAR(GetBarWidth());
213 
214  Int_t nlevels1 = h1->GetContour(nullptr);
215  Int_t nlevels2 = h2->GetContour(nullptr);
216  TESTSIMPLEEXTVAR (nlevels1, nlevels2, fContour.fN);
217  if (nlevels1 > 0) {
218  TArrayD levels1 (nlevels1);
219  TArrayD levels2 (nlevels1);
220  h1->GetContour (levels1.GetArray());
221  h2->GetContour (levels2.GetArray());
222  ACTUALTESTARRAY(&levels1, &levels2, "fContour");
223  }
224 
225  bool test_sumw2(true);
227  if ((h1->GetSumw2()->fN==0||h2->GetSumw2()->fN==0) && ((h1->GetSumw2()->fN==0)!=(h2->GetSumw2()->fN==0)))
228  test_sumw2 = false;
229  }
230  if (test_sumw2)
231  TESTARRAYPTR(GetSumw2());
232  TESTSIMPLEVAR(GetOption());
233  if (!tlistsCompatible<TFunction>(h1->GetListOfFunctions(),h2->GetListOfFunctions())) {
234  REPORT("Incompatible fXaxis");
235  return false;
236  }
237  if (!axisCompatible(h1->GetXaxis(), h2->GetXaxis())) {
238  REPORT("Incompatible fXaxis");
239  return false;
240  }
241  if (!axisCompatible(h1->GetYaxis(), h2->GetYaxis())) {
242  REPORT("Incompatible fYaxis");
243  return false;
244  }
245  if (!axisCompatible(h1->GetZaxis(), h2->GetZaxis())) {
246  REPORT("Incompatible fZaxis");
247  return false;
248  }
249 
250  //TNamed:
251  //Ignore fName
252  TESTSIMPLEVAR(GetTitle());
253  //TAttLine:
254  TESTSIMPLEVAR(GetLineColor());
255  TESTSIMPLEVAR(GetLineStyle());
256  TESTSIMPLEVAR(GetLineWidth());
257  //TAttFill:
258  TESTSIMPLEVAR(GetFillColor());
259  TESTSIMPLEVAR(GetFillStyle());
260  //TAttMarker:
261  TESTSIMPLEVAR(GetMarkerColor());
262  TESTSIMPLEVAR(GetMarkerStyle());
263  TESTSIMPLEVAR(GetMarkerSize());
264  //TObject:
265  //Ignore fUniqueID
266  for (int i=0; i < 32; i++)
267  TESTSIMPLEVAR(TestBit(i));
268  return true;
269 }

◆ checkParameters() [3/15]

template<>
bool checkParameters ( TH1C h1,
TH1C h2 
)

Definition at line 275 of file comphistpars.h.

275 { TESTASARRAY(); return true; }

◆ checkParameters() [4/15]

template<>
bool checkParameters ( TH1D h1,
TH1D h2 
)

Definition at line 273 of file comphistpars.h.

273 { TESTASARRAY(); return true; }

◆ checkParameters() [5/15]

template<>
bool checkParameters ( TH1F h1,
TH1F h2 
)

Definition at line 272 of file comphistpars.h.

272 { TESTASARRAY(); return true; }

◆ checkParameters() [6/15]

template<>
bool checkParameters ( TH1I h1,
TH1I h2 
)

Definition at line 274 of file comphistpars.h.

274 { TESTASARRAY(); return true; }

◆ checkParameters() [7/15]

template<>
bool checkParameters ( TH1S h1,
TH1S h2 
)

Definition at line 276 of file comphistpars.h.

276 { TESTASARRAY(); return true; }

◆ checkParameters() [8/15]

template<>
bool checkParameters ( TH2 h1,
TH2 h2 
)

Definition at line 279 of file comphistpars.h.

280 {
281  //TESTSIMPLEVAR(fScalefactor);
282  Double_t stats1[20], stats2[20];
283  h1->GetStats(stats1);
284  h2->GetStats(stats2);
285  TESTSIMPLEEXTVAR(stats1[4], stats2[4], fTsumwy);
286  TESTSIMPLEEXTVAR(stats1[5], stats2[5], fTsumwy2);
287  TESTSIMPLEEXTVAR(stats1[6], stats2[6], fTsumwxy);
288  return true;
289 }

◆ checkParameters() [9/15]

template<>
bool checkParameters ( TH2C h1,
TH2C h2 
)

Definition at line 294 of file comphistpars.h.

294 { TESTASARRAY(); return true; }

◆ checkParameters() [10/15]

template<>
bool checkParameters ( TH2D h1,
TH2D h2 
)

Definition at line 292 of file comphistpars.h.

292 { TESTASARRAY(); return true; }

◆ checkParameters() [11/15]

template<>
bool checkParameters ( TH2F h1,
TH2F h2 
)

Definition at line 291 of file comphistpars.h.

291 { TESTASARRAY(); return true; }

◆ checkParameters() [12/15]

template<>
bool checkParameters ( TH2I h1,
TH2I h2 
)

Definition at line 293 of file comphistpars.h.

293 { TESTASARRAY(); return true; }

◆ checkParameters() [13/15]

template<>
bool checkParameters ( TH2S h1,
TH2S h2 
)

Definition at line 295 of file comphistpars.h.

295 { TESTASARRAY(); return true; }

◆ checkParameters() [14/15]

template<>
bool checkParameters ( TProfile h1,
TProfile h2 
)

Definition at line 297 of file comphistpars.h.

298 {
299  TESTSIMPLEVAR(GetNcells());
300  Int_t sz = h1->GetNcells();
301  for (Int_t i = 0; i < sz; i++)
302  TESTSIMPLEVAR (GetBinEntries(i));
303  TESTSIMPLEVAR(GetErrorOption());
304  TESTSIMPLEVAR(GetYmin());
305  TESTSIMPLEVAR(GetYmax());
306  //TESTSIMPLEVAR(fScaling);
307  Double_t stats1[20], stats2[20];
308  h1->GetStats(stats1);
309  h2->GetStats(stats2);
310  TESTSIMPLEEXTVAR(stats1[4], stats2[4], fTsumwy);
311  TESTSIMPLEEXTVAR(stats1[5], stats2[5], fTsumwy2);
312  return true;
313 }

◆ checkParameters() [15/15]

template<>
bool checkParameters ( TProfile2D h1,
TProfile2D h2 
)

Definition at line 315 of file comphistpars.h.

316 {
317  TESTSIMPLEVAR(GetNcells());
318  Int_t sz = h1->GetNcells();
319  for (Int_t i = 0; i < sz; i++)
320  TESTSIMPLEVAR (GetBinEntries(i));
321  TESTSIMPLEVAR(GetErrorOption());
322  TESTSIMPLEVAR(GetZmin());
323  TESTSIMPLEVAR(GetZmax());
324  //TESTSIMPLEVAR(fScaling);
325  Double_t stats1[20], stats2[20];
326  h1->GetStats(stats1);
327  h2->GetStats(stats2);
328  TESTSIMPLEEXTVAR(stats1[7], stats2[7], fTsumwz);
329  TESTSIMPLEEXTVAR(stats1[8], stats2[8], fTsumwz2);
330  return true;
331 }

◆ floatingpointcompat()

bool floatingpointcompat ( double  var1,
double  var2,
const double &  epsilon 
)
inline

Definition at line 44 of file comphistpars.h.

45 {
46  const bool var1_nan = (var1!=var1);
47  const bool var2_nan = (var2!=var2);
48  if (var1_nan&&var2_nan) {
49  if (cfg_report_NaN)
50  std::cout<<"WARNING: Spotted NaN values in floating point number (but same in both of the compared histograms)!"<<std::endl;
51  return true;
52  }
53  if (var1_nan||var2_nan) {
54  if (cfg_report_NaN)
55  REPORT("Spotted NaN values in floating point number (from only one of the compared histograms)!");
56  return false;
57  }
58  const double test(fabs(var1-var2)/(1.0+std::max<double>(fabs(var1),fabs(var2))));
59  // if (!(test<epsilon)) {
60  // std::cout<<"NB: var difference: "<<var1<<" vs. "<<var2<<" :"<<test<<std::endl;
61  // }
62  return test<epsilon;
63 }

◆ tlistsCompatible()

template<class TContainedType >
bool tlistsCompatible ( const TList *  h1,
const TList *  h2 
)

Definition at line 161 of file comphistpars.h.

161  {
162  if (!h1&&!h2)
163  return true;
164  if (!h1||!h2)
165  return false;
166  //TCollection:
167  TESTSIMPLEVAR(GetName());
168  TESTSIMPLEVAR(Capacity());
169  //TSeqCollection:
170  TESTSIMPLEVAR(IsSorted());
171  //For the TList itself we loop, cast each element to TContainedType,
172  //and compare using operator==.
173  Int_t sz = h1->Capacity();
174  for (int i = 0; i<sz; ++i) {
175  TContainedType * t1 = dynamic_cast<TContainedType*>(h1->At(i));
176  TContainedType * t2 = dynamic_cast<TContainedType*>(h1->At(i));
177  if (!t1&&!t2)
178  continue;
179  if (!t1||!t2)
180  return false;
181  if (!varCompatible(*t1,*t2))
182  return false;
183  }
184  return true;
185 }

◆ varCompatible() [1/6]

template<>
bool varCompatible ( const char *  var1,
const char *  var2 
)

Definition at line 66 of file comphistpars.h.

66 { return std::string(var1)==std::string(var2); }

◆ varCompatible() [2/6]

template<>
bool varCompatible ( const double  var1,
const double  var2 
)

Definition at line 64 of file comphistpars.h.

64 { return floatingpointcompat(var1,var2,1.0e-5); }

◆ varCompatible() [3/6]

template<>
bool varCompatible ( const float  var1,
const float  var2 
)

Definition at line 65 of file comphistpars.h.

65 { return floatingpointcompat(var1,var2,1.0e-3); }

◆ varCompatible() [4/6]

template<class T >
bool varCompatible ( const var1,
const var2 
)

Definition at line 25 of file comphistpars.h.

25  {
26  if (var1==var2)
27  return true;
28  const bool var1_nan = std::isnan(var1);
29  const bool var2_nan = std::isnan(var2);
30  if (var1_nan&&var2_nan) {
31  if (cfg_report_NaN)
32  std::cout<<"WARNING: Spotted NaN values in parameter (but same in both of the compared histograms)!"<<std::endl;
33  return true;
34  }
35  if (var1_nan||var2_nan) {
36  if (cfg_report_NaN)
37  REPORT("Spotted NaN values in parameter (from only one of the compared histograms)!");
38  return false;
39  }
40  REPORT("different values found: "<<var1<<" vs. "<<var2);
41  return false;
42 }

◆ varCompatible() [5/6]

template<>
bool varCompatible ( TFunction  var1,
TFunction  var2 
)

Definition at line 73 of file comphistpars.h.

74 {
75  if (!varCompatible(var1.GetMangledName(), var2.GetMangledName()))
76  return false;
77  if (!varCompatible(var1.GetSignature(), var2.GetSignature()))
78  return false;
79  if (!tlistsCompatible<TString>(var1.GetListOfMethodArgs(), var2.GetListOfMethodArgs()))
80  return false;
81  return true;
82 }

◆ varCompatible() [6/6]

template<>
bool varCompatible ( TString  var1,
TString  var2 
)

Definition at line 67 of file comphistpars.h.

67 { return var1 == var2; }
cfg_ignore_errors_related_to_a_non_existant_sumw2_array
std::atomic< bool > cfg_ignore_errors_related_to_a_non_existant_sumw2_array
Definition: jobflags.h:11
REPORT
#define REPORT(x)
Definition: comphistpars.h:24
fitman.sz
sz
Definition: fitman.py:527
varCompatible
bool varCompatible(const T var1, const T var2)
Definition: comphistpars.h:25
TESTSIMPLEEXTVAR
#define TESTSIMPLEEXTVAR(var1, var2, varname)
Definition: comphistpars.h:89
ACTUALTESTARRAY
#define ACTUALTESTARRAY(a, b, name)
Definition: comphistpars.h:117
TESTASARRAY
#define TESTASARRAY()
Definition: comphistpars.h:121
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:144
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
arrayCompatible
bool arrayCompatible(const TArrayX *a1, const TArrayX *a2, const char *name)
Definition: comphistpars.h:98
axisCompatible
bool axisCompatible(const TAxis *h1, const TAxis *h2)
Definition: comphistpars.h:125
TESTSIMPLEVAR
#define TESTSIMPLEVAR(varname)
Definition: comphistpars.h:84
lumiFormat.i
int i
Definition: lumiFormat.py:92
TESTARRAYPTR
#define TESTARRAYPTR(varname)
Definition: comphistpars.h:123
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
cfg_report_NaN
std::atomic< bool > cfg_report_NaN
Definition: jobflags.h:9
floatingpointcompat
bool floatingpointcompat(double var1, double var2, const double &epsilon)
Definition: comphistpars.h:44
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
LArG4AODNtuplePlotter.varname
def varname(hname)
Definition: LArG4AODNtuplePlotter.py:37
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
a
TList * a
Definition: liststreamerinfos.cxx:10
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
stringify
#define stringify(s)
Definition: comphistpars.h:22
TESTSIMPLEUNSUPPORTEDSTYLEVAR
#define TESTSIMPLEUNSUPPORTEDSTYLEVAR(varname)
Definition: comphistpars.h:94