CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Namespaces | Typedefs | Enumerations | Functions
noPileUpMEtAuxFunctions.h File Reference
#include "DataFormats/Common/interface/AssociationMap.h"
#include "DataFormats/Common/interface/OneToManyWithQuality.h"
#include "DataFormats/Common/interface/Ref.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "CommonTools/RecoUtils/interface/PFCand_AssoMapAlgos.h"

Go to the source code of this file.

Namespaces

 noPuUtils
 

Typedefs

typedef edm::AssociationMap
< edm::OneToManyWithQuality
< reco::PFCandidateCollection,
reco::VertexCollection, int > > 
reversedPFCandidateToVertexAssociationMap
 

Enumerations

enum  { noPuUtils::kNeutral =0, noPuUtils::kChNoAssoc, noPuUtils::kChPUAssoc, noPuUtils::kChHSAssoc }
 

Functions

int isVertexAssociated (const reco::PFCandidate &, const PFCandToVertexAssMap &, const reco::VertexCollection &, double)
 
int isVertexAssociated_fast (const reco::PFCandidateRef &, const reversedPFCandidateToVertexAssociationMap &, const reco::VertexCollection &, double, int &, int)
 
reversedPFCandidateToVertexAssociationMap reversePFCandToVertexAssociation (const PFCandToVertexAssMap &)
 

Typedef Documentation

Definition at line 24 of file noPileUpMEtAuxFunctions.h.

Function Documentation

int isVertexAssociated ( const reco::PFCandidate ,
const PFCandToVertexAssMap ,
const reco::VertexCollection ,
double   
)

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 int minPFCandToVertexAssocQuality
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
int isVertexAssociated_fast ( const reco::PFCandidateRef ,
const reversedPFCandidateToVertexAssociationMap ,
const reco::VertexCollection ,
double  ,
int &  ,
int   
)

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 int minPFCandToVertexAssocQuality
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
reversedPFCandidateToVertexAssociationMap reversePFCandToVertexAssociation ( const PFCandToVertexAssMap )

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 }
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