/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
CalibParam::HighGainTools::PmtTableWriterAlg Class Reference
Inheritance diagram for CalibParam::HighGainTools::PmtTableWriterAlg:
Inheritance graph
[legend]
Collaboration diagram for CalibParam::HighGainTools::PmtTableWriterAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def initialize
def execute
def finalize
def initializeCalibTable
def initializeCalib
def updateCalibration
def updateAdCalibration
def getAdCalibHists
def updateWaterShieldCalibration
def getWPCalibHists
def calibTableLine
def writeCalibTable
def __init__
def initialize
def execute
def finalize
def verbose
def debug
def info
def warning
def error
def fatal
def getAES
def initializeHeader
def finalizeHeader

Public Attributes

 StatsPath
 OutputTableName
 IsDryAd
 SetDefaultCalib
 SourcePosition
 DetId
 site
 UseLastGain
 cableSvc
 statsSvc
 pmtGeomSvc
 calibDataSvc
 msgSvc
 archiveSvc
 stats
 defaultInputLocation
 execNumber
 currentJobId

Detailed Description

Definition at line 26 of file HighGainTools.py.


Constructor & Destructor Documentation

def CalibParam::HighGainTools::PmtTableWriterAlg::__init__ (   self,
  name 
)

Definition at line 28 of file HighGainTools.py.

00029                            :
00030         DybPythonAlg.__init__(self,name)
00031         # Properties
00032         self.StatsPath = "/file0/pmtCalibLeadingEdge"
00033         self.OutputTableName = "pmtCalibTable.txt"
00034         self.IsDryAd = False
00035         self.SetDefaultCalib = True
00036         self.SourcePosition = [0.,0.,0.]
00037         self.DetId=1
00038         self.site = 1 
00039         self.UseLastGain=1 # when errors, use default value or Last commit in DB, 1 use DB, 0 use default
00040         return


Member Function Documentation

def CalibParam::HighGainTools::PmtTableWriterAlg::initialize (   self)

Definition at line 41 of file HighGainTools.py.

00042                         :
00043         status = DybPythonAlg.initialize(self)
00044         if status.isFailure(): return status
00045         self.info("initializing")
00046 
00047         # Initialize services
00048         self.cableSvc = self.svc('ICableSvc','CableSvc')
00049         if self.cableSvc == None:
00050             self.error("Failed to get CableSvc")
00051             return FAILURE
00052         self.statsSvc = self.svc('IStatisticsSvc','StatisticsSvc')
00053         if self.statsSvc == None:
00054             self.error("Failed to get StatisticsSvc")
00055             return FAILURE
00056         self.pmtGeomSvc = self.svc('IPmtGeomInfoSvc','PmtGeomInfoSvc')
00057         if self.pmtGeomSvc == None:
00058             self.error("Failed to get PmtGeomInfoSvc")
00059             return FAILURE
00060         self.calibDataSvc = self.svc('ICalibDataSvc','CalibDataSvc')
00061         if self.calibDataSvc == None:
00062             self.error("Failed to get PMT calibData svc")
00063             return FAILURE
00064         if self.UseLastGain ==1:
00065            print "Use last commit in database when Gain is bad"
00066         if self.UseLastGain ==0:
00067            print "Use Default value(20) when Gain is bad"
00068         return status

def CalibParam::HighGainTools::PmtTableWriterAlg::execute (   self)

Definition at line 69 of file HighGainTools.py.

00070                      :
00071         self.info("executing")
00072         return SUCCESS
        
def CalibParam::HighGainTools::PmtTableWriterAlg::finalize (   self)

Definition at line 73 of file HighGainTools.py.

00074                       :
00075         self.info("finalizing")
00076         # Generate the PMT calibration table, and write to file
00077         # Step 1: initialize the table
00078         pmtCalibList = self.initializeCalibTable()
00079         self.info("I initialized the table") #tmp
00080         # Step 2: incorporate data using the current calibration statistics
00081         status = self.updateCalibration(pmtCalibList)
00082         if not status.isSuccess(): return status
00083         # Step 3: Print out the table
00084         self.writeCalibTable(pmtCalibList)
00085         status = DybPythonAlg.finalize(self)
00086         return status

def CalibParam::HighGainTools::PmtTableWriterAlg::initializeCalibTable (   self)

Definition at line 87 of file HighGainTools.py.

