00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 from DybPython.DybPythonAlg import DybPythonAlg
00011 from GaudiPython import SUCCESS, FAILURE
00012 from GaudiPython import gbl
00013 from DybPython.Util import irange
00014 import GaudiKernel.SystemOfUnits as units
00015
00016
00017 TH1F = gbl.TH1F
00018 TH1 = gbl.TH1
00019 TimeStamp = gbl.TimeStamp
00020 FeeChannelId = gbl.DayaBay.FeeChannelId
00021 Detector = gbl.DayaBay.Detector
00022
00023
00024 gbl.gStyle.SetHistLineColor(4)
00025 gbl.gStyle.SetHistLineWidth(2)
00026 gbl.gStyle.SetMarkerColor(4)
00027 gbl.gStyle.SetMarkerStyle(8)
00028 gbl.gStyle.SetPalette(1)
00029
00030
00031 class TesterAlg(DybPythonAlg):
00032 "Tester Algorithm"
00033 def __init__(self,name):
00034 DybPythonAlg.__init__(self,name)
00035 return
00036
00037 def initialize(self):
00038 status = DybPythonAlg.initialize(self)
00039 if status.isFailure(): return status
00040 self.info("initializing")
00041
00042 self.runNumber=None
00043 self.lastReadoutTime = None
00044 self.activeChannelIds = []
00045 self.activeDetectors = []
00046
00047 return SUCCESS
00048
00049 def execute(self):
00050 self.info("executing")
00051
00052
00053 evt = self.evtSvc()
00054 readoutHdr = evt["/Event/Readout/ReadoutHeader"]
00055 if readoutHdr == None:
00056 self.error("Failed to get current readout header")
00057 return FAILURE
00058
00059 readout = readoutHdr.readout()
00060 if readout == None:
00061 self.error("Failed to get readout from header")
00062 return FAILURE
00063
00064 if not self.runNumber:
00065
00066 self.runNumber = readout.rawEvent().runNumber()
00067
00068 detector = readout.detector()
00069 if self.isNewDetector( detector ):
00070 self.prepareDetectorHistograms( detector )
00071 runPath = "/file1/diagnostics/run_%06d" % self.runNumber
00072 detectorName = readout.detector().detName()
00073 detectorPath = runPath + "/detector_" + detectorName
00074
00075 nChannels = 0
00076 for channelPair in readout.channelReadout():
00077 channel = channelPair.second
00078 channelId = channel.channelId()
00079 if self.isNewChannel( channelId ):
00080 self.prepareChannelHistograms( channelId )
00081
00082
00083 path = "%s/channel_board%02d_connector%02d" % (detectorPath,
00084 channelId.board(),
00085 channelId.connector())
00086 self.debug("Processing channel with path: "+path)
00087
00088 for hitIdx in range(channel.size()):
00089 self.stats[path + "/tdc"].Fill( channel.tdc(hitIdx) )
00090 self.stats[path + "/adc"].Fill( channel.adc(hitIdx) )
00091
00092 channelIndex = channelId.board()*16 + channelId.connector()
00093 self.stats[detectorPath + "/hitRate"].Fill( channelIndex )
00094 nChannels += 1
00095
00096
00097
00098 self.stats[detectorPath + "/nChannels"].Fill( nChannels )
00099
00100 self.stats[detectorPath + "/triggerType"].Fill( readout.triggerType() )
00101
00102 if self.lastReadoutTime != None:
00103
00104 dT_trigger = TimeStamp( readout.triggerTime() )
00105 dT_trigger.Subtract( self.lastReadoutTime )
00106 self.debug("Dt Readout: "+str(dT_trigger.GetSeconds()))
00107 self.stats[detectorPath + "/dT_trigger"].Fill(
00108 dT_trigger.GetSeconds() )
00109
00110
00111 self.lastReadoutTime = TimeStamp(readout.triggerTime())
00112 self.debug("done execute")
00113 return SUCCESS
00114
00115 def finalize(self):
00116 self.info("finalizing")
00117
00118 for channelInt in self.activeChannelIds:
00119 channelId = FeeChannelId( channelInt )
00120 runPath = "/file1/diagnostics/run_%06d" % self.runNumber
00121 detectorName = channelId.detName()
00122 detectorPath = runPath + "/detector_" + detectorName
00123 path = "%s/channel_board%02d_connector%02d" % (detectorPath,
00124 channelId.board(),
00125 channelId.connector())
00126 channelIndex = channelId.board()*16 + channelId.connector()
00127
00128 meanAdc = self.stats[path + "/adc"].GetMean()
00129 rmsAdc = self.stats[path + "/adc"].GetRMS()
00130 self.stats[detectorPath + "/meanAdc"].Fill(channelIndex, meanAdc)
00131 self.stats[detectorPath + "/rmsAdc"].Fill(channelIndex, rmsAdc)
00132 for detectorInt in self.activeDetectors:
00133
00134 detector = Detector( detectorInt )
00135 runPath = "/file1/diagnostics/run_%06d" % self.runNumber
00136 detectorPath = runPath + "/detector_" + detector.detName()
00137 nReadouts = self.stats[detectorPath + "/nChannels"].GetEntries()
00138 self.stats[detectorPath + "/hitRate"].Scale( 1 / nReadouts )
00139 self.stats[detectorPath + "/hitRate"].SetBit( TH1.kIsAverage )
00140
00141 status = DybPythonAlg.finalize(self)
00142 return status
00143
00144 def isNewChannel(self, channelId):
00145
00146 if channelId.fullPackedData() in self.activeChannelIds:
00147 return False
00148 return True
00149
00150 def isNewDetector(self, detector):
00151
00152 if detector.fullPackedData() in self.activeDetectors:
00153 return False
00154 return True
00155
00156 def prepareDetectorHistograms(self, detector):
00157
00158 path = self.runPath() + "/detector_" + detector.detName()
00159 self.debug("Making histograms at path: "+path)
00160
00161 self.stats[path + "/nChannels"] = TH1F("nChannels",
00162 "Number of Hit Channels",
00163 250,0,250)
00164 hist = self.stats[path + "/nChannels"]
00165 hist.GetXaxis().SetTitle("Number of Hit Channels")
00166 hist.GetYaxis().SetTitle("Number of Triggered Readouts")
00167
00168 self.stats[path + "/triggerType"] = TH1F("triggerType",
00169 "Trigger Type",
00170 4096,0,4096)
00171 hist = self.stats[path + "/triggerType"]
00172 hist.GetXaxis().SetTitle("Trigger Type")
00173 hist.GetYaxis().SetTitle("Number of Triggered Readouts")
00174
00175 self.stats[path + "/dT_trigger"] = TH1F("dT_trigger",
00176 "Time between triggers [s]",
00177 1000,0,1)
00178 hist = self.stats[path + "/dT_trigger"]
00179 hist.GetXaxis().SetTitle("Time Between Triggered Readouts [s]")
00180 hist.GetYaxis().SetTitle("Number of Triggered Readouts / 1 ms")
00181
00182
00183 self.stats[path + "/meanAdc"] = TH1F("meanAdc",
00184 "Mean ADC by channel",
00185 300,0,300)
00186 hist = self.stats[path + "/meanAdc"]
00187 hist.GetXaxis().SetTitle("Channel Index (Board*16 + Connector)")
00188 hist.GetYaxis().SetTitle("Mean ADC value")
00189
00190 self.stats[path + "/rmsAdc"] = TH1F("rmsAdc",
00191 "RMS ADC by channel (board*16 + connector)",
00192 300,0,300)
00193 hist = self.stats[path + "/rmsAdc"]
00194 hist.GetXaxis().SetTitle("Channel Index (Board*16 + Connector)")
00195 hist.GetYaxis().SetTitle("RMS of ADC values")
00196
00197 self.stats[path + "/hitRate"] = TH1F("hitRate",
00198 "Hit Rate by channel",
00199 300,0,300)
00200 hist = self.stats[path + "/hitRate"]
00201 hist.GetXaxis().SetTitle("Channel Index (Board*16 + Connector)")
00202 hist.GetYaxis().SetTitle("Number of Hits / Number of Triggered Readouts")
00203 self.activeDetectors.append( detector.fullPackedData() )
00204 return
00205
00206 def prepareChannelHistograms(self, channelId):
00207
00208 path = "%s/detector_%s/channel_board%02d_connector%02d" % (
00209 self.runPath(),
00210 channelId.detName(),
00211 channelId.board(),
00212 channelId.connector())
00213 self.debug("Making histograms at path: "+path)
00214
00215 self.stats[path + "/tdc"] = TH1F("tdc",
00216 "TDC Values",
00217 4096,0,4096)
00218 hist = self.stats[path + "/tdc"]
00219 hist.GetXaxis().SetTitle("TDC value")
00220 hist.GetYaxis().SetTitle("Number of TDCs")
00221
00222 self.stats[path + "/adc"] = TH1F("adc",
00223 "ADC Values",
00224 4096,0,4096)
00225 hist = self.stats[path + "/adc"]
00226 hist.GetXaxis().SetTitle("ADC value")
00227 hist.GetYaxis().SetTitle("Number of ADCs")
00228 self.activeChannelIds.append( channelId.fullPackedData() )
00229 return
00230
00231 def runPath(self):
00232
00233 return "/file1/diagnostics/run_%06d" % self.runNumber
00234
00235
00236
00237 def configure(argv=[]):
00238 return
00239
00240 def run(app):
00241 '''
00242 Generate test output for run diagnostics
00243 '''
00244 myAlg = TesterAlg("MyTesterAlg")
00245 app.addAlgorithm(myAlg)
00246 pass
00247