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 
13 
14 #include <iostream>
15 
17  result_ = 0;
18  do_nothing_ = false;
19 }
20 
21 HistoCompare::HistoCompare(const TString& refFilename) {
22 
23  result_ = 0;
24  do_nothing_ = false;
25  // open reference file
26  refFile_ = new TFile(refFilename);
27  if (refFile_->IsZombie()) {
28  std::cout << " Error openning file " << refFilename << std::endl;
29  std::cout << " we will not compare histograms. " << std::endl;
30  do_nothing_ = true;
31  } else {
32  std::cout << " open file " << refFilename << std::endl;
33  }
34 
35  setChi2Test_ = true;
36 
37 }
38 
40 }
41 
42 
43 TH1* HistoCompare::Compare(TH1 *h, const TString& hname) {
44 
45  if (do_nothing_) return 0;
46 
47  //std::cout << "histo: " << h->GetName() << " entries: "<< h->GetEntries() << std::endl;
48  //std::cout << "hname: " << hname << std::endl;
49 
50 
51  //create a residual histogram
52  //if (resHisto_) delete resHisto_;
53  resHisto_ = (TH1*) h->Clone(TString(h->GetName())+"_residuals");
54  resHisto_->Reset();
55 
56  // clone input histogram
57  TH1 *htemp = (TH1*) h->Clone(TString(h->GetName()));
58 
59  refFile_->cd();
60  //std::cout << "get reference" << std::endl;
61  refHisto_ = (TH1*) gDirectory->Get( hname );
62  //std::cout << "historef: " << refHisto_->GetName() << " entries: "<< refHisto_->GetEntries() << std::endl;
63  //std::cout << "name: " << refHisto_->GetName() << std::endl;
64 
65 
66  // normalize histograms
67  htemp->Scale(1./htemp->Integral());
68  refHisto_->Scale(1./refHisto_->Integral());
69 
70  if (setChi2Test_) {
71  result_ = refHisto_->Chi2Test(htemp,"UFOF");
72  }
73  if (setKGTest_) {
74  result_ = refHisto_->KolmogorovTest(htemp,"UO");
75  }
76 
77 
78  resHisto_->Add( htemp, refHisto_, 1., -1.);
79 
80  //std::cout << " residual done." << std::endl;
81 
82  return resHisto_;
83 
84 }
double result_
Definition: HistoCompare.h:60
TH1 * resHisto_
Definition: HistoCompare.h:63
bool do_nothing_
Definition: HistoCompare.h:61
TH1 * refHisto_
Definition: HistoCompare.h:64
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:54
TFile * refFile_
Definition: HistoCompare.h:65
TH1 * Compare(TH1 *h, const TString &hname)
Definition: HistoCompare.cc:43