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  layer1 = new UCTLayer1;
135  vector<UCTCrate*> crates = layer1->getCrates();
136  for(uint32_t crt = 0; crt < crates.size(); crt++) {
137  vector<UCTCard*> cards = crates[crt]->getCards();
138  for(uint32_t crd = 0; crd < cards.size(); crd++) {
139  vector<UCTRegion*> regions = cards[crd]->getRegions();
140  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
141  vector<UCTTower*> towers = regions[rgn]->getTowers();
142  for(uint32_t twr = 0; twr < towers.size(); twr++) {
143  twrList.push_back(towers[twr]);
144  }
145  }
146  }
147  }
148 
149  // This sort corresponds to the sort condition on
150  // the output CaloTowerBxCollection
151  std::sort(twrList.begin(), twrList.end(), [](UCTTower* a, UCTTower* b) {
152  return CaloTools::caloTowerHash(a->caloEta(), a->caloPhi()) < CaloTools::caloTowerHash(b->caloEta(), b->caloPhi());
153  });
154 }
155 
157  if(layer1 != 0) delete layer1;
158 }
159 
160 //
161 // member functions
162 //
163 
164 // ------------ method called to produce the data ------------
165 void
167 {
168  using namespace edm;
169 
171  iEvent.getByToken(ecalTPSource, ecalTPs);
173  iEvent.getByToken(hcalTPSource, hcalTPs);
174 
175  std::auto_ptr<CaloTowerBxCollection> towersColl (new CaloTowerBxCollection);
176  std::auto_ptr<L1CaloRegionCollection> rgnCollection (new L1CaloRegionCollection);
177 
178  uint32_t expectedTotalET = 0;
179  if(!layer1->clearEvent()) {
180  LOG_ERROR << "UCT: Failed to clear event" << std::endl;
181  return;
182  }
183 
184  for ( const auto& ecalTp : *ecalTPs ) {
185  if ( unpackEcalMask && ((ecalTp.sample(0).raw()>>13) & 0x1) ) continue;
186  int caloEta = ecalTp.id().ieta();
187  int caloPhi = ecalTp.id().iphi();
188  int et = ecalTp.compressedEt();
189  bool fgVeto = ecalTp.fineGrain();
190  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
191  if(!layer1->setECALData(t,fgVeto,et)) {
192  LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
193  return;
194  }
195  expectedTotalET += et;
196  }
197 
198  for ( const auto& hcalTp : *hcalTPs ) {
199  if ( unpackHcalMask && ((hcalTp.sample(0).raw()>>13) & 0x1) ) continue;
200  int caloEta = hcalTp.id().ieta();
201  uint32_t absCaloEta = abs(caloEta);
202  // Tower 29 is not used by Layer-1
203  if(absCaloEta == 29) {
204  continue;
205  }
206  // Prevent usage of HF TPs with Layer-1 emulator if HCAL TPs are old style
207  else if(hcalTp.id().version() == 0 && absCaloEta > 29) {
208  continue;
209  }
210  else if(absCaloEta <= 41) {
211  int caloPhi = hcalTp.id().iphi();
212  int et = hcalTp.SOI_compressedEt();
213  bool fg = hcalTp.t0().fineGrain(0);
214  bool fg2 = hcalTp.t0().fineGrain(1);
215  if(caloPhi <= 72) {
216  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
217  uint32_t featureBits = 0;
218  if(fg) featureBits |= 0b01;
219  // fg2 should only be set for HF
220  if(absCaloEta > 29 && fg2) featureBits |= 0b10;
221  if(!layer1->setHCALData(t, featureBits, et)) {
222  LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
223  LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
224  return;
225  }
226  expectedTotalET += et;
227  }
228  else {
229  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << "; et = " << et << std::endl;
230  }
231  }
232  else {
233  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << std::endl;
234  }
235  }
236 
237  //Process
238  if(!layer1->process()) {
239  LOG_ERROR << "UCT: Failed to process layer 1" << std::endl;
240  }
241 
242  int theBX = 0; // Currently we only read and process the "hit" BX only
243 
244  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
245  CaloTower caloTower;
246  caloTower.setHwPt(twrList[twr]->et()); // Bits 0-8 of the 16-bit word per the interface protocol document
247  caloTower.setHwEtRatio(twrList[twr]->er()); // Bits 9-11 of the 16-bit word per the interface protocol document
248  caloTower.setHwQual(twrList[twr]->miscBits()); // Bits 12-15 of the 16-bit word per the interface protocol document
249  caloTower.setHwEta(twrList[twr]->caloEta()); // caloEta = 1-28 and 30-41
250  caloTower.setHwPhi(twrList[twr]->caloPhi()); // caloPhi = 1-72
251  caloTower.setHwEtEm(twrList[twr]->getEcalET()); // This is provided as a courtesy - not available to hardware
252  caloTower.setHwEtHad(twrList[twr]->getHcalET()); // This is provided as a courtesy - not available to hardware
253  towersColl->push_back(theBX, caloTower);
254  }
255 
256  iEvent.put(towersColl);
257 
258  UCTGeometry g;
259  vector<UCTCrate*> crates = layer1->getCrates();
260  for(uint32_t crt = 0; crt < crates.size(); crt++) {
261  vector<UCTCard*> cards = crates[crt]->getCards();
262  for(uint32_t crd = 0; crd < cards.size(); crd++) {
263  vector<UCTRegion*> regions = cards[crd]->getRegions();
264  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
265  uint32_t rawData = regions[rgn]->rawData();
266  uint32_t regionData = rawData & 0x0000FFFF;
267  uint32_t crate = regions[rgn]->getCrate();
268  uint32_t card = regions[rgn]->getCard();
269  uint32_t region = regions[rgn]->getRegion();
270  bool negativeEta = regions[rgn]->isNegativeEta();
271  uint32_t rPhi = g.getUCTRegionPhiIndex(crate, card);
272  if(region < NRegionsInCard) { // We only store the Barrel and Endcap - HF has changed in the upgrade
273  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
274  if(!negativeEta) rEta = 11 + region; // Positive eta portion is offset by 11
275  rgnCollection->push_back(L1CaloRegion((uint16_t) regionData, (unsigned) rEta, (unsigned) rPhi, (int16_t) 0));
276  }
277  }
278  }
279  }
280  iEvent.put(rgnCollection);
281 
282 }
283 
284 
285 
286 // ------------ method called once each job just before starting event loop ------------
287 void
289 {
290 }
291 
292 // ------------ method called once each job just after ending the event loop ------------
293 void
295 }
296 
297 // ------------ method called when starting to processes a run ------------
298 void
300 {
302  LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
303  }
304  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
305  twrList[twr]->setECALLUT(&ecalLUT);
306  twrList[twr]->setHCALLUT(&hcalLUT);
307  twrList[twr]->setHFLUT(&hfLUT);
308  }
309 }
310 
311 
312 // ------------ method called when ending the processing of a run ------------
313 /*
314  void
315  L1TCaloLayer1::endRun(edm::Run const&, edm::EventSetup const&)
316  {
317  }
318 */
319 
320 // ------------ method called when starting to processes a luminosity block ------------
321 /*
322  void
323  L1TCaloLayer1::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
324  {
325  }
326 */
327 
328 // ------------ method called when ending the processing of a luminosity block ------------
329 /*
330  void
331  L1TCaloLayer1::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
332  {
333  }
334 */
335 
336 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
337 void
339  //The following says we do not know what parameters are allowed so do no validation
340  // Please change this to state exactly what you do use, even if it is no parameters
342  desc.setUnknown();
343  descriptions.addDefault(desc);
344 }
345 
346 //define this as a plug-in
348 /* vim: set ts=8 sw=2 tw=0 et :*/
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.cc:64
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.cc:54
virtual void beginJob() override
double b
Definition: hdecay.h:120
std::string hcalTPSourceLabel
L1TCaloLayer1(const edm::ParameterSet &)
void setHwPt(int pt)
Definition: L1Candidate.cc:44
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.cc:49
std::vector< L1CaloRegion > L1CaloRegionCollection
void setHwEtEm(int et)
Definition: CaloTower.cc:39
#define LOG_ERROR
Definition: CSCDQM_Logger.h:41
Definition: Run.h:43