test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::vector< std::vector < uint32_t > > > ecalLUT;
85  std::vector< std::vector< std::vector < uint32_t > > > hcalLUT;
86  std::vector< std::vector< uint32_t > > hfLUT;
87 
88  std::vector< UCTTower* > twrList;
89 
90  bool useLSB;
91  bool useCalib;
92  bool useECALLUT;
93  bool useHCALLUT;
94  bool useHFLUT;
95  bool verbose;
98 
99  UCTLayer1 *layer1;
100 
101 };
102 
103 //
104 // constants, enums and typedefs
105 //
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  ecalTPSourceLabel(iConfig.getParameter<edm::InputTag>("ecalToken").label()),
118  hcalTPSource(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalToken"))),
119  hcalTPSourceLabel(iConfig.getParameter<edm::InputTag>("hcalToken").label()),
120  ecalLUT(28, std::vector< std::vector<uint32_t> >(2, std::vector<uint32_t>(256))),
121  hcalLUT(28, std::vector< std::vector<uint32_t> >(2, std::vector<uint32_t>(256))),
122  hfLUT(12, std::vector < uint32_t >(256)),
123  useLSB(iConfig.getParameter<bool>("useLSB")),
124  useCalib(iConfig.getParameter<bool>("useCalib")),
125  useECALLUT(iConfig.getParameter<bool>("useECALLUT")),
126  useHCALLUT(iConfig.getParameter<bool>("useHCALLUT")),
127  useHFLUT(iConfig.getParameter<bool>("useHFLUT")),
128  verbose(iConfig.getParameter<bool>("verbose")),
129  unpackHcalMask(iConfig.getParameter<bool>("unpackHcalMask")),
130  unpackEcalMask(iConfig.getParameter<bool>("unpackEcalMask"))
131 {
132  produces<CaloTowerBxCollection>();
133  produces<L1CaloRegionCollection>();
134 
135  // See UCTLayer1.hh for firmware version definitions
136  int fwVersion = iConfig.getParameter<int>("firmwareVersion");
137  layer1 = new UCTLayer1(fwVersion);
138 
139  vector<UCTCrate*> crates = layer1->getCrates();
140  for(uint32_t crt = 0; crt < crates.size(); crt++) {
141  vector<UCTCard*> cards = crates[crt]->getCards();
142  for(uint32_t crd = 0; crd < cards.size(); crd++) {
143  vector<UCTRegion*> regions = cards[crd]->getRegions();
144  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
145  vector<UCTTower*> towers = regions[rgn]->getTowers();
146  for(uint32_t twr = 0; twr < towers.size(); twr++) {
147  twrList.push_back(towers[twr]);
148  }
149  }
150  }
151  }
152 
153  // This sort corresponds to the sort condition on
154  // the output CaloTowerBxCollection
155  std::sort(twrList.begin(), twrList.end(), [](UCTTower* a, UCTTower* b) {
156  return CaloTools::caloTowerHash(a->caloEta(), a->caloPhi()) < CaloTools::caloTowerHash(b->caloEta(), b->caloPhi());
157  });
158 }
159 
161  if(layer1 != 0) delete layer1;
162 }
163 
164 //
165 // member functions
166 //
167 
168 // ------------ method called to produce the data ------------
169 void
171 {
172  using namespace edm;
173 
175  iEvent.getByToken(ecalTPSource, ecalTPs);
177  iEvent.getByToken(hcalTPSource, hcalTPs);
178 
179  std::auto_ptr<CaloTowerBxCollection> towersColl (new CaloTowerBxCollection);
180  std::auto_ptr<L1CaloRegionCollection> rgnCollection (new L1CaloRegionCollection);
181 
182  uint32_t expectedTotalET = 0;
183  if(!layer1->clearEvent()) {
184  LOG_ERROR << "UCT: Failed to clear event" << std::endl;
185  return;
186  }
187 
188  for ( const auto& ecalTp : *ecalTPs ) {
189  if ( unpackEcalMask && ((ecalTp.sample(0).raw()>>13) & 0x1) ) continue;
190  int caloEta = ecalTp.id().ieta();
191  int caloPhi = ecalTp.id().iphi();
192  int et = ecalTp.compressedEt();
193  bool fgVeto = ecalTp.fineGrain();
194  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
195  if(!layer1->setECALData(t,fgVeto,et)) {
196  LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
197  return;
198  }
199  expectedTotalET += et;
200  }
201 
202  for ( const auto& hcalTp : *hcalTPs ) {
203  if ( unpackHcalMask && ((hcalTp.sample(0).raw()>>13) & 0x1) ) continue;
204  int caloEta = hcalTp.id().ieta();
205  uint32_t absCaloEta = abs(caloEta);
206  // Tower 29 is not used by Layer-1
207  if(absCaloEta == 29) {
208  continue;
209  }
210  // Prevent usage of HF TPs with Layer-1 emulator if HCAL TPs are old style
211  else if(hcalTp.id().version() == 0 && absCaloEta > 29) {
212  continue;
213  }
214  else if(absCaloEta <= 41) {
215  int caloPhi = hcalTp.id().iphi();
216  int et = hcalTp.SOI_compressedEt();
217  bool fg = hcalTp.t0().fineGrain(0);
218  bool fg2 = hcalTp.t0().fineGrain(1);
219  if(caloPhi <= 72) {
220  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
221  uint32_t featureBits = 0;
222  if(fg) featureBits |= 0b01;
223  // fg2 should only be set for HF
224  if(absCaloEta > 29 && fg2) featureBits |= 0b10;
225  if(!layer1->setHCALData(t, featureBits, et)) {
226  LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
227  LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
228  return;
229  }
230  expectedTotalET += et;
231  }
232  else {
233  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << "; et = " << et << std::endl;
234  }
235  }
236  else {
237  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << std::endl;
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.put(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 = 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
278  if(!negativeEta) rEta = 11 + region; // Positive eta portion is offset by 11
279  rgnCollection->push_back(L1CaloRegion((uint16_t) regionData, (unsigned) rEta, (unsigned) rPhi, (int16_t) 0));
280  }
281  }
282  }
283  }
284  iEvent.put(rgnCollection);
285 
286 }
287 
288 
289 
290 // ------------ method called once each job just before starting event loop ------------
291 void
293 {
294 }
295 
296 // ------------ method called once each job just after ending the event loop ------------
297 void
299 }
300 
301 // ------------ method called when starting to processes a run ------------
302 void
304 {
306  LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
307  }
308  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
309  twrList[twr]->setECALLUT(&ecalLUT);
310  twrList[twr]->setHCALLUT(&hcalLUT);
311  twrList[twr]->setHFLUT(&hfLUT);
312  }
313 }
314 
315 
316 // ------------ method called when ending the processing of a run ------------
317 /*
318  void
319  L1TCaloLayer1::endRun(edm::Run const&, edm::EventSetup const&)
320  {
321  }
322 */
323 
324 // ------------ method called when starting to processes a luminosity block ------------
325 /*
326  void
327  L1TCaloLayer1::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
328  {
329  }
330 */
331 
332 // ------------ method called when ending the processing of a luminosity block ------------
333 /*
334  void
335  L1TCaloLayer1::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
336  {
337  }
338 */
339 
340 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
341 void
343  //The following says we do not know what parameters are allowed so do no validation
344  // Please change this to state exactly what you do use, even if it is no parameters
346  desc.setUnknown();
347  descriptions.addDefault(desc);
348 }
349 
350 //define this as a plug-in
352 /* vim: set ts=8 sw=2 tw=0 et :*/
T getParameter(std::string const &) const
std::vector< std::vector< std::vector< uint32_t > > > hcalLUT
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
virtual void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< std::vector< uint32_t > > hfLUT
edm::EDGetTokenT< HcalTrigPrimDigiCollection > hcalTPSource
void setHwQual(int qual)
Definition: L1Candidate.h:44
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
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
std::vector< std::vector< std::vector< uint32_t > > > ecalLUT
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string ecalTPSourceLabel
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
std::string hcalTPSourceLabel
L1TCaloLayer1(const edm::ParameterSet &)
void setHwPt(int pt)
Definition: L1Candidate.h:41
double a
Definition: hdecay.h:121
bool L1TCaloLayer1FetchLUTs(const edm::EventSetup &iSetup, std::vector< std::vector< std::vector< uint32_t > > > &eLUT, std::vector< std::vector< std::vector< uint32_t > > > &hLUT, std::vector< std::vector< uint32_t > > &hfLUT, bool useLSB, bool useCalib, bool useECALLUT, bool useHCALLUT, bool useHFLUT)
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
#define LOG_ERROR
Definition: CSCDQM_Logger.h:41
Definition: Run.h:43