![]() |
![]() |
00001 #ifndef CommonTools_CandUtils_CompositeCandSelector_h 00002 #define CommonTools_CandUtils_CompositeCandSelector_h 00003 #include "DataFormats/Candidate/interface/Candidate.h" 00004 #include "FWCore/Utilities/interface/EDMException.h" 00005 00006 template<typename Selector, typename T1 = reco::Candidate, typename T2 = T1, unsigned int nDau = 2> 00007 class CompositeCandSelector { 00008 public: 00009 explicit CompositeCandSelector(const Selector& select) : select_(select) { } 00010 bool operator()(const reco::Candidate & cmp) const { 00011 if(cmp.numberOfDaughters() != nDau) 00012 throw edm::Exception(edm::errors::InvalidReference) 00013 << "candidate has " << cmp.numberOfDaughters() 00014 << ", while CompositeCandSelector " 00015 << "requires " << nDau << " daughters.\n"; 00016 const T1 * dau1 = dynamic_cast<const T1 *>(cmp.daughter(0)); 00017 if(dau1 == 0) 00018 throw edm::Exception(edm::errors::InvalidReference) 00019 << "candidate's first daughter is not of the type required " 00020 << "by CompositeCandSelector.\n"; 00021 const T2 * dau2 = dynamic_cast<const T2 *>(cmp.daughter(1)); 00022 if(dau2 == 0) 00023 throw edm::Exception(edm::errors::InvalidReference) 00024 << "candidate's second daughter is not of the type required " 00025 << "by CompositeCandSelector.\n"; 00026 return select_(*dau1, *dau2); 00027 } 00028 private: 00029 Selector select_; 00030 }; 00031 00032 // specializations for nDau = 3, 4, ... could go here if needed 00033 00034 #endif