Exemplo n.º 1
0
 def correct(self,mon,dio,plot=False):
   pp = self.poly
   x0 = (-pp[1]+np.sqrt(pp[1]**2-4*pp[0]*pp[2]))/2/pp[0]
   if ( x0<0 ):
     dioC  = dio-pp[2]
     monC  = mon
   else:
     monC  = mon-x0
     dioC  = dio
   if (pp[0]>0):
     monC  = monC + pp[0]/pp[1]*monC**2
   else:
     dioC  = dioC - pp[0]*monC**2
   if (plot):
     toolsPlot.nfigure("Check non lin correction")
     pl.plot(mon,dio/mon,"+",label = "before correction")
     pl.plot(monC,dioC/monC,"o",label = "after correction")
     pl.ylabel("ratio signal/monitor")
     pl.legend()
     pl.grid()
   return (monC,dioC)
Exemplo n.º 2
0
 def calibrate(self,mon,dio,plot=False):
   self.mon = mon
   self.dio = dio
   self.poly = np.polyfit(mon,dio,2)
   if (plot):
     toolsPlot.nfigure("calibration")
     ax1=pl.subplot("211",title="det vs monitor (before correction)")
     pl.plot(mon,dio,"+")
     m=np.min(mon); M=np.max(mon)
     x = np.arange(m,M,(M-m)/100.)
     pl.plot(x,np.polyval(self.poly,x))
     pl.subplot("212",title="Ratio vs monitor",sharex=ax1)
     #pl.plot(mon,dio/mon,"+",label="before")
     M=mon.max()
     m=mon.min()
     h1 = np.histogram(mon,np.arange(m,M,(M-m)/30.),weights=dio/mon)
     h0 = np.histogram(mon,np.arange(m,M,(M-m)/30.),)
     pl.plot(toolsPlot.histVecCenter(h1[1]),h1[0]/h0[0],label="before")
     mon,dio=self.correct(mon,dio)
     h1 = np.histogram(mon,np.arange(m,M,(M-m)/30.),weights=dio/mon)
     h0 = np.histogram(mon,np.arange(m,M,(M-m)/30.),)
     pl.plot(toolsPlot.histVecCenter(h1[1]),h1[0]/h0[0],label="after")
     pl.legend()