113 vector<Trajectory> &trajoutput)
116 std::vector<Trajectory> trajSmooth;
117 std::vector<Trajectory>::iterator trajIter;
119 TrajectorySeedCollection::const_iterator
iseed;
121 for(iseed=collseed.begin();iseed!=collseed.end();iseed++){
135 vector<const TrackingRecHit*> allHitsOppsite =
SortHits(collstereo,collrphi,collmatched,collpixel, *iseed,
true);
137 if (allHitsOppsite.size())
147 cout <<
"Hits in opposite direction..." << endl;
148 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
149 for ( iHit =
hits.begin(); iHit!=
hits.end(); iHit++)
151 cout << (**iHit).globalPosition() << endl;
160 tracker->idToDet((
hits.front())->geographicalId())->surface()).isValid()){
161 TSOS startingStateNew =
163 tracker->idToDet((
hits.front())->geographicalId())->surface()));
167 cout <<
"Hits in opposite direction reversed..." << endl;
168 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
169 for ( iHit =
hits.begin(); iHit!=
hits.end(); iHit++)
171 cout << (**iHit).globalPosition() << endl;
179 cout <<
"Debugging show fitted hits" << endl;
180 auto hitsFit= trajTmp.recHits();
181 for(
auto hit=hitsFit.begin();
hit!=hitsFit.end();
hit++){
191 if(
debug_info)
cout <<
"There are no hits in opposite direction ..." << endl;
194 vector<const TrackingRecHit*> allHits;
198 allHits=
SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
false);
204 allHits=
SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
true);
211 cout <<
"Debugging show All fitted hits" << endl;
212 auto hits= traj.recHits();
215 cout << (*hit)->globalPosition() << endl;
225 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState =
innerState(traj);
226 if (initState.first.isValid())
230 for (trajIter=
trajFit.begin(); trajIter!=
trajFit.end();trajIter++){
233 for (trajIter= trajSmooth.begin(); trajIter!=trajSmooth.end();trajIter++){
234 if((*trajIter).isValid()){
237 trajoutput.push_back((*trajIter));
257 for (
auto i : seedMeas)
result.push(std::move(
i));
262 std::vector<TrajectoryMeasurement>
265 std::vector<TrajectoryMeasurement>
result;
268 ihit != hitRange.second; ihit++) {
271 const GeomDet* hitGeomDet = (&(*tracker))->idToDet( ihit->geographicalId());
274 if (ihit == hitRange.second - 1) {
276 result.push_back(std::move(
TM( invalidState, updatedState, recHit)));
280 result.push_back(std::move(
TM( invalidState, recHit)));
288 vector<const TrackingRecHit*>
294 const bool bAddSeedHits
301 vector<const TrackingRecHit*> allHits;
329 int seedHitSize= hRange.second - hRange.first;
331 vector <int> detIDSeedMatched (seedHitSize);
332 vector <int> detIDSeedRphi (seedHitSize);
333 vector <int> detIDSeedStereo (seedHitSize);
335 for (ihit = hRange.first;
336 ihit != hRange.second; ihit++) {
343 if (ihit == hRange.first)
359 if ( yGlobStereo < yMin ) yMin = yGlobStereo;
360 if ( yGlobRPhi < yMin ) yMin = yGlobRPhi;
362 if ( yGlobStereo > yMax ) yMax = yGlobStereo;
363 if ( yGlobRPhi > yMax ) yMax = yGlobRPhi;
366 detIDSeedRphi.push_back (
m.geographicalId().rawId() );
367 detIDSeedStereo.push_back (
s.geographicalId().rawId() );
378 if ( ( (yGlobRPhi > yGlobStereo ) &&
seed_plus ) || ((yGlobRPhi < yGlobStereo ) && !
seed_plus ))
392 else if (bAddSeedHits)
395 detIDSeedRphi.push_back ( ihit->geographicalId().rawId() );
396 detIDSeedMatched.push_back ( -1 );
397 detIDSeedStereo.push_back ( -1 );
401 if ( yref < yMin ) yMin = yref;
402 if ( yref > yMax ) yMax = yref;
416 if ((&collpixel)!=0){
418 for(ipix=collpixel.
data().begin();ipix!=collpixel.
data().end();ipix++){
421 allHits.push_back(&(*ipix));
431 if ((&collmatched)!=0){
432 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++){
435 int cDetId=istripm->geographicalId().rawId();
436 bool noSeedDet = ( detIDSeedMatched.end() ==
find (detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId ) ) ;
442 allHits.push_back(&(*istripm));
449 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
452 if (monoDetId.partnerDetId())
454 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
457 int cDetId=istrip->geographicalId().rawId();
458 bool noSeedDet = ( detIDSeedRphi.end()==
find (detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId ) ) ;
463 bool hitIsUnique =
true;
465 if ((&collmatched)!=0)
466 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++)
472 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
479 allHits.push_back(&(*istrip));
527 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
530 allHits.push_back(&(*istrip));
535 if ((&collstereo)!=0){
536 for(istrip=collstereo.
data().begin();istrip!=collstereo.
data().end();istrip++){
539 allHits.push_back(&(*istrip));
574 vector<const TrackingRecHit*>::iterator iHit;
575 for (iHit=allHits.begin(); iHit<allHits.end(); iHit++)
583 tracker->idToDet((*iHit)->geographicalId())->surface());
607 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
615 const vector<const TrackingRecHit*>& _Hits,
Propagator *currPropagator){
616 vector<const TrackingRecHit*> Hits = _Hits;
617 if ( Hits.size() == 0 )
623 vector <TrackingRecHitRange> hitRangeByDet;
626 prevDet = Hits.begin();
629 if ( (*prevDet)->geographicalId() == (*iHit)->geographicalId() )
632 hitRangeByDet.push_back( make_pair( prevDet, iHit ) );
635 hitRangeByDet.push_back( make_pair( prevDet, Hits.end() ) );
646 tracker->idToDet(currDet)->surface());
660 if (
debug_info)
cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
663 if (
debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
667 if ( currChi2 < chi2min )
680 hits.push_back(bestHit);
681 traj.
push(
TM(prSt,UpdatedState, bestHit, chi2min) );
683 "STATE UPDATED WITH HIT AT POSITION "
685 << bestHit->globalPosition()
689 "STATE UPDATED WITH HIT AT POSITION "
691 << bestHit->globalPosition()
699 edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position " << endl;
703 "NOT! UPDATED WITH HIT AT POSITION "
705 << bestHit->globalPosition()
723 std::vector < std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
724 std::vector <std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
725 std::vector <uint32_t> processedDets;
730 trackHitCandidates.clear();
737 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end() )
741 tracker->idToDet(currDet)->surface());
742 if ( ( !prSt.
isValid() ) || (
theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface() ) ==
false) )
746 trackHitCandidates.push_back( make_pair(iHit, prSt) );
749 if (!trackHitCandidates.size())
752 if (
debug_info)
cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
756 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
758 if (
debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
768 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
770 if (
debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
775 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
779 if (
debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
783 TSOS currPrSt = (*iHitRange).second;
785 if (
debug_info)
cout <<
"curr position" << bestHit->globalPosition();
786 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
789 if (
debug_info)
cout <<
"curr position" << tmpHit->globalPosition() ;
801 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
805 if (
debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
814 if (
debug_info)
cout <<
"curr position A" << bestHit->globalPosition() << endl;
815 TSOS currPrSt = (*iHitRange).second;
818 if (
debug_info)
cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
819 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
821 if (
debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
824 if (
debug_info)
cout <<
"curr position B" << tmpHit->globalPosition() << endl;
826 if ( currChi2 < chi2min )
850 hits.push_back(bestHit);
851 traj.
push(
TM(currPrSt,UpdatedState, bestHit, chi2min) );
853 "STATE UPDATED WITH HIT AT POSITION "
857 if (
debug_info)
cout <<
"Added Hit" << bestHit->globalPosition() << endl;
858 if (
debug_info)
cout <<
"State is valid ..." << UpdatedState << endl;
875 << bestHit->globalPosition();
892 while ( iHitRange != trackHitCandidates.end() );
903 auto hits= traj.recHits();
905 unsigned int iid=(*hit)->hit()->geographicalId().rawId();
907 if(((iid>>0)&0x3)!=1) ngoodhits++;
943 std::pair<TrajectoryStateOnSurface, const GeomDet*>
946 int lastFitted = 999;
948 if (nhits < lastFitted+1) lastFitted = nhits-1;
950 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
953 bool foundLast =
false;
954 int actualLast = -99;
955 for (
int i=lastFitted;
i >= 0;
i--) {
956 if(measvec[
i].recHit()->isValid()){
961 firstHits.push_back( measvec[
i].recHit());
964 TSOS unscaledState = measvec[actualLast].updatedState();
985 vector<Trajectory> fitres = backFitter.fit( fakeSeed, firstHits, startingState);
987 if (fitres.size() != 1) {
989 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
1002 return std::pair<TrajectoryStateOnSurface, const GeomDet*>( initialState,
1003 firstMeas.
recHit()->det());
PropagationDirection direction() const
virtual const MagneticField * magneticField() const
T getParameter(std::string const &) const
edm::ESHandle< MagneticField > magfield
T getUntrackedParameter(std::string const &, T const &) const
std::vector< TrackingRecHitRange >::iterator TrackingRecHitRangeIterator
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Trajectory createStartingTrajectory(const TrajectorySeed &seed) const
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
friend class CompareDetByTraj
ConstRecHitPointer const & recHit() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
const LocalTrajectoryParameters & localParameters() const
Chi2MeasurementEstimator * theEstimator
GlobalPoint globalPosition() const
const TransientTrackingRecHitBuilder * RHBuilder
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
TransientTrackingRecHit::RecHitContainer hits
~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.
virtual TrajectoryContainer trajectories(const Trajectory &traj) const
std::vector< const TrackingRecHit * >::iterator TrackingRecHitIterator
PropagationDirection const & direction() const
uint32_t rawId() const
get the raw id
const KFTrajectorySmoother * theSmoother
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj) const
std::vector< Trajectory > trajFit
DataContainer const & measurements() const
bool qualityFilter(const Trajectory &traj)
const SurfaceType & surface() const
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) 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
edm::ESHandle< TrackerGeometry > tracker
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
TrajectoryMeasurement const & lastMeasurement() const
data_type const * data(size_t cell) const
std::pair< const_iterator, const_iterator > range
PropagatorWithMaterial * thePropagatorOp
const AlgebraicSymMatrix55 & matrix() const
std::vector< TrajectoryMeasurement > seedMeasurements(const TrajectorySeed &seed) const
const LocalTrajectoryError & localError() const
tuple Chi2MeasurementEstimator
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)
PropagatorWithMaterial * thePropagator
SiStripRecHit2D monoHit() const
const KFTrajectoryFitter * theFitter
unsigned int nHits() const
virtual std::pair< bool, double > estimate(const TrajectoryStateOnSurface &, const TrackingRecHit &) const
tuple KFTrajectorySmoother
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
std::vector< Trajectory > fit(const Trajectory &traj, fitType type=standard) const
DetId geographicalId() const
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit * > &Hits, Propagator *currPropagator)
virtual LocalPoint localPosition() const
void push(const TrajectoryMeasurement &tm)