Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need for GsfElectronCoreBaseProducer and merging .h and .cc files for EgammaElectronProducers #28746

Merged
merged 4 commits into from Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,56 +1,61 @@

#include "GEDGsfElectronCoreProducer.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
#include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing these include's? Are you relying on them being included through GsfElectronCore.h?
I would personally further add GsfTrackFwd.h, for completeness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, correct me if I'm wrong, but I think these *Fwd.h are not meant to be included in *.cc files, and that's why I removed them. Indeed, I'm relying here on the indirect include via GsfElectronCore.h which I think is fine because the *Track objects in this producer are only used as arguments for GsfElectronCore constructors or member functions, so we can rely on GsfElectronCore.h to have the good typedefs imported to use it's own functions. Is that OK for you?

#include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/Common/interface/ValueMap.h"

#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtra.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/GsfElectronTools.h"

class GEDGsfElectronCoreProducer : public edm::global::EDProducer<> {
public:
static void fillDescriptions(edm::ConfigurationDescriptions &);

explicit GEDGsfElectronCoreProducer(const edm::ParameterSet &conf);
void produce(edm::StreamID iStream, edm::Event &, const edm::EventSetup &) const override;

#include <map>
private:
void produceElectronCore(const reco::PFCandidate &pfCandidate,
reco::GsfElectronCoreCollection &electrons,
edm::Handle<reco::TrackCollection> const &ctfTracksHandle) const;

const edm::EDGetTokenT<reco::TrackCollection> ctfTracksToken_;
const edm::EDGetTokenT<reco::PFCandidateCollection> gedEMUnbiasedToken_;
const edm::EDPutTokenT<reco::GsfElectronCoreCollection> putToken_;
};

using namespace reco;

void GEDGsfElectronCoreProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
edm::ParameterSetDescription desc;
GsfElectronCoreBaseProducer::fillDescription(desc);
desc.add<edm::InputTag>("GEDEMUnbiased", edm::InputTag("particleFlowEGamma"));
desc.add<edm::InputTag>("ctfTracks", {"generalTracks"});
desc.add<edm::InputTag>("GEDEMUnbiased", {"particleFlowEGamma"});
descriptions.add("gedGsfElectronCores", desc);
}

GEDGsfElectronCoreProducer::GEDGsfElectronCoreProducer(const edm::ParameterSet &config)
: GsfElectronCoreBaseProducer(config) {
gedEMUnbiasedTag_ = consumes<reco::PFCandidateCollection>(config.getParameter<edm::InputTag>("GEDEMUnbiased"));
}

