/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

CheckFadc.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''Algorithm to test FADC readout
00004 
00005 It can be called via nuwa.py:
00006 
00007   nuwa.py -n 2000 AdBasicFigs.CheckFadc file.data
00008 
00009 '''
00010 
00011 from DybPython.DybPythonAlg import DybPythonAlg
00012 from GaudiPython import SUCCESS, FAILURE
00013 from GaudiPython import gbl
00014 TH1F = gbl.TH1F
00015 # number of single event waveforms to be recorded
00016 nFadcExample = 10
00017 
00018 class CheckAlg(DybPythonAlg):
00019     '''
00020     Algorithm to test RPC readout simulation
00021     '''
00022 
00023     def __init__(self,myname):
00024         ''' '''
00025         DybPythonAlg.__init__(self,myname)
00026         return
00027 
00028     def initialize(self):
00029         status = DybPythonAlg.initialize(self)
00030         if status.isFailure(): return status
00031         self.info("initializing")
00032         
00033         self.eventEntries = [0]*4
00034         self.fadcEntries  = [0]*4
00035         # Make FADC histograms
00036         for adIdx in range(1,5):
00037             for fadcChIdx in range(1,9):
00038                 # averaged waveforms     
00039                 pathname = "/file1/AD" + str(adIdx) + "/average/"
00040                 self.stats.defaultPath = pathname
00041                 histName  = "FADC_ch" + str(fadcChIdx)
00042                 histTitle = "FADC channel " + str(fadcChIdx)
00043                 self.stats[histName] = TH1F(histName,histTitle,120,-0.5,119.5)
00044                 self.stats[histName].SetLineColor(4)
00045                 # single event waveforms
00046                 pathname = "/file1/AD" + str(adIdx) + "/single/"
00047                 self.stats.defaultPath = pathname
00048                 for histIdx in range(1,nFadcExample+1):
00049                     histExName  = "FADC_#" + str(histIdx) + "_ch" + str(fadcChIdx)
00050                     self.stats[histExName] = TH1F(histExName,"",120,-0.5,119.5)
00051                     self.stats[histExName].SetLineColor(4)
00052         return SUCCESS
00053 
00054     def execute(self):
00055         evt = self.evtSvc()
00056 
00057         rohdr = evt["/Event/Readout/ReadoutHeader"]
00058         if rohdr == None:
00059             self.info("No ReadoutHeader header this cycle")
00060         else :
00061             daq = rohdr.daqCrate()
00062             if daq == None:
00063                 self.info("No daq crate this cycle")
00064             else :
00065                 if (daq.detector().isAD()):
00066                     # rought energy estimate
00067                     pmtReadout = daq.asPmtCrate();
00068                     energy = 0
00069                     recordEvent = False
00070                     negChannels = 0
00071                     pmtChannels = pmtReadout.pmtChannelReadouts()
00072                     for pmtChannel in pmtChannels:
00073                         rawCharge = pmtChannel.deltaAdc(0) / 18.
00074                         energy += rawCharge
00075                         if rawCharge < 0:
00076                             negChannels += 1
00077                         if rawCharge < 0:
00078                             recordEvent = False
00079                     energy /= 160.
00080                     # only record 1-3 MeV range
00081                     # try to skip obvious muons and muon retriggers
00082                     if energy > 1 and energy < 3 and negChannels < 2:
00083                         self.info("Detector: %s"%(daq.detector().detName()))
00084                         self.info("Energy: %s"%(energy))
00085                         detNo = daq.detector().detectorId()
00086                         fadcChannels = pmtReadout.fadcChannelReadouts()
00087                         self.eventEntries[detNo-1] += 1
00088                         nFadcChannels = fadcChannels.size()
00089                         if fadcChannels.size() == 0:
00090                             self.info("No FADC data recorded")
00091                         else:
00092                             self.info("FADC data found")
00093                             self.fadcEntries[detNo-1] += 1
00094                             for fadcChIdx in range(len(fadcChannels)):
00095                                 waveform = fadcChannels[fadcChIdx].samples();
00096                                 histName = "FADC_ch" + str(fadcChIdx+1)
00097                                 for dacIdx in range(len(waveform)):
00098                                     dac = waveform[dacIdx]
00099                                     # fill averaged FADC waveforms
00100                                     pathname = "/file1/AD" + str(detNo) + "/average/"
00101                                     self.stats.defaultPath = pathname
00102                                     self.stats[histName].Fill(dacIdx,dac);
00103                                     # record some single event waveforms
00104                                     if self.fadcEntries[detNo-1] < nFadcExample+1:
00105                                         pathname = "/file1/AD" + str(detNo) + "/single/"
00106                                         self.stats.defaultPath = pathname
00107                                         histExName  = "FADC_#" + str(self.fadcEntries[detNo-1]) + "_ch" + str(fadcChIdx+1)
00108                                         histExTitle = "E = " + str(energy) + " MeV, channel " + str(fadcChIdx+1)
00109                                         self.stats[histExName].SetTitle(histExTitle) 
00110                                         self.stats[histExName].Fill(dacIdx,dac);
00111                                   
00112         return SUCCESS
00113     pass
00114     
00115     def finalize(self):
00116         recordNothing = True
00117         self.info("****************************************************")
00118         for adIdx in range(1,5):      
00119             if self.fadcEntries[adIdx-1] > 0:
00120                 recordNothing = False
00121                 pathname = "/file1/AD" + str(adIdx) + "/average/"
00122                 self.stats.defaultPath = pathname
00123                 norm = 1./self.fadcEntries[adIdx-1]
00124                 for fadcChIdx in range(1,9):
00125                     histName  = "FADC_ch" + str(fadcChIdx)
00126                     self.stats[histName].Scale(norm)
00127                 self.info("AD :  %s"%(adIdx))
00128                 self.info("Number of selected events:  %s"%(self.eventEntries[adIdx-1]))
00129                 self.info("Number of events with FADC: %s"%(self.fadcEntries[adIdx-1]))
00130         if recordNothing:
00131             self.warning("No FADC waveforms recorded, try to process more events")
00132         status = DybPythonAlg.finalize(self)
00133         return status
00134 
00135 def configure(argv = []):
00136     from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00137     statsSvc = StatisticsSvc()
00138     statsSvc.Output ={"file1":"fadcCheckPlots.root"}
00139     pass
00140 
00141 def run(app):
00142     app.ExtSvc += ["StatisticsSvc"]
00143     alg = CheckAlg("FadcCheckAlg")
00144     app.addAlgorithm(alg)
00145     return
00146 
00147 
00148 
00149 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:04:09 for AdBasicFigs by doxygen 1.7.4