File indexing completed on 2024-04-06 12:20:11
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 "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include "DataFormats/L1TCalorimeterPhase2/interface/CaloCrystalCluster.h"
0033 #include "DataFormats/L1TCalorimeterPhase2/interface/CaloTower.h"
0034 #include "DataFormats/L1TCalorimeterPhase2/interface/CaloPFCluster.h"
0035 #include "DataFormats/L1Trigger/interface/EGamma.h"
0036
0037 #include <ap_int.h>
0038 #include <fstream>
0039 #include <iomanip>
0040 #include <iostream>
0041 #include <cstdio>
0042 #include "L1Trigger/L1CaloTrigger/interface/Phase2L1CaloPFClusterEmulator.h"
0043
0044
0045
0046
0047
0048 class Phase2L1CaloPFClusterEmulator : public edm::stream::EDProducer<> {
0049 public:
0050 explicit Phase2L1CaloPFClusterEmulator(const edm::ParameterSet&);
0051 ~Phase2L1CaloPFClusterEmulator() override = default;
0052
0053 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0054
0055 private:
0056 void produce(edm::Event&, const edm::EventSetup&) override;
0057
0058
0059 const edm::EDGetTokenT<l1tp2::CaloTowerCollection> caloTowerToken_;
0060 };
0061
0062
0063
0064
0065 Phase2L1CaloPFClusterEmulator::Phase2L1CaloPFClusterEmulator(const edm::ParameterSet& iConfig)
0066 : caloTowerToken_(consumes<l1tp2::CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("gctFullTowers"))) {
0067 produces<l1tp2::CaloPFClusterCollection>("GCTPFCluster");
0068 }
0069
0070
0071
0072
0073
0074
0075 void Phase2L1CaloPFClusterEmulator::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0076 using namespace edm;
0077 std::unique_ptr<l1tp2::CaloPFClusterCollection> pfclusterCands(make_unique<l1tp2::CaloPFClusterCollection>());
0078
0079 edm::Handle<std::vector<l1tp2::CaloTower>> caloTowerCollection;
0080 iEvent.getByToken(caloTowerToken_, caloTowerCollection);
0081 if (!caloTowerCollection.isValid())
0082 cms::Exception("Phase2L1CaloPFClusterEmulator") << "Failed to get towers from caloTowerCollection!";
0083
0084 float GCTintTowers[nTowerEta][nTowerPhi];
0085 float realEta[nTowerEta][nTowerPhi];
0086 float realPhi[nTowerEta][nTowerPhi];
0087 for (const l1tp2::CaloTower& i : *caloTowerCollection) {
0088 int ieta = i.towerIEta();
0089 int iphi = i.towerIPhi();
0090 GCTintTowers[ieta][iphi] = i.ecalTowerEt();
0091 realEta[ieta][iphi] = i.towerEta();
0092 realPhi[ieta][iphi] = i.towerPhi();
0093 }
0094
0095 float regions[nSLR][nTowerEtaSLR][nTowerPhiSLR];
0096
0097 for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
0098 for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
0099 for (int k = 0; k < nSLR; k++) {
0100 regions[k][ieta][iphi] = 0.;
0101 }
0102 }
0103 }
0104
0105
0106
0107 for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
0108 for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
0109 if (ieta > 1) {
0110 if (iphi > 1)
0111 regions[0][ieta][iphi] = GCTintTowers[ieta - 2][iphi - 2];
0112 for (int k = 1; k < 17; k++) {
0113 regions[k * 2][ieta][iphi] = GCTintTowers[ieta - 2][iphi + k * 4 - 2];
0114 }
0115 if (iphi < 6)
0116 regions[34][ieta][iphi] = GCTintTowers[ieta - 2][iphi + 66];
0117 }
0118 if (ieta < 19) {
0119 if (iphi > 1)
0120 regions[1][ieta][iphi] = GCTintTowers[ieta + 15][iphi - 2];
0121 for (int k = 1; k < 17; k++) {
0122 regions[k * 2 + 1][ieta][iphi] = GCTintTowers[ieta + 15][iphi + k * 4 - 2];
0123 }
0124 if (iphi < 6)
0125 regions[35][ieta][iphi] = GCTintTowers[ieta + 15][iphi + 66];
0126 }
0127 }
0128 }
0129
0130 float temporary[nTowerEtaSLR][nTowerPhiSLR];
0131 int etaoffset = 0;
0132 int phioffset = 0;
0133
0134
0135 for (int k = 0; k < nSLR; k++) {
0136 for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
0137 for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
0138 temporary[ieta][iphi] = regions[k][ieta][iphi];
0139 }
0140 }
0141 if (k % 2 == 0)
0142 etaoffset = 0;
0143 else
0144 etaoffset = 17;
0145 if (k > 1 && k % 2 == 0)
0146 phioffset = phioffset + 4;
0147
0148 gctpf::PFcluster_t tempPfclusters;
0149 tempPfclusters = gctpf::pfcluster(temporary, etaoffset, phioffset);
0150
0151 for (int i = 0; i < nPFClusterSLR; i++) {
0152 int gcteta = tempPfclusters.GCTpfclusters[i].eta;
0153 int gctphi = tempPfclusters.GCTpfclusters[i].phi;
0154 float towereta = realEta[gcteta][gctphi];
0155 float towerphi = realPhi[gcteta][gctphi];
0156 l1tp2::CaloPFCluster l1CaloPFCluster;
0157 l1CaloPFCluster.setClusterEt(tempPfclusters.GCTpfclusters[i].et);
0158 l1CaloPFCluster.setClusterIEta(gcteta);
0159 l1CaloPFCluster.setClusterIPhi(gctphi);
0160 l1CaloPFCluster.setClusterEta(towereta);
0161 l1CaloPFCluster.setClusterPhi(towerphi);
0162 pfclusterCands->push_back(l1CaloPFCluster);
0163 }
0164 }
0165
0166 iEvent.put(std::move(pfclusterCands), "GCTPFCluster");
0167 }
0168
0169
0170 void Phase2L1CaloPFClusterEmulator::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0171 edm::ParameterSetDescription desc;
0172 desc.add<edm::InputTag>("gctFullTowers", edm::InputTag("l1tPhase2L1CaloEGammaEmulator", "GCTFullTowers"));
0173 descriptions.addWithDefaultLabel(desc);
0174 }
0175
0176
0177 DEFINE_FWK_MODULE(Phase2L1CaloPFClusterEmulator);