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

In This Package:

WaveDumper.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Sctipt to dump waveforms to a Root File
00004 #
00005 #  Usage:
00006 #   nuwa.py -n -1 WaveDumper simulationData.root
00007 
00008 # Load DybPython
00009 from DybPython.DybPythonAlg import DybPythonAlg
00010 from GaudiPython import SUCCESS, FAILURE
00011 from GaudiPython import gbl
00012 from array import array
00013 
00014 # Make shortcuts to ROOT classes
00015 TH1F = gbl.TH1F
00016 TFile = gbl.TFile
00017 TGraph = gbl.TGraph
00018 
00019 # Make your algorithm
00020 class WaveDumperAlg(DybPythonAlg):
00021     "Example Python Algorithm"
00022     def __init__(self,name):
00023         DybPythonAlg.__init__(self,name)
00024         self.plot={}
00025         return
00026 
00027     def initialize(self):
00028         status = DybPythonAlg.initialize(self)
00029         if status.isFailure(): return status
00030         self.info("initializing")
00031         
00032         self.eventNumber = 0
00033         
00034         # Initialize services
00035         #self.cableSvc = self.svc('ICableSvc','StaticCableSvc')
00036 
00037         #self.stats.defaultPath = "/file1/waves/"
00038         # Make the trigger time histogram
00039         #self.stats["waveform"] = TGraph
00040 
00041         return SUCCESS
00042 
00043     def execute(self):
00044         self.info("executing")
00045         
00046         self.eventNumber+=1
00047         
00048         evt = self.evtSvc()
00049         hdr = evt["/Event/Elec/ElecHeader"]
00050         
00051         if (hdr.__class__ != gbl.DayaBay.ElecHeader ): 
00052             self.warning("ElecHeader not found for this event")
00053             return SUCCESS
00054         
00055         crateHeader = hdr.crateHeader()
00056         hitDt = 12.5
00057         energyDt = 5
00058         adcDt = 25
00059         tdcDt = 25./16
00060         for det,crate in crateHeader.crates():
00061             self.debug("Processing " + det.detName())
00062             crate.__class__=gbl.DayaBay.ElecFeeCrate
00063             
00064             boardpath="/file1/event_%d/%s/"%(self.eventNumber,
00065                                                            det.detName())                
00066             esumAdc = crate.esumADC()
00067             energyClock = [tick*energyDt for tick in range(esumAdc.size())]
00068             print esumAdc
00069             graph = TGraph(esumAdc.size(),
00070                            array('f',energyClock),
00071                            array('f',esumAdc))
00072             graph.SetMarkerStyle(8)   # large circle
00073             graph.SetMarkerColor(600) # blue
00074             graph.SetTitle("esumADC")
00075             self.stats[boardpath+"esumAdc"] = graph
00076            
00077             esumUpper = crate.esumUpper()
00078             energyClock = [tick*energyDt for tick in range(esumUpper.size())]
00079             graph = TGraph(esumAdc.size(),
00080                            array('f',energyClock),
00081                            array('f',esumUpper))
00082             graph.SetMarkerStyle(8)   # large circle
00083             graph.SetMarkerColor(600) # blue
00084             graph.SetTitle("esumUpper")
00085             self.stats[boardpath+"esumUpper"] = graph
00086 
00087             esumLower = crate.esumLower()
00088             energyClock = [tick*energyDt for tick in range(esumLower.size())]
00089             graph = TGraph(esumLower.size(),
00090                            array('f',energyClock),
00091                            array('f',esumLower))
00092             graph.SetMarkerStyle(8)   # large circle
00093             graph.SetMarkerColor(600) # blue
00094             graph.SetTitle("esumLower")
00095             self.stats[boardpath+"esumLower"] = graph
00096            
00097             esumTotal = crate.esumTotal()
00098             energyClock = [tick*energyDt for tick in range(esumTotal.size())]
00099             graph = TGraph(esumTotal.size(),
00100                            array('f',energyClock),
00101                            array('f',esumTotal))
00102             graph.SetMarkerStyle(8)   # large circle
00103             graph.SetMarkerColor(600) # blue
00104             graph.SetTitle("esumTotal")
00105             self.stats[boardpath+"esumTotal"] = graph
00106                            
00107            
00108             for chID,channel in crate.channelData():
00109                 path="/file1/"
00110                 path+="event_%d/%s/board_%d/connector_%d/"%(self.eventNumber,
00111                                                            det.detName(),
00112                                                            chID.board(),
00113                                                            chID.connector())
00114 #                self.debug(path)
00115                 # only proceed if the channel was hit
00116                 tdc = channel.tdc()
00117                 if tdc.size() > 0:
00118                     adcHigh = channel.adcHigh()
00119                     adcHighClock = [tick*adcDt for tick in range(adcHigh.size())]
00120                     graph=TGraph(adcHigh.size(),
00121                                  array('f',adcHighClock),
00122                                  array('f',adcHigh))
00123                     graph.SetMarkerStyle(8)   # large circle
00124                     graph.SetMarkerColor(600) # blue
00125                     graph.SetTitle("adcHigh")
00126                     self.stats[path+"adcHigh"] = graph
00127                    
00128                     hit = channel.hit()
00129                     hitClock = [tick*hitDt for tick in range(hit.size())]
00130                     graph= TGraph(hit.size(),
00131                                                     array('f',hitClock),
00132                                                     array('f',hit))
00133                     graph.SetMarkerStyle(8)   # large circle
00134                     graph.SetMarkerColor(600) # blue
00135                     graph.SetTitle("nhit")
00136                     self.stats[path+"nhit"]=graph
00137                     
00138                     adcLow = channel.adcLow()
00139                     adcLowClock = [tick*adcDt for tick in range(adcLow.size())]
00140                     graph = TGraph(adcLow.size(),
00141                                    array('f',adcLowClock),
00142                                    array('f',adcLow))
00143                     graph.SetMarkerStyle(8)   # large circle
00144                     graph.SetMarkerColor(600) # blue
00145                     graph.SetTitle("adcLow")
00146                     self.stats[path+"adcLow"] = graph                                  
00147                                                   
00148         return SUCCESS
00149         
00150     def finalize(self):        
00151         self.info("finalizing")
00152         status = DybPythonAlg.finalize(self)
00153         return status
00154 
00155 
00156 def configure():
00157     #from StatisticsSvc.StatisticsSvcConf import StatisticsSvc
00158     #statsSvc = StatisticsSvc()
00159     #statsSvc.Output ={"file1":"waveforms.root"}
00160     return
00161 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:07 2011 for ElecTutorial by doxygen 1.4.7