#!/usr/bin/env python """ A fully working, 1-line z-vs-t style event display options: -f : input file, default= -d : det file, default= -t : require this many doms to hava a trig. hit. default=5 -w : show each event for this many seconds default=0 -h : this help message and exit default=False -i : Python interative mode (prompt when done) default=False """ from __future__ import print_function import time, sys, aa import collections, array from ROOT import EventFile, Det, TH1F, TCanvas, TMarker, SetOwnership, gStyle, TLatex, double, gPad gStyle.SetOptStat(0) options = aa.Options( __doc__, sys.argv[1:] ) aa.i() f, det = EventFile( options.f ), Det( options.d ) # let's look at some events to find wich lines have data def get_line( hit ): return det.doms[ hit.dom_id ].line_id working_lines = set() for evt in f : for h in evt.hits : working_lines.add( get_line( h ) ) if f.index > 10 : break print (" these lines have data in the first 10 events : " , working_lines) # -- sort the doms by line, and count the lines, and setup the canvas accoringly -- lines = collections.defaultdict ( list ) for dum,dom in det.doms : if dom.line_id not in working_lines : continue lines[ dom.line_id ].append( dom ) for l in lines.values() : l.sort( key = lambda d : d.pos.z ) def line_shape( line_id, zpos ) : "returns the estimated position of the line, inter- and extrapolated" doms = lines[ line_id ] # walk up the line until zpos is between p0 and p1 for i in range( len ( doms) -1 ) : p0, p1 = doms[i].pos, doms[i+1].pos if zpos < p1.z : break f = ( zpos - p0.z ) / ( p1.z - p0.z ) return p0 + f * (p1-p0) # Histogram to define axes h0 = TH1F('h0', "h0;time (ns);height (m)" ,1,-500,1000) h0.SetMaximum( max( l[-1].pos.z for l in lines.values() )+20 ) h0.SetMinimum( min( l[0].pos.z for l in lines.values() )-20 ) def nice_canvas( N = 4 , title = "canvas title") : "make canvas with N sub-pads, with some room for a title" w,h = 1,1 while w * h < len(lines) : if w==h : w+=1 else : h+=1 c = TCanvas('c','c', min( 1000, w*500), min(1000, h*400) ) c.Divide(w,h) Tl = TLatex() Tl.SetTextAlign(21) Tl.SetTextSize(0.05) c.header = Tl.DrawLatexNDC(0.5,0.94,"title") # make some room for the title : scale all pads in y-direction for i in range( w*h ): c.cd(i+1) xlow, ylow, xup, yup = double(), double(), double(), double() gPad.GetPadPar( xlow, ylow, xup, yup ) fac = 0.9 gPad.SetPad( xlow, fac*ylow, xup, fac*yup ) return c c = nice_canvas( len(lines) ) # Event loop! for evt in f: # count how many doms had a triggered hit ntrigdoms = len( { h.dom_id for h in evt.hits if h.trig } ) if ntrigdoms < options.t : continue c.cd(0); c.header.SetTitle( evt.__str__() ) # set the hit possitions etc. det.apply( evt ) # Find time of the first trigger-hit, to use as offet t0 = min( h.t for h in evt.hits if h.trig ) trk = evt.best_reco_track( 4000 ) # 4000 = jchain trk.t -= t0 canv = 0 for line_id, doms_on_this_line in lines.items() : domids = { d.id for d in doms_on_this_line } hits_on_this_line = [ h for h in evt.hits if h.dom_id in domids and -500 < h.t-t0 < 1000 ] canv+=1 c.cd( canv ) h0.SetTitle("line "+str(line_id) ) h0.DrawCopy() for h in hits_on_this_line: m = TMarker( h.t - t0 , h.pos.z, 20 ) m.SetMarkerColor( 2 if h.trig else 4 ) m.Draw() # tell python it should not garbage-collect the markers SetOwnership(m, False ) # make a graph of z vs t for the track hypothesis zs = [ h0.GetMinimum() + ( h0.GetMaximum()-h0.GetMinimum() ) / 25 * i for i in range(25) ] ts = [ trk.time_at( line_shape( line_id, z ) ) for z in zs ] gg = TGraph( len( ts), array.array('d',ts), array.array('d',zs) ) gg.SetLineWidth(2); gg.SetLineColor(8) gg.Draw("L") SetOwnership(gg, False ) c.Update() print ("Now showing",evt) dump( trk ) time.sleep( options.w ) #del h0 # get rid of annoying root warnings