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

Public Attributes

 StatsPath
 OutputTableName
 IsDryAd
 SetDefaultCalib
 SourcePosition
 cableSvc
 statsSvc
 pmtGeomSvc

Detailed Description

Definition at line 26 of file Tools.py.


Constructor & Destructor Documentation

def RandomGain::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/pmtCalibRandomGain"
00033         self.OutputTableName = "pmtCalibTable.txt"
00034         self.IsDryAd = False
00035         self.SetDefaultCalib = True
00036         self.SourcePosition = [0.,0.,0.]
00037         return


Member Function Documentation

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

Definition at line 38 of file Tools.py.

00039                         :
00040         status = DybPythonAlg.initialize(self)
00041         if status.isFailure(): return status
00042         self.info("initializing")
00043 
00044         # Initialize services
00045         self.cableSvc = self.svc('ICableSvc','CableSvc')
00046         if self.cableSvc == None:
00047             self.error("Failed to get StaticCableSvc")
00048             return FAILURE
00049         self.statsSvc = self.svc('IStatisticsSvc','StatisticsSvc')
00050         if self.statsSvc == None:
00051             self.error("Failed to get StatisticsSvc")
00052             return FAILURE
00053         self.pmtGeomSvc = self.svc('IPmtGeomInfoSvc','PmtGeomInfoSvc')
00054         if self.pmtGeomSvc == None:
00055             self.error("Failed to get PmtGeomInfoSvc")
00056             return FAILURE
00057         return status

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

Definition at line 58 of file Tools.py.

00059                      :
00060         self.info("executing")
00061         return SUCCESS
        
def RandomGain::Tools::PmtTableWriterAlg::finalize (   self)

Definition at line 62 of file Tools.py.

00063                       :
00064         self.info("finalizing")
00065         # Generate the PMT calibration table, and write to file
00066         # Step 1: initialize the table
00067         pmtCalibList = self.initializeCalibTable()
00068         self.info("I initialized the table") #tmp
00069         # Step 2: incorporate data using the current calibration statistics
00070         status = self.updateCalibration(pmtCalibList)
00071         if not status.isSuccess(): return status
00072         # Step 3: Print out the table
00073         self.writeCalibTable(pmtCalibList)
00074         status = DybPythonAlg.finalize(self)
00075         return status

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

Definition at line 76 of file Tools.py.

