CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/CalibMuon/DTCalibration/python/PlottingTools/fitResidual.py

Go to the documentation of this file.
00001 import ROOT
00002 
00003 def fitResidual(histo,nSigmas=2,verbose=False):
00004     option = "R0"
00005     if not verbose: option += "Q"
00006 
00007     minFit = histo.GetMean() - histo.GetRMS()
00008     maxFit = histo.GetMean() + histo.GetRMS()
00009 
00010     funcName = histo.GetName() + "_gaus"
00011     fitFunc = ROOT.TF1(funcName,"gaus",minFit,maxFit)
00012     histo.Fit(fitFunc,option)
00013 
00014     minFit = fitFunc.GetParameter(1) - nSigmas*fitFunc.GetParameter(2)
00015     maxFit = fitFunc.GetParameter(1) + nSigmas*fitFunc.GetParameter(2)
00016     fitFunc.SetRange(minFit,maxFit)
00017     histo.Fit(fitFunc,option)
00018 
00019     return (histo,fitFunc)