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