Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:20:15

0001 #include "RecoMET/METPUSubtraction/interface/NoPileUpMEtAuxFunctions.h"
0002 
0003 #include "DataFormats/Math/interface/deltaR.h"
0004 #include "DataFormats/Common/interface/RefToPtr.h"
0005 
0006 #include <cmath>
0007 
0008 namespace noPuUtils {
0009   const double dR2Min = 0.01 * 0.01;
0010 
0011   int isVertexAssociated(const reco::PFCandidatePtr& pfCandidate,
0012                          const PFCandToVertexAssMap& pfCandToVertexAssociations,
0013                          const reco::VertexCollection& vertices,
0014                          double dZ) {
0015     int vtxAssociationType = noPuUtils::kNeutral;
0016 
0017     if (pfCandidate->charge() != 0) {
0018       vtxAssociationType = noPuUtils::kChNoAssoc;
0019       for (PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
0020            pfCandToVertexAssociation != pfCandToVertexAssociations.end();
0021            ++pfCandToVertexAssociation) {
0022         const noPuUtils::CandQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
0023 
0024         for (noPuUtils::CandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
0025              pfCandidate_vertex != pfCandidates_vertex.end();
0026              ++pfCandidate_vertex) {
0027           const reco::PFCandidatePtr pfcVtx = edm::refToPtr(pfCandidate_vertex->first);  //<reco::PFCandidatePtr>
0028           //std::cout<<pfCandidate<<"   "<<test<<std::endl;
0029 
0030           if (pfCandidate != pfcVtx)
0031             continue;  //std::cout<<" pouet "<<pfCandidate<<"  "<<test<<std::endl;
0032 
0033           //if(deltaR2(pfCandidate->p4(), pfCandidate_vertex->first->p4()) > dR2Min ) continue;
0034           double z = pfCandToVertexAssociation->key->position().z();
0035           int quality = pfCandidate_vertex->second;
0036           promoteAssocToHSAssoc(quality, z, vertices, dZ, vtxAssociationType, false);
0037         }
0038       }
0039     }
0040 
0041     return vtxAssociationType;
0042   }
0043 
0044   noPuUtils::reversedPFCandToVertexAssMap reversePFCandToVertexAssociation(
0045       const PFCandToVertexAssMap& pfCandToVertexAssociations) {
0046     noPuUtils::reversedPFCandToVertexAssMap revPfCandToVtxAssoc;
0047 
0048     for (PFCandToVertexAssMap::const_iterator pfCandToVertexAssociation = pfCandToVertexAssociations.begin();
0049          pfCandToVertexAssociation != pfCandToVertexAssociations.end();
0050          ++pfCandToVertexAssociation) {
0051       const reco::VertexRef& vertex = pfCandToVertexAssociation->key;
0052 
0053       const noPuUtils::CandQualityPairVector& pfCandidates_vertex = pfCandToVertexAssociation->val;
0054       for (noPuUtils::CandQualityPairVector::const_iterator pfCandidate_vertex = pfCandidates_vertex.begin();
0055            pfCandidate_vertex != pfCandidates_vertex.end();
0056            ++pfCandidate_vertex) {
0057         revPfCandToVtxAssoc.insert(pfCandidate_vertex->first, std::make_pair(vertex, pfCandidate_vertex->second));
0058       }
0059     }
0060 
0061     return revPfCandToVtxAssoc;
0062   }
0063 
0064   int isVertexAssociated_fast(const reco::PFCandidateRef& pfCandidate,
0065                               const noPuUtils::reversedPFCandToVertexAssMap& pfCandToVertexAssociations,
0066                               const reco::VertexCollection& vertices,
0067                               double dZ,
0068                               int& numWarnings,
0069                               int maxWarnings) {
0070     int vtxAssociationType = noPuUtils::kNeutral;
0071 
0072     if (pfCandidate->charge() != 0) {
0073       vtxAssociationType = noPuUtils::kChNoAssoc;
0074 
0075       const noPuUtils::VertexQualityPairVector* pfCandAssocVtxs = nullptr;
0076       noPuUtils::reversedPFCandToVertexAssMap::const_iterator itPfcToVtxAss =
0077           pfCandToVertexAssociations.find(pfCandidate);
0078       if (itPfcToVtxAss != pfCandToVertexAssociations.end()) {
0079         pfCandAssocVtxs = &itPfcToVtxAss->val;
0080       } else {
0081         for (noPuUtils::reversedPFCandToVertexAssMap::const_iterator pfcToVtxAssoc = pfCandToVertexAssociations.begin();
0082              pfcToVtxAssoc != pfCandToVertexAssociations.end();
0083              ++pfcToVtxAssoc) {
0084           if (deltaR2(pfCandidate->p4(), pfcToVtxAssoc->key->p4()) < dR2Min) {
0085             pfCandAssocVtxs = &pfcToVtxAssoc->val;
0086             break;
0087           }
0088         }
0089       }
0090       if (pfCandAssocVtxs != nullptr) {
0091         for (noPuUtils::VertexQualityPairVector::const_iterator pfcAssVtx = pfCandAssocVtxs->begin();
0092              pfcAssVtx != pfCandAssocVtxs->end();
0093              ++pfcAssVtx) {
0094           double z = pfcAssVtx->first->position().z();
0095           int quality = pfcAssVtx->second;
0096           promoteAssocToHSAssoc(quality, z, vertices, dZ, vtxAssociationType, false);
0097         }
0098       }
0099     }
0100 
0101     return vtxAssociationType;
0102   }
0103 
0104   void promoteAssocToHSAssoc(int quality,
0105                              double z,
0106                              const reco::VertexCollection& vertices,
0107                              double dZ,
0108                              int& vtxAssociationType,
0109                              bool checkdR2) {
0110     if (quality >= noPuUtils::kChHSAssoc) {
0111       for (reco::VertexCollection::const_iterator vertex = vertices.begin(); vertex != vertices.end(); ++vertex) {
0112         if (std::abs(z - vertex->position().z()) < dZ) {
0113           if (vtxAssociationType < noPuUtils::kChHSAssoc)
0114             vtxAssociationType = noPuUtils::kChHSAssoc;
0115         }
0116       }
0117     }
0118   }
0119 
0120 }  // namespace noPuUtils