4 #if !defined(__CINT__) || defined(__MAKECINT__)
22 #include "TDataSetIter.h"
24 #include "TDataSetIter.h"
25 #include "TClassTable.h"
28 #include "TSpectrum.h"
33 #include "TPolyMarker.h"
39 TFile *F12[2] = {0,0};
41 void Kolmogorov(
const Char_t *file1 =
"",
const Char_t *file2 =
"",
42 const Char_t *histName =
"",
43 Bool_t allProc = kTRUE,
44 Bool_t makePNG = kTRUE,
45 Double_t probCut = 1.e-2) {
48 if (File1 ==
"" && File2 ==
"") {
49 cout <<
"Usage: " << endl;
50 cout <<
"root.exe \'Kolmogorov.C+("
51 <<
"\"/star/rcf/test/dev/trs_sl302/Tue/year_2005/cucu200_minbias/rcf1216_05_200evts.hist.root\","
52 <<
"\"/star/rcf/test/dev/trs_sl302/Wed/year_2005/cucu200_minbias/rcf1216_05_200evts.hist.root\")\'" << endl;
55 if ( gClassTable->GetID(
"StIOEvent") < 0) {
56 gSystem->Load(
"St_base");
57 gSystem->Load(
"StUtilities");
59 TString HistName(histName);
60 cout <<
"Run Kolmogorov Test for files:" << File1 <<
" and " << File2;
61 if (HistName !=
"") cout <<
" for Histogram: " << HistName;
62 else cout <<
" for all histograms in file";
63 if (allProc) cout <<
" Process them non stop";
64 else cout <<
" Start Dialog after test fails";
66 if (makePNG) cout <<
" Create png files with result of failed comparision" << endl;
67 cout <<
"Probability cut is " << probCut << endl;
69 if (File1 !=
"") F12[0] = TFile::Open(file1);
70 if (File2 !=
"") F12[1] = TFile::Open(file2);
71 TSeqCollection *files = gROOT->GetListOfFiles();
76 while ((f = (TFile *) nextF())) {
77 if (NF == 2) {cout <<
"more than " << NF <<
" files. Skip the rest." << endl;
break;}
79 FileN[NF] = f->GetName();
80 FileN[NF].ReplaceAll(
".hist.root",
"");
81 if (NF == 1) {FileN[NF].ReplaceAll(FileN[0].Data(),
""); FileN[NF].ReplaceAll(
"/star/rcf/test/",
"");}
82 TListIter nextkey( f->GetListOfKeys() );
84 while ((key = (TKey*) nextkey())) {
85 TString Name(key->GetName());
87 if (Name.BeginsWith(
"histBranch")) {
89 TList *makerList = (TList *) io->fObj;
91 TListIter nextMaker(makerList);
94 TList *histList = (TList *) o->
GetObject();
97 TListIter nextH(histList);
98 while ((h = (TH1 *) nextH())) {
99 if (h->InheritsFrom(
"TH1")) {
107 cout <<
"Source file " << NF++ <<
": " << f->GetName() <<
" with " << nh <<
" Histograms" << endl;
111 if (NF != 2) {cout <<
"Problem to get 2 files" << endl;
return;}
112 TListIter next(F12[0]->GetList());
115 if (! gROOT->IsBatch()) c1 =
new TCanvas(
"c1",
"c1",800,500);
117 while ((obj = next()) && nhists <10000 ) {
118 nhists++; cout << obj->GetName() <<
" hist " << nhists << endl;
122 Bool_t makepng = makePNG;
123 cout <<
"obj " << obj->GetName() <<
"/" << obj->GetTitle() << endl;
124 if ( obj->IsA()->InheritsFrom(
"TH1" )) {
125 if (obj->IsA()->InheritsFrom(
"StMultiH1F" )) ifMult = 1;
127 h1 =
new TH2F(* ((TH2F *) obj));
130 Stat_t e1 = h1->GetEntries();
131 if (HistName !=
"" && HistName != TString(h1->GetName()))
continue;
132 cout <<
"Found histogram " << h1->GetName() <<
" in " << F12[0]->GetName() <<
" with " << e1 <<
" Entries" << endl;
133 h = (TH1 *) F12[1]->Get(h1->GetName());
134 if (! h) {cout <<
"Can't find histogram " << h1->GetName() <<
" in " << F12[1]->GetName() << endl;
continue;}
136 h2 =
new TH2F(* ((TH2F *)h));
139 Stat_t e2 = h2->GetEntries();
140 cout <<
"Found histogram " << h2->GetName() <<
" in " << F12[1]->GetName() <<
" with " << e2 <<
" Entries" << endl;
141 if (e1 <= 0.0 || e2 <= 0.0) {
143 cout <<
"==== Incomparibale Histograms" << h1->GetName() <<
" e1: " << e1 <<
"\te2: " << e2 << endl;
146 if ( h1->Integral() <= 0.0) { cout <<
"\tis empty" << endl;
continue;}
147 cout <<
"Found histogram " << h2->GetName() <<
" in " << F12[1]->GetName() << endl;
149 h1->SetXTitle(FileN[0]);
150 h2->SetXTitle(FileN[1]);
151 prob = h1->KolmogorovTest(h2,
"UOD");
152 probN = h1->KolmogorovTest(h2,
"UOND");
153 TString pngName(h1->GetName());
154 Int_t Fail = prob < probCut || probN < probCut;
155 if (! Fail) makepng = kFALSE;
156 if (prob < probCut) pngName +=
"FailS";
157 if (probN < probCut) pngName +=
"FailN";
159 h2->SetMarkerColor(2);
161 TLegend leg(0.7,0.6,1.1,0.8,
"");
162 TString Title(
"_file0 (new)");
163 leg.AddEntry(h1,Title.Data());
164 Title = Form(
"prob = %f",prob);
165 leg.AddEntry(h1,Title.Data());
166 Title =
"_file1 (ref)";
167 leg.AddEntry(h2,Title.Data());
168 Title = Form(
"probN = %f",probN);
169 leg.AddEntry(h2,Title.Data());
170 if (! gROOT->IsBatch()) {
174 cName += h1->GetName();
175 c1->SetTitle(cName.Data());
176 c1->SetName(cName.Data());
180 if ( h1->InheritsFrom(
"TH2" ) ) {
186 }
else if (h1->InheritsFrom(
"TH1" )) {
197 pngName.ReplaceAll(
" ",
"");
202 if (prob < probCut || probN < probCut) {
203 cout <<
"======== KolmogorovTest fails for " << h1->GetName() <<
" with prob "
204 << prob <<
" ===================" << endl;
207 cout <<
"Type in a number (<0 break, >=0 go to the next histogram <";
213 if (ifMult) {
delete h1;
delete h2;}
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)