CMS 3D CMS Logo

Phase2L1CaloPFClusterEmulator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1CaloTrigger
4 // Class: Phase2L1CaloPFClusterEmulator
5 //
13 //
14 // Original Author: Pallabi Das
15 // Created: Wed, 21 Sep 2022 14:54:20 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
36 
37 #include <ap_int.h>
38 #include <fstream>
39 #include <iomanip>
40 #include <iostream>
41 #include <cstdio>
43 
44 //
45 // class declaration
46 //
47 
49 public:
51  ~Phase2L1CaloPFClusterEmulator() override = default;
52 
53  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
54 
55 private:
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58  // ----------member data ---------------------------
60 };
61 
62 //
63 // constructors and destructor
64 //
66  : caloTowerToken_(consumes<l1tp2::CaloTowerCollection>(iConfig.getParameter<edm::InputTag>("gctFullTowers"))) {
67  produces<l1tp2::CaloPFClusterCollection>("GCTPFCluster");
68 }
69 
70 //
71 // member functions
72 //
73 
74 // ------------ method called to produce the data ------------
76  using namespace edm;
77  std::unique_ptr<l1tp2::CaloPFClusterCollection> pfclusterCands(make_unique<l1tp2::CaloPFClusterCollection>());
78 
79  edm::Handle<std::vector<l1tp2::CaloTower>> caloTowerCollection;
80  iEvent.getByToken(caloTowerToken_, caloTowerCollection);
81  if (!caloTowerCollection.isValid())
82  cms::Exception("Phase2L1CaloPFClusterEmulator") << "Failed to get towers from caloTowerCollection!";
83 
84  float GCTintTowers[nTowerEta][nTowerPhi];
85  float realEta[nTowerEta][nTowerPhi];
86  float realPhi[nTowerEta][nTowerPhi];
87  for (const l1tp2::CaloTower& i : *caloTowerCollection) {
88  int ieta = i.towerIEta();
89  int iphi = i.towerIPhi();
90  GCTintTowers[ieta][iphi] = i.ecalTowerEt();
91  realEta[ieta][iphi] = i.towerEta();
92  realPhi[ieta][iphi] = i.towerPhi();
93  }
94 
96 
97  for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
98  for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
99  for (int k = 0; k < nSLR; k++) {
100  regions[k][ieta][iphi] = 0.;
101  }
102  }
103  }
104 
105  //Assign ETs to 36 21x8 regions
106 
107  for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
108  for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
109  if (ieta > 1) {
110  if (iphi > 1)
111  regions[0][ieta][iphi] = GCTintTowers[ieta - 2][iphi - 2];
112  for (int k = 1; k < 17; k++) {
113  regions[k * 2][ieta][iphi] = GCTintTowers[ieta - 2][iphi + k * 4 - 2];
114  }
115  if (iphi < 6)
116  regions[34][ieta][iphi] = GCTintTowers[ieta - 2][iphi + 66];
117  }
118  if (ieta < 19) {
119  if (iphi > 1)
120  regions[1][ieta][iphi] = GCTintTowers[ieta + 15][iphi - 2];
121  for (int k = 1; k < 17; k++) {
122  regions[k * 2 + 1][ieta][iphi] = GCTintTowers[ieta + 15][iphi + k * 4 - 2];
123  }
124  if (iphi < 6)
125  regions[35][ieta][iphi] = GCTintTowers[ieta + 15][iphi + 66];
126  }
127  }
128  }
129 
130  float temporary[nTowerEtaSLR][nTowerPhiSLR];
131  int etaoffset = 0;
132  int phioffset = 0;
133 
134  //Use same code from firmware for finding clusters
135  for (int k = 0; k < nSLR; k++) {
136  for (int ieta = 0; ieta < nTowerEtaSLR; ieta++) {
137  for (int iphi = 0; iphi < nTowerPhiSLR; iphi++) {
138  temporary[ieta][iphi] = regions[k][ieta][iphi];
139  }
140  }
141  if (k % 2 == 0)
142  etaoffset = 0;
143  else
144  etaoffset = 17;
145  if (k > 1 && k % 2 == 0)
146  phioffset = phioffset + 4;
147 
148  gctpf::PFcluster_t tempPfclusters;
149  tempPfclusters = gctpf::pfcluster(temporary, etaoffset, phioffset);
150 
151  for (int i = 0; i < nPFClusterSLR; i++) {
152  int gcteta = tempPfclusters.GCTpfclusters[i].eta;
153  int gctphi = tempPfclusters.GCTpfclusters[i].phi;
154  float towereta = realEta[gcteta][gctphi];
155  float towerphi = realPhi[gcteta][gctphi];
156  l1tp2::CaloPFCluster l1CaloPFCluster;
157  l1CaloPFCluster.setClusterEt(tempPfclusters.GCTpfclusters[i].et);
158  l1CaloPFCluster.setClusterIEta(gcteta);
159  l1CaloPFCluster.setClusterIPhi(gctphi);
160  l1CaloPFCluster.setClusterEta(towereta);
161  l1CaloPFCluster.setClusterPhi(towerphi);
162  pfclusterCands->push_back(l1CaloPFCluster);
163  }
164  }
165 
166  iEvent.put(std::move(pfclusterCands), "GCTPFCluster");
167 }
168 
169 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
172  desc.add<edm::InputTag>("gctFullTowers", edm::InputTag("l1tPhase2L1CaloEGammaEmulator", "GCTFullTowers"));
173  descriptions.addWithDefaultLabel(desc);
174 }
175 
176 //define this as a plug-in
void setClusterEta(float clusterEtaIn)
Definition: CaloPFCluster.h:43
const edm::EDGetTokenT< l1tp2::CaloTowerCollection > caloTowerToken_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
static constexpr int nPFClusterSLR
void setClusterIPhi(int clusterIPhiIn)
Definition: CaloPFCluster.h:42
~Phase2L1CaloPFClusterEmulator() override=default
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static constexpr int nSLR
int iEvent
Definition: GenABIO.cc:224
GCTpfcluster_t GCTpfclusters[nPFClusterSLR]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static constexpr int nTowerEtaSLR
static constexpr int nTowerEta
PFcluster_t pfcluster(float temporary[nTowerEtaSLR][nTowerPhiSLR], int etaoffset, int phioffset)
static constexpr int nTowerPhiSLR
Phase2L1CaloPFClusterEmulator(const edm::ParameterSet &)
static constexpr int nTowerPhi
bool isValid() const
Definition: HandleBase.h:70
void produce(edm::Event &, const edm::EventSetup &) override
HLT enums.
void setClusterPhi(float clusterPhiIn)
Definition: CaloPFCluster.h:44
void setClusterIEta(int clusterIEtaIn)
Definition: CaloPFCluster.h:41
def move(src, dest)
Definition: eostools.py:511
void setClusterEt(float clusterEtIn)
Definition: CaloPFCluster.h:40