CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/DQMServices/ClientConfig/src/FitSlicesYTool.cc

Go to the documentation of this file.
00001 #include "DQMServices/ClientConfig/interface/FitSlicesYTool.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include "DQMServices/Core/interface/MonitorElement.h"
00004 #include "TDirectory.h"
00005 
00006 using namespace std;
00007 
00008 FitSlicesYTool::FitSlicesYTool(MonitorElement* me)
00009 { 
00010   const bool oldAddDir = TH1::AddDirectoryStatus();
00011   TH1::AddDirectory(true);
00012   // ... create your hists
00013   TH2F * h = me->getTH2F();
00014   h->FitSlicesY();
00015   string name(h->GetName());
00016   h0 = (TH1*)gDirectory->Get((name+"_0").c_str());
00017   h1 = (TH1*)gDirectory->Get((name+"_1").c_str());
00018   h2 = (TH1*)gDirectory->Get((name+"_2").c_str());
00019   h3 = (TH1*)gDirectory->Get((name+"_chi2").c_str());
00020   TH1::AddDirectory(oldAddDir);
00021 }
00022 
00023 // FitSlicesYTool::FitSlicesYTool(TH2F* h){
00024 //   h->FitSlicesY();
00025 //   string name(h->GetName());
00026 //   h0 = (TH1*)gDirectory->Get((name+"_0").c_str());
00027 //   h1 = (TH1*)gDirectory->Get((name+"_1").c_str());
00028 //   h2 = (TH1*)gDirectory->Get((name+"_2").c_str());
00029 //   h3 = (TH1*)gDirectory->Get((name+"_chi2").c_str());
00030 // }
00031 FitSlicesYTool::~FitSlicesYTool(){
00032   delete h0;  
00033   delete h1;  
00034   delete h2;  
00035   delete h3;  
00036 }
00037 void FitSlicesYTool::getFittedMean(MonitorElement * me){
00038   if (!(h1&&me)) throw cms::Exception("FitSlicesYTool") << "Pointer =0 : h1=" << h1 << " me=" << me;
00039   if (h1->GetNbinsX()==me->getNbinsX()){
00040     for (int bin=0;bin!=h1->GetNbinsX();bin++){
00041       me->setBinContent(bin+1,h1->GetBinContent(bin+1));
00042 //       me->setBinEntries(bin+1, 1.);
00043     }
00044   } else {
00045     throw cms::Exception("FitSlicesYTool") << "Different number of bins!";
00046   }
00047 }
00048 void FitSlicesYTool::getFittedSigma(MonitorElement * me){
00049   if (!(h2&&me)) throw cms::Exception("FitSlicesYTool") << "Pointer =0 : h1=" << h1 << " me=" << me;
00050   if (h2->GetNbinsX()==me->getNbinsX()){
00051     for (int bin=0;bin!=h2->GetNbinsX();bin++){
00052       me->setBinContent(bin+1,h2->GetBinContent(bin+1));
00053 //       me->setBinEntries(bin+1, 1.);
00054     }
00055   } else {
00056     throw cms::Exception("FitSlicesYTool") << "Different number of bins!";
00057   }
00058 }
00059 void FitSlicesYTool::getFittedMeanWithError(MonitorElement * me){
00060   if (!(h1&&me)) throw cms::Exception("FitSlicesYTool") << "Pointer =0 : h1=" << h1 << " me=" << me;
00061   if (h1->GetNbinsX()==me->getNbinsX()){
00062     for (int bin=0;bin!=h1->GetNbinsX();bin++){
00063       me->setBinContent(bin+1,h1->GetBinContent(bin+1));
00064 //       me->setBinEntries(bin+1, 1.);
00065       me->setBinError(bin+1,h1->GetBinError(bin+1));
00066     }
00067   } else {
00068     throw cms::Exception("FitSlicesYTool") << "Different number of bins!";
00069   }
00070 }
00071 void FitSlicesYTool::getFittedSigmaWithError(MonitorElement * me){
00072   if (!(h2&&me)) throw cms::Exception("FitSlicesYTool") << "Pointer =0 : h1=" << h1 << " me=" << me;
00073   if (h2->GetNbinsX()==me->getNbinsX()){
00074     for (int bin=0;bin!=h2->GetNbinsX();bin++){
00075       me->setBinContent(bin+1,h2->GetBinContent(bin+1));
00076 //       me->setBinEntries(bin+1, 1.);
00077       me->setBinError(bin+1,h2->GetBinError(bin+1));
00078     }
00079   } else {
00080     throw cms::Exception("FitSlicesYTool") << "Different number of bins!";
00081   }
00082 }