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;
176 trajTmp =
theFitter->fit(tmpseed,
hits, startingStateNew ).front();
179 cout <<
"Debugging show fitted hits" << endl;
180 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> > hitsFit= trajTmp.
recHits();
181 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >::const_iterator
hit;
182 for(hit=hitsFit.begin();hit!=hitsFit.end();hit++){
192 if(
debug_info)
cout <<
"There are no hits in opposite direction ..." << endl;
195 vector<const TrackingRecHit*> allHits;
199 allHits=
SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
false);
205 allHits=
SortHits(collstereo,collrphi,collmatched,collpixel,*iseed,
true);
212 cout <<
"Debugging show All fitted hits" << endl;
213 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >
hits= traj.
recHits();
214 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >::const_iterator
hit;
215 for(hit=hits.begin();hit!=hits.end();hit++){
227 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState =
innerState(traj);
228 if (initState.first.isValid())
232 for (trajIter=
trajFit.begin(); trajIter!=
trajFit.end();trajIter++){
235 for (trajIter= trajSmooth.begin(); trajIter!=trajSmooth.end();trajIter++){
236 if((*trajIter).isValid()){
239 trajoutput.push_back((*trajIter));
259 if ( !seedMeas.empty()) {
260 for (std::vector<TM>::const_iterator
i=seedMeas.begin();
i!=seedMeas.end();
i++){
269 std::vector<TrajectoryMeasurement>
272 std::vector<TrajectoryMeasurement>
result;
275 ihit != hitRange.second; ihit++) {
278 const GeomDet* hitGeomDet = (&(*tracker))->idToDet( ihit->geographicalId());
279 TSOS invalidState(
new BasicSingleTrajectoryState( hitGeomDet->
surface()));
281 if (ihit == hitRange.second - 1) {
283 result.push_back(
TM( invalidState, updatedState, recHit));
287 result.push_back(
TM( invalidState, recHit));
295 vector<const TrackingRecHit*>
301 const bool bAddSeedHits
308 vector<const TrackingRecHit*> allHits;
336 int seedHitSize= hRange.second - hRange.first;
338 vector <int> detIDSeedMatched (seedHitSize);
339 vector <int> detIDSeedRphi (seedHitSize);
340 vector <int> detIDSeedStereo (seedHitSize);
342 for (ihit = hRange.first;
343 ihit != hRange.second; ihit++) {
347 const SiStripMatchedRecHit2D* matchedhit=
dynamic_cast<const SiStripMatchedRecHit2D*
>(&(*ihit));
350 if (ihit == hRange.first)
358 auto m = matchedhit->monoHit();
359 auto s = matchedhit->stereoHit();
366 if ( yGlobStereo < yMin ) yMin = yGlobStereo;
367 if ( yGlobRPhi < yMin ) yMin = yGlobRPhi;
369 if ( yGlobStereo > yMax ) yMax = yGlobStereo;
370 if ( yGlobRPhi > yMax ) yMax = yGlobRPhi;
372 detIDSeedMatched.push_back ( matchedhit->geographicalId().rawId() );
373 detIDSeedRphi.push_back (
m.geographicalId().rawId() );
374 detIDSeedStereo.push_back (
s.geographicalId().rawId() );
385 if ( ( (yGlobRPhi > yGlobStereo ) &&
seed_plus ) || ((yGlobRPhi < yGlobStereo ) && !
seed_plus ))
399 else if (bAddSeedHits)
402 detIDSeedRphi.push_back ( ihit->geographicalId().rawId() );
403 detIDSeedMatched.push_back ( -1 );
404 detIDSeedStereo.push_back ( -1 );
408 if ( yref < yMin ) yMin = yref;
409 if ( yref > yMax ) yMax = yref;
423 if ((&collpixel)!=0){
425 for(ipix=collpixel.
data().begin();ipix!=collpixel.
data().end();ipix++){
428 allHits.push_back(&(*ipix));
438 if ((&collmatched)!=0){
439 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++){
442 int cDetId=istripm->geographicalId().rawId();
443 bool noSeedDet = ( detIDSeedMatched.end() ==
find (detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId ) ) ;
449 allHits.push_back(&(*istripm));
456 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
459 if (monoDetId.partnerDetId())
461 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
464 int cDetId=istrip->geographicalId().rawId();
465 bool noSeedDet = ( detIDSeedRphi.end()==
find (detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId ) ) ;
470 bool hitIsUnique =
true;
472 if ((&collmatched)!=0)
473 for(istripm=collmatched.
data().begin();istripm!=collmatched.
data().end();istripm++)
479 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
486 allHits.push_back(&(*istrip));
534 for(istrip=collrphi.
data().begin();istrip!=collrphi.
data().end();istrip++){
537 allHits.push_back(&(*istrip));
542 if ((&collstereo)!=0){
543 for(istrip=collstereo.
data().begin();istrip!=collstereo.
data().end();istrip++){
546 allHits.push_back(&(*istrip));
581 vector<const TrackingRecHit*>::iterator iHit;
582 for (iHit=allHits.begin(); iHit<allHits.end(); iHit++)
590 tracker->idToDet((*iHit)->geographicalId())->surface());
614 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
622 const vector<const TrackingRecHit*>& _Hits,
Propagator *currPropagator){
623 vector<const TrackingRecHit*> Hits = _Hits;
624 if ( Hits.size() == 0 )
630 vector <TrackingRecHitRange> hitRangeByDet;
633 prevDet = Hits.begin();
636 if ( (*prevDet)->geographicalId() == (*iHit)->geographicalId() )
639 hitRangeByDet.push_back( make_pair( prevDet, iHit ) );
642 hitRangeByDet.push_back( make_pair( prevDet, Hits.end() ) );
653 tracker->idToDet(currDet)->surface());
665 double chi2min =
theEstimator->estimate( prSt, *bestHit).second;
667 if (
debug_info)
cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
670 if (
debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
673 double currChi2 =
theEstimator->estimate(prSt, *tmpHit).second;
674 if ( currChi2 < chi2min )
687 hits.push_back(&(*bestHit));
688 traj.
push(
TM(prSt,UpdatedState, bestHit, chi2min) );
690 "STATE UPDATED WITH HIT AT POSITION "
692 << bestHit->globalPosition()
696 "STATE UPDATED WITH HIT AT POSITION "
698 << bestHit->globalPosition()
706 edm::LogWarning(
"CosmicTrackFinder")<<
" State can not be updated with hit at position " << endl;
710 "NOT! UPDATED WITH HIT AT POSITION "
712 << bestHit->globalPosition()
730 std::vector < std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
731 std::vector <std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
732 std::vector <uint32_t> processedDets;
737 trackHitCandidates.clear();
744 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end() )
748 tracker->idToDet(currDet)->surface());
749 if ( ( !prSt.
isValid() ) || (
theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface() ) ==
false) )
753 trackHitCandidates.push_back( make_pair(iHit, prSt) );
756 if (!trackHitCandidates.size())
759 if (
debug_info)
cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
763 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
765 if (
debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
775 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
777 if (
debug_info)
cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
782 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
786 if (
debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
790 TSOS currPrSt = (*iHitRange).second;
792 if (
debug_info)
cout <<
"curr position" << bestHit->globalPosition();
793 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
796 if (
debug_info)
cout <<
"curr position" << tmpHit->globalPosition() ;
808 for( iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++ )
812 if (
debug_info)
cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
821 if (
debug_info)
cout <<
"curr position A" << bestHit->globalPosition() << endl;
822 TSOS currPrSt = (*iHitRange).second;
823 double chi2min =
theEstimator->estimate( currPrSt, *bestHit).second;
825 if (
debug_info)
cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
826 for(
TrackingRecHitIterator iHit = (*iHitRange).first->first+1; iHit != iHitRange->first->second; iHit++ )
828 if (
debug_info)
cout <<
"loop3 " <<
" "<< Hits.end() - iHit << endl;
831 if (
debug_info)
cout <<
"curr position B" << tmpHit->globalPosition() << endl;
832 double currChi2 =
theEstimator->estimate(currPrSt, *tmpHit).second;
833 if ( currChi2 < chi2min )
857 hits.push_back(&(*bestHit));
858 traj.
push(
TM(currPrSt,UpdatedState, bestHit, chi2min) );
860 "STATE UPDATED WITH HIT AT POSITION "
864 if (
debug_info)
cout <<
"Added Hit" << bestHit->globalPosition() << endl;
865 if (
debug_info)
cout <<
"State is valid ..." << UpdatedState << endl;
882 << bestHit->globalPosition();
899 while ( iHitRange != trackHitCandidates.end() );
910 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >
hits= traj.
recHits();
911 std::vector< ConstReferenceCountingPointer< TransientTrackingRecHit> >::const_iterator
hit;
912 for(hit=hits.begin();hit!=hits.end();hit++){
913 unsigned int iid=(*hit)->hit()->geographicalId().rawId();
915 if(((iid>>0)&0x3)!=1) ngoodhits++;
933 if ( hitA.geographicalId() != hitB.geographicalId() )
935 if ( hitA.localPosition().x() != hitB.localPosition().x() )
937 if ( hitA.localPosition().y() != hitB.localPosition().y() )
939 if ( hitA.localPosition().z() != hitB.localPosition().z() )
951 std::pair<TrajectoryStateOnSurface, const GeomDet*>
954 int lastFitted = 999;
956 if (nhits < lastFitted+1) lastFitted = nhits-1;
958 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
961 bool foundLast =
false;
962 int actualLast = -99;
963 for (
int i=lastFitted;
i >= 0;
i--) {
964 if(measvec[
i].recHit()->isValid()){
969 firstHits.push_back( measvec[
i].recHit());
972 TSOS unscaledState = measvec[actualLast].updatedState();
993 vector<Trajectory> fitres = backFitter.fit( fakeSeed, firstHits, startingState);
995 if (fitres.size() != 1) {
997 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
1010 return std::pair<TrajectoryStateOnSurface, const GeomDet*>( initialState,
1011 firstMeas.
recHit()->det());
PropagationDirection direction() const
T getParameter(std::string const &) const
edm::ESHandle< MagneticField > magfield
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
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.
std::vector< const TrackingRecHit * >::iterator TrackingRecHitIterator
ConstRecHitContainer recHits(bool splitting=false) const
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
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
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryMeasurement const & firstMeasurement() const
PTrajectoryStateOnDet const & startingState() 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
const KFTrajectoryFitter * theFitter
unsigned int nHits() 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
DetId geographicalId() const
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit * > &Hits, Propagator *currPropagator)
void push(const TrajectoryMeasurement &tm)
double chiSquared() const