Go to the documentation of this file.00001 #ifndef RecoTauTag_RecoTau_RecoTauCommonUtilities_h
00002 #define RecoTauTag_RecoTau_RecoTauCommonUtilities_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00014 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00015 #include "DataFormats/TauReco/interface/PFTau.h"
00016 #include <vector>
00017 #include <algorithm>
00018 #include <numeric>
00019
00020
00021 #include <boost/iterator/transform_iterator.hpp>
00022 #include <boost/iterator/indirect_iterator.hpp>
00023 #include <boost/mem_fn.hpp>
00024
00025 #include <boost/type_traits/is_base_of.hpp>
00026 #include <boost/static_assert.hpp>
00027
00028 namespace reco { namespace tau {
00029
00032 std::vector<PFCandidatePtr> pfCandidates(const PFJet& jet,
00033 int particleId, bool sort=true);
00034
00036 std::vector<PFCandidatePtr> pfCandidates(const PFJet& jet,
00037 const std::vector<int>& particleIds,
00038 bool sort=true);
00039
00041 std::vector<PFCandidatePtr> pfChargedCands(const PFJet& jet, bool sort=true);
00042
00044 std::vector<PFCandidatePtr> pfGammas(const PFJet& jet, bool sort=true);
00045
00047 std::vector<PFCandidatePtr> flattenPiZeros(const std::vector<RecoTauPiZero>&);
00048
00050 template<typename RefVectorType, typename BaseView>
00051 RefVectorType castView(const edm::Handle<BaseView>& view) {
00052 typedef typename RefVectorType::value_type OutputRef;
00053
00054
00055 BOOST_STATIC_ASSERT(
00056 (boost::is_base_of<typename BaseView::value_type,
00057 typename RefVectorType::member_type>::value));
00058 RefVectorType output;
00059 size_t nElements = view->size();
00060 output.reserve(nElements);
00061
00062 for (size_t i = 0; i < nElements; ++i) {
00063 output.push_back(view->refAt(i).template castTo<OutputRef>());
00064 }
00065 return output;
00066 }
00067
00068
00069
00070
00071
00072
00073 template<typename InputIterator> InputIterator takeNElements(
00074 const InputIterator& begin, const InputIterator& end, size_t N) {
00075 size_t input_size = end - begin;
00076 return (N > input_size) ? end : begin + N;
00077 }
00078
00080 template<typename InputIterator, typename FunctionPtr, typename ReturnType>
00081 ReturnType sumPFVector(InputIterator begin, InputIterator end,
00082 FunctionPtr func, ReturnType init) {
00083 ReturnType output = init;
00084 for(InputIterator cand = begin; cand != end; ++cand) {
00085
00086 output += ((**cand).*(func))();
00087 }
00088 return output;
00089 }
00090
00091 template<typename InputIterator> reco::Candidate::LorentzVector sumPFCandP4(
00092 InputIterator begin, InputIterator end) {
00093 return sumPFVector(begin, end, &PFCandidate::p4,
00094 reco::Candidate::LorentzVector());
00095 }
00096
00098 template<typename InputIterator> double sumPFCandPt(InputIterator begin,
00099 InputIterator end) {
00100 return sumPFVector(begin, end, &PFCandidate::pt, 0.0);
00101 }
00102
00104 template<typename InputIterator> int sumPFCandCharge(InputIterator begin,
00105 InputIterator end) {
00106 return sumPFVector(begin, end, &PFCandidate::charge, 0);
00107 }
00108
00109 template<typename InputIterator> InputIterator leadPFCand(InputIterator begin,
00110 InputIterator end) {
00111 double max_pt = 0;
00112 InputIterator max_cand = begin;
00113 for(InputIterator cand = begin; cand != end; ++cand) {
00114 if( (*cand)->pt() > max_pt ) {
00115 max_pt = (*cand)->pt();
00116 max_cand = cand;
00117 }
00118 }
00119 return max_cand;
00120 }
00121 }}
00122 #endif