File indexing completed on 2023-10-25 09:57:47
0001 #ifndef HepMCCandAlgos_MCTruthPairSelector_h
0002 #define HepMCCandAlgos_MCTruthPairSelector_h
0003
0004
0005
0006
0007
0008
0009 #include <set>
0010 #include "DataFormats/Candidate/interface/Candidate.h"
0011
0012 namespace helpers {
0013 template <typename T>
0014 struct MCTruthPairSelector {
0015 MCTruthPairSelector(bool checkCharge = false) : checkCharge_(checkCharge) {}
0016 template <typename I>
0017 MCTruthPairSelector(const I& begin, const I& end, bool checkCharge = false) : checkCharge_(checkCharge) {
0018 for (I i = begin; i != end; ++i)
0019 matchIds_.insert(std::abs(*i));
0020 }
0021 bool operator()(const T& c, const reco::Candidate& mc) const {
0022 if (mc.status() != 1)
0023 return false;
0024 if (checkCharge_ && c.charge() != mc.charge())
0025 return false;
0026 if (matchIds_.empty())
0027 return true;
0028 return matchIds_.find(std::abs(mc.pdgId())) != matchIds_.end();
0029 }
0030
0031 private:
0032 std::set<int> matchIds_;
0033 bool checkCharge_;
0034 };
0035 }
0036
0037 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
0038 #include <algorithm>
0039 #include <string>
0040 #include <vector>
0041
0042 namespace reco {
0043 namespace modules {
0044
0045 template <typename T>
0046 struct ParameterAdapter<helpers::MCTruthPairSelector<T> > {
0047 static helpers::MCTruthPairSelector<T> make(const edm::ParameterSet& cfg) {
0048 const std::string matchPDGId("matchPDGId");
0049 const std::string checkCharge("checkCharge");
0050 bool ck = false;
0051 std::vector<std::string> bools = cfg.template getParameterNamesForType<bool>();
0052 bool found = find(bools.begin(), bools.end(), checkCharge) != bools.end();
0053 if (found)
0054 ck = cfg.template getParameter<bool>(checkCharge);
0055 typedef std::vector<int> vint;
0056 std::vector<std::string> ints = cfg.template getParameterNamesForType<vint>();
0057 found = find(ints.begin(), ints.end(), matchPDGId) != ints.end();
0058 if (found) {
0059 vint ids = cfg.template getParameter<vint>(matchPDGId);
0060 return helpers::MCTruthPairSelector<T>(ids.begin(), ids.end(), ck);
0061 } else {
0062 return helpers::MCTruthPairSelector<T>(ck);
0063 }
0064 }
0065 };
0066
0067 }
0068 }
0069
0070 #endif