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

In This Package:

PrintCalibData.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"Calibrate" -m"Quickstart.PrintCalibData" daq...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 AdPmtSensor = gbl.DayaBay.AdPmtSensor
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 PrintCalibDataAlg(DybPythonAlg):
00034     "Print Calib 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/chargeSum"] = TH1F("chargeSum",
00046                                    "Sum of PMT charge for each trigger",
00047                                    2000,0,2000)
00048         return SUCCESS
00049 
00050     def execute(self):
00051         self.info("executing")
00052 
00053         evt = self.evtSvc()
00054 
00055         # Access the Calib Readout Header.
00056         # This is a container for calibrated data
00057         calibHdr = evt["/Event/CalibReadout/CalibReadoutHeader"]
00058         if calibHdr == None:
00059             self.error("Failed to get current calib readout header")
00060             return FAILURE
00061 
00062         # Access the Readout.  This is the calibrated data from one trigger.
00063         calibReadout = calibHdr.calibReadout()
00064         if calibReadout == None:
00065             self.error("Failed to get calibrated readout from header")
00066             return FAILURE
00067 
00068         # Get the detector ID for this trigger
00069         detector = calibReadout.detector()
00070         self.info("Detector Name: "+detector.detName())
00071 
00072         # Trigger Type: This is an integer of the type for this trigger
00073         self.info("Trigger Type: "+str( calibReadout.triggerType() ))
00074         # Trigger Number: A count of the trigger, according to the DAQ
00075         self.info("Trigger Number: "+str( calibReadout.triggerNumber() ))
00076 
00077         # Trigger Time: Absolute time of trigger for this calibrated data
00078         triggerTime = calibReadout.triggerTime()
00079         # Trigger Time [Seconds]: Trigger time in seconds
00080         self.info("Trigger Time [Seconds part]: "
00081                   +str( triggerTime.GetSec() ))
00082         # Trigger Time [Nanoseconds]: Nanoseconds part of trigger time
00083         self.info("Trigger Time [Nanoseconds part]: "
00084                   +str( triggerTime.GetNanoSec() ))
00085         # Full Trigger Time: Seconds + nanoseconds
00086         # Warning: When you add this together, it will lose some precision.
00087         self.info("Full Trigger Time: "
00088                   +str( triggerTime.GetSec()
00089                         +triggerTime.GetNanoSec()*1.0e-9 ))
00090         
00091         # Loop over each channel data in this trigger
00092         chargeSum = 0
00093         for channel in calibReadout.channelReadout():
00094             sensorId = channel.pmtSensorId()
00095             pmtId = AdPmtSensor( sensorId.fullPackedData() )
00096 
00097             # The pmt ID contains the detector ID, AD column and row numbers.
00098             self.info("Pmt ID:"
00099                       +" detector="
00100                       +pmtId.detName()
00101                       +" column="
00102                       +str(pmtId.column())
00103                       +" ring="
00104                       +str(pmtId.ring()))
00105 
00106             # Calibrated hit data for this channel
00107             for hitIdx in range( channel.size() ):
00108                 # Hit time is in units of ns, and is relative to trigger time
00109                 hitTime = channel.time( hitIdx )
00110                 self.info("Hit Time: "+str( hitTime ))
00111                 # Hit charge is in units of photoelectrons
00112                 hitCharge = channel.charge( hitIdx )
00113                 self.info("Hit Charge: "+str( hitCharge ))
00114                 chargeSum += hitCharge
00115 
00116         # Add this trigger to histogram of Charge sum
00117         self.stats["/file1/myhists/chargeSum"].Fill( chargeSum )
00118         return SUCCESS
00119         
00120     def finalize(self):
00121         self.info("finalizing")
00122         status = DybPythonAlg.finalize(self)
00123         return status
00124 
00125 #####  Job Configuration for nuwa.py ########################################
00126 
00127 def configure( argv=[] ):
00128     """ Example of processing calibrated data """
00129 
00130     # Setup root file for output histograms
00131     from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00132     statsSvc = StatisticsSvc()
00133     statsSvc.Output = {"file1":"calibDataResult.root"}
00134 
00135     return
00136 
00137 def run(app):
00138     '''
00139     Configure and add the algorithm to job
00140     '''
00141     app.ExtSvc += ["StatisticsSvc"]
00142     myAlg = PrintCalibDataAlg("MyPrintCalibDataAlg")
00143     app.addAlgorithm(myAlg)
00144     pass
00145 
| 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