CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TrackAssociatorByPosition Class Reference

#include <TrackAssociatorByPosition.h>

Inheritance diagram for TrackAssociatorByPosition:
TrackAssociatorBase

Public Member Functions

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 More...
 
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 More...
 
double quality (const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
 
 TrackAssociatorByPosition (const edm::ParameterSet &iConfig, const TrackingGeometry *geo, const Propagator *prop)
 Constructor with propagator and PSet. More...
 
 ~TrackAssociatorByPosition ()
 Destructor. More...
 
- Public Member Functions inherited from TrackAssociatorBase
virtual reco::RecoToSimCollection associateRecoToSim (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::RecoToSimCollectionSeed 
associateRecoToSim (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 
virtual
reco::RecoToSimCollectionTCandidate 
associateRecoToSim (const edm::Handle< TrackCandidateCollection > &, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 
virtual reco::SimToRecoCollection associateSimToReco (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::SimToRecoCollectionSeed 
associateSimToReco (const edm::Handle< edm::View< TrajectorySeed > > &, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 
virtual
reco::SimToRecoCollectionTCandidate 
associateSimToReco (const edm::Handle< TrackCandidateCollection > &, const edm::Handle< TrackingParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 
 TrackAssociatorBase ()
 Constructor. More...
 
virtual ~TrackAssociatorBase ()
 Destructor. More...
 

Private Member Functions

FreeTrajectoryState getState (const reco::Track &) const
 
TrajectoryStateOnSurface getState (const TrackingParticle &) const
 

Private Attributes

bool theConsiderAllSimHits
 
const TrackingGeometrytheGeometry
 
unsigned int theMethod
 
bool theMinIfNoMatch
 
double thePositionMinimumDistance
 
const PropagatorthePropagator
 
double theQCut
 
double theQminCut
 

Detailed Description

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

Date:
2010/10/12 12:10:00
Revision:
1.11
Author
vlimant

Definition at line 30 of file TrackAssociatorByPosition.h.

Constructor & Destructor Documentation

TrackAssociatorByPosition::TrackAssociatorByPosition ( const edm::ParameterSet iConfig,
const TrackingGeometry geo,
const Propagator prop 
)
inline

Constructor with propagator and PSet.

Definition at line 35 of file TrackAssociatorByPosition.h.

References edm::ParameterSet::getParameter(), theConsiderAllSimHits, theGeometry, theMethod, theMinIfNoMatch, thePositionMinimumDistance, thePropagator, theQCut, and theQminCut.

37  {
38  theGeometry = geo;
39  thePropagator = prop;
40  theMinIfNoMatch = iConfig.getParameter<bool>("MinIfNoMatch");
41  theQminCut = iConfig.getParameter<double>("QminCut");
42  theQCut = iConfig.getParameter<double>("QCut");
43  thePositionMinimumDistance = iConfig.getParameter<double>("positionMinimumDistance");
44  std::string meth= iConfig.getParameter<std::string>("method");
45  if (meth=="chi2"){ theMethod =0; }
46  else if (meth=="dist"){theMethod =1;}
47  else if (meth=="momdr"){theMethod = 2;}
48  else if (meth=="posdr"){theMethod = 3;}
49  else{
50  edm::LogError("TrackAssociatorByPosition")<<meth<<" mothed not recognized. Use dr or chi2."; }
51 
52  theConsiderAllSimHits = iConfig.getParameter<bool>("ConsiderAllSimHits");
53  };
T getParameter(std::string const &) const
const TrackingGeometry * theGeometry
TrackAssociatorByPosition::~TrackAssociatorByPosition ( )
inline

Destructor.

Definition at line 57 of file TrackAssociatorByPosition.h.

57  {
58  };

Member Function Documentation

RecoToSimCollection TrackAssociatorByPosition::associateRecoToSim ( const edm::RefToBaseVector< reco::Track > &  tCH,
const edm::RefVector< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
virtual

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

Implements TrackAssociatorBase.

Definition at line 99 of file TrackAssociatorByPosition.cc.

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

102  {
103  RecoToSimCollection outputCollection;
104  //for each reco track find a matching tracking particle
105  std::pair<unsigned int,unsigned int> minPair;
106  const double dQmin_default=1542543;
107  double dQmin=dQmin_default;
108  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
109  //initial state (initial OR inner OR outter)
110  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
111 
112  bool atLeastOne=false;
113  // for each tracking particle, find a state position and the plane to propagate the track to.
114  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi) {
115  //get a state in the muon system
116  TrajectoryStateOnSurface simReferenceState = getState(*(tPCH)[TPi]);
117  if (!simReferenceState.isValid()) continue;
118 
119  //propagate the TRACK to the surface
120  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
121  if (!trackReferenceState.isValid()) continue;
122 
123  //comparison
124  double dQ= quality(trackReferenceState,simReferenceState);
125  if (dQ < theQCut){
126  atLeastOne=true;
127  outputCollection.insert(tCH[Ti],
128  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,TPi),-dQ));//association map with quality, is order greater-first
129  edm::LogVerbatim("TrackAssociatorByPosition")<<"track number: "<<Ti
130  <<" associated with dQ: "<<dQ
131  <<" to TrackingParticle number: " <<TPi;}
132  if (dQ < dQmin){
133  dQmin=dQ;
134  minPair = std::make_pair(Ti,TPi);}
135  }//loop over tracking particles
136  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
137  outputCollection.insert(tCH[minPair.first],
138  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,minPair.second),-dQmin));}
139  }//loop over tracks
140  outputCollection.post_insert();
141  return outputCollection;
142 }
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
void post_insert()
post insert action
size_type size() const
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
void insert(const key_type &k, const data_type &v)
insert an association
const Surface & surface() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
FreeTrajectoryState getState(const reco::Track &) const
SimToRecoCollection TrackAssociatorByPosition::associateSimToReco ( const edm::RefToBaseVector< reco::Track > &  tCH,
const edm::RefVector< TrackingParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
virtual

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

Implements TrackAssociatorBase.

Definition at line 146 of file TrackAssociatorByPosition.cc.

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

149  {
150  SimToRecoCollection outputCollection;
151  //for each tracking particle, find matching tracks.
152 
153  std::pair<unsigned int,unsigned int> minPair;
154  const double dQmin_default=1542543;
155  double dQmin=dQmin_default;
156  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi){
157  //get a state in the muon system
158  TrajectoryStateOnSurface simReferenceState= getState(*(tPCH)[TPi]);
159 
160  if (!simReferenceState.isValid()) continue;
161  bool atLeastOne=false;
162  // propagate every track from any state (initial, inner, outter) to the surface
163  // and make the position test
164  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
165  //initial state
166  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
167 
168  //propagation to surface
169  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
170  if (!trackReferenceState.isValid()) continue;
171 
172  //comparison
173  double dQ= quality(trackReferenceState, simReferenceState);
174  if (dQ < theQCut){
175  atLeastOne=true;
176  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,TPi),
177  std::make_pair(tCH[Ti],-dQ));//association map with quality, is order greater-first
178  edm::LogVerbatim("TrackAssociatorByPosition")<<"TrackingParticle number: "<<TPi
179  <<" associated with dQ: "<<dQ
180  <<" to track number: "<<Ti;}
181  if (dQ <dQmin){
182  dQmin=dQ;
183  minPair = std::make_pair(TPi,Ti);}
184  }//loop over tracks
185  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
186  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,minPair.first),
187  std::make_pair(tCH[minPair.second],-dQmin));}
188  }//loop over tracking particles
189 
190  outputCollection.post_insert();
191  return outputCollection;
192 }
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
void post_insert()
post insert action
size_type size() const
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
void insert(const key_type &k, const data_type &v)
insert an association
const Surface & surface() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
FreeTrajectoryState getState(const reco::Track &) const
FreeTrajectoryState TrackAssociatorByPosition::getState ( const reco::Track track) const
private

