CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
noPileUpMEtAuxFunctions.cc File Reference
#include "RecoMET/METPUSubtraction/interface/noPileUpMEtAuxFunctions.h"
#include "DataFormats/Math/interface/deltaR.h"
#include <math.h>

Go to the source code of this file.

Functions

int isVertexAssociated (const reco::PFCandidate &pfCandidate, const PFCandToVertexAssMap &pfCandToVertexAssociations, const reco::VertexCollection &vertices, double dZ)
 
int isVertexAssociated_fast (const reco::PFCandidateRef &pfCandidate, const reversedPFCandidateToVertexAssociationMap &pfCandToVertexAssociations, const reco::VertexCollection &vertices, double dZ, int &numWarnings, int maxWarnings)
 
reversedPFCandidateToVertexAssociationMap reversePFCandToVertexAssociation (const PFCandToVertexAssMap &pfCandToVertexAssociations)
 

Variables

const double dR2Min =0.01*0.01
 
const int minPFCandToVertexAssocQuality = noPuUtils::kChHSAssoc
 

Function Documentation

int isVertexAssociated ( const reco::PFCandidate pfCandidate,
const PFCandToVertexAssMap pfCandToVertexAssociations,
const reco::VertexCollection vertices,
double  dZ 
)

Definition at line 11 of file noPileUpMEtAuxFunctions.cc.

References funct::abs(), edm::AssociationMap< Tag >::begin(), reco::LeafCandidate::charge(), reco::deltaR2(), dR2Min, edm::AssociationMap< Tag >::end(), noPuUtils::kChHSAssoc, noPuUtils::kChNoAssoc, noPuUtils::kChPUAssoc, noPuUtils::kNeutral, minPFCandToVertexAssocQuality, and reco::LeafCandidate::p4().

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 }
const_iterator end() const
last iterator over the map (read only)
const int minPFCandToVertexAssocQuality
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
const double dR2Min
const_iterator begin() const
first iterator over the map (read only)
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
int isVertexAssociated_fast ( const reco::PFCandidateRef pfCandidate,
const reversedPFCandidateToVertexAssociationMap pfCandToVertexAssociations,
const reco::VertexCollection vertices,
double  dZ,
int &  numWarnings,
int  maxWarnings 
)

Definition at line 60 of file noPileUpMEtAuxFunctions.cc.

References funct::abs(), edm::AssociationMap< Tag >::begin(), reco::deltaR2(), dR2Min, edm::AssociationMap< Tag >::end(), edm::AssociationMap< Tag >::find(), noPuUtils::kChHSAssoc, noPuUtils::kChPUAssoc, edm::Ref< C, T, F >::key(), minPFCandToVertexAssocQuality, and edm::helpers::KeyVal< K, V >::val.

Referenced by NoPileUpPFMEtDataProducer::produce().

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
const int minPFCandToVertexAssocQuality
key_type key() const
Accessor for product key.
Definition: Ref.h:266
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
const double dR2Min
const_iterator begin() const
first iterator over the map (read only)
reversedPFCandidateToVertexAssociationMap reversePFCandToVertexAssociation ( const PFCandToVertexAssMap pfCandToVertexAssociations)

Definition at line 42 of file noPileUpMEtAuxFunctions.cc.

References edm::AssociationMap< Tag >::begin(), edm::AssociationMap< Tag >::end(), edm::AssociationMap< Tag >::insert(), and edm::Ref< C, T, F >::key().

Referenced by NoPileUpPFMEtDataProducer::produce().

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 }
const_iterator end() const
last iterator over the map (read only)
key_type key() const
Accessor for product key.
Definition: Ref.h:266
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator begin() const
first iterator over the map (read only)

Variable Documentation

const double dR2Min =0.01*0.01

Definition at line 9 of file noPileUpMEtAuxFunctions.cc.

const int minPFCandToVertexAssocQuality = noPuUtils::kChHSAssoc

Definition at line 7 of file noPileUpMEtAuxFunctions.cc.

Referenced by isVertexAssociated(), and isVertexAssociated_fast().