FairShip
Loading...
Searching...
No Matches
strawtubesDetector.py
Go to the documentation of this file.
1import global_variables
2import ROOT
3import shipunit as u
4from BaseDetector import BaseDetector
5
6
8 def __init__(self, name, intree, outtree=None) -> None:
9 super().__init__(name, intree, outtree=outtree)
10
11 def digitize(self) -> None:
12 """Digitize strawtube MC hits.
13
14 The earliest hit per straw will be marked valid, all later ones invalid.
15 """
16 earliest_per_det_id = {}
17 for index, point in enumerate(self.intree.strawtubesPoint):
18 hit = ROOT.strawtubesHit(point, self.intree.t0)
19 self.det.push_back(hit)
20 if hit.isValid():
21 detector_id = hit.GetDetectorID()
22 if detector_id in earliest_per_det_id:
23 earliest = earliest_per_det_id[detector_id]
24 if self.det[earliest].GetTDC() > hit.GetTDC():
25 # second hit with smaller tdc
26 self.det[earliest].setInvalid()
27 earliest_per_det_id[detector_id] = index
28 else:
29 self.det[index].setInvalid()
30 else:
31 earliest_per_det_id[detector_id] = index
32
33 def withT0Estimate(self) -> list[dict[str, float | int]]:
34 # loop over all straw tdcs and make average, correct for ToF
35 n = 0
36 t0 = 0.0
37 key = -1
38 stop = ROOT.TVector3()
39 start = ROOT.TVector3()
40 SmearedHits = []
41 v_drift = global_variables.modules["strawtubes"].StrawVdrift()
42 # straw 1002001 (first straw of station 1) defines the z reference
43 # plane for the time-of-flight correction
44 global_variables.modules["strawtubes"].StrawEndPoints(1002001, start, stop)
45 z1 = stop.z()
46 for aDigi in self.det:
47 key += 1
48 if not aDigi.isValid():
49 continue
50 detID = aDigi.GetDetectorID()
51 global_variables.modules["strawtubes"].StrawEndPoints(detID, start, stop)
52 delt1 = (start[2] - z1) / u.speedOfLight
53 t0 += aDigi.GetDigi() - delt1
54 SmearedHits.append(
55 {
56 "digiHit": key,
57 "xtop": stop.x(),
58 "ytop": stop.y(),
59 "z": stop.z(),
60 "xbot": start.x(),
61 "ybot": start.y(),
62 "dist": aDigi.GetDigi(),
63 "detID": detID,
64 }
65 )
66 n += 1
67 if n > 0:
68 # 73.2 ns: empirical offset aligning the averaged, ToF-corrected
69 # TDC times with the event t0.
70 # TODO(olantwin, 2026-08-12): document its derivation
71 t0 = t0 / n - 73.2 * u.ns
72 for s in SmearedHits:
73 delt1 = (s["z"] - z1) / u.speedOfLight
74 s["dist"] = (s["dist"] - delt1 - t0) * v_drift
75 return SmearedHits
76
77 def smearHits(self, no_amb=None) -> list[dict[str, float | int]]:
78 # smear strawtube points
79 SmearedHits = []
80 key = -1
81 stop = ROOT.TVector3()
82 start = ROOT.TVector3()
83 v_drift = global_variables.modules["strawtubes"].StrawVdrift()
84 for aDigi in self.det:
85 key += 1
86 if not aDigi.isValid():
87 continue
88 detID = aDigi.GetDetectorID()
89 global_variables.modules["strawtubes"].StrawEndPoints(detID, start, stop)
90 p = self.intree.strawtubesPoint[key]
91 # use true t0 construction:
92 # fdigi = t0 + p->GetTime() + t_drift + ( stop[0]-p->GetX() )/ speedOfLight;
93 smear = (aDigi.GetDigi() - self.intree.t0 - p.GetTime() - (stop[0] - p.GetX()) / u.speedOfLight) * v_drift
94 if no_amb:
95 smear = p.dist2Wire()
96 SmearedHits.append(
97 {
98 "digiHit": key,
99 "xtop": stop.x(),
100 "ytop": stop.y(),
101 "z": stop.z(),
102 "xbot": start.x(),
103 "ybot": start.y(),
104 "dist": smear,
105 "detID": detID,
106 }
107 )
108 # Note: top.z()==bot.z() unless misaligned, so only add key 'z' to smearedHit
109 if abs(stop.y()) == abs(start.y()):
110 global_variables.h["disty"].Fill(smear)
111 elif abs(stop.y()) > abs(start.y()):
112 global_variables.h["distu"].Fill(smear)
113 elif abs(stop.y()) < abs(start.y()):
114 global_variables.h["distv"].Fill(smear)
115
116 return SmearedHits
None __init__(self, name, intree, outtree=None)
list[dict[str, float|int]] smearHits(self, no_amb=None)
list[dict[str, float|int]] withT0Estimate(self)