/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #!/usr/bin/env python 00002 # 00003 # Example script for printing raw data to the terminal, and makes one histogram 00004 # 00005 # This script contains comments describing the contents of the raw data. 00006 # 00007 # Usage: 00008 # nuwa.py -A None -n -1 -m"Quickstart.PrintRawData" daq.NoTag.....data 00009 # 00010 # 00011 00012 # Load DybPython 00013 from DybPython.DybPythonAlg import DybPythonAlg 00014 from GaudiPython import SUCCESS, FAILURE 00015 from GaudiPython import gbl 00016 from DybPython.Util import irange 00017 import GaudiKernel.SystemOfUnits as units 00018 00019 # Make shortcuts to any ROOT classes you want to use 00020 TH1F = gbl.TH1F 00021 TimeStamp = gbl.TimeStamp 00022 FeeChannelId = gbl.DayaBay.FeeChannelId 00023 Detector = gbl.DayaBay.Detector 00024 00025 #change default ROOT style 00026 gbl.gStyle.SetHistLineColor(4) 00027 gbl.gStyle.SetHistLineWidth(2) 00028 gbl.gStyle.SetMarkerColor(4) 00029 gbl.gStyle.SetMarkerStyle(8) 00030 gbl.gStyle.SetPalette(1) 00031 00032 # Make your algorithm 00033 class PrintRawDataAlg(DybPythonAlg): 00034 "Print Raw Data Example Algorithm" 00035 def __init__(self,name): 00036 DybPythonAlg.__init__(self,name) 00037 return 00038 00039 def initialize(self): 00040 status = DybPythonAlg.initialize(self) 00041 if status.isFailure(): return status 00042 self.info("initializing") 00043 00044 # Example histogram: Total raw ADC sum for each trigger 00045 self.stats["/file1/myhists/adcSum"] = TH1F("adcSum", 00046 "Sum of raw ADC values for each trigger", 00047 2000,0,20000) 00048 return SUCCESS 00049 00050 def execute(self): 00051 self.info("executing") 00052 00053 evt = self.evtSvc() 00054 00055 # Access the Readout Header. This is a container for the readout data 00056 readoutHdr = evt["/Event/Readout/ReadoutHeader"] 00057 if readoutHdr == None: 00058 self.error("Failed to get current readout header") 00059 return FAILURE 00060 00061 # Access the DaqCrate Readout. This is the data from one trigger. 00062 daqCrate = readoutHdr.daqCrate() 00063 if daqCrate == None: 00064 self.info("No daqCrate readout this cycle") 00065 return SUCCESS 00066 00067 # Get the detector ID for this trigger 00068 detector = daqCrate.detector() 00069 self.info("Detector Name: "+detector.detName()) 00070 00071 # Trigger Type: This is an integer of the type for this trigger 00072 self.info("Trigger Type: "+str( daqCrate.triggerType() )) 00073 # Event Number: A count of the trigger, according to the DAQ 00074 self.info("Event Number: "+str( daqCrate.eventNumber() )) 00075 00076 # Trigger Time: Absolute time of trigger for this raw data 00077 triggerTime = daqCrate.triggerTime() 00078 # Trigger Time [Seconds]: Trigger time in seconds from some day in 1990 00079 self.info("Trigger Time [Seconds part]: " 00080 +str( triggerTime.GetSec() )) 00081 # Trigger Time [Nanoseconds]: Nanoseconds part of trigger time 00082 self.info("Trigger Time [Nanoseconds part]: " 00083 +str( triggerTime.GetNanoSec() )) 00084 # Full Trigger Time: Seconds + nanoseconds 00085 # Warning: When you add this together, it will lose some precision. 00086 self.info("Full Trigger Time: " 00087 +str( triggerTime.GetSec() 00088 +triggerTime.GetNanoSec()*1.0e-9 )) 00089 00090 readout = daqCrate.asPmtCrate() 00091 if readout == None: 00092 self.info("No pmt readout this cycle") 00093 return SUCCESS 00094 00095 # Loop over each channel data in this trigger 00096 adcSum = 0 00097 for channel in readout.channelReadouts(): 00098 channelId = channel.channelId() 00099 00100 # The channel ID contains the detector ID, electronics board number, 00101 # and the connector number on the board. 00102 self.info("Channel ID:" 00103 +" detector=" 00104 +channelId.detName() 00105 +" board=" 00106 +str(channelId.board()) 00107 +" connector=" 00108 +str(channelId.connector())) 00109 00110 # Loop over hits for this channel 00111 for hitIdx in range( channel.hitCount() ): 00112 # TDC data for this channel 00113 # 00114 # The TDC is an integer count of the time between the time 00115 # the PMT pulse arrived at the channel, and the time the 00116 # trigger reads out the data. Therefore, a larger TDC = 00117 # earlier time. One TDC count ~= 1.5625 nanoseconds. 00118 # 00119 tdc = channel.tdc( hitIdx ) 00120 self.info("TDC value: "+str( tdc )) 00121 00122 # ADC data for this channel 00123 # 00124 # The ADC is an integer count of the charge of the PMT 00125 # pulse. It is 12 bits (0 to 4095). There are two ADCs 00126 # for every PMT channel (High gain and Low gain). Only 00127 # the high gain ADC is recorded by default. If the high 00128 # gain ADC is saturated (near 4095), then the low gain ADC 00129 # is recorded instead. 00130 # 00131 # For the Mini Dry Run data, one PMT photoelectron makes 00132 # about 20 high gain ADC counts and about 1 low gain ADC 00133 # count. There is an offset (Pedestal) for each ADC of 00134 # ~70 ADC counts (ie. no signal = ~70 ADC, 1 photoelectron 00135 # = ~90 ADC, 2 p.e. = ~110 ADC, etc.) 00136 # 00137 # The ADC peal cycle is a record of the clock cycle which had 00138 # the 'peak' ADC. 00139 # 00140 # ADC Gain: Here is a description of ADC gain for these values 00141 # Unknown = 0 00142 # High = 1 00143 # Low = 2 00144 # 00145 adc = channel.adc( hitIdx ) 00146 preAdc = channel.preAdcAvg( hitIdx ) 00147 peakCycle = channel.peakCycle( hitIdx ) 00148 isHighGain = channel.isHighGainAdc( hitIdx ) 00149 self.info("ADC value: "+str(adc) 00150 + " (preAdc: "+str( preAdc )+"," 00151 + " peak cycle: "+str( peakCycle )+"," 00152 + " isHighGain?: "+str( isHighGain )+")") 00153 # Add to total ADC sum for this trigger 00154 if isHighGain == 1: 00155 adcSum += (adc-preAdc) 00156 else: 00157 # Adjust low gain adc to high gain scale 00158 adcSum += (adc-preAdc) * 19 00159 00160 # Add this trigger to histogram of ADC sum 00161 self.stats["/file1/myhists/adcSum"].Fill( adcSum ) 00162 return SUCCESS 00163 00164 def finalize(self): 00165 self.info("finalizing") 00166 status = DybPythonAlg.finalize(self) 00167 return status 00168 00169 ##### Job Configuration for nuwa.py ######################################## 00170 00171 def configure( argv=[] ): 00172 """ Example of processing raw data """ 00173 00174 # Setup root file for output histograms 00175 from StatisticsSvc.StatisticsSvcConf import StatisticsSvc 00176 statsSvc = StatisticsSvc() 00177 statsSvc.Output = {"file1":"rawDataResult.root"} 00178 return 00179 00180 def run(app): 00181 ''' 00182 Configure and add the algorithm to job 00183 ''' 00184 app.ExtSvc += ["StatisticsSvc"] 00185 myAlg = PrintRawDataAlg("MyPrintRawDataAlg") 00186 app.addAlgorithm(myAlg) 00187 pass 00188