|
| 1 | +// -*- C++ -*- |
| 2 | +// |
| 3 | +// Package: PhysicsTools/NanoAOD |
| 4 | +// Class: CaloTPTableProducer |
| 5 | +// |
| 6 | +/**\class CaloTPTableProducer CaloTPTableProducer.cc PhysicsTools/NanoAOD/plugins/CaloTPTableProducer.cc |
| 7 | +
|
| 8 | + Description: [one line class summary] |
| 9 | +
|
| 10 | + Implementation: |
| 11 | + [Notes on implementation] |
| 12 | +*/ |
| 13 | +// |
| 14 | +// Original Author: localusers user |
| 15 | +// Created: Wed, 08 Nov 2023 13:16:40 GMT |
| 16 | +// |
| 17 | +// |
| 18 | + |
| 19 | +// system include files |
| 20 | +#include <memory> |
| 21 | + |
| 22 | +// user include files |
| 23 | +#include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h" |
| 24 | +#include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h" |
| 25 | + |
| 26 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 27 | +#include "FWCore/Framework/interface/stream/EDProducer.h" |
| 28 | + |
| 29 | +#include "FWCore/Framework/interface/Event.h" |
| 30 | +#include "FWCore/Framework/interface/MakerMacros.h" |
| 31 | + |
| 32 | +#include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 33 | +#include "FWCore/Utilities/interface/StreamID.h" |
| 34 | + |
| 35 | +#include "DataFormats/NanoAOD/interface/FlatTable.h" |
| 36 | + |
| 37 | +#include "DataFormats/EcalDigi/interface/EcalDigiCollections.h" |
| 38 | +#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h" |
| 39 | + |
| 40 | +#include "DataFormats/L1TCalorimeter/interface/CaloTower.h" |
| 41 | +#include "DataFormats/L1TCalorimeter/interface/CaloCluster.h" |
| 42 | + |
| 43 | +#include "Geometry/CaloGeometry/interface/CaloGeometry.h" |
| 44 | +#include "Geometry/Records/interface/CaloGeometryRecord.h" |
| 45 | + |
| 46 | +// |
| 47 | +// class declaration |
| 48 | +// |
| 49 | + |
| 50 | +class CaloTPTableProducer : public edm::stream::EDProducer<> { |
| 51 | +public: |
| 52 | + explicit CaloTPTableProducer(const edm::ParameterSet&); |
| 53 | + |
| 54 | + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); |
| 55 | + |
| 56 | +private: |
| 57 | + void beginStream(edm::StreamID) override; |
| 58 | + void produce(edm::Event&, const edm::EventSetup&) override; |
| 59 | + void endStream() override; |
| 60 | + |
| 61 | + // ----------member data --------------------------- |
| 62 | + const double ecalLSB_; |
| 63 | + |
| 64 | + const edm::EDGetTokenT<EcalTrigPrimDigiCollection> ecalTPsToken_; |
| 65 | + const std::string ecalTPsName_; |
| 66 | + |
| 67 | + const edm::EDGetTokenT<HcalTrigPrimDigiCollection> hcalTPsToken_; |
| 68 | + const std::string hcalTPsName_; |
| 69 | + |
| 70 | + const edm::ESGetToken<CaloTPGTranscoder, CaloTPGRecord> decoderToken_; |
| 71 | +}; |
| 72 | + |
| 73 | +CaloTPTableProducer::CaloTPTableProducer(const edm::ParameterSet& iConfig) |
| 74 | + : ecalLSB_(iConfig.getUntrackedParameter<double>("ecalLSB", 0.5)), |
| 75 | + ecalTPsToken_(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalTPsSrc"))), |
| 76 | + ecalTPsName_(iConfig.getParameter<std::string>("ecalTPsName")), |
| 77 | + hcalTPsToken_(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalTPsSrc"))), |
| 78 | + hcalTPsName_(iConfig.getParameter<std::string>("hcalTPsName")), |
| 79 | + decoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()) { |
| 80 | + produces<nanoaod::FlatTable>("EcalTP"); |
| 81 | + produces<nanoaod::FlatTable>("HcalTP"); |
| 82 | + |
| 83 | + //now do what ever other initialization is needed |
| 84 | +} |
| 85 | + |
| 86 | +// |
| 87 | +// member functions |
| 88 | +// |
| 89 | + |
| 90 | +// ------------ method called to produce the data ------------ |
| 91 | +void CaloTPTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { |
| 92 | + using namespace edm; |
| 93 | + |
| 94 | + edm::ESHandle<CaloTPGTranscoder> decoder; |
| 95 | + decoder = iSetup.getHandle(decoderToken_); |
| 96 | + |
| 97 | + edm::Handle<EcalTrigPrimDigiCollection> ecalTPs; |
| 98 | + iEvent.getByToken(ecalTPsToken_, ecalTPs); |
| 99 | + |
| 100 | + edm::Handle<HcalTrigPrimDigiCollection> hcalTPs; |
| 101 | + iEvent.getByToken(hcalTPsToken_, hcalTPs); |
| 102 | + |
| 103 | + vector<int> ecalTPieta; |
| 104 | + vector<int> ecalTPCaliphi; |
| 105 | + vector<int> ecalTPiphi; |
| 106 | + vector<float> ecalTPet; |
| 107 | + vector<int> ecalTPcompEt; |
| 108 | + vector<int> ecalTPfineGrain; |
| 109 | + int nECALTP(0); |
| 110 | + if (ecalTPs.isValid()) { |
| 111 | + for (const auto& itr : *(ecalTPs.product())) { |
| 112 | + short ieta = (short)itr.id().ieta(); |
| 113 | + |
| 114 | + unsigned short cal_iphi = (unsigned short)itr.id().iphi(); |
| 115 | + unsigned short iphi = (72 + 18 - cal_iphi) % 72; |
| 116 | + unsigned short compEt = itr.compressedEt(); |
| 117 | + double et = ecalLSB_ * compEt; |
| 118 | + unsigned short fineGrain = (unsigned short)itr.fineGrain(); |
| 119 | + |
| 120 | + if (compEt > 0) { |
| 121 | + ecalTPieta.push_back(ieta); |
| 122 | + ecalTPCaliphi.push_back(cal_iphi); |
| 123 | + ecalTPiphi.push_back(iphi); |
| 124 | + ecalTPet.push_back(et); |
| 125 | + ecalTPcompEt.push_back(compEt); |
| 126 | + ecalTPfineGrain.push_back(fineGrain); |
| 127 | + nECALTP++; |
| 128 | + } |
| 129 | + } |
| 130 | + } |
| 131 | + auto ecalTPTable = std::make_unique<nanoaod::FlatTable>(nECALTP, ecalTPsName_, false); |
| 132 | + ecalTPTable->addColumn<int16_t>("ieta", ecalTPieta, ""); |
| 133 | + ecalTPTable->addColumn<int16_t>("Caliphi", ecalTPCaliphi, ""); |
| 134 | + ecalTPTable->addColumn<int16_t>("iphi", ecalTPiphi, ""); |
| 135 | + ecalTPTable->addColumn<float>("et", ecalTPet, "", 12); |
| 136 | + ecalTPTable->addColumn<int16_t>("compEt", ecalTPcompEt, ""); |
| 137 | + ecalTPTable->addColumn<int16_t>("fineGrain", ecalTPfineGrain, ""); |
| 138 | + |
| 139 | + vector<int> hcalTPieta; |
| 140 | + vector<int> hcalTPCaliphi; |
| 141 | + vector<int> hcalTPiphi; |
| 142 | + vector<float> hcalTPet; |
| 143 | + vector<int> hcalTPcompEt; |
| 144 | + vector<int> hcalTPfineGrain; |
| 145 | + int nHCALTP(0); |
| 146 | + if (hcalTPs.isValid()) { |
| 147 | + for (auto itr : (*hcalTPs.product())) { |
| 148 | + int ver = itr.id().version(); |
| 149 | + short ieta = (short)itr.id().ieta(); |
| 150 | + unsigned short absIeta = (unsigned short)abs(ieta); |
| 151 | + unsigned short cal_iphi = (unsigned short)itr.id().iphi(); |
| 152 | + unsigned short iphi = (72 + 18 - cal_iphi) % 72; |
| 153 | + |
| 154 | + unsigned short compEt = itr.SOI_compressedEt(); |
| 155 | + double et = decoder->hcaletValue(itr.id(), itr.t0()); |
| 156 | + unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain(); |
| 157 | + |
| 158 | + if (compEt > 0 && (absIeta < 29 || ver == 1)) { |
| 159 | + hcalTPieta.push_back(ieta); |
| 160 | + hcalTPCaliphi.push_back(cal_iphi); |
| 161 | + hcalTPiphi.push_back(iphi); |
| 162 | + hcalTPet.push_back(et); |
| 163 | + hcalTPcompEt.push_back(compEt); |
| 164 | + hcalTPfineGrain.push_back(fineGrain); |
| 165 | + nHCALTP++; |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + auto hcalTPTable = std::make_unique<nanoaod::FlatTable>(nHCALTP, hcalTPsName_, false); |
| 171 | + hcalTPTable->addColumn<int16_t>("ieta", hcalTPieta, ""); |
| 172 | + hcalTPTable->addColumn<int16_t>("Caliphi", hcalTPCaliphi, ""); |
| 173 | + hcalTPTable->addColumn<int16_t>("iphi", hcalTPiphi, ""); |
| 174 | + hcalTPTable->addColumn<float>("et", hcalTPet, "", 12); |
| 175 | + hcalTPTable->addColumn<int16_t>("compEt", hcalTPcompEt, ""); |
| 176 | + hcalTPTable->addColumn<int16_t>("fineGrain", hcalTPfineGrain, ""); |
| 177 | + |
| 178 | + iEvent.put(std::move(ecalTPTable), "HcalTP"); |
| 179 | + iEvent.put(std::move(hcalTPTable), "EcalTP"); |
| 180 | +} |
| 181 | + |
| 182 | +// ------------ method called once each stream before processing any runs, lumis or events ------------ |
| 183 | +void CaloTPTableProducer::beginStream(edm::StreamID) { |
| 184 | + // please remove this method if not needed |
| 185 | +} |
| 186 | + |
| 187 | +// ------------ method called once each stream after processing all runs, lumis and events ------------ |
| 188 | +void CaloTPTableProducer::endStream() { |
| 189 | + // please remove this method if not needed |
| 190 | +} |
| 191 | + |
| 192 | +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ |
| 193 | +void CaloTPTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 194 | + edm::ParameterSetDescription desc; |
| 195 | + |
| 196 | + desc.add<std::string>("name", "l1calotowerflattableproducer"); |
| 197 | + desc.addUntracked<double>("ecalLSB", 0.5); |
| 198 | + desc.add<edm::InputTag>("ecalTPsSrc", edm::InputTag{"ecalDigis", "EcalTriggerPrimitives"}); |
| 199 | + desc.add<string>("ecalTPsName", "EcalUnpackedTPs"); |
| 200 | + desc.add<edm::InputTag>("hcalTPsSrc", edm::InputTag{"hcalDigis"}); |
| 201 | + desc.add<string>("hcalTPsName", "HcalUnpackedTPs"); |
| 202 | + |
| 203 | + descriptions.addWithDefaultLabel(desc); |
| 204 | +} |
| 205 | + |
| 206 | +//define this as a plug-in |
| 207 | +DEFINE_FWK_MODULE(CaloTPTableProducer); |
0 commit comments