void GEDGsfElectronCoreProducer::produce(edm::Event &event, const edm::EventSetup &setup) {
// base input
GsfElectronCoreBaseProducer::initEvent(event, setup);
: ctfTracksToken_(consumes<reco::TrackCollection>(config.getParameter<edm::InputTag>("ctfTracks"))),
gedEMUnbiasedToken_(consumes<reco::PFCandidateCollection>(config.getParameter<edm::InputTag>("GEDEMUnbiased"))),
putToken_(produces<reco::GsfElectronCoreCollection>()) {}

edm::Handle<reco::PFCandidateCollection> gedEMUnbiasedH_;
event.getByToken(gedEMUnbiasedTag_, gedEMUnbiasedH_);
void GEDGsfElectronCoreProducer::produce(edm::StreamID iStream, edm::Event &event, const edm::EventSetup &setup) const {
auto ctfTracksHandle = event.getHandle(ctfTracksToken_);

// output
auto electrons = std::make_unique<GsfElectronCoreCollection>();
reco::GsfElectronCoreCollection electrons;

const PFCandidateCollection *pfCandidateCollection = gedEMUnbiasedH_.product();
for (unsigned int i = 0; i < pfCandidateCollection->size(); ++i)
produceElectronCore((*pfCandidateCollection)[i], electrons.get());
for (auto const &pfCand : event.get(gedEMUnbiasedToken_)) {
produceElectronCore(pfCand, electrons, ctfTracksHandle);
}

event.put(std::move(electrons));
event.emplace(putToken_, std::move(electrons));
}

void GEDGsfElectronCoreProducer::produceElectronCore(const reco::PFCandidate &pfCandidate,
reco::GsfElectronCoreCollection *electrons) {
reco::GsfElectronCoreCollection &electrons,
edm::Handle<reco::TrackCollection> const &ctfTracksHandle) const {
const GsfTrackRef gsfTrackRef = pfCandidate.gsfTrackRef();
if (gsfTrackRef.isNull())
return;
Expand All @@ -59,29 +64,32 @@ void GEDGsfElectronCoreProducer::produceElectronCore(const reco::PFCandidate &pf
if (extraRef.isNull())
return;

GsfElectronCore *eleCore = new GsfElectronCore(gsfTrackRef);
electrons.emplace_back(gsfTrackRef);
auto &eleCore = electrons.back();

GsfElectronCoreBaseProducer::fillElectronCore(eleCore);
auto ctfpair = egamma::getClosestCtfToGsf(eleCore.gsfTrack(), ctfTracksHandle);
eleCore.setCtfTrack(ctfpair.first, ctfpair.second);

SuperClusterRef scRef = extraRef->superClusterRef();
SuperClusterRef scBoxRef = extraRef->superClusterPFECALRef();

for (const auto &convref : extraRef->conversionRef()) {
eleCore->addConversion(convref);
eleCore.addConversion(convref);
}

for (const auto &convref : extraRef->singleLegConversionRef()) {
eleCore->addOneLegConversion(convref);
eleCore.addOneLegConversion(convref);
}

if (!scRef.isNull() || !scBoxRef.isNull()) {
eleCore->setSuperCluster(scRef);
eleCore->setParentSuperCluster(scBoxRef);
electrons->push_back(*eleCore);
eleCore.setSuperCluster(scRef);
eleCore.setParentSuperCluster(scBoxRef);
} else {
electrons.pop_back();
edm::LogWarning("GEDGsfElectronCoreProducer")
<< "Both superClusterRef and superClusterBoxRef of pfCandidate.egammaExtraRef() are Null";
}

delete eleCore;
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(GEDGsfElectronCoreProducer);

This file was deleted.

107 changes: 53 additions & 54 deletions RecoEgamma/EgammaElectronProducers/plugins/GEDGsfElectronFinalizer.cc
@@ -1,56 +1,58 @@
#include "RecoEgamma/EgammaElectronProducers/plugins/GEDGsfElectronFinalizer.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "CommonTools/CandAlgos/interface/ModifyObjectValueBase.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GsfElectronFwd.h is already correctly imported in GsfElectron.h and PFCandidateFwd.h is already correctly imported in PFCandidate.h.

#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
class GEDGsfElectronFinalizer : public edm::global::EDProducer<> {
public:
explicit GEDGsfElectronFinalizer(const edm::ParameterSet&);

#include <iostream>
#include <string>
void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;

using namespace reco;
private:
const edm::EDGetTokenT<reco::GsfElectronCollection> previousGsfElectrons_;
const edm::EDGetTokenT<reco::PFCandidateCollection> pfCandidates_;
std::vector<edm::EDGetTokenT<edm::ValueMap<float> > > tokenElectronIsoVals_;
std::unique_ptr<ModifyObjectValueBase> gedRegression_;

GEDGsfElectronFinalizer::GEDGsfElectronFinalizer(const edm::ParameterSet& cfg) {
previousGsfElectrons_ =
consumes<reco::GsfElectronCollection>(cfg.getParameter<edm::InputTag>("previousGsfElectronsTag"));
pfCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("pfCandidatesTag"));
outputCollectionLabel_ = cfg.getParameter<std::string>("outputCollectionLabel");
edm::ParameterSet pfIsoVals(cfg.getParameter<edm::ParameterSet>("pfIsolationValues"));
const edm::EDPutTokenT<reco::GsfElectronCollection> putToken_;
};

tokenElectronIsoVals_.push_back(
consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumChargedHadronPt")));
tokenElectronIsoVals_.push_back(
consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPhotonEt")));
tokenElectronIsoVals_.push_back(
consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumNeutralHadronEt")));
tokenElectronIsoVals_.push_back(consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumPUPt")));
tokenElectronIsoVals_.push_back(
consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumEcalClusterEt")));
tokenElectronIsoVals_.push_back(
consumes<edm::ValueMap<float> >(pfIsoVals.getParameter<edm::InputTag>("pfSumHcalClusterEt")));
using edm::InputTag;
using edm::ValueMap;

nDeps_ = tokenElectronIsoVals_.size();
using reco::GsfElectronCollection;

GEDGsfElectronFinalizer::GEDGsfElectronFinalizer(const edm::ParameterSet& cfg)
: previousGsfElectrons_(consumes<GsfElectronCollection>(cfg.getParameter<InputTag>("previousGsfElectronsTag"))),
pfCandidates_(consumes<reco::PFCandidateCollection>(cfg.getParameter<InputTag>("pfCandidatesTag"))),
putToken_{produces<reco::GsfElectronCollection>()} {
edm::ParameterSet pfIsoVals(cfg.getParameter<edm::ParameterSet>("pfIsolationValues"));

tokenElectronIsoVals_ = {consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumChargedHadronPt")),
consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumPhotonEt")),
consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumNeutralHadronEt")),
consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumPUPt")),
consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumEcalClusterEt")),
consumes<ValueMap<float> >(pfIsoVals.getParameter<InputTag>("pfSumHcalClusterEt"))};

if (cfg.existsAs<edm::ParameterSet>("regressionConfig")) {
const edm::ParameterSet& iconf = cfg.getParameterSet("regressionConfig");
const std::string& mname = iconf.getParameter<std::string>("modifierName");
auto const& iconf = cfg.getParameterSet("regressionConfig");
auto const& mname = iconf.getParameter<std::string>("modifierName");
auto cc = consumesCollector();
gedRegression_ = ModifyObjectValueFactory::get()->create(mname, iconf, cc);
}

produces<reco::GsfElectronCollection>(outputCollectionLabel_);
}

GEDGsfElectronFinalizer::~GEDGsfElectronFinalizer() {}

// ------------ method called to produce the data ------------
void GEDGsfElectronFinalizer::produce(edm::Event& event, const edm::EventSetup& setup) {
void GEDGsfElectronFinalizer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
// Output collection
auto outputElectrons_p = std::make_unique<reco::GsfElectronCollection>();
reco::GsfElectronCollection outputElectrons;

if (gedRegression_) {
gedRegression_->setEvent(event);
Expand All @@ -59,28 +61,24 @@ void GEDGsfElectronFinalizer::produce(edm::Event& event, const edm::EventSetup&

// read input collections
// electrons
edm::Handle<reco::GsfElectronCollection> gedElectronHandle;
event.getByToken(previousGsfElectrons_, gedElectronHandle);
auto gedElectronHandle = event.getHandle(previousGsfElectrons_);

// PFCandidates
edm::Handle<reco::PFCandidateCollection> pfCandidateHandle;
event.getByToken(pfCandidates_, pfCandidateHandle);
auto pfCandidateHandle = event.getHandle(pfCandidates_);
// value maps
std::vector<edm::Handle<edm::ValueMap<float> > > isolationValueMaps(nDeps_);
std::vector<edm::ValueMap<float> const*> isolationValueMaps(tokenElectronIsoVals_.size());

for (unsigned i = 0; i < nDeps_; ++i) {
event.getByToken(tokenElectronIsoVals_[i], isolationValueMaps[i]);
for (unsigned i = 0; i < tokenElectronIsoVals_.size(); ++i) {
isolationValueMaps[i] = &event.get(tokenElectronIsoVals_[i]);
}

// prepare a map of PFCandidates having a valid GsfTrackRef to save time
std::map<reco::GsfTrackRef, const reco::PFCandidate*> gsfPFMap;
reco::PFCandidateCollection::const_iterator it = pfCandidateHandle->begin();
reco::PFCandidateCollection::const_iterator itend = pfCandidateHandle->end();
for (; it != itend; ++it) {
for (auto const& pfCand : *pfCandidateHandle) {
// First check that the GsfTrack is non null
if (it->gsfTrackRef().isNonnull()) {
if (abs(it->pdgId()) == 11) // consider only the electrons
gsfPFMap[it->gsfTrackRef()] = &(*it);
if (pfCand.gsfTrackRef().isNonnull()) {
if (abs(pfCand.pdgId()) == 11) // consider only the electrons
gsfPFMap[pfCand.gsfTrackRef()] = &pfCand;
}
}

Expand All @@ -103,10 +101,8 @@ void GEDGsfElectronFinalizer::produce(edm::Event& event, const edm::EventSetup&
// now set a status if not already done (in GEDGsfElectronProducer.cc)
// std::cout << " previous status " << newElectron.mvaOutput().status << std::endl;
if (newElectron.mvaOutput().status <= 0) {
std::map<reco::GsfTrackRef, const reco::PFCandidate*>::const_iterator itcheck =
gsfPFMap.find(newElectron.gsfTrack());
reco::GsfElectron::MvaOutput myMvaOutput(newElectron.mvaOutput());
if (itcheck != gsfPFMap.end()) {
if (gsfPFMap.find(newElectron.gsfTrack()) != gsfPFMap.end()) {
// it means that there is a PFCandidate with the same GsfTrack
myMvaOutput.status = 3; //as defined in PFCandidateEGammaExtra.h
//this is currently fully redundant with mvaOutput.stats so candidate for removal
Expand All @@ -122,8 +118,11 @@ void GEDGsfElectronFinalizer::produce(edm::Event& event, const edm::EventSetup&
if (gedRegression_) {
gedRegression_->modifyObject(newElectron);
}
outputElectrons_p->push_back(newElectron);
outputElectrons.push_back(newElectron);
}

event.put(std::move(outputElectrons_p), outputCollectionLabel_);
event.emplace(putToken_, std::move(outputElectrons));
}

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(GEDGsfElectronFinalizer);

This file was deleted.