Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:42

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 //
0058 // member functions
0059 //
0060 
0061 // ------------ method called to produce the data  ------------
0062 
0063 void NanoAODBaseCrossCleaner::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0064   using namespace edm;
0065   const auto& jetsProd = iEvent.get(jets_);
0066   std::vector<uint8_t> jets;
0067   jets.reserve(jetsProd.size());
0068   for (const auto& j : jetsProd) {
0069     jets.push_back(jetSel_(j));
0070   }
0071   auto jetsTable = std::make_unique<nanoaod::FlatTable>(jetsProd.size(), jetName_, false, true);
0072 
0073   const auto& muonsProd = iEvent.get(muons_);
0074   std::vector<uint8_t> muons;
0075   muons.reserve(muonsProd.size());
0076   for (const auto& m : muonsProd) {
0077     muons.push_back(muonSel_(m));
0078   }
0079   auto muonsTable = std::make_unique<nanoaod::FlatTable>(muonsProd.size(), muonName_, false, true);
0080 
0081   const auto& electronsProd = iEvent.get(electrons_);
0082   std::vector<uint8_t> eles;
0083   eles.reserve(electronsProd.size());
0084   for (const auto& e : electronsProd) {
0085     eles.push_back(electronSel_(e));
0086   }
0087   auto electronsTable = std::make_unique<nanoaod::FlatTable>(electronsProd.size(), electronName_, false, true);
0088 
0089   const auto& lowPtelectronsProd = iEvent.get(lowPtElectrons_);
0090   std::vector<uint8_t> lowPtEles;
0091   lowPtEles.reserve(lowPtelectronsProd.size());
0092   for (const auto& e : lowPtelectronsProd) {
0093     lowPtEles.push_back(lowPtElectronSel_(e));
0094   }
0095   auto lowPtElectronsTable = std::make_unique<nanoaod::FlatTable>(lowPtEles.size(), lowPtElectronName_, false, true);
0096 
0097   const auto& tausProd = iEvent.get(taus_);
0098   std::vector<uint8_t> taus;
0099   for (const auto& t : tausProd) {
0100     taus.push_back(tauSel_(t));
0101   }
0102   auto tausTable = std::make_unique<nanoaod::FlatTable>(tausProd.size(), tauName_, false, true);
0103 
0104   const auto& photonsProd = iEvent.get(photons_);
0105   std::vector<uint8_t> photons;
0106   for (const auto& p : photonsProd) {
0107     photons.push_back(photonSel_(p));
0108   }
0109   auto photonsTable = std::make_unique<nanoaod::FlatTable>(photonsProd.size(), photonName_, false, true);
0110 
0111   objectSelection(jetsProd, muonsProd, electronsProd, tausProd, photonsProd, jets, muons, eles, taus, photons);
0112 
0113   muonsTable->addColumn<uint8_t>(name_, muons, doc_);
0114   jetsTable->addColumn<uint8_t>(name_, jets, doc_);
0115   electronsTable->addColumn<uint8_t>(name_, eles, doc_);
0116   lowPtElectronsTable->addColumn<uint8_t>(name_, lowPtEles, doc_);
0117   tausTable->addColumn<uint8_t>(name_, taus, doc_);
0118   photonsTable->addColumn<uint8_t>(name_, photons, doc_);
0119 
0120   iEvent.put(std::move(jetsTable), "jets");
0121   iEvent.put(std::move(muonsTable), "muons");
0122   iEvent.put(std::move(electronsTable), "electrons");
0123   iEvent.put(std::move(tausTable), "taus");
0124   iEvent.put(std::move(photonsTable), "photons");
0125   iEvent.put(std::move(lowPtElectronsTable), "lowPtElectrons");
0126 }
0127 
0128 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0129 void NanoAODBaseCrossCleaner::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0130   edm::ParameterSetDescription desc;
0131   desc.add<std::string>("name")->setComment("suffix name of the output flat table");
0132   desc.add<std::string>("doc")->setComment(
0133       "a bitmap defining the objects that remain after selection and cross cleaning");
0134   desc.add<edm::InputTag>("jets")->setComment("a jet collection derived from pat::Jet");
0135   desc.add<edm::InputTag>("muons")->setComment("a muon collection derived from pat::Muon");
0136   desc.add<edm::InputTag>("electrons")->setComment("an electron collection derived from pat::Electron");
0137   desc.add<edm::InputTag>("lowPtElectrons")
0138       ->setComment("an optional electron collection derived from pat::Electron, empty=>not used");
0139   desc.add<edm::InputTag>("taus")->setComment("a tau collection derived from pat::Tau");
0140   desc.add<edm::InputTag>("photons")->setComment("a photon collection derived from pat::Photon");
0141 
0142   desc.add<std::string>("jetSel")->setComment("function on pat::Jet defining the selection of jets");
0143   desc.add<std::string>("muonSel")->setComment("function on pat::Muon defining the selection of muons");
0144   desc.add<std::string>("electronSel")->setComment("function on pat::Electron defining the selection of electrons");
0145   desc.add<std::string>("lowPtElectronSel")
0146       ->setComment("function on pat::Electron defining the selection on alternative electrons collection");
0147   desc.add<std::string>("tauSel")->setComment("function on pat::Tau defining the selection on taus");
0148   desc.add<std::string>("photonSel")->setComment("function on pat::Photon defining the selection on photons");
0149 
0150   desc.add<std::string>("jetName")->setComment("name of the jet mask flat table output");
0151   desc.add<std::string>("muonName")->setComment("name of the muon mask flat table output");
0152   desc.add<std::string>("electronName")->setComment("name of the electron mask flat table output");
0153   desc.add<std::string>("lowPtElectronName")->setComment("name of the alternative electron mask flat table output");
0154   desc.add<std::string>("tauName")->setComment("name of the tau mask flat table output");
0155   desc.add<std::string>("photonName")->setComment("name of the photon mask flat table output");
0156 
0157   descriptions.addWithDefaultLabel(desc);
0158 }
0159 
0160 //define this as a plug-in
0161 DEFINE_FWK_MODULE(NanoAODBaseCrossCleaner);