Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:04

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/MakerMacros.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0007 
0008 #include "DataFormats/Common/interface/EDProductfwd.h"
0009 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0010 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0011 
0012 class TrackingParticleConversionRefSelector : public edm::global::EDProducer<> {
0013 public:
0014   TrackingParticleConversionRefSelector(const edm::ParameterSet& iConfig);
0015 
0016   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0017 
0018   void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0019 
0020 private:
0021   edm::EDGetTokenT<TrackingParticleCollection> tpToken_;
0022 };
0023 
0024 TrackingParticleConversionRefSelector::TrackingParticleConversionRefSelector(const edm::ParameterSet& iConfig)
0025     : tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("src"))) {
0026   produces<TrackingParticleRefVector>();
0027 }
0028 
0029 void TrackingParticleConversionRefSelector::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0030   edm::ParameterSetDescription desc;
0031   desc.add<edm::InputTag>("src", edm::InputTag("mix", "MergedTrackTruth"));
0032   descriptions.add("trackingParticleConversionRefSelectorDefault", desc);
0033 }
0034 
0035 void TrackingParticleConversionRefSelector::produce(edm::StreamID,
0036                                                     edm::Event& iEvent,
0037                                                     const edm::EventSetup& iSetup) const {
0038   edm::Handle<TrackingParticleCollection> h_tps;
0039   iEvent.getByToken(tpToken_, h_tps);
0040 
0041   auto ret = std::make_unique<TrackingParticleRefVector>();
0042 
0043   // Logic is similar to Validation/RecoEgamma/plugins/PhotonValidator.cc
0044   // and RecoEgamma/EgammaMCTools/src/PhotonMCTruthFinder.cc,
0045   // but implemented purely in terms of TrackingParticles (simpler and works for pileup too)
0046   for (const auto& tp : *h_tps) {
0047     if (tp.pdgId() == 22) {
0048       for (const auto& vertRef : tp.decayVertices()) {
0049         for (const auto& tpRef : vertRef->daughterTracks()) {
0050           if (std::abs(tpRef->pdgId()) == 11) {
0051             ret->push_back(tpRef);
0052           }
0053         }
0054       }
0055     }
0056   }
0057 
0058   iEvent.put(std::move(ret));
0059 }
0060 
0061 DEFINE_FWK_MODULE(TrackingParticleConversionRefSelector);