12 import pxl.core,pxl.astro,pxl.hep
13 import_root_error=
None
17 from array
import array
21 LABEL =
"&ROOT Canvas View"
24 AbstractView.__init__(self)
25 QWidget.__init__(self, parent)
26 ROOT.gROOT.SetStyle(
'Plain')
35 """ Sets the DataAccessor from which the data is read
36 You need to call updateContent() in order to make the changes visible.
38 if not isinstance(accessor, BasicDataAccessor):
39 raise TypeError(__name__ +
" requires data accessor of type BasicDataAccessor.")
42 AbstractView.setDataAccessor(self, accessor)
45 """ Clear the view and refill it.
47 logging.debug(__name__ +
": updateContent")
48 if import_root_error!=
None:
49 logging.error(__name__ +
": Could not import pxl and ROOT: "+import_root_error[1])
50 QCoreApplication.instance().errorMessage(
"Could not import pxl and ROOT (see logfile for details):\n"+import_root_error[0])
58 for object
in objects:
67 ''' The actual plotting script - has to be replaced later with
68 script from external file by user'''
71 logging.debug(__name__ +
": _plotscript")
73 if isinstance(object, pxl.core.BasicContainer):
75 abos = object.getObjectsOfType(pxl.astro.AstroBasicObject)
76 logging.debug(__name__ +
": _plotscript: Plotting " + str(len(abos)) +
" AstroObjects")
80 lat.append(ao.getLatitude())
81 lon.append(ao.getLongitude())
83 self.
f = ROOT.TGraph(len(lat), array(
'f', lon), array(
'f', lat))
86 self.f.GetXaxis().SetTitle(
'Longitude')
87 self.f.GetYaxis().SetTitle(
'Latitude')
90 self.f.SetEditable(
False)
92 elif isinstance(object, pxl.astro.RegionOfInterest)
or isinstance(object, pxl.astro.UHECRSource):
94 self.p.append(ROOT.TMarker(object.getLongitude(), object.getLatitude(), 3))
95 logging.debug(__name__ +
'DrawROI with ' + str(len(object.getSoftRelations().getContainer().items())) +
' UHECR')
96 for key, item
in object.getSoftRelations().getContainer().items():
98 uhecr = pxl.astro.toUHECR(self.basiccontainer.getById(item))
99 if isinstance(uhecr,pxl.astro.UHECR):
100 self.p.append(ROOT.TMarker(uhecr.getLongitude(), uhecr.getLatitude(), 7))
101 self.
p[ - 1].SetMarkerSize(10)
102 self.
p[ - 1].SetMarkerColor(ROOT.kGreen + 1)
104 uhecr = pxl.astro.toAstroObject(self.basiccontainer.getById(item))
105 if isinstance(uhecr,pxl.astro.AstroObject):
106 self.p.append(ROOT.TMarker(uhecr.getLongitude(), uhecr.getLatitude(), 7))
107 self.
p[ - 1].SetMarkerSize(8)
108 self.
p[ - 1].SetMarkerColor(ROOT.kOrange + 1)
113 elif isinstance(object, pxl.astro.AstroBasicObject):
114 self.
p = ROOT.TMarker(object.getLongitude(), object.getLatitude(), 7)
115 self.p.SetMarkerSize(10)
116 self.p.SetMarkerColor(ROOT.kRed)
118 elif isinstance(object, pxl.hep.EventView):
120 elif isinstance(object, pxl.core.Event):
121 for eventview
in object.getObjectsOfType(pxl.hep.EventView):
123 elif isinstance(object, pxl.hep.Particle):
124 self.
p = ROOT.TMarker(object.getPhi(), object.getEta(), 20)
125 if (object.getName() ==
"Muon"):
126 h2 = ROOT.TH2F(
'muon-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
128 h2.Fill(object.getEta(), object.getPhi(), object.getPt())
129 h2.DrawCopy(
'SAME LEGO A')
130 elif (object.getName() ==
"Jet"):
131 h2 = ROOT.TH2F(
'jet-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
133 h2.Fill(object.getEta(), object.getPhi(), object.getPt())
134 h2.DrawCopy(
'SAME LEGO A')
135 elif (object.getName() ==
"Electron"):
136 h2 = ROOT.TH2F(
'electron-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
138 h2.Fill(object.getEta(), object.getPhi(), object.getPt())
139 h2.DrawCopy(
'SAME LEGO A')
140 elif (object.getName() ==
"MET"):
141 h2 = ROOT.TH2F(
'met-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
143 h2.Fill(object.getEta(), object.getPhi(), object.getPt())
144 h2.DrawCopy(
'SAME LEGO A')
146 h2 = ROOT.TH2F(
'all-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
148 h2.Fill(object.getEta(), object.getPhi(), object.getPt())
149 h2.DrawCopy(
'SAME LEGO A')
156 particles = eventview.getObjectsOfType(pxl.hep.Particle)
157 logging.info(
"Display " + str(len(particles)) +
" Particles.")
158 if (len(particles) > 0):
161 for particle
in particles:
162 if (particle.getEta() < 1000.):
163 etas.append(particle.getEta())
164 phis.append(particle.getPhi())
165 self.
f = ROOT.TGraph(len(etas), array(
'f', phis), array(
'f', etas))
167 self.f.GetXaxis().SetTitle(
'#Phi')
168 self.f.GetXaxis().SetRangeUser(- 3.14156, 3.14156)
169 self.f.GetYaxis().SetTitle(
'#eta')
170 self.f.GetXaxis().SetRangeUser(- 5., 5.)
171 self.f.SetMarkerSize(1)
172 self.f.SetMarkerStyle(20)
175 self.f.SetEditable(
False)
179 particles = eventview.getObjectsOfType(pxl.hep.Particle)
180 logging.info(
"Display " + str(len(particles)) +
" Particles")
181 if (len(particles) > 0):
182 self.
f = ROOT.TH2F(
'eta-phi-plot',
'', 50, - 4, 4, 50, - 3.141593, 3.141593)
183 for particle
in particles:
184 self.f.Fill(particle.getEta(), particle.getPhi(), particle.getPt())
187 self.f.GetXaxis().SetTitle(
'#eta')
188 self.f.GetYaxis().SetTitle(
'#Phi')
189 self.f.GetZaxis().SetTitle(
'p_{T} (GeV)')
191 self.f.DrawCopy(
'LEGO2')
195 """ Stop all running operations.
200 QWidget.mousePressEvent(self,event)
201 if event.button()==Qt.RightButton:
202 self.emit(SIGNAL(
"mouseRightPressed"), event.globalPos())