CMS 3D CMS Logo

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,
14  double dZ) {
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();
21  ++pfCandToVertexAssociation) {
22  const noPuUtils::CandQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
23 
24  for (noPuUtils::CandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
25  pfCandidate_vertex != pfCandidates_vertex.end();
26  ++pfCandidate_vertex) {
27  const reco::PFCandidatePtr pfcVtx = edm::refToPtr(pfCandidate_vertex->first); //<reco::PFCandidatePtr>
28  //std::cout<<pfCandidate<<" "<<test<<std::endl;
29 
30  if (pfCandidate != pfcVtx)
31  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  const PFCandToVertexAssMap& pfCandToVertexAssociations) {
46  noPuUtils::reversedPFCandToVertexAssMap revPfCandToVtxAssoc;
47 
48  for (PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
49  pfCandToVertexAssociation != pfCandToVertexAssociations.end();
50  ++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();
56  ++pfCandidate_vertex) {
57  revPfCandToVtxAssoc.insert(pfCandidate_vertex->first, std::make_pair(vertex, pfCandidate_vertex->second));
58  }
59  }
60 
61  return revPfCandToVtxAssoc;
62  }
63 
65  const noPuUtils::reversedPFCandToVertexAssMap& pfCandToVertexAssociations,
67  double dZ,
68  int& numWarnings,
69  int maxWarnings) {
70  int vtxAssociationType = noPuUtils::kNeutral;
71 
72  if (pfCandidate->charge() != 0) {
73  vtxAssociationType = noPuUtils::kChNoAssoc;
74 
75  const noPuUtils::VertexQualityPairVector* pfCandAssocVtxs = nullptr;
77  pfCandToVertexAssociations.find(pfCandidate);
78  if (itPfcToVtxAss != pfCandToVertexAssociations.end()) {
79  pfCandAssocVtxs = &itPfcToVtxAss->val;
80  } else {
81  for (noPuUtils::reversedPFCandToVertexAssMap::const_iterator pfcToVtxAssoc = pfCandToVertexAssociations.begin();
82  pfcToVtxAssoc != pfCandToVertexAssociations.end();
83  ++pfcToVtxAssoc) {
84  if (deltaR2(pfCandidate->p4(), pfcToVtxAssoc->key->p4()) < dR2Min) {
85  pfCandAssocVtxs = &pfcToVtxAssoc->val;
86  break;
87  }
88  }
89  }
90  if (pfCandAssocVtxs != nullptr) {
91  for (noPuUtils::VertexQualityPairVector::const_iterator pfcAssVtx = pfCandAssocVtxs->begin();
92  pfcAssVtx != pfCandAssocVtxs->end();
93  ++pfcAssVtx) {
94  double z = pfcAssVtx->first->position().z();
95  int quality = pfcAssVtx->second;
96  promoteAssocToHSAssoc(quality, z, vertices, dZ, vtxAssociationType, false);
97  }
98  }
99  }
100 
101  return vtxAssociationType;
102  }
103 
105  double z,
107  double dZ,
108  int& vtxAssociationType,
109  bool checkdR2) {
111  for (reco::VertexCollection::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) {
112  if (std::abs(z - vertex->position().z()) < dZ) {
113  if (vtxAssociationType < noPuUtils::kChHSAssoc)
114  vtxAssociationType = noPuUtils::kChHSAssoc;
115  }
116  }
117  }
118  }
119 
120 } // namespace noPuUtils
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
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:244
const_iterator find(const key_type &k) const
find element with specified reference key
const_iterator end() const
last iterator over the map (read only)
string quality
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
std::vector< std::pair< reco::VertexRef, int > > VertexQualityPairVector
const_iterator begin() const
first iterator over the map (read only)
int isVertexAssociated_fast(const reco::PFCandidateRef &, const noPuUtils::reversedPFCandToVertexAssMap &, const reco::VertexCollection &, double, int &, int)