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;
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PFCandidate.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
Association.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref< PFCandidateCollection >
edm::refToPtr
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
pfElectronTranslator_cfi.PFCandidate
PFCandidate
Definition: pfElectronTranslator_cfi.py:6
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
l1t::PFCandidateRef
edm::Ref< l1t::PFCandidateCollection > PFCandidateRef
Definition: PFCandidate.h:58
packedPFCandidateRefMixer_cfi.pf2pf
pf2pf
Definition: packedPFCandidateRefMixer_cfi.py:5
pat::PackedPFCandidateRefMixer::PackedPFCandidateRefMixer
PackedPFCandidateRefMixer(const edm::ParameterSet &iConfig)
Definition: PackedPFCandidateRefMixer.cc:37
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
PackedCandidate.h
pat::PackedPFCandidateRefMixer::~PackedPFCandidateRefMixer
~PackedPFCandidateRefMixer() override
Definition: PackedPFCandidateRefMixer.cc:25
pat::PackedPFCandidateRefMixer
Definition: PackedPFCandidateRefMixer.cc:22
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::Association
Definition: Association.h:18
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
pat::PackedPFCandidateRefMixer::pf_
edm::EDGetTokenT< std::vector< reco::PFCandidate > > pf_
Definition: PackedPFCandidateRefMixer.cc:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
packedPFCandidateRefMixer_cfi.pf
pf
Definition: packedPFCandidateRefMixer_cfi.py:4
edm::ValueMap
Definition: ValueMap.h:107
Exception
Definition: hltDiff.cc:245
pat::PackedPFCandidateRefMixer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: PackedPFCandidateRefMixer.cc:46
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
pat::PackedPFCandidateRefMixer::pf2pf_
edm::EDGetTokenT< edm::ValueMap< reco::PFCandidateRef > > pf2pf_
Definition: PackedPFCandidateRefMixer.cc:31
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
edm::helper::Filler
Definition: ValueMap.h:22
ParameterSet.h
edm::Event
Definition: Event.h:73
pat::PackedPFCandidateRefMixer::pf2pcs_
std::vector< edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > > pf2pcs_
Definition: PackedPFCandidateRefMixer.cc:32
edm::InputTag
Definition: InputTag.h:15
PFCandidateFwd.h