00088                                   :
00089         # Initialize table of PMT calibrations
00090         # Initialize table of PMT calibrations
00091         detDirs = self.statsSvc.getSubFolders(self.StatsPath)
00092         adPmtCalibList = []
00093         wpPmtCalibList = []
00094         for detDir in detDirs:
00095             detector = Detector(detDir)
00096             context = Context()
00097             context.SetSite(detector.site())
00098             context.SetDetId(detector.detectorId())
00099             if not detector.site() == self.site:
00100                 continue
00101             if not detector.detectorId() == self.DetId:
00102                 continue
00103             path = self.StatsPath + "/" + detDir
00104             sec =   self.statsSvc.get(path + "/timeSec")
00105             nanosec = self.statsSvc.get(path + "/timeNanoSec")
00106             timeStamp = TimeStamp(sec.GetVal(),nanosec.GetVal())
00107             context.SetTimeStamp(timeStamp)
00108             simf = self.statsSvc.get(path + "/simFlag")
00109             context.SetSimFlag(simf.GetVal())
00110             svcMode = ServiceMode(context, 0)  # Dummy ServiceMode
00111             adPmts = self.cableSvc.adPmtSensors(svcMode)
00112             wpPmts = self.cableSvc.poolPmtSensors(svcMode)
00113             for adPmt in adPmts:
00114                 pmtCalib = PmtCalibData()
00115                 pmtCalib.m_pmtId = adPmt
00116                 if self.SetDefaultCalib: 
00117                     self.initializeCalib(pmtCalib)
00118                 adPmtCalibList.append( pmtCalib )
00119             for wpPmt in wpPmts:
00120                 pmtCalib = PmtCalibData()
00121                 pmtCalib.m_pmtId = wpPmt
00122                 if self.SetDefaultCalib: 
00123                    self.initializeCalib(pmtCalib)
00124                 wpPmtCalibList.append( pmtCalib )
00125         pmtCalibList = adPmtCalibList + wpPmtCalibList
00126         return pmtCalibList

def CalibParam::HighGainTools::PmtTableWriterAlg::initializeCalib (   self,
  pmtCalib 
)

Definition at line 127 of file HighGainTools.py.

00128                                        :
00129         # Initialize using an approximate default calibration
00130         pmtCalib.m_status = PmtCalibData.kGood
00131         pmtCalib.m_speHigh = 20.0
00132         pmtCalib.m_sigmaSpeHigh = 0.0
00133         pmtCalib.m_speLow = 2.0
00134         pmtCalib.m_Chi2NDF = 1.0
00135         pmtCalib.m_speHighError = 1.0
00136         pmtCalib.m_speLowError = 1.0
        pmtCalib.m_channelId = 0
def CalibParam::HighGainTools::PmtTableWriterAlg::updateCalibration (   self,
  pmtCalibList 
)

Definition at line 137 of file HighGainTools.py.

00138                                              :
00139         # Process the calibration statistics and update the
00140         # calibration parameters
00141         detDirs = self.statsSvc.getSubFolders(self.StatsPath)
00142         for detDir in detDirs:
00143             detector = Detector(detDir)
00144             if not detector.site() == self.site:
00145                 continue
00146             if not detector.detectorId() == self.DetId:
00147                 continue
00148             if( detector.site() == Site.kUnknown
00149                 or detector.detectorId() == DetectorId.kUnknown ):
00150                 self.error("Unknown detector: "+detDir)
00151                 return FAILURE
00152             else:
00153                 self.info("Processing: "+detDir)
00154             # Find the PMT IDs that are in the current detector
00155             pmtCalibs = []
00156             for pmtCalib in pmtCalibList:
00157                 pmtId = pmtCalib.m_pmtId
00158                 if (pmtId.site() == detector.site()
00159                     and pmtId.detectorId() == detector.detectorId()):
00160                     pmtCalibs.append(pmtCalib)
00161             if detector.isAD():
00162                 status = self.updateAdCalibration(detector, pmtCalibs)
00163                 if not status.isSuccess(): return status
00164             elif detector.isWaterShield():
00165                 status = self.updateWaterShieldCalibration(detector, pmtCalibs)
00166                 if not status.isSuccess(): return status
00167         return SUCCESS

def CalibParam::HighGainTools::PmtTableWriterAlg::updateAdCalibration (   self,
  detector,
  pmtCalibList 
)

Definition at line 168 of file HighGainTools.py.

