| 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         #self.cableSvc = self.svc('ICableSvc','StaticCableSvc')
00031         #self.testH = TH1F("testH","Test Histogram",100,0.0,2.0)
00032         return SUCCESS
00033 
00034     def execute(self):
00035         print "Executing EsViewerAlg",self.name()
00036         evt = self.evtSvc()
00037         hdr = evt["/Event/Elec/ElecHeader"]
00038         crateHdr = hdr.crateHeader()
00039         crates = crateHdr.crates()
00040         crate = crates[DayaBay.Detector(0x01,1)]
00041         # Signal clock ticks [ns]
00042         hitDt = 12.5
00043         energyDt = 1
00044         adcDt = 25
00045         tdcDt = 25./16.
00046         # Draw entire crate nhit signal
00047         nhitBoard = crate.nhit()
00048         nhitSignal = None
00049         for board in range(1,13):
00050             boardId = DayaBay.FeeChannelId(board,0,0x01,1)
00051             boardNhit = nhitBoard[boardId]
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         # Draw an example channel
00061         channel = None
00062         tdc = None
00063         for connector in range(1,17):
00064             # Look for a channel with hits
00065             channelId = DayaBay.FeeChannelId(1,connector,0x01,1)
00066             channel = crate.channel(channelId)
00067             tdc = channel.tdc()
00068             if tdc.size() > 0:
00069                 print "Found a hit channel"
00070                 break
00071         energy = channel.energy()
00072         energyClock = [tick*energyDt for tick in range(energy.size())]
00073         self.plot["energy"] = TGraph(energy.size(),
00074                                      array('f',energyClock),
00075                                      array('f',energy))
00076         hit = channel.hit()
00077         hitClock = [tick*hitDt for tick in range(hit.size())]
00078         self.plot["hit"] = TGraph(hit.size(),
00079                                   array('f',hitClock),
00080                                   array('f',hit))
00081         adcLow = channel.adcLow()
00082         adcLowClock = [tick*adcDt for tick in range(adcLow.size())]
00083         self.plot["adcLow"] = TGraph(adcLow.size(),
00084                                      array('f',adcLowClock),
00085                                      array('f',adcLow))
00086         adcHigh = channel.adcHigh()
00087         adcHighClock = [tick*adcDt for tick in range(adcHigh.size())]
00088         self.plot["adcHigh"] = TGraph(adcHigh.size(),
00089                                       array('f',adcHighClock),
00090                                       array('f',adcHigh))
00091         print nhitSignal
00092         return SUCCESS
00093 
00094     def finalize(self):
00095         print "Finalizing EsViewerAlg",self.name()
00096         outFile = TFile("elecSimPlots.root","RECREATE")
00097         for key in self.plot.keys():
00098             self.plot[key].SetTitle(key)
00099             self.plot[key].SetName(key)
00100             self.plot[key].GetXaxis().SetTitle("time [ns]")
00101             self.plot[key].Write()
00102             #canvas = TCanvas()
00103             #self.plot[key].Draw("APL")
00104             #canvas.SaveAs(key+".root")
00105         status = GaudiAlgo.finalize(self)
00106         return status
00107 
00108 def configure():
00109     return
00110 
00111 def run(app):
00112     '''
00113     Configure and add an algorithm to generate figures of ElecSim Data Objects
00114     '''
00115     viewer = EsViewerAlg("EsViewer")
00116     app.addAlgorithm(viewer)
00117     pass
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:49:26 2011 for ElecSim by doxygen 1.4.7