test
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 
5 
6 #include <cmath>
7 
8 namespace noPuUtils{
9  const double dR2Min=0.01*0.01;
10 
11  int isVertexAssociated(const reco::PFCandidatePtr& 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 
22  const noPuUtils::CandQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
23 
24 
25  for ( noPuUtils::CandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
26  pfCandidate_vertex != pfCandidates_vertex.end(); ++pfCandidate_vertex ) {
27 
28  const reco::PFCandidatePtr pfcVtx= edm::refToPtr(pfCandidate_vertex->first); //<reco::PFCandidatePtr>
29  //std::cout<<pfCandidate<<" "<<test<<std::endl;
30 
31  if(pfCandidate != pfcVtx ) continue;//std::cout<<" pouet "<<pfCandidate<<" "<<test<<std::endl;
32 
33  //if(deltaR2(pfCandidate->p4(), pfCandidate_vertex->first->p4()) > dR2Min ) continue;
34  double z = pfCandToVertexAssociation->key->position().z();
35  int quality = pfCandidate_vertex->second;
36  promoteAssocToHSAssoc( quality, z, vertices, dZ, vtxAssociationType, false);
37  }
38  }
39  }
40 
41  return vtxAssociationType;
42  }
43 
45  reversePFCandToVertexAssociation(const PFCandToVertexAssMap& pfCandToVertexAssociations) {
46 
47  noPuUtils::reversedPFCandToVertexAssMap revPfCandToVtxAssoc;
48 
49  for ( PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
50  pfCandToVertexAssociation != pfCandToVertexAssociations.end(); ++pfCandToVertexAssociation ) {
51  const reco::VertexRef& vertex = pfCandToVertexAssociation->key;
52 
53  const noPuUtils::CandQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
54  for ( noPuUtils::CandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
55  pfCandidate_vertex != pfCandidates_vertex.end(); ++pfCandidate_vertex ) {
56  revPfCandToVtxAssoc.insert(pfCandidate_vertex->first, std::make_pair(vertex, pfCandidate_vertex->second));
57  }
58  }
59 
60  return revPfCandToVtxAssoc;
61  }
62 
63  int
65  const noPuUtils::reversedPFCandToVertexAssMap& pfCandToVertexAssociations,
66  const reco::VertexCollection& vertices, double dZ,
67  int& numWarnings, int maxWarnings) {
68  int vtxAssociationType = noPuUtils::kNeutral;
69 
70  if ( pfCandidate->charge() != 0 ) {
71  vtxAssociationType = noPuUtils::kChNoAssoc;
72 
73  const noPuUtils::VertexQualityPairVector* pfCandAssocVtxs = nullptr;
74  noPuUtils::reversedPFCandToVertexAssMap::const_iterator itPfcToVtxAss = pfCandToVertexAssociations.find(pfCandidate);
75  if ( itPfcToVtxAss != pfCandToVertexAssociations.end() ) {
76  pfCandAssocVtxs = &itPfcToVtxAss->val;
77  } else {
78  for ( noPuUtils::reversedPFCandToVertexAssMap::const_iterator pfcToVtxAssoc = pfCandToVertexAssociations.begin();
79  pfcToVtxAssoc != pfCandToVertexAssociations.end(); ++pfcToVtxAssoc ) {
80  if ( deltaR2(pfCandidate->p4(), pfcToVtxAssoc->key->p4()) < dR2Min ) {
81  pfCandAssocVtxs = &pfcToVtxAssoc->val;
82  break;
83  }
84  }
85  }
86  if ( pfCandAssocVtxs!=nullptr ) {
87  for ( noPuUtils::VertexQualityPairVector::const_iterator pfcAssVtx = pfCandAssocVtxs->begin();
88  pfcAssVtx != pfCandAssocVtxs->end(); ++pfcAssVtx ) {
89  double z = pfcAssVtx->first->position().z();
90  int quality = pfcAssVtx->second;
91  promoteAssocToHSAssoc( quality, z, vertices, dZ, vtxAssociationType, false);
92  }
93  }
94  }
95 
96  return vtxAssociationType;
97  }
98 
100  double dZ, int& vtxAssociationType, bool checkdR2) {
101 
102  if ( quality >= noPuUtils::kChHSAssoc ) {
103  for ( reco::VertexCollection::const_iterator vertex = vertices.begin();
104  vertex != vertices.end(); ++vertex ) {
105 
106  if ( std::abs( z - vertex->position().z()) < dZ ) {
107  if ( vtxAssociationType < noPuUtils::kChHSAssoc ) vtxAssociationType = noPuUtils::kChHSAssoc;
108  }
109  }
110  }
111 
112  }
113 
114 }
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
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
noPuUtils::reversedPFCandToVertexAssMap reversePFCandToVertexAssociation(const PFCandToVertexAssMap &)
key_type key() const
Accessor for product key.
Definition: Ref.h:264
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< std::pair< reco::PFCandidateRef, int > > CandQualityPairVector
const double dR2Min
int isVertexAssociated(const reco::PFCandidatePtr &, const PFCandToVertexAssMap &, const reco::VertexCollection &, double)
void promoteAssocToHSAssoc(int quality, double z, const reco::VertexCollection &vertices, double dZ, int &vtxAssociationType, bool checkdR2)
void insert(const key_type &k, const data_type &v)
insert an association
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
std::vector< std::pair< reco::VertexRef, int > > VertexQualityPairVector
int isVertexAssociated_fast(const reco::PFCandidateRef &, const noPuUtils::reversedPFCandToVertexAssMap &, const reco::VertexCollection &, double, int &, int)
const_iterator begin() const
first iterator over the map (read only)