00169                                                          :
00170         print "I am in updateAdCalibration" #tmp
00171         # Loop over the pmts and process calibration stats
00172         meanTimeOffset = 0.0
00173         nMeanTimeOffset = 0
00174         relativeEfficiency = {}
00175         for ring in range(1,9): relativeEfficiency[ring] = []
00176         for pmtCalib in pmtCalibList:
00177 
00178             pmtId = pmtCalib.m_pmtId
00179             context = Context()
00180             context.SetSite(pmtId.site())
00181             context.SetDetId(pmtId.detectorId())
00182             path = self.StatsPath + "/" + pmtId.detName()
00183             sec =   self.statsSvc.get(path + "/timeSec")
00184             nanosec = self.statsSvc.get(path + "/timeNanoSec")
00185             timeStamp = TimeStamp(sec.GetVal(),nanosec.GetVal())
00186             context.SetTimeStamp(timeStamp)
00187             simf = self.statsSvc.get(path + "/simFlag")
00188             context.SetSimFlag(simf.GetVal())
00189             svcMode = ServiceMode(context, 0)
00190             feeid = self.cableSvc.feeChannelId(pmtId, svcMode)
00191             pmtCalib.m_channelId  = feeid.fullPackedData()
00192             board = feeid.board()
00193             connector = feeid.connector()
00194             if pmtId.ring() ==0 : # 2 inch PMT can't be calibrated with low intensity, just use last result in DB
00195                 sensDetId = self.cableSvc.adPmtSensor(feeid, svcMode)
00196                 CalibData = self.calibDataSvc.highGainCalibData(sensDetId, svcMode)
00197                 pmtCalib.m_status = PmtCalibData.kGood
00198                 pmtCalib.m_speHigh = CalibData.m_speHigh
00199                 pmtCalib.m_speHighError = CalibData.m_speHighError
00200                 pmtCalib.m_sigmaSpeHigh = CalibData.m_sigmaSpeHigh
00201                 pmtCalib.m_speLow = CalibData.m_speHigh/19.5
00202                 pmtCalib.m_speLowError = CalibData.m_speHighError / 19.5
00203                 pmtCalib.m_Chi2NDF = CalibData.m_speHighFitQual
00204                 continue
00205             # Get the calibration histograms for this pmt
00206             [adcMeanH, adcSigmaH, occuH, Chi2H] = self.getAdCalibHists(pmtId)
00207             if adcMeanH==None or adcSigmaH==None or occuH==None or Chi2H==None:
00208                 self.error("Failed to get calibration histograms for "
00209                            +detector.detName())
00210                 return FAILURE
00211             adcMean       = adcMeanH.GetBinContent(board*16+connector)            
00212             adcMeanUncert = adcMeanH.GetBinError(board*16+connector)
00213             adcReso       = adcSigmaH.GetBinContent(board*16+connector)
00214             adcResoUncert = adcSigmaH.GetBinError(board*16+connector)
00215             chi2 = Chi2H.GetBinContent(board*16+connector)
00216             occu = occuH.GetBinContent(board*16+connector)
00217             if adcReso<0:
00218                 adcReso = adcReso*-1
00219                 # Update PMT status
00220             pmtCalib.m_status = PmtCalibData.kUnknown
00221             sensDetId = self.cableSvc.adPmtSensor(feeid, svcMode)
00222             CalibData = self.calibDataSvc.highGainCalibData(sensDetId, svcMode)
00223             if( adcMean < 10.0 or adcMean > 50.0 or adcMeanUncert>1 or adcReso>15 or adcResoUncert>1 or occu<0.01 or occu > 0.13 or chi2>3):
00224                 if self.UseLastGain ==0:
00225                     pmtCalib.m_status += PmtCalibData.kBadGain
00226                     pmtCalib.m_speHigh = 20.0
00227                     pmtCalib.m_speHighError = 0.1
00228                     pmtCalib.m_sigmaSpeHigh = 8.0
00229                     pmtCalib.m_speLow = 20 / 19.5
00230                     pmtCalib.m_speLowError = 0.1 / 19.5
00231                     pmtCalib.m_Chi2NDF = 10
00232                     print "Error: Bad Calibraion in ",detector.detName(),"Borad: ", board, "Connector: ", connector, ". Please Check it."
00233                 if self.UseLastGain ==1:
00234                     pmtCalib.m_status = PmtCalibData.kGood
00235                     pmtCalib.m_speHigh = CalibData.m_speHigh
00236                     pmtCalib.m_speHighError = CalibData.m_speHighError
00237                     pmtCalib.m_sigmaSpeHigh = CalibData.m_sigmaSpeHigh
00238                     pmtCalib.m_speLow = CalibData.m_speHigh/19.5
00239                     pmtCalib.m_speLowError = CalibData.m_speHighError / 19.5
00240                     pmtCalib.m_Chi2NDF = CalibData.m_speHighFitQual
00241                     print "Error: Bad Calibraion in ",detector.detName(),"Borad: ", board, "Connector: ", connector, ". Please Check it."
00242             if( pmtCalib.m_status == PmtCalibData.kUnknown ):
00243                 pmtCalib.m_status = PmtCalibData.kGood
00244                 pmtCalib.m_speHigh = adcMean
00245                 pmtCalib.m_speHighError = adcMeanUncert
00246                 pmtCalib.m_sigmaSpeHigh = adcReso
00247                 pmtCalib.m_speLow = adcMean / 19.5
00248                 pmtCalib.m_speLowError = adcMeanUncert / 19.5
00249                 pmtCalib.m_Chi2NDF = chi2
00250            
00251         return SUCCESS

