CMS 3D CMS Logo

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

#include <TrackGenAssociatorByChi2.h>

Inheritance diagram for TrackGenAssociatorByChi2:
TrackGenAssociatorBase

Public Types

typedef std::map< double,
SimTrack
Chi2SimMap
 
typedef std::pair< reco::Track,
Chi2SimMap
RecoToSimPair
 
typedef std::vector
< RecoToSimPair
RecoToSimPairAssociation
 

Public Member Functions

reco::GenToRecoCollection associateGenToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 Association Sim To Reco with Collections (Gen Particle version) More...
 
virtual reco::GenToRecoCollection associateGenToReco (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< reco::GenParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
reco::RecoToGenCollection associateRecoToGen (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 Association Sim To Reco with Collections (Gen Particle version) More...
 
virtual reco::RecoToGenCollection associateRecoToGen (edm::Handle< edm::View< reco::Track > > &tCH, edm::Handle< reco::GenParticleCollection > &tPCH, const edm::Event *event=0, const edm::EventSetup *setup=0) const
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
 TrackGenAssociatorByChi2 (const edm::ESHandle< MagneticField > mF, const edm::ParameterSet &conf)
 Constructor with PSet. More...
 
 TrackGenAssociatorByChi2 (const edm::ESHandle< MagneticField > mF, double chi2Cut, bool onlyDiag, const edm::InputTag &beamspotSrc)
 Constructor with magnetic field, double, bool and InputTag. More...
 
- Public Member Functions inherited from TrackGenAssociatorBase
 TrackGenAssociatorBase ()
 Constructor. More...
 
virtual ~TrackGenAssociatorBase ()
 

Private Member Functions

double associateRecoToSim (reco::TrackCollection::const_iterator, TrackingParticleCollection::const_iterator, const reco::BeamSpot &) const
 compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2 More...
 
double getChi2 (const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const reco::BeamSpot &) const
 basic method where chi2 is computed More...
 

Private Attributes

edm::InputTag bsSrc
 
double chi2cut
 
bool onlyDiagonal
 
edm::ESHandle< MagneticFieldtheMF
 

Detailed Description

Class that performs the association of reco::Tracks and TrackingParticles evaluating the chi2 of reco tracks parameters and sim tracks parameters. The cut can be tuned from the config file: see data/TrackGenAssociatorByChi2.cfi. Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater: the track with the lowest association chi2 will be the first in the output map.It is possible to use only diagonal terms (associator by pulls) seeting onlyDiagonal = true in the PSet

Author
cerati, magni

Definition at line 43 of file TrackGenAssociatorByChi2.h.

Member Typedef Documentation

Definition at line 46 of file TrackGenAssociatorByChi2.h.

Definition at line 47 of file TrackGenAssociatorByChi2.h.

Definition at line 48 of file TrackGenAssociatorByChi2.h.

Constructor & Destructor Documentation

TrackGenAssociatorByChi2::TrackGenAssociatorByChi2 ( const edm::ESHandle< MagneticField mF,
const edm::ParameterSet conf 
)
inline

Constructor with PSet.

Definition at line 51 of file TrackGenAssociatorByChi2.h.

References onlyDiagonal, and theMF.

51  :
52  chi2cut(conf.getParameter<double>("chi2cut")),
53  onlyDiagonal(conf.getParameter<bool>("onlyDiagonal")),
54  bsSrc(conf.getParameter<edm::InputTag>("beamSpot")) {
55  theMF=mF;
56  if (onlyDiagonal)
57  edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms = 0 ---- " << "\n";
58  else
59  edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms != 0 ---- " << "\n";
60  }
T getParameter(std::string const &) const
edm::ESHandle< MagneticField > theMF
TrackGenAssociatorByChi2::TrackGenAssociatorByChi2 ( const edm::ESHandle< MagneticField mF,
double  chi2Cut,
bool  onlyDiag,
const edm::InputTag beamspotSrc 
)
inline

Constructor with magnetic field, double, bool and InputTag.

Definition at line 63 of file TrackGenAssociatorByChi2.h.

References bsSrc, chi2cut, onlyDiagonal, and theMF.

63  {
64  chi2cut=chi2Cut;
65  onlyDiagonal=onlyDiag;
66  theMF=mF;
67  bsSrc = beamspotSrc;
68  }
edm::ESHandle< MagneticField > theMF

Member Function Documentation

GenToRecoCollection TrackGenAssociatorByChi2::associateGenToReco ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< reco::GenParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
virtual

Association Sim To Reco with Collections (Gen Particle version)

Implements TrackGenAssociatorBase.

Definition at line 83 of file TrackGenAssociatorByChi2.cc.

References edm::RefToBaseVector< T >::begin(), RecoTauCleanerPlugins::charge, edm::RefToBaseVector< T >::end(), edm::Event::getByLabel(), track_associator::getChi2(), i, edm::AssociationMap< Tag >::insert(), j, LogDebug, edm::AssociationMap< Tag >::post_insert(), edm::RefVector< C, T, F >::size(), and mathSSE::sqrt().

Referenced by associateGenToReco().

86  {
87 
88  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
89  e->getByLabel(bsSrc,recoBeamSpotHandle);
90  reco::BeamSpot bs = *recoBeamSpotHandle;
91 
92  GenToRecoCollection outputCollection;
93 
94  //dereference the edm::Refs only once
95  std::vector<GenParticle const*> tPC;
96  tPC.reserve(tPCH.size());
97  for(auto const& ref: tPCH) {
98  tPC.push_back(&(*ref));
99  }
100 
101  int tpindex =0;
102  for (auto tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
103 
104  //skip tps with a very small pt
105  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
106  int charge = (*tp)->charge();
107  if (charge==0) continue;
108 
109  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
110  << "TrackingParticle #"<<tpindex<<" with pt=" << sqrt((*tp)->momentum().perp2()) << "\n"
111  << "===========================================" << "\n";
112 
113  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
114  Basic3DVector<double> vert((*tp)->vertex().x(),(*tp)->vertex().y(),(*tp)->vertex().z());
115 
116  int tindex=0;
117  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
118 
119  TrackBase::ParameterVector rParameters = (*rt)->parameters();
120  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
121  if (onlyDiagonal) {
122  for (unsigned int i=0;i<5;i++){
123  for (unsigned int j=0;j<5;j++){
124  if (i!=j) recoTrackCovMatrix(i,j)=0;
125  }
126  }
127  }
128  recoTrackCovMatrix.Invert();
129 
130  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
131 
132  if (chi2<chi2cut) {
133  //NOTE: tPCH and tPC have the same index for the same object
134  outputCollection.insert(tPCH[tpindex],
135  std::make_pair(tC[tindex],
136  -chi2));//-chi2 because the Association Map is ordered using std::greater
137  }
138  }
139  }
140  outputCollection.post_insert();
141  return outputCollection;
142 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
const_iterator end() const
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:74
void post_insert()
post insert action
T sqrt(T t)
Definition: SSEVec.h:48
int j
Definition: DBlmapReader.cc:9
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
double getChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const reco::BeamSpot &) const
basic method where chi2 is computed
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
virtual reco::GenToRecoCollection TrackGenAssociatorByChi2::associateGenToReco ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< reco::GenParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
inlinevirtual

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

Implements TrackGenAssociatorBase.

Definition at line 98 of file TrackGenAssociatorByChi2.h.

References associateGenToReco(), event(), edm::HandleBase::id(), j, edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), and HcalObjRepresent::setup().

