Commit 6831448e authored by David Blyth's avatar David Blyth
Browse files

SiEIC Concept: added sim calo hits and MC particles to sieic_vis

parent 5e0106c6
......@@ -2,6 +2,7 @@
import argparse
from array import array
import math
def run(args):
import ROOT, DDG4
......@@ -12,7 +13,8 @@ def run(args):
manager = dd.manager()
manager.CheckOverlaps(0.01)
manager.PrintOverlaps()
manager.SetVisDensity()
if args.input_file == None:
manager.SetVisDensity()
manager.SetVisLevel(2)
top_vol = manager.GetTopVolume()
top_vol.Draw('ogl')
......@@ -33,34 +35,11 @@ def run(args):
clip_state.extend([1,0,0,0,0,0])
clip_set.SetClipState(clip_type, clip_state)
else:
ROOT.gSystem.Load('liblcio')
ROOT.gInterpreter.ProcessLine("#include <lcio.h>")
ROOT.gInterpreter.ProcessLine("#include <EVENT/LCCollection.h>")
ROOT.gInterpreter.ProcessLine("#include <IMPL/SimTrackerHitImpl.h>")
reader = ROOT.IOIMPL.LCFactory.getInstance().createLCReader()
reader.open(args.input_file)
reader.skipNEvents(args.input_event)
event = reader.readNextEvent()
hit_markers = ROOT.TPolyMarker3D()
hit_markers.SetMarkerSize(5)
hit_markers.SetMarkerColor(3)
hit_markers.SetMarkerStyle(4)
coll_names = event.getCollectionNames()
for coll_name in coll_names:
coll = event.getCollection(coll_name)
type_name = coll.getTypeName()
if type_name == "SimTrackerHit":
n_hits = coll.getNumberOfElements()
for i in range(0, n_hits):
hit = coll.getElementAt(i)
hit.__class__ = ROOT.IMPL.SimTrackerHitImpl
pos = hit.getPosition()
hit_markers.SetNextPoint(pos[0] / 10., pos[1] / 10., pos[2] / 10.)
hit_markers.Draw('same')
markers, lines = draw_event(args.input_file, args.input_event)
for marker in markers:
marker.Draw('same')
for line in lines:
line.Draw('same')
if args.interactive:
ROOT.gApplication.Run()
......@@ -73,6 +52,80 @@ def run(args):
overlay.SetShowOrthographic(False)
save_picture(viewer, args.output_prefix + '_angledNoOverlay.png')
def draw_event(input_file, input_event):
import ROOT
ROOT.gSystem.Load('liblcio')
ROOT.gInterpreter.ProcessLine("#include <lcio.h>")
ROOT.gInterpreter.ProcessLine("#include <EVENT/LCCollection.h>")
ROOT.gInterpreter.ProcessLine("#include <IMPL/SimTrackerHitImpl.h>")
ROOT.gInterpreter.ProcessLine("#include <IMPL/SimCalorimeterHitImpl.h>")
ROOT.gInterpreter.ProcessLine("#include <IMPL/MCParticleImpl.h>")
reader = ROOT.IOIMPL.LCFactory.getInstance().createLCReader()
reader.open(input_file)
reader.skipNEvents(input_event)
event = reader.readNextEvent()
markers = []
lines = []
coll_names = event.getCollectionNames()
for coll_name in coll_names:
coll = event.getCollection(coll_name)
type_name = coll.getTypeName()
if type_name == "SimTrackerHit":
n_hits = coll.getNumberOfElements()
tracker_hit_markers = ROOT.TPolyMarker3D(n_hits)
markers.append(tracker_hit_markers)
tracker_hit_markers.SetMarkerSize(10)
tracker_hit_markers.SetMarkerColor(3)
tracker_hit_markers.SetMarkerStyle(2)
for i in range(0, n_hits):
hit = coll.getElementAt(i)
hit.__class__ = ROOT.IMPL.SimTrackerHitImpl
pos = hit.getPosition()
tracker_hit_markers.SetPoint(i, pos[0] / 10., pos[1] / 10., pos[2] / 10.)
elif type_name == "SimCalorimeterHit":
n_hits = coll.getNumberOfElements()
calo_hit_markers = ROOT.TPolyMarker3D()
markers.append(calo_hit_markers)
calo_hit_markers.SetMarkerSize(5)
calo_hit_markers.SetMarkerColor(3)
calo_hit_markers.SetMarkerStyle(4)
for i in range(0, n_hits):
hit = coll.getElementAt(i)
hit.__class__ = ROOT.IMPL.SimCalorimeterHitImpl
pos = hit.getPosition()
calo_hit_markers.SetPoint(i, pos[0] / 10., pos[1] / 10., pos[2] / 10.)
elif type_name == "MCParticle":
n_parts = coll.getNumberOfElements()
for i in range(0, n_parts):
part = coll.getElementAt(i)
part.__class__ = ROOT.IMPL.MCParticleImpl
vertex = part.getVertex()
vertex_marker = ROOT.TPolyMarker3D(1)
markers.append(vertex_marker)
vertex_marker.SetMarkerColor(3)
vertex_marker.SetMarkerStyle(7)
vertex_marker.SetPoint(0, vertex[0] / 10., vertex[1] / 10., vertex[2] / 10.)
vertex_marker.Draw('same')
momentum = part.getMomentum()
mag = math.sqrt(pow(momentum[0], 2) + pow(momentum[1], 2) + pow(momentum[2], 2))
line_len = 50
line_vec = array('d')
line_vec.extend([momentum[0] * line_len / mag, momentum[1] * line_len / mag, momentum[2] * line_len / mag])
part_line = ROOT.TPolyLine3D(2)
lines.append(part_line)
part_line.SetLineColor(1)
part_line.SetLineWidth(2)
part_line.SetPoint(0, vertex[0] / 10., vertex[1] / 10., vertex[2] / 10.)
part_line.SetPoint(1, line_vec[0], line_vec[1], line_vec[2])
part_line.Draw('same')
reader.close()
return markers, lines
def save_picture(viewer, filename):
viewer.SavePictureUsingFBO(filename, 1920, 1080)
print("Saved file: " + filename)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment