File indexing completed on 2024-04-06 12:24:49
0001 #include "CommonTools/Utils/interface/LazyConstructed.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
0007 #include "DataFormats/ParticleFlowReco/interface/GsfPFRecTrack.h"
0008 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0009 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
0010 #include "FWCore/Framework/interface/global/EDProducer.h"
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "RecoEgamma/EgammaElectronAlgos/interface/GsfElectronTools.h"
0014
0015 class GsfElectronCoreEcalDrivenProducer : public edm::global::EDProducer<> {
0016 public:
0017 static void fillDescriptions(edm::ConfigurationDescriptions&);
0018
0019 explicit GsfElectronCoreEcalDrivenProducer(const edm::ParameterSet& conf);
0020 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0021
0022 private:
0023 const bool useGsfPfRecTracks_;
0024 const bool hgcalOnly_;
0025
0026 const edm::EDGetTokenT<reco::GsfPFRecTrackCollection> gsfPfRecTracksToken_;
0027 const edm::EDGetTokenT<reco::GsfTrackCollection> gsfTracksToken_;
0028 const edm::EDGetTokenT<reco::TrackCollection> ctfTracksToken_;
0029
0030 const edm::EDPutTokenT<reco::GsfElectronCoreCollection> putToken_;
0031 };
0032
0033 using reco::ElectronSeedRef;
0034 using reco::GsfPFRecTrackCollection;
0035 using reco::GsfTrackCollection;
0036 using reco::SuperClusterRef;
0037 using reco::TrackCollection;
0038
0039 void GsfElectronCoreEcalDrivenProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0040 edm::ParameterSetDescription desc;
0041 desc.add<edm::InputTag>("gsfPfRecTracks", {"pfTrackElec"});
0042 desc.add<edm::InputTag>("gsfTracks", {"electronGsfTracks"});
0043 desc.add<edm::InputTag>("ctfTracks", {"generalTracks"});
0044 desc.add<bool>("useGsfPfRecTracks", true);
0045 desc.add<bool>("hgcalOnly", false);
0046 descriptions.add("ecalDrivenGsfElectronCores", desc);
0047 }
0048
0049 GsfElectronCoreEcalDrivenProducer::GsfElectronCoreEcalDrivenProducer(const edm::ParameterSet& config)
0050 : useGsfPfRecTracks_(config.getParameter<bool>("useGsfPfRecTracks")),
0051 hgcalOnly_(config.getParameter<bool>("hgcalOnly")),
0052 gsfPfRecTracksToken_(mayConsume<GsfPFRecTrackCollection>(config.getParameter<edm::InputTag>("gsfPfRecTracks"))),
0053 gsfTracksToken_(consumes<reco::GsfTrackCollection>(config.getParameter<edm::InputTag>("gsfTracks"))),
0054 ctfTracksToken_(consumes<reco::TrackCollection>(config.getParameter<edm::InputTag>("ctfTracks"))),
0055 putToken_(produces<reco::GsfElectronCoreCollection>()) {}
0056
0057 void GsfElectronCoreEcalDrivenProducer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup&) const {
0058 auto gsfTracksHandle = event.getHandle(gsfTracksToken_);
0059 auto ctfTracksHandle = event.getHandle(ctfTracksToken_);
0060
0061 auto ctfTrackVariables = makeLazy<edm::soa::EtaPhiTable>(*ctfTracksHandle);
0062
0063
0064 reco::GsfElectronCoreCollection electrons;
0065
0066 auto produceEcalDrivenCore = [&](const reco::GsfTrackRef& gsfTrackRef) {
0067 electrons.emplace_back(gsfTrackRef);
0068 auto& eleCore = electrons.back();
0069
0070 if (!eleCore.ecalDrivenSeed()) {
0071 electrons.pop_back();
0072 return;
0073 }
0074
0075 auto ctfpair = egamma::getClosestCtfToGsf(eleCore.gsfTrack(), ctfTracksHandle, ctfTrackVariables.value());
0076 eleCore.setCtfTrack(ctfpair.first, ctfpair.second);
0077
0078 auto scRef = gsfTrackRef->extra()->seedRef().castTo<ElectronSeedRef>()->caloCluster().castTo<SuperClusterRef>();
0079 if (!scRef.isNull()) {
0080
0081 if (hgcalOnly_ && !scRef->seed()->caloID().detector(reco::CaloID::DET_HGCAL_ENDCAP))
0082 electrons.pop_back();
0083 else
0084 eleCore.setSuperCluster(scRef);
0085 } else {
0086 electrons.pop_back();
0087 edm::LogWarning("GsfElectronCoreEcalDrivenProducer") << "Seed CaloCluster is not a SuperCluster, unexpected...";
0088 }
0089 };
0090
0091
0092 if (useGsfPfRecTracks_) {
0093 for (auto const& gsfPfRecTrack : event.get(gsfPfRecTracksToken_)) {
0094 produceEcalDrivenCore(gsfPfRecTrack.gsfTrackRef());
0095 }
0096 } else {
0097 for (unsigned int i = 0; i < gsfTracksHandle->size(); ++i) {
0098 produceEcalDrivenCore(edm::Ref<GsfTrackCollection>(gsfTracksHandle, i));
0099 }
0100 }
0101
0102 event.emplace(putToken_, std::move(electrons));
0103 }
0104
0105 #include "FWCore/Framework/interface/MakerMacros.h"
0106 DEFINE_FWK_MODULE(GsfElectronCoreEcalDrivenProducer);