HitMap.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file HitMap.cxx
3 // \brief Efficient lookup of hits by plane and cell number
4 // \version $Id: HitMap.cxx,v 1.7 2012-05-11 00:39:30 bckhouse Exp $
5 // \author $Author: bckhouse $
6 ////////////////////////////////////////////////////////////////////////
7 #include "RecoBase/HitMap.h"
8 
9 #include "RecoBase/CellHit.h"
10 #include "RecoBase/Cluster.h"
11 
12 namespace rb
13 {
14  //------------------------------------------------------------
16  {
17  }
18 
19  //------------------------------------------------------------
21  {
22  Add(chits);
23  }
24 
25  //------------------------------------------------------------
27  {
28  Add(clust);
29  }
30 
31  //------------------------------------------------------------
33  {
34  }
35 
36  //------------------------------------------------------------
38  {
39  const geo::OfflineChan chan(chit->Plane(), chit->Cell());
40 
41  typedef std::map<geo::OfflineChan, art::Ptr<rb::CellHit> >::iterator it_t;
42  it_t it = fMap.find(chan);
43 
44  if(it == fMap.end()){
45  // If there's no hit on this channel, store this one there
46  fMap.insert(std::make_pair(chan, chit));
47  }
48  else{
49  // If there already was a hit, highest energy wins
50  if(chit->PE() > it->second->PE()){
51  it->second = chit;
52  }
53  else{
54  // Discard this hit
55  }
56  }
57  }
58 
59  //------------------------------------------------------------
61  {
62  const unsigned int N = chits.size();
63  for(unsigned int n = 0; n < N; ++n) Add(chits[n]);
64  }
65 
66  //------------------------------------------------------------
67  void HitMap::Add(const rb::Cluster* clust)
68  {
69  const int maxIdx = clust->NCell();
70  for(int idx = 0; idx < maxIdx; ++idx)
71  Add(clust->Cell(idx));
72  }
73 
74  //------------------------------------------------------------
75  void HitMap::Remove(unsigned int plane, unsigned int cell)
76  {
77  fMap.erase(geo::OfflineChan(plane, cell));
78  }
79 
80  //------------------------------------------------------------
81  bool HitMap::CellExists(unsigned int plane,
82  unsigned int cell) const
83  {
84  return fMap.find(geo::OfflineChan(plane, cell)) != fMap.end();
85  }
86 
87  //------------------------------------------------------------
89  unsigned int cell) const
90  {
91  std::map<geo::OfflineChan, art::Ptr<rb::CellHit> >::const_iterator it =
92  fMap.find(geo::OfflineChan(plane, cell));
93 
94  if(it == fMap.end()) return art::Ptr<rb::CellHit>();
95 
96  return it->second;
97  }
98 
99  //------------------------------------------------------------
101  unsigned int cellIdx) const
102  {
103  return Cell(planeIdx, cellIdx);
104  }
105 
106 } // end namespace rb
107 //////////////////////////////////////////////////////////////////////
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
std::map< geo::OfflineChan, art::Ptr< rb::CellHit > > fMap
Definition: HitMap.h:52
set< int >::iterator it
unsigned short Plane() const
Definition: CellHit.h:39
A collection of associated CellHits.
Definition: Cluster.h:47
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
unsigned short Cell() const
Definition: CellHit.h:40
float PE() const
Definition: CellHit.h:42
void Remove(unsigned int planeIdx, unsigned int cellIdx)
Definition: HitMap.cxx:75
Perform a "2 point" Hough transform on a collection of hits.
size_type size() const
Definition: PtrVector.h:308
art::Ptr< rb::CellHit > Cell(unsigned int planeIdx, unsigned int cellIdx) const
Return the cell at this position. Empty pointer if no match.
Definition: HitMap.cxx:88
art::Ptr< rb::CellHit > Cell(geo::View_t view, unsigned int viewIdx) const
Get the ith cell from view view.
Definition: Cluster.cxx:145
A (plane, cell) pair.
Definition: OfflineChan.h:17
art::Ptr< rb::CellHit > operator()(unsigned int planeIdx, unsigned int cellIdx) const
Syntactic sugar for Cell.
Definition: HitMap.cxx:100
bool CellExists(unsigned int planeIdx, unsigned int cellIdx) const
Does the map contain any cell at this position?
Definition: HitMap.cxx:81
void Add(const art::Ptr< rb::CellHit > &chit)
Definition: HitMap.cxx:37