/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
DumpDqPmtNew::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 38 of file DumpDqPmtNew.py.


Constructor & Destructor Documentation

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

Definition at line 40 of file DumpDqPmtNew.py.

00041 :
    #def __init__(self):

Member Function Documentation

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

Definition at line 76 of file DumpDqPmtNew.py.

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

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

Definition at line 105 of file DumpDqPmtNew.py.

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

Definition at line 116 of file DumpDqPmtNew.py.

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

Definition at line 131 of file DumpDqPmtNew.py.

00132                                             :
00133         """Talk to offline DB and get the time range of the run"""
00134         try:
00135             con = MySQLdb.connect( host = dbhost,
00136                                    user = dbuser,
00137                                    passwd = dbpasswd,
00138                                    db = database )
00139             cursor = con.cursor()
00140             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) )
00141             row = cursor.fetchone()
00142             if row:
00143                 print "get file time info successfully"
00144         except MySQLdb.Error,e:
00145             print "Error %d: %s" % (e.args[0], e.args[1])
00146             sys.exit(1)
00147 
00148         cursor.close()
00149         con.close()
00150         return row

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

Definition at line 151 of file DumpDqPmtNew.py.

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

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

Definition at line 218 of file DumpDqPmtNew.py.

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


Member Data Documentation

Definition at line 76 of file DumpDqPmtNew.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