CMS 3D CMS Logo

TrackAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
7 
8 
9 using namespace edm;
10 using namespace reco;
11 using namespace std;
12 
14  const TrackBase::CovarianceMatrix& recoTrackCovMatrix,
15  const Basic3DVector<double>& momAtVtx,
16  const Basic3DVector<double>& vert,
17  int charge,
18  const reco::BeamSpot& bs) const{
19  return track_associator::trackAssociationChi2(rParameters, recoTrackCovMatrix,momAtVtx, vert, charge, *theMF, bs);
20 }
21 
22 
25 
26  const reco::BeamSpot& bs = *theBeamSpot;
27 
28  RecoToSimCollection outputCollection;
29 
30  //dereference the edm::Refs only once
31  std::vector<TrackingParticle const*> tPC;
32  tPC.reserve(tPCH.size());
33  for(auto const& ref: tPCH) {
34  tPC.push_back(&(*ref));
35  }
36 
37  int tindex=0;
38  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
39 
40  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
41  << "rec::Track #"<<tindex<<" with pt=" << (*rt)->pt() << "\n"
42  << "===========================================" << "\n";
43 
44  TrackBase::ParameterVector rParameters = (*rt)->parameters();
45 
46  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
47  if (onlyDiagonal){
48  for (unsigned int i=0;i<5;i++){
49  for (unsigned int j=0;j<5;j++){
50  if (i!=j) recoTrackCovMatrix(i,j)=0;
51  }
52  }
53  }
54 
55  recoTrackCovMatrix.Invert();
56 
57  int tpindex =0;
58  for (auto tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
59 
60  //skip tps with a very small pt
61  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
62  int charge = (*tp)->charge();
63  if (charge==0) continue;
64  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
65  Basic3DVector<double> vert=(Basic3DVector<double>) (*tp)->vertex();
66 
67  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
68 
69  if (chi2<chi2cut) {
70  outputCollection.insert(tC[tindex],
71  std::make_pair(tPCH[tpindex],
72  -chi2));//-chi2 because the Association Map is ordered using std::greater
73  }
74  }
75  }
76  outputCollection.post_insert();
77  return outputCollection;
78 }
79 
80 
83  const reco::BeamSpot& bs = *theBeamSpot;
84 
85  SimToRecoCollection outputCollection;
86 
87  int tpindex =0;
88  for (auto tp=tPCH.begin(); tp!=tPCH.end(); tp++, ++tpindex){
89 
90  //skip tps with a very small pt
91  //if (sqrt(tp->momentum().perp2())<0.5) continue;
92  int charge = (*tp)->charge();
93  if (charge==0) continue;
94 
95  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
96  << "TrackingParticle #"<<tpindex<<" with pt=" << sqrt((*tp)->momentum().perp2()) << "\n"
97  << "===========================================" << "\n";
98 
99  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
100  Basic3DVector<double> vert((*tp)->vertex().x(),(*tp)->vertex().y(),(*tp)->vertex().z());
101 
102  int tindex=0;
103  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
104 
105  TrackBase::ParameterVector rParameters = (*rt)->parameters();
106  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
107  if (onlyDiagonal) {
108  for (unsigned int i=0;i<5;i++){
109  for (unsigned int j=0;j<5;j++){
110  if (i!=j) recoTrackCovMatrix(i,j)=0;
111  }
112  }
113  }
114  recoTrackCovMatrix.Invert();
115 
116  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
117 
118  if (chi2<chi2cut) {
119  outputCollection.insert(*tp,
120  std::make_pair(tC[tindex],
121  -chi2));//-chi2 because the Association Map is ordered using std::greater
122  }
123  }
124  }
125  outputCollection.post_insert();
126  return outputCollection;
127 }
128 
#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 reco::BeamSpot &) const
basic method where chi2 is computed
const_iterator end() const
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
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
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
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
double trackAssociationChi2(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
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77