CMS 3D CMS Logo

NanoAODBaseCrossCleaner.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: NanoAODBaseCrossCleaner
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Mon, 28 Aug 2017 09:26:39 GMT
16 //
17 //
18 
21 
22 //
23 // constructors and destructor
24 //
26  : name_(params.getParameter<std::string>("name")),
27  doc_(params.getParameter<std::string>("doc")),
28  jets_(consumes<edm::View<pat::Jet>>(params.getParameter<edm::InputTag>("jets"))),
29  muons_(consumes<edm::View<pat::Muon>>(params.getParameter<edm::InputTag>("muons"))),
30  electrons_(consumes<edm::View<pat::Electron>>(params.getParameter<edm::InputTag>("electrons"))),
31  lowPtElectronsTag_(params.getParameter<edm::InputTag>("lowPtElectrons")),
32  lowPtElectrons_(mayConsume<edm::View<pat::Electron>>(lowPtElectronsTag_)),
33  taus_(consumes<edm::View<pat::Tau>>(params.getParameter<edm::InputTag>("taus"))),
34  photons_(consumes<edm::View<pat::Photon>>(params.getParameter<edm::InputTag>("photons"))),
35  jetSel_(params.getParameter<std::string>("jetSel")),
36  muonSel_(params.getParameter<std::string>("muonSel")),
37  electronSel_(params.getParameter<std::string>("electronSel")),
38  lowPtElectronSel_(params.getParameter<std::string>("lowPtElectronSel")),
39  tauSel_(params.getParameter<std::string>("tauSel")),
40  photonSel_(params.getParameter<std::string>("photonSel")),
41  jetName_(params.getParameter<std::string>("jetName")),
42  muonName_(params.getParameter<std::string>("muonName")),
43  electronName_(params.getParameter<std::string>("electronName")),
44  lowPtElectronName_(params.getParameter<std::string>("lowPtElectronName")),
45  tauName_(params.getParameter<std::string>("tauName")),
46  photonName_(params.getParameter<std::string>("photonName"))
47 
48 {
49  produces<nanoaod::FlatTable>("jets");
50  produces<nanoaod::FlatTable>("muons");
51  produces<nanoaod::FlatTable>("electrons");
52  produces<nanoaod::FlatTable>("lowPtElectrons");
53  produces<nanoaod::FlatTable>("taus");
54  produces<nanoaod::FlatTable>("photons");
55 }
56 
57 //
58 // member functions
59 //
60 
61 // ------------ method called to produce the data ------------
62 
64  using namespace edm;
65  const auto& jetsProd = iEvent.get(jets_);
66  std::vector<uint8_t> jets;
67  jets.reserve(jetsProd.size());
68  for (const auto& j : jetsProd) {
69  jets.push_back(jetSel_(j));
70  }
71  auto jetsTable = std::make_unique<nanoaod::FlatTable>(jetsProd.size(), jetName_, false, true);
72 
73  const auto& muonsProd = iEvent.get(muons_);
74  std::vector<uint8_t> muons;
75  muons.reserve(muonsProd.size());
76  for (const auto& m : muonsProd) {
77  muons.push_back(muonSel_(m));
78  }
79  auto muonsTable = std::make_unique<nanoaod::FlatTable>(muonsProd.size(), muonName_, false, true);
80 
81  const auto& electronsProd = iEvent.get(electrons_);
82  std::vector<uint8_t> eles;
83  eles.reserve(electronsProd.size());
84  for (const auto& e : electronsProd) {
85  eles.push_back(electronSel_(e));
86  }
87  auto electronsTable = std::make_unique<nanoaod::FlatTable>(electronsProd.size(), electronName_, false, true);
88 
89  const auto& lowPtelectronsProd = iEvent.get(lowPtElectrons_);
90  std::vector<uint8_t> lowPtEles;
91  lowPtEles.reserve(lowPtelectronsProd.size());
92  for (const auto& e : lowPtelectronsProd) {
93  lowPtEles.push_back(lowPtElectronSel_(e));
94  }
95  auto lowPtElectronsTable = std::make_unique<nanoaod::FlatTable>(lowPtEles.size(), lowPtElectronName_, false, true);
96 
97  const auto& tausProd = iEvent.get(taus_);
98  std::vector<uint8_t> taus;
99  for (const auto& t : tausProd) {
100  taus.push_back(tauSel_(t));
101  }
102  auto tausTable = std::make_unique<nanoaod::FlatTable>(tausProd.size(), tauName_, false, true);
103 
104  const auto& photonsProd = iEvent.get(photons_);
105  std::vector<uint8_t> photons;
106  for (const auto& p : photonsProd) {
107  photons.push_back(photonSel_(p));
108  }
109  auto photonsTable = std::make_unique<nanoaod::FlatTable>(photonsProd.size(), photonName_, false, true);
110 
111  objectSelection(jetsProd, muonsProd, electronsProd, tausProd, photonsProd, jets, muons, eles, taus, photons);
112 
113  muonsTable->addColumn<uint8_t>(name_, muons, doc_);
114  jetsTable->addColumn<uint8_t>(name_, jets, doc_);
115  electronsTable->addColumn<uint8_t>(name_, eles, doc_);
116  lowPtElectronsTable->addColumn<uint8_t>(name_, lowPtEles, doc_);
117  tausTable->addColumn<uint8_t>(name_, taus, doc_);
118  photonsTable->addColumn<uint8_t>(name_, photons, doc_);
119 
120  iEvent.put(std::move(jetsTable), "jets");
121  iEvent.put(std::move(muonsTable), "muons");
122  iEvent.put(std::move(electronsTable), "electrons");
123  iEvent.put(std::move(tausTable), "taus");
124  iEvent.put(std::move(photonsTable), "photons");
125  iEvent.put(std::move(lowPtElectronsTable), "lowPtElectrons");
126 }
127 
128 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
131  desc.add<std::string>("name")->setComment("suffix name of the output flat table");
132  desc.add<std::string>("doc")->setComment(
133  "a bitmap defining the objects that remain after selection and cross cleaning");
134  desc.add<edm::InputTag>("jets")->setComment("a jet collection derived from pat::Jet");
135  desc.add<edm::InputTag>("muons")->setComment("a muon collection derived from pat::Muon");
136  desc.add<edm::InputTag>("electrons")->setComment("an electron collection derived from pat::Electron");
137  desc.add<edm::InputTag>("lowPtElectrons")
138  ->setComment("an optional electron collection derived from pat::Electron, empty=>not used");
139  desc.add<edm::InputTag>("taus")->setComment("a tau collection derived from pat::Tau");
140  desc.add<edm::InputTag>("photons")->setComment("a photon collection derived from pat::Photon");
141 
142  desc.add<std::string>("jetSel")->setComment("function on pat::Jet defining the selection of jets");
143  desc.add<std::string>("muonSel")->setComment("function on pat::Muon defining the selection of muons");
144  desc.add<std::string>("electronSel")->setComment("function on pat::Electron defining the selection of electrons");
145  desc.add<std::string>("lowPtElectronSel")
146  ->setComment("function on pat::Electron defining the selection on alternative electrons collection");
147  desc.add<std::string>("tauSel")->setComment("function on pat::Tau defining the selection on taus");
148  desc.add<std::string>("photonSel")->setComment("function on pat::Photon defining the selection on photons");
149 
150  desc.add<std::string>("jetName")->setComment("name of the jet mask flat table output");
151  desc.add<std::string>("muonName")->setComment("name of the muon mask flat table output");
152  desc.add<std::string>("electronName")->setComment("name of the electron mask flat table output");
153  desc.add<std::string>("lowPtElectronName")->setComment("name of the alternative electron mask flat table output");
154  desc.add<std::string>("tauName")->setComment("name of the tau mask flat table output");
155  desc.add<std::string>("photonName")->setComment("name of the photon mask flat table output");
156 
157  descriptions.addWithDefaultLabel(desc);
158 }
159 
160 //define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Definition: Photon.py:1
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:212
const StringCutObjectSelector< pat::Jet > jetSel_
Definition: HeavyIon.h:7
const StringCutObjectSelector< pat::Muon > muonSel_
const edm::EDGetTokenT< edm::View< pat::Tau > > taus_
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
Definition: Jet.py:1
const StringCutObjectSelector< pat::Photon > photonSel_
edm::EDGetTokenT< edm::View< pat::Electron > > lowPtElectrons_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
const std::string lowPtElectronName_
Definition: Tau.py:1
const StringCutObjectSelector< pat::Tau > tauSel_
HLT enums.
const edm::EDGetTokenT< edm::View< pat::Electron > > electrons_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const StringCutObjectSelector< pat::Electron > electronSel_
const edm::EDGetTokenT< edm::View< pat::Muon > > muons_
virtual void objectSelection(const edm::View< pat::Jet > &jets, const edm::View< pat::Muon > &muons, const edm::View< pat::Electron > &eles, const edm::View< pat::Tau > &taus, const edm::View< pat::Photon > &photons, std::vector< uint8_t > &jetBits, std::vector< uint8_t > &muonBits, std::vector< uint8_t > &eleBits, std::vector< uint8_t > &tauBits, std::vector< uint8_t > &photonBits)
def move(src, dest)
Definition: eostools.py:511
NanoAODBaseCrossCleaner(const edm::ParameterSet &)
const StringCutObjectSelector< pat::Electron > lowPtElectronSel_