FairShip
Loading...
Searching...
No Matches
split_provenance.SplitProvenance Class Reference

Public Member Functions

 __init__ (self, mother, split_set, split_role, split_weight, start_t, weight, proc_id=None)
 from_tracks (cls, tracks)
 __len__ (self)
 lineage (self, i)
 initial_weight (self, i)
 compatible (self, i, j, t_i=math.inf, t_j=math.inf)
 pair_weight (self, i, j, t_i=math.inf, t_j=math.inf)
 desplit (self, rng)

Public Attributes

 mother = np.asarray(mother, dtype=int)
 split_set = np.asarray(split_set, dtype=int)
 split_role = np.asarray(split_role, dtype=int)
 split_weight = np.asarray(split_weight, dtype=float)
 start_t = np.asarray(start_t, dtype=float)
 weight = np.asarray(weight, dtype=float)
tuple continuation
dict sets = {}

Protected Member Functions

 _line_weight_at_start (self, a)
 _links (self, i, t_obs, at_start=False)

Protected Attributes

dict _lineages = {}

Detailed Description

Split-set structure of one event; see the module docstring.

Definition at line 63 of file split_provenance.py.

Constructor & Destructor Documentation

◆ __init__()

split_provenance.SplitProvenance.__init__ ( self,
mother,
split_set,
split_role,
split_weight,
start_t,
weight,
proc_id = None )

Definition at line 66 of file split_provenance.py.

66 def __init__(self, mother, split_set, split_role, split_weight, start_t, weight, proc_id=None):
67 self.mother = np.asarray(mother, dtype=int)
68 self.split_set = np.asarray(split_set, dtype=int)
69 self.split_role = np.asarray(split_role, dtype=int)
70 self.split_weight = np.asarray(split_weight, dtype=float)
71 self.start_t = np.asarray(start_t, dtype=float)
72 self.weight = np.asarray(weight, dtype=float)
73 # Continuations are pushed by the splitting code (no process); the
74 # original split track was made by Geant4.
75 self.continuation = (
76 np.zeros(len(self.mother), dtype=bool)
77 if proc_id is None
78 else (np.asarray(proc_id, dtype=int) == K_NO_PROCESS) & (self.split_role == SURVIVOR)
79 )
80 self.sets = {}
81 for i in np.flatnonzero(self.split_set >= 0):
82 entry = self.sets.setdefault(
83 int(self.split_set[i]), {"W": float(self.split_weight[i]), "decays": [], "survivors": []}
84 )
85 entry["decays" if self.split_role[i] == DECAY else "survivors"].append(int(i))
86 for entry in self.sets.values():
87 entry["decays"].sort(key=lambda c: self.start_t[c])
88 entry["survivors"].sort(key=lambda c: self.start_t[c])
89 entry["stored"] = float(sum(self.weight[c] for c in entry["decays"]))
90 self._lineages = {}
91

Member Function Documentation

◆ __len__()

split_provenance.SplitProvenance.__len__ ( self)

Definition at line 111 of file split_provenance.py.

111 def __len__(self):
112 return len(self.mother)
113

◆ _line_weight_at_start()

split_provenance.SplitProvenance._line_weight_at_start ( self,
a )
protected
Weight of the survivor line where survivor track a starts.

Definition at line 129 of file split_provenance.py.

129 def _line_weight_at_start(self, a):
130 """Weight of the survivor line where survivor track a starts."""
131 if not self.continuation[a]:
132 return self.split_weight[a]
133 # A continuation starts where the track it continues ended, with that
134 # track's final weight. If that track was not stored, a's own final
135 # weight is the closest lower bound.
136 earlier = [b for b in self.sets[int(self.split_set[a])]["survivors"] if self.start_t[b] < self.start_t[a]]
137 return self.weight[earlier[-1]] if earlier else self.weight[a]
138

◆ _links()

split_provenance.SplitProvenance._links ( self,
i,
t_obs,
at_start = False )
protected
Split sets on the lineage of i (at most one member each, since members are siblings).

