Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:43

0001 import ROOT
0002 
0003 def fitResidual(histo,nSigmas=2,verbose=False):
0004     option = "R0"
0005     if not verbose: option += "Q"
0006 
0007     minFit = histo.GetMean() - histo.GetRMS()
0008     maxFit = histo.GetMean() + histo.GetRMS()
0009 
0010     funcName = histo.GetName() + "_gaus"
0011     fitFunc = ROOT.TF1(funcName,"gaus",minFit,maxFit)
0012     histo.Fit(fitFunc,option)
0013 
0014     minFit = fitFunc.GetParameter(1) - nSigmas*fitFunc.GetParameter(2)
0015     maxFit = fitFunc.GetParameter(1) + nSigmas*fitFunc.GetParameter(2)
0016     fitFunc.SetRange(minFit,maxFit)
0017     histo.Fit(fitFunc,option)
0018 
0019     return (histo,fitFunc)