def CalibParam::HighGainTools::PmtTableWriterAlg::getAdCalibHists (   self,
  pmtId 
)

Definition at line 252 of file HighGainTools.py.

00253                                     :
00254         # Return the calibration histograms for this PMT
00255         path = self.StatsPath + "/" + pmtId.detName()
00256 #       Chi2NDF = self.statsSvc.get(path + "/Chi2_1D")
00257         if self.StatsPath=="/file0/pmtCalibLeadingEdge":
00258             adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00259             adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00260             occuH = self.statsSvc.get(path +"/occupancyChannel")
00261             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00262         else:
00263             adcMeanH = self.statsSvc.get(path + "/gainChannel")
00264             adcSigmaH =  self.statsSvc.get(path + "/gainChannelSigma")
00265             occuH = self.statsSvc.get(path +"/occupancyChannel")
00266             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00267         return [adcMeanH, adcSigmaH, occuH, Chi2H]

def CalibParam::HighGainTools::PmtTableWriterAlg::updateWaterShieldCalibration (   self,
  detector,
  pmtCalibList 
)

Definition at line 268 of file HighGainTools.py.

00269                                                                   :
00270         print "I am in updateWPCalibration" #tmp By yuzy
00271         # Loop over the pmts and process calibration stats
00272         meanTimeOffset = 0.0
00273         nMeanTimeOffset = 0
00274         relativeEfficiency = {}
00275         for pmtCalib in pmtCalibList:
00276             pmtId = pmtCalib.m_pmtId
00277             # Get the calibration histograms for this pmt
00278             [adcMeanH, adcSigmaH, occuH, Chi2H] = self.getWPCalibHists(pmtId)    # only for gain now
00279             if adcMeanH==None or adcSigmaH==None or occuH==None or Chi2H==None:
00280                 self.error("Failed to get calibration histograms for "
00281                            +detector.detName())
00282                 return FAILURE
00283             context = Context()
00284             context.SetSite(pmtId.site())
00285             context.SetDetId(pmtId.detectorId())
00286             path = self.StatsPath + "/" + pmtId.detName()
00287             sec =   self.statsSvc.get(path + "/timeSec")
00288             nanosec = self.statsSvc.get(path + "/timeNanoSec")
00289             timeStamp = TimeStamp(sec.GetVal(),nanosec.GetVal())
00290             context.SetTimeStamp(timeStamp)
00291             simf = self.statsSvc.get(path + "/simFlag")
00292             context.SetSimFlag(simf.GetVal())
00293             svcMode = ServiceMode(context, 0)
00294             feeid = self.cableSvc.feeChannelId(pmtId, svcMode)
00295             pmtCalib.m_channelId  = feeid.fullPackedData()
00296             board = feeid.board()
00297             connector = feeid.connector()
00298             adcMean       = adcMeanH.GetBinContent(board*16+connector)            
00299             adcMeanUncert = adcMeanH.GetBinError(board*16+connector)
00300             adcReso       = adcSigmaH.GetBinContent(board*16+connector)
00301             adcResoUncert = adcSigmaH.GetBinError(board*16+connector)
00302             chi2 = Chi2H.GetBinContent(board*16+connector)
00303             occu = occuH.GetBinContent(board*16+connector)
00304             if adcReso<0:
00305                 adcReso = adcReso*-1
00306             # Update PMT status
00307             pmtCalib.m_status = PmtCalibData.kUnknown
00308             if( adcMean < 10.0 or adcMean > 50.0 or adcMeanUncert>1 or adcReso>15 or adcResoUncert>1 or occu<0.01 or occu > 0.13 or chi2>3):
00309                 pmtCalib.m_status += PmtCalibData.kBadGain
00310                 pmtCalib.m_speHigh = 20.0
00311                 pmtCalib.m_speHighError = 0.1
00312                 pmtCalib.m_sigmaSpeHigh = 8.0
00313                 pmtCalib.m_speLow = 20 / 19.5
00314                 pmtCalib.m_speLowError = 0.1 / 19.5
00315                 pmtCalib.m_Chi2NDF = 10
00316                 print "Error: Bad Calibraion in ",detector.detName(),"Borad: ", board, "Connector: ", connector, ". Please Check it."
00317             # If no problems found, PMT is good
00318             if( pmtCalib.m_status == PmtCalibData.kUnknown ):
00319                 pmtCalib.m_status = PmtCalibData.kGood
00320                 pmtCalib.m_speHigh = adcMean
00321                 pmtCalib.m_speHighError = adcMeanUncert
00322                 pmtCalib.m_sigmaSpeHigh = adcReso
00323                 pmtCalib.m_speLow = adcMean / 19.5
00324                 pmtCalib.m_speLowError = adcMeanUncert / 19.5
00325                 pmtCalib.m_Chi2NDF = chi2
00326                 
        return SUCCESS
