CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Validation/RecoB/src/HistoCompare.cc

Go to the documentation of this file.
00001 
00013 #include "Validation/RecoB/interface/HistoCompare.h"
00014 
00015 #include <iostream>
00016 
00017 HistoCompare::HistoCompare() {
00018   result_ = 0;
00019   do_nothing_ = false;
00020 }
00021 
00022 HistoCompare::HistoCompare(TString refFilename) {
00023 
00024         result_ = 0;
00025         do_nothing_ = false;
00026         // open reference file
00027         refFile_ = new TFile(refFilename);
00028         if (refFile_->IsZombie()) {
00029                 std::cout << " Error openning file " << refFilename << std::endl;
00030                 std::cout << " we will not compare histograms. " << std::endl;
00031                 do_nothing_ = true;
00032         } else {
00033                 std::cout << " open file " << refFilename << std::endl;
00034         }
00035         
00036         setChi2Test_ = true;
00037         
00038 }
00039 
00040 HistoCompare::~HistoCompare() {
00041 }
00042 
00043 
00044 TH1* HistoCompare::Compare(TH1 *h, TString hname) {
00045 
00046         if (do_nothing_) return 0;
00047         
00048         //std::cout << "histo: " << h->GetName() << " entries: "<< h->GetEntries() << std::endl;
00049         //std::cout << "hname: " << hname << std::endl;
00050 
00051         
00052         //create a residual histogram
00053         //if (resHisto_) delete resHisto_;
00054         resHisto_ = (TH1*) h->Clone(TString(h->GetName())+"_residuals");
00055         resHisto_->Reset();
00056 
00057         // clone input histogram
00058         TH1 *htemp = (TH1*) h->Clone(TString(h->GetName()));
00059 
00060         refFile_->cd();
00061         //std::cout << "get reference" << std::endl;
00062         refHisto_ = (TH1*) gDirectory->Get( hname );
00063         //std::cout << "historef: " << refHisto_->GetName() << " entries: "<< refHisto_->GetEntries() << std::endl;
00064         //std::cout << "name: " << refHisto_->GetName() << std::endl;
00065 
00066 
00067         // normalize histograms
00068         htemp->Scale(1./htemp->Integral());
00069         refHisto_->Scale(1./refHisto_->Integral());
00070         
00071         if (setChi2Test_) {
00072                 result_ = refHisto_->Chi2Test(htemp,"UFOF");
00073         }
00074         if (setKGTest_) {
00075                 result_ = refHisto_->KolmogorovTest(htemp,"UO");
00076         }
00077 
00078         
00079         resHisto_->Add( htemp, refHisto_, 1., -1.);
00080         
00081         //std::cout << " residual done." << std::endl;
00082         
00083         return resHisto_;
00084         
00085 }