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

In This Package:

PmtInfoExample.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Example script for reading raw data and using services to access the PMT ID
00004 # and position.
00005 #
00006 #  Usage:
00007 #   nuwa.py -A None -n -1 -m"Quickstart.PmtInfoExample" daq.NoTag.....data
00008 #
00009 #
00010  
00011 # Load DybPython
00012 from DybPython.DybPythonAlg import DybPythonAlg
00013 from GaudiPython import SUCCESS, FAILURE
00014 from GaudiPython import gbl
00015 from DybPython.Util import irange
00016 import GaudiKernel.SystemOfUnits as units
00017 
00018 # Make shortcuts to any ROOT classes you want to use
00019 TH1F = gbl.TH1F
00020 TH2F = gbl.TH2F
00021 gPad = gbl.gPad
00022 TimeStamp = gbl.TimeStamp
00023 FeeChannelId = gbl.DayaBay.FeeChannelId
00024 AdPmtSensor = gbl.DayaBay.AdPmtSensor
00025 Detector = gbl.DayaBay.Detector
00026 ServiceMode = gbl.ServiceMode
00027 Site = gbl.Site
00028 
00029 #change default ROOT style
00030 gbl.gStyle.SetHistLineColor(4)
00031 gbl.gStyle.SetHistLineWidth(2)
00032 gbl.gStyle.SetMarkerColor(4)
00033 gbl.gStyle.SetMarkerStyle(8)
00034 gbl.gStyle.SetPalette(1)
00035 
00036 import math
00037 
00038 # Make your algorithm
00039 class PmtInfoExampleAlg(DybPythonAlg):
00040     "Process raw data and access the related PMT information"
00041     def __init__(self,name):
00042         DybPythonAlg.__init__(self,name)
00043         return
00044 
00045     def initialize(self):
00046         status = DybPythonAlg.initialize(self)
00047         if status.isFailure(): return status
00048         self.info("initializing")
00049 
00050         # Prepare the services here:
00051 
00052         # Cable Service: This service provides a mapping between
00053         # electronics channels and pmts in the detector.
00054         self.cableSvc = self.svc('ICableSvc','StaticCableSvc')
00055         if self.cableSvc == None:
00056             self.error("Failed to get StaticCableSvc")
00057             return FAILURE
00058 
00059         # PMT Geometry Service: This service gives you information
00060         # about the PMT positions in the detectors
00061         self.pmtGeomSvc = self.svc('IPmtGeomInfoSvc','PmtGeomInfoSvc')
00062         if self.pmtGeomSvc == None:
00063             self.error("Failed to get PmtGeomInfoSvc")
00064             return FAILURE
00065 
00066         # Example histogram: Count of hits on PMTs in AD
00067         self.stats["/file1/myhists/pmtHits"] = TH2F("pmtHits",
00068                                                     "Count of PMT hits",
00069                                                     49,-3.25,360+3.25,
00070                                                     19,-2.5+0.125,2.5-0.125)
00071         self.stats["/file1/myhists/pmtHits"].GetXaxis().SetLabelSize(0)
00072         self.stats["/file1/myhists/pmtHits"].GetXaxis().SetTitle("PMT columns")
00073         self.stats["/file1/myhists/pmtHits"].GetYaxis().SetTitle("PMT rings [m]")
00074 
00075         # Example histogram: Sum of charge on PMTs in AD
00076         self.stats["/file1/myhists/pmtCharge"] = TH2F("pmtCharge",
00077                                                     "Sum of charge on each PMT",
00078                                                     48,-3.25,360+3.25,
00079                                                     19,-2.5+0.125,2.5-0.125)
00080         self.stats["/file1/myhists/pmtCharge"].GetXaxis().SetLabelSize(0)
00081         self.stats["/file1/myhists/pmtHits"].GetXaxis().SetTitle("PMT columns")
00082         self.stats["/file1/myhists/pmtHits"].GetYaxis().SetTitle("PMT rings [m]")
00083                 
00084         return SUCCESS
00085 
00086     def execute(self):
00087         self.info("executing")
00088 
00089         evt = self.evtSvc()
00090 
00091         # Access the Readout Header.  This is a container for the readout data
00092         readoutHdr = evt["/Event/Readout/ReadoutHeader"]
00093         if readoutHdr == None:
00094             self.error("Failed to get current readout header")
00095             return FAILURE
00096 
00097         # Access the Readout.  This is the data from one trigger.
00098         readout = readoutHdr.readout()
00099         if readout == None:
00100             self.error("Failed to get readout from header")
00101             return FAILURE
00102 
00103         # The Service mode is used to get the correct cable mapping, etc.
00104         # You set it using the context (time, location) of the current data
00105         svcMode = ServiceMode( readoutHdr.context(), 0 )
00106 
00107         # Loop over each channel data in this trigger
00108         for channelPair in readout.channelReadout():
00109             channel = channelPair.second
00110             channelId = channel.channelId()
00111 
00112             # Get the PMT ID attached to this electronics channel
00113             pmtId = self.cableSvc.adPmtSensor(channelId, svcMode)
00114 
00115             # The PMT ID gives you information about the PMT:
00116             # pmtId.ring()        Ring in AD
00117             # pmtId.column()      Column in AD
00118             # pmtId.detectorId()  Detector ID 
00119             # pmtId.site()        Site ID
00120             # pmtId.detName()     Combined detector name: "SiteDetector"
00121 
00122             # Get the position of this PMT:
00123             #   Must use tempPmtId since we don't have SAB geometry!
00124             tempPmtId = AdPmtSensor(pmtId.ring(), pmtId.column(),
00125                                     Site.kDayaBay, pmtId.detectorId())
00126             pmtGeomInfo = self.pmtGeomSvc.get( tempPmtId.fullPackedData() )
00127             pmtXYZ = pmtGeomInfo.localPosition()
00128 
00129             # Make a new coordinate 'pmtPhiPrime'.  Based on PMT Phi,
00130             # but in correct orientation
00131             pmtPhi = pmtXYZ.phi() * 180/math.pi
00132             pmtZ = pmtXYZ.z()
00133             if pmtId.ring()==0:
00134                 pmtZ *= -1
00135             if pmtPhi<0: pmtPhi+= 360.
00136             pmtPhiPrime = 360-pmtPhi
00137             self.stats["/file1/myhists/pmtHits"].Fill(pmtPhiPrime,
00138                                                       pmtZ/units.m)
00139 
00140             # Add the adc charge to the histogram 
00141             # Loop over each ADC value
00142             for adcIdx in range( channel.size() ):
00143                 adc = channel.adc( adcIdx )
00144                 adcGain = channel.adcRange( adcIdx )
00145                 # Add to total ADC sum for this trigger
00146                 if adcGain == 2:
00147                     # Adjust low gain adc to high gain scale
00148                     adc *= 20
00149                 self.stats["/file1/myhists/pmtCharge"].Fill(pmtPhiPrime,
00150                                                             pmtZ/units.m,
00151                                                             adc)
00152         return SUCCESS
00153         
00154     def finalize(self):
00155         self.info("finalizing")
00156         # Draw Figures:
00157         pmtHits = self.stats["/file1/myhists/pmtHits"].Draw("colz")
00158         gPad.SaveAs("pmtHits.png")
00159         self.stats["/file1/myhists/pmtCharge"].Draw("colz")
00160         gPad.SaveAs("pmtCharge.png")
00161 
00162         status = DybPythonAlg.finalize(self)
00163         
00164         return status
00165 
00166 #####  Job Configuration for nuwa.py ########################################
00167 
00168 def configure( argv=[] ):
00169     """ Example of processing raw data """
00170 
00171     # Setup root file for output histograms
00172     from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00173     statsSvc = StatisticsSvc()
00174     statsSvc.Output = {"file1":"pmtInfoResult.root"}
00175 
00176     # Setup Service to get PMT position in detectors
00177     from DetHelpers.DetHelpersConf import PmtGeomInfoSvc
00178     pgiSvc = PmtGeomInfoSvc()
00179     pgiSvc.StreamItems = ["/dd/Structure/DayaBay"]
00180 
00181     return
00182 
00183 def run(app):
00184     '''
00185     Configure and add the algorithm to job
00186     '''
00187     app.ExtSvc += ["StatisticsSvc","StaticCableSvc","PmtGeomInfoSvc"]
00188     myAlg = PmtInfoExampleAlg("MyPmtInfoExampleAlg")
00189     app.addAlgorithm(myAlg)
00190     pass
00191 
| 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