00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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
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
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
00051
00052
00053
00054 self.cableSvc = self.svc('ICableSvc','StaticCableSvc')
00055 if self.cableSvc == None:
00056 self.error("Failed to get StaticCableSvc")
00057 return FAILURE
00058
00059
00060
00061 self.pmtGeomSvc = self.svc('IPmtGeomInfoSvc','PmtGeomInfoSvc')
00062 if self.pmtGeomSvc == None:
00063 self.error("Failed to get PmtGeomInfoSvc")
00064 return FAILURE
00065
00066
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
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
00092 readoutHdr = evt["/Event/Readout/ReadoutHeader"]
00093 if readoutHdr == None:
00094 self.error("Failed to get current readout header")
00095 return FAILURE
00096
00097
00098 readout = readoutHdr.readout()
00099 if readout == None:
00100 self.error("Failed to get readout from header")
00101 return FAILURE
00102
00103
00104
00105 svcMode = ServiceMode( readoutHdr.context(), 0 )
00106
00107
00108 for channelPair in readout.channelReadout():
00109 channel = channelPair.second
00110 channelId = channel.channelId()
00111
00112
00113 pmtId = self.cableSvc.adPmtSensor(channelId, svcMode)
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
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
00130
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
00141
00142 for adcIdx in range( channel.size() ):
00143 adc = channel.adc( adcIdx )
00144 adcGain = channel.adcRange( adcIdx )
00145
00146 if adcGain == 2:
00147
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
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
00167
00168 def configure( argv=[] ):
00169 """ Example of processing raw data """
00170
00171
00172 from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00173 statsSvc = StatisticsSvc()
00174 statsSvc.Output = {"file1":"pmtInfoResult.root"}
00175
00176
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