/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
DumpDqDetectorNew::DumpDetector Class Reference

List of all members.

Public Member Functions

def __init__
def getEntries
def getFileTimeInfo
def dumpDetector

Public Attributes

 thissite

Detailed Description

Get counts from ROOT file

Definition at line 29 of file DumpDqDetectorNew.py.


Constructor & Destructor Documentation

def DumpDqDetectorNew::DumpDetector::__init__ (   self,
  inputFilename 
)

Definition at line 31 of file DumpDqDetectorNew.py.

00032 :
    #def __init__(self):

Member Function Documentation

def DumpDqDetectorNew::DumpDetector::getEntries (   self)
Constructor

Definition at line 55 of file DumpDqDetectorNew.py.

00056                         :
00057         inputFile = TFile(self.inputFilename, "READ")
00058         #determine which site this file comes from
00059         for site in self.site:
00060             breakOrNot = 0
00061             for det in self.det:
00062                 histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, site, det)
00063                 dir = inputFile.GetDirectory(histdir)
00064                 if dir:
00065                     self.thissite = site
00066                     breakOrNot = 1
00067                     break
00068             if breakOrNot == 1:
00069                 break
00070 
00071         assert self.thissite!=None, 'Error, KUP must have some problems, ODM file is empty!'
00072         #prepare the histogram path for this site
00073         for det in self.det:
00074             if (self.thissite != 'Far') and ( (det == 'AD3') or (det=='AD4') ):
00075                 continue
00076             histdir = "stats/diagnostics/run_%s/detector_%s%s" % (self.runNo, self.thissite, det)
00077             self.histdir.append(histdir)
00078 
00079         #loop over different detectors, get the available histograms for each detector
00080         for histdir in self.histdir:
00081             dir = inputFile.GetDirectory( histdir )
00082             #if path does not exist, continue
00083             if not dir:
00084                 continue
00085             self.entries[ histdir.split('/')[-1] ] = {}
00086             #loop different histgrams
00087             for histname in self.histname:
00088                 hist = dir.Get( histname )
00089                 #if hist not exist, continue
00090                 #print histdir+'/'+histname
00091                 if not hist:
00092                     continue
00093                 #print histdir+'/'+histname
00094                 if histname=='triggerRate':
00095                     eventtime = hist.GetBinLowEdge(1) # get event trigger time to prevent trigger time shift issue
00096                     self.entries[ (histdir.split('/'))[-1] ][histname + '_time'] = eventtime
00097 
00098                 if histname=='triggerBlocked':
00099                     nBins = hist.GetNbinsX()
00100                     nBlocked = hist.Integral(1,nBins)
00101                     self.entries[ (histdir.split('/'))[-1] ][histname] = nBlocked 
00102                 #elif histname=='ratioQmaxQtotVsTrms': 
00103                 #    #Doc 6959
00104                 #    #max charge ratio > 0.3
00105                 #    minYBin = hist.GetYaxis().FindBin(0.3)
00106                 #    #Trms > 50
00107                 #    minXBin = hist.GetXaxis().FindBin(50)
00108                 #    maxYBin = hist.GetNbinsY()
00109                 #    maxXBin = hist.GetNbinsX()
00110                 #    nNonFlasher = hist.Integral(1,minXBin,1,minYBin)
00111                 #    nTotal = hist.Integral(1,maxXBin,1,maxYBin)
00112                 #    nFlasher = nTotal - nNonFlasher
00113                 #    self.entries[ (histdir.split('/'))[-1] ][histname] = nFlasher 
00114                 #ues ellipse to identify flasher events
00115                 elif histname=='logFlasherEllipse':
00116                     nBins = hist.GetNbinsX();
00117                     minBin = hist.FindBin(0)
00118                     nFlasher = hist.Integral(minBin,nBins+1)
00119                     self.entries[ (histdir.split('/'))[-1] ][histname] = nFlasher
00120                     #print "#######nFlasher#####",nFlasher
00121                 elif histname=='maxPmtChargeVsMuonCharge':
00122                     #max charge ratio > 0.7
00123                     minYBin = hist.GetYaxis().FindBin(0.7)
00124                     #total charge > 30 PE
00125                     minXBin = hist.GetXaxis().FindBin( math.log10(30) )
00126                     maxYBin = hist.GetNbinsY()
00127                     maxXBin = hist.GetNbinsX()
00128                     nFlasher = hist.Integral(minXBin, maxXBin, minYBin, maxYBin)
00129                     self.entries[ (histdir.split('/'))[-1] ][histname] = nFlasher 
00130                 elif histname=='logAdCharge':
00131                     minAdMuEnergyBin = hist.FindBin( math.log10(20*170) )  #170pe/MeV
00132                     maxBin = hist.GetNbinsX()
00133                     self.entries[ (histdir.split('/'))[-1] ][histname] = hist.Integral(minAdMuEnergyBin, maxBin) 
00134                 elif histname=='spallEnergyNCaptureGd':
00135                     #spn energy and sigma
00136                     self.entries[ (histdir.split('/'))[-1] ][histname] = hist.GetMean() 
00137                     self.entries[ (histdir.split('/'))[-1] ][histname+"Sigma"] = hist.GetRMS() 
00138                 elif histname=='adEnergy_FlasherCut_AdSimple':
00139                     func = TF1("func","[0]*exp( -(x-[1])*(x-[1])/2/[2]/[2] )+[3]*(x-[4])*(x-[4])+[5]",0,4)
00140                     #fit K40
00141                     func.SetParameters(50,1.5,0.1,-20,-1,1);
00142                     func.SetParLimits(3,-10000,0)
00143                     hist.Fit("func","","",1.3,1.8)
00144                     if func:
00145                         if func.GetNDF()!=0:
00146                             chi2 = func.GetChisquare()/func.GetNDF() # chi2/ndf
00147                             if(chi2<1.5 and chi2>0.5):
00148                                 k40Energy = func.GetParameter(1)
00149                                 k40EnergyErr = func.GetParError(1)
00150                                 self.entries[ (histdir.split('/'))[-1] ][histname+'_k40Energy'] = k40Energy
00151                                 self.entries[ (histdir.split('/'))[-1] ][histname+'_k40EnergyErr'] = k40EnergyErr
00152                                 #print "#####K40######",chi2
00153                     #fit Tl208
00154                     func.SetParameters(50,2.8,0.1,-1,-1,1);
00155                     hist.Fit("func","","",2.4,3.3)
00156                     if func:
00157                         if func.GetNDF()!=0:
00158                             chi2 = func.GetChisquare()/func.GetNDF() # chi2/ndf
00159                             if(chi2<1.5 and chi2>0.5):
00160                                 tl208Energy = func.GetParameter(1)
00161                                 tl208EnergyErr = func.GetParError(1)
00162                                 self.entries[ (histdir.split('/'))[-1] ][histname+'_tl208Energy'] = tl208Energy
00163                                 self.entries[ (histdir.split('/'))[-1] ][histname+'_tl208EnergyErr'] = tl208EnergyErr
00164                                 #print "#######tl208#######",chi2
00165                     #positron/nentron like event
00166                     pLowBin = hist.FindBin(0.7)
00167                     nLowBin = hist.FindBin(6)
00168                     maxBin = hist.GetNbinsX() # adEnergy_FlasherCut_AdSimple goes maximum to 12MeV
00169                     pLikeCounts = hist.Integral(pLowBin,maxBin)
00170                     nLikeCounts = hist.Integral(nLowBin,maxBin)
00171                     self.entries[ (histdir.split('/'))[-1] ][histname+'_pLikeCounts'] = pLikeCounts
00172                     self.entries[ (histdir.split('/'))[-1] ][histname+'_nLikeCounts'] = nLikeCounts
00173                 elif histname=='dtTrigger':
00174                     dtNegativeEntries = hist.GetBinContent(0) # dt<-12.5ns 
00175                     self.entries[ (histdir.split('/'))[-1] ][histname] = dtNegativeEntries
00176                 elif histname=='logDtTrigger':
00177                     minBin = hist.FindBin( math.log10(5) )
00178                     nBins = hist.GetNbinsX()
00179                     dtLargeGapEntries = hist.Integral(minBin,nBins+1)
00180                     self.entries[ (histdir.split('/'))[-1] ][histname] = dtLargeGapEntries
00181                 elif histname=='triggerBitsFlasherCut':
00182                     nNHit = hist.GetBinContent(9) #NHit bit
00183                     nESum = hist.GetBinContent(13) #ESum bit
00184                     self.entries[ (histdir.split('/'))[-1] ][histname+'_nNHit'] = nNHit
00185                     self.entries[ (histdir.split('/'))[-1] ][histname+'_nESum'] = nESum
00186                     #print "####trigger variable####",nNHit,nESum
00187                 elif histname=='nChannels':
00188                     if(histdir.split('/')[-1][-3:]=='IWS' or
00189                        histdir.split('/')[-1][-3:]=='OWS'): #nChannels hist only used for ***WP*** to calculate muon rate, AD's muon rate from logAdCharge hist
00190                         nBins = hist.GetNbinsX()
00191                         minBin = hist.FindBin(12)
00192                         wpMuonEntries = hist.Integral(minBin,nBins)
00193                         self.entries[ (histdir.split('/'))[-1] ][histname] = wpMuonEntries
00194                 else:
00195                     self.entries[ (histdir.split('/'))[-1] ][histname] = hist.GetEntries()
00196         return

