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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
34 
35 #include "L1Trigger/L1TCaloLayer1/src/UCTLayer1.hh"
36 #include "L1Trigger/L1TCaloLayer1/src/UCTCrate.hh"
37 #include "L1Trigger/L1TCaloLayer1/src/UCTCard.hh"
38 #include "L1Trigger/L1TCaloLayer1/src/UCTRegion.hh"
39 #include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh"
40 
41 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
42 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
43 
47 
49 
50 #include "L1Trigger/L1TCaloLayer1/src/L1TCaloLayer1FetchLUTs.hh"
51 
52 using namespace l1t;
53 using namespace l1tcalo;
54 
55 //
56 // class declaration
57 //
58 
60 public:
61  explicit L1TCaloLayer1(const edm::ParameterSet&);
62  ~L1TCaloLayer1() override;
63 
64  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
65 
66 private:
67  void beginJob() override;
68  void produce(edm::Event&, const edm::EventSetup&) override;
69  void endJob() override;
70 
71  void beginRun(edm::Run const&, edm::EventSetup const&) override;
72 
73  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
74  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
75  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
76 
77  // ----------member data ---------------------------
78 
83 
84  std::vector< std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > ecalLUT;
85  std::vector< std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > hcalLUT;
86  std::vector< std::array< std::array<uint32_t, nEtBins>, nHfEtaBins > > hfLUT;
87 
88  std::vector< unsigned int > ePhiMap;
89  std::vector< unsigned int > hPhiMap;
90  std::vector< unsigned int > hfPhiMap;
91 
92  std::vector< UCTTower* > twrList;
93 
94  bool useLSB;
95  bool useCalib;
96  bool useECALLUT;
97  bool useHCALLUT;
98  bool useHFLUT;
99  bool verbose;
103 
104  UCTLayer1 *layer1;
105 
106 };
107 
108 //
109 // constants, enums and typedefs
110 //
111 
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  ecalTPSource(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalToken"))),
122  ecalTPSourceLabel(iConfig.getParameter<edm::InputTag>("ecalToken").label()),
123  hcalTPSource(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalToken"))),
124  hcalTPSourceLabel(iConfig.getParameter<edm::InputTag>("hcalToken").label()),
125  ePhiMap(72*2, 0),
126  hPhiMap(72*2, 0),
127  hfPhiMap(72*2, 0),
128  useLSB(iConfig.getParameter<bool>("useLSB")),
129  useCalib(iConfig.getParameter<bool>("useCalib")),
130  useECALLUT(iConfig.getParameter<bool>("useECALLUT")),
131  useHCALLUT(iConfig.getParameter<bool>("useHCALLUT")),
132  useHFLUT(iConfig.getParameter<bool>("useHFLUT")),
133  verbose(iConfig.getParameter<bool>("verbose")),
134  unpackHcalMask(iConfig.getParameter<bool>("unpackHcalMask")),
135  unpackEcalMask(iConfig.getParameter<bool>("unpackEcalMask")),
136  fwVersion(iConfig.getParameter<int>("firmwareVersion"))
137 {
138  produces<CaloTowerBxCollection>();
139  produces<L1CaloRegionCollection>();
140 
141  // See UCTLayer1.hh for firmware version definitions
142  layer1 = new UCTLayer1(fwVersion);
143 
144  vector<UCTCrate*> crates = layer1->getCrates();
145  for(uint32_t crt = 0; crt < crates.size(); crt++) {
146  vector<UCTCard*> cards = crates[crt]->getCards();
147  for(uint32_t crd = 0; crd < cards.size(); crd++) {
148  vector<UCTRegion*> regions = cards[crd]->getRegions();
149  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
150  vector<UCTTower*> towers = regions[rgn]->getTowers();
151  for(uint32_t twr = 0; twr < towers.size(); twr++) {
152  twrList.push_back(towers[twr]);
153  }
154  }
155  }
156  }
157 
158  // This sort corresponds to the sort condition on
159  // the output CaloTowerBxCollection
160  std::sort(twrList.begin(), twrList.end(), [](UCTTower* a, UCTTower* b) {
161  return CaloTools::caloTowerHash(a->caloEta(), a->caloPhi()) < CaloTools::caloTowerHash(b->caloEta(), b->caloPhi());
162  });
163 }
164 
166  if(layer1 != nullptr) delete layer1;
167 }
168 
169 //
170 // member functions
171 //
172 
173 // ------------ method called to produce the data ------------
174 void
176 {
177  using namespace edm;
178 
180  iEvent.getByToken(ecalTPSource, ecalTPs);
182  iEvent.getByToken(hcalTPSource, hcalTPs);
183 
184  std::unique_ptr<CaloTowerBxCollection> towersColl (new CaloTowerBxCollection);
185  std::unique_ptr<L1CaloRegionCollection> rgnCollection (new L1CaloRegionCollection);
186 
187  uint32_t expectedTotalET = 0;
188  if(!layer1->clearEvent()) {
189  LOG_ERROR << "UCT: Failed to clear event" << std::endl;
190  return;
191  }
192 
193  for ( const auto& ecalTp : *ecalTPs ) {
194  if ( unpackEcalMask && ((ecalTp.sample(0).raw()>>13) & 0x1) ) continue;
195  int caloEta = ecalTp.id().ieta();
196  int caloPhi = ecalTp.id().iphi();
197  int et = ecalTp.compressedEt();
198  bool fgVeto = ecalTp.fineGrain();
199  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
200  if(!layer1->setECALData(t,fgVeto,et)) {
201  LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
202  return;
203  }
204  expectedTotalET += et;
205  }
206 
207 
208  if(hcalTPs.isValid()){
209  for ( const auto& hcalTp : *hcalTPs ) {
210  if ( unpackHcalMask && ((hcalTp.sample(0).raw()>>13) & 0x1) ) continue;
211  int caloEta = hcalTp.id().ieta();
212  uint32_t absCaloEta = std::abs(caloEta);
213  // Tower 29 is not used by Layer-1
214  if(absCaloEta == 29) {
215  continue;
216  }
217  // Prevent usage of HF TPs with Layer-1 emulator if HCAL TPs are old style
218  else if(hcalTp.id().version() == 0 && absCaloEta > 29) {
219  continue;
220  }
221  else if(absCaloEta <= 41) {
222  int caloPhi = hcalTp.id().iphi();
223  int et = hcalTp.SOI_compressedEt();
224  bool fg = hcalTp.t0().fineGrain(0);
225  bool fg2 = hcalTp.t0().fineGrain(1);
226  if(caloPhi <= 72) {
227  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
228  uint32_t featureBits = 0;
229  if(fg) featureBits |= 0b01;
230  // fg2 should only be set for HF
231  if(absCaloEta > 29 && fg2) featureBits |= 0b10;
232  if(!layer1->setHCALData(t, featureBits, et)) {
233  LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
234  LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
235  return;
236  }
237  expectedTotalET += et;
238  }
239  else {
240  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << "; et = " << et << std::endl;
241  }
242  }
243  else {
244  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << std::endl;
245  }
246  }
247  }
248 
249  //Process
250  if(!layer1->process()) {
251  LOG_ERROR << "UCT: Failed to process layer 1" << std::endl;
252  }
253 
254  int theBX = 0; // Currently we only read and process the "hit" BX only
255 
256  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
257  CaloTower caloTower;
258  caloTower.setHwPt(twrList[twr]->et()); // Bits 0-8 of the 16-bit word per the interface protocol document
259  caloTower.setHwEtRatio(twrList[twr]->er()); // Bits 9-11 of the 16-bit word per the interface protocol document
260  caloTower.setHwQual(twrList[twr]->miscBits()); // Bits 12-15 of the 16-bit word per the interface protocol document
261  caloTower.setHwEta(twrList[twr]->caloEta()); // caloEta = 1-28 and 30-41
262  caloTower.setHwPhi(twrList[twr]->caloPhi()); // caloPhi = 1-72
263  caloTower.setHwEtEm(twrList[twr]->getEcalET()); // This is provided as a courtesy - not available to hardware
264  caloTower.setHwEtHad(twrList[twr]->getHcalET()); // This is provided as a courtesy - not available to hardware
265  towersColl->push_back(theBX, caloTower);
266  }
267 
268  iEvent.put(std::move(towersColl));
269 
270  UCTGeometry g;
271  vector<UCTCrate*> crates = layer1->getCrates();
272  for(uint32_t crt = 0; crt < crates.size(); crt++) {
273  vector<UCTCard*> cards = crates[crt]->getCards();
274  for(uint32_t crd = 0; crd < cards.size(); crd++) {
275  vector<UCTRegion*> regions = cards[crd]->getRegions();
276  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
277  uint32_t rawData = regions[rgn]->rawData();
278  uint32_t regionData = rawData & 0x0000FFFF;
279  uint32_t crate = regions[rgn]->getCrate();
280  uint32_t card = regions[rgn]->getCard();
281  uint32_t region = regions[rgn]->getRegion();
282  bool negativeEta = regions[rgn]->isNegativeEta();
283  uint32_t rPhi = g.getUCTRegionPhiIndex(crate, card);
284  if(region < NRegionsInCard) { // We only store the Barrel and Endcap - HF has changed in the upgrade
285  uint32_t rEta = 10 - 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
286  if(!negativeEta) rEta = 11 + region; // Positive eta portion is offset by 11
287  rgnCollection->push_back(L1CaloRegion((uint16_t) regionData, (unsigned) rEta, (unsigned) rPhi, (int16_t) 0));
288  }
289  }
290  }
291  }
292  iEvent.put(std::move(rgnCollection));
293 
294 }
295 
296 
297 
298 // ------------ method called once each job just before starting event loop ------------
299 void
301 {
302 }
303 
304 // ------------ method called once each job just after ending the event loop ------------
305 void
307 }
308 
309 // ------------ method called when starting to processes a run ------------
310 void
312 {
314  LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
315  std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> eCalLayer1EtaSideEtArray;
316  std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> hCalLayer1EtaSideEtArray;
317  std::array< std::array<uint32_t, nEtBins>, nHfEtaBins > hfLayer1EtaEtArray;
318  ecalLUT.push_back(eCalLayer1EtaSideEtArray);
319  hcalLUT.push_back(hCalLayer1EtaSideEtArray);
320  hfLUT.push_back(hfLayer1EtaEtArray);
321  }
322  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
323  // Map goes minus 1 .. 72 plus 1 .. 72 -> 0 .. 143
324  int iphi = twrList[twr]->caloPhi();
325  int ieta = twrList[twr]->caloEta();
326  if (ieta<0) {
327  iphi -= 1;
328  }
329  else {
330  iphi += 71;
331  }
332  twrList[twr]->setECALLUT(&ecalLUT[ePhiMap[iphi]]);
333  twrList[twr]->setHCALLUT(&hcalLUT[hPhiMap[iphi]]);
334  twrList[twr]->setHFLUT(&hfLUT[hfPhiMap[iphi]]);
335  }
336 }
337 
338 
339 // ------------ method called when ending the processing of a run ------------
340 /*
341  void
342  L1TCaloLayer1::endRun(edm::Run const&, edm::EventSetup const&)
343  {
344  }
345 */
346 
347 // ------------ method called when starting to processes a luminosity block ------------
348 /*
349  void
350  L1TCaloLayer1::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
351  {
352  }
353 */
354 
355 // ------------ method called when ending the processing of a luminosity block ------------
356 /*
357  void
358  L1TCaloLayer1::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
359  {
360  }
361 */
362 
363 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
364 void
366  //The following says we do not know what parameters are allowed so do no validation
367  // Please change this to state exactly what you do use, even if it is no parameters
369  desc.setUnknown();
370  descriptions.addDefault(desc);
371 }
372 
373 //define this as a plug-in
375 /* vim: set ts=8 sw=2 tw=0 et :*/
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
std::vector< unsigned int > hfPhiMap
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool L1TCaloLayer1FetchLUTs(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)
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTPSource
void setHwQual(int qual)
Definition: L1Candidate.h:44
delete x;
Definition: CaloConfig.h:22
void setHwEtHad(int et)
Definition: CaloTower.cc:44
std::vector< UCTTower * > twrList
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
void beginJob()
Definition: Breakpoints.cc:15
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< unsigned int > hPhiMap
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
~L1TCaloLayer1() override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string ecalTPSourceLabel
bool isValid() const
Definition: HandleBase.h:74
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void setHwEtRatio(int ratio)
Definition: CaloTower.cc:49
edm::EDGetTokenT< EcalTrigPrimDigiCollection > ecalTPSource
UCTLayer1 * layer1
void setHwPhi(int phi)
Definition: L1Candidate.h:43
void beginJob() override
double b
Definition: hdecay.h:120
et
define resolution functions of each parameter
std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > ecalLUT
std::string hcalTPSourceLabel
L1TCaloLayer1(const edm::ParameterSet &)
std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > hcalLUT
HLT enums.
std::vector< std::array< std::array< uint32_t, nEtBins >, nHfEtaBins > > hfLUT
void setHwPt(int pt)
Definition: L1Candidate.h:41
double a
Definition: hdecay.h:121
std::vector< unsigned int > ePhiMap
void beginRun(edm::Run const &, edm::EventSetup const &) override
A calorimeter trigger region (sum of 4x4 trigger towers)
Definition: L1CaloRegion.h:22
void setHwEta(int eta)
Definition: L1Candidate.h:42
std::vector< L1CaloRegion > L1CaloRegionCollection
void setHwEtEm(int et)
Definition: CaloTower.cc:39
def move(src, dest)
Definition: eostools.py:510
#define LOG_ERROR
Definition: CSCDQM_Logger.h:41
Definition: Run.h:43