00001
00002
00003
00004
00005
00006
00007
00008
00009 from DybPython.DybPythonAlg import DybPythonAlg
00010 from GaudiPython import SUCCESS, FAILURE
00011 from GaudiPython import gbl
00012 from decimal import *
00013 from math import sqrt
00014 import array
00015
00016
00017 TF1 = gbl.TF1
00018 TCanvas = gbl.TCanvas
00019 gbl.gStyle.SetPalette(1)
00020 gbl.gStyle.SetOptFit(1)
00021
00022
00023 class DrawEnergyFigsAlg(DybPythonAlg):
00024 "Algorithm to draw figures from the energy statistics file"
00025 def __init__(self,name):
00026 DybPythonAlg.__init__(self,name)
00027 return
00028
00029 def initialize(self):
00030 status = DybPythonAlg.initialize(self)
00031 if status.isFailure(): return status
00032 self.info("initializing")
00033
00034 return SUCCESS
00035
00036 def execute(self):
00037 self.info("executing")
00038
00039 return SUCCESS
00040
00041 def finalize(self):
00042 self.info("finalizing")
00043
00044
00045 canvas = TCanvas()
00046
00047 self.stats["/file0/energy/nobgEnergy"].Draw()
00048 maxbin = self.stats["/file0/energy/nobgEnergy"].GetMaximumBin()
00049 max = self.stats["/file0/energy/nobgEnergy"].GetMaximumBin() * 0.006
00050 interval=0.02
00051 g = 0
00052 oldfitChi = 1000
00053 for i in range(0,15):
00054 self.stats["/file0/energy/nobgEnergy"].Fit("gaus","","",max-interval,max+2*interval)
00055 print "interval1=", max-interval
00056 print "interval2=", max+interval
00057 fitResults = self.stats["/file0/energy/nobgEnergy"].GetFunction("gaus")
00058 fitChi = fitResults.GetChisquare()
00059 ndf = interval*500-3
00060 fitChi = fitChi / ndf
00061 print "ndf=", ndf
00062 print "fitchi=", fitChi
00063 if oldfitChi > fitChi:
00064 g = i
00065 interval=interval+0.02
00066 oldfitChi = fitChi
00067
00068 interval=0.02+g*0.02
00069 print "interval=", interval
00070 peak1 = TF1("m1","gaus",0,0.75)
00071 peak2 = TF1("m2","gaus",0.75,1.5)
00072 total = TF1("mtotal", "gaus(0) + gaus(3)", 0, 1.5)
00073
00074 self.stats["/file0/energy/nobgEnergy"].Fit(peak1,"R")
00075 self.stats["/file0/energy/nobgEnergy"].Fit(peak2,"R+")
00076 peak1_0 = peak1.GetParameter(0)
00077 peak1_1 = peak1.GetParameter(1)
00078 peak1_2 = peak1.GetParameter(2)
00079
00080
00081 total = TF1("fit", "[0]*TMath::Gaus(x,[1],[2]) + [3]*TMath::Gaus(x,[1]/2,[2]/sqrt(2))", 0, 1.5)
00082 total.SetParameter(0,peak1_0)
00083 total.SetParameter(1,peak1_1)
00084 total.SetParameter(2,peak1_2)
00085 total.SetParameter(3,0)
00086
00087 self.stats["/file0/energy/nobgEnergy"].Fit(total, "R")
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 canvas.SaveAs("nobgEnergy.png")
00098
00099 status = DybPythonAlg.finalize(self)
00100 return status
00101
00102
00103
00104
00105 def configure():
00106 from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00107 statsSvc = StatisticsSvc()
00108 statsSvc.Input ={"file0":"10000energyStatsDiff_10.root"}
00109 return
00110
00111 def run(app):
00112 '''
00113 Configure and add an algorithm to job
00114 '''
00115 app.ExtSvc += ["StatisticsSvc"]
00116 energyFigsAlg = DrawEnergyFigsAlg("MyEnergyFigs")
00117 app.addAlgorithm(energyFigsAlg)
00118 pass
00119