CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
7 #include "getChi2.h"
8 
9 using namespace edm;
10 using namespace reco;
11 using namespace std;
12 
13 double TrackAssociatorByChi2Impl::compareTracksParam ( TrackCollection::const_iterator rt,
14  SimTrackContainer::const_iterator st,
15  const math::XYZTLorentzVectorD& vertexPosition,
16  const GlobalVector& magField,
17  const TrackBase::CovarianceMatrix& invertedCovariance,
18  const reco::BeamSpot& bs) const{
19 
20  Basic3DVector<double> momAtVtx(st->momentum().x(),st->momentum().y(),st->momentum().z());
21  Basic3DVector<double> vert = (Basic3DVector<double>) vertexPosition;
22 
23  std::pair<bool,reco::TrackBase::ParameterVector> params = parametersAtClosestApproach(vert, momAtVtx, st->charge(), bs);
24  if (params.first){
25  TrackBase::ParameterVector sParameters = params.second;
26  TrackBase::ParameterVector rParameters = rt->parameters();
27 
28  TrackBase::ParameterVector diffParameters = rParameters - sParameters;
29  diffParameters[2] = reco::deltaPhi(diffParameters[2],0.f);
30  double chi2 = ROOT::Math::Dot(diffParameters * invertedCovariance, diffParameters);
31 
32  return chi2;
33  } else {
34  return 10000000000.;
35  }
36 }
37 
38 
41  const SimTrackContainer& stColl,
42  const SimVertexContainer& svColl,
43  const reco::BeamSpot& bs) const{
44 
45  RecoToSimPairAssociation outputVec;
46 
47  for (TrackCollection::const_iterator track=rtColl.begin(); track!=rtColl.end(); track++){
48  Chi2SimMap outMap;
49 
50  TrackBase::ParameterVector rParameters = track->parameters();
51 
52  TrackBase::CovarianceMatrix recoTrackCovMatrix = track->covariance();
53  if (onlyDiagonal){
54  for (unsigned int i=0;i<5;i++){
55  for (unsigned int j=0;j<5;j++){
56  if (i!=j) recoTrackCovMatrix(i,j)=0;
57  }
58  }
59  }
60  recoTrackCovMatrix.Invert();
61 
62  for (SimTrackContainer::const_iterator st=stColl.begin(); st!=stColl.end(); st++){
63 
64  Basic3DVector<double> momAtVtx(st->momentum().x(),st->momentum().y(),st->momentum().z());
65  Basic3DVector<double> vert = (Basic3DVector<double>) svColl[st->vertIndex()].position();
66 
67  std::pair<bool,reco::TrackBase::ParameterVector> params = parametersAtClosestApproach(vert, momAtVtx, st->charge(), bs);
68  if (params.first){
69  TrackBase::ParameterVector sParameters = params.second;
70 
71  TrackBase::ParameterVector diffParameters = rParameters - sParameters;
72  diffParameters[2] = reco::deltaPhi(diffParameters[2],0.f);
73  double chi2 = ROOT::Math::Dot(diffParameters * recoTrackCovMatrix, diffParameters);
74  chi2/=5;
75  if (chi2<chi2cut) outMap[chi2]=*st;
76  }
77  }
78  outputVec.push_back(RecoToSimPair(*track,outMap));
79  }
80  return outputVec;
81 }
82 
84  const TrackBase::CovarianceMatrix& recoTrackCovMatrix,
85  const Basic3DVector<double>& momAtVtx,
86  const Basic3DVector<double>& vert,
87  int charge,
88  const reco::BeamSpot& bs) const{
89  return track_associator::getChi2(rParameters, recoTrackCovMatrix,momAtVtx, vert, charge, *theMF, bs);
90 }
91 
92 
93 double TrackAssociatorByChi2Impl::associateRecoToSim( TrackCollection::const_iterator rt,
94  TrackingParticleCollection::const_iterator tp,
95  const reco::BeamSpot& bs) const{
96  TrackBase::ParameterVector rParameters = rt->parameters();
97  TrackBase::CovarianceMatrix recoTrackCovMatrix = rt->covariance();
98  if (onlyDiagonal){
99  for (unsigned int i=0;i<5;i++){
100  for (unsigned int j=0;j<5;j++){
101  if (i!=j) recoTrackCovMatrix(i,j)=0;
102  }
103  }
104  }
105 
106  recoTrackCovMatrix.Invert();
107  Basic3DVector<double> momAtVtx(tp->momentum().x(),tp->momentum().y(),tp->momentum().z());
108  Basic3DVector<double> vert(tp->vertex().x(),tp->vertex().y(),tp->vertex().z());
109  int charge = tp->charge();
110  return getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
111 }
112 
113 pair<bool,TrackBase::ParameterVector>
115  const Basic3DVector<double>& momAtVtx,
116  float charge,
117  const BeamSpot& bs) const{
118  return reco::trackingParametersAtClosestApproachToBeamSpot(vertex,momAtVtx,charge, *theMF, bs);
119 }
120 
122  const edm::RefVector<TrackingParticleCollection>& tPCH) const {
123 
124  const reco::BeamSpot& bs = *theBeamSpot;
125 
126  RecoToSimCollection outputCollection;
127 
128  //dereference the edm::Refs only once
129  std::vector<TrackingParticle const*> tPC;
130  tPC.reserve(tPCH.size());
131  for(auto const& ref: tPCH) {
132  tPC.push_back(&(*ref));
133  }
134 
135  int tindex=0;
136  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
137 
138  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
139  << "rec::Track #"<<tindex<<" with pt=" << (*rt)->pt() << "\n"
140  << "===========================================" << "\n";
141 
142  TrackBase::ParameterVector rParameters = (*rt)->parameters();
143 
144  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
145  if (onlyDiagonal){
146  for (unsigned int i=0;i<5;i++){
147  for (unsigned int j=0;j<5;j++){
148  if (i!=j) recoTrackCovMatrix(i,j)=0;
149  }
150  }
151  }
152 
153  recoTrackCovMatrix.Invert();
154 
155  int tpindex =0;
156  for (auto tp=tPC.begin(); tp!=tPC.end(); tp++, ++tpindex){
157 
158  //skip tps with a very small pt
159  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
160  int charge = (*tp)->charge();
161  if (charge==0) continue;
162  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
163  Basic3DVector<double> vert=(Basic3DVector<double>) (*tp)->vertex();
164 
165  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
166 
167  if (chi2<chi2cut) {
168  outputCollection.insert(tC[tindex],
169  std::make_pair(tPCH[tpindex],
170  -chi2));//-chi2 because the Association Map is ordered using std::greater
171  }
172  }
173  }
174  outputCollection.post_insert();
175  return outputCollection;
176 }
177 
178 
180  const edm::RefVector<TrackingParticleCollection>& tPCH) const {
181  const reco::BeamSpot& bs = *theBeamSpot;
182 
183  SimToRecoCollection outputCollection;
184 
185  int tpindex =0;
186  for (auto tp=tPCH.begin(); tp!=tPCH.end(); tp++, ++tpindex){
187 
188  //skip tps with a very small pt
189  //if (sqrt(tp->momentum().perp2())<0.5) continue;
190  int charge = (*tp)->charge();
191  if (charge==0) continue;
192 
193  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION===========" << "\n"
194  << "TrackingParticle #"<<tpindex<<" with pt=" << sqrt((*tp)->momentum().perp2()) << "\n"
195  << "===========================================" << "\n";
196 
197  Basic3DVector<double> momAtVtx((*tp)->momentum().x(),(*tp)->momentum().y(),(*tp)->momentum().z());
198  Basic3DVector<double> vert((*tp)->vertex().x(),(*tp)->vertex().y(),(*tp)->vertex().z());
199 
200  int tindex=0;
201  for (RefToBaseVector<reco::Track>::const_iterator rt=tC.begin(); rt!=tC.end(); rt++, tindex++){
202 
203  TrackBase::ParameterVector rParameters = (*rt)->parameters();
204  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
205  if (onlyDiagonal) {
206  for (unsigned int i=0;i<5;i++){
207  for (unsigned int j=0;j<5;j++){
208  if (i!=j) recoTrackCovMatrix(i,j)=0;
209  }
210  }
211  }
212  recoTrackCovMatrix.Invert();
213 
214  double chi2 = getChi2(rParameters,recoTrackCovMatrix,momAtVtx,vert,charge,bs);
215 
216  if (chi2<chi2cut) {
217  outputCollection.insert(*tp,
218  std::make_pair(tC[tindex],
219  -chi2));//-chi2 because the Association Map is ordered using std::greater
220  }
221  }
222  }
223  outputCollection.post_insert();
224  return outputCollection;
225 }
226 
#define LogDebug(id)
virtual reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
int i
Definition: DBlmapReader.cc:9
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
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
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
virtual reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
const_iterator end() const
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:74
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:255
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:250
std::vector< RecoToSimPair > RecoToSimPairAssociation
std::pair< reco::Track, Chi2SimMap > RecoToSimPair
void post_insert()
post insert action
T sqrt(T t)
Definition: SSEVec.h:18
int j
Definition: DBlmapReader.cc:9
double compareTracksParam(reco::TrackCollection::const_iterator, edm::SimTrackContainer::const_iterator, const math::XYZTLorentzVectorD &, const GlobalVector &, const reco::TrackBase::CovarianceMatrix &, const reco::BeamSpot &) const
compare reco::TrackCollection and edm::SimTrackContainer iterators: returns the chi2 ...
double f[11][100]
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
void insert(const key_type &k, const data_type &v)
insert an association
std::pair< bool, reco::TrackBase::ParameterVector > trackingParametersAtClosestApproachToBeamSpot(const Basic3DVector< double > &vertex, const Basic3DVector< double > &momAtVtx, float charge, const MagneticField &magField, const BeamSpot &bs)
std::pair< bool, reco::TrackBase::ParameterVector > parametersAtClosestApproach(const Basic3DVector< double > &, const Basic3DVector< double > &, float, const reco::BeamSpot &) const
propagate the track parameters of TrackinParticle from production vertex to the point of closest appr...
std::vector< SimVertex > SimVertexContainer
const_iterator begin() const
std::map< double, SimTrack > Chi2SimMap
size_type size() const
Size of the RefVector.
Definition: RefVector.h:99
std::vector< SimTrack > SimTrackContainer
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:77