CMS 3D CMS Logo

PackedPFCandidateRefMixer.cc
Go to the documentation of this file.
1 
20 
21 namespace pat {
23  public:
24  explicit PackedPFCandidateRefMixer(const edm::ParameterSet& iConfig);
26 
27  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
28 
29  private:
32  std::vector<edm::EDGetTokenT<edm::Association<pat::PackedCandidateCollection>>> pf2pcs_;
33  };
34 
35 } // namespace pat
36 
38  : pf_(consumes<std::vector<reco::PFCandidate>>(iConfig.getParameter<edm::InputTag>("pf"))),
39  pf2pf_(consumes<edm::ValueMap<reco::PFCandidateRef>>(iConfig.getParameter<edm::InputTag>("pf2pf"))) {
40  for (edm::InputTag const& tag : iConfig.getParameter<std::vector<edm::InputTag>>("pf2packed")) {
42  }
43  produces<edm::ValueMap<reco::CandidatePtr>>();
44 }
45 
49  std::vector<edm::Handle<edm::Association<pat::PackedCandidateCollection>>> pf2pcs(pf2pcs_.size());
50  iEvent.getByToken(pf_, pf);
51  iEvent.getByToken(pf2pf_, pf2pf);
52  for (unsigned int i = 0, n = pf2pcs.size(); i < n; ++i) {
53  iEvent.getByToken(pf2pcs_[i], pf2pcs[i]);
54  }
55  std::vector<reco::CandidatePtr> outptrs;
56  outptrs.reserve(pf->size());
57  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
58  reco::PFCandidateRef oldpfRef(pf, i);
59  const auto& newpfRef = (*pf2pf)[oldpfRef];
60  bool found = false;
61  for (const auto& pf2pc : pf2pcs) {
62  if (pf2pc->contains(newpfRef.id())) {
63  outptrs.push_back(refToPtr((*pf2pc)[newpfRef]));
64  found = true;
65  break;
66  }
67  }
68  if (!found) {
69  edm::LogPrint("PackedPFCandidateRefMixer") << "oldpfRef: " << oldpfRef.id() << " / " << oldpfRef.key() << "\n";
70  edm::LogPrint("PackedPFCandidateRefMixer") << "newpfRef: " << newpfRef.id() << " / " << newpfRef.key() << "\n";
71  edm::LogPrint("PackedPFCandidateRefMixer") << "and I have " << pf2pcs.size() << " rekey maps."
72  << "\n";
73  for (const auto& pf2pc : pf2pcs) {
74  edm::LogPrint("PackedPFCandidateRefMixer") << "this map has keys in: "
75  << "\n";
76  for (const auto& pair : pf2pc->ids()) {
77  edm::LogPrint("PackedPFCandidateRefMixer") << "\t" << pair.first << "\n";
78  }
79  }
80  throw cms::Exception("LogicError") << "A packed candidate has refs that we don't understand\n";
81  }
82  }
83  std::unique_ptr<edm::ValueMap<reco::CandidatePtr>> out(new edm::ValueMap<reco::CandidatePtr>());
85  filler.insert(pf, outptrs.begin(), outptrs.end());
86  filler.fill();
87  iEvent.put(std::move(out));
88 }
89 
91 using namespace pat;
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
key_type key() const
Accessor for product key.
Definition: Ref.h:250
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< std::vector< reco::PFCandidate > > pf_
Log< level::Warning, true > LogPrint
edm::EDGetTokenT< edm::ValueMap< reco::PFCandidateRef > > pf2pf_
PackedPFCandidateRefMixer(const edm::ParameterSet &iConfig)
fixed size matrix
HLT enums.
std::vector< edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > > pf2pcs_
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:58
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
def move(src, dest)
Definition: eostools.py:511