CMS 3D CMS Logo

L1TCaloLayer1.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1Trigger/L1TCaloLayer1
4 // Class: L1TCaloLayer1
5 //
13 //
14 // Original Author: Sridhara Rao Dasu
15 // Created: Thu, 08 Oct 2015 09:20:16 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
33 
34 #include "L1Trigger/L1TCaloLayer1/src/UCTLayer1.hh"
35 #include "L1Trigger/L1TCaloLayer1/src/UCTCrate.hh"
36 #include "L1Trigger/L1TCaloLayer1/src/UCTCard.hh"
37 #include "L1Trigger/L1TCaloLayer1/src/UCTRegion.hh"
38 #include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh"
39 
40 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
41 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
42 
46 
48 
49 #include "L1Trigger/L1TCaloLayer1/src/L1TCaloLayer1FetchLUTs.hh"
50 
51 using namespace l1t;
52 using namespace l1tcalo;
53 
54 //
55 // class declaration
56 //
57 
59 public:
60  explicit L1TCaloLayer1(const edm::ParameterSet&);
61 
62  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
63 
64 private:
65  void produce(edm::Event&, const edm::EventSetup&) override;
66 
67  void beginRun(edm::Run const&, edm::EventSetup const&) override;
68 
69  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
70  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
71  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
72 
73  // ----------member data ---------------------------
74 
79  const L1TCaloLayer1FetchLUTsTokens lutsTokens;
80 
81  std::vector<std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> > ecalLUT;
82  std::vector<std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> > hcalLUT;
83  std::vector<std::array<std::array<uint32_t, nEtBins>, nHfEtaBins> > hfLUT;
84 
85  std::vector<unsigned int> ePhiMap;
86  std::vector<unsigned int> hPhiMap;
87  std::vector<unsigned int> hfPhiMap;
88 
89  std::vector<UCTTower*> twrList;
90 
91  bool useLSB;
92  bool useCalib;
93  bool useECALLUT;
94  bool useHCALLUT;
95  bool useHFLUT;
96  bool verbose;
99  int fwVersion;
100 
101  std::unique_ptr<UCTLayer1> layer1;
102 };
103 
104 //
105 // constants, enums and typedefs
106 //
107 
108 //
109 // static data member definitions
110 //
111 
112 //
113 // constructors and destructor
114 //
116  : ecalTPSource(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalToken"))),
117  hcalTPSource(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalToken"))),
118  towerPutToken{produces<CaloTowerBxCollection>()},
119  regionPutToken{produces<L1CaloRegionCollection>()},
120  lutsTokens{esConsumes<edm::Transition::BeginRun>(),
121  esConsumes<edm::Transition::BeginRun>(),
122  esConsumes<edm::Transition::BeginRun>()},
123  ePhiMap(72 * 2, 0),
124  hPhiMap(72 * 2, 0),
125  hfPhiMap(72 * 2, 0),
126  useLSB(iConfig.getParameter<bool>("useLSB")),
127  useCalib(iConfig.getParameter<bool>("useCalib")),
128  useECALLUT(iConfig.getParameter<bool>("useECALLUT")),
129  useHCALLUT(iConfig.getParameter<bool>("useHCALLUT")),
130  useHFLUT(iConfig.getParameter<bool>("useHFLUT")),
131  verbose(iConfig.getParameter<bool>("verbose")),
132  unpackHcalMask(iConfig.getParameter<bool>("unpackHcalMask")),
133  unpackEcalMask(iConfig.getParameter<bool>("unpackEcalMask")),
134  fwVersion(iConfig.getParameter<int>("firmwareVersion")) {
135  // See UCTLayer1.hh for firmware version definitions
136  layer1 = std::make_unique<UCTLayer1>(fwVersion);
137 
138  vector<UCTCrate*> crates = layer1->getCrates();
139  for (uint32_t crt = 0; crt < crates.size(); crt++) {
140  vector<UCTCard*> cards = crates[crt]->getCards();
141  for (uint32_t crd = 0; crd < cards.size(); crd++) {
142  vector<UCTRegion*> regions = cards[crd]->getRegions();
143  for (uint32_t rgn = 0; rgn < regions.size(); rgn++) {
144  vector<UCTTower*> towers = regions[rgn]->getTowers();
145  for (uint32_t twr = 0; twr < towers.size(); twr++) {
146  twrList.push_back(towers[twr]);
147  }
148  }
149  }
150  }
151 
152  // This sort corresponds to the sort condition on
153  // the output CaloTowerBxCollection
154  std::sort(twrList.begin(), twrList.end(), [](UCTTower* a, UCTTower* b) {
155  return CaloTools::caloTowerHash(a->caloEta(), a->caloPhi()) < CaloTools::caloTowerHash(b->caloEta(), b->caloPhi());
156  });
157 }
158 
159 //
160 // member functions
161 //
162 
163 // ------------ method called to produce the data ------------
165  using namespace edm;
166 
168  iEvent.getByToken(ecalTPSource, ecalTPs);
170  iEvent.getByToken(hcalTPSource, hcalTPs);
171 
172  CaloTowerBxCollection towersColl;
173  L1CaloRegionCollection rgnCollection;
174 
175  if (!layer1->clearEvent()) {
176  LOG_ERROR << "UCT: Failed to clear event" << std::endl;
177  return;
178  }
179 
180  for (const auto& ecalTp : *ecalTPs) {
181  if (unpackEcalMask && ((ecalTp.sample(0).raw() >> 13) & 0x1))
182  continue;
183  int caloEta = ecalTp.id().ieta();
184  int caloPhi = ecalTp.id().iphi();
185  int et = ecalTp.compressedEt();
186  bool fgVeto = ecalTp.fineGrain();
187  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
188  if (!layer1->setECALData(t, fgVeto, et)) {
189  LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
190  return;
191  }
192  }
193 
194  if (hcalTPs.isValid()) {
195  for (const auto& hcalTp : *hcalTPs) {
196  if (unpackHcalMask && ((hcalTp.sample(0).raw() >> 13) & 0x1))
197  continue;
198  int caloEta = hcalTp.id().ieta();
199  uint32_t absCaloEta = std::abs(caloEta);
200  // Tower 29 is not used by Layer-1
201  if (absCaloEta == 29) {
202  continue;
203  }
204  // Prevent usage of HF TPs with Layer-1 emulator if HCAL TPs are old style
205  else if (hcalTp.id().version() == 0 && absCaloEta > 29) {
206  continue;
207  } else if (absCaloEta <= 41) {
208  int caloPhi = hcalTp.id().iphi();
209  int et = hcalTp.SOI_compressedEt();
210  bool fg = hcalTp.t0().fineGrain(0); // depth
211  bool fg2 = hcalTp.t0().fineGrain(1); // prompt
212  bool fg3 = hcalTp.t0().fineGrain(2); // delay 1
213  bool fg4 = hcalTp.t0().fineGrain(3); // delay 2
214  // note that hcalTp.t0().fineGrain(4) and hcalTp.t0().fineGrain(5) are the reserved MIP bits (not used for LLP logic)
215  if (caloPhi <= 72) {
216  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
217  uint32_t featureBits = 0;
218  if (absCaloEta > 29) {
219  if (fg)
220  featureBits |= 0b01;
221  // fg2 should only be set for HF
222  if (fg2)
223  featureBits |= 0b10;
224  } else if (absCaloEta < 16)
225  featureBits |= (fg | ((!fg2) & (fg3 | fg4))); // depth | (!prompt & (delay1 | delay2))
226  if (!layer1->setHCALData(t, featureBits, et)) {
227  LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
228  LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
229  return;
230  }
231  } else {
232  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << "; et = " << et
233  << std::endl;
234  }
235  } else {
236  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << std::endl;
237  }
238  }
239  }
240 
241  //Process
242  if (!layer1->process()) {
243  LOG_ERROR << "UCT: Failed to process layer 1" << std::endl;
244  }
245 
246  int theBX = 0; // Currently we only read and process the "hit" BX only
247 
248  for (uint32_t twr = 0; twr < twrList.size(); twr++) {
249  CaloTower caloTower;
250  caloTower.setHwPt(twrList[twr]->et()); // Bits 0-8 of the 16-bit word per the interface protocol document
251  caloTower.setHwEtRatio(twrList[twr]->er()); // Bits 9-11 of the 16-bit word per the interface protocol document
252  caloTower.setHwQual(twrList[twr]->miscBits()); // Bits 12-15 of the 16-bit word per the interface protocol document
253  caloTower.setHwEta(twrList[twr]->caloEta()); // caloEta = 1-28 and 30-41
254  caloTower.setHwPhi(twrList[twr]->caloPhi()); // caloPhi = 1-72
255  caloTower.setHwEtEm(twrList[twr]->getEcalET()); // This is provided as a courtesy - not available to hardware
256  caloTower.setHwEtHad(twrList[twr]->getHcalET()); // This is provided as a courtesy - not available to hardware
257  towersColl.push_back(theBX, caloTower);
258  }
259 
260  iEvent.emplace(towerPutToken, std::move(towersColl));
261 
262  UCTGeometry g;
263  vector<UCTCrate*> crates = layer1->getCrates();
264  for (uint32_t crt = 0; crt < crates.size(); crt++) {
265  vector<UCTCard*> cards = crates[crt]->getCards();
266  for (uint32_t crd = 0; crd < cards.size(); crd++) {
267  vector<UCTRegion*> regions = cards[crd]->getRegions();
268  for (uint32_t rgn = 0; rgn < regions.size(); rgn++) {
269  uint32_t rawData = regions[rgn]->rawData();
270  uint32_t regionData = rawData & 0x0000FFFF;
271  uint32_t crate = regions[rgn]->getCrate();
272  uint32_t card = regions[rgn]->getCard();
273  uint32_t region = regions[rgn]->getRegion();
274  bool negativeEta = regions[rgn]->isNegativeEta();
275  uint32_t rPhi = g.getUCTRegionPhiIndex(crate, card);
276  if (region < NRegionsInCard) { // We only store the Barrel and Endcap - HF has changed in the upgrade
277  uint32_t rEta =
278  10 -
279  region; // UCT region is 0-6 for B/E but GCT eta goes 0-21, 0-3 -HF, 4-10 -B/E, 11-17 +B/E, 18-21 +HF
280  if (!negativeEta)
281  rEta = 11 + region; // Positive eta portion is offset by 11
282  rgnCollection.push_back(L1CaloRegion((uint16_t)regionData, (unsigned)rEta, (unsigned)rPhi, (int16_t)0));
283  }
284  }
285  }
286  }
287  iEvent.emplace(regionPutToken, std::move(rgnCollection));
288 }
289 
290 // ------------ method called when starting to processes a run ------------
291 void L1TCaloLayer1::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
293  iSetup,
294  ecalLUT,
295  hcalLUT,
296  hfLUT,
297  ePhiMap,
298  hPhiMap,
299  hfPhiMap,
300  useLSB,
301  useCalib,
302  useECALLUT,
303  useHCALLUT,
304  useHFLUT,
305  fwVersion)) {
306  LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
307  std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> eCalLayer1EtaSideEtArray;
308  std::array<std::array<std::array<uint32_t, nEtBins>, nCalSideBins>, nCalEtaBins> hCalLayer1EtaSideEtArray;
309  std::array<std::array<uint32_t, nEtBins>, nHfEtaBins> hfLayer1EtaEtArray;
310  ecalLUT.push_back(eCalLayer1EtaSideEtArray);
311  hcalLUT.push_back(hCalLayer1EtaSideEtArray);
312  hfLUT.push_back(hfLayer1EtaEtArray);
313  }
314  for (uint32_t twr = 0; twr < twrList.size(); twr++) {
315  // Map goes minus 1 .. 72 plus 1 .. 72 -> 0 .. 143
316  int iphi = twrList[twr]->caloPhi();
317  int ieta = twrList[twr]->caloEta();
318  if (ieta < 0) {
319  iphi -= 1;
320  } else {
321  iphi += 71;
322  }
323  twrList[twr]->setECALLUT(&ecalLUT[ePhiMap[iphi]]);
324  twrList[twr]->setHCALLUT(&hcalLUT[hPhiMap[iphi]]);
325  twrList[twr]->setHFLUT(&hfLUT[hfPhiMap[iphi]]);
326  }
327 }
328 
329 // ------------ method called when ending the processing of a run ------------
330 /*
331  void
332  L1TCaloLayer1::endRun(edm::Run const&, edm::EventSetup const&)
333  {
334  }
335 */
336 
337 // ------------ method called when starting to processes a luminosity block ------------
338 /*
339  void
340  L1TCaloLayer1::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
341  {
342  }
343 */
344 
345 // ------------ method called when ending the processing of a luminosity block ------------
346 /*
347  void
348  L1TCaloLayer1::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
349  {
350  }
351 */
352 
353 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
355  //The following says we do not know what parameters are allowed so do no validation
356  // Please change this to state exactly what you do use, even if it is no parameters
358  desc.setUnknown();
359  descriptions.addDefault(desc);
360 }
361 
362 //define this as a plug-in
364 /* vim: set ts=8 sw=2 tw=0 et :*/
std::vector< std::array< std::array< uint32_t, nEtBins >, nHfEtaBins > > hfLUT
std::vector< unsigned int > hfPhiMap
bool verbose
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTPSource
void setHwQual(int qual)
Definition: L1Candidate.h:31
delete x;
Definition: CaloConfig.h:22
std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > ecalLUT
void setHwEtHad(int et)
Definition: CaloTower.cc:29
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
std::unique_ptr< UCTLayer1 > layer1
edm::EDPutTokenT< L1CaloRegionCollection > regionPutToken
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > hcalLUT
std::vector< UCTTower * > twrList
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool L1TCaloLayer1FetchLUTs(const L1TCaloLayer1FetchLUTsTokens &iTokens, const edm::EventSetup &iSetup, std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > &eLUT, std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > &hLUT, std::vector< std::array< std::array< uint32_t, nEtBins >, nHfEtaBins > > &hfLUT, std::vector< unsigned int > &ePhiMap, std::vector< unsigned int > &hPhiMap, std::vector< unsigned int > &hfPhiMap, bool useLSB, bool useCalib, bool useECALLUT, bool useHCALLUT, bool useHFLUT, int fwVersion)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setHwEtRatio(int ratio)
Definition: CaloTower.cc:31
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalTPSource
void setHwPhi(int phi)
Definition: L1Candidate.h:30
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const L1TCaloLayer1FetchLUTsTokens lutsTokens
double b
Definition: hdecay.h:118
edm::EDPutTokenT< CaloTowerBxCollection > towerPutToken
std::vector< unsigned int > hPhiMap
bool isValid() const
Definition: HandleBase.h:70
L1TCaloLayer1(const edm::ParameterSet &)
HLT enums.
void setHwPt(int pt)
Definition: L1Candidate.h:28
double a
Definition: hdecay.h:119
void beginRun(edm::Run const &, edm::EventSetup const &) override
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:21
void setHwEta(int eta)
Definition: L1Candidate.h:29
std::vector< L1CaloRegion > L1CaloRegionCollection
void setHwEtEm(int et)
Definition: CaloTower.cc:27
std::vector< unsigned int > ePhiMap
def move(src, dest)
Definition: eostools.py:511
#define LOG_ERROR
Definition: CSCDQM_Logger.h:40
Definition: Run.h:45
void push_back(int bx, T object)