CMS 3D CMS Logo

TrackAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
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::trackAssociationChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, *theMF, bs);
19 }
20 
23  const reco::BeamSpot& bs = *theBeamSpot;
24 
25  RecoToSimCollection outputCollection;
26 
27  //dereference the edm::Refs only once
28  std::vector<TrackingParticle 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  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
37  << "\n"
38  << "rec::Track #" << tindex << " with pt=" << (*rt)->pt() << "\n"
39  << "==========================================="
40  << "\n";
41 
42  TrackBase::ParameterVector rParameters = (*rt)->parameters();
43 
44  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
45  if (onlyDiagonal) {
46  for (unsigned int i = 0; i < 5; i++) {
47  for (unsigned int j = 0; j < 5; j++) {
48  if (i != j)
49  recoTrackCovMatrix(i, j) = 0;
50  }
51  }
52  }
53 
54  recoTrackCovMatrix.Invert();
55 
56  int tpindex = 0;
57  for (auto tp = tPC.begin(); tp != tPC.end(); tp++, ++tpindex) {
58  //skip tps with a very small pt
59  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
60  int charge = (*tp)->charge();
61  if (charge == 0)
62  continue;
63  Basic3DVector<double> momAtVtx((*tp)->momentum().x(), (*tp)->momentum().y(), (*tp)->momentum().z());
64  Basic3DVector<double> vert = (Basic3DVector<double>)(*tp)->vertex();
65 
66  double chi2 = getChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, bs);
67 
68  if (chi2 < chi2cut) {
69  outputCollection.insert(
70  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 
82  const reco::BeamSpot& bs = *theBeamSpot;
83 
84  SimToRecoCollection outputCollection;
85 
86  int tpindex = 0;
87  for (auto tp = tPCH.begin(); tp != tPCH.end(); tp++, ++tpindex) {
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)
92  continue;
93 
94  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
95  << "\n"
96  << "TrackingParticle #" << tpindex << " with pt=" << sqrt((*tp)->momentum().perp2())
97  << "\n"
98  << "==========================================="
99  << "\n";
100 
101  Basic3DVector<double> momAtVtx((*tp)->momentum().x(), (*tp)->momentum().y(), (*tp)->momentum().z());
102  Basic3DVector<double> vert((*tp)->vertex().x(), (*tp)->vertex().y(), (*tp)->vertex().z());
103 
104  int tindex = 0;
105  for (RefToBaseVector<reco::Track>::const_iterator rt = tC.begin(); rt != tC.end(); rt++, tindex++) {
106  TrackBase::ParameterVector rParameters = (*rt)->parameters();
107  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
108  if (onlyDiagonal) {
109  for (unsigned int i = 0; i < 5; i++) {
110  for (unsigned int j = 0; j < 5; j++) {
111  if (i != j)
112  recoTrackCovMatrix(i, j) = 0;
113  }
114  }
115  }
116  recoTrackCovMatrix.Invert();
117 
118  double chi2 = getChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, bs);
119 
120  if (chi2 < chi2cut) {
121  outputCollection.insert(
122  *tp,
123  std::make_pair(tC[tindex],
124  -chi2)); //-chi2 because the Association Map is ordered using std::greater
125  }
126  }
127  }
128  outputCollection.post_insert();
129  return outputCollection;
130 }
edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
mps_fire.i
i
Definition: mps_fire.py:355
TrackAssociatorByChi2Impl::getChi2
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
Definition: TrackAssociatorByChi2Impl.cc:12
TrackAssociatorByChi2Impl::associateRecoToSim
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
Definition: TrackAssociatorByChi2Impl.cc:21
trackAssociatorByChi2_cfi.chi2cut
chi2cut
Definition: trackAssociatorByChi2_cfi.py:4
TrackAssociatorByChi2Impl.h
edm
HLT enums.
Definition: AlignableModifier.h:19
hcal_runs.rt
rt
Definition: hcal_runs.py:76
edm::RefVector::begin
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
track_associator::trackAssociationChi2
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
Definition: trackAssociationChi2.cc:9
edm::RefVector< TrackingParticleCollection >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
edm::AssociationMap::post_insert
void post_insert()
post insert action
Definition: AssociationMap.h:229
cms::cuda::bs
bs
Definition: HistoContainer.h:127
edm::RefVector::end
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
reco::TrackBase::ParameterVector
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
TrackAssociatorByChi2Impl::associateSimToReco
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
Definition: TrackAssociatorByChi2Impl.cc:80
Line.h
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
trackAssociatorByChi2_cfi.onlyDiagonal
onlyDiagonal
Definition: trackAssociatorByChi2_cfi.py:6
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
edm::RefToBaseVector< reco::Track >
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
TrackingParticle.h
std
Definition: JetResolutionObject.h:76
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
trackAssociationChi2.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
reco::TrackBase::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
Basic3DVector
Definition: extBasic3DVector.h:30
deltaPhi.h