If i is itself on a survivor line, it is observed at t_obs with its
stored weight (the weight at the end of its path, e.g. at the scoring
plane where tracks stop), or with at_start at its own start.

Definition at line 139 of file split_provenance.py.

139 def _links(self, i, t_obs, at_start=False):
140 """Split sets on the lineage of i (at most one member each, since members are siblings).
141
142 If i is itself on a survivor line, it is observed at t_obs with its
143 stored weight (the weight at the end of its path, e.g. at the scoring
144 plane where tracks stop), or with at_start at its own start.
145 """
146 line = self.lineage(i)
147 links = {}
148 for k, a in enumerate(line):
149 s = self.split_set[a]
150 if s < 0:
151 continue
152 if self.split_role[a] == DECAY:
153 links[int(s)] = _Link(int(s), DECAY, a, self.start_t[a], self.weight[a])
154 elif k == 0 and at_start:
155 links[int(s)] = _Link(int(s), SURVIVOR, a, self.start_t[a], self._line_weight_at_start(a))
156 elif k == 0:
157 links[int(s)] = _Link(int(s), SURVIVOR, a, t_obs, self.weight[a])
158 else:
159 child = line[k - 1]
160 links[int(s)] = _Link(int(s), SURVIVOR, a, self.start_t[child], self.initial_weight(child))
161 return links
162

◆ compatible()

split_provenance.SplitProvenance.compatible ( self,
i,
j,
t_i = math.inf,
t_j = math.inf )
Whether tracks i and j can exist in the same real event.

t_i, t_j: when a survivor-line track is itself the observed object (e.g.
a hit of the split kaon), the time of that observation.

Definition at line 165 of file split_provenance.py.

165 def compatible(self, i, j, t_i=math.inf, t_j=math.inf):
166 """Whether tracks i and j can exist in the same real event.
167
168 t_i, t_j: when a survivor-line track is itself the observed object (e.g.
169 a hit of the split kaon), the time of that observation.
170 """
171 li, lj = self._links(i, t_i), self._links(j, t_j)
172 for s in li.keys() & lj.keys():
173 a, b = li[s], lj[s]
174 if a.member == b.member:
175 continue
176 if a.role == DECAY and b.role == DECAY:
177 return False
178 if a.role == DECAY and not b.branch_time < a.branch_time:
179 return False
180 if b.role == DECAY and not a.branch_time < b.branch_time:
181 return False
182 return True
183

◆ desplit()

split_provenance.SplitProvenance.desplit ( self,
rng )
Draw one outcome per split set; see Desplit.

Definition at line 218 of file split_provenance.py.

218 def desplit(self, rng):
219 """Draw one outcome per split set; see Desplit."""
220 return Desplit(self, rng)
221
222

◆ from_tracks()

split_provenance.SplitProvenance.from_tracks ( cls,
tracks )
From a sequence of ShipMCTrack (e.g. event.MCTrack).

Definition at line 93 of file split_provenance.py.

93 def from_tracks(cls, tracks):
94 """From a sequence of ShipMCTrack (e.g. event.MCTrack)."""
95 rows = [
96 (
97 t.GetMotherId(),
98 t.GetSplitSet(),
99 t.GetSplitRole(),
100 t.GetSplitWeight(),
101 t.GetStartT(),
102 t.GetWeight(),
103 t.GetProcID(),
104 )
105 for t in tracks
106 ]
107 if not rows:
108 return cls([], [], [], [], [], [], [])
109 return cls(*zip(*rows))
110

◆ initial_weight()

split_provenance.SplitProvenance.initial_weight ( self,
i )
Weight of track i when it was created (before any split of its own).

Definition at line 125 of file split_provenance.py.

125 def initial_weight(self, i):
126 """Weight of track i when it was created (before any split of its own)."""
127 return self.split_weight[i] if self.split_set[i] >= 0 else self.weight[i]
128

◆ lineage()

