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/05/18 15:40:39
Revision:
1.10
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 100 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().

103  {
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 }
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:9
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:84
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 147 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().

150  {
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 }
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:9
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:84
FreeTrajectoryState getState(const reco::Track &) const
FreeTrajectoryState TrackAssociatorByPosition::getState ( const reco::Track track) const
private

Definition at line 58 of file TrackAssociatorByPosition.cc.

58  {
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 }
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(), 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(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 }
#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
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
double TrackAssociatorByPosition::quality ( const TrajectoryStateOnSurface tr,
const TrajectoryStateOnSurface sim 
) const

Definition at line 64 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().

64  {
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 }
const LocalTrajectoryParameters & localParameters() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
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:70
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().