Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-09 11:29:54

0001 // -*- C++ -*-
0002 //
0003 // Package:    PhysicsTools/NanoAOD
0004 // Class:      NanoAODBaseCrossCleaner
0005 //
0006 /**\class NanoAODBaseCrossCleaner NanoAODBaseCrossCleaner.cc PhysicsTools/NanoAODBaseCrossCleaner/plugins/NanoAODBaseCrossCleaner.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Andrea Rizzi
0015 //         Created:  Mon, 28 Aug 2017 09:26:39 GMT
0016 //
0017 //
0018 
0019 #include "PhysicsTools/NanoAOD/plugins/NanoAODBaseCrossCleaner.h"
0020 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0021 
0022 //
0023 // constructors and destructor
0024 //
0025 NanoAODBaseCrossCleaner::NanoAODBaseCrossCleaner(const edm::ParameterSet& params)
0026     : name_(params.getParameter<std::string>("name")),
0027       doc_(params.getParameter<std::string>("doc")),
0028       jets_(consumes<edm::View<pat::Jet>>(params.getParameter<edm::InputTag>("jets"))),
0029       muons_(consumes<edm::View<pat::Muon>>(params.getParameter<edm::InputTag>("muons"))),
0030       electrons_(consumes<edm::View<pat::Electron>>(params.getParameter<edm::InputTag>("electrons"))),
0031       lowPtElectronsTag_(params.getParameter<edm::InputTag>("lowPtElectrons")),
0032       lowPtElectrons_(mayConsume<edm::View<pat::Electron>>(lowPtElectronsTag_)),
0033       taus_(consumes<edm::View<pat::Tau>>(params.getParameter<edm::InputTag>("taus"))),
0034       photons_(consumes<edm::View<pat::Photon>>(params.getParameter<edm::InputTag>("photons"))),
0035       jetSel_(params.getParameter<std::string>("jetSel")),
0036       muonSel_(params.getParameter<std::string>("muonSel")),
0037       electronSel_(params.getParameter<std::string>("electronSel")),
0038       lowPtElectronSel_(params.getParameter<std::string>("lowPtElectronSel")),
0039       tauSel_(params.getParameter<std::string>("tauSel")),
0040       photonSel_(params.getParameter<std::string>("photonSel")),
0041       jetName_(params.getParameter<std::string>("jetName")),
0042       muonName_(params.getParameter<std::string>("muonName")),
0043       electronName_(params.getParameter<std::string>("electronName")),
0044       lowPtElectronName_(params.getParameter<std::string>("lowPtElectronName")),
0045       tauName_(params.getParameter<std::string>("tauName")),
0046       photonName_(params.getParameter<std::string>("photonName"))
0047 
0048 {
0049   produces<nanoaod::FlatTable>("jets");
0050   produces<nanoaod::FlatTable>("muons");
0051   produces<nanoaod::FlatTable>("electrons");
0052   produces<nanoaod::FlatTable>("lowPtElectrons");
0053   produces<nanoaod::FlatTable>("taus");
0054   produces<nanoaod::FlatTable>("photons");
0055 }
0056 
0057 NanoAODBaseCrossCleaner::~NanoAODBaseCrossCleaner() {
0058   // do anything here that needs to be done at destruction time
0059   // (e.g. close files, deallocate resources etc.)
0060 }
0061 
0062 //
0063 // member functions
0064 //
0065 
0066 // ------------ method called to produce the data  ------------
0067 
0068 void NanoAODBaseCrossCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0069   using namespace edm;
0070   const auto& jetsProd = iEvent.get(jets_);
0071   std::vector<uint8_t> jets;
0072   jets.reserve(jetsProd.size());
0073   for (const auto& j : jetsProd) {
0074     jets.push_back(jetSel_(j));
0075   }
0076   auto jetsTable = std::make_unique<nanoaod::FlatTable>(jetsProd.size(), jetName_, false, true);
0077 
0078   const auto& muonsProd = iEvent.get(muons_);
0079   std::vector<uint8_t> muons;
0080   muons.reserve(muonsProd.size());
0081   for (const auto& m : muonsProd) {
0082     muons.push_back(muonSel_(m));
0083   }
0084   auto muonsTable = std::make_unique<nanoaod::FlatTable>(muonsProd.size(), muonName_, false, true);
0085 
0086   const auto& electronsProd = iEvent.get(electrons_);
0087   std::vector<uint8_t> eles;
0088   eles.reserve(electronsProd.size());
0089   for (const auto& e : electronsProd) {
0090     eles.push_back(electronSel_(e));
0091   }
0092   auto electronsTable = std::make_unique<nanoaod::FlatTable>(electronsProd.size(), electronName_, false, true);
0093 
0094   const auto& lowPtelectronsProd = iEvent.get(lowPtElectrons_);
0095   std::vector<uint8_t> lowPtEles;
0096   lowPtEles.reserve(lowPtelectronsProd.size());
0097   for (const auto& e : lowPtelectronsProd) {
0098     lowPtEles.push_back(lowPtElectronSel_(e));
0099   }
0100   auto lowPtElectronsTable = std::make_unique<nanoaod::FlatTable>(lowPtEles.size(), lowPtElectronName_, false, true);
0101 
0102   const auto& tausProd = iEvent.get(taus_);
0103   std::vector<uint8_t> taus;
0104   for (const auto& t : tausProd) {
0105     taus.push_back(tauSel_(t));
0106   }
0107   auto tausTable = std::make_unique<nanoaod::FlatTable>(tausProd.size(), tauName_, false, true);
0108 
0109   const auto& photonsProd = iEvent.get(photons_);
0110   std::vector<uint8_t> photons;
0111   for (const auto& p : photonsProd) {
0112     photons.push_back(photonSel_(p));
0113   }
0114   auto photonsTable = std::make_unique<nanoaod::FlatTable>(photonsProd.size(), photonName_, false, true);
0115 
0116   objectSelection(jetsProd, muonsProd, electronsProd, tausProd, photonsProd, jets, muons, eles, taus, photons);
0117 
0118   muonsTable->addColumn<uint8_t>(name_, muons, doc_);
0119   jetsTable->addColumn<uint8_t>(name_, jets, doc_);
0120   electronsTable->addColumn<uint8_t>(name_, eles, doc_);
0121   lowPtElectronsTable->addColumn<uint8_t>(name_, lowPtEles, doc_);
0122   tausTable->addColumn<uint8_t>(name_, taus, doc_);
0123   photonsTable->addColumn<uint8_t>(name_, photons, doc_);
0124 
0125   iEvent.put(std::move(jetsTable), "jets");
0126   iEvent.put(std::move(muonsTable), "muons");
0127   iEvent.put(std::move(electronsTable), "electrons");
0128   iEvent.put(std::move(tausTable), "taus");
0129   iEvent.put(std::move(photonsTable), "photons");
0130   iEvent.put(std::move(lowPtElectronsTable), "lowPtElectrons");
0131 }
0132 
0133 // ------------ method called once each stream before processing any runs, lumis or events  ------------
0134 void NanoAODBaseCrossCleaner::beginStream(edm::StreamID) {}
0135 
0136 // ------------ method called once each stream after processing all runs, lumis and events  ------------
0137 void NanoAODBaseCrossCleaner::endStream() {}
0138 
0139 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0140 void NanoAODBaseCrossCleaner::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0141   edm::ParameterSetDescription desc;
0142   desc.add<std::string>("name")->setComment("suffix name of the output flat table");
0143   desc.add<std::string>("doc")->setComment(
0144       "a bitmap defining the objects that remain after selection and cross cleaning");
0145   desc.add<edm::InputTag>("jets")->setComment("a jet collection derived from pat::Jet");
0146   desc.add<edm::InputTag>("muons")->setComment("a muon collection derived from pat::Muon");
0147   desc.add<edm::InputTag>("electrons")->setComment("an electron collection derived from pat::Electron");
0148   desc.add<edm::InputTag>("lowPtElectrons")
0149       ->setComment("an optional electron collection derived from pat::Electron, empty=>not used");
0150   desc.add<edm::InputTag>("taus")->setComment("a tau collection derived from pat::Tau");
0151   desc.add<edm::InputTag>("photons")->setComment("a photon collection derived from pat::Photon");
0152 
0153   desc.add<std::string>("jetSel")->setComment("function on pat::Jet defining the selection of jets");
0154   desc.add<std::string>("muonSel")->setComment("function on pat::Muon defining the selection of muons");
0155   desc.add<std::string>("electronSel")->setComment("function on pat::Electron defining the selection of electrons");
0156   desc.add<std::string>("lowPtElectronSel")
0157       ->setComment("function on pat::Electron defining the selection on alternative electrons collection");
0158   desc.add<std::string>("tauSel")->setComment("function on pat::Tau defining the selection on taus");
0159   desc.add<std::string>("photonSel")->setComment("function on pat::Photon defining the selection on photons");
0160 
0161   desc.add<std::string>("jetName")->setComment("name of the jet mask flat table output");
0162   desc.add<std::string>("muonName")->setComment("name of the muon mask flat table output");
0163   desc.add<std::string>("electronName")->setComment("name of the electron mask flat table output");
0164   desc.add<std::string>("lowPtElectronName")->setComment("name of the alternative electron mask flat table output");
0165   desc.add<std::string>("tauName")->setComment("name of the tau mask flat table output");
0166   desc.add<std::string>("photonName")->setComment("name of the photon mask flat table output");
0167 
0168   descriptions.addWithDefaultLabel(desc);
0169 }
0170 
0171 //define this as a plug-in
0172 DEFINE_FWK_MODULE(NanoAODBaseCrossCleaner);