Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:30:29

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/ParticleFlowCandidate/interface/PFCandidate.h"
0008 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateEGammaExtra.h"
0009 #include "FWCore/Framework/interface/global/EDProducer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "RecoEgamma/EgammaElectronAlgos/interface/GsfElectronTools.h"
0013 
0014 class GEDGsfElectronCoreProducer : public edm::global::EDProducer<> {
0015 public:
0016   static void fillDescriptions(edm::ConfigurationDescriptions &);
0017 
0018   explicit GEDGsfElectronCoreProducer(const edm::ParameterSet &conf);
0019   void produce(edm::StreamID iStream, edm::Event &, const edm::EventSetup &) const override;
0020 
0021 private:
0022   void produceElectronCore(reco::GsfTrackRef const &gsfTrackRef,
0023                            reco::PFCandidateEGammaExtraRef const &extraRef,
0024                            reco::GsfElectronCoreCollection &electrons,
0025                            edm::Handle<reco::TrackCollection> const &ctfTracksHandle,
0026                            edm::soa::EtaPhiTableView ctfTrackVariables) const;
0027 
0028   const edm::EDGetTokenT<reco::TrackCollection> ctfTracksToken_;
0029   const edm::EDGetTokenT<reco::PFCandidateCollection> gedEMUnbiasedToken_;
0030   const edm::EDPutTokenT<reco::GsfElectronCoreCollection> putToken_;
0031 };
0032 
0033 using namespace reco;
0034 
0035 void GEDGsfElectronCoreProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0036   edm::ParameterSetDescription desc;
0037   desc.add<edm::InputTag>("ctfTracks", {"generalTracks"});
0038   desc.add<edm::InputTag>("GEDEMUnbiased", {"particleFlowEGamma"});
0039   descriptions.add("gedGsfElectronCores", desc);
0040 }
0041 
0042 GEDGsfElectronCoreProducer::GEDGsfElectronCoreProducer(const edm::ParameterSet &config)
0043     : ctfTracksToken_(consumes<reco::TrackCollection>(config.getParameter<edm::InputTag>("ctfTracks"))),
0044       gedEMUnbiasedToken_(consumes<reco::PFCandidateCollection>(config.getParameter<edm::InputTag>("GEDEMUnbiased"))),
0045       putToken_(produces<reco::GsfElectronCoreCollection>()) {}
0046 
0047 void GEDGsfElectronCoreProducer::produce(edm::StreamID iStream, edm::Event &event, const edm::EventSetup &) const {
0048   auto ctfTracksHandle = event.getHandle(ctfTracksToken_);
0049   auto ctfTrackVariables = makeLazy<edm::soa::EtaPhiTable>(*ctfTracksHandle);
0050 
0051   // output
0052   reco::GsfElectronCoreCollection electrons;
0053 
0054   for (auto const &pfCand : event.get(gedEMUnbiasedToken_)) {
0055     const GsfTrackRef gsfTrackRef = pfCand.gsfTrackRef();
0056     if (gsfTrackRef.isNull())
0057       continue;
0058 
0059     reco::PFCandidateEGammaExtraRef extraRef = pfCand.egammaExtraRef();
0060     if (extraRef.isNull())
0061       continue;
0062     produceElectronCore(gsfTrackRef, extraRef, electrons, ctfTracksHandle, ctfTrackVariables.value());
0063   }
0064 
0065   event.emplace(putToken_, std::move(electrons));
0066 }
0067 
0068 void GEDGsfElectronCoreProducer::produceElectronCore(GsfTrackRef const &gsfTrackRef,
0069                                                      reco::PFCandidateEGammaExtraRef const &extraRef,
0070                                                      reco::GsfElectronCoreCollection &electrons,
0071                                                      edm::Handle<reco::TrackCollection> const &ctfTracksHandle,
0072                                                      edm::soa::EtaPhiTableView ctfTrackVariables) const {
0073   electrons.emplace_back(gsfTrackRef);
0074   auto &eleCore = electrons.back();
0075 
0076   auto ctfpair = egamma::getClosestCtfToGsf(eleCore.gsfTrack(), ctfTracksHandle, ctfTrackVariables);
0077   eleCore.setCtfTrack(ctfpair.first, ctfpair.second);
0078 
0079   SuperClusterRef scRef = extraRef->superClusterRef();
0080   SuperClusterRef scBoxRef = extraRef->superClusterPFECALRef();
0081 
0082   for (const auto &convref : extraRef->conversionRef()) {
0083     eleCore.addConversion(convref);
0084   }
0085 
0086   for (const auto &convref : extraRef->singleLegConversionRef()) {
0087     eleCore.addOneLegConversion(convref);
0088   }
0089 
0090   if (!scRef.isNull() || !scBoxRef.isNull()) {
0091     eleCore.setSuperCluster(scRef);
0092     eleCore.setParentSuperCluster(scBoxRef);
0093   } else {
0094     electrons.pop_back();
0095     edm::LogWarning("GEDGsfElectronCoreProducer")
0096         << "Both superClusterRef and superClusterBoxRef of pfCandidate.egammaExtraRef() are Null";
0097   }
0098 }
0099 
0100 #include "FWCore/Framework/interface/MakerMacros.h"
0101 DEFINE_FWK_MODULE(GEDGsfElectronCoreProducer);