45 category_ =
"Muon|RecoMuon|CosmicMuon|GlobalCosmicMuonTrajectoryBuilder";
110 if (muCand.first ==
nullptr || !muCand.first->isValid()) {
113 muRecHits = muCand.first->recHits();
149 (muonState1.
globalPosition().
y() > tkState1.globalPosition().y()) ? muonState1 : tkState1;
151 (muonState2.globalPosition().y() > tkState2.globalPosition().y()) ? muonState2 : tkState2;
154 (firstState1.globalPosition().y() > firstState2.
globalPosition().
y()) ? firstState1 : firstState2;
158 front =
hits.front()->globalPosition();
159 back =
hits.back()->globalPosition();
160 if ((front.
perp() < 130 && fabs(front.
z()) < 300) || (back.
perp() < 130 && fabs(back.
z()) < 300)) {
161 if (
hits.front()->globalPosition().perp() >
hits.back()->globalPosition().perp())
167 firstState = (tkState1.globalPosition().perp() < tkState2.globalPosition().perp()) ? tkState1 : tkState2;
179 if (refitted.empty()) {
184 if (refitted.empty()) {
189 auto myTraj = std::make_unique<Trajectory>(refitted.front());
191 const std::vector<TrajectoryMeasurement>& mytms = myTraj->measurements();
193 LogTrace(
category_) <<
"Orignally there are " << tkTrack->found() <<
" tk rhs and " << muTrack->found() <<
" mu rhs.";
195 if (mytms.size() <= tkTrack->found()) {
200 result.push_back(std::make_unique<MuonCandidate>(
std::move(myTraj), muTrack, tkTrack));
202 for (std::vector<TrajectoryMeasurement>::const_iterator itm = mytms.begin(); itm != mytms.end(); ++itm) {
203 LogTrace(
category_) <<
"updated pos " << itm->updatedState().globalPosition() <<
"mom "
204 << itm->updatedState().globalMomentum();
212 if (tkHits.empty()) {
216 if (muonHits.empty()) {
221 ConstRecHitContainer::const_iterator frontTkHit = tkHits.begin();
222 ConstRecHitContainer::const_iterator backTkHit = tkHits.end() - 1;
223 while (!(*frontTkHit)->isValid() && frontTkHit != backTkHit) {
226 while (!(*backTkHit)->isValid() && backTkHit != frontTkHit) {
230 ConstRecHitContainer::const_iterator frontMuHit = muonHits.begin();
231 ConstRecHitContainer::const_iterator backMuHit = muonHits.end() - 1;
232 while (!(*frontMuHit)->isValid() && frontMuHit != backMuHit) {
235 while (!(*backMuHit)->isValid() && backMuHit != frontMuHit) {
239 if (frontTkHit == backTkHit) {
243 if (frontMuHit == backMuHit) {
248 GlobalPoint frontTkPos = (*frontTkHit)->globalPosition();
249 GlobalPoint backTkPos = (*backTkHit)->globalPosition();
251 GlobalPoint frontMuPos = (*frontMuHit)->globalPosition();
252 GlobalPoint backMuPos = (*backMuHit)->globalPosition();
255 if (frontTkPos.
y() < backTkPos.
y()) {
256 reverse(tkHits.begin(), tkHits.end());
259 if (frontMuPos.
y() < backMuPos.
y()) {
260 reverse(muonHits.begin(), muonHits.end());
272 ConstRecHitContainer::iterator middlepoint = muonHits.begin();
273 bool insertInMiddle =
false;
275 for (ConstRecHitContainer::iterator ihit = muonHits.begin(); ihit != muonHits.end() - 1; ihit++) {
277 GlobalPoint nextpos = (*(ihit + 1))->globalPosition();
278 if ((ipos - nextpos).
mag() < 100.0)
281 GlobalPoint middle((ipos.
x() + nextpos.
x()) / 2, (ipos.
y() + nextpos.
y()) / 2, (ipos.
z() + nextpos.
z()) / 2);
282 LogTrace(
category_) <<
"ipos " << ipos <<
"nextpos" << nextpos <<
" middle " << middle << endl;
286 insertInMiddle =
true;
292 if (insertInMiddle) {
293 GlobalPoint jointpointpos = (*middlepoint)->globalPosition();
295 if ((frontTkPos - jointpointpos).
mag() >
296 (backTkPos - jointpointpos).
mag()) {
297 reverse(tkHits.begin(), tkHits.end());
299 muonHits.insert(middlepoint + 1, tkHits.begin(), tkHits.end());
302 if (frontTkPos.
y() < frontMuPos.
y()) {
306 hits.insert(
hits.end(), tkHits.begin(), tkHits.end());
308 LogTrace(
category_) <<
"insert at the beginning " << frontTkPos << frontMuPos << endl;
310 hits.insert(
hits.end(), muonHits.begin(), muonHits.end());
325 if ((*hit)->isValid()) {
326 DetId recoid = (*hit)->geographicalId();
330 ->propagate(currTsos,
theService->trackingGeometry()->idToDet(recoid)->surface());
334 result.emplace_back(hitCloner(**
hit, predTsos));
346 std::vector<TrackCand>
result;
353 vector<TrackCand> tkTrackCands;
357 tkTrackCands.push_back(tkCand);
364 if (tkTrackCands.size() <= 1) {
375 outerPos.
basicVector().
dot(outerTsos.globalMomentum().basicVector()) >
377 GlobalPoint geoInnerPos = (innerPos.
mag() < outerPos.
mag()) ? innerPos : outerPos;
383 for (vector<TrackCand>::const_iterator itkCand = tkTrackCands.begin(); itkCand != tkTrackCands.end(); ++itkCand) {
386 GlobalPoint tkInnerPos(tkTrack->innerPosition().x(), tkTrack->innerPosition().y(), tkTrack->innerPosition().z());
387 GlobalPoint tkOuterPos(tkTrack->outerPosition().x(), tkTrack->outerPosition().y(), tkTrack->outerPosition().z());
390 float closetDistance11 = (geoInnerPos - tkInnerPos).
mag();
391 float closetDistance12 = (geoInnerPos - tkOuterPos).
mag();
392 float closetDistance1 = (closetDistance11 < closetDistance12) ? closetDistance11 : closetDistance12;
397 for (vector<TrackCand>::const_iterator itkCand2 = tkTrackCands.begin(); itkCand2 != tkTrackCands.end();
399 if (itkCand2 == itkCand)
404 tkTrack2->innerPosition().x(), tkTrack2->innerPosition().y(), tkTrack2->innerPosition().z());
406 tkTrack2->outerPosition().x(), tkTrack2->outerPosition().y(), tkTrack2->outerPosition().z());
409 float farthestDistance21 = (geoInnerPos - tkInnerPos2).
mag();
410 float farthestDistance22 = (geoInnerPos - tkOuterPos2).
mag();
411 float farthestDistance2 = (farthestDistance21 > farthestDistance22) ? farthestDistance21 : farthestDistance22;
414 if (closetDistance1 > farthestDistance2 - 1
e-3) {
420 result.push_back(*itkCand);
424 result.push_back(*itkCand);
438 LogTrace(
category_) <<
"TrackMatcher found " << matched_trackerTracks.size() <<
"tracker tracks matched";
441 if (matched_trackerTracks.size() < 2) {
442 return matched_trackerTracks;
451 double max_quality = 1e6;
452 for (vector<TrackCand>::const_iterator iter = matched_trackerTracks.begin(); iter != matched_trackerTracks.end();
470 if ((*hit)->isValid()) {
478 if ((*hit)->isValid()) {
489 (posFirst.
x() + posLast.
x()) / 2, (posFirst.
y() + posLast.
y()) / 2, (posFirst.
z() + posLast.
z()) / 2);
491 if ((middle.
mag() < posFirst.
mag()) && (middle.
mag() < posLast.
mag())) {