FairRoot/PandaRoot
tracking/trackingQA/comp_recoqa.C
Go to the documentation of this file.
1 #include "TString.h"
2 #include "TFile.h"
3 #include "TCanvas.h"
4 #include "TKey.h"
5 #include <iostream>
6 #include "TH1F.h"
7 #include "TRandom.h"
8 
9 using std::cout;
10 using std::endl;
11 
12 TCanvas* createCanvas(int picpercan){
13  double division = TMath::Sqrt((double)picpercan);
14  int first = ceil(division);
15  int second = round(division);
16  cout << "createCanvas: " << picpercan << " : " << first << "/" << second << endl;
17  TCanvas* newCan = new TCanvas();
18  newCan->Divide(first, second);
19  return newCan;
20 }
21 
22 int comp_recoqa(TString fn = "QA_histograms.root", TString fn2 =
23  "QA_histograms_test.root", int picpercan = 9, double minP = 0.03, int minev = 3,
24  int maxfail = 3) {
25  // fn -> red
26  // fn2 -> blue
27  std::vector<TCanvas*> canvasses;
28  TCanvas *c1 = new TCanvas();
29  c1->Divide(6, 6);
30  bool fTest = kFALSE;
31 
32  TFile *f = new TFile(fn, "READ");
33  if (!f->IsZombie()) {
34  TFile *f2 = new TFile(fn2, "READ");
35 
36  TKey *key;
37  TIter next(f->GetListOfKeys());
38 
39  int failcount = 0;
40  Int_t histoCount = 0;
41  Int_t actualCanvas = 0;
42  Int_t actualPad = 0;
43  while ((key = (TKey*) next())) {
44  actualCanvas = TMath::Floor((double)histoCount / picpercan);
45  actualPad = (histoCount % picpercan) + 1;
46  cout << histoCount << " : " << actualCanvas << "/" << actualPad << endl;
47  if (!(canvasses.size() > actualCanvas)){
48  cout << "New canvas" << endl;
49  canvasses.push_back(createCanvas(picpercan));
50  }
51  canvasses[actualCanvas]->cd(actualPad);
52  TObject *obj = key->ReadObj();
53 
54  // only check TH1Fs
55  if (!obj->InheritsFrom("TH1F"))
56  continue;
57 
58  TString name = obj->GetName();
59  TH1F* h = (TH1F*) obj;
60  TH1F* h2 = (TH1F*) f2->Get(name);
61  h->SetLineColor(2);
62  h->SetLineWidth(2);
63  h2->SetLineWidth(2);
64  if (h->GetMaximum() < h2->GetMaximum()) {
65  h2->Draw();
66  h->Draw("same");
67  } else {
68  h->Draw();
69  h2->Draw("same");
70  }
71  if (h->GetEntries() < minev) {
72  cout << "Histogram (almost) empty : " << name << " \""
73  << h2->GetTitle() << "\": N = " << h->GetEntries()
74  << endl;
75  failcount++;
76  } else {
77  double P = h2->KolmogorovTest(h);
78  if (P < minP) {
79  cout << "Incompatible distribution: " << name << " \""
80  << h2->GetTitle() << "\": P = " << P << endl;
81  failcount++;
82  }
83  }
84 
85  auto legend = new TLegend(0.1,0.7,0.48,0.9);
86  legend->SetHeader("File Comparison","C"); // option "C" allows to center the header
87  legend->AddEntry(h,fn.Data(),"f");
88  legend->AddEntry(h2,fn2.Data(),"f");
89  legend->Draw();
90  histoCount++;
91  }
92 
93  if (failcount < maxfail)
94  fTest = kTRUE;
95 
96  }
97 
98  if (fTest) {
99  cout << " Test passed" << endl;
100  cout << " All ok " << endl;
101  } else {
102  cout << " Test Failed" << endl;
103  cout << " Not Ok " << endl;
104  }
105  return 0;
106 }
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
TCanvas * createCanvas(int picpercan)
TFile * f
Definition: bump_analys.C:12
c1
Definition: plot_dirc.C:35
TString name
bool comp_recoqa(TString fn="QA_histograms.root", TString fn2="QA_histograms_test.root", double minP=0.03, int minev=3, int maxfail=3)
GeV c P
TFile * f2
static int next[96]
Definition: ranlxd.cxx:374