38 edm::LogInfo(
"CosmicTrackFinder")<<
"Minimum number of hits "<<theMinHits<<
" Cut on Chi2= "<<
chi2cut;
88 RHBuilder= theBuilder.
product();
93 theFitter=
new KFTrajectoryFitter(*thePropagator,
112 vector<Trajectory> &trajoutput)
115 std::vector<Trajectory> trajSmooth;
116 std::vector<Trajectory>::iterator trajIter;
118 TrajectorySeedCollection::const_iterator
iseed;
120 for(iseed=collseed.begin();iseed!=collseed.end();iseed++){
127 Trajectory startingTraj = createStartingTrajectory(*iseed);
133 seed_plus = !seed_plus;
134 vector<const TrackingRecHit*> allHitsOppsite = SortHits(collstereo,collrphi,collmatched,collpixel, *iseed,
true);
135 seed_plus = !seed_plus;
136 if (!allHitsOppsite.empty())
141 AddHit( traj, allHitsOppsite, thePropagatorOp);
146 cout <<
"Hits in opposite direction..." << endl;
147 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
148 for ( iHit =
hits.begin(); iHit!=
hits.end(); iHit++)
150 cout << (**iHit).globalPosition() << endl;
159 tracker->idToDet((
hits.front())->geographicalId())->surface()).isValid()){
160 TSOS startingStateNew =
162 tracker->idToDet((
hits.front())->geographicalId())->surface()));
166 cout <<
"Hits in opposite direction reversed..." << endl;
167 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
168 for ( iHit =
hits.begin(); iHit!=
hits.end(); iHit++)
170 cout << (**iHit).globalPosition() << endl;
175 trajTmp = theFitter->fit(tmpseed,
hits, startingStateNew ).front();
178 cout <<
"Debugging show fitted hits" << endl;
179 auto hitsFit= trajTmp.
recHits();
180 for(
auto hit=hitsFit.begin();
hit!=hitsFit.end();
hit++){
182 cout << RHBuilder->build( &(*(*hit)->hit()) )->globalPosition() << endl;
190 if(debug_info)
cout <<
"There are no hits in opposite direction ..." << endl;
193 vector<const TrackingRecHit*> allHits;
197 allHits= SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
false);
203 allHits= SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
true);
206 AddHit( traj,allHits, thePropagator);
210 cout <<
"Debugging show All fitted hits" << endl;
214 cout << (*hit)->globalPosition() << endl;
217 cout << qualityFilter( traj) <<
" <- quality filter good?" << endl;
221 if (debug_info)
cout <<
"now do quality checks" << endl;
222 if ( qualityFilter( traj) ) {
224 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = innerState(traj);
225 if (initState.first.isValid())
226 trajFit = theFitter->fit(tmpseed,
hits, initState.first);
229 for (trajIter=trajFit.begin(); trajIter!=trajFit.end();trajIter++){
230 trajSmooth=theSmoother->trajectories((*trajIter));
232 for (trajIter= trajSmooth.begin(); trajIter!=trajSmooth.end();trajIter++){
233 if((*trajIter).isValid()){
235 if (debug_info)
cout <<
"adding track ... " << endl;
236 trajoutput.push_back((*trajIter));
241 delete thePropagator;
242 delete thePropagatorOp;
255 std::vector<TM> && seedMeas = seedMeasurements(seed);
261 std::vector<TrajectoryMeasurement>
264 std::vector<TrajectoryMeasurement>
result;
267 ihit != hitRange.second; ihit++) {
270 const GeomDet* hitGeomDet = (&(*tracker))->idToDet( ihit->geographicalId());
273 if (ihit == hitRange.second - 1) {
275 result.push_back(
std::move(
TM( invalidState, updatedState, recHit)));
279 result.push_back(
std::move(
TM( invalidState, recHit)));
287 vector<const TrackingRecHit*>
293 const bool bAddSeedHits
300 vector<const TrackingRecHit*> allHits;
307 if (debug_info)
cout <<
"SEED " << startingTSOS(seed) << endl;
308 if (debug_info)
cout <<
"seed hits size " << seed.
nHits() << endl;
317 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"SEED " << startingTSOS(seed);
328 int seedHitSize= hRange.second - hRange.first;
330 vector <int> detIDSeedMatched (seedHitSize);
331 vector <int> detIDSeedRphi (seedHitSize);
332 vector <int> detIDSeedStereo (seedHitSize);
334 for (ihit = hRange.first;
335 ihit != hRange.second; ihit++) {
342 if (ihit == hRange.first)
353 float_t yGlobStereo = RHBuilder->build(&
s)->globalPosition().y();
355 if (debug_info)
cout <<
"Rphi ..." << yGlobRPhi << endl;
356 if (debug_info)
cout <<
"Stereo ..." << yGlobStereo << endl;
358 if ( yGlobStereo < yMin ) yMin = yGlobStereo;
359 if ( yGlobRPhi < yMin ) yMin = yGlobRPhi;
361 if ( yGlobStereo > yMax ) yMax = yGlobStereo;
362 if ( yGlobRPhi > yMax ) yMax = yGlobRPhi;
365 detIDSeedRphi.push_back (
m.geographicalId().rawId() );
366 detIDSeedStereo.push_back (
s.geographicalId().rawId() );
373 hits.push_back((RHBuilder->build(&(*ihit))));
377 if ( ( (yGlobRPhi > yGlobStereo ) && seed_plus ) || ((yGlobRPhi < yGlobStereo ) && !seed_plus ))
379 hits.push_back((RHBuilder->build(&
m)));
380 hits.push_back((RHBuilder->build(&
s)));
384 hits.push_back((RHBuilder->build(&
s)));
385 hits.push_back((RHBuilder->build(&
m)));
391 else if (bAddSeedHits)
393 hits.push_back((RHBuilder->build(&(*ihit))));
394 detIDSeedRphi.push_back ( ihit->geographicalId().rawId() );
395 detIDSeedMatched.push_back ( -1 );
396 detIDSeedStereo.push_back ( -1 );
400 if ( yref < yMin ) yMin = yref;
401 if ( yref > yMax ) yMax = yref;
406 LogDebug(
"CosmicTrackFinder")<<
"SEED HITS"<<RHBuilder->build(&(*ihit))->globalPosition();
407 if (debug_info)
cout <<
"SEED HITS"<<RHBuilder->build(&(*ihit))->globalPosition() << endl;
413 yref = (seed_plus) ? yMin : yMax;
416 for(ipix=collpixel.
data().begin();ipix!=collpixel.
data().end();ipix++){
417 float ych= RHBuilder->build(&(*ipix))->globalPosition().y();
418 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
419 allHits.push_back(&(*ipix));
427 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++){
428 float ych= RHBuilder->build(&(*istripm))->globalPosition().y();
430 int cDetId=istripm->geographicalId().rawId();
431 bool noSeedDet = ( detIDSeedMatched.end() ==
find (detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId ) ) ;
434 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
435 allHits.push_back(&(*istripm));
439 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
440 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
442 if (monoDetId.partnerDetId())
444 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
447 int cDetId=istrip->geographicalId().rawId();
448 bool noSeedDet = ( detIDSeedRphi.end()==
find (detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId ) ) ;
450 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
453 bool hitIsUnique =
true;
455 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++)
458 if ( isDifferentStripReHit2D ( *istrip, (istripm->monoHit() ) ) ==
false)
461 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
468 allHits.push_back(&(*istrip));
478 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
479 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
480 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
481 allHits.push_back(&(*istrip));
484 for(istrip=collstereo.
data().begin();istrip!=collstereo.
data().end();istrip++){
485 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
486 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
487 allHits.push_back(&(*istrip));
500 if (debug_info)
cout <<
"all hits" << endl;
503 Trajectory startingTraj = createStartingTrajectory(seed);
509 vector<const TrackingRecHit*>::iterator iHit;
510 for (iHit=allHits.begin(); iHit<allHits.end(); iHit++)
512 GlobalPoint gphit=RHBuilder->build(*iHit)->globalPosition();
513 if (debug_info)
cout <<
"GH " << gphit << endl;
518 tracker->idToDet((*iHit)->geographicalId())->surface());
528 if (debug_info)
cout <<
"not valid" << endl;
531 if (debug_info)
cout <<
"all hits end" << endl;
542 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
550 const vector<const TrackingRecHit*>& _Hits,
Propagator *currPropagator){
551 vector<const TrackingRecHit*> Hits = _Hits;
555 if (debug_info)
cout <<
"CRackTrajectoryBuilder::AddHit" << endl;
558 vector <TrackingRecHitRange> hitRangeByDet;
561 prevDet = Hits.begin();
564 if ( (*prevDet)->geographicalId() == (*iHit)->geographicalId() )
567 hitRangeByDet.push_back( make_pair( prevDet, iHit ) );
570 hitRangeByDet.push_back( make_pair( prevDet, Hits.end() ) );
574 if (fastPropagation) {
581 tracker->idToDet(currDet)->surface());
593 double chi2min = theEstimator->estimate( prSt, *bestHit).second;
595 if (debug_info)
cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
598 if (debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
601 double currChi2 = theEstimator->estimate(prSt, *tmpHit).second;
602 if ( currChi2 < chi2min )
609 if (debug_info)
cout << chi2min << endl;
612 if (debug_info)
cout <<
"chi2 fine : " << chi2min << endl;
613 TSOS UpdatedState= theUpdator->
update( prSt, *bestHit );
615 hits.push_back(bestHit);
616 traj.
push(
TM(prSt,UpdatedState, bestHit, chi2min) );
618 "STATE UPDATED WITH HIT AT POSITION " 620 << bestHit->globalPosition()
623 if (debug_info)
cout <<
624 "STATE UPDATED WITH HIT AT POSITION " 626 << bestHit->globalPosition()
629 if (debug_info)
cout <<
"State is valid ..." << endl;
634 edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position " << endl;
635 TSOS UpdatedState= theUpdator->
update( prSt, *bestHit );
638 "NOT! UPDATED WITH HIT AT POSITION " 640 << bestHit->globalPosition()
658 std::vector < std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
659 std::vector <std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
660 std::vector <uint32_t> processedDets;
665 trackHitCandidates.clear();
672 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end() )
676 tracker->idToDet(currDet)->surface());
677 if ( ( !prSt.
isValid() ) || (theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface() ) ==
false) )
681 trackHitCandidates.push_back( make_pair(iHit, prSt) );
684 if (trackHitCandidates.empty())
687 if (debug_info)
cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
688 if (debug_info)
cout <<
"Before sorting ... " << endl;
691 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
693 if (debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
695 if (debug_info)
cout << endl;
700 if (debug_info)
cout <<
"After sorting ... " << endl;
703 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
705 if (debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
710 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
714 if (debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
718 TSOS currPrSt = (*iHitRange).second;
720 if (debug_info)
cout <<
"curr position" << bestHit->globalPosition();
721 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
724 if (debug_info)
cout <<
"curr position" << tmpHit->globalPosition() ;
728 if (debug_info)
cout <<
"Cross check end ..." << endl;
736 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
740 if (debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
749 if (debug_info)
cout <<
"curr position A" << bestHit->globalPosition() << endl;
750 TSOS currPrSt = (*iHitRange).second;
751 double chi2min = theEstimator->estimate( currPrSt, *bestHit).second;
753 if (debug_info)
cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
754 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
756 if (debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
759 if (debug_info)
cout <<
"curr position B" << tmpHit->globalPosition() << endl;
760 double currChi2 = theEstimator->estimate(currPrSt, *tmpHit).second;
761 if ( currChi2 < chi2min )
763 if (debug_info)
cout <<
"Is best hit" << endl;
775 if (debug_info)
cout << chi2min << endl;
779 if (debug_info)
cout <<
"chi2 fine : " << chi2min << endl;
782 TSOS UpdatedState= theUpdator->
update( currPrSt, *bestHit );
785 hits.push_back(bestHit);
786 traj.
push(
TM(currPrSt,UpdatedState, bestHit, chi2min) );
788 "STATE UPDATED WITH HIT AT POSITION " 792 if (debug_info)
cout <<
"Added Hit" << bestHit->globalPosition() << endl;
793 if (debug_info)
cout <<
"State is valid ..." << UpdatedState << endl;
809 if (debug_info)
edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position " 810 << bestHit->globalPosition();
819 if (debug_info)
cout <<
" continue 1 " << endl;
824 if (debug_info)
cout <<
" continue 2 " << endl;
827 while ( iHitRange != trackHitCandidates.end() );
840 unsigned int iid=(*hit)->hit()->geographicalId().rawId();
842 if(((iid>>0)&0x3)!=1) ngoodhits++;
847 if ( ngoodhits >= theMinHits) {
878 std::pair<TrajectoryStateOnSurface, const GeomDet*>
881 int lastFitted = 999;
883 if (nhits < lastFitted+1) lastFitted = nhits-1;
885 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
888 bool foundLast =
false;
889 int actualLast = -99;
890 for (
int i=lastFitted;
i >= 0;
i--) {
891 if(measvec[
i].
recHit()->isValid()){
896 firstHits.push_back( measvec[
i].
recHit());
899 TSOS unscaledState = measvec[actualLast].updatedState();
905 thePropagator->magneticField());
909 KFTrajectoryFitter backFitter( *thePropagator,
920 vector<Trajectory> fitres = backFitter.fit( fakeSeed, firstHits, startingState);
922 if (fitres.size() != 1) {
924 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
928 const TSOS& firstState = firstMeas.updatedState();
935 thePropagator->magneticField());
937 return std::pair<TrajectoryStateOnSurface, const GeomDet*>( initialState,
938 firstMeas.recHit()->det());
PropagationDirection direction() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< TrackingRecHitRange >::iterator TrackingRecHitRangeIterator
Trajectory createStartingTrajectory(const TrajectorySeed &seed) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
const LocalTrajectoryParameters & localParameters() const
GlobalPoint globalPosition() const
ConstRecHitContainer recHits() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
~CRackTrajectoryBuilder()
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const Plane & surface() const
The nominal surface of the GeomDet.
std::vector< const TrackingRecHit * >::iterator TrackingRecHitIterator
PropagationDirection const & direction() const
uint32_t rawId() const
get the raw id
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj) const
DataContainer const & measurements() const
bool qualityFilter(const Trajectory &traj)
const SurfaceType & surface() const
std::vector< TrajectorySeed > TrajectorySeedCollection
void run(const TrajectorySeedCollection &collseed, const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const edm::EventSetup &es, edm::Event &e, std::vector< Trajectory > &trajoutput)
Runs the algorithm.
recHitContainer::const_iterator const_iterator
TrajectoryMeasurement const & lastMeasurement() const
void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
data_type const * data(size_t cell) const
std::pair< const_iterator, const_iterator > range
const AlgebraicSymMatrix55 & matrix() const
std::vector< TrajectoryMeasurement > seedMeasurements(const TrajectorySeed &seed) const
const LocalTrajectoryError & localError() const
TSOS startingTSOS(const TrajectorySeed &seed) const
std::shared_ptr< TrackingRecHit const > RecHitPointer
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryMeasurement const & firstMeasurement() const
PTrajectoryStateOnDet const & startingState() const
SiStripRecHit2D stereoHit() const
CRackTrajectoryBuilder(const edm::ParameterSet &conf)
bool isDifferentStripReHit2D(const SiStripRecHit2D &hitA, const SiStripRecHit2D &hitB)
void init(const edm::EventSetup &es, bool)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
SiStripRecHit2D monoHit() const
unsigned int nHits() const
std::vector< const TrackingRecHit * > SortHits(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const TrajectorySeed &seed, const bool bAddSeedHits)
LocalPoint localPosition() const final
GlobalPoint globalPosition() const final
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit * > &Hits, Propagator *currPropagator)
T const * product() const
void push(const TrajectoryMeasurement &tm)