29 long long totLockHits;
31 totGroup=totSeg=totLockHits=0;
33 void incr(
long long g,
long long s,
long long l) {
39 std::cout <<
"TrajectorySegmentBuilder stat\nGroup/Seg/Lock "
40 << totGroup<<
'/'<<totSeg<<
'/'<<totLockHits
43 StatCount() {
zero();}
44 ~StatCount() {
print();}
49 void incr(
long long,
long long,
long long){}
66 theLockedHits.clear();
67 TempTrajectory startingTrajectory(theFullPropagator.propagationDirection());
71 vector<TMG> measGroups =
72 theLayerMeasurements->groupedMeasurements(theLayer,startingState,theFullPropagator,theEstimator);
76 cout <<
"TSB: number of measurement groups = " << measGroups.size() << endl;
87 for (vector<TMG>::const_iterator ig=measGroups.begin();
88 ig!=measGroups.end(); ++ig) {
90 const vector<TM>& measurements = ig->measurements();
91 for ( vector<TM>::const_iterator im=measurements.begin();
92 im!=measurements.end(); ++im ) {
93 if ( im->recHit()->isValid() ) ngrp++;
96 if ( ngrp>0 ) ntot *= ngrp;
99 cout <<
"TrajectorySegmentBuilder::partialTrajectories:: det ids & hit types / group" << endl;
100 for (vector<TMG>::const_iterator ig=measGroups.begin();
101 ig!=measGroups.end(); ++ig) {
102 const vector<TM>& measurements = ig->measurements();
103 for ( vector<TM>::const_iterator im=measurements.begin();
104 im!=measurements.end(); ++im ) {
105 if ( im!=measurements.begin() )
cout <<
" / ";
106 if ( im->recHit()->det() )
107 cout << im->recHit()->det()->geographicalId().rawId() <<
" "
108 << im->recHit()->getType();
117 cout <<
typeid(theLayer).
name() << endl;
136 addGroup(startingTrajectory,measGroups.begin(),measGroups.end());
138 if (theDbgFlg)
cout <<
"TSB: back with " << candidates.size() <<
" candidates" << endl;
145 updateWithInvalidHit(startingTrajectory,measGroups,candidates);
147 if (theDbgFlg)
cout <<
"TSB: " << candidates.size() <<
" candidates after invalid hit" << endl;
149 statCount.incr(measGroups.size(), candidates.size(), theLockedHits.size());
152 theLockedHits.clear();
163 if ( hit->isValid()) {
164 traj.
push(
TM( predictedState, theUpdator.
update( predictedState, *hit),
181 traj.
push(
TM( predictedState, hit,0, tm.
layer()));
188 vector<TMG>::const_iterator
begin,
189 vector<TMG>::const_iterator
end)
191 vector<TempTrajectory>
ret;
194 if (theDbgFlg)
cout <<
"TSB::addGroup : no groups left" << endl;
201 <<
" first group at " << &(*begin)
208 vector<TM> firstMeasurements = unlockedMeasurements(begin->measurements());
209 if ( theBestHitOnly )
210 updateCandidatesWithBestHit(traj,firstMeasurements,updatedTrajectories);
212 updateCandidates(traj,begin->
measurements(),updatedTrajectories);
213 if (theDbgFlg)
cout <<
"TSB::addGroup : updating with first group - "
214 << updatedTrajectories.size() <<
" trajectories" << endl;
217 if ( theBestHitOnly )
218 updateCandidatesWithBestHit(traj,redoMeasurements(traj,begin->detGroup()),
219 updatedTrajectories);
221 updateCandidates(traj,redoMeasurements(traj,begin->detGroup()),
222 updatedTrajectories);
223 if (theDbgFlg)
cout <<
"TSB::addGroup : updating"
224 << updatedTrajectories.size() <<
" trajectories" << endl;
227 if (begin+1 != end) {
229 for ( TempTrajectoryContainer::iterator it=updatedTrajectories.begin();
230 it!=updatedTrajectories.end(); ++it ) {
231 if (theDbgFlg)
cout <<
"TSB::addGroup : trying to extend candidate at "
232 << &(*it) <<
" size " << it->measurements().size() << endl;
233 vector<TempTrajectory> finalTrajectories = addGroup(*it,begin+1,end);
234 if (theDbgFlg)
cout <<
"TSB::addGroup : " << finalTrajectories.size()
235 <<
" finalised candidates before cleaning" << endl;
237 cleanCandidates(finalTrajectories);
239 if (theDbgFlg)
cout <<
"TSB::addGroup : got " << finalTrajectories.size()
240 <<
" finalised candidates" << endl;
241 ret.insert(ret.end(),finalTrajectories.begin(),
242 finalTrajectories.end());
245 ret.reserve(updatedTrajectories.size());
246 for (TempTrajectoryContainer::iterator it=updatedTrajectories.begin();
247 it!=updatedTrajectories.end(); ++it ) {
248 if (!it->empty()) ret.push_back(*it);
262 const vector<TM>& measurements,
268 for ( vector<TM>::const_iterator im=measurements.begin();
269 im!=measurements.end(); ++im ) {
270 if ( im->recHit()->isValid() ) {
271 candidates.push_back(traj);
272 updateTrajectory(candidates.back(),*im);
273 if ( theLockHits ) lockMeasurement(*im);
279 candidates.push_back(traj);
284 const vector<TM>& measurements,
287 vector<TM>::const_iterator ibest = measurements.begin();
289 while(ibest!=measurements.end() && !ibest->recHit()->isValid()) ++ibest;
290 if ( ibest!=measurements.end() ) {
292 for ( vector<TM>::const_iterator im=ibest+1;
293 im!=measurements.end(); ++im ) {
294 if ( im->recHit()->isValid() &&
295 im->estimate()<ibest->estimate()
301 if ( theLockHits ) lockMeasurement(*ibest);
302 candidates.push_back(traj);
303 updateTrajectory(candidates.back(),*ibest);
306 cout <<
"TSB: found best measurement at "
307 << ibest->recHit()->globalPosition().perp() <<
" "
308 << ibest->recHit()->globalPosition().phi() <<
" "
309 << ibest->recHit()->globalPosition().z() << endl;
316 candidates.push_back(traj);
319 vector<TrajectoryMeasurement>
327 if (theDbgFlg)
cout <<
"TSB::redoMeasurements : nr. of measurements / group =";
329 for (DetGroup::const_iterator idet=detGroup.begin();
330 idet!=detGroup.end(); ++idet) {
336 pair<bool, TrajectoryStateOnSurface> compat =
339 theGeomPropagator,theEstimator);
341 if (theDbgFlg && !compat.first)
cout <<
" 0";
343 if(!compat.first)
continue;
344 const MeasurementDet* mdet = theMeasurementTracker->idToDet(idet->det()->geographicalId());
346 = mdet->
fastMeasurements( compat.second, idet->trajectoryState(), theGeomPropagator, theEstimator);
358 if (theDbgFlg)
cout <<
" " << tmp.size();
360 for(vector<TM>::iterator tmpIt=tmp.begin(); tmpIt!=tmp.end(); ++tmpIt){
361 if ( tmpIt->recHit()->isValid() ) {
362 tmpIt->setLayer(&theLayer);
363 result.push_back(*tmpIt);
367 if (theDbgFlg)
cout << endl;
374 const vector<TMG>& groups,
383 for ( vector<TMG>::const_iterator ig=groups.begin(); ig!=groups.end(); ++ig) {
385 const vector<TM>& measurements = ig->measurements();
386 for ( vector<TM>::const_reverse_iterator im=measurements.rbegin();
387 im!=measurements.rend(); ++im ) {
396 TSOS predState(im->predictedState());
398 (predState.isValid() &&
399 hit->det()->surface().bounds().inside(predState.localPosition())) ) {
404 candidates.push_back(traj);
405 updateTrajectory(candidates.back(), *im);
406 if ( theDbgFlg )
cout <<
"TrajectorySegmentBuilder::updateWithInvalidHit "
407 <<
"added inactive hit" << endl;
422 for ( vector<TMG>::const_iterator ig=groups.begin();
423 ig!=groups.end(); ++ig) {
424 const vector<TM>& measurements = ig->measurements();
425 for ( vector<TM>::const_reverse_iterator im=measurements.rbegin();
426 im!=measurements.rend(); ++im ) {
431 if ( hit->isValid() )
continue;
436 TSOS predState(im->predictedState());
438 if (
iteration>0 || (predState.isValid() &&
439 hit->det()->surface().bounds().inside(predState.localPosition())) ) {
444 candidates.push_back(traj);
445 updateTrajectory(candidates.back(), *im);
451 if (
iteration>0 || (predState.isValid() &&
452 im->layer()->surface().bounds().inside(predState.localPosition())) ){
457 candidates.push_back(traj);
458 updateTrajectory(candidates.back(), *im);
466 if ( theDbgFlg && !found )
cout <<
"TrajectorySegmentBuilder::updateWithInvalidHit: "
467 <<
" did not find invalid hit on 1st iteration" << endl;
471 if (theDbgFlg)
cout <<
"TrajectorySegmentBuilder::updateWithInvalidHit: "
472 <<
" did not find invalid hit" << endl;
476 vector<TrajectoryMeasurement>
483 result.reserve(measurements.size());
487 for ( vector<TM>::const_iterator im=measurements.begin();
488 im!=measurements.end(); ++im ) {
490 if ( !testHit->isValid() )
continue;
493 for ( ConstRecHitContainer::const_iterator ih=theLockedHits.begin();
494 ih!=theLockedHits.end(); ++ih ) {
501 if ( !found ) result.push_back(*im);
511 theLockedHits.push_back(measurement.
recHit());
524 if ( candidates.size()<=1 )
return;
527 vector<TempTrajectory> sortedCandidates(candidates);
535 for ( vector<TempTrajectory>::iterator i1=sortedCandidates.begin();
536 i1!=sortedCandidates.end()-1; ++i1 ) {
539 for ( vector<TempTrajectory>::iterator i2=i1+1;
540 i2!=sortedCandidates.end(); ++i2 ) {
542 if ( i2->foundHits()==i1->foundHits() )
continue;
552 im1!=im1end; --im1 ) {
554 if ( !im1->recHit()->isValid() )
continue;
557 im2!=im2end; --im2 ) {
559 if ( !im2->recHit()->isValid() )
continue;
562 from2 = im2; --from2;
571 if ( allFound ) i1->invalidate();
581 candidates.erase(std::remove_if( candidates.begin(),candidates.end(),
585 if (theMaxSegments >=0 && candidates.size() > (
unsigned int)theMaxSegments){
586 unsigned int nExtra = candidates.size() - theMaxSegments;
588 candidates.erase(candidates.begin(), candidates.begin()+nExtra);
591 cout <<
"TSB: cleanCandidates: reduced from " << sortedCandidates.size()
592 <<
" to " << candidates.size() <<
" candidates" << endl;
const_iterator rend() const
void updateCandidatesWithBestHit(TempTrajectory &traj, const std::vector< TM > &measurements, TempTrajectoryContainer &candidates)
creation of a new candidate from a segment and the best hit out of a collection
bool empty() const
True if trajectory has no measurements.
void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
std::vector< TempTrajectory > TempTrajectoryContainer
void cleanCandidates(std::vector< TempTrajectory > &candidates) const
clean a set of candidates
void updateCandidates(TempTrajectory &traj, const std::vector< TM > &measurements, TempTrajectoryContainer &candidates)
creation of new candidates from a segment and a collection of hits
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
const DataContainer & measurements() const
std::vector< TrajectoryMeasurement > unlockedMeasurements(const std::vector< TM > &measurements) const
get list of unused hits
ConstRecHitPointer recHit() const
static std::pair< bool, TrajectoryStateOnSurface > isCompatible(const GeomDet *theDet, const TrajectoryStateOnSurface &ts, const Propagator &prop, const MeasurementEstimator &est)
TempTrajectoryContainer segments(const TSOS startingState)
new segments within layer
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
const TrajectoryMeasurement & lastMeasurement() const
void lockMeasurement(const TM &measurement)
mark a hit as used
std::vector< TrajectoryMeasurement > redoMeasurements(const TempTrajectory &traj, const DetGroup &detGroup) const
retrieve compatible hits from a DetGroup
virtual std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &startingState, const Propagator &, const MeasurementEstimator &) const =0
const DetLayer * layer() const
TrajectoryStateOnSurface updatedState() const
const AlgebraicSymMatrix55 & matrix() const
TrajectoryStateOnSurface predictedState() const
const LocalTrajectoryError & localError() const
std::vector< TempTrajectory > addGroup(TempTrajectory &traj, std::vector< TrajectoryMeasurementGroup >::const_iterator begin, std::vector< TrajectoryMeasurementGroup >::const_iterator end)
std::vector< std::vector< double > > tmp
void updateTrajectory(TempTrajectory &traj, const TM &tm) const
update of a trajectory with a hit
void push(const TrajectoryMeasurement &tm)
void updateWithInvalidHit(TempTrajectory &traj, const std::vector< TMG > &groups, TempTrajectoryContainer &candidates) const