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 
63  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
64 
65 private:
66  void produce(edm::Event&, const edm::EventSetup&) override;
67 
68  void beginRun(edm::Run const&, edm::EventSetup const&) override;
69 
70  //virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
71  //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
72  //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
73 
74  // ----------member data ---------------------------
75 
80 
81 
82  std::vector< std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > ecalLUT;
83  std::vector< std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> > hcalLUT;
84  std::vector< std::array< std::array<uint32_t, nEtBins>, nHfEtaBins > > hfLUT;
85 
86  std::vector< unsigned int > ePhiMap;
87  std::vector< unsigned int > hPhiMap;
88  std::vector< unsigned int > hfPhiMap;
89 
90  std::vector< UCTTower* > twrList;
91 
92  bool useLSB;
93  bool useCalib;
94  bool useECALLUT;
95  bool useHCALLUT;
96  bool useHFLUT;
97  bool verbose;
101 
102  std::unique_ptr<UCTLayer1> layer1;
103 
104 };
105 
106 //
107 // constants, enums and typedefs
108 //
109 
110 
111 //
112 // static data member definitions
113 //
114 
115 //
116 // constructors and destructor
117 //
119  ecalTPSource(consumes<EcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("ecalToken"))),
120  hcalTPSource(consumes<HcalTrigPrimDigiCollection>(iConfig.getParameter<edm::InputTag>("hcalToken"))),
121  towerPutToken{produces<CaloTowerBxCollection>()},
122  regionPutToken{produces<L1CaloRegionCollection>()},
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 {
136 
137  // See UCTLayer1.hh for firmware version definitions
138  layer1 = std::make_unique<UCTLayer1>(fwVersion);
139 
140  vector<UCTCrate*> crates = layer1->getCrates();
141  for(uint32_t crt = 0; crt < crates.size(); crt++) {
142  vector<UCTCard*> cards = crates[crt]->getCards();
143  for(uint32_t crd = 0; crd < cards.size(); crd++) {
144  vector<UCTRegion*> regions = cards[crd]->getRegions();
145  for(uint32_t rgn = 0; rgn < regions.size(); rgn++) {
146  vector<UCTTower*> towers = regions[rgn]->getTowers();
147  for(uint32_t twr = 0; twr < towers.size(); twr++) {
148  twrList.push_back(towers[twr]);
149  }
150  }
151  }
152  }
153 
154  // This sort corresponds to the sort condition on
155  // the output CaloTowerBxCollection
156  std::sort(twrList.begin(), twrList.end(), [](UCTTower* a, UCTTower* b) {
157  return CaloTools::caloTowerHash(a->caloEta(), a->caloPhi()) < CaloTools::caloTowerHash(b->caloEta(), b->caloPhi());
158  });
159 }
160 
161 //
162 // member functions
163 //
164 
165 // ------------ method called to produce the data ------------
166 void
168 {
169  using namespace edm;
170 
172  iEvent.getByToken(ecalTPSource, ecalTPs);
174  iEvent.getByToken(hcalTPSource, hcalTPs);
175 
176  CaloTowerBxCollection towersColl;
177  L1CaloRegionCollection rgnCollection;
178 
179  uint32_t expectedTotalET = 0;
180  if(!layer1->clearEvent()) {
181  LOG_ERROR << "UCT: Failed to clear event" << std::endl;
182  return;
183  }
184 
185  for ( const auto& ecalTp : *ecalTPs ) {
186  if ( unpackEcalMask && ((ecalTp.sample(0).raw()>>13) & 0x1) ) continue;
187  int caloEta = ecalTp.id().ieta();
188  int caloPhi = ecalTp.id().iphi();
189  int et = ecalTp.compressedEt();
190  bool fgVeto = ecalTp.fineGrain();
191  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
192  if(!layer1->setECALData(t,fgVeto,et)) {
193  LOG_ERROR << "UCT: Failed loading an ECAL tower" << std::endl;
194  return;
195  }
196  expectedTotalET += et;
197  }
198 
199 
200  if(hcalTPs.isValid()){
201  for ( const auto& hcalTp : *hcalTPs ) {
202  if ( unpackHcalMask && ((hcalTp.sample(0).raw()>>13) & 0x1) ) continue;
203  int caloEta = hcalTp.id().ieta();
204  uint32_t absCaloEta = std::abs(caloEta);
205  // Tower 29 is not used by Layer-1
206  if(absCaloEta == 29) {
207  continue;
208  }
209  // Prevent usage of HF TPs with Layer-1 emulator if HCAL TPs are old style
210  else if(hcalTp.id().version() == 0 && absCaloEta > 29) {
211  continue;
212  }
213  else if(absCaloEta <= 41) {
214  int caloPhi = hcalTp.id().iphi();
215  int et = hcalTp.SOI_compressedEt();
216  bool fg = hcalTp.t0().fineGrain(0);
217  bool fg2 = hcalTp.t0().fineGrain(1);
218  if(caloPhi <= 72) {
219  UCTTowerIndex t = UCTTowerIndex(caloEta, caloPhi);
220  uint32_t featureBits = 0;
221  if(fg) featureBits |= 0b01;
222  // fg2 should only be set for HF
223  if(absCaloEta > 29 && fg2) featureBits |= 0b10;
224  if(!layer1->setHCALData(t, featureBits, et)) {
225  LOG_ERROR << "caloEta = " << caloEta << "; caloPhi =" << caloPhi << std::endl;
226  LOG_ERROR << "UCT: Failed loading an HCAL tower" << std::endl;
227  return;
228  }
229  expectedTotalET += et;
230  }
231  else {
232  LOG_ERROR << "Illegal Tower: caloEta = " << caloEta << "; caloPhi =" << caloPhi << "; et = " << et << std::endl;
233  }
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 = 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.emplace(regionPutToken,std::move(rgnCollection));
285 
286 }
287 
288 
289 
290 // ------------ method called when starting to processes a run ------------
291 void
293 {
295  LOG_ERROR << "L1TCaloLayer1::beginRun: failed to fetch LUTS - using unity" << std::endl;
296  std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> eCalLayer1EtaSideEtArray;
297  std::array< std::array< std::array<uint32_t, nEtBins>, nCalSideBins >, nCalEtaBins> hCalLayer1EtaSideEtArray;
298  std::array< std::array<uint32_t, nEtBins>, nHfEtaBins > hfLayer1EtaEtArray;
299  ecalLUT.push_back(eCalLayer1EtaSideEtArray);
300  hcalLUT.push_back(hCalLayer1EtaSideEtArray);
301  hfLUT.push_back(hfLayer1EtaEtArray);
302  }
303  for(uint32_t twr = 0; twr < twrList.size(); twr++) {
304  // Map goes minus 1 .. 72 plus 1 .. 72 -> 0 .. 143
305  int iphi = twrList[twr]->caloPhi();
306  int ieta = twrList[twr]->caloEta();
307  if (ieta<0) {
308  iphi -= 1;
309  }
310  else {
311  iphi += 71;
312  }
313  twrList[twr]->setECALLUT(&ecalLUT[ePhiMap[iphi]]);
314  twrList[twr]->setHCALLUT(&hcalLUT[hPhiMap[iphi]]);
315  twrList[twr]->setHFLUT(&hfLUT[hfPhiMap[iphi]]);
316  }
317 }
318 
319 
320 // ------------ method called when ending the processing of a run ------------
321 /*
322  void
323  L1TCaloLayer1::endRun(edm::Run const&, edm::EventSetup const&)
324  {
325  }
326 */
327 
328 // ------------ method called when starting to processes a luminosity block ------------
329 /*
330  void
331  L1TCaloLayer1::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
332  {
333  }
334 */
335 
336 // ------------ method called when ending the processing of a luminosity block ------------
337 /*
338  void
339  L1TCaloLayer1::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
340  {
341  }
342 */
343 
344 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
345 void
347  //The following says we do not know what parameters are allowed so do no validation
348  // Please change this to state exactly what you do use, even if it is no parameters
350  desc.setUnknown();
351  descriptions.addDefault(desc);
352 }
353 
354 //define this as a plug-in
356 /* vim: set ts=8 sw=2 tw=0 et :*/
std::vector< unsigned int > hfPhiMap
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
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
std::unique_ptr< UCTLayer1 > layer1
edm::EDPutTokenT< L1CaloRegionCollection > regionPutToken
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< unsigned int > hPhiMap
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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
void setHwPhi(int phi)
Definition: L1Candidate.h:43
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
Definition: Event.h:413
double b
Definition: hdecay.h:120
edm::EDPutTokenT< CaloTowerBxCollection > towerPutToken
et
define resolution functions of each parameter
std::vector< std::array< std::array< std::array< uint32_t, nEtBins >, nCalSideBins >, nCalEtaBins > > ecalLUT
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:511
#define LOG_ERROR
Definition: CSCDQM_Logger.h:41
Definition: Run.h:45
void push_back(int bx, T object)