FairRoot/PandaRoot
outdated/run/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 bool comp_recoqa(TString fn="QA_histograms.root", TString fn2="QA_histograms_test.root", double minP = 0.03, int minev = 3, int maxfail=3)
13 {
14  // fn -> red
15  // fn2 -> blue
16  TCanvas *c1 = new TCanvas();
17  c1->Divide(6,6);
18  bool fTest=kFALSE;
19  TString templateFile = gSystem->Getenv("VMCWORKDIR");
20  templateFile += "/macro/run/";
21  templateFile += fn2;
22 
23  TFile *f=new TFile(fn,"READ");
24  if (!f->IsZombie())
25  {
26  TFile *f2=new TFile(templateFile,"READ");
27 
28  TKey *key;
29  TIter next(f->GetListOfKeys());
30 
31  int failcount = 0;
32  Int_t yy = 0;
33  while ( (key = (TKey*)next()) )
34  {
35  c1->cd(yy+1);
36  TObject *obj = key->ReadObj();
37 
38  // only check TH1Fs
39  if (!obj->InheritsFrom("TH1F")) continue;
40 
41  TString name = obj->GetName();
42  TH1F* h = (TH1F*) obj;
43  TH1F* h2 = (TH1F*) f2->Get(name);
44  h->SetLineColor(2);
45  h->SetLineWidth(2);
46  h2->SetLineWidth(2);
47  if ( h->GetMaximum()< h2->GetMaximum())
48  {
49  h2->Draw(); h->Draw("same");
50  }
51  else
52  {
53  h->Draw(); h2->Draw("same");
54  }
55  if ( h->GetEntries()<minev )
56  {
57  cout << "Histogram (almost) empty : " << name << " \"" << h2->GetTitle() << "\": N = " << h->GetEntries() << endl;
58  failcount++;
59  }
60  else
61  {
62  double P = h2->KolmogorovTest(h);
63  if ( P<minP )
64  {
65  cout << "Incompatible distribution: " << name << " \"" << h2->GetTitle() << "\": P = " << P << endl;
66  failcount++;
67  }
68  }
69  yy++;
70  }
71 
72  if (failcount<maxfail) fTest = kTRUE;
73 
74  }
75 
76  if (fTest){
77  cout << " Test passed" << endl;
78  cout << " All ok " << endl;
79  }else{
80  cout << " Test Failed" << endl;
81  cout << " Not Ok " << endl;
82  }
83 
84 
85 }
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