101  {
103  for (unsigned int j=0; j<tCH->size();j++)
104  tc.push_back(edm::RefToBase<reco::Track>(tCH,j));
105 
107  for (unsigned int j=0; j<tPCH->size();j++)
109 
110  return associateGenToReco(tc,tpc,event,setup);
111  }
reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Sim To Reco with Collections (Gen Particle version)
ProductID id() const
Definition: HandleBase.cc:15
int j
Definition: DBlmapReader.cc:9
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
RecoToGenCollection TrackGenAssociatorByChi2::associateRecoToGen ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< reco::GenParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
virtual

Association Sim To Reco with Collections (Gen Particle version)

Implements TrackGenAssociatorBase.

Definition at line 21 of file TrackGenAssociatorByChi2.cc.

References edm::RefToBaseVector< T >::begin(), RecoTauCleanerPlugins::charge, edm::RefToBaseVector< T >::end(), edm::Event::getByLabel(), track_associator::getChi2(), i, edm::AssociationMap< Tag >::insert(), j, LogDebug, edm::AssociationMap< Tag >::post_insert(), and edm::RefVector< C, T, F >::size().

Referenced by associateRecoToGen().

24  {
25  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
26  e->getByLabel(bsSrc,recoBeamSpotHandle);
27  reco::BeamSpot bs = *recoBeamSpotHandle;
28 
29  RecoToGenCollection outputCollection;
30 
31  //dereference the edm::Ref's only once
32  std::vector<const GenParticle*> tPC;
33  tPC.reserve(tPCH.size());
34  for(auto const& ref: tPCH) {
35  tPC.push_back(&(*ref));
36  }
37 
38  int tindex=0;
39  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
40 
41  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
42  << "rec::Track #"<<tindex<<" with pt=" << (*rt)->pt() << "\n"
43  << "===========================================" << "\n";
44 
45  TrackBase::ParameterVector rParameters = (*rt)->parameters();
46 
47  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
48  if (onlyDiagonal){
49  for (unsigned int i=0;i<5;i++){
50  for (unsigned int j=0;j<5;j++){
51  if (i!=j) recoTrackCovMatrix(i,j)=0;
52  }
53  }
54  }
55 
56  recoTrackCovMatrix.Invert();
57 
58  int tpindex =0;
59  for (auto tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
60 
61  //skip tps with a very small pt
62  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
63  int charge = (*tp)->charge();
64  if (charge==0) continue;
65  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
66  Basic3DVector<double> vert=(Basic3DVector<double>) (*tp)->vertex();
67 
68  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
69 
70  if (chi2<chi2cut) {
71  //NOTE: tPCH and tPC have the same index for the same object
72  outputCollection.insert(tC[tindex],
73  std::make_pair(tPCH[tpindex],
74  -chi2));//-chi2 because the Association Map is ordered using std::greater
75  }
76  }
77  }
78  outputCollection.post_insert();
79  return outputCollection;
80 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
const_iterator end() const
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:74
void post_insert()
post insert action
int j
Definition: DBlmapReader.cc:9
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
double getChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const reco::BeamSpot &) const
basic method where chi2 is computed
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77
virtual reco::RecoToGenCollection TrackGenAssociatorByChi2::associateRecoToGen ( edm::Handle< edm::View< reco::Track > > &  tCH,
edm::Handle< reco::GenParticleCollection > &  tPCH,
const edm::Event event = 0,
const edm::EventSetup setup = 0 
) const
inlinevirtual

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

