38 edm::LogInfo(
"CosmicTrackFinder")<<
"Minimum number of hits "<<theMinHits<<
" Cut on Chi2= "<<chi2cut;
88 RHBuilder= theBuilder.
product();
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.size())
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;
157 reverse(hits.begin(), hits.end());
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;
212 for(
auto hit=hits.begin();
hit!=hits.end();
hit++){
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) {
274 TSOS updatedState=startingTSOS(seed);
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;
415 if ((&collpixel)!=0){
417 for(ipix=collpixel.
data().begin();ipix!=collpixel.
data().end();ipix++){
418 float ych= RHBuilder->build(&(*ipix))->globalPosition().y();
419 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
420 allHits.push_back(&(*ipix));
430 if ((&collmatched)!=0){
431 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++){
432 float ych= RHBuilder->build(&(*istripm))->globalPosition().y();
434 int cDetId=istripm->geographicalId().rawId();
435 bool noSeedDet = ( detIDSeedMatched.end() ==
find (detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId ) ) ;
438 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
441 allHits.push_back(&(*istripm));
448 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
449 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
451 if (monoDetId.partnerDetId())
453 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
456 int cDetId=istrip->geographicalId().rawId();
457 bool noSeedDet = ( detIDSeedRphi.end()==
find (detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId ) ) ;
459 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
462 bool hitIsUnique =
true;
464 if ((&collmatched)!=0)
465 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++)
468 if ( isDifferentStripReHit2D ( *istrip, (istripm->monoHit() ) ) ==
false)
471 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
478 allHits.push_back(&(*istrip));
526 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
527 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
528 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
529 allHits.push_back(&(*istrip));
534 if ((&collstereo)!=0){
535 for(istrip=collstereo.
data().begin();istrip!=collstereo.
data().end();istrip++){
536 float ych= RHBuilder->build(&(*istrip))->globalPosition().y();
537 if ((seed_plus && (ych<yref)) || (!(seed_plus) && (ych>yref)))
538 allHits.push_back(&(*istrip));
564 if (debug_info)
cout <<
"all hits" << endl;
567 Trajectory startingTraj = createStartingTrajectory(seed);
573 vector<const TrackingRecHit*>::iterator iHit;
574 for (iHit=allHits.begin(); iHit<allHits.end(); iHit++)
576 GlobalPoint gphit=RHBuilder->build(*iHit)->globalPosition();
577 if (debug_info)
cout <<
"GH " << gphit << endl;
582 tracker->idToDet((*iHit)->geographicalId())->surface());
592 if (debug_info)
cout <<
"not valid" << endl;
595 if (debug_info)
cout <<
"all hits end" << endl;
606 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
614 const vector<const TrackingRecHit*>& _Hits,
Propagator *currPropagator){
615 vector<const TrackingRecHit*> Hits = _Hits;
616 if ( Hits.size() == 0 )
619 if (debug_info)
cout <<
"CRackTrajectoryBuilder::AddHit" << endl;
622 vector <TrackingRecHitRange> hitRangeByDet;
625 prevDet = Hits.begin();
628 if ( (*prevDet)->geographicalId() == (*iHit)->geographicalId() )
631 hitRangeByDet.push_back( make_pair( prevDet, iHit ) );
634 hitRangeByDet.push_back( make_pair( prevDet, Hits.end() ) );
638 if (fastPropagation) {
645 tracker->idToDet(currDet)->surface());
657 double chi2min = theEstimator->estimate( prSt, *bestHit).second;
659 if (debug_info)
cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
662 if (debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
665 double currChi2 = theEstimator->estimate(prSt, *tmpHit).second;
666 if ( currChi2 < chi2min )
673 if (debug_info)
cout << chi2min << endl;
674 if (chi2min < chi2cut)
676 if (debug_info)
cout <<
"chi2 fine : " << chi2min << endl;
677 TSOS UpdatedState= theUpdator->
update( prSt, *bestHit );
679 hits.push_back(bestHit);
680 traj.
push(
TM(prSt,UpdatedState, bestHit, chi2min) );
682 "STATE UPDATED WITH HIT AT POSITION "
684 << bestHit->globalPosition()
687 if (debug_info)
cout <<
688 "STATE UPDATED WITH HIT AT POSITION "
690 << bestHit->globalPosition()
693 if (debug_info)
cout <<
"State is valid ..." << endl;
698 edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position " << endl;
699 TSOS UpdatedState= theUpdator->
update( prSt, *bestHit );
702 "NOT! UPDATED WITH HIT AT POSITION "
704 << bestHit->globalPosition()
722 std::vector < std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
723 std::vector <std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
724 std::vector <uint32_t> processedDets;
729 trackHitCandidates.clear();
736 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end() )
740 tracker->idToDet(currDet)->surface());
741 if ( ( !prSt.
isValid() ) || (theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface() ) ==
false) )
745 trackHitCandidates.push_back( make_pair(iHit, prSt) );
748 if (!trackHitCandidates.size())
751 if (debug_info)
cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
752 if (debug_info)
cout <<
"Before sorting ... " << endl;
755 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
757 if (debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
759 if (debug_info)
cout << endl;
764 if (debug_info)
cout <<
"After sorting ... " << endl;
767 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
769 if (debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
774 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
778 if (debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
782 TSOS currPrSt = (*iHitRange).second;
784 if (debug_info)
cout <<
"curr position" << bestHit->globalPosition();
785 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
788 if (debug_info)
cout <<
"curr position" << tmpHit->globalPosition() ;
792 if (debug_info)
cout <<
"Cross check end ..." << endl;
800 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
804 if (debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
813 if (debug_info)
cout <<
"curr position A" << bestHit->globalPosition() << endl;
814 TSOS currPrSt = (*iHitRange).second;
815 double chi2min = theEstimator->estimate( currPrSt, *bestHit).second;
817 if (debug_info)
cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
818 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
820 if (debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
823 if (debug_info)
cout <<
"curr position B" << tmpHit->globalPosition() << endl;
824 double currChi2 = theEstimator->estimate(currPrSt, *tmpHit).second;
825 if ( currChi2 < chi2min )
827 if (debug_info)
cout <<
"Is best hit" << endl;
839 if (debug_info)
cout << chi2min << endl;
841 if (chi2min < chi2cut)
843 if (debug_info)
cout <<
"chi2 fine : " << chi2min << endl;
846 TSOS UpdatedState= theUpdator->
update( currPrSt, *bestHit );
849 hits.push_back(bestHit);
850 traj.
push(
TM(currPrSt,UpdatedState, bestHit, chi2min) );
852 "STATE UPDATED WITH HIT AT POSITION "
856 if (debug_info)
cout <<
"Added Hit" << bestHit->globalPosition() << endl;
857 if (debug_info)
cout <<
"State is valid ..." << UpdatedState << endl;
873 if (debug_info)
edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position "
874 << bestHit->globalPosition();
883 if (debug_info)
cout <<
" continue 1 " << endl;
888 if (debug_info)
cout <<
" continue 2 " << endl;
891 while ( iHitRange != trackHitCandidates.end() );
903 for(
auto hit=hits.begin();
hit!=hits.end();
hit++){
904 unsigned int iid=(*hit)->hit()->geographicalId().rawId();
906 if(((iid>>0)&0x3)!=1) ngoodhits++;
911 if ( ngoodhits >= theMinHits) {
942 std::pair<TrajectoryStateOnSurface, const GeomDet*>
945 int lastFitted = 999;
947 if (nhits < lastFitted+1) lastFitted = nhits-1;
949 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
952 bool foundLast =
false;
953 int actualLast = -99;
954 for (
int i=lastFitted;
i >= 0;
i--) {
955 if(measvec[
i].recHit()->isValid()){
960 firstHits.push_back( measvec[
i].recHit());
963 TSOS unscaledState = measvec[actualLast].updatedState();
969 thePropagator->magneticField());
984 vector<Trajectory> fitres = backFitter.fit( fakeSeed, firstHits, startingState);
986 if (fitres.size() != 1) {
988 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
999 thePropagator->magneticField());
1001 return std::pair<TrajectoryStateOnSurface, const GeomDet*>( initialState,
1002 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
ConstRecHitPointer const & recHit() const
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)
T const * product() const
void init(const edm::EventSetup &es, bool)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
SiStripRecHit2D monoHit() const
ESHandle< TrackerGeometry > geometry
unsigned int nHits() const
virtual GlobalPoint globalPosition() const final
std::vector< const TrackingRecHit * > SortHits(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const TrajectorySeed &seed, const bool bAddSeedHits)
TrajectoryStateOnSurface const & updatedState() const
DetId geographicalId() const
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit * > &Hits, Propagator *currPropagator)
void push(const TrajectoryMeasurement &tm)
virtual LocalPoint localPosition() const final