/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
DumpDqPmt::DumpPmt Class Reference

List of all members.

Public Member Functions

def __init__
def contextInfo
def fill_file_det_info
def generateMapTable
def getFileTimeInfo
def checkHist
def dumpPmt

Public Attributes

 thissite

Detailed Description

Get Rate from ROOT file

Definition at line 37 of file DumpDqPmt.py.


Constructor & Destructor Documentation

def DumpDqPmt::DumpPmt::__init__ (   self,
  inputFilename 
)

Definition at line 39 of file DumpDqPmt.py.

00040 :
    #def __init__(self):

Member Function Documentation

def DumpDqPmt::DumpPmt::contextInfo (   self)
Constructor
find out site info and alive detectors in this site

Definition at line 75 of file DumpDqPmt.py.

00076                          :
00077         """find out site info and alive detectors in this site"""
00078         inputFile = TFile(self.inputFilename, "READ")
00079         #determine which site this file comes from
00080         for site in self.allSites.keys():
00081             breakOrNot = 0
00082             for det in self.allDets.keys():
00083                 histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, site, det)
00084                 dir = inputFile.GetDirectory(histdir)
00085                 if dir:
00086                     self.thissite = site
00087                     breakOrNot = 1
00088                     break
00089             if breakOrNot == 1:
00090                 break
00091 
00092         assert self.thissite!=None, 'Error, KUP must have some problems, ODM file is empty!'
00093         #prepare the histogram path for this site
00094         for det,detId in self.allDets.items():
00095             if (self.thissite == 'SAB') and ( (det != 'AD1') or (det != 'AD2') ):
00096                 continue
00097             if (self.thissite != 'Far') and ( (det == 'AD3') or (det == 'AD4') ):
00098                 continue
00099             histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, self.thissite, det)
00100             dir = inputFile.GetDirectory(histdir)
00101             if dir:
00102                 self.dets[det] = detId
00103         return

def DumpDqPmt::DumpPmt::fill_file_det_info (   self,
  runNo,
  fileNo,
  site,
  dets 
)
fill file_det_info table

Definition at line 104 of file DumpDqPmt.py.

00105                                                            :
00106         """fill file_det_info table"""
00107         detset = ','.join(dets.keys())
00108         res = dq_db('SELECT * FROM file_det_info where runNo=%s AND fileNo=%s' % (runNo, fileNo))
00109         if len(res)==0:
00110             dq_db('INSERT INTO file_det_info(runNo, fileNo, site, det) VALUES ( %s, %s, "%s", ("%s") )' % (runNo, fileNo, site, detset))
00111         else:
00112             dq_db('UPDATE file_det_info SET site="%s", det=("%s") WHERE runNo=%s AND fileNo=%s' % (site, detset, runNo, fileNo))
00113         dq_db.close()
00114         return
        
def DumpDqPmt::DumpPmt::generateMapTable (   self,
  thissite,
  dets,
  timeStamp 
)
query offline db for the cable map of this site

Definition at line 115 of file DumpDqPmt.py.

00116                                                          :
00117         """query offline db for the cable map of this site"""
00118         rpt = GCableMap.Rpt()
00119         for detId in dets.values():
00120             rpt.ctx( site = thissite,
00121                      subsite = detId,
00122                      simflag = SimFlag.kData,
00123                      timestamp = timeStamp )
00124             rptlen = len(rpt)
00125             for idx in range(rptlen):
00126                 record = rpt[idx]
00127                 self.mapTable[ record.GetChannelId() ] = record.GetSensorId()
00128         return
        
def DumpDqPmt::DumpPmt::getFileTimeInfo (   self,
  runNo,
  fileNo 
)
Talk to offline DB and get the time range of the run

Definition at line 129 of file DumpDqPmt.py.

00130                                             :
00131         """Talk to offline DB and get the time range of the run"""
00132         try:
00133             con = MySQLdb.connect( host = dbhost,
00134                                    user = dbuser,
00135                                    passwd = dbpasswd,
00136                                    db = database )
00137             cursor = con.cursor()
00138             cursor.execute( "SELECT DaqRawDataFileInfoVld.timestart, DaqRawDataFileInfoVld.timeend FROM DaqRawDataFileInfoVld, DaqRawDataFileInfo WHERE DaqRawDataFileInfoVld.seqno = DaqRawDataFileInfo.seqno AND DaqRawDataFileInfo.runNo = %s AND DaqRawDataFileInfo.fileNo = %s" % (runNo, fileNo) )
00139             row = cursor.fetchone()
00140             if row:
00141                 print "get file time info successfully"
00142         except MySQLdb.Error,e:
00143             print "Error %d: %s" % (e.args[0], e.args[1])
00144             sys.exit(1)
00145 
00146         cursor.close()
00147         con.close()
00148         return row

