Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:32:57

0001 /**_________________________________________________________________
0002    class:   HistoCompare.cc
0003    package: Validation/RecoB
0004 
0005 
0006  author: Victor Bazterra, UIC
0007          Francisco Yumiceva, Fermilab (yumiceva@fnal.gov)
0008 
0009 
0010 ________________________________________________________________**/
0011 
0012 #include "Validation/RecoB/interface/HistoCompare.h"
0013 
0014 #include <iostream>
0015 
0016 HistoCompare::HistoCompare() {
0017   result_ = 0;
0018   do_nothing_ = false;
0019 }
0020 
0021 HistoCompare::HistoCompare(const TString &refFilename) {
0022   result_ = 0;
0023   do_nothing_ = false;
0024   // open reference file
0025   refFile_ = new TFile(refFilename);
0026   if (refFile_->IsZombie()) {
0027     std::cout << " Error openning file " << refFilename << std::endl;
0028     std::cout << " we will not compare histograms. " << std::endl;
0029     do_nothing_ = true;
0030   } else {
0031     std::cout << " open file " << refFilename << std::endl;
0032   }
0033 
0034   setChi2Test_ = true;
0035 }
0036 
0037 HistoCompare::~HistoCompare() {}
0038 
0039 TH1 *HistoCompare::Compare(TH1 *h, const TString &hname) {
0040   if (do_nothing_)
0041     return nullptr;
0042 
0043   // std::cout << "histo: " << h->GetName() << " entries: "<< h->GetEntries() <<
0044   // std::endl; std::cout << "hname: " << hname << std::endl;
0045 
0046   // create a residual histogram
0047   // if (resHisto_) delete resHisto_;
0048   resHisto_ = (TH1 *)h->Clone(TString(h->GetName()) + "_residuals");
0049   resHisto_->Reset();
0050 
0051   // clone input histogram
0052   TH1 *htemp = (TH1 *)h->Clone(TString(h->GetName()));
0053 
0054   refFile_->cd();
0055   // std::cout << "get reference" << std::endl;
0056   refHisto_ = (TH1 *)gDirectory->Get(hname);
0057   // std::cout << "historef: " << refHisto_->GetName() << " entries: "<<
0058   // refHisto_->GetEntries() << std::endl; std::cout << "name: " <<
0059   // refHisto_->GetName() << std::endl;
0060 
0061   // normalize histograms
0062   htemp->Scale(1. / htemp->Integral());
0063   refHisto_->Scale(1. / refHisto_->Integral());
0064 
0065   if (setChi2Test_) {
0066     result_ = refHisto_->Chi2Test(htemp, "UFOF");
0067   }
0068   if (setKGTest_) {
0069     result_ = refHisto_->KolmogorovTest(htemp, "UO");
0070   }
0071 
0072   resHisto_->Add(htemp, refHisto_, 1., -1.);
0073 
0074   // std::cout << " residual done." << std::endl;
0075 
0076   return resHisto_;
0077 }