File indexing completed on 2023-03-17 11:12:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022 #include <fstream>
0023
0024
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034
0035 #include "DataFormats/L1TMuon/interface/MuonCaloSumFwd.h"
0036 #include "DataFormats/L1TMuon/interface/MuonCaloSum.h"
0037 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0038
0039 #include "TMath.h"
0040 #include "TRandom3.h"
0041
0042
0043
0044
0045 using namespace l1t;
0046
0047 class L1TMuonCaloSumProducer : public edm::stream::EDProducer<> {
0048 public:
0049 explicit L1TMuonCaloSumProducer(const edm::ParameterSet&);
0050 ~L1TMuonCaloSumProducer() override;
0051
0052 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0053
0054 private:
0055 void produce(edm::Event&, const edm::EventSetup&) override;
0056
0057 void beginRun(const edm::Run&, edm::EventSetup const&) override;
0058 void endRun(const edm::Run&, edm::EventSetup const&) override;
0059 void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0060 void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0061
0062 edm::EDGetTokenT<CaloTowerBxCollection> m_caloTowerToken;
0063 edm::InputTag m_caloLabel;
0064 };
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 L1TMuonCaloSumProducer::L1TMuonCaloSumProducer(const edm::ParameterSet& iConfig) {
0078
0079 m_caloLabel = iConfig.getParameter<edm::InputTag>("caloStage2Layer2Label");
0080 m_caloTowerToken = consumes<CaloTowerBxCollection>(m_caloLabel);
0081
0082 produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0083 produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
0084 }
0085
0086 L1TMuonCaloSumProducer::~L1TMuonCaloSumProducer() {
0087
0088
0089 }
0090
0091
0092
0093
0094
0095
0096 void L1TMuonCaloSumProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0097 using namespace edm;
0098 std::unique_ptr<MuonCaloSumBxCollection> towerSums(std::make_unique<MuonCaloSumBxCollection>());
0099 std::unique_ptr<MuonCaloSumBxCollection> tower2x2s(std::make_unique<MuonCaloSumBxCollection>());
0100
0101 edm::Handle<CaloTowerBxCollection> caloTowers;
0102
0103 if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
0104 int detamax = 4;
0105 int dphimax = 4;
0106
0107 const int iFirstBx = caloTowers->getFirstBX();
0108 const int iLastBx = caloTowers->getLastBX();
0109
0110
0111 towerSums->setBXRange(iFirstBx, iLastBx);
0112 tower2x2s->setBXRange(iFirstBx, iLastBx);
0113
0114 for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
0115 std::map<int, MuonCaloSum> sums;
0116 std::map<int, MuonCaloSum> regs;
0117
0118 for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
0119 const CaloTower& twr = *it;
0120 int hwEta = twr.hwEta();
0121 if (std::abs(hwEta) > 27) {
0122 continue;
0123 }
0124 int hwPt = twr.hwPt();
0125 if (hwPt < 1) {
0126 continue;
0127 }
0128 int hwPhi = twr.hwPhi();
0129
0130
0131 int ieta2x2 = (hwEta + 27) / 2;
0132 int iphi2x2 = hwPhi / 2;
0133 int muon_idx = iphi2x2 * 28 + ieta2x2;
0134 if (regs.count(muon_idx) == 0) {
0135 regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
0136 } else {
0137 regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
0138 }
0139
0140
0141
0142
0143 int ietamax = hwEta + detamax + 1;
0144 for (int ieta = hwEta - detamax; ieta < ietamax; ++ieta) {
0145 if (std::abs(ieta) > 27) {
0146 continue;
0147 }
0148 int ietamu = (ieta + 27) / 2;
0149 int iphimax = hwPhi + dphimax + 1;
0150 for (int iphi = hwPhi - dphimax; iphi < iphimax; ++iphi) {
0151 int iphiwrapped = iphi;
0152 if (iphiwrapped < 0) {
0153 iphiwrapped += 72;
0154 } else if (iphiwrapped > 71) {
0155 iphiwrapped -= 72;
0156 }
0157 int iphimu = iphiwrapped / 2;
0158 int idxmu = iphimu * 28 + ietamu;
0159 if (sums.count(idxmu) == 0) {
0160 sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
0161 } else {
0162 sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
0163 }
0164 }
0165 }
0166 }
0167
0168
0169 for (auto it = sums.begin(); it != sums.end(); ++it) {
0170 if (it->second.etBits() > 0) {
0171 MuonCaloSum sum = MuonCaloSum(it->second);
0172
0173 if (sum.etBits() > 31) {
0174 sum.setEtBits(31);
0175 }
0176 towerSums->push_back(bx, sum);
0177 }
0178 }
0179
0180 for (auto it = regs.begin(); it != regs.end(); ++it) {
0181 if (it->second.etBits() > 0) {
0182 tower2x2s->push_back(bx, it->second);
0183 }
0184 }
0185 }
0186 } else {
0187 LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
0188 }
0189
0190 iEvent.put(std::move(towerSums), "TriggerTowerSums");
0191 iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
0192 }
0193
0194
0195 void L1TMuonCaloSumProducer::beginRun(const edm::Run&, edm::EventSetup const&) {}
0196
0197
0198 void L1TMuonCaloSumProducer::endRun(const edm::Run&, edm::EventSetup const&) {}
0199
0200
0201 void L1TMuonCaloSumProducer::beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0202
0203
0204 void L1TMuonCaloSumProducer::endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0205
0206
0207 void L1TMuonCaloSumProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0208
0209
0210 edm::ParameterSetDescription desc;
0211 desc.setUnknown();
0212 descriptions.addDefault(desc);
0213 }
0214
0215
0216 DEFINE_FWK_MODULE(L1TMuonCaloSumProducer);