CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTauTag/RecoTau/src/RecoTauCommonUtilities.cc

Go to the documentation of this file.
00001 #include "RecoTauTag/RecoTau/interface/RecoTauCommonUtilities.h"
00002 
00003 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00004 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00005 #include "DataFormats/JetReco/interface/PFJet.h"
00006 #include "DataFormats/VertexReco/interface/Vertex.h"
00007 
00008 #include <algorithm>
00009 
00010 typedef std::vector<reco::PFCandidatePtr> PFCandPtrs;
00011 typedef PFCandPtrs::iterator PFCandIter;
00012 
00013 namespace reco { namespace tau {
00014 
00015 std::vector<PFCandidatePtr>
00016 flattenPiZeros( const std::vector<RecoTauPiZero>& piZeros) {
00017   std::vector<PFCandidatePtr> output;
00018 
00019   for(std::vector<RecoTauPiZero>::const_iterator piZero = piZeros.begin();
00020       piZero != piZeros.end(); ++piZero) {
00021     for(size_t iDaughter = 0; iDaughter < piZero->numberOfDaughters();
00022         ++iDaughter) {
00023       output.push_back(PFCandidatePtr(piZero->daughterPtr(iDaughter)));
00024     }
00025   }
00026   return output;
00027 }
00028 
00029 std::vector<reco::PFCandidatePtr> pfCandidates(const reco::PFJet& jet,
00030     int particleId, bool sort) {
00031   PFCandPtrs pfCands = jet.getPFConstituents();
00032   PFCandPtrs selectedPFCands = filterPFCandidates(
00033       pfCands.begin(), pfCands.end(), particleId, sort);
00034   return selectedPFCands;
00035 }
00036 
00037 std::vector<reco::PFCandidatePtr> pfCandidates(const reco::PFJet& jet,
00038     const std::vector<int>& particleIds, bool sort) {
00039   PFCandPtrs output;
00040   // Get each desired candidate type, unsorted for now
00041   for(std::vector<int>::const_iterator particleId = particleIds.begin();
00042       particleId != particleIds.end(); ++particleId) {
00043     PFCandPtrs selectedPFCands = pfCandidates(jet, *particleId, false);
00044     output.insert(output.end(), selectedPFCands.begin(), selectedPFCands.end());
00045   }
00046   if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
00047   return output;
00048 }
00049 
00050 std::vector<reco::PFCandidatePtr> pfGammas(const reco::PFJet& jet, bool sort) {
00051   return pfCandidates(jet, reco::PFCandidate::gamma, sort);
00052 }
00053 
00054 std::vector<reco::PFCandidatePtr> pfChargedCands(const reco::PFJet& jet,
00055                                                  bool sort) {
00056   PFCandPtrs output;
00057   PFCandPtrs mus = pfCandidates(jet, reco::PFCandidate::mu, false);
00058   PFCandPtrs es = pfCandidates(jet, reco::PFCandidate::e, false);
00059   PFCandPtrs chs = pfCandidates(jet, reco::PFCandidate::h, false);
00060   output.reserve(mus.size() + es.size() + chs.size());
00061   output.insert(output.end(), mus.begin(), mus.end());
00062   output.insert(output.end(), es.begin(), es.end());
00063   output.insert(output.end(), chs.begin(), chs.end());
00064   if (sort) std::sort(output.begin(), output.end(), SortPFCandsDescendingPt());
00065   return output;
00066 }
00067 
00068 
00069 
00070 } }