| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

PrintRawData.py

Go to the documentation of this file.
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 Readout.  This is the data from one trigger.
00062         readout = readoutHdr.daqCrate().asPmtCrate()
00063         if readout == None:
00064             self.info("No readout this cycle")
00065             return SUCCESS
00066 
00067         # Get the detector ID for this trigger
00068         detector = readout.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( readout.triggerType() ))
00073         # Event Number: A count of the trigger, according to the DAQ
00074         self.info("Event Number: "+str( readout.eventNumber() ))
00075 
00076         # Trigger Time: Absolute time of trigger for this raw data
00077         triggerTime = readout.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         # Loop over each channel data in this trigger
00091         adcSum = 0
00092         for channel in readout.channelReadouts():
00093             channelId = channel.channelId()
00094 
00095             # The channel ID contains the detector ID, electronics board number,
00096             # and the connector number on the board.
00097             self.info("Channel ID:"
00098                       +" detector="
00099                       +channelId.detName()
00100                       +" board="
00101                       +str(channelId.board())
00102                       +" connector="
00103                       +str(channelId.connector()))
00104             
00105             # Loop over hits for this channel
00106             for hitIdx in range( channel.hitCount() ):
00107                 # TDC data for this channel
00108                 #
00109                 # The TDC is an integer count of the time between the time
00110                 # the PMT pulse arrived at the channel, and the time the
00111                 # trigger reads out the data.  Therefore, a larger TDC =
00112                 # earlier time.  One TDC count ~= 1.5625 nanoseconds.
00113                 #
00114                 tdc = channel.tdc( hitIdx )
00115                 self.info("TDC value: "+str( tdc ))
00116 
00117                 # ADC data for this channel
00118                 #
00119                 # The ADC is an integer count of the charge of the PMT
00120                 # pulse.  It is 12 bits (0 to 4095).  There are two ADCs
00121                 # for every PMT channel (High gain and Low gain).  Only
00122                 # the high gain ADC is recorded by default.  If the high
00123                 # gain ADC is saturated (near 4095), then the low gain ADC
00124                 # is recorded instead.
00125                 #
00126                 # For the Mini Dry Run data, one PMT photoelectron makes
00127                 # about 20 high gain ADC counts and about 1 low gain ADC
00128                 # count.  There is an offset (Pedestal) for each ADC of
00129                 # ~70 ADC counts (ie. no signal = ~70 ADC, 1 photoelectron
00130                 # = ~90 ADC, 2 p.e. = ~110 ADC, etc.)
00131                 #
00132                 # The ADC peal cycle is a record of the clock cycle which had
00133                 # the 'peak' ADC.
00134                 #
00135                 # ADC Gain: Here is a description of ADC gain for these values
00136                 #  Unknown = 0
00137                 #  High = 1
00138                 #  Low = 2
00139                 #
00140                 adc = channel.adc( hitIdx )
00141                 preAdc = channel.preAdcAvg( hitIdx )
00142                 peakCycle = channel.peakCycle( hitIdx )
00143                 isHighGain = channel.isHighGainAdc( hitIdx )
00144                 self.info("ADC value: "+str(adc)
00145                           + " (preAdc: "+str( preAdc )+","
00146                           + " peak cycle: "+str( peakCycle )+","
00147                           + " isHighGain?: "+str( isHighGain )+")")
00148                 # Add to total ADC sum for this trigger
00149                 if isHighGain == 1:
00150                     adcSum += (adc-preAdc)
00151                 else:
00152                     # Adjust low gain adc to high gain scale
00153                     adcSum += (adc-preAdc) * 19
00154 
00155         # Add this trigger to histogram of ADC sum
00156         self.stats["/file1/myhists/adcSum"].Fill( adcSum )
00157         return SUCCESS
00158         
00159     def finalize(self):
00160         self.info("finalizing")
00161         status = DybPythonAlg.finalize(self)
00162         return status
00163 
00164 #####  Job Configuration for nuwa.py ########################################
00165 
00166 def configure( argv=[] ):
00167     """ Example of processing raw data """
00168 
00169     # Setup root file for output histograms
00170     from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00171     statsSvc = StatisticsSvc()
00172     statsSvc.Output = {"file1":"rawDataResult.root"}
00173     return
00174 
00175 def run(app):
00176     '''
00177     Configure and add the algorithm to job
00178     '''
00179     app.ExtSvc += ["StatisticsSvc"]
00180     myAlg = PrintRawDataAlg("MyPrintRawDataAlg")
00181     app.addAlgorithm(myAlg)
00182     pass
00183 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:11:13 2011 for Quickstart by doxygen 1.4.7