00077                                   :
00078         # Initialize table of PMT calibrations
00079         context = Context()
00080         context.SetSite(Site.kDayaBay)
00081         context.SetDetId(DetectorId.kAD1)
00082         timeStamp = TimeStamp(2011,10,20,10,10,10)
00083         context.SetTimeStamp(timeStamp)
00084         context.SetSimFlag(1)
00085         svcMode = ServiceMode(context, 0)  # Dummy ServiceMode
00086         adPmts = self.cableSvc.adPmtSensors(svcMode)
00087         poolPmts = self.cableSvc.poolPmtSensors(svcMode)
00088         adPmtCalibList = []
00089         poolPmtCalibList = []
00090         for adPmt in adPmts:
00091             pmtCalib = PmtCalibData()
00092             pmtCalib.m_pmtId = adPmt
00093             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00094             adPmtCalibList.append( pmtCalib )
00095         context1 = Context()
00096         context1.SetSite(Site.kDayaBay)
00097         context1.SetDetId(DetectorId.kAD2)
00098         timeStamp = TimeStamp(2011,10,20,10,10,10)
00099         context1.SetTimeStamp(timeStamp)
00100         context1.SetSimFlag(1)
00101         svcMode1 = ServiceMode(context1, 0)  # Dummy ServiceMode
00102         adPmts = self.cableSvc.adPmtSensors(svcMode1)
00103         for adPmt in adPmts:
00104             pmtCalib = PmtCalibData()
00105             pmtCalib.m_pmtId = adPmt
00106             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00107             adPmtCalibList.append( pmtCalib )
00108         context2 = Context()
00109         context2.SetSite(Site.kLingAo)
00110         context2.SetDetId(DetectorId.kAD1)
00111         timeStamp = TimeStamp(2011,10,20,10,10,10)
00112         context2.SetTimeStamp(timeStamp)
00113         context2.SetSimFlag(1)
00114         svcMode2 = ServiceMode(context2, 0)  # Dummy ServiceMode
00115         adPmts = self.cableSvc.adPmtSensors(svcMode2)
00116         for adPmt in adPmts:
00117             pmtCalib = PmtCalibData()
00118             pmtCalib.m_pmtId = adPmt
00119             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00120             adPmtCalibList.append( pmtCalib )
00121             context3 = Context()
00122         context3.SetSite(Site.kDayaBay)
00123         context3.SetDetId(DetectorId.kOWS)
00124         timeStamp = TimeStamp(2011,10,20,10,10,10)
00125         context3.SetTimeStamp(timeStamp)
00126         context3.SetSimFlag(1)
00127         svcMode3 = ServiceMode(context3, 0)  # Dummy ServiceMode
00128         wpPmts = self.cableSvc.poolPmtSensors(svcMode3)
00129         for wpPmt in wpPmts:
00130             pmtCalib = PmtCalibData()
00131             pmtCalib.m_pmtId = wpPmt
00132             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00133             poolPmtCalibList.append( pmtCalib )
00134         context4 = Context()
00135         context4.SetSite(Site.kDayaBay)
00136         context4.SetDetId(DetectorId.kIWS)
00137         timeStamp = TimeStamp(2011,10,20,10,10,10)
00138         context4.SetTimeStamp(timeStamp)
00139         context4.SetSimFlag(1)
00140         svcMode4 = ServiceMode(context4, 0)  # Dummy ServiceMode
00141         wpPmts = self.cableSvc.poolPmtSensors(svcMode4)
00142         for wpPmt in wpPmts:
00143             pmtCalib = PmtCalibData()
00144             pmtCalib.m_pmtId = wpPmt
00145             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00146             poolPmtCalibList.append( pmtCalib )
00147         context5 = Context()
00148         context5.SetSite(Site.kLingAo)
00149         context5.SetDetId(DetectorId.kOWS)
00150         timeStamp = TimeStamp(2011,10,20,10,10,10)
00151         context5.SetTimeStamp(timeStamp)
00152         context5.SetSimFlag(1)
00153         svcMode5 = ServiceMode(context5, 0)  # Dummy ServiceMode
00154         wpPmts = self.cableSvc.poolPmtSensors(svcMode5)
00155         for wpPmt in wpPmts:
00156             pmtCalib = PmtCalibData()
00157             pmtCalib.m_pmtId = wpPmt
00158             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00159             poolPmtCalibList.append( pmtCalib )
00160         context6 = Context()
00161         context6.SetSite(Site.kLingAo)
00162         context6.SetDetId(DetectorId.kIWS)
00163         timeStamp = TimeStamp(2011,10,20,10,10,10)
00164         context6.SetTimeStamp(timeStamp)
00165         context6.SetSimFlag(1)
00166         svcMode6 = ServiceMode(context6, 0)  # Dummy ServiceMode
00167         wpPmts = self.cableSvc.poolPmtSensors(svcMode6)
00168         for wpPmt in wpPmts:
00169             pmtCalib = PmtCalibData()
00170             pmtCalib.m_pmtId = wpPmt
00171             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00172             poolPmtCalibList.append( pmtCalib )
00173         context7 = Context()
00174         context7.SetSite(Site.kSAB)
00175         context7.SetDetId(DetectorId.kAD1)
00176         timeStamp = TimeStamp(2011,10,20,10,10,10)
00177         context7.SetTimeStamp(timeStamp)
00178         context7.SetSimFlag(1)
00179         svcMode7 = ServiceMode(context7, 0)  # Dummy ServiceMode
00180         adPmts = self.cableSvc.adPmtSensors(svcMode7)
00181         for adPmt in adPmts:
00182             pmtCalib = PmtCalibData()
00183             pmtCalib.m_pmtId = adPmt
00184             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00185             adPmtCalibList.append( pmtCalib )
00186         context8 = Context()
00187         context8.SetSite(Site.kSAB)
00188         context8.SetDetId(DetectorId.kAD2)
00189         timeStamp = TimeStamp(2011,10,20,10,10,10)
00190         context8.SetTimeStamp(timeStamp)
00191         context8.SetSimFlag(1)
00192         svcMode8 = ServiceMode(context8, 0)  # Dummy ServiceMode
00193         adPmts = self.cableSvc.adPmtSensors(svcMode8)
00194         for adPmt in adPmts:
00195             pmtCalib = PmtCalibData()
00196             pmtCalib.m_pmtId = adPmt
00197             if self.SetDefaultCalib: self.initializeCalib(pmtCalib)
00198             adPmtCalibList.append( pmtCalib )
00199         pmtCalibList = adPmtCalibList + poolPmtCalibList
00200         print "SUCCESS initialize"
00201         return pmtCalibList

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

Definition at line 202 of file Tools.py.

