File indexing completed on 2024-04-06 12:24:08
0001 #include <memory>
0002
0003 #include "DataFormats/Common/interface/Handle.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "PhysicsTools/RecoAlgos/interface/MassKinFitterCandProducer.h"
0008
0009 MassKinFitterCandProducer::MassKinFitterCandProducer(const edm::ParameterSet& cfg, CandMassKinFitter* f)
0010 : srcToken_(consumes<reco::CandidateCollection>(cfg.getParameter<edm::InputTag>("src"))), fitter_(f) {
0011 if (f == nullptr)
0012 fitter_ = std::make_unique<CandMassKinFitter>(cfg.getParameter<double>("mass"));
0013 produces<reco::CandidateCollection>();
0014 }
0015
0016 void MassKinFitterCandProducer::produce(edm::Event& evt, const edm::EventSetup& es) {
0017 using namespace edm;
0018 using namespace reco;
0019 Handle<CandidateCollection> cands;
0020 evt.getByToken(srcToken_, cands);
0021 auto refitted = std::make_unique<CandidateCollection>();
0022 for (CandidateCollection::const_iterator c = cands->begin(); c != cands->end(); ++c) {
0023 Candidate* clone = c->clone();
0024 fitter_->set(*clone);
0025 refitted->push_back(clone);
0026 }
0027 evt.put(std::move(refitted));
0028 }