Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:13

0001 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
0002 
0003 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0004 #include "DataFormats/Candidate/interface/Candidate.h"
0005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0006 #include "DataFormats/JetReco/interface/Jet.h"
0007 #include "DataFormats/VertexReco/interface/Vertex.h"
0008 
0009 #include "CommonTools/BaseParticlePropagator/interface/BaseParticlePropagator.h"
0010 
0011 #include <algorithm>
0012 
0013 typedef std::vector<reco::CandidatePtr> CandPtrs;
0014 typedef CandPtrs::iterator CandIter;
0015 
0016 namespace reco {
0017   namespace tau {
0018 
0019     namespace {
0020       // Re-implemented from PFCandidate.cc
0021       int translateTypeToAbsPdgId(int type) {
0022         switch (type) {
0023           case reco::PFCandidate::h:
0024             return 211;  // pi+
0025           case reco::PFCandidate::e:
0026             return 11;
0027           case reco::PFCandidate::mu:
0028             return 13;
0029           case reco::PFCandidate::gamma:
0030             return 22;
0031           case reco::PFCandidate::h0:
0032             return 130;  // K_L0
0033           case reco::PFCandidate::h_HF:
0034             return 1;  // dummy pdg code
0035           case reco::PFCandidate::egamma_HF:
0036             return 2;  // dummy pdg code
0037           case reco::PFCandidate::X:
0038           default:
0039             return 0;
0040         }
0041       }
0042     }  // namespace
0043     std::vector<CandidatePtr> flattenPiZeros(const std::vector<RecoTauPiZero>::const_iterator& piZerosBegin,
0044                                              const std::vector<RecoTauPiZero>::const_iterator& piZerosEnd) {
0045       std::vector<CandidatePtr> output;
0046 
0047       for (std::vector<RecoTauPiZero>::const_iterator piZero = piZerosBegin; piZero != piZerosEnd; ++piZero) {
0048         for (size_t iDaughter = 0; iDaughter < piZero->numberOfDaughters(); ++iDaughter) {
0049           output.push_back(CandidatePtr(piZero->daughterPtr(iDaughter)));
0050         }
0051       }
0052       return output;
0053     }
0054 
0055     std::vector<CandidatePtr> flattenPiZeros(const std::vector<RecoTauPiZero>& piZeros) {
0056       return flattenPiZeros(piZeros.begin(), piZeros.end());
0057     }
0058 
0059     std::vector<reco::CandidatePtr> pfCandidates(const reco::Jet& jet, int particleId, bool sort) {
0060       return pfCandidatesByPdgId(jet, translateTypeToAbsPdgId(particleId), sort);
0061     }
0062 
0063     std::vector<CandidatePtr> pfCandidates(const Jet& jet, const std::vector<int>& particleIds, bool sort) {
0064       std::vector<int> pdgIds;
0065       pdgIds.reserve(particleIds.size());
0066       for (auto particleId : particleIds)
0067         pdgIds.push_back(translateTypeToAbsPdgId(particleId));
0068       return pfCandidatesByPdgId(jet, pdgIds, sort);
0069     }
0070 
0071     std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet, int pdgId, bool sort) {
0072       CandPtrs pfCands = jet.daughterPtrVector();
0073       CandPtrs selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), pdgId, sort);
0074       return selectedPFCands;
0075     }
0076 
0077     std::vector<reco::CandidatePtr> pfCandidatesByPdgId(const reco::Jet& jet,
0078                                                         const std::vector<int>& pdgIds,
0079                                                         bool sort) {
0080       const CandPtrs& pfCands = jet.daughterPtrVector();
0081       CandPtrs output;
0082       // Get each desired candidate type, unsorted for now
0083       for (std::vector<int>::const_iterator pdgId = pdgIds.begin(); pdgId != pdgIds.end(); ++pdgId) {
0084         CandPtrs&& selectedPFCands = filterPFCandidates(pfCands.begin(), pfCands.end(), *pdgId, false);
0085         output.insert(output.end(), selectedPFCands.begin(), selectedPFCands.end());
0086       }
0087       if (sort)
0088         std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
0089       return output;
0090     }
0091 
0092     std::vector<reco::CandidatePtr> pfGammas(const reco::Jet& jet, bool sort) { return pfCandidates(jet, 22, sort); }
0093 
0094     std::vector<reco::CandidatePtr> pfChargedCands(const reco::Jet& jet, bool sort) {
0095       const CandPtrs& pfCands = jet.daughterPtrVector();
0096       CandPtrs output;
0097       CandPtrs&& mus = filterPFCandidates(pfCands.begin(), pfCands.end(), 13, false);
0098       CandPtrs&& es = filterPFCandidates(pfCands.begin(), pfCands.end(), 11, false);
0099       CandPtrs&& chs = filterPFCandidates(pfCands.begin(), pfCands.end(), 211, false);
0100       output.reserve(mus.size() + es.size() + chs.size());
0101       output.insert(output.end(), mus.begin(), mus.end());
0102       output.insert(output.end(), es.begin(), es.end());
0103       output.insert(output.end(), chs.begin(), chs.end());
0104       if (sort)
0105         std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
0106       return output;
0107     }
0108 
0109     math::XYZPointF atECALEntrance(const reco::Candidate* part, double bField) {
0110       const reco::PFCandidate* pfCand = dynamic_cast<const reco::PFCandidate*>(part);
0111       if (pfCand)
0112         return pfCand->positionAtECALEntrance();
0113 
0114       math::XYZPointF pos;
0115       BaseParticlePropagator theParticle = BaseParticlePropagator(
0116           RawParticle(math::XYZTLorentzVector(part->px(), part->py(), part->pz(), part->energy()),
0117                       math::XYZTLorentzVector(part->vertex().x(), part->vertex().y(), part->vertex().z(), 0.)),
0118           part->charge(),
0119           0.,
0120           0.,
0121           bField);
0122       theParticle.propagateToEcalEntrance(false);
0123       if (theParticle.getSuccess() != 0) {
0124         pos = math::XYZPointF(theParticle.particle().vertex());
0125       }
0126       return pos;
0127     }
0128 
0129   }  // namespace tau
0130 }  // namespace reco