87 vector<Trajectory>& trajoutput) {
88 std::vector<Trajectory> trajSmooth;
89 std::vector<Trajectory>::iterator trajIter;
91 TrajectorySeedCollection::const_iterator
iseed;
106 vector<const TrackingRecHit*> allHitsOppsite =
SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
true);
108 if (!allHitsOppsite.empty()) {
115 cout <<
"Hits in opposite direction..." << endl;
116 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
117 for (iHit =
hits.begin(); iHit !=
hits.end(); iHit++) {
118 cout << (**iHit).globalPosition() << endl;
129 TSOS startingStateNew =
134 cout <<
"Hits in opposite direction reversed..." << endl;
135 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
136 for (iHit =
hits.begin(); iHit !=
hits.end(); iHit++) {
137 cout << (**iHit).globalPosition() << endl;
142 trajTmp =
theFitter->fit(tmpseed,
hits, startingStateNew).front();
145 cout <<
"Debugging show fitted hits" << endl;
146 auto hitsFit = trajTmp.
recHits();
147 for (
auto hit = hitsFit.begin();
hit != hitsFit.end();
hit++) {
154 cout <<
"There are no hits in opposite direction ..." << endl;
157 vector<const TrackingRecHit*> allHits;
160 allHits =
SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
false);
164 allHits =
SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
true);
170 cout <<
"Debugging show All fitted hits" << endl;
173 cout << (*hit)->globalPosition() << endl;
180 cout <<
"now do quality checks" << endl;
183 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState =
185 if (initState.first.isValid())
189 for (trajIter =
trajFit.begin(); trajIter !=
trajFit.end(); trajIter++) {
192 for (trajIter = trajSmooth.begin(); trajIter != trajSmooth.end(); trajIter++) {
193 if ((*trajIter).isValid()) {
195 cout <<
"adding track ... " << endl;
196 trajoutput.push_back((*trajIter));
215 for (
auto i : seedMeas)
221 std::vector<TrajectoryMeasurement>
result;
222 auto const& hitRange =
seed.recHits();
223 for (
auto ihit = hitRange.begin(); ihit != hitRange.end(); ihit++) {
226 const GeomDet* hitGeomDet = (&(*tracker))->idToDet(ihit->geographicalId());
229 if (ihit == hitRange.end() - 1) {
231 result.emplace_back(invalidState, updatedState,
recHit);
246 const bool bAddSeedHits) {
250 vector<const TrackingRecHit*> allHits;
258 cout <<
"seed hits size " <<
seed.nHits() << endl;
274 int seedHitSize =
seed.nHits();
276 vector<int> detIDSeedMatched(seedHitSize);
277 vector<int> detIDSeedRphi(seedHitSize);
278 vector<int> detIDSeedStereo(seedHitSize);
280 auto const& hRange =
seed.recHits();
281 for (
auto ihit = hRange.begin(); ihit != hRange.end(); ihit++) {
287 if (ihit == hRange.begin()) {
299 cout <<
"Rphi ..." << yGlobRPhi << endl;
301 cout <<
"Stereo ..." << yGlobStereo << endl;
303 if (yGlobStereo <
yMin)
305 if (yGlobRPhi <
yMin)
308 if (yGlobStereo >
yMax)
310 if (yGlobRPhi >
yMax)
314 detIDSeedRphi.push_back(
m.geographicalId().rawId());
315 detIDSeedStereo.push_back(
s.geographicalId().rawId());
321 if (((yGlobRPhi > yGlobStereo) &&
seed_plus) || ((yGlobRPhi < yGlobStereo) && !
seed_plus)) {
330 }
else if (bAddSeedHits) {
332 detIDSeedRphi.push_back(ihit->geographicalId().rawId());
333 detIDSeedMatched.push_back(-1);
334 detIDSeedStereo.push_back(-1);
354 for (ipix = collpixel.
data().begin(); ipix != collpixel.
data().end(); ipix++) {
357 allHits.push_back(&(*ipix));
365 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
368 int cDetId = istripm->geographicalId().rawId();
369 bool noSeedDet = (detIDSeedMatched.end() ==
find(detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId));
373 allHits.push_back(&(*istripm));
377 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
380 if (monoDetId.partnerDetId()) {
381 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
384 int cDetId = istrip->geographicalId().rawId();
385 bool noSeedDet = (detIDSeedRphi.end() ==
find(detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId));
388 bool hitIsUnique =
true;
390 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
394 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
400 allHits.push_back(&(*istrip));
407 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
410 allHits.push_back(&(*istrip));
413 for (istrip = collstereo.
data().begin(); istrip != collstereo.
data().end(); istrip++) {
416 allHits.push_back(&(*istrip));
427 cout <<
"all hits" << endl;
437 vector<const TrackingRecHit*>::iterator iHit;
438 for (iHit = allHits.begin(); iHit < allHits.end(); iHit++) {
441 cout <<
"GH " << gphit << endl;
455 cout <<
"not valid" << endl;
459 cout <<
"all hits end" << endl;
467 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
473 const vector<const TrackingRecHit*>& _Hits,
475 vector<const TrackingRecHit*> Hits = _Hits;
480 cout <<
"CRackTrajectoryBuilder::AddHit" << endl;
484 vector<TrackingRecHitRange> hitRangeByDet;
487 prevDet = Hits.begin();
489 if ((*prevDet)->geographicalId() == (*iHit)->geographicalId())
492 hitRangeByDet.push_back(make_pair(prevDet, iHit));
495 hitRangeByDet.push_back(make_pair(prevDet, Hits.end()));
516 double chi2min =
theEstimator->estimate(prSt, *bestHit).second;
519 cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
523 <<
" " << Hits.end() - iHit << endl;
526 double currChi2 =
theEstimator->estimate(prSt, *tmpHit).second;
527 if (currChi2 < chi2min) {
534 cout << chi2min << endl;
537 cout <<
"chi2 fine : " << chi2min << endl;
540 hits.push_back(bestHit);
541 traj.
push(
TM(prSt, UpdatedState, bestHit, chi2min));
543 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION " 545 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
547 cout <<
"STATE UPDATED WITH HIT AT POSITION " 549 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
551 cout <<
"State is valid ..." << endl;
554 edm::LogWarning(
"CosmicTrackFinder") <<
" State can not be updated with hit at position " << endl;
557 cout <<
"NOT! UPDATED WITH HIT AT POSITION " 559 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
572 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
573 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
574 std::vector<uint32_t> processedDets;
577 trackHitCandidates.clear();
583 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end())
593 trackHitCandidates.push_back(make_pair(iHit, prSt));
596 if (trackHitCandidates.empty())
600 cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
602 cout <<
"Before sorting ... " << endl;
605 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
607 cout << (
tracker->
idToDet((*(iHitRange->first->first))->geographicalId()))->position();
612 stable_sort(trackHitCandidates.begin(),
613 trackHitCandidates.end(),
617 cout <<
"After sorting ... " << endl;
619 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
621 cout << (
tracker->
idToDet((*(iHitRange->first->first))->geographicalId()))->position();
626 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++)
630 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
634 TSOS currPrSt = (*iHitRange).second;
637 cout <<
"curr position" << bestHit->globalPosition();
638 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
641 cout <<
"curr position" << tmpHit->globalPosition();
645 cout <<
"Cross check end ..." << endl;
652 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end();
657 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
666 cout <<
"curr position A" << bestHit->globalPosition() << endl;
667 TSOS currPrSt = (*iHitRange).second;
668 double chi2min =
theEstimator->estimate(currPrSt, *bestHit).second;
671 cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
672 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
675 <<
" " << Hits.end() - iHit << endl;
679 cout <<
"curr position B" << tmpHit->globalPosition() << endl;
680 double currChi2 =
theEstimator->estimate(currPrSt, *tmpHit).second;
681 if (currChi2 < chi2min) {
683 cout <<
"Is best hit" << endl;
696 cout << chi2min << endl;
700 cout <<
"chi2 fine : " << chi2min << endl;
705 hits.push_back(bestHit);
706 traj.
push(
TM(currPrSt, UpdatedState, bestHit, chi2min));
708 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION " 712 cout <<
"Added Hit" << bestHit->globalPosition() << endl;
714 cout <<
"State is valid ..." << UpdatedState << endl;
730 <<
" State can not be updated with hit at position " << bestHit->globalPosition();
738 cout <<
" continue 1 " << endl;
744 cout <<
" continue 2 " << endl;
747 while (iHitRange != trackHitCandidates.end());
756 unsigned int iid = (*hit)->hit()->geographicalId().rawId();
758 if (((iid >> 0) & 0x3) != 1)
792 int lastFitted = 999;
794 if (
nhits < lastFitted + 1)
795 lastFitted =
nhits - 1;
797 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
800 bool foundLast =
false;
801 int actualLast = -99;
802 for (
int i = lastFitted;
i >= 0;
i--) {
808 firstHits.push_back(measvec[
i].
recHit());
811 TSOS unscaledState = measvec[actualLast].updatedState();
829 vector<Trajectory> fitres = backFitter.fit(fakeSeed, firstHits, startingState);
831 if (fitres.size() != 1) {
833 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
845 return std::pair<TrajectoryStateOnSurface, const GeomDet*>(initialState, firstMeas.
recHit()->det());
std::vector< TrackingRecHitRange >::iterator TrackingRecHitRangeIterator
T getParameter(std::string const &) const
friend class CompareDetByTraj
SiStripRecHit2D stereoHit() const
virtual TrajectoryContainer trajectories(const Trajectory &traj) const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const LocalTrajectoryError & localError() const
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Chi2MeasurementEstimator * theEstimator
data_type const * data(size_t cell) const
const TransientTrackingRecHitBuilder * RHBuilder
const LocalTrajectoryParameters & localParameters() const
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj) const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
TransientTrackingRecHit::RecHitContainer hits
const SurfaceType & surface() const
~CRackTrajectoryBuilder()
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
TrajectoryMeasurement const & lastMeasurement() const
std::vector< const TrackingRecHit * >::iterator TrackingRecHitIterator
DataContainer const & measurements() const
T getUntrackedParameter(std::string const &, T const &) const
const KFTrajectorySmoother * theSmoother
std::vector< Trajectory > trajFit
bool qualityFilter(const Trajectory &traj)
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > builderToken_
GlobalPoint globalPosition() const
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
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.
void AddHit(Trajectory &traj, const std::vector< const TrackingRecHit *> &Hits, Propagator *currPropagator)
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
PropagationDirection const & direction() const
ConstRecHitContainer recHits() const
const TrackerGeometry * tracker
TSOS startingTSOS(const TrajectorySeed &seed) const
PropagatorWithMaterial * thePropagatorOp
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerToken_
const TrackerGeomDet * idToDet(DetId) const override
std::shared_ptr< TrackingRecHit const > RecHitPointer
std::vector< ConstRecHitPointer > ConstRecHitContainer
std::vector< TrajectoryMeasurement > seedMeasurements(const TrajectorySeed &seed) const
const MagneticField * magfield
Log< level::Info, false > LogInfo
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const Plane & surface() const
The nominal surface of the GeomDet.
DetId geographicalId() const
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
bool isDifferentStripReHit2D(const SiStripRecHit2D &hitA, const SiStripRecHit2D &hitB)
constexpr uint32_t rawId() const
get the raw id
Trajectory createStartingTrajectory(const TrajectorySeed &seed) const
CRackTrajectoryBuilder(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void init(const edm::EventSetup &es, bool)
const MagneticField * magneticField() const override
PropagatorWithMaterial * thePropagator
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
TrajectoryStateOnSurface const & updatedState() const
const KFTrajectoryFitter * theFitter
TrajectoryMeasurement const & firstMeasurement() const
LocalPoint localPosition() const override
const AlgebraicSymMatrix55 & matrix() const
std::vector< const TrackingRecHit * > SortHits(const SiStripRecHit2DCollection &collstereo, const SiStripRecHit2DCollection &collrphi, const SiStripMatchedRecHit2DCollection &collmatched, const SiPixelRecHitCollection &collpixel, const TrajectorySeed &seed, const bool bAddSeedHits)
SiStripRecHit2D monoHit() const
Log< level::Warning, false > LogWarning
void push(const TrajectoryMeasurement &tm)
ConstRecHitPointer const & recHit() const