CMS 3D CMS Logo

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

#include <TrackAssociatorByPositionImpl.h>

Inheritance diagram for TrackAssociatorByPositionImpl:
reco::TrackToTrackingParticleAssociatorBaseImpl

Public Types

enum  Method { Method::chi2, Method::dist, Method::momdr, Method::posdr }
 
typedef std::vector< SimHitTPPairSimHitTPAssociationList
 
typedef std::pair< TrackingParticleRef, TrackPSimHitRefSimHitTPPair
 

Public Member Functions

reco::RecoToSimCollection associateRecoToSim (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
reco::SimToRecoCollection associateSimToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
 TrackAssociatorByPositionImpl (edm::EDProductGetter const &productGetter, const TrackingGeometry *geo, const Propagator *prop, const SimHitTPAssociationList *assocList, double qMinCut, double qCut, double positionMinimumDistance, Method method, bool minIfNoMatch, bool considerAllSimHits)
 
- Public Member Functions inherited from reco::TrackToTrackingParticleAssociatorBaseImpl
virtual reco::RecoToSimCollection associateRecoToSim (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
 
virtual reco::RecoToSimCollectionSeed associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed >> &, const edm::Handle< TrackingParticleCollection > &) const
 
virtual reco::RecoToSimCollectionTCandidate associateRecoToSim (const edm::Handle< TrackCandidateCollection > &, const edm::RefVector< TrackingParticleCollection > &) const
 
virtual reco::SimToRecoCollection associateSimToReco (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< TrackingParticleCollection > &tPCH) const
 
virtual reco::SimToRecoCollectionSeed associateSimToReco (const edm::Handle< edm::View< TrajectorySeed >> &, const edm::Handle< TrackingParticleCollection > &) const
 
virtual reco::SimToRecoCollectionTCandidate associateSimToReco (const edm::Handle< TrackCandidateCollection > &, const edm::RefVector< TrackingParticleCollection > &) const
 
 TrackToTrackingParticleAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TrackToTrackingParticleAssociatorBaseImpl ()
 Destructor. More...
 

Private Member Functions

FreeTrajectoryState getState (const reco::Track &) const
 
TrajectoryStateOnSurface getState (const TrackingParticleRef &, const SimHitTPAssociationList &simHitsTPAssoc) const
 
double quality (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 

Private Attributes

edm::EDProductGetter const * productGetter_
 
bool theConsiderAllSimHits
 
const TrackingGeometrytheGeometry
 
Method theMethod
 
bool theMinIfNoMatch
 
double thePositionMinimumDistance
 
const PropagatorthePropagator
 
double theQCut
 
double theQminCut
 
const SimHitTPAssociationListtheSimHitsTPAssoc
 

Detailed Description

Class that performs the association of reco::Tracks and TrackingParticles based on position in muon detector

Author
vlimant

Definition at line 31 of file TrackAssociatorByPositionImpl.h.

Member Typedef Documentation

◆ SimHitTPAssociationList

Definition at line 34 of file TrackAssociatorByPositionImpl.h.

◆ SimHitTPPair

Definition at line 33 of file TrackAssociatorByPositionImpl.h.

Member Enumeration Documentation

◆ Method

Enumerator
chi2 
dist 
momdr 
posdr 

Definition at line 35 of file TrackAssociatorByPositionImpl.h.

35 { chi2, dist, momdr, posdr };

Constructor & Destructor Documentation

◆ TrackAssociatorByPositionImpl()

TrackAssociatorByPositionImpl::TrackAssociatorByPositionImpl ( edm::EDProductGetter const &  productGetter,
const TrackingGeometry geo,
const Propagator prop,
const SimHitTPAssociationList assocList,
double  qMinCut,
double  qCut,
double  positionMinimumDistance,
Method  method,
bool  minIfNoMatch,
bool  considerAllSimHits 
)
inline

Definition at line 37 of file TrackAssociatorByPositionImpl.h.

48  theGeometry(geo),
49  thePropagator(prop),
50  theSimHitsTPAssoc(assocList),
51  theQminCut(qMinCut),
52  theQCut(qCut),
55  theMinIfNoMatch(minIfNoMatch),
56  theConsiderAllSimHits(considerAllSimHits) {}
const SimHitTPAssociationList * theSimHitsTPAssoc
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)
edm::EDProductGetter const * productGetter_

Member Function Documentation

◆ associateRecoToSim()

RecoToSimCollection TrackAssociatorByPositionImpl::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tCH,
const edm::RefVector< TrackingParticleCollection > &  tPCH 
) const
overridevirtual

compare reco to sim the handle of reco::Track and TrackingParticle collections

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 117 of file TrackAssociatorByPositionImpl.cc.

