Skip to main content

gondola_core/physics/
tracklet.rs

1// This file is part of gaps-online-software and published 
2// under the GPLv3 license
3
4use crate::prelude::*;
5
6// copy over the G4Process so that we do not need to
7// include G4 here
8/// Types of serializable data structures used
9/// throughout the TOF system. 
10#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy, FromRepr, AsRefStr, EnumIter)]
11#[cfg_attr(feature = "pybindings", pyclass(eq, eq_int))]
12#[repr(u8)]
13pub enum G4ProcessType {
14   NotDefined        = 0u8,
15   Transportation    = 10u8,
16   Electromagnetic   = 20u8,
17   Optical           = 30u8,
18   Hadronic          = 40u8,
19   PhotoLeptonHadron = 50u8,
20   Decay             = 60u8,
21   General           = 70u8,
22   Parametrisation   = 80u8,
23   UserDefined       = 90u8,
24   Parallel          = 100u8,
25   Phonon            = 110u8,
26   Ucn               = 120u8,
27   Unknown           = 255u8, // since 0 is already assigned
28}
29
30// in case we have pybindings for this type, 
31// expand it so that it can be used as keys
32// in dictionaries
33#[cfg(feature = "pybindings")]
34#[pymethods]
35impl G4ProcessType {
36
37  #[getter]
38  fn __hash__(&self) -> usize {
39    (*self as u8) as usize
40  } 
41}
42
43expand_and_test_enum!(G4ProcessType, test_g4processtype_repr);
44
45//------------------------------------------------------------
46
47#[derive(Debug, Copy, Clone)]
48#[cfg_attr(feature="pybindings", pyclass)] 
49pub struct RecoHit {
50  pub x      : f32,
51  pub x_err  : f32,
52  pub y      : f32,
53  pub y_err  : f32,
54  pub z      : f32,
55  pub z_err  : f32,
56  pub time   : f32,
57  pub energy : f32,
58  pub volume : u32
59}
60
61impl RecoHit {
62  pub fn new() -> Self {
63    Self {
64      x      : 0.0,
65      x_err  : 0.0,
66      y      : 0.0,
67      y_err  : 0.0,
68      z      : 0.0,
69      z_err  : 0.0,
70      time   : 0.0,
71      energy : 0.0,
72      volume : 0
73    }
74  }
75}
76
77/// A representation of a physics track, as a single, 
78/// unbent, stright line
79#[derive(Debug, Copy, Clone)]
80#[cfg_attr(feature="pybindings", pyclass)] 
81pub struct Tracklet {
82  pub start         : RecoHit,
83  pub stop          : RecoHit,
84  pub is_infinite   : bool,
85  pub vertex_mom_x  : f32,
86  pub vertex_mom_y  : f32,
87  pub vertex_mom_z  : f32,
88  pub vertex_x      : f32,
89  pub vertex_y      : f32,
90  pub vertex_z      : f32,
91  // initial kinetic energy in MeV
92  pub vertex_energy : f32,
93}
94
95impl Tracklet {
96  pub fn new() -> Self {
97    Self {
98      start         : RecoHit::new(),
99      stop          : RecoHit::new(),
100      is_infinite   : true,
101      vertex_mom_x  : 0.0,
102      vertex_mom_y  : 0.0,
103      vertex_mom_z  : 0.0,
104      vertex_x      : 0.0,
105      vertex_y      : 0.0,
106      vertex_z      : 0.0,
107      vertex_energy : 0.0,
108    }
109  }
110
111  pub fn get_vertex_pos(&self) -> (f32,f32,f32) {
112    (self.vertex_x, self.vertex_y, self.vertex_z)
113  }
114  
115  pub fn get_vertex_mom(&self) -> (f32,f32,f32) {
116    (self.vertex_mom_x, self.vertex_mom_y, self.vertex_mom_z)
117  }
118}
119
120#[cfg(feature="pybindings")]
121#[pymethods]
122impl Tracklet {
123  
124  #[getter]
125  #[pyo3(name="vertex_mom")]
126  fn get_vertex_mom_py(&self) -> (f32,f32,f32) {
127    self.get_vertex_mom() 
128  }
129
130  #[getter] 
131  #[pyo3(name="vertex_energy")]
132  fn get_vertex_energy_py(&self) -> f32 {
133    self.vertex_energy
134  }
135
136  #[getter]
137  #[pyo3(name="vertex_pos")]
138  fn get_vertex_pos_py(&self) -> (f32,f32,f32) {
139    self.get_vertex_pos()
140  }
141
142}
143
144impl fmt::Display for Tracklet {
145  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
146    let mut repr = String::from("<Tracklet");
147    repr += &(format!("\n  vertex {:.2} {:.2} {:.2}", self.vertex_x, self.vertex_y, self.vertex_z));
148
149    write!(f,"{}", repr)
150  } 
151}
152
153pub struct Track {
154  pub tracklets : Vec<Tracklet>
155}
156