CMS 3D CMS Logo

VertexAssociatorByTracks.cc
Go to the documentation of this file.
2 
8 
11 
15 
17 
19 
20 /* Constructor */
22  double R2SMatchedSimRatio,
23  double R2SMatchedRecoRatio,
24  double S2RMatchedSimRatio,
25  double S2RMatchedRecoRatio,
26  const TrackingParticleSelector *selector,
28  const reco::RecoToSimCollection *trackRecoToSimAssociation,
29  const reco::SimToRecoCollection *trackSimToRecoAssociation)
30  : productGetter_(productGetter),
31  R2SMatchedSimRatio_(R2SMatchedSimRatio),
32  R2SMatchedRecoRatio_(R2SMatchedRecoRatio),
33  S2RMatchedSimRatio_(S2RMatchedSimRatio),
34  S2RMatchedRecoRatio_(S2RMatchedRecoRatio),
35  selector_(selector),
36  trackQuality_(trackQuality),
37  trackRecoToSimAssociation_(trackRecoToSimAssociation),
38  trackSimToRecoAssociation_(trackSimToRecoAssociation) {}
39 
40 /* Destructor */
42 
44  const edm::Handle<edm::View<reco::Vertex>> &recoVertexes,
45  const edm::Handle<TrackingVertexCollection> &trackingVertexes) const {
47 
48  std::map<TrackingVertexRef, std::pair<double, std::size_t>> matches;
49 
50  LogDebug("VertexAssociation") << "reco::VertexCollection size = " << recoVertexes->size()
51  << " ; TrackingVertexCollection size = " << trackingVertexes->size() << std::endl;
52 
53  // Loop over RecoVertex
54  for (std::size_t recoIndex = 0; recoIndex < recoVertexes->size(); ++recoIndex) {
55  reco::VertexBaseRef recoVertex(recoVertexes, recoIndex);
56 
57  matches.clear();
58 
59  double recoDaughterWeight = 0.;
60 
61  // Loop over daughter tracks of RecoVertex
62  for (reco::Vertex::trackRef_iterator recoDaughter = recoVertex->tracks_begin();
63  recoDaughter != recoVertex->tracks_end();
64  ++recoDaughter) {
65  // Check the quality of the RecoDoughters
66  if (!(*recoDaughter)->quality(trackQuality_))
67  continue;
68 
69  // Check for association for the given RecoDaughter
70  if (trackRecoToSimAssociation_->numberOfAssociations(*recoDaughter) > 0) {
71  std::vector<std::pair<TrackingParticleRef, double>> associations = (*trackRecoToSimAssociation_)[*recoDaughter];
72 
73  // Loop over TrackingParticles associated with RecoDaughter
74  for (std::vector<std::pair<TrackingParticleRef, double>>::const_iterator association = associations.begin();
75  association != associations.end();
76  ++association) {
77  // Get a reference to parent vertex of TrackingParticle associated to
78  // the RecoDaughter
79  TrackingVertexRef trackingVertex = association->first->parentVertex();
80  // Store matched RecoDaughter to the trackingVertex
81  matches[trackingVertex].first += recoVertex->trackWeight(*recoDaughter);
82  matches[trackingVertex].second++;
83  }
84  }
85 
86  recoDaughterWeight += recoVertex->trackWeight(*recoDaughter);
87  } // loop over daughter tracks of RecoVertex
88 
89  std::size_t assoIndex = 0;
90 
91  // Loop over map between TrackingVertexes and matched RecoDaugther
92  for (std::map<TrackingVertexRef, std::pair<double, std::size_t>>::const_iterator match = matches.begin();
93  match != matches.end();
94  ++match) {
95  // Getting the TrackingVertex information
96  TrackingVertexRef trackingVertex = match->first;
97  double matchedDaughterWeight = match->second.first;
98  std::size_t matchedDaughterCounter = match->second.second;
99 
100  // Count for only reconstructible SimDaughters
101  std::size_t simDaughterCounter = 0;
102 
103  for (TrackingVertex::tp_iterator simDaughter = trackingVertex->daughterTracks_begin();
104  simDaughter != trackingVertex->daughterTracks_end();
105  ++simDaughter)
106  if ((*selector_)(**simDaughter))
107  simDaughterCounter++;
108 
109  // Sanity condition in case that reconstructable condition is too tight
110  if (simDaughterCounter < matchedDaughterCounter)
111  simDaughterCounter = matchedDaughterCounter;
112 
113  // Condition over S2RMatchedSimRatio
114  if ((double)matchedDaughterCounter / simDaughterCounter < R2SMatchedSimRatio_)
115  continue;
116 
117  double quality = (double)matchedDaughterWeight / recoDaughterWeight;
118 
119  // Condition over R2SMatchedRecoRatio
121  continue;
122 
123  outputCollection.insert(recoVertex, std::make_pair(trackingVertex, quality));
124 
125  LogTrace("VertexAssociation") << "R2S: INDEX " << assoIndex << " ; SimDaughterCounter = " << simDaughterCounter
126  << " ; RecoDaughterWeight = " << recoDaughterWeight
127  << " ; MatchedDaughterCounter = " << matchedDaughterCounter
128  << " ; MatchedDaughterWeight = " << matchedDaughterWeight
129  << " ; quality = " << quality;
130 
131  assoIndex++;
132  }
133  } // Loop on RecoVertex
134 
135  LogTrace("VertexAssociation") << "\nRecoToSim OUTPUT COLLECTION: outputCollection.size() = "
136  << outputCollection.size() << std::endl;
137 
138  return outputCollection;
139 }
140 
142  const edm::Handle<edm::View<reco::Vertex>> &recoVertexes,
143  const edm::Handle<TrackingVertexCollection> &trackingVertexes) const {
145 
146  // Loop over TrackingVertexes
147  std::map<std::size_t, std::pair<double, std::size_t>> matches;
148 
149  // Loop over TrackingVertexes
150  for (std::size_t simIndex = 0; simIndex < trackingVertexes->size(); ++simIndex) {
151  TrackingVertexRef trackingVertex(trackingVertexes, simIndex);
152 
153  matches.clear();
154 
155  std::size_t simDaughterCounter = 0;
156 
157  // Loop over daughter tracks of TrackingVertex
158  for (TrackingVertex::tp_iterator simDaughter = trackingVertex->daughterTracks_begin();
159  simDaughter != trackingVertex->daughterTracks_end();
160  ++simDaughter) {
161  // Select only reconstructible SimDaughters
162  if (!(*selector_)(**simDaughter))
163  continue;
164 
165  // Check for association for the given RecoDaughter
166  if (trackSimToRecoAssociation_->numberOfAssociations(*simDaughter) > 0) {
167  std::vector<std::pair<reco::TrackBaseRef, double>> associations = (*trackSimToRecoAssociation_)[*simDaughter];
168 
169  // Loop over RecoTracks associated with TrackingParticle
170  for (std::vector<std::pair<reco::TrackBaseRef, double>>::const_iterator association = associations.begin();
171  association != associations.end();
172  ++association) {
173  reco::TrackBaseRef recoTrack = association->first;
174 
175  for (std::size_t recoIndex = 0; recoIndex < recoVertexes->size(); ++recoIndex) {
176  reco::VertexBaseRef recoVertex(recoVertexes, recoIndex);
177 
178  for (reco::Vertex::trackRef_iterator recoDaughter = recoVertex->tracks_begin();
179  recoDaughter != recoVertex->tracks_end();
180  ++recoDaughter) {
181  // Store matched RecoDaughter to the RecoVertex
182  if (recoDaughter->id() == recoTrack.id() && recoDaughter->key() == recoTrack.key()) {
183  matches[recoIndex].first += recoVertex->trackWeight(*recoDaughter);
184  matches[recoIndex].second++;
185  }
186  }
187  }
188  } // loop a recotracks
189  }
190 
191  simDaughterCounter++;
192  } // loop a simDaughter
193 
194  std::size_t assoIndex = 0;
195 
196  // Loop over map, set score, add to outputCollection
197  for (std::map<std::size_t, std::pair<double, std::size_t>>::const_iterator match = matches.begin();
198  match != matches.end();
199  ++match) {
200  // Getting the TrackingVertex information
201  reco::VertexBaseRef recoVertex(recoVertexes, match->first);
202  double matchedDaughterWeight = match->second.first;
203  std::size_t matchedDaughterCounter = match->second.second;
204 
205  double recoDaughterWeight = 0.;
206 
207  // Weighted count of those tracks with a given quality of the
208  // RecoDoughters
209  for (reco::Vertex::trackRef_iterator recoDaughter = recoVertex->tracks_begin();
210  recoDaughter != recoVertex->tracks_end();
211  ++recoDaughter)
212  if ((*recoDaughter)->quality(trackQuality_))
213  recoDaughterWeight += recoVertex->trackWeight(*recoDaughter);
214 
215  // Sanity condition in case that track quality condition is too tight
216  if (recoDaughterWeight < matchedDaughterWeight)
217  recoDaughterWeight = matchedDaughterWeight;
218 
219  // Condition over S2RMatchedRecoRatio
220  if (matchedDaughterWeight / recoDaughterWeight < S2RMatchedRecoRatio_)
221  continue;
222 
223  double quality = (double)matchedDaughterCounter / simDaughterCounter;
224 
225  // Condition over S2RMatchedSimRatio
227  continue;
228 
229  outputCollection.insert(trackingVertex, std::make_pair(recoVertex, quality));
230 
231  LogTrace("VertexAssociation") << "R2S: INDEX " << assoIndex << " ; SimDaughterCounter = " << simDaughterCounter
232  << " ; RecoDaughterWeight = " << recoDaughterWeight
233  << " ; MatchedDaughterCounter = " << matchedDaughterCounter
234  << " ; MatchedDaughterWeight = " << matchedDaughterWeight
235  << " ; quality = " << quality;
236 
237  assoIndex++;
238  }
239  } // loop over TrackingVertexes
240 
241  LogTrace("VertexAssociation") << "SimToReco OUTPUT COLLECTION: outputCollection.size() = " << outputCollection.size()
242  << std::endl;
243 
244  return outputCollection;
245 }
VertexAssociatorByTracks::productGetter_
const edm::EDProductGetter * productGetter_
Definition: VertexAssociatorByTracks.h:32
reco::Vertex::trackRef_iterator
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:38
genericTrackCandidates_cff.associations
associations
Definition: genericTrackCandidates_cff.py:45
Handle.h
StandaloneTrackMonitor_cfi.trackQuality
trackQuality
Definition: StandaloneTrackMonitor_cfi.py:11
MessageLogger.h
edm::RefToBase::key
size_t key() const
Definition: RefToBase.h:219
VertexAssociatorByTracks::associateSimToReco
reco::VertexSimToRecoCollection associateSimToReco(const edm::Handle< edm::View< reco::Vertex >> &vCH, const edm::Handle< TrackingVertexCollection > &tVCH) const override
Definition: VertexAssociatorByTracks.cc:141
TrackingParticleSelector.h
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
reco::TrackBase::TrackQuality
TrackQuality
track quality
Definition: TrackBase.h:150
ChiSquaredProbability.h
TrackingVertex.h
VertexAssociatorByTracks::S2RMatchedRecoRatio_
const double S2RMatchedRecoRatio_
Definition: VertexAssociatorByTracks.h:37
TrackingParticleSelector
Definition: TrackingParticleSelector.h:16
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< TrackingVertexCollection >
quality
const uint32_t *__restrict__ Quality * quality
Definition: CAHitNtupletGeneratorKernelsImpl.h:109
edm::EDProductGetter
Definition: EDProductGetter.h:41
TrackingVertexContainer.h
VertexAssociatorByTracks::trackQuality_
const reco::TrackBase::TrackQuality trackQuality_
Definition: VertexAssociatorByTracks.h:40
VertexAssociatorByTracks.h
VertexAssociatorByTracks::S2RMatchedSimRatio_
const double S2RMatchedSimRatio_
Definition: VertexAssociatorByTracks.h:36
RefToBase.h
VertexAssociatorByTracks::R2SMatchedRecoRatio_
const double R2SMatchedRecoRatio_
Definition: VertexAssociatorByTracks.h:35
VertexAssociatorByTracks::R2SMatchedSimRatio_
const double R2SMatchedSimRatio_
Definition: VertexAssociatorByTracks.h:34
Vertex.h
VertexAssociatorByTracks::associateRecoToSim
reco::VertexRecoToSimCollection associateRecoToSim(const edm::Handle< edm::View< reco::Vertex >> &vCH, const edm::Handle< TrackingVertexCollection > &tVCH) const override
Definition: VertexAssociatorByTracks.cc:43
edm::View
Definition: CaloClusterFwd.h:14
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::AssociationMap::size
size_type size() const
map size
Definition: AssociationMap.h:162
VertexAssociatorByTracks::trackSimToRecoAssociation_
const reco::SimToRecoCollection * trackSimToRecoAssociation_
Definition: VertexAssociatorByTracks.h:43
edm::AssociationMap< edm::OneToManyWithQualityGeneric< edm::View< reco::Track >, TrackingParticleCollection, double > >
VertexAssociatorByTracks::~VertexAssociatorByTracks
~VertexAssociatorByTracks() override
Definition: VertexAssociatorByTracks.cc:41
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
VertexAssociatorByTracks::VertexAssociatorByTracks
VertexAssociatorByTracks(const edm::EDProductGetter *productGetter, double R2SMatchedSimRatio, double R2SMatchedRecoRatio, double S2RMatchedSimRatio, double S2RMatchedRecoRatio, const TrackingParticleSelector *selector, reco::TrackBase::TrackQuality trackQuality, const reco::RecoToSimCollection *trackRecoToSimAssociation, const reco::SimToRecoCollection *trackSimToRecoAssociation)
Definition: VertexAssociatorByTracks.cc:21
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::refcoreimpl::productGetter
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
Definition: refcore_implementation.h:72
VertexAssociatorByTracks::trackRecoToSimAssociation_
const reco::RecoToSimCollection * trackRecoToSimAssociation_
Definition: VertexAssociatorByTracks.h:42
edm::RefToBase::id
ProductID id() const
Definition: RefToBase.h:214
VertexFwd.h
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
HLTEgPhaseIITestSequence_cff.recoVertex
recoVertex
Definition: HLTEgPhaseIITestSequence_cff.py:50
Ref.h
hgcal::association
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
Definition: LayerClusterAssociatorByEnergyScoreImpl.h:44
Frameworkfwd.h
edm::RefVectorIterator
Definition: EDProductfwd.h:33
edm::RefToBase< reco::Vertex >
genParticles_cff.map
map
Definition: genParticles_cff.py:11
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
VertexAssociatorByTracks::selector_
const TrackingParticleSelector * selector_
Definition: VertexAssociatorByTracks.h:39
edm::AssociationMap::numberOfAssociations
size_type numberOfAssociations(const key_type &k) const
number of associations to a key
Definition: AssociationMap.h:197
EncodedEventId.h