CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAssociatorByPosition.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  // TrackingParticle* simtrack = const_cast<TrackingParticle*>(&st);
15  //loop over PSimHits
16  const PSimHit * psimhit=0;
17  const BoundPlane * plane=0;
18  double dLim=thePositionMinimumDistance;
19 
20  // look for the further most hit beyond a certain limit
21  std::vector<PSimHit> pSimHit = st.trackPSimHit();
22  if (!theConsiderAllSimHits) pSimHit=st.trackPSimHit(DetId::Tracker);
23  std::vector<PSimHit> ::const_iterator start=pSimHit.begin();
24  std::vector<PSimHit> ::const_iterator end=pSimHit.end();
25  LogDebug("TrackAssociatorByPosition")<<pSimHit.size()<<" PSimHits.";
26 
27  unsigned int count=0;
28  for (std::vector<PSimHit> ::const_iterator psit=start;psit!=end;++psit){
29  //get the detid
30  DetId dd(psit->detUnitId());
31  LogDebug("TrackAssociatorByPosition")<<count++<<"] PSimHit on: "<<dd.rawId();
32  //get the surface from the global geometry
33  const GeomDet * gd=theGeometry->idToDet(dd);
34  if (!gd){edm::LogError("TrackAssociatorByPosition")<<"no geomdet for: "<<dd.rawId()<<". will skip.";
35  continue;}
36  double d=gd->surface().toGlobal(psit->localPosition()).mag();
37  if (d>dLim ){
38  dLim=d;
39  psimhit=&(*psit);
40  plane=&gd->surface();}
41  }
42 
43 
44  if (psimhit && plane){
45  //build a trajectorystate on this surface
47  GlobalPoint initialPoint=plane->toGlobal(psimhit->localPosition());
48  GlobalVector initialMomentum=plane->toGlobal(psimhit->momentumAtEntry());
49  int initialCharge = (psimhit->particleType()>0) ? -1:1;
50  CartesianTrajectoryError initialCartesianErrors(CLHEP::HepSymMatrix(6,0)); //no error at initial state
51  const GlobalTrajectoryParameters initialParameters(initialPoint,initialMomentum,initialCharge,thePropagator->magneticField());
52  return TrajectoryStateOnSurface(initialParameters,initialCartesianErrors,*plane,surfaceside);}
53  else{
54  // edm::LogError("TrackAssociatorByPosition")<<"no corresponding PSimHit for a tracking particle. will fail.";
55  return TrajectoryStateOnSurface();}
56 }
57 
59  static TrajectoryStateTransform transformer;
60  //may be you want to do more than that if track does not go to IP
61  return transformer. initialFreeState(track,thePropagator->magneticField());
62 }
63 
65  switch(theMethod){
66  case 0:
67  {
70  int ierr = ! m.Invert();
71  if (ierr!=0) edm::LogInfo("TrackAssociatorByPosition")<<"error inverting the error matrix:\n"<<m;
72  double est = ROOT::Math::Similarity(v,m);
73  return est;
74  break;
75  }
76  case 1:
77  {
78  return (tr.globalPosition() - sim.globalPosition()).mag();
79  break;
80  }
81  case 2:
82  {
83  return (deltaR<double>(tr.globalDirection().eta(),tr.globalDirection().phi(),
84  sim.globalDirection().eta(),sim.globalDirection().phi()));
85  break;
86  }
87  case 3:
88  {
89  return (deltaR<double>(tr.globalPosition().eta(),tr.globalPosition().phi(),
90  sim.globalPosition().eta(),sim.globalPosition().phi()));
91  break;
92  }
93  }
94  //should never be reached
95  edm::LogError("TrackAssociatorByPosition")<<"option: "<<theMethod<<" has not been recognized. association has no meaning.";
96  return -1;
97 }
98 
99 
102  const edm::Event * e,
103  const edm::EventSetup *setup ) const{
104  RecoToSimCollection outputCollection;
105  //for each reco track find a matching tracking particle
106  std::pair<unsigned int,unsigned int> minPair;
107  const double dQmin_default=1542543;
108  double dQmin=dQmin_default;
109  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
110  //initial state (initial OR inner OR outter)
111  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
112 
113  bool atLeastOne=false;
114  // for each tracking particle, find a state position and the plane to propagate the track to.
115  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi) {
116  //get a state in the muon system
117  TrajectoryStateOnSurface simReferenceState = getState(*(tPCH)[TPi]);
118  if (!simReferenceState.isValid()) continue;
119 
120  //propagate the TRACK to the surface
121  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
122  if (!trackReferenceState.isValid()) continue;
123 
124  //comparison
125  double dQ= quality(trackReferenceState,simReferenceState);
126  if (dQ < theQCut){
127  atLeastOne=true;
128  outputCollection.insert(tCH[Ti],
129  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,TPi),-dQ));//association map with quality, is order greater-first
130  edm::LogVerbatim("TrackAssociatorByPosition")<<"track number: "<<Ti
131  <<" associated with dQ: "<<dQ
132  <<" to TrackingParticle number: " <<TPi;}
133  if (dQ < dQmin){
134  dQmin=dQ;
135  minPair = std::make_pair(Ti,TPi);}
136  }//loop over tracking particles
137  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
138  outputCollection.insert(tCH[minPair.first],
139  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,minPair.second),-dQmin));}
140  }//loop over tracks
141  outputCollection.post_insert();
142  return outputCollection;
143 }
144 
145 
146 
149  const edm::Event * e,
150  const edm::EventSetup *setup ) const {
151  SimToRecoCollection outputCollection;
152  //for each tracking particle, find matching tracks.
153 
154  std::pair<unsigned int,unsigned int> minPair;
155  const double dQmin_default=1542543;
156  double dQmin=dQmin_default;
157  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi){
158  //get a state in the muon system
159  TrajectoryStateOnSurface simReferenceState= getState(*(tPCH)[TPi]);
160 
161  if (!simReferenceState.isValid()) continue;
162  bool atLeastOne=false;
163  // propagate every track from any state (initial, inner, outter) to the surface
164  // and make the position test
165  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
166  //initial state
167  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
168 
169  //propagation to surface
170  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
171  if (!trackReferenceState.isValid()) continue;
172 
173  //comparison
174  double dQ= quality(trackReferenceState, simReferenceState);
175  if (dQ < theQCut){
176  atLeastOne=true;
177  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,TPi),
178  std::make_pair(tCH[Ti],-dQ));//association map with quality, is order greater-first
179  edm::LogVerbatim("TrackAssociatorByPosition")<<"TrackingParticle number: "<<TPi
180  <<" associated with dQ: "<<dQ
181  <<" to track number: "<<Ti;}
182  if (dQ <dQmin){
183  dQmin=dQ;
184  minPair = std::make_pair(TPi,Ti);}
185  }//loop over tracks
186  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
187  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,minPair.first),
188  std::make_pair(tCH[minPair.second],-dQmin));}
189  }//loop over tracking particles
190 
191  outputCollection.post_insert();
192  return outputCollection;
193 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
const LocalTrajectoryParameters & localParameters() const
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
Definition: PSimHit.h:47
const std::vector< PSimHit > & trackPSimHit() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: sim.h:19
AlgebraicVector5 vector() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Local3DPoint localPosition() const
Definition: PSimHit.h:44
void post_insert()
post insert action
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
const AlgebraicSymMatrix55 & matrix() const
#define end
Definition: vmac.h:38
const LocalTrajectoryError & localError() const
size_type size() const
Definition: DetId.h:20
ROOT::Math::SVector< double, 5 > AlgebraicVector5
void insert(const key_type &k, const data_type &v)
insert an association
T eta() const
Definition: PV3DBase.h:70
int particleType() const
Definition: PSimHit.h:85
const Surface & surface() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:85
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
compare reco to sim the handle of reco::Track and TrackingParticle collections
FreeTrajectoryState getState(const reco::Track &) const
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
mathSSE::Vec4< T > v
GlobalVector globalDirection() const