gondola_core/physics/searchlight/
detector.rs1use crate::prelude::*;
7
8use glam::DVec3;
9
10#[derive(Debug, Copy, Clone, PartialEq)]
12pub struct SearchlightPaddle {
13 pub center : DVec3,
14 pub principal : DVec3,
16 pub normal : DVec3,
18 pub width : f64,
19 pub length : f64,
20}
21
22#[derive(Debug, Copy, Clone, PartialEq)]
25pub struct SearchlightStrip {
26 pub measured : u8,
28 pub half_chord : f64,
29}
30
31#[derive(Debug, Clone, Default)]
34#[cfg_attr(feature="pybindings", pyclass)]
35pub struct SearchlightGeometry {
36 pub paddles : HashMap<u8, SearchlightPaddle>,
37 pub overlaps : TofPaddleOverlaps,
38 pub strips : HashMap<u32, SearchlightStrip>,
40}
41
42impl SearchlightGeometry {
43 pub fn new(paddles : &HashMap<u8, TofPaddle>) -> Self {
46 let vec = |v : (f32, f32, f32)| DVec3::new(v.0 as f64, v.1 as f64, v.2 as f64);
47 let mut geo = HashMap::<u8, SearchlightPaddle>::new();
48 for (&pid, p) in paddles {
49 geo.insert(pid, SearchlightPaddle {
51 center : 10.0*vec(p.center_pos()),
52 principal : vec(p.principal()),
53 normal : vec(p.normal()),
54 width : 10.0*p.width as f64,
55 length : 10.0*p.length as f64,
56 });
57 }
58 Self {
59 paddles : geo,
60 overlaps : TofPaddleOverlaps::new(paddles),
61 strips : HashMap::new(),
62 }
63 }
64
65 pub const R_DISK : f64 = 50.0;
67
68 pub fn with_strips(mut self, strips : &HashMap<u32, TrackerStrip>) -> Self {
75 for (&sid, st) in strips {
76 let ox = 10.0*st.global_pos_x_l0 as f64 - 10.0*st.global_pos_x_det_l0 as f64;
78 let oy = 10.0*st.global_pos_y_l0 as f64 - 10.0*st.global_pos_y_det_l0 as f64;
79 let (measured, o) = if ox.abs() > oy.abs() { (0u8, ox) } else { (1u8, oy) };
80 let half_chord = (Self::R_DISK*Self::R_DISK - o*o).max(100.0).sqrt();
81 self.strips.insert(sid, SearchlightStrip { measured, half_chord });
82 }
83 self
84 }
85
86 pub fn closest_on_paddle(&self, paddle_id : u8, a : DVec3, u : DVec3) -> Option<(DVec3, f64)> {
91 let p = self.paddles.get(&paddle_id)?;
92 let h = 0.5*p.length;
93 let w = p.center - a;
94 let b = p.principal.dot(u);
95 let d = 1.0 - b*b;
96 let s = if d < 1e-9 { 0.0 } else { (b*u.dot(w) - p.principal.dot(w))/d };
97 let pt = p.center + s.clamp(-h, h)*p.principal;
98 let r = pt - a;
99 Some((pt, (r - r.dot(u)*u).length()))
100 }
101}