def DumpDqDetectorNew::DumpDetector::getFileTimeInfo (   self,
  runNo,
  fileNo 
)
Talk to offline DB and get the time range of the run

Definition at line 197 of file DumpDqDetectorNew.py.

00198                                             :
00199         """Talk to offline DB and get the time range of the run"""
00200         try:
00201             con = MySQLdb.connect( host = dbhost,
00202                                    user = dbuser,
00203                                    passwd = dbpasswd,
00204                                    db = database )
00205             cursor = con.cursor()
00206             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) )
00207             row = cursor.fetchone()
00208             #if row:
00209             #    print "get file time info successfully"
00210         except MySQLdb.Error,e:
00211             print "Error %d: %s" % (e.args[0], e.args[1])
00212             sys.exit(1)
00213 
00214         cursor.close()
00215         con.close()
00216         return row
        
def DumpDqDetectorNew::DumpDetector::dumpDetector (   self)
calculate rate

Definition at line 217 of file DumpDqDetectorNew.py.

00218                           :
00219         """calculate rate"""
00220         #could use offline DB to get the precise run time range
00221         #or get a rough time range from historgram triggerRate
00222         runTime = self.getFileTimeInfo(self.runNo, self.fileNo)
00223         import calendar
00224         starttime = calendar.timegm( runTime[0].timetuple() )
00225         endtime = calendar.timegm( runTime[1].timetuple() )
00226         timeRange = endtime - starttime
00227         self.getEntries()
00228         #print "get entries from summary root file successfully"
00229         wrt = DqDetector.Wrt()
00230         if self.thissite == 'DayaBay':
00231             sitectx = Site.kDayaBay
00232         if self.thissite == 'LingAo':
00233             sitectx = Site.kLingAo
00234         if self.thissite == 'Far':
00235             sitectx = Site.kFar 
00236         cr = ContextRange( sitectx,
00237                            SimFlag.kData|SimFlag.kMC,
00238                            TimeStamp(starttime),
00239                            TimeStamp(endtime) )
00240         wrt.ctx(contextrange=cr, versiondate=TimeStamp(0,0))
00241         #every detector has an entry
00242         for det,hists in self.entries.items():
00243             detId = self.det.index(det[-3:]) + 1 
00244             triggerCounts = -1
00245             flasherCounts = -1
00246             muonCounts = -1
00247             ibdCounts = -1
00248             spnCounts = -1
00249             blockTrigCounts = -1
00250             spnEnergy = -1
00251             spnEnergySigma = -1
00252             k40Energy = -1
00253             k40EnergyErr = -1
00254             tl208Energy = -1
00255             tl208EnergyErr = -1
00256             pLikeCounts = -1
00257             nLikeCounts = -1
00258             dtNegCounts = -1
00259             dtLargeGapCounts = -1
00260             nHitCountsGt = -1
00261             eSumCountsGt = -1
00262 
00263             isTimeShift = abs(hists['triggerRate_time'] - starttime) > 300 # time shift > 5 min, bad!
00264             
00265             #print det, hists
00266             for histname,entries in hists.items():
00267             #element of self.entries[det] is loop over all the hist in self.histname
00268                 if histname == 'triggerRate':
00269                     triggerCounts = entries
00270                 elif (histname == 'maxPmtChargeVsMuonCharge' or 
00271                     histname == 'logFlasherEllipse'):
00272                     flasherCounts = entries
00273                 elif (histname == 'logAdCharge' or
00274                     histname == 'nChannels'): #muonCounts, AD from logAdCharge, WP from nChannels
00275                     muonCounts = entries
00276                 elif histname == 'ibdCandidateTime':
00277                     ibdCounts = entries
00278                 elif histname == 'spallTimeNCaptureGd':
00279                     spnCounts = entries
00280                 elif histname == 'triggerBlocked':
00281                     blockTrigCounts = entries
00282                 elif histname == 'spallEnergyNCaptureGd':
00283                     spnEnergy = entries
00284                 elif histname == 'spallEnergyNCaptureGdSigma':
00285                     spnEnergySigma = entries
00286                 elif histname == 'adEnergy_FlasherCut_AdSimple_k40Energy':
00287                     k40Energy = entries
00288                 elif histname == 'adEnergy_FlasherCut_AdSimple_k40EnergyErr':
00289                     k40EnergyErr = entries
00290                 elif histname == 'adEnergy_FlasherCut_AdSimple_tl208Energy':
00291                     tl208Energy = entries
00292                 elif histname == 'adEnergy_FlasherCut_AdSimple_tl208EnergyErr':
00293                     tl208EnergyErr = entries
00294                 elif histname == 'adEnergy_FlasherCut_AdSimple_pLikeCounts':
00295                     pLikeCounts = entries
00296                 elif histname == 'adEnergy_FlasherCut_AdSimple_nLikeCounts':
00297                     nLikeCounts = entries
00298                 elif histname == 'dtTrigger':
00299                     dtNegCounts = entries
00300                 elif histname == 'logDtTrigger':
00301                     dtLargeGapCounts = -999 if isTimeShift else entries # time shift is indicated by value -999
00302                 elif histname == 'triggerBitsFlasherCut_nNHit':
00303                     nHitCountsGt = entries
00304                 elif histname == 'triggerBitsFlasherCut_nESum':
00305                     eSumCountsGt = entries
00306 
00307             #print detId,triggerRate,blockTriggerFrac,flasherRate 
00308             record = DqDetector.Create( RunNo = int( self.runNo ),
00309                                         FileNo = int( self.fileNo ),
00310                                         DetectorId = detId,
00311                                         TriggerCounts = triggerCounts,
00312                                         FlasherCounts = flasherCounts,
00313                                         MuonCounts = muonCounts,  
00314                                         IbdCounts = ibdCounts,
00315                                         SpnCounts = spnCounts, 
00316                                         BlockTrigCounts = blockTrigCounts,
00317                                         SpnEnergy = spnEnergy,
00318                                         SpnEnergySigma = spnEnergySigma,
00319                                         K40Energy = k40Energy,
00320                                         K40EnergyErr = k40EnergyErr,
00321                                         Tl208Energy = tl208Energy,
00322                                         Tl208EnergyErr = tl208EnergyErr,
00323                                         PLikeCounts = pLikeCounts,
00324                                         NLikeCounts = nLikeCounts,
00325                                         DtNegCounts = dtNegCounts,
00326                                         DtLargeGapCounts = dtLargeGapCounts,
00327                                         NHitCountsGt = nHitCountsGt,
00328                                         ESumCountsGt = eSumCountsGt )
00329             wrt.Write(record)
00330         wrt.Close()
        

Member Data Documentation

Definition at line 55 of file DumpDqDetectorNew.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