|
| 1 | +// |
| 2 | +// L1TZDCEtSumsProducer |
| 3 | +// EDProducer to compute the ZDC l1t::EtSums from HCAL trigger primitives |
| 4 | +// |
| 5 | +// Original author: Chris McGinn |
| 6 | + |
| 7 | +// cfmcginn on github for bugs/issues |
| 8 | +// |
| 9 | +#include <algorithm> |
| 10 | +#include <array> |
| 11 | +#include <memory> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +#include "DataFormats/L1Trigger/interface/EtSum.h" |
| 15 | +#include "DataFormats/HcalDigi/interface/HcalDigiCollections.h" |
| 16 | + |
| 17 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 18 | +#include "FWCore/Framework/interface/global/EDProducer.h" |
| 19 | +#include "FWCore/Framework/interface/Event.h" |
| 20 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 21 | +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" |
| 22 | +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" |
| 23 | +#include "FWCore/Utilities/interface/EDGetToken.h" |
| 24 | +#include "FWCore/Utilities/interface/InputTag.h" |
| 25 | + |
| 26 | +#include "L1Trigger/L1TCalorimeter/interface/CaloTools.h" |
| 27 | + |
| 28 | +class L1TZDCEtSumsProducer : public edm::global::EDProducer<> { |
| 29 | +public: |
| 30 | + explicit L1TZDCEtSumsProducer(edm::ParameterSet const&); |
| 31 | + |
| 32 | + static void fillDescriptions(edm::ConfigurationDescriptions&); |
| 33 | + |
| 34 | +private: |
| 35 | + void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override; |
| 36 | + |
| 37 | + edm::EDGetTokenT<HcalTrigPrimDigiCollection> const hcalTPDigisToken_; |
| 38 | + |
| 39 | + int const bxFirst_; |
| 40 | + int const bxLast_; |
| 41 | + |
| 42 | + static constexpr int kZDCAbsIEta = 42; |
| 43 | + static constexpr int kZDCiEtSumsIPhi = 99; |
| 44 | + static constexpr int kZDCiEtSumMaxValue = 1023; |
| 45 | +}; |
| 46 | + |
| 47 | +L1TZDCEtSumsProducer::L1TZDCEtSumsProducer(edm::ParameterSet const& ps) |
| 48 | + : hcalTPDigisToken_{consumes(ps.getParameter<edm::InputTag>("hcalTPDigis"))}, |
| 49 | + bxFirst_{ps.getParameter<int>("bxFirst")}, |
| 50 | + bxLast_{ps.getParameter<int>("bxLast")} { |
| 51 | + produces<l1t::EtSumBxCollection>(); |
| 52 | +} |
| 53 | + |
| 54 | +void L1TZDCEtSumsProducer::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const { |
| 55 | + auto outZDCEtSums = std::make_unique<l1t::EtSumBxCollection>(0, bxFirst_, bxLast_); |
| 56 | + |
| 57 | + auto const hcalTPs = iEvent.getHandle(hcalTPDigisToken_); |
| 58 | + |
| 59 | + if (not hcalTPs.isValid()) { |
| 60 | + edm::LogWarning("L1TZDCEtSumsProducer") << "Invalid handle to HcalTrigPrimDigiCollection collection" |
| 61 | + << ": returning empty l1t::EtSumBxCollection for ZDC EtSums !"; |
| 62 | + } else if (bxFirst_ > bxLast_) { |
| 63 | + edm::LogWarning("L1TZDCEtSumsProducer") |
| 64 | + << "Invalid configuration parameters (bxFirst [" << bxFirst_ << "] > bxLast [" << bxLast_ |
| 65 | + << "]): returning empty l1t::EtSumBxCollection for ZDC EtSums !"; |
| 66 | + } else { |
| 67 | + // number of bunch crossings |
| 68 | + unsigned int const nBXs = (bxLast_ - bxFirst_) + 1; |
| 69 | + |
| 70 | + // iEtSums as taken directly from the ZDC iEtSum TPs (iphi == 99) |
| 71 | + std::vector<std::array<int, 2>> iEtSumsFromEtSumTPs{nBXs, {{0, 0}}}; |
| 72 | + |
| 73 | + // iEtSums recomputed from the ZDC non-iEtSums TPs (iphi != 99) |
| 74 | + std::vector<std::array<int, 2>> iEtSumsFromOtherTPs{nBXs, {{0, 0}}}; |
| 75 | + |
| 76 | + // unsigned integers indicating which iEtSums are available for a given BX |
| 77 | + // - Bit #1 (0b01): iEtSums as taken directly from the ZDC iEtSum TPs |
| 78 | + // - Bit #2 (0b10): iEtSums recomputed from the ZDC non-iEtSums TPs |
| 79 | + std::vector<std::array<unsigned int, 2>> iEtSumsFillFlags{nBXs, {{0, 0}}}; |
| 80 | + |
| 81 | + for (auto const& hcalTp : *hcalTPs) { |
| 82 | + // absIEta position 42 is used for the ZDC (-42 for ZDCM, +42 for ZDCP) |
| 83 | + auto const ieta = hcalTp.id().ieta(); |
| 84 | + auto const absIEta = std::abs(ieta); |
| 85 | + |
| 86 | + if (absIEta != kZDCAbsIEta) { |
| 87 | + continue; |
| 88 | + } |
| 89 | + |
| 90 | + // ZDC "index": 0 for ZDCM, 1 for ZDCP |
| 91 | + auto const zdcIndex = (ieta < 0) ? 0 : 1; |
| 92 | + |
| 93 | + // For ZDC, iphi position 99 is used for iEtSum TPs |
| 94 | + auto const iphi = hcalTp.id().iphi(); |
| 95 | + auto const isZDCiEtSum = (iphi == kZDCiEtSumsIPhi); |
| 96 | + |
| 97 | + // Number of samples, and number of presamples (nPresamples is BX=0) |
| 98 | + int const nSamples = hcalTp.size(); |
| 99 | + int const nPresamples = hcalTp.presamples(); |
| 100 | + |
| 101 | + for (auto iSample = 0; iSample < nSamples; ++iSample) { |
| 102 | + auto const ibx = iSample - nPresamples; |
| 103 | + if (ibx >= bxFirst_ and ibx <= bxLast_) { |
| 104 | + auto const& hcalTpSample = hcalTp.sample(iSample); |
| 105 | + auto const ietIn = hcalTpSample.raw() & kZDCiEtSumMaxValue; |
| 106 | + auto const bxIndex = ibx - bxFirst_; |
| 107 | + if (isZDCiEtSum) { |
| 108 | + iEtSumsFromEtSumTPs[bxIndex][zdcIndex] = ietIn; |
| 109 | + iEtSumsFillFlags[bxIndex][zdcIndex] |= 0b01; |
| 110 | + } else { |
| 111 | + iEtSumsFromOtherTPs[bxIndex][zdcIndex] += ietIn; |
| 112 | + iEtSumsFillFlags[bxIndex][zdcIndex] |= 0b10; |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + for (unsigned int bxIndex = 0; bxIndex < nBXs; ++bxIndex) { |
| 119 | + int const bx = bxIndex + bxFirst_; |
| 120 | + for (unsigned int zdcIndex = 0; zdcIndex < 2; ++zdcIndex) { |
| 121 | + int zdc_hwPt{0}; |
| 122 | + // Option #1: take iEtSum from the ZDC iEtSum TP |
| 123 | + if (iEtSumsFillFlags[bxIndex][zdcIndex] & 0b01) { |
| 124 | + zdc_hwPt = iEtSumsFromEtSumTPs[bxIndex][zdcIndex]; |
| 125 | + } |
| 126 | + // Option #2: take iEtSum recomputed from the ZDC non-iEtSums TPs |
| 127 | + else if (iEtSumsFillFlags[bxIndex][zdcIndex] & 0b10) { |
| 128 | + // recomputed sum cannot be higher than kZDCiEtSumMaxValue |
| 129 | + zdc_hwPt = std::min(iEtSumsFromOtherTPs[bxIndex][zdcIndex], kZDCiEtSumMaxValue); |
| 130 | + } |
| 131 | + // Skip if no iEtSum value is available for this BX |
| 132 | + else { |
| 133 | + continue; |
| 134 | + } |
| 135 | + |
| 136 | + int const zdc_hwEta = (zdcIndex == 0) ? -1 : 1; |
| 137 | + |
| 138 | + auto const zdc_type = (zdcIndex == 0) ? l1t::EtSum::EtSumType::kZDCM : l1t::EtSum::EtSumType::kZDCP; |
| 139 | + |
| 140 | + l1t::EtSum zdc_etSum{}; |
| 141 | + zdc_etSum.setHwPt(zdc_hwPt); |
| 142 | + zdc_etSum.setHwEta(zdc_hwEta); |
| 143 | + zdc_etSum.setHwPhi(0); |
| 144 | + zdc_etSum.setType(zdc_type); |
| 145 | + |
| 146 | + outZDCEtSums->push_back(bx, l1t::CaloTools::etSumP4Demux(zdc_etSum)); |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + iEvent.put(std::move(outZDCEtSums)); |
| 152 | +} |
| 153 | + |
| 154 | +void L1TZDCEtSumsProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { |
| 155 | + edm::ParameterSetDescription desc; |
| 156 | + desc.add<edm::InputTag>("hcalTPDigis", edm::InputTag("simHcalTriggerPrimitiveDigis")); |
| 157 | + desc.add<int>("bxFirst", -2); |
| 158 | + desc.add<int>("bxLast", 2); |
| 159 | + descriptions.add("l1tZDCEtSumsProducer", desc); |
| 160 | +} |
| 161 | + |
| 162 | +#include "FWCore/Framework/interface/MakerMacros.h" |
| 163 | +DEFINE_FWK_MODULE(L1TZDCEtSumsProducer); |
0 commit comments