#!/usr/bin/env python # This example shows basic a basic aanet event loop and the many # options there are for printing event information. # # """ Usage user_info.py -f input_file -o output_file.root The Evt, Trk and Hit classes of aanet derive from a small base class AAObject, which provides simple functionality to add user data to the event. This is usefull if you want to add a small bit of information to each Event/Track/Hit, and don't care too much about speed. options: -f : input file default=/sps/km3net/users/heijboer/example_files/JGandalf_aanet_muon-CC_3-100GeV_1.root -o : output file default=info.root -n : process this many events, default=10 -p : print 1-line event summaries, default=True -h : this help message and exit default=False -i : Python interative mode (prompt when done) default=True """ import sys, aa from ROOT import * # aa.py contains helper to deal with cmd line options options = aa.Options( __doc__, sys.argv[1:] ) outfile = options.o f = EventFile( options.f ) f.set_output( outfile ) # this opend an aanet output file f.autosave = true # true = default, but just illustrate for evt in f : evt.setusr("my_parameter", 42 ) for t in evt.mc_trks : t.setusr("trackpar", 42*42 ) # You can also just use the usr member for h in evt.hits : h.usr.resize(3); h.usr[0] = 1; h.usr[1] = 2; h.usr[2] = 3; if f.index > options.n : break; del f #================================================================ print ("-- now reading the file with user info --") f2 = EventFile( outfile ) for evt in f2 : print evt.getusr("my_parameter") print evt.mc_trks[0].getusr("trackpar") for i in range (evt.hits.size()): print i,evt.hits[i].usr[2] print # If you know the index-numbers, you can use them in TTree::Draw # and TTree::Scan. (Unfortunatelly, you can not refer to the usr # variables by name when doing this). E.Draw("hits[].usr[2]") # lots of entries at 3