#!/usr/bin/env python import sys from math import sqrt if ( len(sys.argv) < 2): print "You must supply a filename!" sys.exit(-1) infilename=sys.argv[1] outfilename=infilename.replace(".dat", ".ascii") print "input file: %s" % (infilename) print "output file: %s" % (outfilename) Nevents=0 RunNumber=1 outfile = open(outfilename, "w") infile = open(infilename, "r") while infile: line = infile.readline() if(line==''):break if line.find("k1x")!=-1: continue vals = line.split() if(len(vals)<6): continue k1x = float(vals[0]) k1y = float(vals[1]) k1z = float(vals[2]) k2x = float(vals[3]) k2y = float(vals[4]) k2z = float(vals[5]) Nevents+=1 # Event header outfile.write('%d %d %d\n' % (RunNumber,Nevents,2)) # pi+, pi- mass = 0.13957 E1 = sqrt(k1x*k1x + k1y*k1y + k1z*k1z + mass*mass) outfile.write('1 pi+ %f +1 %f %f %f %f\n' % (mass, k1x, k1y, k1z, E1)) E2 = sqrt(k2x*k2x + k2y*k2y + k2z*k2z + mass*mass) outfile.write('2 pi- %f -1 %f %f %f %f\n' % (mass, k2x, k2y, k2z, E2)) print '%d events processed' % (Nevents) outfile.close() infile.close()