Definition at line 58 of file TrackAssociatorByPosition.cc.

References trajectoryStateTransform::initialFreeState().

58  {
59  //may be you want to do more than that if track does not go to IP
61 }
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field)
virtual const MagneticField * magneticField() const =0
TrajectoryStateOnSurface TrackAssociatorByPosition::getState ( const TrackingParticle st) const
private

Definition at line 13 of file TrackAssociatorByPosition.cc.

References SurfaceSideDefinition::atCenterOfSurface, prof2calltree::count, createTree::dd, end, PSimHit::localPosition(), LogDebug, mag(), PSimHit::momentumAtEntry(), PSimHit::particleType(), errorMatrix2Lands_multiChannel::start, GeomDet::surface(), Surface::toGlobal(), DetId::Tracker, and TrackingParticle::trackPSimHit().

13  {
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();
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; //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 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
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
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Local3DPoint localPosition() const
Definition: PSimHit.h:44
const TrackingGeometry * theGeometry
#define end
Definition: vmac.h:38
Definition: DetId.h:20
virtual const GeomDet * idToDet(DetId) const =0
virtual const MagneticField * magneticField() const =0
int particleType() const
Definition: PSimHit.h:85
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double TrackAssociatorByPosition::quality ( const TrajectoryStateOnSurface tr,
const TrajectoryStateOnSurface sim 
) const

Definition at line 63 of file TrackAssociatorByPosition.cc.

References PV3DBase< T, PVType, FrameType >::eta(), TrajectoryStateOnSurface::globalDirection(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localParameters(), m, mag(), LocalTrajectoryError::matrix(), PV3DBase< T, PVType, FrameType >::phi(), v, and LocalTrajectoryParameters::vector().

63  {
64  switch(theMethod){
65  case 0:
66  {
69  int ierr = ! m.Invert();
70  if (ierr!=0) edm::LogInfo("TrackAssociatorByPosition")<<"error inverting the error matrix:\n"<<m;
71  double est = ROOT::Math::Similarity(v,m);
72  return est;
73  break;
74  }
75  case 1:
76  {
77  return (tr.globalPosition() - sim.globalPosition()).mag();
78  break;
79  }
80  case 2:
81  {
82  return (deltaR<double>(tr.globalDirection().eta(),tr.globalDirection().phi(),
83  sim.globalDirection().eta(),sim.globalDirection().phi()));
84  break;
85  }
86  case 3:
87  {
88  return (deltaR<double>(tr.globalPosition().eta(),tr.globalPosition().phi(),
89  sim.globalPosition().eta(),sim.globalPosition().phi()));
90  break;
91  }
92  }
93  //should never be reached
94  edm::LogError("TrackAssociatorByPosition")<<"option: "<<theMethod<<" has not been recognized. association has no meaning.";
95  return -1;
96 }
const LocalTrajectoryParameters & localParameters() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
GlobalPoint globalPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
AlgebraicVector5 vector() const
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
ROOT::Math::SVector< double, 5 > AlgebraicVector5
T eta() const
Definition: PV3DBase.h:75
mathSSE::Vec4< T > v
GlobalVector globalDirection() const

Member Data Documentation

bool TrackAssociatorByPosition::theConsiderAllSimHits
private

Definition at line 84 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

const TrackingGeometry* TrackAssociatorByPosition::theGeometry
private

Definition at line 77 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

unsigned int TrackAssociatorByPosition::theMethod
private

Definition at line 79 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

bool TrackAssociatorByPosition::theMinIfNoMatch
private

Definition at line 82 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::thePositionMinimumDistance
private

Definition at line 83 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

const Propagator* TrackAssociatorByPosition::thePropagator
private

Definition at line 78 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::theQCut
private

Definition at line 81 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::theQminCut
private

Definition at line 80 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().