CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
noPileUpMEtAuxFunctions.cc
Go to the documentation of this file.
2 
4 
5 #include <math.h>
6 
7 const int minPFCandToVertexAssocQuality = noPuUtils::kChHSAssoc; // CV: value recommended by Matthias Geisler, representing "good" PFCandidate-vertex associations
8 
9 const double dR2Min=0.01*0.01;
10 
11 int isVertexAssociated(const reco::PFCandidate& pfCandidate,
12  const PFCandToVertexAssMap& pfCandToVertexAssociations,
13  const reco::VertexCollection& vertices, double dZ)
14 {
15  int vtxAssociationType = noPuUtils::kNeutral;
16 
17  if ( pfCandidate.charge() != 0 ) {
18  vtxAssociationType = noPuUtils::kChNoAssoc;
19  for ( PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
20  pfCandToVertexAssociation != pfCandToVertexAssociations.end(); ++pfCandToVertexAssociation ) {
21  typedef std::vector<std::pair<reco::PFCandidateRef, int> > PFCandidateQualityPairVector;
22  const PFCandidateQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
23  for ( PFCandidateQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
24  pfCandidate_vertex != pfCandidates_vertex.end(); ++pfCandidate_vertex ) {
25  int pfCandToVertexAssocQuality = pfCandidate_vertex->second;
26  if ( pfCandToVertexAssocQuality >= minPFCandToVertexAssocQuality && deltaR2(pfCandidate.p4(), pfCandidate_vertex->first->p4()) < dR2Min ) {
27  if ( vtxAssociationType < noPuUtils::kChPUAssoc ) vtxAssociationType = noPuUtils::kChPUAssoc;
28  for ( reco::VertexCollection::const_iterator vertex = vertices.begin();
29  vertex != vertices.end(); ++vertex ) {
30  if ( std::abs(pfCandToVertexAssociation->key->position().z() - vertex->position().z()) < dZ ) {
31  if ( vtxAssociationType < noPuUtils::kChHSAssoc ) vtxAssociationType = noPuUtils::kChHSAssoc;
32  }
33  }
34  }
35  }
36  }
37  }
38 
39  return vtxAssociationType;
40 }
41 
43 {
44  reversedPFCandidateToVertexAssociationMap pfCandToVertexAssociations_reversed;
45 
46  for ( PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
47  pfCandToVertexAssociation != pfCandToVertexAssociations.end(); ++pfCandToVertexAssociation ) {
48  const reco::VertexRef& vertex = pfCandToVertexAssociation->key;
49  typedef std::vector<std::pair<reco::PFCandidateRef, int> > PFCandidateQualityPairVector;
50  const PFCandidateQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
51  for ( PFCandidateQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
52  pfCandidate_vertex != pfCandidates_vertex.end(); ++pfCandidate_vertex ) {
53  pfCandToVertexAssociations_reversed.insert(pfCandidate_vertex->first, std::make_pair(vertex, pfCandidate_vertex->second));
54  }
55  }
56 
57  return pfCandToVertexAssociations_reversed;
58 }
59 
61  const reversedPFCandidateToVertexAssociationMap& pfCandToVertexAssociations,
62  const reco::VertexCollection& vertices, double dZ,
63  int& numWarnings, int maxWarnings)
64 {
65  int vtxAssociationType = 0; // 0 = neutral particle,
66  // 1 = charged particle not associated to any vertex
67  // 2 = charged particle associated to pile-up vertex
68  // 3 = charged particle associated to vertex of hard-scatter event
69 
70  if ( pfCandidate->charge() != 0 ) {
71  vtxAssociationType = 1;
72  typedef std::vector<std::pair<reco::VertexRef, int> > VertexQualityPairVector;
73  const VertexQualityPairVector* pfCandidate_associated_vertices = nullptr;
74  reversedPFCandidateToVertexAssociationMap::const_iterator pfCandToVertexAssociation_iter = pfCandToVertexAssociations.find(pfCandidate);
75  if ( pfCandToVertexAssociation_iter != pfCandToVertexAssociations.end() ) {
76  pfCandidate_associated_vertices = &pfCandToVertexAssociation_iter->val;
77  } else {
78  for ( reversedPFCandidateToVertexAssociationMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
79  pfCandToVertexAssociation != pfCandToVertexAssociations.end(); ++pfCandToVertexAssociation ) {
80  if ( deltaR2(pfCandidate->p4(), pfCandToVertexAssociation->key->p4()) < dR2Min ) {
81  pfCandidate_associated_vertices = &pfCandToVertexAssociation->val;
82  break;
83  }
84  }
85  if ( numWarnings < maxWarnings ) {
86  edm::LogWarning ("isVertexAssociated")
87  << " The productIDs of PFCandidate and PFCandToVertexAssociationMap passed as function arguments don't match.\n"
88  << "NOTE: The return value will be unaffected, but the code will run MUCH slower !!";
89  ++numWarnings;
90  }
91  }
92  if ( pfCandidate_associated_vertices ) {
93  for ( VertexQualityPairVector::const_iterator pfCandidate_associated_vertex = pfCandidate_associated_vertices->begin();
94  pfCandidate_associated_vertex != pfCandidate_associated_vertices->end(); ++pfCandidate_associated_vertex ) {
95  if ( pfCandidate_associated_vertex->second >= minPFCandToVertexAssocQuality ) {
96  if ( vtxAssociationType < noPuUtils::kChPUAssoc ) vtxAssociationType = noPuUtils::kChPUAssoc;
97  for ( reco::VertexCollection::const_iterator vertex = vertices.begin();
98  vertex != vertices.end(); ++vertex ) {
99  if ( std::abs(pfCandidate_associated_vertex->first->position().z() - vertex->position().z()) < dZ ) {
100  if ( vtxAssociationType < noPuUtils::kChHSAssoc ) vtxAssociationType = noPuUtils::kChHSAssoc;
101  }
102  }
103  }
104  }
105  }
106  }
107 
108  return vtxAssociationType;
109 }
const_iterator end() const
last iterator over the map (read only)
const_iterator find(const key_type &k) const
find element with specified reference key
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const int minPFCandToVertexAssocQuality
key_type key() const
Accessor for product key.
Definition: Ref.h:266
reversedPFCandidateToVertexAssociationMap reversePFCandToVertexAssociation(const PFCandToVertexAssMap &)
virtual int charge() const
electric charge
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
int isVertexAssociated(const reco::PFCandidate &, const PFCandToVertexAssMap &, const reco::VertexCollection &, double)
void insert(const key_type &k, const data_type &v)
insert an association
const double dR2Min
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
int isVertexAssociated_fast(const reco::PFCandidateRef &, const reversedPFCandidateToVertexAssociationMap &, const reco::VertexCollection &, double, int &, int)
const_iterator begin() const
first iterator over the map (read only)
virtual const LorentzVector & p4() const
four-momentum Lorentz vector