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

In This Package:

Viewer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 
00004 from GaudiPython.GaudiAlgs import GaudiAlgo
00005 from GaudiPython import SUCCESS, FAILURE
00006 from GaudiPython import gbl
00007 from array import array
00008 
00009 TH1F = gbl.TH1F
00010 TGraph = gbl.TGraph
00011 TCanvas = gbl.TCanvas
00012 TFile = gbl.TFile
00013 DayaBay = gbl.DayaBay
00014 gStyle = gbl.gStyle
00015 gStyle.SetPalette(1)
00016 gStyle.SetMarkerStyle(8)
00017 gStyle.SetMarkerColor(4)
00018 
00019 class EsViewerAlg(GaudiAlgo):
00020     "An algorithm for generating figures of ElecSim Data Objects"
00021     def __init__(self,name):
00022         GaudiAlgo.__init__(self,name)
00023         print "Making EsViewerAlg",name
00024         self.plot = {}
00025 
00026     def initialize(self):
00027         status = GaudiAlgo.initialize(self)
00028         print "Init EsViewerAlg",self.name()
00029         if status.isFailure(): return status
00030         return SUCCESS
00031 
00032     def execute(self):
00033         print "Executing EsViewerAlg",self.name()
00034         evt = self.evtSvc()
00035         hdr = evt["/Event/Elec/ElecHeader"]
00036         crateHdr = hdr.crateHeader()
00037         crates = crateHdr.crates()
00038         crate = crates[DayaBay.Detector(0x01,1)]
00039         # Signal clock ticks [ns]
00040         hitDt = 12.5
00041         energyDt = 1.5625
00042         esumDt = 6.25
00043         adcDt = 25
00044         tdcDt = 25./16.
00045          #Draw entire crate nhit signal
00046         nhitBoard = crate.nhit()
00047         nhitSignal = None
00048         for board in range(6,17):
00049             boardId = DayaBay.FeeChannelId(board,0,0x01,1)
00050             boardNhit = nhitBoard[boardId]
00051             #print "init size: ",boardNhit.size()
00052             if nhitSignal == None:
00053                 nhitSignal = [0] * boardNhit.size()
00054             for cycle in range(boardNhit.size()):
00055                 nhitSignal[cycle] += boardNhit[cycle]
00056         nhitClock = [tick*hitDt for tick in range(boardNhit.size())]
00057         self.plot["nhit"] = TGraph(boardNhit.size(),
00058                                    array('f',nhitClock),
00059                                    array('f',nhitSignal))
00060                                    
00061         # Plot energy sum
00062         energySum = None 
00063         energySize = None
00064         for connector in range(1,17):
00065             for board in range(1,24):
00066                 channelId = DayaBay.FeeChannelId(board,connector,0x01,1)
00067                 channel = crate.channel(channelId)
00068                 energyChannel = channel.energy()
00069                 if energyChannel.size() == 0:
00070                     continue
00071                 if energySum == None:
00072                     energySum = [0] * energyChannel.size()
00073                     energySize = energyChannel.size()
00074                 for cycle in range(energyChannel.size()):
00075                     energySum[cycle] += energyChannel[cycle]
00076         energyClock = [tick*energyDt for tick in range(energySize)]
00077         self.plot["energySum"] = TGraph(energySize,
00078                                    array('f',energyClock),
00079                                    array('f',energySum))
00080         # Draw an example channel
00081         tdc = None
00082         flag = 0
00083         channel = None
00084         for connector in range(1,17):
00085           if flag == 1: 
00086               break
00087           for board in range(1,24):
00088               # Look for a channel with hits
00089               channelId = DayaBay.FeeChannelId(board,connector,0x01,1)
00090               channel = crate.channel(channelId)
00091               tdc = channel.tdc()
00092               if tdc.size() > 0:
00093                   print "Found a hit channel"
00094                   flag = 1
00095                   break
00096         if flag == 0:
00097             print "No hit channel found"
00098         if flag == 1:
00099             energy = channel.energy()
00100             energyClock = [tick*energyDt for tick in range(energy.size())]
00101             self.plot["energy"] = TGraph(energy.size(),
00102                                          array('f',energyClock),
00103                                          array('f',energy))
00104             hit = channel.hit()
00105             hitClock = [tick*hitDt for tick in range(hit.size())]
00106             self.plot["hit"] = TGraph(hit.size(),
00107                                       array('f',hitClock),
00108                                       array('f',hit))
00109             adcLow = channel.adcLow()
00110             adcLowClock = [tick*adcDt for tick in range(adcLow.size())]
00111             self.plot["adcLow"] = TGraph(adcLow.size(),
00112                                          array('f',adcLowClock),
00113                                          array('f',adcLow))
00114             adcHigh = channel.adcHigh()
00115             adcHighClock = [tick*adcDt for tick in range(adcHigh.size())]
00116             self.plot["adcHigh"] = TGraph(adcHigh.size(),
00117                                           array('f',adcHighClock),
00118                                           array('f',adcHigh))
00119             esumTotal = crate.esumTotal()
00120             energyClock = [tick*esumDt for tick in range(esumTotal.size())]
00121             self.plot["esumTotal"] = TGraph(esumTotal.size(),
00122                                           array('f',energyClock),
00123                                           array('f',esumTotal))
00124             esumLower = crate.esumLower()
00125             energyClock = [tick*esumDt for tick in range(esumLower.size())]
00126             self.plot["esumLower"] = TGraph(esumLower.size(),
00127                                           array('f',energyClock),
00128                                           array('f',esumLower))
00129             esumUpper = crate.esumUpper()
00130             energyClock = [tick*esumDt for tick in range(esumUpper.size())]
00131             self.plot["esumUpper"] = TGraph(esumUpper.size(),
00132                                           array('f',energyClock),
00133                                           array('f',esumUpper))
00134         return SUCCESS
00135 
00136     def finalize(self):
00137         print "Finalizing EsViewerAlg",self.name()
00138         outFile = TFile("elecSimPlots.root","RECREATE")
00139         for key in self.plot.keys():
00140             self.plot[key].SetTitle(key)
00141             self.plot[key].SetName(key)
00142             self.plot[key].GetXaxis().SetTitle("time [ns]")
00143             self.plot[key].Write()
00144         status = GaudiAlgo.finalize(self)
00145         return status
00146 
00147 def configure():
00148     return
00149 
00150 def run(app):
00151     viewer = EsViewerAlg("EsViewer")
00152     app.addAlgorithm(viewer)
00153     pass
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:16:37 for ElecSim by doxygen 1.7.4