CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HistoCompare.cc
Go to the documentation of this file.
1 
14 
15 #include <iostream>
16 
18  result_ = 0;
19  do_nothing_ = false;
20 }
21 
22 HistoCompare::HistoCompare(TString refFilename) {
23 
24  result_ = 0;
25  do_nothing_ = false;
26  // open reference file
27  refFile_ = new TFile(refFilename);
28  if (refFile_->IsZombie()) {
29  std::cout << " Error openning file " << refFilename << std::endl;
30  std::cout << " we will not compare histograms. " << std::endl;
31  do_nothing_ = true;
32  } else {
33  std::cout << " open file " << refFilename << std::endl;
34  }
35 
36  setChi2Test_ = true;
37 
38 }
39 
41 }
42 
43 
44 TH1* HistoCompare::Compare(TH1 *h, TString hname) {
45 
46  if (do_nothing_) return 0;
47 
48  //std::cout << "histo: " << h->GetName() << " entries: "<< h->GetEntries() << std::endl;
49  //std::cout << "hname: " << hname << std::endl;
50 
51 
52  //create a residual histogram
53  //if (resHisto_) delete resHisto_;
54  resHisto_ = (TH1*) h->Clone(TString(h->GetName())+"_residuals");
55  resHisto_->Reset();
56 
57  // clone input histogram
58  TH1 *htemp = (TH1*) h->Clone(TString(h->GetName()));
59 
60  refFile_->cd();
61  //std::cout << "get reference" << std::endl;
62  refHisto_ = (TH1*) gDirectory->Get( hname );
63  //std::cout << "historef: " << refHisto_->GetName() << " entries: "<< refHisto_->GetEntries() << std::endl;
64  //std::cout << "name: " << refHisto_->GetName() << std::endl;
65 
66 
67  // normalize histograms
68  htemp->Scale(1./htemp->Integral());
69  refHisto_->Scale(1./refHisto_->Integral());
70 
71  if (setChi2Test_) {
72  result_ = refHisto_->Chi2Test(htemp,"UFOF");
73  }
74  if (setKGTest_) {
75  result_ = refHisto_->KolmogorovTest(htemp,"UO");
76  }
77 
78 
79  resHisto_->Add( htemp, refHisto_, 1., -1.);
80 
81  //std::cout << " residual done." << std::endl;
82 
83  return resHisto_;
84 
85 }
double result_
Definition: HistoCompare.h:61
TH1 * resHisto_
Definition: HistoCompare.h:64
bool do_nothing_
Definition: HistoCompare.h:62
TH1 * refHisto_
Definition: HistoCompare.h:65
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple cout
Definition: gather_cfg.py:121
bool setChi2Test_
Definition: HistoCompare.h:55
TH1 * Compare(TH1 *h, TString hname)
Definition: HistoCompare.cc:44
TFile * refFile_
Definition: HistoCompare.h:66