Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-28 03:10:10

0001 
0002 // system include files
0003 #include <memory>
0004 
0005 // user include files
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/stream/EDProducer.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/Utilities/interface/StreamID.h"
0014 
0015 #include "DataFormats/JetReco/interface/GenJetCollection.h"
0016 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0017 
0018 #include "DataFormats/Common/interface/ValueMap.h"
0019 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0020 #include "CommonTools/Utils/interface/StringObjectFunction.h"
0021 
0022 //
0023 // class declaration
0024 //
0025 
0026 class GenJetGenPartMerger : public edm::stream::EDProducer<> {
0027 public:
0028   explicit GenJetGenPartMerger(const edm::ParameterSet&);
0029   ~GenJetGenPartMerger() override;
0030 
0031 private:
0032   void beginStream(edm::StreamID) override;
0033   void produce(edm::Event&, const edm::EventSetup&) override;
0034   void endStream() override;
0035 
0036   const edm::EDGetTokenT<reco::GenJetCollection> jetToken_;
0037   const edm::EDGetTokenT<reco::GenParticleCollection> partToken_;
0038   const StringCutObjectSelector<reco::Candidate> cut_;
0039   const edm::EDGetTokenT<edm::ValueMap<bool>> tauAncToken_;
0040 };
0041 
0042 //
0043 // constants, enums and typedefs
0044 //
0045 
0046 //
0047 // static data member definitions
0048 //
0049 
0050 //
0051 // constructors and destructor
0052 //
0053 GenJetGenPartMerger::GenJetGenPartMerger(const edm::ParameterSet& iConfig)
0054     : jetToken_(consumes<reco::GenJetCollection>(iConfig.getParameter<edm::InputTag>("srcJet"))),
0055       partToken_(consumes<reco::GenParticleCollection>(iConfig.getParameter<edm::InputTag>("srcPart"))),
0056       cut_(iConfig.getParameter<std::string>("cut")),
0057       tauAncToken_(consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("hasTauAnc"))) {
0058   produces<reco::GenJetCollection>("merged");
0059   produces<edm::ValueMap<bool>>("hasTauAnc");
0060 }
0061 
0062 GenJetGenPartMerger::~GenJetGenPartMerger() {}
0063 
0064 //
0065 // member functions
0066 //
0067 
0068 // ------------ method called to produce the data  ------------
0069 void GenJetGenPartMerger::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0070   using namespace edm;
0071   std::unique_ptr<reco::GenJetCollection> merged(new reco::GenJetCollection);
0072 
0073   std::vector<bool> hasTauAncValues;
0074 
0075   edm::Handle<reco::GenJetCollection> jetHandle;
0076   iEvent.getByToken(jetToken_, jetHandle);
0077 
0078   edm::Handle<reco::GenParticleCollection> partHandle;
0079   iEvent.getByToken(partToken_, partHandle);
0080 
0081   edm::Handle<edm::ValueMap<bool>> tauAncHandle;
0082   iEvent.getByToken(tauAncToken_, tauAncHandle);
0083 
0084   for (unsigned int ijet = 0; ijet < jetHandle->size(); ++ijet) {
0085     auto jet = jetHandle->at(ijet);
0086     if (cut_(jet)) {
0087       merged->push_back(reco::GenJet(jet));
0088       reco::GenJetRef jetRef(jetHandle, ijet);
0089       hasTauAncValues.push_back((*tauAncHandle)[jetRef]);
0090     }
0091   }
0092 
0093   for (auto& part : *partHandle) {
0094     reco::GenJet jet;
0095     jet.setP4(part.p4());
0096     jet.setPdgId(part.pdgId());
0097     jet.setCharge(part.charge());
0098     merged->push_back(jet);
0099     hasTauAncValues.push_back(false);
0100   }
0101 
0102   auto newmerged = iEvent.put(std::move(merged), "merged");
0103 
0104   std::unique_ptr<edm::ValueMap<bool>> out(new edm::ValueMap<bool>());
0105   edm::ValueMap<bool>::Filler filler(*out);
0106   filler.insert(newmerged, hasTauAncValues.begin(), hasTauAncValues.end());
0107   filler.fill();
0108 
0109   iEvent.put(std::move(out), "hasTauAnc");
0110 }
0111 
0112 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0113 void GenJetGenPartMerger::beginStream(edm::StreamID) {}
0114 
0115 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0116 void GenJetGenPartMerger::endStream() {}
0117 
0118 //define this as a plug-in
0119 DEFINE_FWK_MODULE(GenJetGenPartMerger);