/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::FineGainTools::PmtTableWriterAlg Class Reference
Inheritance diagram for CalibParam::FineGainTools::PmtTableWriterAlg:
Inheritance graph
[legend]
Collaboration diagram for CalibParam::FineGainTools::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 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 28 of file FineGainTools.py.


Constructor & Destructor Documentation

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

Definition at line 30 of file FineGainTools.py.

00031                            :
00032         DybPythonAlg.__init__(self,name)
00033         # Properties
00034         self.StatsPath = "/file0/pmtCalibLeadingEdge"
00035         self.OutputTableName = "pmtCalibTable.txt"
00036         self.IsDryAd = False
00037         self.SetDefaultCalib = True
00038         self.SourcePosition = [0.,0.,0.]
00039         self.DetId=1
00040         self.site = 1 
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::FineGainTools::PmtTableWriterAlg::initialize (   self)

Definition at line 43 of file FineGainTools.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 CableSvc")
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('IPmtCalibSvc','DybPmtCalibSvc')
00063         if self.calibDataSvc == None:
00064             self.error("Failed to get PMT calib 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::FineGainTools::PmtTableWriterAlg::execute (   self)

Definition at line 71 of file FineGainTools.py.

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

Definition at line 75 of file FineGainTools.py.

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

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

Definition at line 89 of file FineGainTools.py.

00090                                   :
00091         # Initialize table of PMT calibrations
00092         # Initialize table of PMT calibrations
00093         detDirs = self.statsSvc.getSubFolders(self.StatsPath)
00094         chanIdList = []
00095        
00096         for detDir in detDirs:
00097             detector = Detector(detDir)
00098             context = Context()
00099             context.SetSite(detector.site())
00100             context.SetDetId(detector.detectorId())
00101             if not detector.site() == self.site:
00102                 continue
00103             if not detector.detectorId() == self.DetId:
00104                 continue
00105             path = self.StatsPath + "/" + detDir
00106             sec =   self.statsSvc.get(path + "/timeSec")
00107             nanosec = self.statsSvc.get(path + "/timeNanoSec")
00108             timeStamp = TimeStamp(sec.GetVal(),nanosec.GetVal())
00109             context.SetTimeStamp(timeStamp)
00110             simf = self.statsSvc.get(path + "/simFlag")
00111             context.SetSimFlag(simf.GetVal())
00112             svcMode = ServiceMode(context, 0)  # Dummy ServiceMode
00113             chanIds = self.cableSvc.feeChannelIds(svcMode)
00114            
00115             for chanId in chanIds:
00116                 fineCalib = FineGainCalibData()
00117                 fineCalib.m_channelId = chanId
00118                 if self.SetDefaultCalib:
00119                     self.initializeCalib(fineCalib)
00120                 chanIdList.append(fineCalib)
00121            
00122         return chanIdList

def CalibParam::FineGainTools::PmtTableWriterAlg::initializeCalib (   self,
  fineCalib 
)

Definition at line 123 of file FineGainTools.py.

00124                                         :
00125         # Initialize using an approximate default calibration
00126         fineCalib.m_status = FineGainCalibData.kGood
00127         fineCalib.m_speHigh = 20.0
00128         fineCalib.m_sigmaSpeHigh = 0.0
00129         fineCalib.m_speHighFitQual = 1.0
00130         fineCalib.m_speHighError = 1.0
    
def CalibParam::FineGainTools::PmtTableWriterAlg::updateCalibration (   self,
  chanCalibList 
)

Definition at line 131 of file FineGainTools.py.

00132                                               :
00133         # Process the calibration statistics and update the
00134         # calibration parameters
00135         detDirs = self.statsSvc.getSubFolders(self.StatsPath)
00136         for detDir in detDirs:
00137             detector = Detector(detDir)
00138             if not detector.site() == self.site:
00139                 continue
00140             if not detector.detectorId() == self.DetId:
00141                 continue
00142             if( detector.site() == Site.kUnknown
00143                 or detector.detectorId() == DetectorId.kUnknown ):
00144                 self.error("Unknown detector: "+detDir)
00145                 return FAILURE
00146             else:
00147                 self.info("Processing: "+detDir)
00148             # Find the channelIds that are in the current detector
00149             chanCalibs = []
00150             for fineCalib in chanCalibList:
00151                 chanId = fineCalib.m_channelId
00152                 if (chanId.site() == detector.site()
00153                     and chanId.detectorId() == detector.detectorId()):
00154                     chanCalibs.append(fineCalib)
00155             if detector.isAD():
00156                 status = self.updateAdCalibration(detector, chanCalibs)
00157                 if not status.isSuccess(): return status
00158             elif detector.isWaterShield():
00159                 print "********************************************"
00160                 print "Water pool calibration not implemented for FineGainTools!!!"
00161                 print "********************************************"
00162                 return FAILURE
00163 
00164         return SUCCESS

def CalibParam::FineGainTools::PmtTableWriterAlg::updateAdCalibration (   self,
  detector,
  chanCalibList 
)

Definition at line 165 of file FineGainTools.py.

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

def CalibParam::FineGainTools::PmtTableWriterAlg::getAdCalibHists (   self,
  channelId 
)

Definition at line 240 of file FineGainTools.py.

00241                                         :
00242         # Return the calibration histograms for this PMT
00243         path = self.StatsPath + "/" + channelId.detName()
00244 #       Chi2NDF = self.statsSvc.get(path + "/Chi2_1D")
00245         if self.StatsPath=="/file0/pmtCalibLeadingEdge":
00246             adcMeanH =   self.statsSvc.get(path + "/expAdcMean")
00247             adcSigmaH =  self.statsSvc.get(path + "/expAdcSigma")
00248             occuH = self.statsSvc.get(path +"/occupancyChannel")
00249             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00250         else:
00251             adcMeanH = self.statsSvc.get(path + "/gainChannel")
00252             adcSigmaH =  self.statsSvc.get(path + "/gainChannelSigma")
00253             occuH = self.statsSvc.get(path +"/occupancyChannel")
00254             Chi2H =  self.statsSvc.get(path +"/Chi2_1D")
00255         return [adcMeanH, adcSigmaH, occuH, Chi2H]
00256 
   
def CalibParam::FineGainTools::PmtTableWriterAlg::calibTableLine (   self,
  fineCalib 
)

Definition at line 257 of file FineGainTools.py.

00258                                        :
00259         # Write a line for the calibration table
00260       
00261         channelId = fineCalib.m_channelId
00262         
00263         line=("%d %2d %7.3f %5.3f %5.3f %5.3f \n"
00264               % (fineCalib.m_channelId.fullPackedData(),
00265                  fineCalib.m_status,
00266                  fineCalib.m_speHigh,
00267                  fineCalib.m_speHighError,
00268                  fineCalib.m_sigmaSpeHigh,
00269                  fineCalib.m_speHighFitQual 
00270                  )
00271               )
00272         return line

def CalibParam::FineGainTools::PmtTableWriterAlg::writeCalibTable (   self,
  chanCalibList 
)

Definition at line 273 of file FineGainTools.py.

00274                                             :
00275         # Write a calibration table using the list of pmt calibrations
00276         tableLines = []
00277         tableLines.append("# Table of Calibration constants for each channel\n")
00278         tableLines.append("# [channelID] [status] [speHigh] [speHighError] [sigmaSpe] [FitQuality]\n")
00279 
00280         # sort them by id, otherwise it is out of control
00281         idCalib = {}
00282         for fineCalib in chanCalibList:
00283             idCalib[ fineCalib.m_channelId.fullPackedData() ] = fineCalib
00284 
00285         for id in sorted( idCalib.keys() ):
00286             fineCalib = idCalib[id]
00287             line = self.calibTableLine(fineCalib)
00288             if not fineCalib.m_sigmaSpeHigh == 0.0: 
00289                 tableLines.append(line)
00290         outFile = open(self.OutputFileName,'w')
00291         outFile.writelines(tableLines)
00292         outFile.close()        
00293 
00294 
# Merge calibration tables

Member Data Documentation

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 30 of file FineGainTools.py.

Definition at line 43 of file FineGainTools.py.

Definition at line 43 of file FineGainTools.py.

Definition at line 43 of file FineGainTools.py.

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