CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TCaloLayer1RawToDigi.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventFilter/L1TXRawToDigi
4 // Class: L1TCaloLayer1RawToDigi
5 //
16 //
17 // Original Author: Sridhara Rao Dasu
18 // Created: Sun, 13 Sep 2015 00:31:25 GMT
19 //
20 //
21 
22 
23 // system include files
24 #include <memory>
25 
26 // user include files
32 
34 
35 
38 
39 // Raw data collection headers
43 
47 
49 
53 
55 
56 #include "UCTDAQRawData.h"
57 #include "UCTAMCRawData.h"
58 #include "UCTCTP7RawData.h"
59 
60 using namespace edm;
61 
62 //
63 // class declaration
64 //
65 
67 public:
68  explicit L1TCaloLayer1RawToDigi(const ParameterSet&);
70 
71  static void fillDescriptions(ConfigurationDescriptions& descriptions);
72 
73 private:
74  virtual void beginStream(StreamID) override;
75  virtual void produce(Event&, const EventSetup&) override;
76  virtual void endStream() override;
77 
78  void makeECalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<EcalTrigPrimDigiCollection>& ecalTPGs);
79 
80  void makeHCalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<HcalTrigPrimDigiCollection>& hcalTPGs);
81 
82  void makeHFTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<HcalTrigPrimDigiCollection>& hfTPGs);
83 
84  //virtual void beginRun(Run const&, EventSetup const&) override;
85  //virtual void endRun(Run const&, EventSetup const&) override;
86  //virtual void beginLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
87  //virtual void endLuminosityBlock(LuminosityBlock const&, EventSetup const&) override;
88 
89  // ----------member data ---------------------------
90 
92  std::vector<int> fedIDs;
93 
94  uint32_t event;
95 
96  bool verbose;
97 
98 };
99 
100 //
101 // constants, enums and typedefs
102 //
103 
104 
105 //
106 // static data member definitions
107 //
108 
109 //
110 // constructors and destructor
111 //
113  fedRawDataLabel(iConfig.getParameter<InputTag>("fedRawDataLabel")),
114  fedIDs(iConfig.getParameter<std::vector<int> >("FEDIDs")),
115  event(0),
116  verbose(iConfig.getParameter<bool>("verbose"))
117 {
118 
119  produces<EcalTrigPrimDigiCollection>();
120  produces<HcalTrigPrimDigiCollection>();
121  produces<HcalTrigPrimDigiCollection>("hfTPGDigis");
122 
123  consumes<FEDRawDataCollection>(fedRawDataLabel);
124 
125 }
126 
127 
129 {
130 
131 }
132 
133 //
134 // member functions
135 //
136 
137 // ------------ method called to produce the data ------------
138 void
140 {
141  using namespace edm;
142  using namespace std;
143 
144  Handle<FEDRawDataCollection> fedRawDataCollection;
145  iEvent.getByLabel(fedRawDataLabel, fedRawDataCollection);
146 
147  std::auto_ptr<EcalTrigPrimDigiCollection> ecalTPGs(new EcalTrigPrimDigiCollection);
148  std::auto_ptr<HcalTrigPrimDigiCollection> hcalTPGs(new HcalTrigPrimDigiCollection);
149  std::auto_ptr<HcalTrigPrimDigiCollection> hfTPGs(new HcalTrigPrimDigiCollection);
150 
151  // if raw data collection is present, check the headers and do the unpacking
152  if (fedRawDataCollection.isValid()) {
153 
154  for(uint32_t i = 0; i < fedIDs.size(); i++) {
155 
156  uint32_t fed = fedIDs[i];
157 
158  const FEDRawData& fedRawData = fedRawDataCollection->FEDData(fed);
159 
160  //Check FED size
161  if(verbose) LogDebug("L1TCaloLayer1") << "Upacking FEDRawData for fed " << std::dec << fed << " of size " << fedRawData.size();
162 
163  const uint64_t *fedRawDataArray = (const uint64_t *) fedRawData.data();
164 
165  UCTDAQRawData daqData(fedRawDataArray);
166  if(verbose && event < 5) daqData.print();
167  for(uint32_t i = 0; i < daqData.nAMCs(); i++) {
168  UCTAMCRawData amcData(daqData.amcPayload(i));
169  if(verbose && event < 5) {
170  LogDebug("L1TCaloLayer1") << endl;
171  amcData.print();
172  LogDebug("L1TCaloLayer1") << endl;
173  }
174  uint32_t lPhi = amcData.layer1Phi();
175  UCTCTP7RawData ctp7Data(amcData.payload());
176  if(verbose && event < 5) ctp7Data.print();
177  if(verbose && event < 5) LogDebug("L1TCaloLayer1") << endl;
178  makeECalTPGs(lPhi, ctp7Data, ecalTPGs);
179  makeHCalTPGs(lPhi, ctp7Data, hcalTPGs);
180  // Note: HF TPGs are separately put in event to avoid RCT gettting confused
181  makeHFTPGs(lPhi, ctp7Data, hfTPGs);
182  }
183 
184  }
185 
186  }
187  else{
188 
189  LogError("L1T") << "Cannot unpack: no collection found";
190 
191  return;
192  }
193 
194  iEvent.put(ecalTPGs);
195  iEvent.put(hcalTPGs);
196  iEvent.put(hfTPGs, "hfTPGDigis");
197 
198  event++;
199  if(verbose && event == 5) LogDebug("L1TCaloLayer1") << "L1TCaloLayer1RawToDigi: Goodbye! Tired of printing junk" << endl;
200 
201 }
202 
203 void L1TCaloLayer1RawToDigi::makeECalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<EcalTrigPrimDigiCollection>& ecalTPGs) {
205  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
206  int cPhi = - 1 + lPhi * 4 + iPhi; // Calorimeter phi index
207  if(cPhi == 0) cPhi = 72;
208  else if(cPhi == -1) cPhi = 71;
209  else if(cPhi < -1) {
210  LogError("L1TCaloLayer1RawToDigi") << "L1TCaloLayer1RawToDigi: Major error in makeECalTPGs" << std::endl;
211  return;
212  }
213  for(int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
214  if(cEta != 0) { // Calorimeter eta = 0 is invalid
215  bool negativeEta = false;
216  if(cEta < 0) negativeEta = true;
217  uint32_t iEta = abs(cEta);
218  // This code is fragile! Note that towerDatum is packed as is done in EcalTriggerPrimitiveSample
219  // Bottom 8-bits are ET
220  // Then finegrain feature bit
221  // Then three bits have ttBits, which I have no clue about (not available on ECAL links so not set)
222  // Then there is a spare FG Veto bit, which is used for L1 spike detection (not available on ECAL links so not set)
223  // Top three bits seem to be unused. So, we steal those to set the tower masking, link masking and link status information
224  // To decode these custom three bits use ((EcalTriggerPrimitiveSample::raw() >> 13) & 0x7)
225  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
226  if(ctp7Data.getFB(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0100;
227  if(ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x2000;
228  if(ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x4000;
229  if(ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
230  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
231  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x8000;
232  EcalTriggerPrimitiveSample sample(towerDatum);
233  int zSide = cEta / ((int) iEta);
235  EcalTrigTowerDetId id(zSide, ecalTriggerTower, iEta, cPhi);
236  EcalTriggerPrimitiveDigi tpg(id);
237  tpg.setSize(1);
238  tpg.setSample(0, sample);
239  ecalTPGs->push_back(tpg);
240  }
241  }
242  }
243 
244 }
245 
246 void L1TCaloLayer1RawToDigi::makeHCalTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<HcalTrigPrimDigiCollection>& hcalTPGs) {
248  for(uint32_t iPhi = 0; iPhi < 4; iPhi++) { // Loop over all four phi divisions on card
249  int cPhi = - 1 + lPhi * 4 + iPhi; // Calorimeter phi index
250  if(cPhi == 0) cPhi = 72;
251  else if(cPhi == -1) cPhi = 71;
252  else if(cPhi < -1) {
253  LogError("L1TCaloLayer1RawToDigi") << "L1TCaloLayer1RawToDigi: Major error in makeHCalTPGs" << std::endl;
254  return;
255  }
256  for(int cEta = -28; cEta <= 28; cEta++) { // Calorimeter Eta indices (HB/HE for now)
257  if(cEta != 0) { // Calorimeter eta = 0 is invalid
258  bool negativeEta = false;
259  if(cEta < 0) negativeEta = true;
260  uint32_t iEta = abs(cEta);
261  // This code is fragile! Note that towerDatum is packed as is done in HcalTriggerPrimitiveSample
262  // Bottom 8-bits are ET
263  // Then feature bit
264  // The remaining bits are undefined presently
265  // We use next three bits for link details, which we did not have room in EcalTriggerPrimitiveSample case
266  // We use next three bits to set the tower masking, link masking and link status information as done for Ecal
267  // To decode these custom six bits use ((EcalTriggerPrimitiveSample::raw() >> 9) & 0x77)
268  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
269  if(ctp7Data.getFB(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0100;
270  if(ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0200;
271  if(ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0400;
272  if(ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0800;
273  if(ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x2000;
274  if(ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x4000;
275  if(ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
276  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
277  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x8000;
278  HcalTriggerPrimitiveSample sample(towerDatum);
279  HcalTrigTowerDetId id(cEta, cPhi);
280  HcalTriggerPrimitiveDigi tpg(id);
281  tpg.setSize(1);
282  tpg.setSample(0, sample);
283  hcalTPGs->push_back(tpg);
284  }
285  }
286  }
287 
288 }
289 
290 void L1TCaloLayer1RawToDigi::makeHFTPGs(uint32_t lPhi, UCTCTP7RawData& ctp7Data, std::auto_ptr<HcalTrigPrimDigiCollection>& hfTPGs) {
292  for(uint32_t side = 0; side <= 1; side++) {
293  bool negativeEta = false;
294  if(side == 0) negativeEta = true;
295  for(uint32_t iEta = 30; iEta <= 40; iEta++) {
296  for(uint32_t iPhi = 0; iPhi < 2; iPhi++) {
297  if(iPhi == 1 && iEta == 40) iEta = 41;
298  int cPhi = 1 + lPhi * 2 + iPhi; // Calorimeter phi index
299  if(iEta == 40 || iEta == 41) cPhi = lPhi + 1;
300  int cEta = iEta;
301  if(negativeEta) cEta = -iEta;
302  // This code is fragile! Note that towerDatum is packed as is done in HcalTriggerPrimitiveSample
303  // Bottom 8-bits are ET
304  // Then feature bit
305  // The remaining bits are undefined presently
306  // We use next three bits for link details, which we did not have room in EcalTriggerPrimitiveSample case
307  // We use next three bits to set the tower masking, link masking and link status information as done for Ecal
308  // To decode these custom six bits use ((EcalTriggerPrimitiveSample::raw() >> 9) & 0x77)
309  uint32_t towerDatum = ctp7Data.getET(cType, negativeEta, iEta, iPhi);
310  if(ctp7Data.getFB(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0100;
311  if(ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0200;
312  if(ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0400;
313  if(ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x0800;
314  if(ctp7Data.isTowerMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x2000;
315  if(ctp7Data.isLinkMasked(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x4000;
316  if(ctp7Data.isLinkMisaligned(cType, negativeEta, iEta, iPhi) ||
317  ctp7Data.isLinkInError(cType, negativeEta, iEta, iPhi) ||
318  ctp7Data.isLinkDown(cType, negativeEta, iEta, iPhi)) towerDatum |= 0x8000;
319  HcalTriggerPrimitiveSample sample(towerDatum);
320  HcalTrigTowerDetId id(cEta, cPhi);
321  HcalTriggerPrimitiveDigi tpg(id);
322  tpg.setSize(1);
323  tpg.setSample(0, sample);
324  hfTPGs->push_back(tpg);
325  }
326  }
327  }
328 }
329 
330 // ------------ method called once each stream before processing any runs, lumis or events ------------
331 void
333 {
334 }
335 
336 // ------------ method called once each stream after processing all runs, lumis and events ------------
337 void
339 }
340 
341 // ------------ method called when starting to processes a run ------------
342 /*
343  void
344  L1TCaloLayer1RawToDigi::beginRun(Run const&, EventSetup const&)
345  {
346  }
347 */
348 
349 // ------------ method called when ending the processing of a run ------------
350 /*
351  void
352  L1TCaloLayer1RawToDigi::endRun(Run const&, EventSetup const&)
353  {
354  }
355 */
356 
357 // ------------ method called when starting to processes a luminosity block ------------
358 /*
359  void
360  L1TCaloLayer1RawToDigi::beginLuminosityBlock(LuminosityBlock const&, EventSetup const&)
361  {
362  }
363 */
364 
365 // ------------ method called when ending the processing of a luminosity block ------------
366 /*
367  void
368  L1TCaloLayer1RawToDigi::endLuminosityBlock(LuminosityBlock const&, EventSetup const&)
369  {
370  }
371 */
372 
373 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
374 void
376  //The following says we do not know what parameters are allowed so do no validation
377  // Please change this to state exactly what you do use, even if it is no parameters
379  desc.setUnknown();
380  descriptions.addDefault(desc);
381 }
382 
383 //define this as a plug-in
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
void setSample(int i, const HcalTriggerPrimitiveSample &sam)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isLinkMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
bool isLinkDown(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
bool isLinkInError(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
bool isTowerMasked(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void makeECalTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, std::auto_ptr< EcalTrigPrimDigiCollection > &ecalTPGs)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
uint32_t nAMCs()
Definition: UCTDAQRawData.h:45
L1TCaloLayer1RawToDigi(const ParameterSet &)
const uint32_t * amcPayload(uint32_t amc)
unsigned long long uint64_t
Definition: Time.h:15
uint32_t getET(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
bool getFB(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)
virtual void endStream() override
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
virtual void produce(Event &, const EventSetup &) override
void makeHFTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, std::auto_ptr< HcalTrigPrimDigiCollection > &hfTPGs)
EcalSubdetector
virtual void beginStream(StreamID) override
void makeHCalTPGs(uint32_t lPhi, UCTCTP7RawData &ctp7Data, std::auto_ptr< HcalTrigPrimDigiCollection > &hcalTPGs)
bool isLinkMisaligned(CaloType cType, bool negativeEta, uint32_t cEta, uint32_t iPhi)