File indexing completed on 2024-04-09 02:22:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
0024 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
0025
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/stream/EDProducer.h"
0028
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/StreamID.h"
0034
0035 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0036
0037 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0038 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0039
0040 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0041 #include "DataFormats/L1TCalorimeter/interface/CaloCluster.h"
0042
0043 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0044 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0045
0046
0047
0048
0049
0050 class CaloTPTableProducer : public edm::stream::EDProducer<> {
0051 public:
0052 explicit CaloTPTableProducer(const edm::ParameterSet&);
0053
0054 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0055
0056 private:
0057 void beginStream(edm::StreamID) override;
0058 void produce(edm::Event&, const edm::EventSetup&) override;
0059 void endStream() override;
0060
0061
0062 const double ecalLSB_;
0063
0064 const edm::EDGetTokenT<EcalTrigPrimDigiCollection> ecalTPsToken_;
0065 const std::string ecalTPsName_;
0066
0067 const edm::EDGetTokenT<HcalTrigPrimDigiCollection> hcalTPsToken_;
0068 const std::string hcalTPsName_;
0069
0070 const edm::ESGetToken<CaloTPGTranscoder, CaloTPGRecord> decoderToken_;
0071 };
0072
0073 CaloTPTableProducer::CaloTPTableProducer(const edm::ParameterSet& iConfig)
0074 : ecalLSB_(iConfig.getUntrackedParameter<double>("ecalLSB", 0.5)),
0075 ecalTPsToken_(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalTPsSrc"))),
0076 ecalTPsName_(iConfig.getParameter<std::string>("ecalTPsName")),
0077 hcalTPsToken_(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalTPsSrc"))),
0078 hcalTPsName_(iConfig.getParameter<std::string>("hcalTPsName")),
0079 decoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()) {
0080 produces<nanoaod::FlatTable>("EcalTP");
0081 produces<nanoaod::FlatTable>("HcalTP");
0082
0083
0084 }
0085
0086
0087
0088
0089
0090
0091 void CaloTPTableProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0092 using namespace edm;
0093
0094 edm::ESHandle<CaloTPGTranscoder> decoder;
0095 decoder = iSetup.getHandle(decoderToken_);
0096
0097 edm::Handle<EcalTrigPrimDigiCollection> ecalTPs;
0098 iEvent.getByToken(ecalTPsToken_, ecalTPs);
0099
0100 edm::Handle<HcalTrigPrimDigiCollection> hcalTPs;
0101 iEvent.getByToken(hcalTPsToken_, hcalTPs);
0102
0103 vector<int> ecalTPieta;
0104 vector<int> ecalTPCaliphi;
0105 vector<int> ecalTPiphi;
0106 vector<float> ecalTPet;
0107 vector<int> ecalTPcompEt;
0108 vector<int> ecalTPfineGrain;
0109 int nECALTP(0);
0110 if (ecalTPs.isValid()) {
0111 for (const auto& itr : *(ecalTPs.product())) {
0112 short ieta = (short)itr.id().ieta();
0113
0114 unsigned short cal_iphi = (unsigned short)itr.id().iphi();
0115 unsigned short iphi = (72 + 18 - cal_iphi) % 72;
0116 unsigned short compEt = itr.compressedEt();
0117 double et = ecalLSB_ * compEt;
0118 unsigned short fineGrain = (unsigned short)itr.fineGrain();
0119
0120 if (compEt > 0) {
0121 ecalTPieta.push_back(ieta);
0122 ecalTPCaliphi.push_back(cal_iphi);
0123 ecalTPiphi.push_back(iphi);
0124 ecalTPet.push_back(et);
0125 ecalTPcompEt.push_back(compEt);
0126 ecalTPfineGrain.push_back(fineGrain);
0127 nECALTP++;
0128 }
0129 }
0130 }
0131 auto ecalTPTable = std::make_unique<nanoaod::FlatTable>(nECALTP, ecalTPsName_, false);
0132 ecalTPTable->addColumn<int16_t>("ieta", ecalTPieta, "");
0133 ecalTPTable->addColumn<int16_t>("Caliphi", ecalTPCaliphi, "");
0134 ecalTPTable->addColumn<int16_t>("iphi", ecalTPiphi, "");
0135 ecalTPTable->addColumn<float>("et", ecalTPet, "", 12);
0136 ecalTPTable->addColumn<int16_t>("compEt", ecalTPcompEt, "");
0137 ecalTPTable->addColumn<int16_t>("fineGrain", ecalTPfineGrain, "");
0138
0139 vector<int> hcalTPieta;
0140 vector<int> hcalTPCaliphi;
0141 vector<int> hcalTPiphi;
0142 vector<float> hcalTPet;
0143 vector<int> hcalTPcompEt;
0144 vector<int> hcalTPfineGrain;
0145 int nHCALTP(0);
0146 if (hcalTPs.isValid()) {
0147 for (auto itr : (*hcalTPs.product())) {
0148 int ver = itr.id().version();
0149 short ieta = (short)itr.id().ieta();
0150 unsigned short absIeta = (unsigned short)abs(ieta);
0151 unsigned short cal_iphi = (unsigned short)itr.id().iphi();
0152 unsigned short iphi = (72 + 18 - cal_iphi) % 72;
0153
0154 unsigned short compEt = itr.SOI_compressedEt();
0155 double et = decoder->hcaletValue(itr.id(), itr.t0());
0156 unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain();
0157
0158 if (compEt > 0 && (absIeta < 29 || ver == 1)) {
0159 hcalTPieta.push_back(ieta);
0160 hcalTPCaliphi.push_back(cal_iphi);
0161 hcalTPiphi.push_back(iphi);
0162 hcalTPet.push_back(et);
0163 hcalTPcompEt.push_back(compEt);
0164 hcalTPfineGrain.push_back(fineGrain);
0165 nHCALTP++;
0166 }
0167 }
0168 }
0169
0170 auto hcalTPTable = std::make_unique<nanoaod::FlatTable>(nHCALTP, hcalTPsName_, false);
0171 hcalTPTable->addColumn<int16_t>("ieta", hcalTPieta, "");
0172 hcalTPTable->addColumn<int16_t>("Caliphi", hcalTPCaliphi, "");
0173 hcalTPTable->addColumn<int16_t>("iphi", hcalTPiphi, "");
0174 hcalTPTable->addColumn<float>("et", hcalTPet, "", 12);
0175 hcalTPTable->addColumn<int16_t>("compEt", hcalTPcompEt, "");
0176 hcalTPTable->addColumn<int16_t>("fineGrain", hcalTPfineGrain, "");
0177
0178 iEvent.put(std::move(ecalTPTable), "HcalTP");
0179 iEvent.put(std::move(hcalTPTable), "EcalTP");
0180 }
0181
0182
0183 void CaloTPTableProducer::beginStream(edm::StreamID) {
0184
0185 }
0186
0187
0188 void CaloTPTableProducer::endStream() {
0189
0190 }
0191
0192
0193 void CaloTPTableProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0194 edm::ParameterSetDescription desc;
0195
0196 desc.add<std::string>("name", "l1calotowerflattableproducer");
0197 desc.addUntracked<double>("ecalLSB", 0.5);
0198 desc.add<edm::InputTag>("ecalTPsSrc", edm::InputTag{"ecalDigis", "EcalTriggerPrimitives"});
0199 desc.add<string>("ecalTPsName", "EcalUnpackedTPs");
0200 desc.add<edm::InputTag>("hcalTPsSrc", edm::InputTag{"hcalDigis"});
0201 desc.add<string>("hcalTPsName", "HcalUnpackedTPs");
0202
0203 descriptions.addWithDefaultLabel(desc);
0204 }
0205
0206
0207 DEFINE_FWK_MODULE(CaloTPTableProducer);