9 #include "Sti/Base/Filter.h"
10 #include "StiKalmanTrackNode.h"
12 #include "StiPlacement.h"
13 #include "StiDetector.h"
14 #include "StiHitContainer.h"
19 using std::lower_bound;
20 using std::upper_bound;
21 using std::stable_partition;
22 ostream& operator<<(ostream& os,
const StiHit&
hit);
23 ostream& operator<<(ostream&,
const HitMapKey&);
25 int VectorAndEnd::fIdCounter = 0;
27 VectorAndEnd::VectorAndEnd(): fEffectiveEndValid(false)
31 theEffectiveEnd=theHitVec.end();
36 void VectorAndEnd::TestId(
int id)
43 void VectorAndEnd:: clear()
49 StiHitContainer::StiHitContainer(
const string & name,
50 const string & description,
54 _hitFactory(hitFactory)
56 cout <<
"StiHitContainer::StiHitContainer() -I- Started with name:"<<name<<endl;
62 StiHitContainer::~StiHitContainer()
64 cout <<
"StiHitContainer::~StiHitContainer()"<<endl;
93 _key.refangle = det->getPlacement()->getLayerAngle();
94 _key.position = det->getPlacement()->getLayerRadius();
95 _map[_key].push_back(hit);
100 void StiHitContainer::reset()
102 HitMapToVectorAndEndType::iterator it;
103 vector<StiHit*>::iterator iter;
105 for (it=_map.begin(); it!=_map.end(); it++)
107 vector<StiHit*> &hits = (*it).second.hits();
109 for (iter=hits.begin();iter!=hits.end();iter++)
111 (*iter)->setTimesUsed(0);
125 HitMapToVectorAndEndType::iterator it;
126 for (it=_map.begin(); it!=_map.end(); it++)
128 (*it).second.clear();
140 unsigned int thesize = 0;
141 HitMapToVectorAndEndType::const_iterator it;
142 for (it=_map.begin(); it!=_map.end(); it++) {
143 thesize+=(*it).second.size();
151 vector<StiHit*>::iterator StiHitContainer::hitsBegin(
const StiDetector* layer)
154 _key.refangle = layer->getPlacement()->getLayerAngle();
156 _key.position = layer->getPlacement()->getLayerRadius();
157 assert(_map.find(_key) != _map.end());
158 return _map[_key].begin();
162 vector<StiHit*>::iterator StiHitContainer::hitsEnd(
const StiDetector* layer)
165 _key.refangle = layer->getPlacement()->getLayerAngle();
167 _key.position = layer->getPlacement()->getLayerRadius();
168 assert(_map.find(_key) != _map.end());
169 return _map[_key].TheEffectiveEnd();
201 _selectedHits.clear();
211 if (_map.find(_key) != _map.end()) {
212 vector<StiHit*>& tempvec = _map[_key].hits();
217 vector<StiHit*>::iterator tempend = _map[_key].TheEffectiveEnd();
220 vector<StiHit*>::iterator tmptest = tempvec.begin();
221 vector<StiHit*>::iterator tmpend = tempvec.end();
222 if (!tempvec.size() ) {
223 cout <<
"-- Doing tmptest for id:" <<
id<<
" " << ( tmpend != tmptest )
224 <<
" cmp " << ( tempend != tmptest )
225 <<
" " << tempvec.size() <<
" --> " << endl;
230 _start = lower_bound(tempvec.begin(), tempend, &_minPoint,
StizHitLessThan());
232 _stop = upper_bound(tempvec.begin(), tempend, &_maxPoint,
StizHitLessThan());
240 for (vector<StiHit*>::iterator cit=_start; cit!=_stop; cit++)
243 if (fabs( hit->y() - ref.y() ) < dY)
245 if (fetchAll || (hit->
isUsed()==0 && hit->
detector()->isActive()) )
246 _selectedHits.push_back(hit);
254 return _selectedHits;
274 HitMapToVectorAndEndType::iterator it;
275 for (it=_map.begin(); it!=_map.end(); ++it)
277 vector<StiHit*>& tempvec = (*it).second.hits();
279 (*it).second.invalidateEnd();
285 ostream& operator<<(ostream& os, const vector<StiHit*>& vec)
287 for (vector<StiHit*>::const_iterator vit=vec.begin(); vit!=vec.end(); vit++) {
296 for (HitMapToVectorAndEndType::const_iterator it=store._map.begin(); it!=store._map.end(); it++) {
298 os <<(*it).second.hits();
309 _selectedHits.clear();
310 for(HitMapToVectorAndEndType::const_iterator iter= _map.begin(); iter !=_map.end(); iter++)
312 const vector<StiHit*> & t_hits = (*iter).second.hits();
313 for (vector<StiHit*>::const_iterator it=t_hits.begin();it!=t_hits.end();++it)
314 _selectedHits.push_back(*it);
316 return _selectedHits;
325 _selectedHits.clear();
327 for(HitMapToVectorAndEndType::const_iterator iter= _map.begin(); iter !=_map.end(); iter++)
329 const vector<StiHit*> & t_hits = (*iter).second.hits();
330 for (vector<StiHit*>::const_iterator it=t_hits.begin();
335 if (filter.accept(hit)) _selectedHits.push_back(hit);
338 return _selectedHits;
343 StiHit * StiHitContainer::getNearestHit(
StiHit& ref,
double dY,
double dZ,
bool fetchAll)
347 double dMax = DBL_MAX;
349 vector<StiHit*> & hits =
getHits(ref,dY,dZ,fetchAll);
350 for (vector<StiHit*>::iterator iter=hits.begin();iter!=hits.end();++iter)
353 dy = hit->y() - ref.y();
354 dz = hit->z() - ref.z();
368 for(HitMapToVectorAndEndType::const_iterator iter= _map.begin(); iter !=_map.end(); iter++)
370 const vector<StiHit*> & t_hits = (*iter).second.hits();
371 for (vector<StiHit*>::const_iterator it=t_hits.begin();it!=t_hits.end();++it)
372 (*it)->setMaxTimes(nTimes);
virtual void add(StiHit *)
vector< StiHit * > & getHits()
Get hits selected by the given filter. If no filter is given (i.e. filter==0)
const StiDetector * detector() const
Float_t refangle() const
Return the refAngle of the detector plane from which the hit arose.
virtual unsigned int size() const
Float_t position() const
Return the position of the detector plane from which the hit arose.
void setMaxTimes(int nTimes)
Set max time for all hits.