36 edm::LogInfo(
"CosmicTrackFinder") <<
"Minimum number of hits " << theMinHits <<
" Cut on Chi2= " <<
chi2cut;
75 RHBuilder = theBuilder.
product();
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;
228 const GeomDet* hitGeomDet = (&(*tracker))->idToDet(ihit->geographicalId());
231 if (ihit == hitRange.second - 1) {
248 const bool bAddSeedHits) {
252 vector<const TrackingRecHit*> allHits;
260 cout <<
"SEED " << startingTSOS(
seed) << endl;
262 cout <<
"seed hits size " <<
seed.nHits() << endl;
269 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"SEED " << startingTSOS(
seed);
278 int seedHitSize = hRange.second - hRange.first;
280 vector<int> detIDSeedMatched(seedHitSize);
281 vector<int> detIDSeedRphi(seedHitSize);
282 vector<int> detIDSeedStereo(seedHitSize);
284 for (ihit = hRange.first; ihit != hRange.second; ihit++) {
289 yref = RHBuilder->build(&(*ihit))->globalPosition().y();
290 if (ihit == hRange.first) {
299 float_t yGlobStereo = RHBuilder->build(&
s)->globalPosition().y();
302 cout <<
"Rphi ..." << yGlobRPhi << endl;
304 cout <<
"Stereo ..." << yGlobStereo << endl;
306 if (yGlobStereo <
yMin)
308 if (yGlobRPhi <
yMin)
311 if (yGlobStereo >
yMax)
313 if (yGlobRPhi >
yMax)
317 detIDSeedRphi.push_back(
m.geographicalId().rawId());
318 detIDSeedStereo.push_back(
s.geographicalId().rawId());
321 if (useMatchedHits) {
322 hits.push_back((RHBuilder->build(&(*ihit))));
324 if (((yGlobRPhi > yGlobStereo) && seed_plus) || ((yGlobRPhi < yGlobStereo) && !seed_plus)) {
325 hits.push_back((RHBuilder->build(&
m)));
326 hits.push_back((RHBuilder->build(&
s)));
328 hits.push_back((RHBuilder->build(&
s)));
329 hits.push_back((RHBuilder->build(&
m)));
333 }
else if (bAddSeedHits) {
334 hits.push_back((RHBuilder->build(&(*ihit))));
335 detIDSeedRphi.push_back(ihit->geographicalId().rawId());
336 detIDSeedMatched.push_back(-1);
337 detIDSeedStereo.push_back(-1);
348 LogDebug(
"CosmicTrackFinder") <<
"SEED HITS" << RHBuilder->build(&(*ihit))->globalPosition();
350 cout <<
"SEED HITS" << RHBuilder->build(&(*ihit))->globalPosition() << endl;
357 for (ipix = collpixel.
data().begin(); ipix != collpixel.
data().end(); ipix++) {
358 float ych = RHBuilder->build(&(*ipix))->globalPosition().y();
359 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
360 allHits.push_back(&(*ipix));
368 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
369 float ych = RHBuilder->build(&(*istripm))->globalPosition().y();
371 int cDetId = istripm->geographicalId().rawId();
372 bool noSeedDet = (detIDSeedMatched.end() ==
find(detIDSeedMatched.begin(), detIDSeedMatched.end(), cDetId));
375 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
376 allHits.push_back(&(*istripm));
380 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
381 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
383 if (monoDetId.partnerDetId()) {
384 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"this det belongs to a glued det " << ych << endl;
387 int cDetId = istrip->geographicalId().rawId();
388 bool noSeedDet = (detIDSeedRphi.end() ==
find(detIDSeedRphi.begin(), detIDSeedRphi.end(), cDetId));
390 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref))) {
391 bool hitIsUnique =
true;
393 for (istripm = collmatched.
data().begin(); istripm != collmatched.
data().end(); istripm++) {
395 if (isDifferentStripReHit2D(*istrip, (istripm->monoHit())) ==
false) {
397 edm::LogInfo(
"CRackTrajectoryBuilder::SortHits") <<
"rphi hit is in matched hits; y: " << ych << endl;
403 allHits.push_back(&(*istrip));
410 for (istrip = collrphi.
data().begin(); istrip != collrphi.
data().end(); istrip++) {
411 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
412 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
413 allHits.push_back(&(*istrip));
416 for (istrip = collstereo.
data().begin(); istrip != collstereo.
data().end(); istrip++) {
417 float ych = RHBuilder->build(&(*istrip))->globalPosition().y();
418 if ((seed_plus && (ych < yref)) || (!(seed_plus) && (ych > yref)))
419 allHits.push_back(&(*istrip));
430 cout <<
"all hits" << endl;
440 vector<const TrackingRecHit*>::iterator iHit;
441 for (iHit = allHits.begin(); iHit < allHits.end(); iHit++) {
442 GlobalPoint gphit = RHBuilder->build(*iHit)->globalPosition();
444 cout <<
"GH " << gphit << endl;
449 tracker->idToDet((*iHit)->geographicalId())->surface());
458 cout <<
"not valid" << endl;
462 cout <<
"all hits end" << endl;
470 const GeomDet* gdet = (&(*tracker))->idToDet(
DetId(pState.detId()));
476 const vector<const TrackingRecHit*>& _Hits,
478 vector<const TrackingRecHit*> Hits = _Hits;
483 cout <<
"CRackTrajectoryBuilder::AddHit" << endl;
487 vector<TrackingRecHitRange> hitRangeByDet;
490 prevDet = Hits.begin();
492 if ((*prevDet)->geographicalId() == (*iHit)->geographicalId())
495 hitRangeByDet.push_back(make_pair(prevDet, iHit));
498 hitRangeByDet.push_back(make_pair(prevDet, Hits.end()));
502 if (fastPropagation) {
519 double chi2min = theEstimator->estimate(prSt, *bestHit).second;
522 cout <<
"Size " << iHitRange->first - (*iHitRange).second << endl;
526 <<
" " << Hits.end() - iHit << endl;
529 double currChi2 = theEstimator->estimate(prSt, *tmpHit).second;
530 if (currChi2 < chi2min) {
537 cout << chi2min << endl;
540 cout <<
"chi2 fine : " << chi2min << endl;
541 TSOS UpdatedState = theUpdator->
update(prSt, *bestHit);
543 hits.push_back(bestHit);
544 traj.
push(
TM(prSt, UpdatedState, bestHit, chi2min));
546 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION "
548 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
550 cout <<
"STATE UPDATED WITH HIT AT POSITION "
552 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
554 cout <<
"State is valid ..." << endl;
557 edm::LogWarning(
"CosmicTrackFinder") <<
" State can not be updated with hit at position " << endl;
558 TSOS UpdatedState = theUpdator->
update(prSt, *bestHit);
560 cout <<
"NOT! UPDATED WITH HIT AT POSITION "
562 << bestHit->globalPosition() << UpdatedState <<
" " << traj.
chiSquared();
575 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> > trackHitCandidates;
576 std::vector<std::pair<TrackingRecHitRangeIterator, TSOS> >::iterator iHitRange;
577 std::vector<uint32_t> processedDets;
580 trackHitCandidates.clear();
586 if (
find(processedDets.begin(), processedDets.end(), currDet.
rawId()) != processedDets.end())
592 (theEstimator->Chi2MeasurementEstimatorBase::estimate(prSt,
tracker->idToDet(currDet)->surface()) ==
false))
596 trackHitCandidates.push_back(make_pair(iHit, prSt));
599 if (trackHitCandidates.empty())
603 cout << Hits.size() <<
" (int) trackHitCandidates.begin() " << trackHitCandidates.size() << endl;
605 cout <<
"Before sorting ... " << endl;
608 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
610 cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
615 stable_sort(trackHitCandidates.begin(),
616 trackHitCandidates.end(),
620 cout <<
"After sorting ... " << endl;
622 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++) {
624 cout << (
tracker->idToDet((*(iHitRange->first->first))->geographicalId()))->position();
629 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end(); iHitRange++)
633 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
637 TSOS currPrSt = (*iHitRange).second;
640 cout <<
"curr position" << bestHit->globalPosition();
641 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
644 cout <<
"curr position" << tmpHit->globalPosition();
648 cout <<
"Cross check end ..." << endl;
655 for (iHitRange = trackHitCandidates.begin(); iHitRange != trackHitCandidates.end();
660 cout <<
"loop2 " << trackHitCandidates.size() <<
" " << trackHitCandidates.end() - iHitRange << endl;
669 cout <<
"curr position A" << bestHit->globalPosition() << endl;
670 TSOS currPrSt = (*iHitRange).second;
671 double chi2min = theEstimator->estimate(currPrSt, *bestHit).second;
674 cout <<
"Size " << iHitRange->first->second - (*iHitRange).first->first << endl;
675 for (
TrackingRecHitIterator iHit = (*iHitRange).first->first + 1; iHit != iHitRange->first->second; iHit++) {
678 <<
" " << Hits.end() - iHit << endl;
682 cout <<
"curr position B" << tmpHit->globalPosition() << endl;
683 double currChi2 = theEstimator->estimate(currPrSt, *tmpHit).second;
684 if (currChi2 < chi2min) {
686 cout <<
"Is best hit" << endl;
699 cout << chi2min << endl;
703 cout <<
"chi2 fine : " << chi2min << endl;
706 TSOS UpdatedState = theUpdator->
update(currPrSt, *bestHit);
708 hits.push_back(bestHit);
709 traj.
push(
TM(currPrSt, UpdatedState, bestHit, chi2min));
711 edm::LogInfo(
"CosmicTrackFinder") <<
"STATE UPDATED WITH HIT AT POSITION "
715 cout <<
"Added Hit" << bestHit->globalPosition() << endl;
717 cout <<
"State is valid ..." << UpdatedState << endl;
733 <<
" State can not be updated with hit at position " << bestHit->globalPosition();
741 cout <<
" continue 1 " << endl;
747 cout <<
" continue 2 " << endl;
750 while (iHitRange != trackHitCandidates.end());
759 unsigned int iid = (*hit)->hit()->geographicalId().rawId();
761 if (((iid >> 0) & 0x3) != 1)
767 if (ngoodhits >= theMinHits) {
795 int lastFitted = 999;
797 if (
nhits < lastFitted + 1)
798 lastFitted =
nhits - 1;
800 std::vector<TrajectoryMeasurement> measvec = traj.
measurements();
803 bool foundLast =
false;
804 int actualLast = -99;
805 for (
int i = lastFitted;
i >= 0;
i--) {
806 if (measvec[
i].
recHit()->isValid()) {
811 firstHits.push_back(measvec[
i].
recHit());
814 TSOS unscaledState = measvec[actualLast].updatedState();
821 thePropagator->magneticField());
832 vector<Trajectory> fitres = backFitter.fit(fakeSeed, firstHits, startingState);
834 if (fitres.size() != 1) {
836 return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
848 return std::pair<TrajectoryStateOnSurface, const GeomDet*>(initialState, firstMeas.
recHit()->det());