Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:44

0001 // -*- C++ -*-
0002 //
0003 // Package:    PhysicsTools/NanoAOD
0004 // Class:      GenJetTauTaggerProducer
0005 //
0006 /**\class GenJetTauTaggerProducer GenJetTauTaggerProducer.cc PhysicsTools/NanoAOD/plugins/GenJetTauTaggerProducer.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Elisabetta Manca
0015 //         Created:  Wed, 08 May 2019 13:09:28 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031 
0032 #include "DataFormats/JetReco/interface/GenJet.h"
0033 #include "DataFormats/Common/interface/ValueMap.h"
0034 
0035 //
0036 // class declaration
0037 //
0038 
0039 class GenJetTauTaggerProducer : public edm::stream::EDProducer<> {
0040 public:
0041   explicit GenJetTauTaggerProducer(const edm::ParameterSet& iConfig)
0042       : src_(consumes<std::vector<reco::GenJet>>(iConfig.getParameter<edm::InputTag>("src"))) {
0043     produces<edm::ValueMap<bool>>();
0044   }
0045   ~GenJetTauTaggerProducer() override;
0046 
0047   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0048 
0049 private:
0050   void produce(edm::Event&, const edm::EventSetup&) override;
0051   edm::EDGetTokenT<std::vector<reco::GenJet>> src_;
0052 };
0053 
0054 GenJetTauTaggerProducer::~GenJetTauTaggerProducer() {}
0055 
0056 //
0057 // member functions
0058 //
0059 
0060 // ------------ method called to produce the data  ------------
0061 void GenJetTauTaggerProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0062   using namespace edm;
0063 
0064   edm::Handle<reco::GenJetCollection> jets;
0065   iEvent.getByToken(src_, jets);
0066 
0067   std::vector<bool> tags;
0068 
0069   for (auto jet = jets->begin(); jet != jets->end(); ++jet) {
0070     bool found = false;
0071     for (auto cand : jet->getJetConstituentsQuick()) {
0072       if (abs(cand->pdgId()) == 15)
0073         found = true;
0074     }
0075     tags.push_back(found);
0076   }
0077 
0078   std::unique_ptr<edm::ValueMap<bool>> tagsV(new edm::ValueMap<bool>());
0079   edm::ValueMap<bool>::Filler fillerCorr(*tagsV);
0080   fillerCorr.insert(jets, tags.begin(), tags.end());
0081   fillerCorr.fill();
0082   iEvent.put(std::move(tagsV));
0083 }
0084 
0085 void GenJetTauTaggerProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086   //The following says we do not know what parameters are allowed so do no validation
0087   // Please change this to state exactly what you do use, even if it is no parameters
0088   edm::ParameterSetDescription desc;
0089   desc.add<edm::InputTag>("src")->setComment("input physics object collection");
0090   descriptions.addDefault(desc);
0091 }
0092 
0093 //define this as a plug-in
0094 DEFINE_FWK_MODULE(GenJetTauTaggerProducer);