CMS 3D CMS Logo

DTResidualFitter.cc
Go to the documentation of this file.
1 
2 /*
3  * Fits core distribution to single gaussian; iterates once.
4  *
5  * \author A. Vilela Pereira
6  */
7 
10 
11 #include "TH1F.h"
12 #include "TF1.h"
13 #include "TString.h"
14 
16 
18 
20  TString option("R");
21  if (!debug_)
22  option += "Q";
23 
24  float under = histo.GetBinContent(0) / histo.GetEntries();
25  float over = histo.GetBinContent(histo.GetNbinsX() + 1) / histo.GetEntries();
26  float minFit = histo.GetMean() - histo.GetRMS();
27  float maxFit = histo.GetMean() + histo.GetRMS();
28 
29  if ((under > 0.1) || (over > 0.1))
30  edm::LogError("DTResidualFitter") << "WARNING in histogram: " << histo.GetName() << "\n"
31  << " entries: " << histo.GetEntries() << "\n"
32  << " underflow: " << under * 100. << "% \n"
33  << " overflow: " << over * 100. << "%";
34 
35  TString funcName = TString(histo.GetName()) + "_gaus";
36  TF1* fitFunc = new TF1(funcName, "gaus", minFit, maxFit);
37 
38  histo.Fit(fitFunc, option);
39 
40  minFit = fitFunc->GetParameter(1) - nSigmas * fitFunc->GetParameter(2);
41  maxFit = fitFunc->GetParameter(1) + nSigmas * fitFunc->GetParameter(2);
42  fitFunc->SetRange(minFit, maxFit);
43  histo.Fit(fitFunc, option);
44 
45  return DTResidualFitResult(
46  fitFunc->GetParameter(1), fitFunc->GetParError(1), fitFunc->GetParameter(2), fitFunc->GetParError(2));
47 }
DTResidualFitter::debug_
bool debug_
Definition: DTResidualFitter.h:29
MessageLogger.h
DTResidualFitter::~DTResidualFitter
~DTResidualFitter()
Definition: DTResidualFitter.cc:17
DTResidualFitter.h
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
DTResidualFitter::fitResiduals
DTResidualFitResult fitResiduals(TH1F &histo, int nSigmas=1)
Definition: DTResidualFitter.cc:19
fileinputsource_cfi.option
option
Definition: fileinputsource_cfi.py:94
debug
#define debug
Definition: HDRShower.cc:19
DTResidualFitter::DTResidualFitter
DTResidualFitter(bool debug=false)
Definition: DTResidualFitter.cc:15
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DTResidualFitResult
Definition: DTResidualFitter.h:10