00203                                        :
00204         # Initialize using an approximate default calibration
00205         pmtCalib.m_status = PmtCalibData.kGood
00206         pmtCalib.m_speHigh = 20.0
00207         pmtCalib.m_sigmaSpeHigh = 0.0
00208         pmtCalib.m_speLow = 2.0
00209         pmtCalib.m_timeOffset = 0.0
00210         pmtCalib.m_timeSpread = 0.0
00211         pmtCalib.m_efficiency = 1.0
00212         pmtCalib.m_prePulseProb = 0.0
00213         pmtCalib.m_afterPulseProb = 0.0
00214         pmtCalib.m_darkRate = 0.0

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

Definition at line 215 of file Tools.py.

00216                                              :
00217         # Process the calibration statistics and update the
00218         # calibration parameters
00219         detDirs = self.statsSvc.getSubFolders(self.StatsPath)
00220         for detDir in detDirs:
00221             detector = Detector(detDir)
00222             if( detector.site() == Site.kUnknown
00223                 or detector.detectorId() == DetectorId.kUnknown ):
00224                 self.error("Unknown detector: "+detDir)
00225                 return FAILURE
00226             else:
00227                 self.info("Processing: "+detDir)
00228             # Find the PMT IDs that are in the current detector
00229             pmtCalibs = []
00230             for pmtCalib in pmtCalibList:
00231                 pmtId = pmtCalib.m_pmtId
00232                 if (pmtId.site() == detector.site()
00233                     and pmtId.detectorId() == detector.detectorId()):
00234                     pmtCalibs.append(pmtCalib)
00235             if detector.isAD():
00236                 status = self.updateAdCalibration(detector, pmtCalibs)
00237                 if not status.isSuccess(): return status
00238             elif detector.isWaterShield():
00239                 status = self.updateWaterShieldCalibration(detector, pmtCalibs)
00240                 if not status.isSuccess(): return status
00241         return SUCCESS

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

Definition at line 242 of file Tools.py.

00243                                                          :
00244         print "I am in updateAdCalibration" #tmp
00245         for pmtCalib in pmtCalibList:
00246             pmtId = pmtCalib.m_pmtId
00247             context = Context()
00248             context.SetSite(pmtId.site())
00249             context.SetDetId(pmtId.detectorId())
00250             timeStamp = TimeStamp(2011,10,20,10,10,10)
00251             context.SetTimeStamp(timeStamp)
00252             context.SetSimFlag(1)
00253             svcMode = ServiceMode(context, 0)
00254             feeid = self.cableSvc.feeChannelId(pmtId, svcMode)
00255             board = feeid.board()
00256             connector = feeid.connector()
00257             [adcMeanH, adcSigmaH,Chi2H] = self.getAdCalibHists(pmtId)
00258             if adcMeanH==None or adcSigmaH==None or Chi2H==None:
00259                 self.error("Failed to get calibration histograms for "
00260                            +detector.detName())
00261                 return FAILURE
00262             adcMean       = adcMeanH.GetBinContent(board*16+connector)            
00263             adcMeanUncert = adcMeanH.GetBinError(board*16+connector)
00264             #print adcMeanUncert
00265             adcReso       = adcSigmaH.GetBinContent(board*16+connector)
00266             adcResoUncert = adcSigmaH.GetBinError(board*16+connector)
00267             chi2 = Chi2H.GetBinContent(board*16+connector)
00268             if adcReso < 0:
00269                 adcReso = adcReso*-1
00270             # Update PMT status
00271             pmtCalib.m_status = PmtCalibData.kUnknown
00272             if( adcMean < 10.0 or adcMean > 50.0 or adcMeanUncert>1 or adcReso>15 or adcResoUncert>1 or chi2>3):
00273                 pmtCalib.m_status += PmtCalibData.kBadGain
00274                 print "Error: Bad Calibraion in ",detector.detName(),"Borad: ", board, "Connector: ", connector, ". Please Check it."
00275             # If no problems found, PMT is good
00276             if( pmtCalib.m_status == PmtCalibData.kUnknown ):
00277                 pmtCalib.m_status = PmtCalibData.kGood
00278             # Convert time offset to nanoseconds
00279             # wz
00280             pmtCalib.m_speHigh = adcMean
00281             pmtCalib.m_sigmaSpeHigh = adcReso
00282             # FIXME: need dedicated Low-gain calibration:
00283             # According to DocDB 5038, for dry run it is set to 19.5
00284             pmtCalib.m_speLow = adcMean / 19.5
00285         return SUCCESS

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

Definition at line 286 of file Tools.py.

00287                                     :
00288         # Return the calibration histograms for this PMT
00289         path = self.StatsPath + "/" + pmtId.detName()
00290         #print self.StatsPath
00291         
00292         adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00293         adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00294         Chi2H =  self.statsSvc.get(path + "/Chi2_1D")
00295         return [adcMeanH, adcSigmaH,Chi2H]
00296     

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

