Skip to main content

gondola_core/events/
mc_tree.rs

1// The following file is part of gaps-online-software and published 
2// under the GPLv3 license
3
4use crate::prelude::*;
5
6#[derive(Debug, Clone, PartialEq)]
7#[cfg_attr(feature="pybindings", pyclass)] 
8pub struct McTree {
9  pub tracks    : Vec<McTrack>,
10  pub trackmap  : HashMap<u32, Vec<McHit>>,
11  pub max_gen   : usize,
12
13  //pub track_map : HashMap<usize, McTrack>,
14  ////pub n_tracks : usize;
15  //  // number of generations in the tree
16  //  uint NGenerations() const;
17  //  // number of tracks in total
18  //  uint NTracks() const;
19  //  // the initial track of the priamry
20  //  CTrackMc GetPrimary() const;
21  //  // daughters of any track in the tree
22  //  std::vector<CTrackMc> GetDaughters(CTrackMc track) const;
23  //  // get a specific generation
24  //  std::vector<CTrackMc> GetGeneration(uint gen) const;
25  //  // access to the whole tree
26  //  const std::map<uint, std::vector<CTrackMc>>& GetTree() const;
27
28
29  //private:
30  //  void InitializeTree(std::vector<CTrackMc> tracks);
31  //  void MakeGenerationTree();
32  //  bool StillAlive(CTrackMc track) const;
33  //  uint maxGen_;
34  //  uint nTracks_;
35  //  std::map<uint, CTrackMc> tracks_;
36  //  std::map<uint, std::vector<CTrackMc>> generationTree_;
37  //  CTrackMc primary_;
38  //};
39}
40
41impl McTree {
42  pub fn new() -> Self {
43    Self {
44      tracks   : Vec::<McTrack>::new(),
45      max_gen  : 0,
46      trackmap : HashMap::<u32, Vec<McHit>>::new(),
47    }
48  }
49
50  pub fn get_daughters(&self) -> Vec<McTrack> {
51    let mut daughters =  Vec::<McTrack>::new();
52  //for (auto t_pair : tracks_)
53  //  {
54  //    if (t_pair.second.GetParentId() == track.GetTrackId())
55  //      {daughters.push_back(t_pair.second);}
56  //  }
57    return daughters;
58  }
59
60  // create all the tracks and create the actual 
61  // tree
62  pub fn assemble(&mut self, hits : &mut Vec<McHit>) {
63    let mut trackmap = HashMap::<u32, Vec<McHit>>::new();
64    let mut nhits = hits.len();
65    while nhits > 0 {
66      let h = hits.pop().unwrap();
67      if trackmap.contains_key(&h.track_id) {
68        trackmap.get_mut(&h.track_id).unwrap().push(h);
69      } else {
70        trackmap.insert(h.track_id, vec![h]);
71      }
72      nhits -= 1;
73    }
74    let mut tm_keys = Vec::<u32>::new();
75    for k in trackmap.keys() {
76      tm_keys.push(*k);
77    }
78    for k in &tm_keys {
79      trackmap.get_mut(&k).unwrap().sort_by(|i,j| i.glob_time.total_cmp(&j.glob_time));  
80    }
81    self.trackmap = trackmap;
82  }
83}
84
85impl fmt::Display for McTree {
86  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87    let mut repr = String::from("<McTree");
88    for k in self.trackmap.keys() {
89      repr += &(format!("\n  Track Id: {} -> NHits : {}",k, self.trackmap[k].len()));
90    }
91    repr += ">";
92    write!(f, "{}", repr) 
93  }
94}
95
96#[cfg(feature="pybindings")] 
97#[pymethods] 
98impl McTree {
99}
100
101
102
103#[cfg(feature="pybindings")]
104pythonize!(McTree);