def DumpDqPmt::DumpPmt::checkHist (   self,
  runNo,
  rootfile,
  channelId 
)

Definition at line 149 of file DumpDqPmt.py.

00150                                                    :
00151         board = channelId.board()
00152         connector = channelId.connector()
00153 
00154         # Use occupancy to determine PMT working status
00155         hoccpath = 'stats/diagnostics/run_%07d/detector_%s/channelHits' % ( runNo, channelId.detName() )
00156         hocc = rootfile.Get(hoccpath)
00157         occupancy = hocc.GetBinContent(board,connector)
00158         if(channelId.isAD()):
00159             if(board==18):
00160                 quality=1 #set 2inch PMT always as good
00161             else: #AD 8inch PMT
00162                 if(occupancy<0.001): # 0.001 to protect from FEE noise
00163                     quality=0 #HV off, dead PMT
00164                     #print "dead",channelId.detName(),board,connector
00165                 elif(occupancy<self.adOccLowerLimit):
00166                     quality=2 #HV turned down, e.g.,flahser test runs, HV=~1000V; dead PMTs may fall into this catagory due to FEE noise;
00167                     #print "low HV",channelId.detName(),board,connector,occupancy
00168                 elif(occupancy<self.adOccUpperLimit):
00169                     quality=1 #good range
00170                 else:
00171                     quality=3 #occupancy>upperLimit, noisy channels
00172                     #print "noisy channel",channelId.detName(),board,connector
00173         else: #WP PMT
00174             wpOccLowerLimit = self.wpOccLowerLimit[channelId.site()]
00175             wpOccUpperLimit = self.wpOccUpperLimit[channelId.site()]
00176             #print wpOccLowerLimit, wpOccUpperLimit
00177             if(occupancy<0.001): # 0.001 to protect from FEE noise
00178                 quality=0 #HV off, dead PMT
00179                 #print "dead",channelId.detName(),board,connector
00180             elif(occupancy<wpOccLowerLimit):
00181                 quality=2 #HV turned down, e.g.,flahser test runs, HV=~1000V; dead PMTs may fall into this catagory due to FEE noise;
00182                 #print "low HV",channelId.detName(),board,connector,occupancy
00183             elif(occupancy<wpOccUpperLimit):
00184                 quality=1 #good range
00185             else:
00186                 quality=3 #occupancy>upperLimit, noisy channels
00187                 #print "noisy channel",channelId.detName(),board,connector
00188 
00189         channeldir = 'stats/diagnostics/run_%07d/detector_%s/channel_board%02d_connector%02d' % ( runNo, channelId.detName(), board, connector )
00190         cdchanneldir = rootfile.GetDirectory(channeldir)
00191         if cdchanneldir:
00192             hadcpath = '%s/adcFine' % channeldir
00193             htdcpath = '%s/tdc' % channeldir 
00194             hforcedpath = '%s/tdcForced' % channeldir 
00195             hflasherpath = '%s/qFlasherPMT' % channeldir 
00196             hadc = rootfile.Get(hadcpath) 
00197             htdc = rootfile.Get(htdcpath)
00198             hforced = rootfile.Get(hforcedpath)
00199             hflasher = rootfile.Get(hflasherpath)
00200             adcMean = hadc.GetMean()
00201             adcRMS = hadc.GetRMS()
00202             tdcMean = htdc.GetMean()
00203             tdcRMS = htdc.GetRMS()
00204             if hforced:
00205                 dnCountsForced = hforced.GetEntries()
00206             else:
00207                 dnCountsForced = 0
00208             if hflasher:
00209                 flashingCounts = hflasher.GetEntries()
00210             else:
00211                 flashingCounts = 0
00212             histValue = [adcMean,adcRMS,tdcMean,tdcRMS,dnCountsForced,flashingCounts,quality]
00213         else:
00214             histValue = [0, 0, 0, 0, 0, 0, 0]
00215         return histValue

def DumpDqPmt::DumpPmt::dumpPmt (   self)
calculate rate

Definition at line 216 of file DumpDqPmt.py.

