#!/usr/bin/env python """ Usage skim -f input_file -o output_file Simple example to show how to set an output file and write selected events to it (aka skimming). options: -f : input file default=../data/mc5.1.numuCC.nohits.aa.root -o : output file default=prime.aa.root -h : this help message and exit default=False -i : Python interative mode (prompt when done) default=False """ import sys, aa from ROOT import EventFile options = aa.Options( __doc__, sys.argv[1:] ) if options.o == "auto" : outfile = options.f.split("/")[-1]+".aa.root" else : outfile = options.o infile = options.f # open the input file f = EventFile( options.f ) # If we set an output file, the output TTree is filled automatically f.set_output( outfile ) # this opens an aanet output file f.autosave = False # manually decide which events to write def is_prime ( n ) : if n < 2 : return False for d in range (2,int( n**0.5+1 ) ) : if n%d == 0 : return False; return True; for evt in f : keep = is_prime( evt.id ) if keep : print (evt) f.write() del f