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, const edm::EventSetup *setup) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::RecoToSimCollectionSeed 
associateRecoToSim (edm::Handle< edm::View< TrajectorySeed > > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
 
virtual
reco::RecoToSimCollectionTCandidate 
associateRecoToSim (edm::Handle< TrackCandidateCollection > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
 
virtual reco::SimToRecoCollection associateSimToReco (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< TrackingParticleCollection > &tPCH, const edm::Event *event, const edm::EventSetup *setup) const
 compare reco to sim the handle of reco::Track and TrackingParticle collections More...
 
virtual
reco::SimToRecoCollectionSeed 
associateSimToReco (edm::Handle< edm::View< TrajectorySeed > > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
 
virtual
reco::SimToRecoCollectionTCandidate 
associateSimToReco (edm::Handle< TrackCandidateCollection > &, edm::Handle< TrackingParticleCollection > &, const edm::Event *event, const edm::EventSetup *setup) const
 
 TrackAssociatorBase ()
 Constructor. More...
 
virtual ~TrackAssociatorBase ()
 Destructor. More...
 

Private Member Functions

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

Private Attributes

edm::InputTag _simHitTpMapTag
 
edm::Handle
< SimHitTPAssociationProducer::SimHitTPAssociationList
simHitsTPAssoc
 
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 32 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 37 of file TrackAssociatorByPosition.h.

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

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

Destructor.

Definition at line 60 of file TrackAssociatorByPosition.h.

60  {
61  };

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 109 of file TrackAssociatorByPosition.cc.

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

112  {
113  RecoToSimCollection outputCollection;
114  //for each reco track find a matching tracking particle
115  std::pair<unsigned int,unsigned int> minPair;
116  const double dQmin_default=1542543;
117  double dQmin=dQmin_default;
118 
119  //warning: make sure the TP collection used in the map is the same used in the associator!
120  e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
121 
122  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
123  //initial state (initial OR inner OR outter)
124  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
125 
126  bool atLeastOne=false;
127  // for each tracking particle, find a state position and the plane to propagate the track to.
128  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi) {
129  //get a state in the muon system
130  TrajectoryStateOnSurface simReferenceState = getState((tPCH)[TPi]);
131  if (!simReferenceState.isValid()) continue;
132 
133  //propagate the TRACK to the surface
134  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
135  if (!trackReferenceState.isValid()) continue;
136 
137  //comparison
138  double dQ= quality(trackReferenceState,simReferenceState);
139  if (dQ < theQCut){
140  atLeastOne=true;
141  outputCollection.insert(tCH[Ti],
142  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,TPi),-dQ));//association map with quality, is order greater-first
143  edm::LogVerbatim("TrackAssociatorByPosition")<<"track number: "<<Ti
144  <<" associated with dQ: "<<dQ
145  <<" to TrackingParticle number: " <<TPi;}
146  if (dQ < dQmin){
147  dQmin=dQ;
148  minPair = std::make_pair(Ti,TPi);}
149  }//loop over tracking particles
150  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
151  outputCollection.insert(tCH[minPair.first],
152  std::make_pair(edm::Ref<TrackingParticleCollection>(tPCH,minPair.second),-dQmin));}
153  }//loop over tracks
154  outputCollection.post_insert();
155  return outputCollection;
156 }
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
const SurfaceType & surface() 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
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 160 of file TrackAssociatorByPosition.cc.

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

163  {
164  SimToRecoCollection outputCollection;
165  //for each tracking particle, find matching tracks.
166 
167  std::pair<unsigned int,unsigned int> minPair;
168  const double dQmin_default=1542543;
169  double dQmin=dQmin_default;
170 
171  //warning: make sure the TP collection used in the map is the same used in the associator!
172  e->getByLabel(_simHitTpMapTag,simHitsTPAssoc);
173 
174  for (unsigned int TPi=0;TPi!=tPCH.size();++TPi){
175  //get a state in the muon system
176  TrajectoryStateOnSurface simReferenceState= getState((tPCH)[TPi]);
177 
178  if (!simReferenceState.isValid()) continue;
179  bool atLeastOne=false;
180  // propagate every track from any state (initial, inner, outter) to the surface
181  // and make the position test
182  for (unsigned int Ti=0; Ti!=tCH.size();++Ti){
183  //initial state
184  FreeTrajectoryState iState = getState(*(tCH)[Ti]);
185 
186  //propagation to surface
187  TrajectoryStateOnSurface trackReferenceState = thePropagator->propagate(iState,simReferenceState.surface());
188  if (!trackReferenceState.isValid()) continue;
189 
190  //comparison
191  double dQ= quality(trackReferenceState, simReferenceState);
192  if (dQ < theQCut){
193  atLeastOne=true;
194  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,TPi),
195  std::make_pair(tCH[Ti],-dQ));//association map with quality, is order greater-first
196  edm::LogVerbatim("TrackAssociatorByPosition")<<"TrackingParticle number: "<<TPi
197  <<" associated with dQ: "<<dQ
198  <<" to track number: "<<Ti;}
199  if (dQ <dQmin){
200  dQmin=dQ;
201  minPair = std::make_pair(TPi,Ti);}
202  }//loop over tracks
203  if (theMinIfNoMatch && !atLeastOne && dQmin!=dQmin_default){
204  outputCollection.insert(edm::Ref<TrackingParticleCollection>(tPCH,minPair.first),
205  std::make_pair(tCH[minPair.second],-dQmin));}
206  }//loop over tracking particles
207 
208  outputCollection.post_insert();
209  return outputCollection;
210 }
double quality(const TrajectoryStateOnSurface &, const TrajectoryStateOnSurface &) const
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
const SurfaceType & surface() 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
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 68 of file TrackAssociatorByPosition.cc.