00217                      :
00218         """calculate rate"""
00219         runTime = self.getFileTimeInfo(self.runNo, self.fileNo)
00220         import calendar
00221         from datetime import timedelta
00222         starttime = calendar.timegm( runTime[0].timetuple() )
00223         
00224         # put timeend to be 3 days later
00225         #endtime = calendar.timegm( runTime[1].timetuple() )
00226         t = runTime[1] + timedelta(days=3)
00227         endtime = calendar.timegm( t.timetuple() )
00228        
00229         #get site and det info
00230         self.contextInfo()
00231         #fill file_det_info table
00232         self.fill_file_det_info(self.runNo, self.fileNo, self.thissite, self.dets)
00233         
00234         site = self.allSites[self.thissite] 
00235         #generate cable map
00236         self.generateMapTable(site, self.dets, TimeStamp(starttime))
00237 
00238         rootfile = TFile(self.inputFilename)
00239         tree = rootfile.Get(self.treepath)
00240 
00241         wrt = DqPmt.Wrt()
00242         cr = ContextRange( site,
00243                            SimFlag.kData|SimFlag.kMC,
00244                            TimeStamp(starttime),
00245                            TimeStamp(endtime) )
00246         wrt.ctx(contextrange=cr, versiondate=TimeStamp(0,0))
00247        
00248 
00249         for channelId, pmtId in self.mapTable.items():
00250             histValue = self.checkHist( int(self.runNo), rootfile, channelId )
00251             if histValue.count(0)==7: # HV-off for this channel, don't even look at RG output
00252                 record = DqPmt.Create( RunNo = int(self.runNo), 
00253                                        FileNo = int(self.fileNo),
00254                                        PmtId = pmtId,
00255                                        Status = 0,
00256                                        Chi2ndf = 0,
00257                                        Gain = 0,
00258                                        GainErr = 0,
00259                                        DarkRate = 0,
00260                                        DarkRateErr = 0,
00261                                        ElecNoiseRate = 0,
00262                                        ElecNoiseRateErr = 0,
00263                                        PreAdc = 0,
00264                                        PreAdcErr = 0,
00265                                        AdcMean = 0,   
00266                                        AdcRMS = 0,  
00267                                        TdcMean = 0,
00268                                        TdcRMS = 0,
00269                                        DNCountsForced = 0,
00270                                        FlashingCounts = 0,
00271                                        Quality = 0 ) 
00272                 wrt.Write(record)
00273             #find the corresponding pmt in DQTree
00274             else: # this channel is alive, check RG output
00275                 RGRes = tree.Query( "*","pmtID==%s" % pmtId.fullPackedData() )
00276                 if RGRes.GetRowCount()==1:
00277                     row = RGRes.Next()
00278                     #ncols = RGRes.GetFieldCount()
00279                     gain = float( row.GetField(0) );
00280                     gainerr = float( row.GetField(1) );
00281                     darkrate = float( row.GetField(2) );
00282                     darkrateerr = float( row.GetField(3) );
00283                     elecnoiserate = float( row.GetField(4) );
00284                     elecnoiserateerr = float( row.GetField(5) );
00285                     preadc = float( row.GetField(6) );
00286                     preadcerr = float( row.GetField(7) );
00287                     #pmtid = int( row.GetField(8) );
00288                     fitstatus = int( row.GetField(9) );
00289                     chisquare = float( row.GetField(10) );
00290                 else:
00291                     gain = 0
00292                     gainerr = 0
00293                     darkrate = 0
00294                     darkrateerr = 0
00295                     elecnoiserate = 0
00296                     elecnoiserateerr = 0
00297                     preadc = 0
00298                     preadcerr = 0
00299                     fitstatus = 0
00300                     chisquare = 0
00301                 
00302                 record = DqPmt.Create( RunNo = int(self.runNo),
00303                                        FileNo = int(self.fileNo),
00304                                        PmtId = pmtId,
00305                                        Status = fitstatus,
00306                                        Chi2ndf = chisquare,
00307                                        Gain = gain,
00308                                        GainErr = gainerr,
00309                                        DarkRate = darkrate,
00310                                        DarkRateErr = darkrateerr,
00311                                        ElecNoiseRate = elecnoiserate,
00312                                        ElecNoiseRateErr = elecnoiserateerr,
00313                                        PreAdc = preadc,
00314                                        PreAdcErr = preadcerr,
00315                                        AdcMean = histValue[0],  #DataQualityPmt Table structrure need to be 
00316                                        AdcRMS = histValue[1],   #updated to include the adc/tdc value in table
00317                                        TdcMean = histValue[2],
00318                                        TdcRMS = histValue[3],
00319                                        DNCountsForced = histValue[4],
00320                                        FlashingCounts = histValue[5],
00321                                        Quality = histValue[6] ) 
00322                                        #Quality code:(0,HV-off),(1,normal),(2,HV lower than working setting,say ~1000V),(3,noisy)
00323                 wrt.Write(record) 
00324         wrt.Close()
00325         return


Member Data Documentation

Definition at line 75 of file DumpDqPmt.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:54:23 for DQDump by doxygen 1.7.4