/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Public Attributes
autoES::AutoES Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def Accumulate
def Fit
def GetESCalib
def WriteToDB

Public Attributes

 outfile
 ADs
 checkNEvents
 isFit
 uploader

Detailed Description

Definition at line 15 of file autoES.py.


Constructor & Destructor Documentation

def autoES::AutoES::__init__ (   self,
  outfilename,
  dbconf 
)

Definition at line 17 of file autoES.py.

00018                                            :
00019         logging.info('Loading autoES v2013-12-06')
00020 
00021         from ROOT import TFile
00022         self.outfile = TFile(outfilename, 'UPDATE')
00023         self.ADs = {1:[1,2], 2:[1,2], 3:[1,2,3,4]}
00024 
00025         for hall in [1,2,3]:
00026             if self.outfile.Get('EH%d' % hall) == None:
00027                 logging.debug('Create folder EH%d' % hall)
00028                 self.outfile.mkdir('EH%d' % hall)
00029 
00030             folder = self.outfile.Get('EH%d' % hall)
00031             for AD in self.ADs[hall]:
00032                 if self.outfile.Get('EH%d/AD%d' % (hall, AD)) == None:
00033                     logging.debug('Create folder EH%d/AD%d' % (
00034                         hall, AD))
00035                     folder.mkdir('AD%d' % AD)
00036 
00037         self.checkNEvents = 10000
00038         self.isFit = False
00039 
00040         from DBUploader import DBUploader
00041         self.uploader = DBUploader(dbconf)

def autoES::AutoES::__del__ (   self)

Definition at line 42 of file autoES.py.

00043                      :
00044         self.outfile.Close()


Member Function Documentation

def autoES::AutoES::Accumulate (   self,
  filename,
  reset = False 
)

Definition at line 45 of file autoES.py.

00046                                                :
00047         self.isFit = False
00048 
00049         from ROOT import TFile, TObject
00050         infile = TFile(filename)
00051 
00052         if 'EH1' in filename:
00053             hall = 1
00054         elif 'EH2' in filename:
00055             hall = 2
00056         elif 'EH3' in filename:
00057             hall = 3
00058         else:
00059             return
00060 
00061         file_timestamp = infile.Get('stats/ESCalib/TimeStampSec')
00062         if file_timestamp == None:
00063             return
00064 
00065         for AD in self.ADs[hall]:
00066             h_signal = infile.Get('stats/ESCalib/EH%d/AD%d/PESum' % (
00067                 hall, AD))
00068             h_bkg = infile.Get('stats/ESCalib/EH%d/AD%d/PESumBkg' % (
00069                 hall, AD))
00070 
00071             if h_signal == None or h_bkg == None:
00072                 continue
00073 
00074             curr_status = self.outfile.Get(
00075                     'EH%d/AD%d/Status' % (hall, AD))
00076 
00077             if curr_status == None:
00078                 logging.debug('Set status 0 EH%d/AD%d' % (hall, AD))
00079                 from ROOT import TParameter
00080                 curr_status = TParameter('int')('Status', 0)
00081 
00082             curr_timestamp = self.outfile.Get(
00083                     'EH%d/AD%d/TimeStampSec' % (hall, AD))
00084 
00085             if curr_timestamp == None:
00086                 logging.debug('Clone timestamp EH%d/AD%d' % (hall, AD))
00087                 curr_timestamp = file_timestamp.Clone()
00088 
00089             h_curr = self.outfile.Get(
00090                     'EH%d/AD%d/PESumBkgSubtracted' % (hall, AD))
00091 
00092             if h_curr == None:
00093                 logging.debug('Clone histogram EH%d/AD%d' % (hall, AD))
00094                 h_curr = h_signal.Clone('PESumBkgSubtracted')
00095 
00096             else:
00097                 if reset or curr_status.GetVal() == 1:
00098                     logging.debug('Set timestamp EH%d/AD%d' % (hall, AD))
00099                     curr_timestamp.SetVal(file_timestamp.GetVal())
00100 
00101                     logging.debug('Set status 0 EH%d/AD%d' % (hall, AD))
00102                     curr_status.SetVal(0)
00103 
00104                     logging.debug('Reset histogram EH%d/AD%d' % (hall, AD))
00105                     h_curr.Reset()
00106 
00107                 h_curr.Add(h_signal)
00108                 logging.debug('Add histogram EH%d/AD%d' % (hall, AD))
00109 
00110             h_curr.Add(h_bkg, -1.0)
00111 
00112             nevents = h_curr.Integral(
00113                     h_curr.FindBin(1000.0), h_curr.FindBin(1600.0))
00114 
00115             if nevents > self.checkNEvents:
00116                 fit = self.Fit(h_curr)
00117                 result = self.GetESCalib(hall, AD, fit)
00118                 if result:
00119                     self.isFit = True
00120                     logging.debug('Fit histogram EH%d/AD%d' % (hall, AD))
00121                     logging.info('AutoESCalib Result')
00122                     logging.info('%d %d %d %.2f %.2f %.2f %.2f' % (
00123                         curr_timestamp.GetVal(), hall, AD,
00124                         result.mean, result.mean_err,
00125                         result.sigma, result.sigma_err))
00126 
00127                     self.WriteToDB(curr_timestamp.GetVal(), hall, AD, result)
00128 
00129                     logging.debug('Set status 1 EH%d/AD%d' % (hall, AD))
00130                     curr_status.SetVal(1)
00131                 else:
00132                     logging.info('Orphan entry. Skip filling DB.')
00133 
00134             logging.info('EH%d/AD%d     status %d   \
00135 TimeStamp %d    nEvents %d' % (
00136                     hall, AD, curr_status.GetVal(),
00137                     curr_timestamp.GetVal(), nevents))
00138 
00139             self.outfile.cd('EH%d/AD%d' % (hall, AD))
00140             h_curr.Write('', TObject.kWriteDelete)
00141             curr_timestamp.Write('', TObject.kWriteDelete)
00142             curr_status.Write('', TObject.kWriteDelete)
00143 
00144         self.outfile.Flush()
00145         infile.Close()