References edm::AssociationMap< Tag >::insert(), TrajectoryStateOnSurface::isValid(), edm::AssociationMap< Tag >::post_insert(), quality, edm::RefToBaseVector< T >::size(), edm::RefVector< C, T, F >::size(), and TrajectoryStateOnSurface::surface().

118  {
119  RecoToSimCollection outputCollection(productGetter_);
120  //for each reco track find a matching tracking particle
121  std::pair<unsigned int, unsigned int> minPair;
122  const double dQmin_default = 1542543;
123  double dQmin = dQmin_default;
124 
125  //cdj edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
126 
127  //warning: make sure the TP collection used in the map is the same used in the associator!
128  //e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
129 
130  for (unsigned int Ti = 0; Ti != tCH.size(); ++Ti) {
131  //initial state (initial OR inner OR outter)
132  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
133 
134  bool atLeastOne = false;
135  // for each tracking particle, find a state position and the plane to propagate the track to.
136  for (unsigned int TPi = 0; TPi != tPCH.size(); ++TPi) {
137  //get a state in the muon system
138  TrajectoryStateOnSurface simReferenceState = getState((tPCH)[TPi], *theSimHitsTPAssoc);
139  if (!simReferenceState.isValid())
140  continue;
141 
142  //propagate the TRACK to the surface
143  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState, simReferenceState.surface());
144  if (!trackReferenceState.isValid())
145  continue;
146 
147  //comparison
148  double dQ = quality(trackReferenceState, simReferenceState);
149  if (dQ < theQCut) {
150  atLeastOne = true;
151  outputCollection.insert(tCH[Ti],
152  std::make_pair(tPCH[TPi], -dQ)); //association map with quality, is order greater-first
153  edm::LogVerbatim("TrackAssociatorByPositionImpl")
154  << "track number: " << Ti << " associated with dQ: " << dQ << " to TrackingParticle number: " << TPi;
155  }
156  if (dQ < dQmin) {
157  dQmin = dQ;
158  minPair = std::make_pair(Ti, TPi);
159  }
160  } //loop over tracking particles
161  if (theMinIfNoMatch && !atLeastOne && dQmin != dQmin_default) {
162  outputCollection.insert(tCH[minPair.first], std::make_pair(tPCH[minPair.second], -dQmin));
163  }
164  } //loop over tracks
165  outputCollection.post_insert();
166  return outputCollection;
167 }
Log< level::Info, true > LogVerbatim
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
const SurfaceType & surface() const
size_type size() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
const SimHitTPAssociationList * theSimHitsTPAssoc
FreeTrajectoryState getState(const reco::Track &) const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
edm::EDProductGetter const * productGetter_

◆ associateSimToReco()

SimToRecoCollection TrackAssociatorByPositionImpl::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tCH,
const edm::RefVector< TrackingParticleCollection > &  tPCH 
) const
overridevirtual

compare reco to sim the handle of reco::Track and TrackingParticle collections

Implements reco::TrackToTrackingParticleAssociatorBaseImpl.

Definition at line 169 of file TrackAssociatorByPositionImpl.cc.

References edm::AssociationMap< Tag >::insert(), TrajectoryStateOnSurface::isValid(), edm::AssociationMap< Tag >::post_insert(), quality, edm::RefToBaseVector< T >::size(), edm::RefVector< C, T, F >::size(), and TrajectoryStateOnSurface::surface().

170  {
171  SimToRecoCollection outputCollection(productGetter_);
172  //for each tracking particle, find matching tracks.
173 
174  std::pair<unsigned int, unsigned int> minPair;
175  const double dQmin_default = 1542543;
176  double dQmin = dQmin_default;
177 
178  //edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
179 
180  //warning: make sure the TP collection used in the map is the same used in the associator!
181  //e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
182 
183  for (unsigned int TPi = 0; TPi != tPCH.size(); ++TPi) {
184  //get a state in the muon system
185  TrajectoryStateOnSurface simReferenceState = getState((tPCH)[TPi], *theSimHitsTPAssoc);
186 
187  if (!simReferenceState.isValid())
188  continue;
189  bool atLeastOne = false;
190  // propagate every track from any state (initial, inner, outter) to the surface
191  // and make the position test
192  for (unsigned int Ti = 0; Ti != tCH.size(); ++Ti) {
193  //initial state
194  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
195 
196  //propagation to surface
197  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState, simReferenceState.surface());
198  if (!trackReferenceState.isValid())
199  continue;
200 
201  //comparison
202  double dQ = quality(trackReferenceState, simReferenceState);
203  if (dQ < theQCut) {
204  atLeastOne = true;
205  outputCollection.insert(tPCH[TPi],
206  std::make_pair(tCH[Ti], -dQ)); //association map with quality, is order greater-first
207  edm::LogVerbatim("TrackAssociatorByPositionImpl")
208  << "TrackingParticle number: " << TPi << " associated with dQ: " << dQ << " to track number: " << Ti;
209  }
210  if (dQ < dQmin) {
211  dQmin = dQ;
212  minPair = std::make_pair(TPi, Ti);
213  }
214  } //loop over tracks
215  if (theMinIfNoMatch && !atLeastOne && dQmin != dQmin_default) {
216  outputCollection.insert(tPCH[minPair.first], std::make_pair(tCH[minPair.second], -dQmin));
217  }
218  } //loop over tracking particles
219 
220  outputCollection.post_insert();
221  return outputCollection;
222 }
Log< level::Info, true > LogVerbatim
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
const SurfaceType & surface() const
size_type size() const
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
const SimHitTPAssociationList * theSimHitsTPAssoc
FreeTrajectoryState getState(const reco::Track &) const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
edm::EDProductGetter const * productGetter_

