MakeVectorFile.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 from __future__ import print_function
4 from builtins import range
5 from os.path import join
6 from math import sqrt, cos, sin
7 import sys
8 
9 ##
10 # Read in the commadn line options
11 ##
12 
13 from optparse import OptionParser
14 usage = "usage: %prog [options] <trigger file>"
15 parser = OptionParser(usage=usage)
16 parser.add_option("-p", "--momentum", default="10.0", help="Momentum in GeV (%default)", metavar="P")
17 parser.add_option("-t", "--time", default="0.0", help="Start Time (%default)", metavar="T")
18 parser.add_option( "--pdg", default="13", help="Particle PDG code (%default, mu-)")
19 parser.add_option("-n", "--number", default="0", help="Number of particles", metavar="N")
20 parser.add_option( "--direction",default="y", help="Direction of the scan")
21 parser.add_option( "--min", default="0", help="Minimum value")
22 parser.add_option( "--max", default="220", help="Maximum value")
23 (options, args) = parser.parse_args()
24 
25 
26 ## Particle Masses
27 massref = { 11:0.000511, 13:0.105 }
28 
29 ##
30 # Function which creates events
31 ##
32 def MakeEvent(outfile,
33  status = 1,
34  pdg = int(options.pdg),
35  mother1 = 0, mother2 = 0, daughter1 = 0, daughter2 = 0,
36  momentum = float(options.momentum),
37  direction = (0.0, 0.0, 1.0),
38  position = (50., 0.0, 0.0),
39  time = float(options.time) ):
40  global eventno
41 
42  momx, momy, momz = tuple([ momentum*x for x in direction ])
43  mass = massref[abs(pdg)]
44  energy = sqrt(momentum**2 + mass**2)
45  posx, posy, posz = position
46 
47  print(eventno, 1, file=outfile)
48  print(status, pdg, end=' ', file=outfile)
49  print(mother1, mother2, daughter1, daughter2, end=' ', file=outfile)
50  print(momx, momy, momz, energy, mass, end=' ', file=outfile)
51  print(posx, posy, posz, time, file=outfile)
52  eventno += 1
53 
54 
55 
56 vecfile = open(options.direction+"scan.vec","w")
57 
58 N = int(options.number)
59 minimum = float(options.min)
60 maximum = float(options.max)
61 step = (maximum - minimum)/(N - 1)
62 
63 
64 for eventno in range(N):
65  val = minimum + eventno * step
66 
67  if options.direction == "x":
68  pos = ( val, 0., 0.)
69  dir = (0., 0., 1.)
70  elif options.direction == "y":
71  pos = (50., val, 0.)
72  dir = (0., 0., 1.)
73  elif options.direction == "z":
74  pos = (50., 115., val)
75  dir = (0., -1., 0.)
76  else:
77  print("Unknown direction", options.direction)
78  sys.exit(1)
79 
80  MakeEvent(vecfile, position=pos, direction=dir )
81 
82 vecfile.close()
int open(const char *, int)
Opens a file descriptor.
T abs(T value)
def MakeEvent(outfile, status=1, pdg=int(options.pdg), mother1=0, mother2=0, daughter1=0, daughter2=0, momentum=float(options.momentum), direction=(0.0, 0.0, 1.0), position=(50., 0.0, 0.0), time=float(options.time))
Function which creates events.