CMS 3D CMS Logo

TrackAssociatorByPositionImpl.cc
Go to the documentation of this file.
3 
6 
8 //#include "PhysicsTools/Utilities/interface/DeltaR.h"
9 
10 using namespace edm;
11 using namespace reco;
12 
14  const SimHitTPAssociationList& simHitsTPAssoc) const {
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 }
75 
77  //may be you want to do more than that if track does not go to IP
78  return trajectoryStateTransform::initialFreeState(track, thePropagator->magneticField());
79 }
80 
82  const TrajectoryStateOnSurface& sim) const {
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 }
116 
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 }
168 
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 }
Vector3DBase
Definition: Vector3DBase.h:8
TrajectoryStateOnSurface::globalDirection
GlobalVector globalDirection() const
Definition: TrajectoryStateOnSurface.h:67
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
TrackAssociatorByPositionImpl::associateSimToReco
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
Definition: TrackAssociatorByPositionImpl.cc:169
start
Definition: start.py:1
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11713
GeomDet
Definition: GeomDet.h:27
trajectoryStateTransform::initialFreeState
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field, bool withErr=true)
Definition: TrajectoryStateTransform.cc:58
TrackAssociatorByPositionImpl::quality
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
Definition: TrackAssociatorByPositionImpl.cc:81
edm
HLT enums.
Definition: AlignableModifier.h:19
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
SurfaceSideDefinition::SurfaceSide
SurfaceSide
Definition: SurfaceSideDefinition.h:8
LocalTrajectoryError::matrix
const AlgebraicSymMatrix55 & matrix() const
Definition: LocalTrajectoryError.h:60
edm::RefVector< TrackingParticleCollection >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
findQualityFiles.v
v
Definition: findQualityFiles.py:179
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
SurfaceSideDefinition::atCenterOfSurface
Definition: SurfaceSideDefinition.h:8
TrackAssociatorByPositionImpl.h
edm::Ref< TrackingParticleCollection >
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:109
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
edm::AssociationMap::post_insert
void post_insert()
post insert action
Definition: AssociationMap.h:229
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
mps_fire.end
end
Definition: mps_fire.py:242
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
reco::Track
Definition: Track.h:27
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
TrackAssociatorByPositionImpl::getState
FreeTrajectoryState getState(const reco::Track &) const
Definition: TrackAssociatorByPositionImpl.cc:76
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
LocalTrajectoryParameters::vector
AlgebraicVector5 vector() const
Definition: LocalTrajectoryParameters.h:120
Point3DBase< float, GlobalTag >
createTree.dd
string dd
Definition: createTree.py:154
TrajectoryStateOnSurface::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: TrajectoryStateOnSurface.h:73
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
DetId::Tracker
Definition: DetId.h:25
deltaR.h
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
sim
Definition: GeometryProducer.h:20
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlgebraicVector5
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Definition: AlgebraicROOTObjects.h:14
edm::RefToBaseVector< reco::Track >
TrackAssociatorByPositionImpl::SimHitTPPair
std::pair< TrackingParticleRef, TrackPSimHitRef > SimHitTPPair
Definition: TrackAssociatorByPositionImpl.h:33
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
TrackingParticle.h
CartesianTrajectoryError
Definition: CartesianTrajectoryError.h:15
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
GeomDet.h
edm::RefToBaseVector::size
size_type size() const
Definition: RefToBaseVector.h:160
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
BoundPlane
TrackAssociatorByPositionImpl::associateRecoToSim
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
Definition: TrackAssociatorByPositionImpl.cc:117
TrackPSimHitRef
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
Definition: PSimHitContainer.h:14
TrajectoryStateTransform.h
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
ztail.d
d
Definition: ztail.py:151
PSimHit
Definition: PSimHit.h:15
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
TrackAssociatorByPositionImpl::SimHitTPAssociationList
std::vector< SimHitTPPair > SimHitTPAssociationList
Definition: TrackAssociatorByPositionImpl.h:34