def autoES::AutoES::Fit (   histo,
  xmin = 1000,
  xmax = 1600,
  auto = False 
)

Definition at line 147 of file autoES.py.

00148                                                     :
00149         try:
00150             from ROOT import DoubleCrystalBallFit
00151         except ImportError:
00152             from ROOT import gROOT
00153             gROOT.ProcessLine('.L $ESCALIBSPNROOT/share/DoubleCrystalBall.C')
00154             from ROOT import DoubleCrystalBallFit
00155 
00156         from ROOT import TF1
00157         prefit = TF1('prefit', 'gaus', 1000, 1600)
00158         histo.Fit(prefit, 'RQ0')
00159         mean = prefit.GetParameter(1)
00160         sigma = prefit.GetParameter(2)
00161         norm = prefit.GetParameter(3)
00162 
00163         if auto:
00164             fit = DoubleCrystalBallFit('fit', mean+xmin*sigma, mean+xmax*sigma)
00165         else:
00166             fit = DoubleCrystalBallFit('fit', xmin, xmax)
00167 
00168         fit.SetParameters(2.0, 0.15, mean, sigma, norm)
00169 
00170         fit.SetParLimits(0, 0, 5)
00171         fit.SetParLimits(1, 0, 1)
00172         fit.SetParLimits(2, 1000, 1600)
00173         fit.SetParLimits(3, 20, 500)
00174 
00175         histo.Fit(fit, 'RQ0')
00176         return fit

def autoES::AutoES::GetESCalib (   hall,
  AD,
  fit 
)

Definition at line 178 of file autoES.py.

00179                                  :
00180         # Handling for orphan entry
00181         from math import isnan
00182         if (isnan(fit.GetParameter(2)) or isnan(fit.GetParameter(3)) or
00183                 isnan(fit.GetParError(2)) or isnan(fit.GetParError(3))):
00184             return None
00185 
00186         #docdb-9418 p7
00187         correction = {
00188             (1,1):0.9927,
00189             (1,2):0.9934,
00190             (2,1):0.9921,
00191             (2,2):0.9922,
00192             (3,1):0.9901,
00193             (3,2):0.9904,
00194             (3,3):0.9899,
00195             (3,4):0.9895}
00196 
00197         corr = correction[(hall, AD)]
00198         result = ESCalibResult(
00199                 chisq = fit.GetChisquare(),
00200                 ndf = fit.GetNDF(),
00201                 mean = corr*fit.GetParameter(2)/7.937,
00202                 mean_err = corr*fit.GetParError(2)/7.937,
00203                 sigma = corr*fit.GetParameter(3)/7.937,
00204                 sigma_err = corr*fit.GetParError(3)/7.937)
00205 
00206         return result

def autoES::AutoES::WriteToDB (   self,
  timestamp,
  hall,
  AD,
  result 
)

Definition at line 207 of file autoES.py.

00208                                                     :
00209         site = hall
00210         if hall == 3:
00211             site = 4
00212         self.uploader.Upload(timestamp, site, AD,
00213                 result.mean, result.mean_err)


Member Data Documentation

Definition at line 17 of file autoES.py.

Definition at line 17 of file autoES.py.

Definition at line 17 of file autoES.py.

Definition at line 17 of file autoES.py.

Definition at line 17 of file autoES.py.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:55:35 for ESCalibSPN by doxygen 1.7.4