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  virtual 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
36 
37 
39  pf_(consumes<std::vector<reco::PFCandidate>>(iConfig.getParameter<edm::InputTag>("pf"))),
40  pf2pf_(consumes<edm::ValueMap<reco::PFCandidateRef>>(iConfig.getParameter<edm::InputTag>("pf2pf")))
41 {
42  for (edm::InputTag const& tag : iConfig.getParameter<std::vector<edm::InputTag>>("pf2packed")) {
44  }
45  produces<edm::ValueMap<reco::CandidatePtr>>();
46 }
47 
48 
49 void
53  std::vector<edm::Handle<edm::Association<pat::PackedCandidateCollection>>> pf2pcs(pf2pcs_.size());
54  iEvent.getByToken(pf_, pf);
55  iEvent.getByToken(pf2pf_, pf2pf);
56  for (unsigned int i = 0, n = pf2pcs.size(); i < n; ++i) {
57  iEvent.getByToken(pf2pcs_[i], pf2pcs[i]);
58  }
59  std::vector<reco::CandidatePtr> outptrs;
60  outptrs.reserve(pf->size());
61  for (unsigned int i = 0, n = pf->size(); i < n; ++i) {
62  reco::PFCandidateRef oldpfRef(pf, i);
63  const auto & newpfRef = (*pf2pf)[oldpfRef];
64  bool found = false;
65  for (const auto & pf2pc : pf2pcs) {
66  if (pf2pc->contains(newpfRef.id())) {
67  outptrs.push_back(refToPtr((*pf2pc)[newpfRef]));
68  found = true;
69  break;
70  }
71  }
72  if (!found) {
73  edm::LogPrint("PackedPFCandidateRefMixer") << "oldpfRef: " << oldpfRef.id() << " / " << oldpfRef.key() << "\n";
74  edm::LogPrint("PackedPFCandidateRefMixer") << "newpfRef: " << newpfRef.id() << " / " << newpfRef.key() << "\n";
75  edm::LogPrint("PackedPFCandidateRefMixer") << "and I have " << pf2pcs.size() << " rekey maps." << "\n";
76  for (const auto & pf2pc : pf2pcs) {
77  edm::LogPrint("PackedPFCandidateRefMixer") << "this map has keys in: " << "\n";
78  for (const auto & pair : pf2pc->ids()) { edm::LogPrint("PackedPFCandidateRefMixer") << "\t" << pair.first << "\n"; }
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
key_type key() const
Accessor for product key.
Definition: Ref.h:265
ProductID id() const
Accessor for product ID.
Definition: Ref.h:259
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< std::vector< reco::PFCandidate > > pf_
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
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_
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
def move(src, dest)
Definition: eostools.py:510