CMS 3D CMS Logo

TrackGenAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
5 
6 #include "getChi2.h"
7 
8 using namespace edm;
9 using namespace reco;
10 using namespace std;
11 
13  const TrackBase::CovarianceMatrix& recoTrackCovMatrix,
14  const Basic3DVector<double>& momAtVtx,
15  const Basic3DVector<double>& vert,
16  int charge,
17  const reco::BeamSpot& bs) const{
18  return track_associator::getChi2(rParameters, recoTrackCovMatrix,momAtVtx, vert, charge, *theMF, bs);
19 }
20 
22  const edm::RefVector<GenParticleCollection>& tPCH) const {
23  reco::BeamSpot const& bs = *theBeamSpot;
24 
25  RecoToGenCollection outputCollection;
26 
27  //dereference the edm::Refs only once
28  std::vector<GenParticle const*> tPC;
29  tPC.reserve(tPCH.size());
30  for(auto const& ref: tPCH) {
31  tPC.push_back(&(*ref));
32  }
33 
34  int tindex=0;
35  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
36 
37  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
38  << "rec::Track #"<<tindex<<" with pt=" << (*rt)->pt() << "\n"
39  << "===========================================" << "\n";
40 
41  TrackBase::ParameterVector rParameters = (*rt)->parameters();
42 
43  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
44  if (onlyDiagonal){
45  for (unsigned int i=0;i<5;i++){
46  for (unsigned int j=0;j<5;j++){
47  if (i!=j) recoTrackCovMatrix(i,j)=0;
48  }
49  }
50  }
51 
52  recoTrackCovMatrix.Invert();
53 
54  int tpindex =0;
55  for (auto tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
56 
57  //skip tps with a very small pt
58  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
59  int charge = (*tp)->charge();
60  if (charge==0) continue;
61  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
62  Basic3DVector<double> vert=(Basic3DVector<double>) (*tp)->vertex();
63 
64  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
65 
66  if (chi2<chi2cut) {
67  //NOTE: tPC and tPCH use the same index for the same object
68  outputCollection.insert(tC[tindex],
69  std::make_pair(tPCH[tpindex],
70  -chi2));//-chi2 because the Association Map is ordered using std::greater
71  }
72  }
73  }
74  outputCollection.post_insert();
75  return outputCollection;
76 }
77 
78 
80  const edm::RefVector<GenParticleCollection>& tPCH) const {
81  reco::BeamSpot const& bs = *theBeamSpot;
82 
83  GenToRecoCollection outputCollection;
84 
85  int tpindex =0;
86  for (auto tp=tPCH.begin(); tp!=tPCH.end(); tp++, ++tpindex){
87 
88  //skip tps with a very small pt
89  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
90  int charge = (*tp)->charge();
91  if (charge==0) continue;
92 
93  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
94  << "TrackingParticle #"<<tpindex<<" with pt=" << sqrt((*tp)->momentum().perp2()) << "\n"
95  << "===========================================" << "\n";
96 
97  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
98  Basic3DVector<double> vert((*tp)->vertex().x(),(*tp)->vertex().y(),(*tp)->vertex().z());
99 
100  int tindex=0;
101  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
102 
103  TrackBase::ParameterVector rParameters = (*rt)->parameters();
104  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
105  if (onlyDiagonal) {
106  for (unsigned int i=0;i<5;i++){
107  for (unsigned int j=0;j<5;j++){
108  if (i!=j) recoTrackCovMatrix(i,j)=0;
109  }
110  }
111  }
112  recoTrackCovMatrix.Invert();
113 
114  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
115 
116  if (chi2<chi2cut) {
117  outputCollection.insert(*tp,
118  std::make_pair(tC[tindex],
119  -chi2));//-chi2 because the Association Map is ordered using std::greater
120  }
121  }
122  }
123  outputCollection.post_insert();
124  return outputCollection;
125 }
#define LogDebug(id)
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
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
const_iterator end() const
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:74
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:253
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:248
void post_insert()
post insert action
T sqrt(T t)
Definition: SSEVec.h:18
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
fixed size matrix
HLT enums.
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77