References trajectoryStateTransform::initialFreeState().

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

Definition at line 13 of file TrackAssociatorByPosition.cc.

References SurfaceSideDefinition::atCenterOfSurface, prof2calltree::count, createTree::dd, end, LogDebug, mag(), SimHitTPAssociationProducer::simHitTPAssociationListGreater(), dqm_diff::start, GeomDet::surface(), Surface::toGlobal(), and DetId::Tracker.

13  {
14 
15  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(st,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
16  // sorting only the cluster is needed
17  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
19 
20  // TrackingParticle* simtrack = const_cast<TrackingParticle*>(&st);
21  //loop over PSimHits
22  const PSimHit * psimhit=0;
23  const BoundPlane * plane=0;
24  double dLim=thePositionMinimumDistance;
25 
26  // look for the further most hit beyond a certain limit
27  auto start=range.first;
28  auto end=range.second;
29  LogDebug("TrackAssociatorByPosition")<<range.second-range.first<<" PSimHits.";
30 
31  unsigned int count=0;
32  for (auto ip=start;ip!=end;++ip){
33 
34  TrackPSimHitRef psit = ip->second;
35 
36  //get the detid
37  DetId dd(psit->detUnitId());
38 
39  if (!theConsiderAllSimHits && dd.det()!=DetId::Tracker) continue;
40 
41  LogDebug("TrackAssociatorByPosition")<<count++<<"] PSimHit on: "<<dd.rawId();
42  //get the surface from the global geometry
43  const GeomDet * gd=theGeometry->idToDet(dd);
44  if (!gd){edm::LogError("TrackAssociatorByPosition")<<"no geomdet for: "<<dd.rawId()<<". will skip.";
45  continue;}
46  double d=gd->surface().toGlobal(psit->localPosition()).mag();
47  if (d>dLim ){
48  dLim=d;
49  psimhit=&(*psit);
50  plane=&gd->surface();}
51  }
52 
53 
54  if (psimhit && plane){
55  //build a trajectorystate on this surface
57  GlobalPoint initialPoint=plane->toGlobal(psimhit->localPosition());
58  GlobalVector initialMomentum=plane->toGlobal(psimhit->momentumAtEntry());
59  int initialCharge = (psimhit->particleType()>0) ? -1:1;
60  CartesianTrajectoryError initialCartesianErrors; //no error at initial state
61  const GlobalTrajectoryParameters initialParameters(initialPoint,initialMomentum,initialCharge,thePropagator->magneticField());
62  return TrajectoryStateOnSurface(initialParameters,initialCartesianErrors,*plane,surfaceside);}
63  else{
64  // edm::LogError("TrackAssociatorByPosition")<<"no corresponding PSimHit for a tracking particle. will fail.";
65  return TrajectoryStateOnSurface();}
66 }
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
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
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
double TrackAssociatorByPosition::quality ( const TrajectoryStateOnSurface tr,
const TrajectoryStateOnSurface sim 
) const

Definition at line 73 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(), findQualityFiles::v, and LocalTrajectoryParameters::vector().

73  {
74  switch(theMethod){
75  case 0:
76  {
79  int ierr = ! m.Invert();
80  if (ierr!=0) edm::LogInfo("TrackAssociatorByPosition")<<"error inverting the error matrix:\n"<<m;
81  double est = ROOT::Math::Similarity(v,m);
82  return est;
83  break;
84  }
85  case 1:
86  {
87  return (tr.globalPosition() - sim.globalPosition()).mag();
88  break;
89  }
90  case 2:
91  {
92  return (deltaR<double>(tr.globalDirection().eta(),tr.globalDirection().phi(),
93  sim.globalDirection().eta(),sim.globalDirection().phi()));
94  break;
95  }
96  case 3:
97  {
98  return (deltaR<double>(tr.globalPosition().eta(),tr.globalPosition().phi(),
99  sim.globalPosition().eta(),sim.globalPosition().phi()));
100  break;
101  }
102  }
103  //should never be reached
104  edm::LogError("TrackAssociatorByPosition")<<"option: "<<theMethod<<" has not been recognized. association has no meaning.";
105  return -1;
106 }
const LocalTrajectoryParameters & localParameters() const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
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:76
GlobalVector globalDirection() const

Member Data Documentation

edm::InputTag TrackAssociatorByPosition::_simHitTpMapTag
private

Definition at line 92 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> TrackAssociatorByPosition::simHitsTPAssoc
mutableprivate

Definition at line 91 of file TrackAssociatorByPosition.h.

bool TrackAssociatorByPosition::theConsiderAllSimHits
private

Definition at line 87 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

const TrackingGeometry* TrackAssociatorByPosition::theGeometry
private

Definition at line 80 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

unsigned int TrackAssociatorByPosition::theMethod
private

Definition at line 82 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

bool TrackAssociatorByPosition::theMinIfNoMatch
private

Definition at line 85 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::thePositionMinimumDistance
private

Definition at line 86 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

const Propagator* TrackAssociatorByPosition::thePropagator
private

Definition at line 81 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::theQCut
private

Definition at line 84 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().

double TrackAssociatorByPosition::theQminCut
private

Definition at line 83 of file TrackAssociatorByPosition.h.

Referenced by TrackAssociatorByPosition().