CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HistoCompare Class Reference

#include <HistoCompare.h>

Public Member Functions

TH1 * Compare (TH1 *h, const TString &hname)
 
double GetResult ()
 
 HistoCompare ()
 
 HistoCompare (const TString &refFilename)
 
void SetChi2Test (bool test=true)
 
void SetKGTest (bool test=true)
 
void SetReferenceFilename (const TString &filename)
 
 ~HistoCompare ()
 

Private Attributes

bool do_nothing_
 
TFile * refFile_
 
TString refFilename_
 
TH1 * refHisto_
 
TH1 * resHisto_
 
double result_
 
bool setChi2Test_
 
bool setKGTest_
 

Detailed Description


class: HistoCompare.h package: Validation/RecoB

author: Victor Bazterra, UIC Francisco Yumiceva, Fermilab (yumic.nosp@m.eva@.nosp@m.fnal..nosp@m.gov)


Definition at line 23 of file HistoCompare.h.

Constructor & Destructor Documentation

◆ HistoCompare() [1/2]

HistoCompare::HistoCompare ( )

class: HistoCompare.cc package: Validation/RecoB

author: Victor Bazterra, UIC Francisco Yumiceva, Fermilab (yumic.nosp@m.eva@.nosp@m.fnal..nosp@m.gov)


Definition at line 16 of file HistoCompare.cc.

16  {
17  result_ = 0;
18  do_nothing_ = false;
19 }

References do_nothing_, and result_.

◆ HistoCompare() [2/2]

HistoCompare::HistoCompare ( const TString &  refFilename)

Definition at line 21 of file HistoCompare.cc.

21  {
22  result_ = 0;
23  do_nothing_ = false;
24  // open reference file
25  refFile_ = new TFile(refFilename);
26  if (refFile_->IsZombie()) {
27  std::cout << " Error openning file " << refFilename << std::endl;
28  std::cout << " we will not compare histograms. " << std::endl;
29  do_nothing_ = true;
30  } else {
31  std::cout << " open file " << refFilename << std::endl;
32  }
33 
34  setChi2Test_ = true;
35 }

References gather_cfg::cout, do_nothing_, refFile_, result_, and setChi2Test_.

◆ ~HistoCompare()

HistoCompare::~HistoCompare ( )

Definition at line 37 of file HistoCompare.cc.

37 {}

Member Function Documentation

◆ Compare()

TH1 * HistoCompare::Compare ( TH1 *  h,
const TString &  hname 
)

Definition at line 39 of file HistoCompare.cc.

39  {
40  if (do_nothing_)
41  return nullptr;
42 
43  // std::cout << "histo: " << h->GetName() << " entries: "<< h->GetEntries() <<
44  // std::endl; std::cout << "hname: " << hname << std::endl;
45 
46  // create a residual histogram
47  // if (resHisto_) delete resHisto_;
48  resHisto_ = (TH1 *)h->Clone(TString(h->GetName()) + "_residuals");
49  resHisto_->Reset();
50 
51  // clone input histogram
52  TH1 *htemp = (TH1 *)h->Clone(TString(h->GetName()));
53 
54  refFile_->cd();
55  // std::cout << "get reference" << std::endl;
56  refHisto_ = (TH1 *)gDirectory->Get(hname);
57  // std::cout << "historef: " << refHisto_->GetName() << " entries: "<<
58  // refHisto_->GetEntries() << std::endl; std::cout << "name: " <<
59  // refHisto_->GetName() << std::endl;
60 
61  // normalize histograms
62  htemp->Scale(1. / htemp->Integral());
63  refHisto_->Scale(1. / refHisto_->Integral());
64 
65  if (setChi2Test_) {
66  result_ = refHisto_->Chi2Test(htemp, "UFOF");
67  }
68  if (setKGTest_) {
69  result_ = refHisto_->KolmogorovTest(htemp, "UO");
70  }
71 
72  resHisto_->Add(htemp, refHisto_, 1., -1.);
73 
74  // std::cout << " residual done." << std::endl;
75 
76  return resHisto_;
77 }

