gondola_core/events/
tracker_hit.rs

1//! Per-strip event information for the GAPS tracker
2// This file is part of gaps-online-software and published 
3// under the GPLv3 license
4
5
6use crate::prelude::*;
7
8/// Hit on a tracker strip
9#[derive(Debug, Copy, Clone)]
10#[cfg_attr(feature="pybindings", pyclass)]
11pub struct TrackerHit {
12  pub layer           : u16,
13  pub row             : u16,
14  pub module          : u16,
15  pub channel         : u16,
16  pub adc             : u16,
17  pub oscillator      : u64,
18
19  // not getting serialized
20  /// calibrated energy
21  pub energy          : f32, 
22  pub x               : f32,
23  pub y               : f32,
24  pub z               : f32,
25  pub has_coordinates : bool,
26  pub adc_pedestal    : u16,
27}
28
29impl TrackerHit {
30  //const SIZE : usize = 18;
31  
32  pub fn new() -> Self {
33    Self {
34      layer           : 0,
35      row             : 0,
36      module          : 0,
37      channel         : 0,
38      adc             : 0,
39      oscillator      : 0,
40      energy          : 0.0,
41      x               : 0.0,
42      y               : 0.0,
43      z               : 0.0,
44      has_coordinates : false,
45      adc_pedestal    : 0,
46    }
47  }
48 
49  /// Calculate the strip id from layer, module, row and channel
50  pub fn get_stripid(&self) -> u32 {
51    crate::events::strip_id(self.layer   as u8, 
52                            self.row     as u8,
53                            self.module  as u8,
54                            self.channel as u8)
55  }
56
57 #[cfg(feature="database")]
58 pub fn set_coordinates(&mut self, strip_map : &HashMap<u32, TrackerStrip>) {
59   match strip_map.get(&self.get_stripid()) {
60     None  => error!("Can not get strip for strip id {}" , self.get_stripid()),
61     Some(strip) => { 
62       self.x = strip.global_pos_x_l0;
63       self.y = strip.global_pos_y_l0;
64       self.z = strip.global_pos_z_l0;
65       self.has_coordinates = true
66     }
67   }
68 }
69}
70
71impl fmt::Display for TrackerHit {
72  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73    let mut repr = String::from("<TrackerHit:");
74    repr += &(format!("\n  Layer, Row, Module, Channel : {} {} {} {}" ,self.layer, self.row, self.module, self.channel));
75    repr += &(format!("\n  ADC           : {}" ,self.adc));
76    repr += &(format!("\n  Oscillator    : {}",self.oscillator));
77    if self.has_coordinates {
78      repr += &(format!("\n -- coordinates x : {} , y : {} , z {}", self.x, self.y, self.z));
79    } else {
80      repr += "\n -- [no coordinates set]";
81    }
82    repr += &(format!("\n  Cali. energy  : {}>", self.energy));
83    write!(f, "{}", repr)
84  }
85}
86
87#[cfg(feature="pybindings")]
88#[pymethods]
89impl TrackerHit {
90
91  /// Change the ADC value, e.g. if the 
92  /// pedestal should be subtracted
93  fn subtract_pedestal(&mut self, pedestal : u16) {
94    self.adc -= pedestal;
95  }
96
97  #[getter]
98  fn get_strip_id(&self) -> u32 {
99    self.get_stripid()
100  }
101
102  #[getter]
103  fn get_layer(&self) -> u16 {
104    self.layer
105  }
106
107  #[getter]
108  fn get_row(&self) -> u16 {
109    self.row
110  }
111
112  #[getter]
113  fn get_module(&self) -> u16 {
114    self.module
115  }
116
117  #[getter]
118  fn get_channel(&self) -> u16 {
119    self.channel
120  }
121
122  #[getter]
123  fn get_adc(&self) -> u16 {
124    self.adc
125  }
126
127  #[getter]
128  fn get_oscillator(&self) -> u64 {
129    self.oscillator
130  }
131  
132  #[getter]
133  fn get_energy(&self) -> f32 {
134    self.energy
135  }
136
137  #[getter]
138  fn get_x(&self) -> f32 {
139    self.x
140  }
141  
142  #[getter]
143  fn get_y(&self) -> f32 {
144    self.y
145  }
146  
147  #[getter]
148  fn get_z(&self) -> f32 {
149    self.z
150  }
151}
152
153#[cfg(feature="pybindings")]
154pythonize!(TrackerHit);
155