/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::Tools::PmtTableWriterAlg Class Reference
Inheritance diagram for CalibParam::Tools::PmtTableWriterAlg:
Inheritance graph
[legend]
Collaboration diagram for CalibParam::Tools::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
 mean1
 mean2
 UseLastGain
 cableSvc
 statsSvc
 pmtGeomSvc
 calibDataSvc
 msgSvc
 archiveSvc
 stats
 defaultInputLocation
 execNumber
 currentJobId

Detailed Description

Definition at line 26 of file Tools.py.


Constructor & Destructor Documentation

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

Definition at line 28 of file Tools.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.mean1=0.0
00040         self.mean2=0.0
00041         self.UseLastGain=1 # when errors, use default value or Last commit in DB, 1 use DB, 0 use default
00042         return


Member Function Documentation

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

Definition at line 43 of file Tools.py.

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

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

Definition at line 71 of file Tools.py.

00072                      :
00073         self.info("executing")
00074         return SUCCESS
        
def CalibParam::Tools::PmtTableWriterAlg::finalize (   self)

Definition at line 75 of file Tools.py.

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

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

Definition at line 89 of file Tools.py.

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

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

Definition at line 128 of file Tools.py.

00129                                        :
00130         # Initialize using an approximate default calibration
00131         pmtCalib.m_status = PmtCalibData.kGood
00132         pmtCalib.m_speHigh = 20.0
00133         pmtCalib.m_sigmaSpeHigh = 0.0
00134         pmtCalib.m_speLow = 2.0
00135         pmtCalib.m_timeOffset = 0.0
00136         pmtCalib.m_timeSpread = 0.0
00137         pmtCalib.m_efficiency = 1.0
00138         pmtCalib.m_prePulseProb = 0.0
00139         pmtCalib.m_afterPulseProb = 0.0
00140         pmtCalib.m_darkRate = 0.0

def CalibParam::Tools::PmtTableWriterAlg::updateCalibration (   self,
  pmtCalibList 
)

Definition at line 141 of file Tools.py.

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

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

Definition at line 172 of file Tools.py.

00173                                                          :
00174         print "I am in updateAdCalibration" #tmp
00175         # Loop over the pmts and process calibration stats
00176         meanTimeOffset = 0.0
00177         nMeanTimeOffset = 0
00178         badch=0
00179         relativeEfficiency = {}
00180         #for ring in range(1,9): relativeEfficiency[ring] = []
00181         for pmtCalib in pmtCalibList:
00182             pmtId = pmtCalib.m_pmtId
00183             context = Context()
00184             context.SetSite(pmtId.site())
00185             context.SetDetId(pmtId.detectorId())
00186             path = self.StatsPath + "/" + pmtId.detName()
00187             sec =   self.statsSvc.get(path + "/timeSec")
00188             nanosec = self.statsSvc.get(path + "/timeNanoSec")
00189             timeStamp = TimeStamp(sec.GetVal(),nanosec.GetVal())
00190             context.SetTimeStamp(timeStamp)
00191             simf = self.statsSvc.get(path + "/simFlag")
00192             context.SetSimFlag(simf.GetVal())
00193             svcMode = ServiceMode(context, 0)
00194             feeid = self.cableSvc.feeChannelId(pmtId, svcMode)
00195             board = feeid.board()
00196             connector = feeid.connector()
00197             if pmtId.ring() ==0 : # 2 inch PMT can't be calibrated with low intensity, just use last result in DB
00198                 sensDetId = self.cableSvc.adPmtSensor(feeid, svcMode)
00199                 CalibData = self.calibDataSvc.pmtCalibData(sensDetId, svcMode)
00200                 pmtCalib.m_status = PmtCalibData.kGood
00201                 if CalibData == 0:
00202                     pmtCalib.m_speHigh = 0
00203                     pmtCalib.m_sigmaSpeHigh = 0
00204                     pmtCalib.m_speLow = 0
00205                     pmtCalib.m_timeOffset = 0
00206                 else :
00207                     pmtCalib.m_speHigh = CalibData.m_speHigh
00208                     pmtCalib.m_sigmaSpeHigh = CalibData.m_sigmaSpeHigh
00209                     pmtCalib.m_speLow = CalibData.m_speLow
00210                     pmtCalib.m_timeOffset = CalibData.m_timeOffset
00211                 continue
00212             [adcMeanH, adcSigmaH, occuH, Chi2H] = self.getAdCalibHists(pmtId)
00213             if adcMeanH==None or adcSigmaH==None or occuH==None or Chi2H==None:
00214                 self.error("Failed to get calibration histograms for "
00215                            +detector.detName())
00216                 return FAILURE
00217             adcMean       = adcMeanH.GetBinContent(board*16+connector)            
00218             adcMeanUncert = adcMeanH.GetBinError(board*16+connector)
00219             adcReso       = adcSigmaH.GetBinContent(board*16+connector)
00220             adcResoUncert = adcSigmaH.GetBinError(board*16+connector)
00221             chi2 = Chi2H.GetBinContent(board*16+connector)
00222             occu = occuH.GetBinContent(board*16+connector)
00223             if adcReso<0:
00224                 adcReso = adcReso*-1
00225             # Update PMT status
00226             pmtCalib.m_status = PmtCalibData.kUnknown
00227             sensDetId = self.cableSvc.adPmtSensor(feeid, svcMode)
00228             CalibData = self.calibDataSvc.pmtCalibData(sensDetId, svcMode)
00229             lastGain = CalibData.m_speHigh
00230             self.mean2 += CalibData.m_speHigh
00231 #            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):
00232 #                if self.UseLastGain ==0:
00233 #                    pmtCalib.m_status += PmtCalibData.kBadGain
00234 #                    badch+=1
00235 #                    pmtCalib.m_speHigh = 20.0
00236 #                    pmtCalib.m_sigmaSpeHigh = 8.0
00237 #                    pmtCalib.m_speLow = 20.0 / 19.5
00238 #                    pmtCalib.m_timeOffset = CalibData.m_timeOffset
00239 #                    print "Error: Bad Calibraion in ",detector.detName(),"Board: ", board, "Connector: ", connector, ". Please Check it."
00240 #                if self.UseLastGain ==1:
00241 #                    pmtCalib.m_status = PmtCalibData.kGood
00242 #                    badch+=1
00243 #                    pmtCalib.m_speHigh = CalibData.m_speHigh
00244 #                    pmtCalib.m_sigmaSpeHigh = CalibData.m_sigmaSpeHigh
00245 #                    pmtCalib.m_speLow = CalibData.m_speLow
00246 #                    pmtCalib.m_timeOffset = CalibData.m_timeOffset
00247 #                    print "Error: Bad Calibraion in ",detector.detName(),"Board: ", board, "Connector: ", connector, ". Please Check it."
00248             # If no problems found, PMT is good
00249             if( pmtCalib.m_status == PmtCalibData.kUnknown ):
00250                 pmtCalib.m_status = PmtCalibData.kGood
00251                 pmtCalib.m_speHigh = adcMean
00252                 pmtCalib.m_sigmaSpeHigh = adcReso
00253                 pmtCalib.m_speLow = adcMean / 19.5
00254                 pmtCalib.m_timeOffset = CalibData.m_timeOffset
00255                 self.mean1+=adcMean
00256         print "total bad channel", badch
00257         print "mean gain of 8inch PMT in this update is ", self.mean1/192.
00258         print "mean gain of 8inch PMT in last commit is ", self.mean2/192.
00259         return SUCCESS

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

