source: fact/tools/pyscripts/simulation/absorb_photons.py@ 18342

Last change on this file since 18342 was 14820, checked in by neise, 12 years ago
initial commit; run before actual photon tracing.
  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/usr/bin/python -itt
2
3import sys
4import numpy as np
5import rlcompleter
6import readline
7readline.parse_and_bind('tab: complete')
8
9from readcorsika import read_corsika_file
10import fact_spline_interpolations as fact_si
11from Turnable import *
12
13absorbtion_coeff = fact_si.interpolate_from_files(
14 fact_si.Wavelength_dependency_description_files )
15
16angular_acceptance = fact_si.interpolate_from_files(
17 fact_si.angular_acceptance_files)
18
19
20run = read_corsika_file(sys.argv[1])
21
22print "photons = ", run.table.shape[0]
23
24wavelength = run.table[:,9]
25efficiencies = absorbtion_coeff(wavelength)
26# get uniform randomvalues between 0.0 and 1.0
27rndm = np.random.rand(wavelength.shape[0])
28
29# if the randomvalue is larger than the efficiency, the photon is absorbed
30# if the randomvalue is smaller, the photon survives
31run.not_absorbed = run.table[rndm < efficiencies,:]
32
33print "photons not absorbed = ", run.not_absorbed.shape[0],
34print float(run.not_absorbed.shape[0])/run.table.shape[0]*100, "%"
35
36distance = np.sqrt((run.not_absorbed[:,0:3]**2).sum(axis=1))
37run.inside = run.table[distance<210,:]
38
39print "photons inside = ", run.inside.shape[0],
40print float(run.inside.shape[0])/run.not_absorbed.shape[0]*100, "%"
41
42tm = run.inside[:,6].mean()
43pm = run.inside[:,7].mean()
44print "theta mean = ", tm
45print " phi mean = ", pm
46# now I can turn the photons such that the photons come from directly above
47
48# lets turn the world around the z-axis, so that phi mean becomes zero.
49Rphi = make_rotation_matrix( [0,0,1], pm)
50
51new_cosines = np.dot( run.inside[:,3:6],Rphi)
52new_theta = np.arccos(new_cosines[:,2])
53new_phi = np.arctan2(new_cosines[:,1], new_cosines[:,0])
54
55print "new theta mean", new_theta.mean()
56print "new phi mean", new_phi.mean()
57
58# now I think we need to turn around the y-axis
59Rtheta = make_rotation_matrix( [0,1,0], tm)
60
61new_cosines = np.dot( new_cosines,Rtheta)
62new_theta = np.arccos(new_cosines[:,2])
63new_phi = np.arctan2(new_cosines[:,1], new_cosines[:,0])
64
65print "new theta mean", new_theta.mean()
66print "new phi mean", new_phi.mean()
67
Note: See TracBrowser for help on using the repository browser.