StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiHitContainer.h
1 //StiHitContainer.h
2 //M.L. Miller (Yale Software)
3 //03/01
4 
95 #ifndef StiHitContainer_HH
96 #define StiHitContainer_HH
97 
98 #include <cassert>
99 #include <vector>
100 #include <map>
101 #include <time.h>
102 #include <Stiostream.h>
103 #include "Stiostream.h"
104 
105 #include "Sti/Base/Named.h"
106 #include "Sti/Base/Described.h"
107 #include "Sti/Base/Filter.h"
108 #include "Sti/Base/Factory.h"
109 #include "Sti/StiMapUtilities.h"
110 #include "Sti/StiHit.h"
111 #include "Sti/StiDetector.h"
112 #include "Sti/StiKalmanTrackNode.h"
113 using namespace std;
114 
117 {
118  private:
119  bool fEffectiveEndValid;
120  vector<StiHit*>::iterator theEffectiveEnd;
121 protected:
122  friend class StiHitContainer;
123  vector<StiHit*>::iterator TheEffectiveEnd() {
124  return fEffectiveEndValid ? theEffectiveEnd
125  : theHitVec.end();
126  }
127  public:
128  VectorAndEnd();
129  void TestId(int id);
130  vector<StiHit*> theHitVec;
131  int fId;
132  static int fIdCounter;
133  void clear();
134  void setEnd(vector<StiHit*>::iterator &endHit) {
135  theEffectiveEnd = endHit;
136  fEffectiveEndValid = true;
137  }
138  void invalidateEnd(){ fEffectiveEndValid = false; }
139  vector<StiHit*> &hits() { return theHitVec; }
140  const vector<StiHit*> &hits() const { return theHitVec; }
141  size_t size() const { return theHitVec.size(); }
142  void push_back(StiHit *hit) { theHitVec.push_back(hit); }
143  vector<StiHit*>::iterator begin() { return theHitVec.begin() ; }
144  };
146 typedef map<HitMapKey, VectorAndEnd, MapKeyLessThan> HitMapToVectorAndEndType;
147 
149 typedef HitMapToVectorAndEndType::value_type HitMapToVectorAndEndTypeValType;
150 
151 class StiHitContainer : public Named, public Described
152 {
153 public:
154 
155  StiHitContainer(const string & name, const string & description, Factory<StiHit> *factory);
156  virtual ~StiHitContainer();
157  virtual void add(StiHit*);
158  virtual unsigned int size() const;
159  virtual void reset();
160  virtual void unset(){;}
161  virtual void clear();
162  //Sort all of the hits in the container.
163  virtual void sortHits();
164  void setMaxTimes(int nTimes);
165  vector<StiHit*> & getHits();
166  vector<StiHit*> & getHits(Filter<StiHit> & filter);
167  vector<StiHit*> & getHits(StiHit& ref, double dY, double dZ, bool fetchAll=false);
168  vector<StiHit*> & getHits(double position, double refAngle, double y, double z,
169  double dY, double dZ, bool fetchAll=false);
170  vector<StiHit*> & getHits(StiKalmanTrackNode &, bool fetchAll=false);
171  vector<StiHit*> & getHits(double refangle, double position);
172  vector<StiHit*> & getHits(const StiDetector*);
173  vector<StiHit*>::iterator hitsBegin(const StiDetector*);
174  vector<StiHit*>::iterator hitsEnd(const StiDetector*);
175  const HitMapToVectorAndEndType& hits() const;
176  HitMapToVectorAndEndType& hits();
177  StiHit * getNearestHit(StiHit& ref, double dY, double dZ, bool fetchAll=false);
178  StiHit * getNearestHit(double position, double refAngle, double y, double z,
179  double dY, double dZ, bool fetchAll=false);
181  Factory<StiHit> * getHitFactory();
183  StiHit * getHit();
184  bool hasKey(double refangle, double position);
185  bool hasDetector(const StiDetector* layer);
186  protected:
187  // Utility key used in hit retrieval (avoid constructor call per search)
188  HitMapToVectorAndEndType::key_type _key;
189  // Utility hit used as a minimum position in searches
190  StiHit _minPoint;
191  // Utility hit used as a maximum position in searches
192  StiHit _maxPoint;
193  // Utility hit used as the reference in searches
194  StiHit _utilityHit;
195  // Utility iterator to mark the position of a hit vector (avoid constructor call per search)
196  vector<StiHit*>::iterator _start;
197  // Utility iterator to mark the position of a hit vector (avoid constructor call per search)
198  vector<StiHit*>::iterator _stop;
199  // Utility hit vector used to return hits (avoid constructor call per search)
200  vector<StiHit*> _selectedHits;
201  // Actual Hit container used for storage of all hits
202  HitMapToVectorAndEndType _map;
203  Factory<StiHit> * _hitFactory;
204  // Utility ostream operator
205  friend ostream& operator<<(ostream&, const StiHitContainer&);
206 
207  private:
208  StiHitContainer();
209 };
210 
211 inline const HitMapToVectorAndEndType& StiHitContainer::hits() const
212 {
213  return _map;
214 }
215 
216 inline HitMapToVectorAndEndType& StiHitContainer::hits()
217 {
218  return _map;
219 }
220 
224 inline vector<StiHit*> & StiHitContainer::getHits(double position, double refAngle,double y, double z,
225  double dY, double dZ, bool fetchAll)
226 {
227  _utilityHit.set(position,refAngle,y,z);
228  return getHits(_utilityHit,dY,dZ,fetchAll);
229 }
230 
232 inline vector<StiHit*> & StiHitContainer::getHits(StiKalmanTrackNode & node, bool fetchAll)
233 {
234  _utilityHit.set(node.getRefPosition(),node.getLayerAngle(),node.getY(),node.getZ());
235  return getHits(_utilityHit,node.getWindowY(),node.getWindowZ(), fetchAll);
236 }
237 
249 inline vector<StiHit*>& StiHitContainer::getHits(double refangle, double position)
250 {
251  _key.refangle = refangle;
252  _key.position = position;
253  assert(_map.find(_key) != _map.end());
254  return _map[_key].theHitVec;
255 }
256 inline bool StiHitContainer::hasKey(double refangle, double position)
257 {
258  HitMapToVectorAndEndType::key_type key;
259  key.refangle = refangle;
260  key.position = position;
261  return _map.find(key) != _map.end();
262 }
263 inline bool StiHitContainer::hasDetector(const StiDetector* layer)
264 {
265  double refangle = layer->getPlacement()->getLayerAngle();
266  double position = layer->getPlacement()->getLayerRadius();
267  return hasKey(refangle,position);
268 }
270 inline vector<StiHit*>& StiHitContainer::getHits(const StiDetector* layer)
271 {
272  _key.refangle = layer->getPlacement()->getLayerAngle();
273  _key.position = layer->getPlacement()->getLayerRadius();
274  assert(_map.find(_key) != _map.end());
275  return _map[_key].theHitVec;
276 }
277 
278 
279 inline StiHit * StiHitContainer::getNearestHit(double position, double refAngle, double y, double z,
280  double dY, double dZ, bool fetchAll)
281 {
282  _utilityHit.set(position,refAngle,y,z);
283  return getNearestHit(_utilityHit,dY,dZ,fetchAll);
284 }
285 
287 {
288  assert(_hitFactory);
289  return _hitFactory;
290 }
291 
293 {
294  StiHit * hit = getHitFactory()->getInstance();
295  hit->reset();
296  return hit;
297 }
298 
299 ostream& operator<<(ostream&, const vector<StiHit*>&);
300 ostream& operator<<(ostream&, const StiHitContainer&);
301 
302 
303 
304 
305 
306 #endif
vector< StiHit * > & getHits()
Get hits selected by the given filter. If no filter is given (i.e. filter==0)
We define this globally for convenience of users.
StiHit * getHit()
Get a hit instance from the factory.
Definition: StiHit.h:51
Definition: Named.h:16
virtual void clear()
Factory< StiHit > * getHitFactory()
Get the hit factory.
virtual unsigned int size() const