◆ getState() [1/2]

FreeTrajectoryState TrackAssociatorByPositionImpl::getState ( const reco::Track track) const
private

Definition at line 76 of file TrackAssociatorByPositionImpl.cc.

References trajectoryStateTransform::initialFreeState(), and HLT_2022v12_cff::track.

76  {
77  //may be you want to do more than that if track does not go to IP
79 }
virtual const MagneticField * magneticField() const =0
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)

◆ getState() [2/2]

TrajectoryStateOnSurface TrackAssociatorByPositionImpl::getState ( const TrackingParticleRef st,
const SimHitTPAssociationList simHitsTPAssoc 
) const
private

Definition at line 13 of file TrackAssociatorByPositionImpl.cc.

References SurfaceSideDefinition::atCenterOfSurface, submitPVResolutionJobs::count, ztail::d, createTree::dd, mps_fire::end, LogDebug, mag(), FastTimerService_cff::range, GeomDet::surface(), Surface::toGlobal(), and DetId::Tracker.

14  {
15  using SimHitTPPair = std::pair<TrackingParticleRef, TrackPSimHitRef>;
16  SimHitTPPair clusterTPpairWithDummyTP(st, TrackPSimHitRef()); //SimHit is dummy:
17  // sorting only the cluster is needed
18  auto range = std::equal_range(
19  simHitsTPAssoc.begin(),
20  simHitsTPAssoc.end(),
21  clusterTPpairWithDummyTP,
22  [](const SimHitTPPair& iLHS, const SimHitTPPair& iRHS) -> bool { return iLHS.first.key() > iRHS.first.key(); });
23 
24  // TrackingParticle* simtrack = const_cast<TrackingParticle*>(&st);
25  //loop over PSimHits
26  const PSimHit* psimhit = nullptr;
27  const BoundPlane* plane = nullptr;
28  double dLim = thePositionMinimumDistance;
29 
30  // look for the further most hit beyond a certain limit
31  auto start = range.first;
32  auto end = range.second;
33  LogDebug("TrackAssociatorByPositionImpl") << range.second - range.first << " PSimHits.";
34 
35  unsigned int count = 0;
36  for (auto ip = start; ip != end; ++ip) {
37  TrackPSimHitRef psit = ip->second;
38 
39  //get the detid
40  DetId dd(psit->detUnitId());
41 
42  if (!theConsiderAllSimHits && dd.det() != DetId::Tracker)
43  continue;
44 
45  LogDebug("TrackAssociatorByPositionImpl") << count++ << "] PSimHit on: " << dd.rawId();
46  //get the surface from the global geometry
47  const GeomDet* gd = theGeometry->idToDet(dd);
48  if (!gd) {
49  edm::LogError("TrackAssociatorByPositionImpl") << "no geomdet for: " << dd.rawId() << ". will skip.";
50  continue;
51  }
52  double d = gd->surface().toGlobal(psit->localPosition()).mag();
53  if (d > dLim) {
54  dLim = d;
55  psimhit = &(*psit);
56  plane = &gd->surface();
57  }
58  }
59 
60  if (psimhit && plane) {
61  //build a trajectorystate on this surface
63  GlobalPoint initialPoint = plane->toGlobal(psimhit->localPosition());
64  GlobalVector initialMomentum = plane->toGlobal(psimhit->momentumAtEntry());
65  int initialCharge = (psimhit->particleType() > 0) ? -1 : 1;
66  CartesianTrajectoryError initialCartesianErrors; //no error at initial state
67  const GlobalTrajectoryParameters initialParameters(
68  initialPoint, initialMomentum, initialCharge, thePropagator->magneticField());
69  return TrajectoryStateOnSurface(initialParameters, initialCartesianErrors, *plane, surfaceside);
70  } else {
71  // edm::LogError("TrackAssociatorByPositionImpl")<<"no corresponding PSimHit for a tracking particle. will fail.";
72  return TrajectoryStateOnSurface();
73  }
74 }
Definition: start.py:1
Log< level::Error, false > LogError
string dd
Definition: createTree.py:154
std::pair< TrackingParticleRef, TrackPSimHitRef > SimHitTPPair
d
Definition: ztail.py:151
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
Definition: DetId.h:17
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
virtual const GeomDet * idToDet(DetId) const =0
virtual const MagneticField * magneticField() const =0
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
#define LogDebug(id)

