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  if (!lowPtElectronsTag_.label().empty())
53  produces<nanoaod::FlatTable>("lowPtElectrons");
54  produces<nanoaod::FlatTable>("taus");
55  produces<nanoaod::FlatTable>("photons");
56 }
57 
59  // do anything here that needs to be done at destruction time
60  // (e.g. close files, deallocate resources etc.)
61 }
62 
63 //
64 // member functions
65 //
66 
67 // ------------ method called to produce the data ------------
68 
70  using namespace edm;
72  iEvent.getByToken(jets_, jetsIn);
73  std::vector<uint8_t> jets;
74  for (const auto& j : *jetsIn) {
75  jets.push_back(jetSel_(j));
76  }
77  auto jetsTable = std::make_unique<nanoaod::FlatTable>(jetsIn->size(), jetName_, false, true);
78 
80  iEvent.getByToken(muons_, muonsIn);
81  std::vector<uint8_t> muons;
82  for (const auto& m : *muonsIn) {
83  muons.push_back(muonSel_(m));
84  }
85  auto muonsTable = std::make_unique<nanoaod::FlatTable>(muonsIn->size(), muonName_, false, true);
86 
88  iEvent.getByToken(electrons_, electronsIn);
89  std::vector<uint8_t> eles;
90  for (const auto& e : *electronsIn) {
91  eles.push_back(electronSel_(e));
92  }
93  auto electronsTable = std::make_unique<nanoaod::FlatTable>(electronsIn->size(), electronName_, false, true);
94 
95  edm::Handle<edm::View<pat::Electron>> lowPtElectronsIn;
96  std::vector<uint8_t> lowPtEles;
97  if (!lowPtElectronsTag_.label().empty()) {
98  iEvent.getByToken(lowPtElectrons_, lowPtElectronsIn);
99  for (const auto& e : *lowPtElectronsIn) {
100  lowPtEles.push_back(lowPtElectronSel_(e));
101  }
102  }
103 
105  iEvent.getByToken(taus_, tausIn);
106  std::vector<uint8_t> taus;
107  for (const auto& t : *tausIn) {
108  taus.push_back(tauSel_(t));
109  }
110  auto tausTable = std::make_unique<nanoaod::FlatTable>(tausIn->size(), tauName_, false, true);
111 
113  iEvent.getByToken(photons_, photonsIn);
114  std::vector<uint8_t> photons;
115  for (const auto& p : *photonsIn) {
116  photons.push_back(photonSel_(p));
117  }
118  auto photonsTable = std::make_unique<nanoaod::FlatTable>(photonsIn->size(), photonName_, false, true);
119 
120  objectSelection(*jetsIn, *muonsIn, *electronsIn, *tausIn, *photonsIn, jets, muons, eles, taus, photons);
121 
122  muonsTable->addColumn<uint8_t>(name_, muons, doc_);
123  jetsTable->addColumn<uint8_t>(name_, jets, doc_);
124  electronsTable->addColumn<uint8_t>(name_, eles, doc_);
125  tausTable->addColumn<uint8_t>(name_, taus, doc_);
126  photonsTable->addColumn<uint8_t>(name_, photons, doc_);
127 
128  iEvent.put(std::move(jetsTable), "jets");
129  iEvent.put(std::move(muonsTable), "muons");
130  iEvent.put(std::move(electronsTable), "electrons");
131  iEvent.put(std::move(tausTable), "taus");
132  iEvent.put(std::move(photonsTable), "photons");
133 
134  if (!lowPtElectronsTag_.label().empty()) {
135  auto lowPtElectronsTable =
136  std::make_unique<nanoaod::FlatTable>(lowPtElectronsIn->size(), lowPtElectronName_, false, true);
137  lowPtElectronsTable->addColumn<uint8_t>(name_, lowPtEles, doc_);
138  iEvent.put(std::move(lowPtElectronsTable), "lowPtElectrons");
139  }
140 }
141 
142 // ------------ method called once each stream before processing any runs, lumis or events ------------
144 
145 // ------------ method called once each stream after processing all runs, lumis and events ------------
147 
148 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
150  //The following says we do not know what parameters are allowed so do no validation
151  // Please change this to state exactly what you do use, even if it is no parameters
153  desc.setUnknown();
154  descriptions.addDefault(desc);
155 }
156 
157 //define this as a plug-in
Definition: Photon.py:1
const edm::EDGetTokenT< edm::View< pat::Photon > > photons_
std::string const & label() const
Definition: InputTag.h:36
const edm::EDGetTokenT< edm::View< pat::Jet > > jets_
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
void addDefault(ParameterSetDescription const &psetDescription)
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 beginStream(edm::StreamID) override
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_