-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdanton.py
85 lines (76 loc) · 3.26 KB
/
danton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Université Clermont Auvergne, CNRS/IN2P3, LPC
# Author: Valentin NIESS (niess@in2p3.fr)
#
# This software is a C99 executable dedicated to the sampling of decaying
# taus from ultra high energy neutrinos.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
import collections
# The Earth radius in the Preliminary Earth Model (PEM).
EARTH_RADIUS = 6371.E+03
# Data structures for decays.
State = collections.namedtuple("State", ("pid", "energy", "direction",
"position"))
Product = collections.namedtuple("Product", ("pid", "momentum"))
Decay = collections.namedtuple("Decay", ("generation", "tau_i", "tau_f",
"product"))
Event = collections.namedtuple("Event", ("id", "primary", "decay", "weight"))
class iter_event:
"""Iterator over the tau decays in a text dump.
"""
def __init__(self, filename):
self.fid = open(filename, "r")
for _ in xrange(3): self.fid.readline() # skip the header
self.field = self.fid.readline().split()
def __iter__(self):
return self
def next(self):
if not self.field:
if not self.fid:
self.fid.close()
self.fid = None
raise StopIteration()
self.field, event = self._get_next_event()
return event
def _get_next_event(self):
"""Get the next event in the record.
"""
# Get the primary and event info.
eventid = int(self.field[0])
weight = float(self.field[9])
primary = State(int(self.field[1]),
float(self.field[2]), map(float, self.field[3:6]),
map(float, self.field[6:9]))
# Get the tau decays info.
decay = []
self.field = self.fid.readline().split()
while len(self.field) == 9:
genid = int(self.field[0])
pid = int(self.field[1])
tau_i = State(pid, float(self.field[2]),
map(float, self.field[3:6]), map(float, self.field[6:9]))
self.field = self.fid.readline().split()
tau_f = State(pid, float(self.field[0]),
map(float, self.field[1:4]), map(float, self.field[4:7]))
# Get the decay product(s)
product = []
self.field = self.fid.readline().split()
while len(self.field) == 4:
product.append(Product(int(self.field[0]),
map(float, self.field[1:4])))
self.field = self.fid.readline().split()
decay.append(Decay(genid, tau_i, tau_f, product))
return self.field, Event(eventid, primary, decay, weight)