def CalibParam::HighGainTools::PmtTableWriterAlg::getWPCalibHists (   self,
  pmtId 
)

Definition at line 327 of file HighGainTools.py.

00328                                     :
00329       path = self.StatsPath + "/" + pmtId.detName()
00330       if self.StatsPath=="/file0/pmtCalibLeadingEdge":
00331             adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00332             adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00333             occuH = self.statsSvc.get(path +"/occupancyChannel")
00334             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00335       else:
00336             adcMeanH = self.statsSvc.get(path + "/gainChannel")
00337             adcSigmaH =  self.statsSvc.get(path + "/gainChannelSigma")
00338             occuH = self.statsSvc.get(path +"/occupancyChannel")
00339             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
      return [adcMeanH, adcSigmaH, occuH, Chi2H]
def CalibParam::HighGainTools::PmtTableWriterAlg::calibTableLine (   self,
  pmtCalib 
)

Definition at line 340 of file HighGainTools.py.

00341                                       :
00342         # Write a line for the calibration table
00343         pmtLabel = None
00344         pmtId = pmtCalib.m_pmtId
00345         if pmtId.isAD():
00346             pmtLabel = "%s-ring%02d-column%02d" % (pmtId.detName(),
00347                                                    pmtId.ring(),
00348                                                    pmtId.column())
00349         elif pmtId.isWaterShield():
00350             inward = "in"
00351             if not pmtId.inwardFacing(): inward = "out"
00352             pmtLabel = "%s-wall%02d-spot%02d-%s" % (pmtId.detName(),
00353                                                     pmtId.wallNumber(),
00354                                                     pmtId.wallSpot(),
00355                                                     inward)
00356         line=("%d %30s %2d %7.3f %5.3f %5.3f %5.3f %5.3f %7.3f \n"
00357               % (pmtCalib.m_channelId,
00358                  pmtLabel,
00359                  pmtCalib.m_status,
00360                  pmtCalib.m_speHigh,
00361                  pmtCalib.m_speHighError,
00362                  pmtCalib.m_sigmaSpeHigh,
00363                  pmtCalib.m_speLow,
00364                  pmtCalib.m_speLowError,
00365                  pmtCalib.m_Chi2NDF
00366                  )
00367               )
00368         return line

def CalibParam::HighGainTools::PmtTableWriterAlg::writeCalibTable (   self,
  pmtCalibList 
)

Definition at line 369 of file HighGainTools.py.

00370                                            :
00371         # Write a calibration table using the list of pmt calibrations
00372         tableLines = []
00373         tableLines.append("# Table of Calibration constants for each channel\n")
00374         tableLines.append("# [chID] [description] [status] [speHigh] [speHighError] [sigmaSpe] [speLow] [speLowError] [FitQuality]\n")
00375 
00376         # sort them by id, otherwise it is out of control
00377         idCalib = {}
00378         for pmtCalib in pmtCalibList:
00379             idCalib[ pmtCalib.m_pmtId.fullPackedData() ] = pmtCalib
00380 
00381         for id in sorted( idCalib.keys() ):
00382             pmtCalib = idCalib[id]
00383             line = self.calibTableLine(pmtCalib)
00384             if not pmtCalib.m_sigmaSpeHigh == 0.0: 
00385                 tableLines.append(line)
00386         outFile = open(self.OutputFileName,'w')
00387         outFile.writelines(tableLines)
00388         outFile.close()        
00389 
00390 
# Merge calibration tables

Member Data Documentation

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 28 of file HighGainTools.py.

Definition at line 41 of file HighGainTools.py.

Definition at line 41 of file HighGainTools.py.

Definition at line 41 of file HighGainTools.py.

Definition at line 41 of file HighGainTools.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 10:04:28 for CalibParam by doxygen 1.7.4