split_provenance.SplitProvenance.lineage ( self,
i )
Track i and its ancestors, nearest first.

Definition at line 116 of file split_provenance.py.

116 def lineage(self, i):
117 """Track i and its ancestors, nearest first."""
118 if i not in self._lineages:
119 line = [i]
120 while self.mother[line[-1]] >= 0 and len(line) <= len(self):
121 line.append(int(self.mother[line[-1]]))
122 self._lineages[i] = line
123 return self._lineages[i]
124

◆ pair_weight()

split_provenance.SplitProvenance.pair_weight ( self,
i,
j,
t_i = math.inf,
t_j = math.inf )
Weight of the pair (i, j) for unbiased pair observables; 0 if incompatible.

Definition at line 184 of file split_provenance.py.

184 def pair_weight(self, i, j, t_i=math.inf, t_j=math.inf):
185 """Weight of the pair (i, j) for unbiased pair observables; 0 if incompatible."""
186 if i == j or not self.compatible(i, j, t_i, t_j):
187 return 0.0
188 line_i, line_j = self.lineage(i), self.lineage(j)
189 on_j = set(line_j)
190 m = next((a for a in line_i if a in on_j), None)
191 if m is None:
192 # No common ancestor: two primaries of the same event.
193 w_a = max(self.initial_weight(line_i[-1]), self.initial_weight(line_j[-1]))
194 return self.weight[i] * self.weight[j] / w_a
195 if m in (i, j):
196 # One is an ancestor of the other: the pair stands for the descendant.
197 return self.weight[j] if m == i else self.weight[i]
198 ci = line_i[line_i.index(m) - 1]
199 cj = line_j[line_j.index(m) - 1]
200 s = self.split_set[ci]
201 if s >= 0 and s == self.split_set[cj]:
202 # The lineages part inside one split set: at a decay on the survivor
203 # line, or where each leaves the survivor line.
204 a, b = self._links(i, t_i)[int(s)], self._links(j, t_j)[int(s)]
205 if a.role == DECAY:
206 w_a = b.branch_weight
207 elif b.role == DECAY:
208 w_a = a.branch_weight
209 else:
210 w_a = max(a.branch_weight, b.branch_weight)
211 else:
212 # The lineages part at m; its weight there is that of the earlier child.
213 w_a = max(self.initial_weight(ci), self.initial_weight(cj))
214 return self.weight[i] * self.weight[j] / w_a
215

Member Data Documentation

◆ _lineages

dict split_provenance.SplitProvenance._lineages = {}
protected

Definition at line 90 of file split_provenance.py.

◆ continuation

tuple split_provenance.SplitProvenance.continuation
Initial value:
= (
np.zeros(len(self.mother), dtype=bool)
if proc_id is None
else (np.asarray(proc_id, dtype=int) == K_NO_PROCESS) & (self.split_role == SURVIVOR)
)

Definition at line 75 of file split_provenance.py.

◆ mother

split_provenance.SplitProvenance.mother = np.asarray(mother, dtype=int)

Definition at line 67 of file split_provenance.py.

◆ sets

dict split_provenance.SplitProvenance.sets = {}

Definition at line 80 of file split_provenance.py.

◆ split_role

split_provenance.SplitProvenance.split_role = np.asarray(split_role, dtype=int)

Definition at line 69 of file split_provenance.py.

◆ split_set

split_provenance.SplitProvenance.split_set = np.asarray(split_set, dtype=int)

Definition at line 68 of file split_provenance.py.

◆ split_weight

split_provenance.SplitProvenance.split_weight = np.asarray(split_weight, dtype=float)

Definition at line 70 of file split_provenance.py.

◆ start_t

split_provenance.SplitProvenance.start_t = np.asarray(start_t, dtype=float)

Definition at line 71 of file split_provenance.py.

◆ weight

split_provenance.SplitProvenance.weight = np.asarray(weight, dtype=float)

Definition at line 72 of file split_provenance.py.


The documentation for this class was generated from the following file: