Skip to content

Commit 8c20c6a

Browse files
Benedikt Volkelchiarazampolli
authored andcommitted
Further devs
* add back potential identical check of histograms * give a summary of number of processed histograms and print potential identical histograms
1 parent 61e6e63 commit 8c20c6a

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

RelVal/ReleaseValidation.C

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void WriteTEfficiency(TEfficiency* obj, TDirectory* outDir, std::string const& c
3535
void WriteToDirectory(TObject* obj, TDirectory* dir, std::string const& prefix = "");
3636
void CompareHistos(TH1* hA, TH1* hB, int whichTest, double valChi2, double valMeanDiff, double valEntriesDiff,
3737
bool firstComparison, bool finalComparison, TH2F* hSum, TH2F* hTests);
38+
bool PotentiallySameHistograms(TH1*, TH1*);
3839
struct results CompareChiSquareBinContentNentr(TH1* hA, TH1* hB, options whichTest, double varChi2, double varMeanDiff, double valEntriesDiff);
3940
void DrawRatio(TH1* hR);
4041
void DrawRelativeDifference(TH1* hR);
@@ -47,6 +48,12 @@ bool checkFileOpen(TFile* file)
4748
return (file && !file->IsZombie());
4849
}
4950

51+
template <typename T>
52+
bool areSufficientlyEqualNumbers(T a, T b, T epsilon = T(0.00001))
53+
{
54+
return std::abs(a - b) / std::abs(a) <= epsilon && std::abs(a - b) / std::abs(b) <= epsilon;
55+
}
56+
5057
// what to give as input:
5158
// 1) name and path of first file,
5259
// 2) name and path of second file,
@@ -109,6 +116,10 @@ void ReleaseValidation(const TString filename1, const TString filename2,
109116

110117
TIter next(extractedFile1.GetListOfKeys());
111118
TKey* key = nullptr;
119+
int nSimilarHistos{};
120+
int nComparisons{};
121+
int nNotFound{};
122+
std::vector<std::string> collectSimilarHistos;
112123
while ((key = static_cast<TKey*>(next()))) {
113124
// At this point we expect objects deriving from TH1 only since that is what we extracted
114125
auto hA = static_cast<TH1*>(key->ReadObj());
@@ -118,14 +129,27 @@ void ReleaseValidation(const TString filename1, const TString filename2,
118129
if (!hB) {
119130
// That could still happen in case we compare either comletely different file by accident or something has been changed/added/removed
120131
std::cerr << "ERROR: Histogram " << oname << " not found in " << filename2 << ", continue with next\n";
132+
nNotFound++;
121133
continue;
122134
}
135+
if (PotentiallySameHistograms(hA, hB)) {
136+
collectSimilarHistos.push_back(hA->GetName());
137+
std::cerr << "WARNING: Found potentially same histogram " << oname << "\n";
138+
nSimilarHistos++;
139+
}
123140
std::cout << "Comparing " << hA->GetName() << " and " << hB->GetName() << "\n";
124141
CompareHistos(hA, hB, whichTest, valueChi2, valueMeanDiff, valueEntriesDiff, isFirstComparison, isLastComparison, hSummaryCheck, hSummaryTests);
142+
nComparisons++;
125143
}
144+
std::cout << "\n##### Summary #####\nNumber of histograms compared: " << nComparisons
145+
<< "\nNumber of potentially same histograms: " << nSimilarHistos << "\n";
146+
for (auto& csh : collectSimilarHistos) {
147+
std::cout << " -> " << csh << "\n";
148+
}
149+
std::cout << "\nNumber of histograms only found in first but NOT second file: " << nNotFound << "\n";
126150

127151
// Create a summary plot with the result of the choosen test for all histograms
128-
TCanvas* summaryCheck = new TCanvas("summaryCheck", "summaryCheck");
152+
TCanvas summaryCheck("summaryCheck", "summaryCheck");
129153
Int_t MyPalette[100];
130154
Double_t R[] = {1.00, 1.00, 0.00};
131155
Double_t G[] = {0.00, 0.50, 1.00};
@@ -136,7 +160,7 @@ void ReleaseValidation(const TString filename1, const TString filename2,
136160
MyPalette[i] = FI + i;
137161
gStyle->SetGridStyle(3);
138162
gStyle->SetGridWidth(3);
139-
summaryCheck->SetGrid();
163+
summaryCheck.SetGrid();
140164
hSummaryCheck->Draw("colz");
141165

142166
// Create a summary plot with the result of each of the three basic tests for each histogram
@@ -159,6 +183,32 @@ void ReleaseValidation(const TString filename1, const TString filename2,
159183
// reading and pre-processing of input files //
160184
///////////////////////////////////////////////
161185

186+
bool PotentiallySameAxes(TAxis* axisA, TAxis* axisB)
187+
{
188+
auto binsA = axisA->GetNbins();
189+
auto binsB = axisB->GetNbins();
190+
191+
if (binsA != binsB) {
192+
// different number of bins --> obvious
193+
return false;
194+
}
195+
for (int i = 1; i <= binsA; i++) {
196+
if (!areSufficientlyEqualNumbers(axisA->GetBinLowEdge(i), axisB->GetBinLowEdge(i))) {
197+
return false;
198+
}
199+
}
200+
return areSufficientlyEqualNumbers(axisA->GetBinUpEdge(binsA), axisB->GetBinUpEdge(binsA));
201+
}
202+
203+
bool PotentiallySameHistograms(TH1* hA, TH1* hB)
204+
{
205+
if (hA->GetEntries() != hB->GetEntries()) {
206+
// different number of entries --> obvious
207+
return false;
208+
}
209+
return (!PotentiallySameAxes(hA->GetXaxis(), hB->GetXaxis()) || !PotentiallySameAxes(hA->GetYaxis(), hB->GetYaxis()) || !PotentiallySameAxes(hA->GetZaxis(), hB->GetZaxis()));
210+
}
211+
162212
// writing a TObject to a TDirectory
163213
void WriteToDirectory(TObject* obj, TDirectory* dir, std::string const& prefix)
164214
{

0 commit comments

Comments
 (0)