Definition at line 260 of file Tools.py.

00261                                     :
00262         # Return the calibration histograms for this PMT
00263         path = self.StatsPath + "/" + pmtId.detName()
00264         if self.StatsPath=="/file0/pmtCalibLeadingEdge":
00265             adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00266             adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00267             occuH = self.statsSvc.get(path +"/occupancyChannel")
00268             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00269         else:
00270             adcMeanH = self.statsSvc.get(path + "/gainChannel")
00271             adcSigmaH =  self.statsSvc.get(path + "/gainChannelSigma")
00272             occuH = self.statsSvc.get(path +"/occupancyChannel")
00273             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00274         return [adcMeanH, adcSigmaH, occuH, Chi2H]
00275     

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

Definition at line 276 of file Tools.py.

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

Definition at line 331 of file Tools.py.

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

Definition at line 344 of file Tools.py.

00345                                       :
00346         # Write a line for the calibration table
00347         pmtLabel = None
00348         pmtId = pmtCalib.m_pmtId
00349         if pmtId.isAD():
00350             pmtLabel = "%s-ring%02d-column%02d" % (pmtId.detName(),
00351                                                    pmtId.ring(),
00352                                                    pmtId.column())
00353         elif pmtId.isWaterShield():
00354             inward = "in"
00355             if not pmtId.inwardFacing(): inward = "out"
00356             pmtLabel = "%s-wall%02d-spot%02d-%s" % (pmtId.detName(),
00357                                                     pmtId.wallNumber(),
00358                                                     pmtId.wallSpot(),
00359                                                     inward)
00360         line=("%d\t%30s\t%2d\t%7.3f\t%5.3f\t%5.3f\t%7.3f\t%5.3f\t%5.3f\t%5.3f\t%5.3f\t%5.3f\n"
00361               % (pmtCalib.m_pmtId.fullPackedData(),
00362                  pmtLabel,
00363                  pmtCalib.m_status,
00364                  pmtCalib.m_speHigh,
00365                  pmtCalib.m_sigmaSpeHigh,
00366                  pmtCalib.m_speLow,
00367                  pmtCalib.m_timeOffset / units.ns,
00368                  pmtCalib.m_timeSpread / units.ns,
00369                  pmtCalib.m_efficiency,
00370                  pmtCalib.m_prePulseProb,
00371                  pmtCalib.m_afterPulseProb,
00372                  pmtCalib.m_darkRate / units.hertz
00373                  )
00374               )
00375         return line

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

Definition at line 376 of file Tools.py.

00377                                            :
00378         # Write a calibration table using the list of pmt calibrations
00379         tableLines = []
00380         tableLines.append("#Table\tof\tCalibration\tconstants\tfor\teach\tchannel\n")
00381         tableLines.append("#[pmtID]\t[description]\t[status]\t[speHigh]\t[sigmaSpe]\t[speLow]\t[timeOffset]\t[timeSpread]\t[efficiency]\t[prePulse]\t[afterPulse]\t[darkRate]\n")
00382 
00383         # sort them by id, otherwise it is out of control
00384         idCalib = {}
00385         for pmtCalib in pmtCalibList:
00386             idCalib[ pmtCalib.m_pmtId.fullPackedData() ] = pmtCalib
00387 
00388         for id in sorted( idCalib.keys() ):
00389             pmtCalib = idCalib[id]
00390             line = self.calibTableLine(pmtCalib)
00391             if not pmtCalib.m_sigmaSpeHigh == 0.0: 
00392                 tableLines.append(line)
00393         outFile = open(self.OutputFileName,'w')
00394         outFile.writelines(tableLines)
00395         outFile.close()        
00396 
00397 
# Merge calibration tables

Member Data Documentation

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 28 of file Tools.py.

Definition at line 43 of file Tools.py.

Definition at line 43 of file Tools.py.

Definition at line 43 of file Tools.py.

Definition at line 43 of file Tools.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