References do_nothing_, refFile_, refHisto_, resHisto_, result_, setChi2Test_, and setKGTest_.

◆ GetResult()

double HistoCompare::GetResult ( )
inline

Definition at line 48 of file HistoCompare.h.

48 { return result_; };

◆ SetChi2Test()

void HistoCompare::SetChi2Test ( bool  test = true)
inline

Definition at line 44 of file HistoCompare.h.

44 { setChi2Test_ = test; };

References setChi2Test_, and ctpps_dqm_sourceclient-live_cfg::test.

◆ SetKGTest()

void HistoCompare::SetKGTest ( bool  test = true)
inline

Definition at line 46 of file HistoCompare.h.

46 { setKGTest_ = test; };

References setKGTest_, and ctpps_dqm_sourceclient-live_cfg::test.

◆ SetReferenceFilename()

void HistoCompare::SetReferenceFilename ( const TString &  filename)
inline

Definition at line 32 of file HistoCompare.h.

32  {
34  // if (refFile_) delete refFile_;
35  refFile_ = new TFile(refFilename_);
36  if (refFile_->IsZombie()) {
37  std::cout << " Error openning file " << refFilename_ << std::endl;
38  std::cout << " we will not compare histograms. " << std::endl;
39  do_nothing_ = true;
40  }
41  std::cout << " open file" << std::endl;
42  };

References gather_cfg::cout, do_nothing_, corrVsCorr::filename, refFile_, and refFilename_.

Member Data Documentation

◆ do_nothing_

bool HistoCompare::do_nothing_
private

Definition at line 54 of file HistoCompare.h.

Referenced by Compare(), HistoCompare(), and SetReferenceFilename().

◆ refFile_

TFile* HistoCompare::refFile_
private

Definition at line 58 of file HistoCompare.h.

Referenced by Compare(), HistoCompare(), and SetReferenceFilename().

◆ refFilename_

TString HistoCompare::refFilename_
private

Definition at line 60 of file HistoCompare.h.

Referenced by SetReferenceFilename().

◆ refHisto_

TH1* HistoCompare::refHisto_
private

Definition at line 57 of file HistoCompare.h.

Referenced by Compare().

◆ resHisto_

TH1* HistoCompare::resHisto_
private

Definition at line 56 of file HistoCompare.h.

Referenced by Compare().

◆ result_

double HistoCompare::result_
private

Definition at line 53 of file HistoCompare.h.

Referenced by Compare(), and HistoCompare().

◆ setChi2Test_

bool HistoCompare::setChi2Test_
private

Definition at line 48 of file HistoCompare.h.

Referenced by Compare(), HistoCompare(), and SetChi2Test().

◆ setKGTest_

bool HistoCompare::setKGTest_
private

Definition at line 52 of file HistoCompare.h.

Referenced by Compare(), and SetKGTest().

HistoCompare::refHisto_
TH1 * refHisto_
Definition: HistoCompare.h:57
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HistoCompare::refFile_
TFile * refFile_
Definition: HistoCompare.h:58
ctpps_dqm_sourceclient-live_cfg.test
test
Definition: ctpps_dqm_sourceclient-live_cfg.py:7
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
HistoCompare::setChi2Test_
bool setChi2Test_
Definition: HistoCompare.h:48
h
HistoCompare::refFilename_
TString refFilename_
Definition: HistoCompare.h:60
HistoCompare::resHisto_
TH1 * resHisto_
Definition: HistoCompare.h:56
HistoCompare::result_
double result_
Definition: HistoCompare.h:53
HistoCompare::setKGTest_
bool setKGTest_
Definition: HistoCompare.h:52
HistoCompare::do_nothing_
bool do_nothing_
Definition: HistoCompare.h:54