◆ quality()

double TrackAssociatorByPositionImpl::quality ( const TrajectoryStateOnSurface tr,
const TrajectoryStateOnSurface sim 
) const
private

Definition at line 81 of file TrackAssociatorByPositionImpl.cc.

References hltPixelTracks_cff::chi2, PV3DBase< T, PVType, FrameType >::eta(), TrajectoryStateOnSurface::globalDirection(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), visualization-live-secondInstance_cfg::m, mag(), LocalTrajectoryError::matrix(), PV3DBase< T, PVType, FrameType >::phi(), findQualityFiles::v, and LocalTrajectoryParameters::vector().

82  {
83  switch (theMethod) {
84  case Method::chi2: {
85  AlgebraicVector5 v(tr.localParameters().vector() - sim.localParameters().vector());
87  int ierr = !m.Invert();
88  if (ierr != 0)
89  edm::LogInfo("TrackAssociatorByPositionImpl") << "error inverting the error matrix:\n" << m;
90  double est = ROOT::Math::Similarity(v, m);
91  return est;
92  break;
93  }
94  case Method::dist: {
95  return (tr.globalPosition() - sim.globalPosition()).mag();
96  break;
97  }
98  case Method::momdr: {
99  return (deltaR<double>(tr.globalDirection().eta(),
100  tr.globalDirection().phi(),
101  sim.globalDirection().eta(),
102  sim.globalDirection().phi()));
103  break;
104  }
105  case Method::posdr: {
106  return (deltaR<double>(
107  tr.globalPosition().eta(), tr.globalPosition().phi(), sim.globalPosition().eta(), sim.globalPosition().phi()));
108  break;
109  }
110  }
111  //should never be reached
112  edm::LogError("TrackAssociatorByPositionImpl")
113  << "option: " << static_cast<int>(theMethod) << " has not been recognized. association has no meaning.";
114  return -1;
115 }
const LocalTrajectoryError & localError() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
const LocalTrajectoryParameters & localParameters() const
Log< level::Error, false > LogError
GlobalPoint globalPosition() const
AlgebraicVector5 vector() const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Log< level::Info, false > LogInfo
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
GlobalVector globalDirection() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const AlgebraicSymMatrix55 & matrix() const

Member Data Documentation

◆ productGetter_

edm::EDProductGetter const* TrackAssociatorByPositionImpl::productGetter_
private

Definition at line 71 of file TrackAssociatorByPositionImpl.h.

◆ theConsiderAllSimHits

bool TrackAssociatorByPositionImpl::theConsiderAllSimHits
private

Definition at line 80 of file TrackAssociatorByPositionImpl.h.

◆ theGeometry

const TrackingGeometry* TrackAssociatorByPositionImpl::theGeometry
private

Definition at line 72 of file TrackAssociatorByPositionImpl.h.

◆ theMethod

Method TrackAssociatorByPositionImpl::theMethod
private

Definition at line 78 of file TrackAssociatorByPositionImpl.h.

◆ theMinIfNoMatch

bool TrackAssociatorByPositionImpl::theMinIfNoMatch
private

Definition at line 79 of file TrackAssociatorByPositionImpl.h.

◆ thePositionMinimumDistance

double TrackAssociatorByPositionImpl::thePositionMinimumDistance
private

Definition at line 77 of file TrackAssociatorByPositionImpl.h.

◆ thePropagator

const Propagator* TrackAssociatorByPositionImpl::thePropagator
private

Definition at line 73 of file TrackAssociatorByPositionImpl.h.

◆ theQCut

double TrackAssociatorByPositionImpl::theQCut
private

Definition at line 76 of file TrackAssociatorByPositionImpl.h.

◆ theQminCut

double TrackAssociatorByPositionImpl::theQminCut
private

Definition at line 75 of file TrackAssociatorByPositionImpl.h.

◆ theSimHitsTPAssoc

const SimHitTPAssociationList* TrackAssociatorByPositionImpl::theSimHitsTPAssoc
private

Definition at line 74 of file TrackAssociatorByPositionImpl.h.