36 edm::LogInfo(
"CosmicTrackFinder") <<
"Minimum number of hits " << theMinHits <<
" Cut on Chi2= " <<
chi2cut;
75 RHBuilder = theBuilder.
product();
77 theFitter =
new KFTrajectoryFitter(*thePropagator, *theUpdator, *theEstimator);
89 vector<Trajectory>& trajoutput) {
90 std::vector<Trajectory> trajSmooth;
91 std::vector<Trajectory>::iterator trajIter;
93 TrajectorySeedCollection::const_iterator
iseed;
107 seed_plus = !seed_plus;
108 vector<const TrackingRecHit*> allHitsOppsite = SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
true);
109 seed_plus = !seed_plus;
110 if (!allHitsOppsite.empty()) {
114 AddHit(traj, allHitsOppsite, thePropagatorOp);
117 cout <<
"Hits in opposite direction..." << endl;
118 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
119 for (iHit =
hits.begin(); iHit !=
hits.end(); iHit++) {
120 cout << (**iHit).globalPosition() << endl;
129 tracker->idToDet((
hits.front())->geographicalId())->surface())
131 TSOS startingStateNew =
133 tracker->idToDet((
hits.front())->geographicalId())->surface()));
136 cout <<
"Hits in opposite direction reversed..." << endl;
137 TransientTrackingRecHit::RecHitContainer::const_iterator iHit;
138 for (iHit =
hits.begin(); iHit !=
hits.end(); iHit++) {
139 cout << (**iHit).globalPosition() << endl;
144 trajTmp = theFitter->fit(tmpseed,
hits, startingStateNew).front();
147 cout <<
"Debugging show fitted hits" << endl;
148 auto hitsFit = trajTmp.
recHits();
149 for (
auto hit = hitsFit.begin();
hit != hitsFit.end();
hit++) {
150 cout << RHBuilder->build(&(*(*hit)->hit()))->globalPosition() << endl;
156 cout <<
"There are no hits in opposite direction ..." << endl;
159 vector<const TrackingRecHit*> allHits;
162 allHits = SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
false);
166 allHits = SortHits(collstereo, collrphi, collmatched, collpixel, *
iseed,
true);
169 AddHit(traj, allHits, thePropagator);
172 cout <<
"Debugging show All fitted hits" << endl;
175 cout << (*hit)->globalPosition() << endl;
178 cout << qualityFilter(traj) <<
" <- quality filter good?" << endl;
182 cout <<
"now do quality checks" << endl;
183 if (qualityFilter(traj)) {
185 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState =
187 if (initState.first.isValid())
188 trajFit = theFitter->fit(tmpseed,
hits, initState.first);
191 for (trajIter = trajFit.begin(); trajIter != trajFit.end(); trajIter++) {
192 trajSmooth = theSmoother->trajectories((*trajIter));
194 for (trajIter = trajSmooth.begin(); trajIter != trajSmooth.end(); trajIter++) {
195 if ((*trajIter).isValid()) {
197 cout <<
"adding track ... " << endl;
198 trajoutput.push_back((*trajIter));
203 delete thePropagator;
204 delete thePropagatorOp;
216 std::vector<TM>&& seedMeas = seedMeasurements(
seed);
217 for (
auto i : seedMeas)
223 std::vector<TrajectoryMeasurement>
result;
224 auto const& hitRange =
seed.recHits();
225 for (
auto ihit = hitRange.begin(); ihit != hitRange.end(); ihit++) {
228 const GeomDet* hitGeomDet = (&(*tracker))->idToDet(ihit->geographicalId());
231 if (ihit == hitRange.end() - 1) {
232 TSOS updatedState = startingTSOS(
seed);
233 result.emplace_back(invalidState, updatedState,
recHit);
248 const bool bAddSeedHits) {
252 vector<const TrackingRecHit*> allHits;
258 cout <<
"SEED " << startingTSOS(
seed) << endl;
260 cout <<
"seed hits size " <<
seed.nHits() << endl;
267 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"SEED " << startingTSOS(
seed);
276 int seedHitSize =
seed.nHits();
278 vector<int> detIDSeedMatched(seedHitSize);
279 vector<int> detIDSeedRphi(seedHitSize);
280 vector<int> detIDSeedStereo(seedHitSize);
282 auto const& hRange =
seed.recHits();
283 for (
auto ihit = hRange.begin(); ihit != hRange.end(); ihit++) {
288 yref = RHBuilder->build(&(*ihit))->globalPosition().y();
289 if (ihit == hRange.begin()) {
298 float_t yGlobStereo = RHBuilder->build(&
s)->globalPosition().y();
301 cout <<
"Rphi ..." << yGlobRPhi << endl;
303 cout <<
"Stereo ..." << yGlobStereo << endl;
305 if (yGlobStereo <
yMin)
307 if (yGlobRPhi <
yMin)
310 if (yGlobStereo >
yMax)
312 if (yGlobRPhi >
yMax)
316 detIDSeedRphi.push_back(
m.geographicalId().rawId());
317 detIDSeedStereo.push_back(
s.geographicalId().rawId());
320 if (useMatchedHits) {
321 hits.push_back((RHBuilder->build(&(*ihit))));
323 if (((yGlobRPhi > yGlobStereo) && seed_plus) || ((yGlobRPhi < yGlobStereo) && !seed_plus)) {
324 hits.push_back((RHBuilder->build(&
m)));
325 hits.push_back((RHBuilder->build(&
s)));
327 hits.push_back((RHBuilder->build(&
s)));
328 hits.push_back((RHBuilder->build(&
m)));
332 }
else if (bAddSeedHits) {
333 hits.push_back((RHBuilder->build(&(*ihit))));
334 detIDSeedRphi.push_back(ihit->geographicalId().rawId());
335 detIDSeedMatched.push_back(-1);
336 detIDSeedStereo.push_back(-1);
347 LogDebug(
"CosmicTrackFinder") <<
"SEED HITS" << RHBuilder->build(&(*ihit))->globalPosition();
349 cout <<
"SEED HITS" << RHBuilder->build(&(*ihit))->globalPosition() << endl;
356 for (ipix = collpixel.
data().begin(); ipix != collpixel.
data().end(); ipix++) {
357 float ych = RHBuilder->build(&(*ipix))->globalPosition().y();
358 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
359 allHits.push_back(&(*ipix));
367 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
368 float ych = RHBuilder->build(&(*istripm))->globalPosition().y();
370 int cDetId = istripm->geographicalId().rawId();
371 bool noSeedDet = (detIDSeedMatched.end() ==
find(detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId));
374 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
375 allHits.push_back(&(*istripm));
379 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
380 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
382 if (monoDetId.partnerDetId()) {
383 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
386 int cDetId = istrip->geographicalId().rawId();
387 bool noSeedDet = (detIDSeedRphi.end() ==
find(detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId));
389 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref))) {
390 bool hitIsUnique =
true;
392 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
394 if (isDifferentStripReHit2D(*istrip, (istripm->monoHit())) ==
false) {
396 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
402 allHits.push_back(&(*istrip));
409 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
410 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
411 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
412 allHits.push_back(&(*istrip));
415 for (istrip = collstereo.
data().begin(); istrip != collstereo.
data().end(); istrip++) {
416 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
417 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
418 allHits.push_back(&(*istrip));
429 cout <<
"all hits" << endl;
439 vector<const TrackingRecHit*>::iterator iHit;
440 for (iHit = allHits.begin(); iHit < allHits.end(); iHit++) {
441 GlobalPoint gphit = RHBuilder->build(*iHit)->globalPosition();
443 cout <<
"GH " << gphit << endl;
448 tracker->idToDet((*iHit)->geographicalId())->surface());
457 cout <<
"not valid" << endl;
461 cout <<
"all hits end" << endl;
469 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
475 const vector<const TrackingRecHit*>& _Hits,
477 vector<const TrackingRecHit*> Hits = _Hits;
482 cout <<
"CRackTrajectoryBuilder::AddHit" << endl;
486 vector<TrackingRecHitRange> hitRangeByDet;
489 prevDet = Hits.begin();
491 if ((*prevDet)->geographicalId() == (*iHit)->geographicalId())
494 hitRangeByDet.push_back(make_pair(prevDet, iHit));
497 hitRangeByDet.push_back(make_pair(prevDet, Hits.end()));
501 if (fastPropagation) {
518 double chi2min = theEstimator->estimate(prSt, *bestHit).second;
521 cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
525 <<
" " << Hits.end() - iHit << endl;
528 double currChi2 = theEstimator->estimate(prSt, *tmpHit).second;
529 if (currChi2 < chi2min) {
536 cout << chi2min << endl;
539 cout <<
"chi2 fine : " << chi2min << endl;
540 TSOS UpdatedState = theUpdator->
update(prSt, *bestHit);
542 hits.push_back(bestHit);
543 traj.
push(
TM(prSt, UpdatedState, bestHit, chi2min));
545 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION "
547 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
549 cout <<
"STATE UPDATED WITH HIT AT POSITION "
551 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
553 cout <<
"State is valid ..." << endl;
556 edm::LogWarning(
"CosmicTrackFinder") <<
" State can not be updated with hit at position " << endl;
557 TSOS UpdatedState = theUpdator->
update(prSt, *bestHit);
559 cout <<
"NOT! UPDATED WITH HIT AT POSITION "
561 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
574 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
575 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
576 std::vector<uint32_t> processedDets;
579 trackHitCandidates.clear();
585 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end())
591 (theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface()) ==
false))
595 trackHitCandidates.push_back(make_pair(iHit, prSt));
598 if (trackHitCandidates.empty())
602 cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
604 cout <<
"Before sorting ... " << endl;
607 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
609 cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
614 stable_sort(trackHitCandidates.begin(),
615 trackHitCandidates.end(),
619 cout <<
"After sorting ... " << endl;
621 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
623 cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
628 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++)
632 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
636 TSOS currPrSt = (*iHitRange).second;
639 cout <<
"curr position" << bestHit->globalPosition();
640 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
643 cout <<
"curr position" << tmpHit->globalPosition();
647 cout <<
"Cross check end ..." << endl;
654 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end();
659 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
668 cout <<
"curr position A" << bestHit->globalPosition() << endl;
669 TSOS currPrSt = (*iHitRange).second;
670 double chi2min = theEstimator->estimate(currPrSt, *bestHit).second;
673 cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
674 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
677 <<
" " << Hits.end() - iHit << endl;
681 cout <<
"curr position B" << tmpHit->globalPosition() << endl;
682 double currChi2 = theEstimator->estimate(currPrSt, *tmpHit).second;
683 if (currChi2 < chi2min) {
685 cout <<
"Is best hit" << endl;
698 cout << chi2min << endl;
702 cout <<
"chi2 fine : " << chi2min << endl;
705 TSOS UpdatedState = theUpdator->
update(currPrSt, *bestHit);
707 hits.push_back(bestHit);
708 traj.
push(
TM(currPrSt, UpdatedState, bestHit, chi2min));
710 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION "
714 cout <<
"Added Hit" << bestHit->globalPosition() << endl;
716 cout <<
"State is valid ..." << UpdatedState << endl;
732 <<
" State can not be updated with hit at position " << bestHit->globalPosition();
740 cout <<
" continue 1 " << endl;
746 cout <<
" continue 2 " << endl;
749 while (iHitRange != trackHitCandidates.end());
758 unsigned int iid = (*hit)->hit()->geographicalId().rawId();
760 if (((iid >> 0) & 0x3) != 1)
766 if (ngoodhits >= theMinHits) {
794 int lastFitted = 999;
796 if (
nhits < lastFitted + 1)
797 lastFitted =
nhits - 1;
799 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
802 bool foundLast =
false;
803 int actualLast = -99;
804 for (
int i = lastFitted;
i >= 0;
i--) {
805 if (measvec[
i].
recHit()->isValid()) {
810 firstHits.push_back(measvec[
i].
recHit());
813 TSOS unscaledState = measvec[actualLast].updatedState();
820 thePropagator->magneticField());
831 vector<Trajectory> fitres = backFitter.fit(fakeSeed, firstHits, startingState);
833 if (fitres.size() != 1) {
835 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
847 return std::pair<TrajectoryStateOnSurface, const GeomDet*>(initialState, firstMeas.
recHit()->det());