00001
00002
00003
00004
00095 #ifndef StiHitContainer_HH
00096 #define StiHitContainer_HH
00097
00098 #include <vector>
00099 #include <map>
00100 #include <time.h>
00101 #include <Stiostream.h>
00102 #include "Stiostream.h"
00103
00104 #include "Sti/Base/Named.h"
00105 #include "Sti/Base/Described.h"
00106 #include "Sti/Base/Filter.h"
00107 #include "Sti/Base/Factory.h"
00108 #include "Sti/StiMapUtilities.h"
00109 #include "Sti/StiHit.h"
00110 #include "Sti/StiDetector.h"
00111 #include "Sti/StiKalmanTrackNode.h"
00112 using namespace std;
00113
00115 class VectorAndEnd
00116 {
00117 private:
00118 bool fEffectiveEndValid;
00119 vector<StiHit*>::iterator theEffectiveEnd;
00120 protected:
00121 friend class StiHitContainer;
00122 vector<StiHit*>::iterator TheEffectiveEnd() {
00123 return fEffectiveEndValid ? theEffectiveEnd
00124 : theHitVec.end();
00125 }
00126 public:
00127 VectorAndEnd();
00128 void TestId(int id);
00129 vector<StiHit*> theHitVec;
00130 int fId;
00131 static int fIdCounter;
00132 void clear();
00133 void setEnd(vector<StiHit*>::iterator &endHit) {
00134 theEffectiveEnd = endHit;
00135 fEffectiveEndValid = true;
00136 }
00137 void invalidateEnd(){ fEffectiveEndValid = false; }
00138 vector<StiHit*> &hits() { return theHitVec; }
00139 const vector<StiHit*> &hits() const { return theHitVec; }
00140 size_t size() const { return theHitVec.size(); }
00141 void push_back(StiHit *hit) { theHitVec.push_back(hit); }
00142 vector<StiHit*>::iterator begin() { return theHitVec.begin() ; }
00143 };
00145 typedef map<HitMapKey, VectorAndEnd, MapKeyLessThan> HitMapToVectorAndEndType;
00146
00148 typedef HitMapToVectorAndEndType::value_type HitMapToVectorAndEndTypeValType;
00149
00150 class StiHitContainer : public Named, public Described
00151 {
00152 public:
00153
00154 StiHitContainer(const string & name, const string & description, Factory<StiHit> *factory);
00155 virtual ~StiHitContainer();
00156 virtual void add(StiHit*);
00157 virtual unsigned int size() const;
00158 virtual void reset();
00159 virtual void unset(){;}
00160 virtual void clear();
00161
00162 virtual void sortHits();
00163
00164 void partitionUsedHits();
00165 vector<StiHit*> & getHits();
00166 vector<StiHit*> & getHits(Filter<StiHit> & filter);
00167 vector<StiHit*> & getHits(StiHit& ref, double dY, double dZ, bool fetchAll=false);
00168 vector<StiHit*> & getHits(double position, double refAngle, double y, double z,
00169 double dY, double dZ, bool fetchAll=false);
00170 vector<StiHit*> & getHits(StiKalmanTrackNode &, bool fetchAll=false);
00171 vector<StiHit*> & getHits(double refangle, double position);
00172 vector<StiHit*> & getHits(const StiDetector*);
00173 vector<StiHit*>::iterator hitsBegin(const StiDetector*);
00174 vector<StiHit*>::iterator hitsEnd(const StiDetector*);
00175 const HitMapToVectorAndEndType& hits() const;
00176 HitMapToVectorAndEndType& hits();
00177 StiHit * getNearestHit(StiHit& ref, double dY, double dZ, bool fetchAll=false);
00178 StiHit * getNearestHit(double position, double refAngle, double y, double z,
00179 double dY, double dZ, bool fetchAll=false);
00181 Factory<StiHit> * getHitFactory();
00183 StiHit * getHit();
00184 bool hasKey(double refangle, double position);
00185 bool hasDetector(const StiDetector* layer);
00186 protected:
00187
00188 HitMapToVectorAndEndType::key_type _key;
00189
00190 StiHit _minPoint;
00191
00192 StiHit _maxPoint;
00193
00194 StiHit _utilityHit;
00195
00196 vector<StiHit*>::iterator _start;
00197
00198 vector<StiHit*>::iterator _stop;
00199
00200 vector<StiHit*> _selectedHits;
00201
00202 HitMapToVectorAndEndType _map;
00203 Factory<StiHit> * _hitFactory;
00204
00205 friend ostream& operator<<(ostream&, const StiHitContainer&);
00206
00207 private:
00208 StiHitContainer();
00209 };
00210
00211 inline const HitMapToVectorAndEndType& StiHitContainer::hits() const
00212 {
00213 return _map;
00214 }
00215
00216 inline HitMapToVectorAndEndType& StiHitContainer::hits()
00217 {
00218 return _map;
00219 }
00220
00224 inline vector<StiHit*> & StiHitContainer::getHits(double position, double refAngle,double y, double z,
00225 double dY, double dZ, bool fetchAll)
00226 {
00227 _utilityHit.set(position,refAngle,y,z);
00228 return getHits(_utilityHit,dY,dZ,fetchAll);
00229 }
00230
00232 inline vector<StiHit*> & StiHitContainer::getHits(StiKalmanTrackNode & node, bool fetchAll)
00233 {
00234 _utilityHit.set(node.getRefPosition(),node.getLayerAngle(),node.getY(),node.getZ());
00235 return getHits(_utilityHit,node.getWindowY(),node.getWindowZ(), fetchAll);
00236 }
00237
00249 inline vector<StiHit*>& StiHitContainer::getHits(double refangle, double position)
00250 {
00251 _key.refangle = refangle;
00252 _key.position = position;
00253 assert(_map.find(_key) != _map.end());
00254 return _map[_key].theHitVec;
00255 }
00256 inline bool StiHitContainer::hasKey(double refangle, double position)
00257 {
00258 HitMapToVectorAndEndType::key_type key;
00259 key.refangle = refangle;
00260 key.position = position;
00261 return _map.find(key) != _map.end();
00262 }
00263 inline bool StiHitContainer::hasDetector(const StiDetector* layer)
00264 {
00265 double refangle = layer->getPlacement()->getLayerAngle();
00266 double position = layer->getPlacement()->getLayerRadius();
00267 return layer ? hasKey(refangle,position) : false;
00268 }
00270 inline vector<StiHit*>& StiHitContainer::getHits(const StiDetector* layer)
00271 {
00272 _key.refangle = layer->getPlacement()->getLayerAngle();
00273 _key.position = layer->getPlacement()->getLayerRadius();
00274 assert(_map.find(_key) != _map.end());
00275 return _map[_key].theHitVec;
00276 }
00277
00278
00279 inline StiHit * StiHitContainer::getNearestHit(double position, double refAngle, double y, double z,
00280 double dY, double dZ, bool fetchAll)
00281 {
00282 _utilityHit.set(position,refAngle,y,z);
00283 return getNearestHit(_utilityHit,dY,dZ,fetchAll);
00284 }
00285
00286 inline Factory<StiHit> * StiHitContainer::getHitFactory()
00287 {
00288 if (_hitFactory)
00289 return _hitFactory;
00290 else
00291 throw runtime_error("StiHitContainer::getHitFactory() -I- _hitFactory is null");
00292 }
00293
00294 inline StiHit * StiHitContainer::getHit()
00295 {
00296 StiHit * hit = getHitFactory()->getInstance();
00297 hit->reset();
00298 return hit;
00299 }
00300
00301 ostream& operator<<(ostream&, const vector<StiHit*>&);
00302 ostream& operator<<(ostream&, const StiHitContainer&);
00303
00304
00305
00306
00307
00308 #endif