Implements TrackGenAssociatorBase.

Definition at line 82 of file TrackGenAssociatorByChi2.h.

References associateRecoToGen(), event(), edm::HandleBase::id(), j, edm::RefToBaseVector< T >::push_back(), edm::RefVector< C, T, F >::push_back(), and HcalObjRepresent::setup().

85  {
87  for (unsigned int j=0; j<tCH->size();j++)
88  tc.push_back(edm::RefToBase<reco::Track>(tCH,j));
89 
91  for (unsigned int j=0; j<tPCH->size();j++)
93 
94  return associateRecoToGen(tc,tpc,event,setup);
95  }
ProductID id() const
Definition: HandleBase.cc:15
int j
Definition: DBlmapReader.cc:9
reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &, const edm::Event *event=0, const edm::EventSetup *setup=0) const
Association Sim To Reco with Collections (Gen Particle version)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
double TrackGenAssociatorByChi2::associateRecoToSim ( reco::TrackCollection::const_iterator  ,
TrackingParticleCollection::const_iterator  ,
const reco::BeamSpot  
) const
private

compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2

double TrackGenAssociatorByChi2::getChi2 ( const reco::TrackBase::ParameterVector rParameters,
const reco::TrackBase::CovarianceMatrix recoTrackCovMatrix,
const Basic3DVector< double > &  momAtVtx,
const Basic3DVector< double > &  vert,
int  charge,
const reco::BeamSpot bs 
) const
private

basic method where chi2 is computed

Definition at line 12 of file TrackGenAssociatorByChi2.cc.

References track_associator::getChi2().

17  {
18  return track_associator::getChi2(rParameters, recoTrackCovMatrix,momAtVtx, vert, charge, *theMF, bs);
19 }
double getChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const MagneticField &magfield, const reco::BeamSpot &bs)
basic method where chi2 is computed
Definition: getChi2.cc:7
edm::ESHandle< MagneticField > theMF

Member Data Documentation

edm::InputTag TrackGenAssociatorByChi2::bsSrc
private

Definition at line 133 of file TrackGenAssociatorByChi2.h.

Referenced by TrackGenAssociatorByChi2().

double TrackGenAssociatorByChi2::chi2cut
private

Definition at line 131 of file TrackGenAssociatorByChi2.h.

Referenced by TrackGenAssociatorByChi2().

bool TrackGenAssociatorByChi2::onlyDiagonal
private

Definition at line 132 of file TrackGenAssociatorByChi2.h.

Referenced by TrackGenAssociatorByChi2().

edm::ESHandle<MagneticField> TrackGenAssociatorByChi2::theMF
private

Definition at line 130 of file TrackGenAssociatorByChi2.h.

Referenced by TrackGenAssociatorByChi2().