Definition at line 297 of file Tools.py.

00298                                                                   :
00299         print "I am in updateWPCalibration" #tmp By yuzy
00300         for pmtCalib in pmtCalibList:
00301             pmtId = pmtCalib.m_pmtId
00302             [adcMeanH, adcSigmaH, Chi2H] = self.getWPCalibHists(pmtId)    # only for gain now
00303             if adcMeanH==None or adcSigmaH==None or Chi2H==None:
00304                 self.error("Failed to get calibration histograms for "
00305                            +detector.detName())
00306                 return FAILURE
00307             context = Context()
00308             context.SetSite(pmtId.site())
00309             context.SetDetId(pmtId.detectorId())
00310             timeStamp = TimeStamp(2011,10,20,10,10,10)
00311             context.SetTimeStamp(timeStamp)
00312             context.SetSimFlag(1)
00313             svcMode = ServiceMode(context, 0)
00314             feeid = self.cableSvc.feeChannelId(pmtId, svcMode)
00315             board = feeid.board()
00316             connector = feeid.connector()
00317             adcMean       = adcMeanH.GetBinContent(board*16+connector)            
00318             adcMeanUncert = adcMeanH.GetBinError(board*16+connector)
00319             #print adcMeanUncert
00320             adcReso       = adcSigmaH.GetBinContent(board*16+connector)
00321             adcResoUncert = adcSigmaH.GetBinError(board*16+connector)
00322             chi2 = Chi2H.GetBinContent(board*16+connector)
00323             if adcReso < 0:
00324                 adcReso = adcReso*-1
00325             # Update PMT status
00326             pmtCalib.m_status = PmtCalibData.kUnknown
00327             if( adcMean < 10.0 or adcMean > 50.0 or adcMeanUncert>1 or adcReso>15 or adcResoUncert>1 or chi2>3):
00328                 pmtCalib.m_status += PmtCalibData.kBadGain
00329                 print "Error: Bad Calibraion in ",detector.detName(),"Borad: ", board, "Connector: ", connector, ". Please Check it."
00330             # If no problems found, PMT is good
00331             if( pmtCalib.m_status == PmtCalibData.kUnknown ):
00332                 pmtCalib.m_status = PmtCalibData.kGood
00333             # Convert time offset to nanoseconds
00334             # wangzhe: comment out temporarily
00335             # pmtCalib.m_efficiency = -math.log(1 - occupancy)
00336             # wz
00337             pmtCalib.m_speHigh = adcMean
00338             pmtCalib.m_sigmaSpeHigh = adcReso
00339             # FIXME: need dedicated Low-gain calibration:
00340             # According to DocDB 5038, for dry run it is set to 19.5
00341             pmtCalib.m_speLow = adcMean / 19.5
00342             # Update mean time        
00343                 
        return SUCCESS
def RandomGain::Tools::PmtTableWriterAlg::getWPCalibHists (   self,
  pmtId 
)

Definition at line 344 of file Tools.py.

00345                                     :
00346       path = self.StatsPath + "/" + pmtId.detName()
00347       adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00348       adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00349       Chi2H =  self.statsSvc.get(path + "/Chi2_1D")
      return [adcMeanH, adcSigmaH,Chi2H]
def RandomGain::Tools::PmtTableWriterAlg::calibTableLine (   self,
  pmtCalib 
)

Definition at line 350 of file Tools.py.

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

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

Definition at line 382 of file Tools.py.

00383                                            :
00384         # Write a calibration table using the list of pmt calibrations
00385         tableLines = []
00386         tableLines.append("# Table of Calibration constants for each channel\n")
00387         tableLines.append("# [pmtID] [description] [status] [speHigh] [sigmaSpe] [speLow] [timeOffset] [timeSpread] [efficiency] [prePulse] [afterPulse] [darkRate]\n")
00388 
00389         # sort them by id, otherwise it is out of control
00390         idCalib = {}
00391         for pmtCalib in pmtCalibList:
00392             idCalib[ pmtCalib.m_pmtId.fullPackedData() ] = pmtCalib
00393 
00394         for id in sorted( idCalib.keys() ):
00395             pmtCalib = idCalib[id]
00396             line = self.calibTableLine(pmtCalib)
00397             if not pmtCalib.m_sigmaSpeHigh == 0.0:
00398                 tableLines.append(line)
00399         outFile = open(self.OutputFileName,'w')
00400         outFile.writelines(tableLines)
00401         outFile.close()        
00402 
00403 
# 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 38 of file Tools.py.

Definition at line 38 of file Tools.py.

Definition at line 38 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:03:04 for RandomGain by doxygen 1.7.4