CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
GlobalMuonTrackMatcher Class Reference

#include <GlobalMuonTrackMatcher.h>

Public Types

typedef std::pair< const Trajectory *, reco::TrackRefTrackCand
 

Public Member Functions

std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurfaceconvertToTSOSMuHit (const TrackCand &, const TrackCand &) const
 
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurfaceconvertToTSOSTk (const TrackCand &, const TrackCand &) const
 
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurfaceconvertToTSOSTkHit (const TrackCand &, const TrackCand &) const
 
 GlobalMuonTrackMatcher (const edm::ParameterSet &, const MuonServiceProxy *)
 constructor More...
 
double match (const TrackCand &sta, const TrackCand &track, int matchOption=0, int surfaceOption=1) const
 
std::vector< TrackCandmatch (const TrackCand &sta, const std::vector< TrackCand > &tracks) const
 choose all tracks with a matching-chi2 less than Chi2Cut More...
 
double match_Chi2 (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
double match_D (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
double match_d (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
double match_dist (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
double match_R_IP (const TrackCand &, const TrackCand &) const
 
double match_Rmom (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
double match_Rpos (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
std::vector< TrackCand >::const_iterator matchOne (const TrackCand &sta, const std::vector< TrackCand > &tracks) const
 choose the one tracker track which best matches a muon track More...
 
bool matchTight (const TrackCand &sta, const TrackCand &track) const
 check if two tracks are compatible (less than Chi2Cut, DeltaDCut, DeltaRCut) More...
 
bool samePlane (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
virtual ~GlobalMuonTrackMatcher ()
 destructor More...
 

Private Attributes

double theChi2_1
 
double theChi2_2
 
double theChi2_3
 
double theDeltaD_1
 
double theDeltaD_2
 
double theDeltaD_3
 
double theDeltaR_1
 
double theDeltaR_2
 
double theDeltaR_3
 
double theEta_threshold
 
double theLocChi2
 
double theMinP
 
double theMinPt
 
std::string theOutPropagatorName
 
double thePt_threshold1
 
double thePt_threshold2
 
double theQual_1
 
double theQual_2
 
double theQual_3
 
const MuonServiceProxytheService
 

Detailed Description

Match a standalone muon track with the most compatible tracker tracks in a TrackCollection. GlobalMuonTrackMatcher is used during global muon reconstruction to check the compatability of a tracker track with a standalone muon track. The compatability is determined on a chi2 comparison, of the local parameters of the two corresponding TrajectoryStates on the surface of the innermost muon measurement for momentum below a threshold and above this, with the position and direction parameters on the mentioned surface. If the comparison of local parameters fails to yield any matches, then it makes a comparison of the TSOS local direction.

Author
Edwin Antillon Purdue University
Chang Liu Purdue University
Adam Everett Purdue University
Norbert Neumeister Purdue University

Definition at line 39 of file GlobalMuonTrackMatcher.h.

Member Typedef Documentation

◆ TrackCand

Definition at line 41 of file GlobalMuonTrackMatcher.h.

Constructor & Destructor Documentation

◆ GlobalMuonTrackMatcher()

GlobalMuonTrackMatcher::GlobalMuonTrackMatcher ( const edm::ParameterSet par,
const MuonServiceProxy service 
)

constructor

Definition at line 49 of file GlobalMuonTrackMatcher.cc.

References edm::ParameterSet::getParameter(), theChi2_1, theChi2_2, theChi2_3, theDeltaD_1, theDeltaD_2, theDeltaD_3, theDeltaR_1, theDeltaR_2, theDeltaR_3, theEta_threshold, theLocChi2, theMinP, theMinPt, theOutPropagatorName, thePt_threshold1, thePt_threshold2, theQual_1, theQual_2, and theQual_3.

50  : theService(service) {
51  theMinP = par.getParameter<double>("MinP");
52  theMinPt = par.getParameter<double>("MinPt");
53  thePt_threshold1 = par.getParameter<double>("Pt_threshold1");
54  thePt_threshold2 = par.getParameter<double>("Pt_threshold2");
55  theEta_threshold = par.getParameter<double>("Eta_threshold");
56  theChi2_1 = par.getParameter<double>("Chi2Cut_1");
57  theChi2_2 = par.getParameter<double>("Chi2Cut_2");
58  theChi2_3 = par.getParameter<double>("Chi2Cut_3");
59  theLocChi2 = par.getParameter<double>("LocChi2Cut");
60  theDeltaD_1 = par.getParameter<double>("DeltaDCut_1");
61  theDeltaD_2 = par.getParameter<double>("DeltaDCut_2");
62  theDeltaD_3 = par.getParameter<double>("DeltaDCut_3");
63  theDeltaR_1 = par.getParameter<double>("DeltaRCut_1");
64  theDeltaR_2 = par.getParameter<double>("DeltaRCut_2");
65  theDeltaR_3 = par.getParameter<double>("DeltaRCut_3");
66  theQual_1 = par.getParameter<double>("Quality_1");
67  theQual_2 = par.getParameter<double>("Quality_2");
68  theQual_3 = par.getParameter<double>("Quality_3");
69  theOutPropagatorName = par.getParameter<string>("Propagator");
70 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const MuonServiceProxy * theService

◆ ~GlobalMuonTrackMatcher()

GlobalMuonTrackMatcher::~GlobalMuonTrackMatcher ( )
virtual

destructor

Definition at line 75 of file GlobalMuonTrackMatcher.cc.

75 {}

Member Function Documentation

◆ convertToTSOSMuHit()

std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > GlobalMuonTrackMatcher::convertToTSOSMuHit ( const TrackCand staCand,
const TrackCand tkCand 
) const

Definition at line 417 of file GlobalMuonTrackMatcher.cc.

References taus_updatedMVAIds_cff::category, relativeConstraints::empty, TrajectoryStateOnSurface::freeState(), TrajectoryStateOnSurface::globalPosition(), trajectoryStateTransform::innerStateOnSurface(), TrajectoryStateOnSurface::isValid(), LogTrace, mag(), trajectoryStateTransform::outerStateOnSurface(), theMinP, theMinPt, theOutPropagatorName, and theService.

Referenced by match(), matchOne(), and matchTight().

418  {
419  const string category = "GlobalMuonTrackMatcher";
421  TransientTrack muTT(*staCand.second, &*theService->magneticField(), theService->trackingGeometry());
422  TrajectoryStateOnSurface innerMuTSOS = muTT.innermostMeasurementState();
423  TrajectoryStateOnSurface outerTkTsos, innerTkTsos;
424  if (tkCand.second.isNonnull()) {
425  // make sure the tracker track has enough momentum to reach the muon chambers
426  if (!(tkCand.second->p() < theMinP || tkCand.second->pt() < theMinPt)) {
427  TrajectoryStateOnSurface innerTkTsos;
428 
430  *tkCand.second, *theService->trackingGeometry(), &*theService->magneticField());
432  *tkCand.second, *theService->trackingGeometry(), &*theService->magneticField());
433  // for cosmics, outer-most referst to last traversed layer
434  if ((innerMuTSOS.globalPosition() - outerTkTsos.globalPosition()).mag() >
435  (innerMuTSOS.globalPosition() - innerTkTsos.globalPosition()).mag())
436  outerTkTsos = innerTkTsos;
437  }
438  }
439 
440  if (!innerMuTSOS.isValid() || !outerTkTsos.isValid()) {
441  LogTrace(category) << "A TSOS validity problem! MuTSOS " << innerMuTSOS.isValid() << " TkTSOS "
442  << outerTkTsos.isValid();
443  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
444  }
445 
446  const Surface& refSurface = innerMuTSOS.surface();
447  TrajectoryStateOnSurface tkAtMu =
448  theService->propagator(theOutPropagatorName)->propagate(*outerTkTsos.freeState(), refSurface);
449 
450  if (!tkAtMu.isValid()) {
451  LogTrace(category) << "Could not propagate Muon and Tracker track to the same muon hit surface!";
452  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
453  }
454 
455  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(innerMuTSOS, tkAtMu);
456 }
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
#define LogTrace(id)
GlobalPoint globalPosition() const
const MuonServiceProxy * theService
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
FreeTrajectoryState const * freeState(bool withErrors=true) const
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)

◆ convertToTSOSTk()

std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > GlobalMuonTrackMatcher::convertToTSOSTk ( const TrackCand staCand,
const TrackCand tkCand 
) const

Definition at line 359 of file GlobalMuonTrackMatcher.cc.

References taus_updatedMVAIds_cff::category, relativeConstraints::empty, TrajectoryStateOnSurface::isValid(), LogTrace, trajectoryStateTransform::outerStateOnSurface(), samePlane(), TrajectoryStateOnSurface::surface(), theMinP, theMinPt, theOutPropagatorName, and theService.

360  {
361  const string category = "GlobalMuonTrackMatcher";
362 
364 
365  TransientTrack muTT(*staCand.second, &*theService->magneticField(), theService->trackingGeometry());
366  TrajectoryStateOnSurface impactMuTSOS = muTT.impactPointState();
367 
368  TrajectoryStateOnSurface outerTkTsos;
369  if (tkCand.second.isNonnull()) {
370  // make sure the tracker track has enough momentum to reach the muon chambers
371  if (!(tkCand.second->p() < theMinP || tkCand.second->pt() < theMinPt)) {
373  *tkCand.second, *theService->trackingGeometry(), &*theService->magneticField());
374  }
375  }
376 
377  if (!impactMuTSOS.isValid() || !outerTkTsos.isValid())
378  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
379 
380  // define StateOnTrackerBound object
381  StateOnTrackerBound fromInside(&*theService->propagator(theOutPropagatorName));
382 
383  // extrapolate to outer tracker surface
384  TrajectoryStateOnSurface tkTsosFromMu = fromInside(impactMuTSOS);
385  TrajectoryStateOnSurface tkTsosFromTk = fromInside(outerTkTsos);
386 
387  if (!samePlane(tkTsosFromMu, tkTsosFromTk)) {
388  // propagate tracker track to same surface as muon
389  bool same1, same2;
390  TrajectoryStateOnSurface newTkTsosFromTk, newTkTsosFromMu;
391  if (tkTsosFromMu.isValid())
392  newTkTsosFromTk = theService->propagator(theOutPropagatorName)->propagate(outerTkTsos, tkTsosFromMu.surface());
393  same1 = samePlane(newTkTsosFromTk, tkTsosFromMu);
394  LogTrace(category) << "Propagating to same tracker surface (Mu):" << same1;
395  if (!same1) {
396  if (tkTsosFromTk.isValid())
397  newTkTsosFromMu = theService->propagator(theOutPropagatorName)->propagate(impactMuTSOS, tkTsosFromTk.surface());
398  same2 = samePlane(newTkTsosFromMu, tkTsosFromTk);
399  LogTrace(category) << "Propagating to same tracker surface (Tk):" << same2;
400  }
401  if (same1)
402  tkTsosFromTk = newTkTsosFromTk;
403  else if (same2)
404  tkTsosFromMu = newTkTsosFromMu;
405  else {
406  LogTrace(category) << "Could not propagate Muon and Tracker track to the same tracker bound!";
407  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
408  }
409  }
410 
411  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(tkTsosFromMu, tkTsosFromTk);
412 }
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
const SurfaceType & surface() const
#define LogTrace(id)
const MuonServiceProxy * theService
bool samePlane(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

◆ convertToTSOSTkHit()

std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > GlobalMuonTrackMatcher::convertToTSOSTkHit ( const TrackCand staCand,
const TrackCand tkCand 
) const

Definition at line 461 of file GlobalMuonTrackMatcher.cc.

References taus_updatedMVAIds_cff::category, relativeConstraints::empty, TrajectoryStateOnSurface::globalPosition(), trajectoryStateTransform::innerStateOnSurface(), TrajectoryStateOnSurface::isValid(), LogTrace, mag(), trajectoryStateTransform::outerStateOnSurface(), TrajectoryStateOnSurface::surface(), theMinP, theMinPt, theOutPropagatorName, and theService.

Referenced by match().

462  {
463  const string category = "GlobalMuonTrackMatcher";
464 
466 
467  TransientTrack muTT(*staCand.second, &*theService->magneticField(), theService->trackingGeometry());
468  TrajectoryStateOnSurface impactMuTSOS = muTT.impactPointState();
469  TrajectoryStateOnSurface innerMuTSOS = muTT.innermostMeasurementState();
470 
471  TrajectoryStateOnSurface outerTkTsos, innerTkTsos;
472  if (tkCand.second.isNonnull()) {
473  // make sure the tracker track has enough momentum to reach the muon chambers
474  if (!(tkCand.second->p() < theMinP || tkCand.second->pt() < theMinPt)) {
476  *tkCand.second, *theService->trackingGeometry(), &*theService->magneticField());
478  *tkCand.second, *theService->trackingGeometry(), &*theService->magneticField());
479 
480  // for cosmics, outer-most referst to last traversed layer
481  if ((innerMuTSOS.globalPosition() - outerTkTsos.globalPosition()).mag() >
482  (innerMuTSOS.globalPosition() - innerTkTsos.globalPosition()).mag())
483  outerTkTsos = innerTkTsos;
484  }
485  }
486 
487  if (!impactMuTSOS.isValid() || !outerTkTsos.isValid()) {
488  LogTrace(category) << "A TSOS validity problem! MuTSOS " << impactMuTSOS.isValid() << " TkTSOS "
489  << outerTkTsos.isValid();
490  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
491  }
492 
493  const Surface& refSurface = outerTkTsos.surface();
494  TrajectoryStateOnSurface muAtTk =
495  theService->propagator(theOutPropagatorName)->propagate(*impactMuTSOS.freeState(), refSurface);
496 
497  if (!muAtTk.isValid()) {
498  LogTrace(category) << "Could not propagate Muon and Tracker track to the same tracker hit surface!";
499  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(empty, empty);
500  }
501 
502  return pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface>(muAtTk, outerTkTsos);
503 }
TrajectoryStateOnSurface outerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)
const SurfaceType & surface() const
#define LogTrace(id)
GlobalPoint globalPosition() const
const MuonServiceProxy * theService
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field, bool withErr=true)

◆ match() [1/2]

double GlobalMuonTrackMatcher::match ( const TrackCand sta,
const TrackCand track,
int  matchOption = 0,
int  surfaceOption = 1 
) const

check if two tracks are compatible matchOption: 0 = chi2, 1 = distance, 2 = deltaR surfaceOption: 0 = outermost tracker surface, 1 = innermost muon system surface

Definition at line 100 of file GlobalMuonTrackMatcher.cc.

References convertToTSOSMuHit(), convertToTSOSTkHit(), match_Chi2(), match_d(), match_dist(), match_Rpos(), and HLT_2022v12_cff::track.

Referenced by GlobalCosmicMuonTrajectoryBuilder::match(), GlobalTrackQualityProducer::produce(), GlobalMuonTrajectoryBuilder::trajectories(), and L3MuonTrajectoryBuilder::trajectories().

103  {
104  std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair;
105  if (surfaceOption == 0)
106  tsosPair = convertToTSOSMuHit(sta, track);
107  if (surfaceOption == 1)
108  tsosPair = convertToTSOSTkHit(sta, track);
109  if (surfaceOption != 0 && surfaceOption != 1)
110  return -1.0;
111 
112  if (matchOption == 0) {
113  // chi^2
114  return match_Chi2(tsosPair.first, tsosPair.second);
115  } else if (matchOption == 1) {
116  // distance
117  return match_d(tsosPair.first, tsosPair.second);
118  } else if (matchOption == 2) {
119  // deltaR
120  return match_Rpos(tsosPair.first, tsosPair.second);
121  } else if (matchOption == 3) {
122  return match_dist(tsosPair.first, tsosPair.second);
123  } else {
124  return -1.0;
125  }
126 }
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
double match_dist(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_d(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSTkHit(const TrackCand &, const TrackCand &) const
double match_Chi2(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_Rpos(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

◆ match() [2/2]

vector< GlobalMuonTrackMatcher::TrackCand > GlobalMuonTrackMatcher::match ( const TrackCand sta,
const std::vector< TrackCand > &  tracks 
) const

choose all tracks with a matching-chi2 less than Chi2Cut

Definition at line 160 of file GlobalMuonTrackMatcher.cc.

References PV3DBase< T, PVType, FrameType >::barePhi(), HLT_2022v12_cff::cands, taus_updatedMVAIds_cff::category, hltPixelTracks_cff::chi2, convertToTSOSMuHit(), SiPixelRawToDigiRegional_cfi::deltaPhi, PbPb_ZMuSkimMuonDPG_cff::deltaR, HLT_2022v12_cff::distance, PV3DBase< T, PVType, FrameType >::eta(), TrajectoryStateOnSurface::globalPosition(), cuy::ii, createfilelist::int, TrajectoryStateOnSurface::isValid(), findQualityFiles::jj, LogTrace, match_Chi2(), match_d(), match_dist(), match_Rpos(), mps_fire::result, theChi2_1, theChi2_2, theDeltaD_1, theDeltaD_2, theDeltaR_1, theDeltaR_2, theEta_threshold, theLocChi2, thePt_threshold1, thePt_threshold2, theQual_1, theQual_2, theQual_3, and tracks.

161  {
162  const string category = "GlobalMuonTrackMatcher";
163 
164  vector<TrackCand> result;
165 
166  if (tracks.empty())
167  return result;
168 
169  typedef std::pair<TrackCand, TrajectoryStateOnSurface> TrackCandWithTSOS;
170  vector<TrackCandWithTSOS> cands;
171  int iiTk = 1;
172  TrajectoryStateOnSurface muonTSOS;
173 
174  LogTrace(category) << " ***" << endl << "STA Muon pT " << sta.second->pt();
175  LogTrace(category) << " Tk in Region " << tracks.size() << endl;
176 
177  for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is, iiTk++) {
178  // propagate to a common surface
179  std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair = convertToTSOSMuHit(sta, *is);
180  LogTrace(category) << " Tk " << iiTk << " of " << tracks.size() << " ConvertToMuHitSurface muon isValid "
181  << tsosPair.first.isValid() << " tk isValid " << tsosPair.second.isValid() << endl;
182  if (tsosPair.first.isValid())
183  muonTSOS = tsosPair.first;
184  cands.push_back(TrackCandWithTSOS(*is, tsosPair.second));
185  }
186 
187  // initialize variables
188  double min_chisq = 999999;
189  double min_d = 999999;
190  double min_de = 999999;
191  double min_r_pos = 999999;
192  std::vector<bool> passes(cands.size(), false);
193  int jj = 0;
194 
195  int iTkCand = 1;
196  for (vector<TrackCandWithTSOS>::const_iterator ii = cands.begin(); ii != cands.end(); ++ii, jj++, iTkCand++) {
197  // tracks that are able not able propagate to a common surface
198  if (!muonTSOS.isValid() || !(*ii).second.isValid())
199  continue;
200 
201  // calculate matching variables
202  double distance = match_d(muonTSOS, (*ii).second);
203  double chi2 = match_Chi2(muonTSOS, (*ii).second);
204  double loc_chi2 = match_dist(muonTSOS, (*ii).second);
205  double deltaR = match_Rpos(muonTSOS, (*ii).second);
206 
207  LogTrace(category) << " iTk " << iTkCand << " of " << cands.size() << " eta "
208  << (*ii).second.globalPosition().eta() << " phi " << (*ii).second.globalPosition().phi() << endl;
209  LogTrace(category) << " distance " << distance << " distance cut "
210  << " " << endl;
211  LogTrace(category) << " chi2 " << chi2 << " chi2 cut "
212  << " " << endl;
213  LogTrace(category) << " loc_chi2 " << loc_chi2 << " locChi2 cut "
214  << " " << endl;
215  LogTrace(category) << " deltaR " << deltaR << " deltaR cut "
216  << " " << endl;
217 
218  if ((*ii).second.globalMomentum().perp() < thePt_threshold1) {
219  LogTrace(category) << " Enters a1" << endl;
220 
221  if ((chi2 > 0 && fabs((*ii).second.globalMomentum().eta()) < theEta_threshold && chi2 < theChi2_1) ||
222  (distance > 0 && distance / (*ii).first.second->pt() < theDeltaD_1 && loc_chi2 > 0 &&
223  loc_chi2 < theLocChi2)) {
224  LogTrace(category) << " Passes a1" << endl;
225  result.push_back((*ii).first);
226  passes[jj] = true;
227  }
228  }
229  if ((passes[jj] == false) && (*ii).second.globalMomentum().perp() < thePt_threshold2) {
230  LogTrace(category) << " Enters a2" << endl;
231  if ((chi2 > 0 && chi2 < theChi2_2) || (distance > 0 && distance < theDeltaD_2)) {
232  LogTrace(category) << " Passes a2" << endl;
233  result.push_back((*ii).first);
234  passes[jj] = true;
235  }
236  } else {
237  LogTrace(category) << " Enters a3" << endl;
238  if (distance > 0 && distance < theDeltaD_3 && deltaR > 0 && deltaR < theDeltaR_1) {
239  LogTrace(category) << " Passes a3" << endl;
240  result.push_back((*ii).first);
241  passes[jj] = true;
242  }
243  }
244 
245  if (passes[jj]) {
246  if (distance < min_d)
247  min_d = distance;
248  if (loc_chi2 < min_de)
249  min_de = loc_chi2;
250  if (deltaR < min_r_pos)
251  min_r_pos = deltaR;
252  if (chi2 < min_chisq)
253  min_chisq = chi2;
254  }
255  }
256 
257  // re-initialize mask counter
258  jj = 0;
259 
260  if (result.empty()) {
261  LogTrace(category) << " Stage 1 returned 0 results";
262  for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is, jj++) {
263  double deltaR = match_Rpos(muonTSOS, (*is).second);
264 
265  if (muonTSOS.isValid() && (*is).second.isValid()) {
266  // check matching between tracker and muon tracks using dEta cut looser then dPhi cut
267  LogTrace(category) << " Stage 2 deltaR " << deltaR << " deltaEta "
268  << fabs((*is).second.globalPosition().eta() - muonTSOS.globalPosition().eta() <
269  1.5 * theDeltaR_2)
270  << " deltaPhi "
271  << (fabs(deltaPhi((*is).second.globalPosition().barePhi(),
272  muonTSOS.globalPosition().barePhi())) < theDeltaR_2)
273  << endl;
274 
275  if (fabs((*is).second.globalPosition().eta() - muonTSOS.globalPosition().eta()) < 1.5 * theDeltaR_2 &&
276  fabs(deltaPhi((*is).second.globalPosition().barePhi(), muonTSOS.globalPosition().barePhi())) <
277  theDeltaR_2) {
278  result.push_back((*is).first);
279  passes[jj] = true;
280  }
281  }
282 
283  if (passes[jj]) {
284  double distance = match_d(muonTSOS, (*is).second);
285  double chi2 = match_Chi2(muonTSOS, (*is).second);
286  double loc_chi2 = match_dist(muonTSOS, (*is).second);
287  if (distance < min_d)
288  min_d = distance;
289  if (loc_chi2 < min_de)
290  min_de = loc_chi2;
291  if (deltaR < min_r_pos)
292  min_r_pos = deltaR;
293  if (chi2 < min_chisq)
294  min_chisq = chi2;
295  }
296  }
297  }
298 
299  for (vector<TrackCand>::const_iterator iTk = result.begin(); iTk != result.end(); ++iTk) {
300  LogTrace(category) << " -----" << endl
301  << "selected pt " << iTk->second->pt() << " eta " << iTk->second->eta() << " phi "
302  << iTk->second->phi() << endl;
303  }
304 
305  if (result.size() < 2)
306  return result;
307  else
308  result.clear();
309 
310  LogTrace(category) << " Cleaning matched candiates" << endl;
311 
312  // re-initialize mask counter
313  jj = 0;
314 
315  for (vector<TrackCandWithTSOS>::const_iterator is = cands.begin(); is != cands.end(); ++is, jj++) {
316  if (!passes[jj])
317  continue;
318 
319  double distance = match_d(muonTSOS, (*is).second);
320  double chi2 = match_Chi2(muonTSOS, (*is).second);
321  //unused double loc_chi2 = match_dist(muonTSOS,(*is).second);
322  double deltaR = match_Rpos(muonTSOS, (*is).second);
323 
324  // compute quality as the relative ratio to the minimum found for each variable
325 
326  int qual = (int)(chi2 / min_chisq + distance / min_d + deltaR / min_r_pos);
327  int n_min =
328  ((chi2 / min_chisq == 1) ? 1 : 0) + ((distance / min_d == 1) ? 1 : 0) + ((deltaR / min_r_pos == 1) ? 1 : 0);
329 
330  if (n_min == 3) {
331  result.push_back((*is).first);
332  }
333 
334  if (n_min == 2 && qual < theQual_1) {
335  result.push_back((*is).first);
336  }
337 
338  if (n_min == 1 && qual < theQual_2) {
339  result.push_back((*is).first);
340  }
341 
342  if (n_min == 0 && qual < theQual_3) {
343  result.push_back((*is).first);
344  }
345  }
346 
347  for (vector<TrackCand>::const_iterator iTk = result.begin(); iTk != result.end(); ++iTk) {
348  LogTrace(category) << " -----" << endl
349  << "selected pt " << iTk->second->pt() << " eta " << iTk->second->eta() << " phi "
350  << iTk->second->phi() << endl;
351  }
352 
353  return result;
354 }
T eta() const
Definition: PV3DBase.h:73
#define LogTrace(id)
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
T barePhi() const
Definition: PV3DBase.h:65
double match_dist(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
GlobalPoint globalPosition() const
double match_d(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
ii
Definition: cuy.py:589
auto const & tracks
cannot be loose
double match_Chi2(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_Rpos(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

◆ match_Chi2()

double GlobalMuonTrackMatcher::match_Chi2 ( const TrajectoryStateOnSurface tsos1,
const TrajectoryStateOnSurface tsos2 
) const

Definition at line 533 of file GlobalMuonTrackMatcher.cc.

References taus_updatedMVAIds_cff::category, TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), visualization-live-secondInstance_cfg::m, LocalTrajectoryError::matrix(), findQualityFiles::v, and LocalTrajectoryParameters::vector().

Referenced by match(), matchOne(), and matchTight().

534  {
535  const string category = "GlobalMuonTrackMatcher";
536  //LogTrace(category) << "match_Chi2 sanity check: " << tsos1.isValid() << " " << tsos2.isValid();
537  if (!tsos1.isValid() || !tsos2.isValid())
538  return -1.;
539 
541  AlgebraicSymMatrix55 m(tsos1.localError().matrix() + tsos2.localError().matrix());
542 
543  //LogTrace(category) << "match_Chi2 vector v " << v;
544 
545  bool ierr = !m.Invert();
546 
547  if (ierr) {
548  edm::LogInfo(category) << "Error inverting covariance matrix";
549  return -1;
550  }
551 
552  double est = ROOT::Math::Similarity(v, m);
553 
554  //LogTrace(category) << "Chi2 " << est;
555 
556  return est;
557 }
const LocalTrajectoryError & localError() const
const LocalTrajectoryParameters & localParameters() const
AlgebraicVector5 vector() const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Log< level::Info, false > LogInfo
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const AlgebraicSymMatrix55 & matrix() const

◆ match_D()

double GlobalMuonTrackMatcher::match_D ( const TrajectoryStateOnSurface sta,
const TrajectoryStateOnSurface tk 
) const

Definition at line 596 of file GlobalMuonTrackMatcher.cc.

References TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::isValid(), and mag().

Referenced by samePlane().

596  {
597  if (!sta.isValid() || !tk.isValid())
598  return -1;
599  return (sta.globalPosition() - tk.globalPosition()).mag();
600 }
GlobalPoint globalPosition() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())

◆ match_d()

double GlobalMuonTrackMatcher::match_d ( const TrajectoryStateOnSurface sta,
const TrajectoryStateOnSurface tk 
) const

Definition at line 605 of file GlobalMuonTrackMatcher.cc.

References TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localPosition(), and mag().

Referenced by match(), matchTight(), and samePlane().

605  {
606  if (!sta.isValid() || !tk.isValid())
607  return -1;
608  return (sta.localPosition() - tk.localPosition()).mag();
609 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())

◆ match_dist()

double GlobalMuonTrackMatcher::match_dist ( const TrajectoryStateOnSurface sta,
const TrajectoryStateOnSurface tk 
) const

Definition at line 615 of file GlobalMuonTrackMatcher.cc.

References taus_updatedMVAIds_cff::category, TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), LogTrace, visualization-live-secondInstance_cfg::m, LocalTrajectoryError::positionError(), findQualityFiles::v, PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), LocalError::xy(), PV3DBase< T, PVType, FrameType >::y(), and LocalError::yy().

Referenced by match().

616  {
617  const string category = "GlobalMuonTrackMatcher";
618 
619  if (!sta.isValid() || !tk.isValid())
620  return -1;
621 
623  m(0, 0) = tk.localError().positionError().xx() + sta.localError().positionError().xx();
624  m(1, 0) = m(0, 1) = tk.localError().positionError().xy() + sta.localError().positionError().xy();
625  m(1, 1) = tk.localError().positionError().yy() + sta.localError().positionError().yy();
626 
628  v[0] = tk.localPosition().x() - sta.localPosition().x();
629  v[1] = tk.localPosition().y() - sta.localPosition().y();
630 
631  if (!m.Invert()) {
632  LogTrace(category) << "Error inverting local matrix ";
633  return -1;
634  }
635 
636  return ROOT::Math::Similarity(v, m);
637 }
const LocalTrajectoryError & localError() const
LocalError positionError() const
#define LogTrace(id)
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
ROOT::Math::SVector< double, 2 > AlgebraicVector2
float xy() const
Definition: LocalError.h:23
ROOT::Math::SMatrix< double, 2, 2, ROOT::Math::MatRepStd< double, 2, 2 > > AlgebraicMatrix22
float xx() const
Definition: LocalError.h:22

◆ match_R_IP()

double GlobalMuonTrackMatcher::match_R_IP ( const TrackCand staCand,
const TrackCand tkCand 
) const

Definition at line 562 of file GlobalMuonTrackMatcher.cc.

References HGC3DClusterGenMatchSelector_cfi::dR.

562  {
563  double dR = 99.0;
564  if (tkCand.second.isNonnull()) {
565  dR = (deltaR<double>(staCand.second->eta(), staCand.second->phi(), tkCand.second->eta(), tkCand.second->phi()));
566  }
567 
568  return dR;
569 }

◆ match_Rmom()

double GlobalMuonTrackMatcher::match_Rmom ( const TrajectoryStateOnSurface sta,
const TrajectoryStateOnSurface tk 
) const

Definition at line 574 of file GlobalMuonTrackMatcher.cc.

References PV3DBase< T, PVType, FrameType >::eta(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::isValid(), and PV3DBase< T, PVType, FrameType >::phi().

575  {
576  if (!sta.isValid() || !tk.isValid())
577  return -1;
578  return (deltaR<double>(
579  sta.globalMomentum().eta(), sta.globalMomentum().phi(), tk.globalMomentum().eta(), tk.globalMomentum().phi()));
580 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
GlobalVector globalMomentum() const

◆ match_Rpos()

double GlobalMuonTrackMatcher::match_Rpos ( const TrajectoryStateOnSurface sta,
const TrajectoryStateOnSurface tk 
) const

Definition at line 585 of file GlobalMuonTrackMatcher.cc.

References PV3DBase< T, PVType, FrameType >::eta(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::isValid(), and PV3DBase< T, PVType, FrameType >::phi().

Referenced by match().

586  {
587  if (!sta.isValid() || !tk.isValid())
588  return -1;
589  return (deltaR<double>(
590  sta.globalPosition().eta(), sta.globalPosition().phi(), tk.globalPosition().eta(), tk.globalPosition().phi()));
591 }
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
GlobalPoint globalPosition() const

◆ matchOne()

std::vector< GlobalMuonTrackMatcher::TrackCand >::const_iterator GlobalMuonTrackMatcher::matchOne ( const TrackCand sta,
const std::vector< TrackCand > &  tracks 
) const

choose the one tracker track which best matches a muon track

Definition at line 132 of file GlobalMuonTrackMatcher.cc.

References hltPixelTracks_cff::chi2, convertToTSOSMuHit(), match_Chi2(), MTVHistoProducerAlgoForTrackerBlock_cfi::minChi2, mps_fire::result, and tracks.

133  {
134  if (tracks.empty())
135  return tracks.end();
136 
137  double minChi2 = 1000.0;
138  vector<TrackCand>::const_iterator result = tracks.end();
139  for (vector<TrackCand>::const_iterator is = tracks.begin(); is != tracks.end(); ++is) {
140  // propagate to common surface
141  std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair = convertToTSOSMuHit(sta, *is);
142 
143  // calculate chi^2 of local track parameters
144  double chi2 = match_Chi2(tsosPair.first, tsosPair.second);
145  if (chi2 > 0. && chi2 <= minChi2) {
146  minChi2 = chi2;
147  result = is;
148  }
149  }
150 
151  return result;
152 }
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
auto const & tracks
cannot be loose
double match_Chi2(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

◆ matchTight()

bool GlobalMuonTrackMatcher::matchTight ( const TrackCand sta,
const TrackCand track 
) const

check if two tracks are compatible (less than Chi2Cut, DeltaDCut, DeltaRCut)

Definition at line 80 of file GlobalMuonTrackMatcher.cc.

References hltPixelTracks_cff::chi2, convertToTSOSMuHit(), HLT_2022v12_cff::distance, match_Chi2(), match_d(), theChi2_2, theDeltaD_2, and HLT_2022v12_cff::track.

Referenced by GlobalTrackQualityProducer::produce().

80  {
81  std::pair<TrajectoryStateOnSurface, TrajectoryStateOnSurface> tsosPair = convertToTSOSMuHit(sta, track);
82 
83  double chi2 = match_Chi2(tsosPair.first, tsosPair.second);
84  if (chi2 > 0. && chi2 < theChi2_2)
85  return true;
86 
87  double distance = match_d(tsosPair.first, tsosPair.second);
88  if (distance > 0. && distance < theDeltaD_2)
89  return true;
90 
91  //double deltaR = match_Rpos(tsosPair.first,tsosPair.second);
92  //if ( deltaR > 0. && deltaR < theDeltaR_3 ) return true;
93 
94  return false;
95 }
std::pair< TrajectoryStateOnSurface, TrajectoryStateOnSurface > convertToTSOSMuHit(const TrackCand &, const TrackCand &) const
double match_d(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_Chi2(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

◆ samePlane()

bool GlobalMuonTrackMatcher::samePlane ( const TrajectoryStateOnSurface tsos1,
const TrajectoryStateOnSurface tsos2 
) const

Definition at line 508 of file GlobalMuonTrackMatcher.cc.

References TrajectoryStateOnSurface::isValid(), TrajectoryStateOnSurface::localPosition(), match_D(), match_d(), LaserDQM_cfg::p1, SiStripOfflineCRack_cfg::p2, TrajectoryStateOnSurface::surface(), and Surface::tangentPlane().

Referenced by convertToTSOSTk().

509  {
510  if (!tsos1.isValid() || !tsos2.isValid())
511  return false;
512 
513  if (fabs(match_D(tsos1, tsos2) - match_d(tsos1, tsos2)) > 0.1)
514  return false;
515 
516  const float maxtilt = 0.999;
517  const float maxdist = 0.01; // in cm
518 
519  auto p1(tsos1.surface().tangentPlane(tsos1.localPosition()));
520  auto p2(tsos2.surface().tangentPlane(tsos2.localPosition()));
521 
522  bool returnValue = ((fabs(p1->normalVector().dot(p2->normalVector())) > maxtilt) ||
523  (fabs((p1->toLocal(p2->position())).z()) < maxdist))
524  ? true
525  : false;
526 
527  return returnValue;
528 }
virtual ConstReferenceCountingPointer< TangentPlane > tangentPlane(const GlobalPoint &) const =0
const SurfaceType & surface() const
double match_d(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
double match_D(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const

Member Data Documentation

◆ theChi2_1

double GlobalMuonTrackMatcher::theChi2_1
private

Definition at line 85 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theChi2_2

double GlobalMuonTrackMatcher::theChi2_2
private

Definition at line 86 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), match(), and matchTight().

◆ theChi2_3

double GlobalMuonTrackMatcher::theChi2_3
private

Definition at line 87 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher().

◆ theDeltaD_1

double GlobalMuonTrackMatcher::theDeltaD_1
private

Definition at line 89 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theDeltaD_2

double GlobalMuonTrackMatcher::theDeltaD_2
private

Definition at line 90 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), match(), and matchTight().

◆ theDeltaD_3

double GlobalMuonTrackMatcher::theDeltaD_3
private

Definition at line 91 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher().

◆ theDeltaR_1

double GlobalMuonTrackMatcher::theDeltaR_1
private

Definition at line 92 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theDeltaR_2

double GlobalMuonTrackMatcher::theDeltaR_2
private

Definition at line 93 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theDeltaR_3

double GlobalMuonTrackMatcher::theDeltaR_3
private

Definition at line 94 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher().

◆ theEta_threshold

double GlobalMuonTrackMatcher::theEta_threshold
private

Definition at line 84 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theLocChi2

double GlobalMuonTrackMatcher::theLocChi2
private

Definition at line 88 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theMinP

double GlobalMuonTrackMatcher::theMinP
private

◆ theMinPt

double GlobalMuonTrackMatcher::theMinPt
private

◆ theOutPropagatorName

std::string GlobalMuonTrackMatcher::theOutPropagatorName
private

◆ thePt_threshold1

double GlobalMuonTrackMatcher::thePt_threshold1
private

Definition at line 82 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ thePt_threshold2

double GlobalMuonTrackMatcher::thePt_threshold2
private

Definition at line 83 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theQual_1

double GlobalMuonTrackMatcher::theQual_1
private

Definition at line 95 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theQual_2

double GlobalMuonTrackMatcher::theQual_2
private

Definition at line 96 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theQual_3

double GlobalMuonTrackMatcher::theQual_3
private

Definition at line 97 of file GlobalMuonTrackMatcher.h.

Referenced by GlobalMuonTrackMatcher(), and match().

◆ theService

const MuonServiceProxy* GlobalMuonTrackMatcher::theService
private