File indexing completed on 2024-04-06 12:32:57
0001
0002
0003
0004
0005
0006
0007
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
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
0044
0045
0046
0047
0048 resHisto_ = (TH1 *)h->Clone(TString(h->GetName()) + "_residuals");
0049 resHisto_->Reset();
0050
0051
0052 TH1 *htemp = (TH1 *)h->Clone(TString(h->GetName()));
0053
0054 refFile_->cd();
0055
0056 refHisto_ = (TH1 *)gDirectory->Get(hname);
0057
0058
0059
0060
0061
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
0075
0076 return resHisto_;
0077 }