MarlinTPC  1.2.0
TPCHitMap.h
1 #ifndef TPCHITMAP_H
2 #define TPCHITMAP_H
3 
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <limits>
8 #include <sstream>
9 
10 #include <gear/TPCParameters.h>
11 #include <EVENT/LCEvent.h>
12 #include <IMPL/TrackerHitImpl.h>
13 #include <TVector3.h>
14 #include <kaldet/GearTPCKalDetector.h>
15 #include <kaldet/GearTPCCylinderMeasLayer.h>
16 
17 
18 
19 namespace marlintpc
20 {
21 
22 class TPCHitDomain;
23 
31 {
32  EVENT::TrackerHit* hit;
33  bool isUsed;
34 
35  MarlinTPCHit(EVENT::TrackerHit* _hit_ = 0, bool _isUsed_ = false)
36  : hit(_hit_), isUsed(_isUsed_)
37  {}
38 
39  //We just compare the z coordinate and hit pointer, ignore isUsed.
40  //Then, if a MarlinTPCHit type hit, which has the same z and pointer with
41  //a MarlinTPCHit in a container(say, a set), can not be added.
42  bool operator<(const MarlinTPCHit &h) const
43  {
44  //Mainly sort the hits according to the z coordinate
45  if( sqrt(hit->getPosition()[2]) == sqrt(h.hit->getPosition()[2]) )
46  {
47  return hit < h.hit;
48  }
49  else
50  {
51  return sqrt(hit->getPosition()[2]) < sqrt(h.hit->getPosition()[2]);
52  }
53  }
54 
55  bool operator == (const MarlinTPCHit &h) const
56  {
57  return hit == h.hit;
58  }
59 
60  MarlinTPCHit& operator = (const MarlinTPCHit &h)
61  {
62  hit = h.hit;
63  isUsed = h.isUsed;
64 
65  return *this;
66  }
67 };
68 
69 typedef std::set< MarlinTPCHit >::iterator HitSetIter;
70 typedef std::pair<int, int> ModuleRow;
71 typedef std::map< ModuleRow, std::set< MarlinTPCHit > > HitContainer;
72 
80 {
81  int module;
82  int row;
83  MarlinTPCHit tpcHit;
84 
85  ModuleRowHit( int _module_ = std::numeric_limits<int>::max(),
86  int _row_ = std::numeric_limits<int>::max(),
87  MarlinTPCHit _tpcHit_= MarlinTPCHit() )
88  : module(_module_), row(_row_), tpcHit(_tpcHit_)
89  {}
90 
91  bool operator ==(const ModuleRowHit &h) const
92  {
93  return module == h.module && row == h.row && tpcHit == h.tpcHit;
94  }
95 
96  double const * getHitPosition() const { return tpcHit.hit->getPosition(); }
97  EVENT::TrackerHit* getTrackerHit() const {return tpcHit.hit;}
98 
99  bool isUsed() const {return tpcHit.isUsed;}
100 };
101 
105 {
106  public:
107  ModuleRowHitListSorter(TVector3 refPos): _referencePosition(refPos){}
108 
109  // the comparison operator for sort
110  bool operator()(ModuleRowHit const & mrh1, ModuleRowHit const & mrh2) const;
111 
112  private:
113  TVector3 _referencePosition;
114 };
115 
117 {
118  public:
119  TPCHitMap(gear::TPCParameters const * tpcParameters,
120  kaldet::GearTPCKalDetector const * det,
121  std::string modulesNotUsed = std::string("-1"));
122 
123  virtual ~TPCHitMap();
124 
134  void fillEventHits(EVENT::LCCollection const * inputHits);
135 
139  void removeHits(std::vector<ModuleRowHit>& hitlist);
140 
143  void removeHit(ModuleRowHit hit);
144 
147  void clear();
148 
151  size_t size() const ;
152 
155  ModuleRowHit getFirstHit(int mode = 0);
156 
159  bool isEmpty() const;
160 
163  std::list<ModuleRowHit> getHitsInDomain(std::set< ModuleRow > const & moduleRowsInDomain);
164 
165  ModuleRowHit getHitInDomain(std::set< ModuleRow > const & moduleRowsInDomain,
166  ModuleRowHit hit);
167 
168  static double getHitsDistance(ModuleRowHit& hit1, ModuleRowHit& hit2);
169 
172  std::list< ModuleRow > getActiveModuleRows();
173 
177  std::set< MarlinTPCHit > const & getHitsInModuleRow(int module, int row);
178 
181  void setHitUsed(const ModuleRowHit& hit, bool used = true);
182 
183  int getLayerIndex(int module, int row);
184 
185  protected:
188  HitContainer _hitContainer;
189 
190  std::map< int, std::set<ModuleRow> > _indexModuleRow;
191 
192  gear::TPCParameters const *_tpcParameters;
193 
194  size_t _nHits;
195 
196  kaldet::GearTPCKalDetector const * _kalDetector;
197 
198  std::set<int> _modulesNotUsedSet;
199 
200 };
201 
202 }
203 #endif //TPCHITMAP_H
std::set< MarlinTPCHit > const & getHitsInModuleRow(int module, int row)
Get all hits in one moduleRow.
size_t _nHits
The total number of hits currently stored in the container.
Definition: TPCHitMap.h:194
This is hits management class for TPC.
Definition: TPCHitMap.h:30
Struct to hold module and row and a hit in this row.
Definition: TPCHitMap.h:79
void fillEventHits(EVENT::LCCollection const *inputHits)
Fill hits to this data container and arrange them by module and row.
A helper function to allow sorting of a std::list of ModuleRowHits according to their distance to a r...
Definition: TPCHitMap.h:104
void setHitUsed(const ModuleRowHit &hit, bool used=true)
Set the used flag in the hits container.
Definition: TPCHitMap.h:116
void removeHit(ModuleRowHit hit)
Remove a hit from the container.
bool isEmpty() const
Check if the container is empty.
void clear()
Clear all hits.
void removeHits(std::vector< ModuleRowHit > &hitlist)
Remove hits from the container and empties the input hit list as the ModuleRowHits in it are invalida...
HitContainer _hitContainer
The hits container.
Definition: TPCHitMap.h:188
std::list< ModuleRow > getActiveModuleRows()
Get a list of all the module/rows pairs which have at least one hit.
std::list< ModuleRowHit > getHitsInDomain(std::set< ModuleRow > const &moduleRowsInDomain)
Get Hits from a TPC domain.
size_t size() const
Get hit size of container.
ModuleRowHit getFirstHit(int mode=0)
Get the first hit from the container.