CMS 3D CMS Logo

GtRecordDump.cc
Go to the documentation of this file.
1 
12 
13 //
14 // This simple module simply retreives the YellowParams object from the event
15 // setup, and sends its payload as an INFO message, for debugging purposes.
16 //
17 
18 
20 
22 //#include "FWCore/ParameterSet/interface/InputTag.h"
23 
24 // system include files
25 #include <fstream>
26 #include <iomanip>
27 
28 // user include files
29 // base class
31 
39 
40 
46 
50 
54 
56 
59 
60 
61 using namespace edm;
62 using namespace std;
63 
64 namespace l1t {
65 
66  // class declaration
67  class GtRecordDump : public edm::EDAnalyzer {
68  public:
69  explicit GtRecordDump(const edm::ParameterSet&);
70  ~GtRecordDump() override{};
71  void analyze(const edm::Event&, const edm::EventSetup&) override;
72  void endRun(edm::Run const&, edm::EventSetup const&) override;
73 
84 
85  void dumpTestVectors(int bx, std::ofstream& myCout,
93 
94  cms_uint64_t formatMuon(std::vector<l1t::Muon>::const_iterator mu);
95  unsigned int formatEG(std::vector<l1t::EGamma>::const_iterator eg);
96  unsigned int formatTau(std::vector<l1t::Tau>::const_iterator tau);
97  unsigned int formatJet(std::vector<l1t::Jet>::const_iterator jet);
98  unsigned int formatMissET(std::vector<l1t::EtSum>::const_iterator etSum);
99  unsigned int formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum);
100  unsigned int formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum);
101  unsigned int formatAsym(std::vector<l1t::EtSum>::const_iterator etSum);
102  unsigned int formatHMB(std::vector<l1t::EtSum>::const_iterator etSum);
103  std::pair<unsigned int, unsigned int> formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum);
104  std::map<std::string, std::vector<int> > m_algoSummary;
105 
106 
107  unsigned int m_absBx;
109 
110  std::ofstream m_testVectorFile;
111 
116  int m_minBx;
117  int m_maxBx;
120 
122 
123  private:
125  };
126 
127  GtRecordDump::GtRecordDump(const edm::ParameterSet& iConfig)
128  {
129  uGtAlgInputTag = iConfig.getParameter<InputTag>("uGtAlgInputTag");
130  uGtExtInputTag = iConfig.getParameter<InputTag>("uGtExtInputTag");
131  egToken = consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<InputTag>("egInputTag"));
132  muToken = consumes<BXVector<l1t::Muon>>(iConfig.getParameter<InputTag>("muInputTag"));
133  tauToken = consumes<BXVector<l1t::Tau>>(iConfig.getParameter<InputTag>("tauInputTag"));
134  jetToken = consumes<BXVector<l1t::Jet>>(iConfig.getParameter<InputTag>("jetInputTag"));
135  etsumToken = consumes<BXVector<l1t::EtSum>>(iConfig.getParameter<InputTag>("etsumInputTag"));
136  uGtAlgToken = consumes<BXVector<GlobalAlgBlk>>(uGtAlgInputTag);
137  uGtExtToken = consumes<BXVector<GlobalExtBlk>>(uGtExtInputTag);
138  uGtObjectMapToken = consumes<GlobalObjectMapRecord>(iConfig.getParameter<InputTag>("uGtObjectMapInputTag"));
139 
140 
141  m_minBx = iConfig.getParameter<int>("minBx");
142  m_maxBx = iConfig.getParameter<int>("maxBx");
143  m_dumpGTRecord = iConfig.getParameter<bool>("dumpGTRecord");
144  m_dumpObjectMap = iConfig.getParameter<bool>("dumpGTObjectMap");
145  m_dumpTriggerResults = iConfig.getParameter<bool>("dumpTrigResults");
146 
147  m_minBxVectors = iConfig.getParameter<int>("minBxVec");
148  m_maxBxVectors = iConfig.getParameter<int>("maxBxVec");
149  m_dumpTestVectors = iConfig.getParameter<bool>("dumpVectors");
150  std::string fileName = iConfig.getParameter<std::string>("tvFileName");
151  if(m_dumpTestVectors) m_testVectorFile.open(fileName.c_str());
152  m_tvVersion = iConfig.getParameter<int>("tvVersion");
153 
154  m_bxOffset = iConfig.getParameter<int>("bxOffset");
155 
156  m_absBx = 0;
157  m_absBx += m_bxOffset;
158 
159  std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
160  unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
161 
162  m_gtUtil = new L1TGlobalUtil(iConfig, consumesCollector(), *this, uGtAlgInputTag, uGtExtInputTag);
163  m_gtUtil->OverridePrescalesAndMasks(preScaleFileName,preScColumn);
164 
165 
166  }
167 
168  // loop over events
170 
171 
172  //inputs
174  iEvent.getByToken(egToken,egammas);
175 
177  iEvent.getByToken(muToken,muons);
178 
180  iEvent.getByToken(tauToken,taus);
181 
183  iEvent.getByToken(jetToken,jets);
184 
186  iEvent.getByToken(etsumToken,etsums);
187 
189  iEvent.getByToken(uGtAlgToken,uGtAlg);
190 
192  iEvent.getByToken(uGtExtToken,uGtExt);
193 
194  Handle<GlobalObjectMapRecord> gtObjectMapRecord;
195  iEvent.getByToken(uGtObjectMapToken, gtObjectMapRecord);
196 
197 
198 
199 
200  //Fill the L1 result maps
201  m_gtUtil->retrieveL1(iEvent,evSetup,uGtAlgToken);
202 
203  LogDebug("GtRecordDump") << "retrieved L1 data " << endl;
204 
205  // grab the map for the final decisions
206  const std::vector<std::pair<std::string, bool> > initialDecisions = m_gtUtil->decisionsInitial();
207  const std::vector<std::pair<std::string, bool> > intermDecisions = m_gtUtil->decisionsInterm();
208  const std::vector<std::pair<std::string, bool> > finalDecisions = m_gtUtil->decisionsFinal();
209  const std::vector<std::pair<std::string, int> > prescales = m_gtUtil->prescales();
210  const std::vector<std::pair<std::string, std::vector<int> > > masks = m_gtUtil->masks();
211 
212  LogDebug("GtRecordDump") << "retrieved all event vectors " << endl;
213 
214  // Dump the results
215  if(m_dumpTriggerResults) {
216  cout << " Bit Algorithm Name Init aBXM Final PS Factor Num Bx Masked " << endl;
217  cout << "===============================================================================================================================" << endl;
218  }
219  for(unsigned int i=0; i<initialDecisions.size(); i++) {
220 
221  // get the name and trigger result
222  std::string name = (initialDecisions.at(i)).first;
223  bool resultInit = (initialDecisions.at(i)).second;
224 
225  // put together our map of algorithms and counts across events
226  if(m_algoSummary.count(name)==0) {
227  std::vector<int> tst;
228  tst.resize(3);
229  m_algoSummary[name]=tst;
230  }
231  if (resultInit) (m_algoSummary.find(name)->second).at(0) += 1;
232 
233  // get prescaled and final results (need some error checking here)
234  bool resultInterm = (intermDecisions.at(i)).second;
235  if (resultInterm) (m_algoSummary.find(name)->second).at(1) += 1;
236  bool resultFin = (finalDecisions.at(i)).second;
237  if (resultFin) (m_algoSummary.find(name)->second).at(2) += 1;
238 
239  // get the prescale and mask (needs some error checking here)
240  int prescale = (prescales.at(i)).second;
241  std::vector<int> mask = (masks.at(i)).second;
242 
243  if(m_dumpTriggerResults && name != "NULL") cout << std::dec << setfill(' ') << " " << setw(5) << i << " " << setw(60) << name.c_str() << " " << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale << setw(11) << mask.size() << endl;
244  }
245  bool finOR = m_gtUtil->getFinalOR();
246  if(m_dumpTriggerResults) {
247  cout << " FinalOR = " << finOR <<endl;
248  cout << "================================================================================================================================" << endl;
249  }
250 
251  if(m_dumpObjectMap) {
252 
253  if (!gtObjectMapRecord.isValid()) {
254  edm::LogWarning("GtRecordDump") << " Warning: GlobalObjectMapRecord requested in configuration, but not found in the event." << std::endl;
255  } else {
256 
257  const std::vector<GlobalObjectMap>& objMaps = gtObjectMapRecord->gtObjectMap();
258  for (size_t imap =0; imap < objMaps.size(); imap++) {
259 
260  GlobalObjectMap oMap = objMaps.at(imap);
261 
262  int bit = oMap.algoBitNumber(); // same as bit from L1T Menu
263  int mapDecision = oMap.algoGtlResult();
264 
265  // Check Object Map Result Agrees with GlobalAlgBlk result
266  if(mapDecision != (finalDecisions.at(bit)).second) {
267  std::cout << "WARNING: GlobalAlgBlk and ObjectMap Disagree on result for bit " << bit << " Alg: " << oMap.algoName() << std::endl;
268  }
269 
270 
271  // dump only if we have a positive trigger
272  if(mapDecision != 0) {
273 
274  // Header info
275  std::cout << " -------------------------------------------------------------------------------------------- \n" <<
276  " Bit " << setw(3) << bit << " Decision " << setw(2) << mapDecision << " Alg Name " << setw(40) << oMap.algoName() << std::endl;
277 
278  // Combination
279  const std::vector<GlobalLogicParser::OperandToken>& opTokenVecObjMap = oMap.operandTokenVector();
280  const std::vector<L1TObjectTypeInCond>& condObjTypeVec = oMap.objectTypeVector();
281 // const std::vector<CombinationsInCond>& condCombinations = oMapcombinationVector();
282 
283  for(size_t iCond=0; iCond<opTokenVecObjMap.size(); iCond++) {
284 
285  std::cout << " " << iCond <<") Condition Token: " << opTokenVecObjMap.at(iCond).tokenName << " Types: ";
286  std::vector<l1t::GlobalObject> condObjType = condObjTypeVec[iCond];
287  for(size_t iCondType=0; iCondType<condObjType.size(); iCondType++) {
288  std::cout << condObjType.at(iCondType) << " ";
289  }
290  std::cout << std::endl;
291 
292  const CombinationsInCond* condComb = oMap.getCombinationsInCond(iCond);
293  std::cout << " Combinations in Condition [" << condComb->size() <<"] : ";
294  for (std::vector<SingleCombInCond>::const_iterator itComb = (*condComb).begin(); itComb != (*condComb).end(); itComb++) {
295 
296  // loop over objects in a combination for a given condition
297  //
298  unsigned int iType = 0;
299  std::cout << "(";
300  for (SingleCombInCond::const_iterator itObject = (*itComb).begin(); itObject != (*itComb).end(); itObject++) {
301 
302  // loop over types for the object in a combination. This object might have more then one type (i.e. mu-eg)
303  //
304 
305 // for (size_t iType =0; iType < condObjType.size(); iType++) {
306 
307  // get object type and push indices on the list
308  //
309  //const l1t::GlobalObject objTypeVal = condObjType.at(iType);
310 
311  std::cout << (*itObject);
312  //std::cout <<objTypeVal << "@" << (*itObject);
313  if(iType<condObjType.size()-1) std::cout << ",";
314  //std::cout
315  //<< "\tAdd object of type " << objTypeVal << " and index " << (*itObject) << " to the seed list."
316  //<< std::endl;
317 
318 // } // end loop over objs in combination
319  iType++;
320 
321  } //end loop over objects for a condition
322  std::cout << ") ";
323  }
324  std::cout << std::endl;
325  }
326  } //end if alg fired
327  } //end loop over maps
328  } //end if valid record
329  } //end if dump maps
330 
331 
332  if(m_dumpGTRecord) {
333 
334  cout << " ----------------------------------------------------- " << endl;
335  cout << " *********** Run " << std::dec << iEvent.id().run() <<" Event " << iEvent.id().event() << " ************** " << endl;
336  cout << " ----------------------------------------------------- " << endl;
337 
338  //Loop over BX
339  for(int i =m_minBx; i <= m_maxBx; ++i) {
340 
341  cout << " ========= Rel BX = " << std::dec << i << " ====== Total BX = " << m_absBx << " ==========" << endl;
342 
343  //Loop over EGamma
344  int nObj =0;
345  cout << " ------ EGammas -------- " << endl;
346  if (egammas.isValid()) {
347  if(i>=egammas->getFirstBX() && i<=egammas->getLastBX()) {
348  for(std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(i); eg != egammas->end(i); ++eg) {
349  cout << " " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0')<< ")";
350  cout << " Pt " << std::dec << std::setw(3) << eg->hwPt() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << eg->hwPt() << ")";
351  cout << " Eta " << std::dec << std::setw(3) << eg->hwEta() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << (eg->hwEta()&0xff) << ")";
352  cout << " Phi " << std::dec << std::setw(3) << eg->hwPhi() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << eg->hwPhi() << ")";
353  cout << " Iso " << std::dec << std::setw(1) << eg->hwIso() ;
354  cout << " Qual "<< std::dec << std::setw(1) << eg->hwQual() ;
355  cout << endl;
356  nObj++;
357  }
358  } else {
359  cout << "No EG stored for this bx " << i << endl;
360  }
361  } else {
362  cout << "No EG Data in this event " << endl;
363  }
364 
365  //Loop over Muons
366  nObj =0;
367  cout << " ------ Muons --------" << endl;
368  if (muons.isValid()) {
369  if(i>=muons->getFirstBX() && i<=muons->getLastBX()) {
370  for(std::vector<l1t::Muon>::const_iterator mu = muons->begin(i); mu != muons->end(i); ++mu) {
371  cout << " " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0')<< ")";
372  cout << " Pt " << std::dec << std::setw(3) << mu->hwPt() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << mu->hwPt() << ")";
373  cout << " EtaAtVtx " << std::dec << std::setw(3) << mu->hwEtaAtVtx() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << (mu->hwEtaAtVtx()&0x1ff) << ")";
374  cout << " Eta " << std::dec << std::setw(3) << mu->hwEta() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << (mu->hwEta()&0x1ff) << ")";
375  cout << " PhiAtVtx " << std::dec << std::setw(3) << mu->hwPhiAtVtx() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << mu->hwPhiAtVtx() << ")";
376  cout << " Phi " << std::dec << std::setw(3) << mu->hwPhi() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << mu->hwPhi() << ")";
377  cout << " Iso " << std::dec << std::setw(1) << mu->hwIso() ;
378  cout << " Qual "<< std::dec << std::setw(1) << mu->hwQual() ;
379  cout << " Chrg "<< std::dec << std::setw(1) << mu->hwCharge();
380  cout << endl;
381  nObj++;
382  }
383  }else {
384  cout << "No Muons stored for this bx " << i << endl;
385  }
386  } else {
387  cout << "No Muon Data in this event " << endl;
388  }
389 
390  //Loop over Taus
391  nObj =0;
392  cout << " ------ Taus ----------" << endl;
393  if(taus.isValid()) {
394  if(i>=taus->getFirstBX() && i<=taus->getLastBX()) {
395  for(std::vector<l1t::Tau>::const_iterator tau = taus->begin(i); tau != taus->end(i); ++tau) {
396  cout << " " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0')<< ")";
397  cout << " Pt " << std::dec << std::setw(3) << tau->hwPt() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << tau->hwPt() << ")";
398  cout << " Eta " << std::dec << std::setw(3) << tau->hwEta() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << (tau->hwEta()&0xff) << ")";
399  cout << " Phi " << std::dec << std::setw(3) << tau->hwPhi() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << tau->hwPhi() << ")";
400  cout << " Iso " << std::dec << std::setw(1) << tau->hwIso() ;
401  cout << " Qual "<< std::dec << std::setw(1) << tau->hwQual() ;
402  cout << endl;
403  nObj++;
404  }
405  } else {
406  cout << "No Taus stored for this bx " << i << endl;
407  }
408  } else {
409  cout << "No Tau Data in this event " << endl;
410  }
411 
412  //Loop over Jets
413  nObj =0;
414  cout << " ------ Jets ----------" << endl;
415  if(jets.isValid()) {
416  if(i>=jets->getFirstBX() && i<=jets->getLastBX()) {
417  for(std::vector<l1t::Jet>::const_iterator jet = jets->begin(i); jet != jets->end(i); ++jet) {
418  cout << " " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0')<< ")";
419  cout << " Pt " << std::dec << std::setw(3) << jet->hwPt() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << jet->hwPt() << ")";
420  cout << " Eta " << std::dec << std::setw(3) << jet->hwEta() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << (jet->hwEta()&0xff) << ")";
421  cout << " Phi " << std::dec << std::setw(3) << jet->hwPhi() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << jet->hwPhi() << ")";
422  cout << " Qual "<< std::dec << std::setw(1) << jet->hwQual() ;
423  cout << endl;
424  nObj++;
425  }
426  } else {
427  cout << "No Jets stored for this bx " << i << endl;
428  }
429  } else {
430  cout << "No jet Data in this event " << endl;
431  }
432 
433  //Dump Content
434  cout << " ------ EtSums ----------" << endl;
435  if(etsums.isValid()) {
436  if(i>=etsums->getFirstBX() && i<=etsums->getLastBX()) {
437  for(std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(i); etsum != etsums->end(i); ++etsum) {
438  switch ( etsum->getType() ) {
440  cout << " ETM: ";
441  break;
443  cout << " ETMHF:";
444  break;
446  cout << " HTMHF:";
447  break;
449  cout << " HTM: ";
450  break;
452  cout << " ETT: ";
453  break;
455  cout << " ETTem:";
456  break;
458  cout << " HTT: ";
459  break;
461  cout << " TowerCounts: ";
462  break;
464  cout << " AsymEt: ";
465  break;
467  cout << " AsymHt: ";
468  break;
470  cout << " AsymEtHF: ";
471  break;
473  cout << " AsymHtHF: ";
474  break;
476  cout << " HFP0: ";
477  break;
479  cout << " HFM0: ";
480  break;
482  cout << " HFP1: ";
483  break;
485  cout << " HFM1: ";
486  break;
488  cout << " Centrality: ";
489  break;
490  default:
491  cout << " Unknown: ";
492  break;
493  }
494  cout << " Et " << std::dec << std::setw(3) << etsum->hwPt() << " (0x" << std::hex << std::setw(3) << std::setfill('0') << etsum->hwPt() << ")";
495  if(etsum->getType() == l1t::EtSum::EtSumType::kMissingEt ||
496  etsum->getType() == l1t::EtSum::EtSumType::kMissingHt ||
497  etsum->getType() == l1t::EtSum::EtSumType::kMissingEtHF)
498  cout << " Phi " << std::dec << std::setw(3) << etsum->hwPhi() << " (0x" << std::hex << std::setw(2) << std::setfill('0') << etsum->hwPhi() << ")";
499  cout << endl;
500  }
501  } else {
502  cout << "No EtSums stored for this bx " << i << endl;
503  }
504  } else {
505  cout << "No EtSum Data in this event " << endl;
506  }
507 
508  // Dump the output record
509  cout << " ------ uGtExt ----------" << endl;
510  if(uGtExt.isValid()) {
511  if(i>=uGtExt->getFirstBX() && i<=uGtExt->getLastBX()) {
512  for(std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(i); extBlk != uGtExt->end(i); ++extBlk) {
513  extBlk->print(std::cout);
514  }
515  } else {
516  cout << "No Ext Conditions stored for this bx " << i << endl;
517  }
518  } else {
519  cout << "No uGtExt Data in this event " << endl;
520  }
521 
522  // Dump the output record
523  cout << " ------ uGtAlg ----------" << endl;
524  if(uGtAlg.isValid()) {
525  if(i>=uGtAlg->getFirstBX() && i<=uGtAlg->getLastBX()) {
526  for(std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(i); algBlk != uGtAlg->end(i); ++algBlk) {
527  algBlk->print(std::cout);
528  }
529  } else {
530  cout << "No Alg Decisions stored for this bx " << i << endl;
531  }
532  } else {
533  cout << "No uGtAlg Data in this event " << endl;
534  }
535 
536 
537 
538 
539 
540  } //loop over Bx
541  cout << std::dec <<endl;
542  } //if dumpGtRecord
543 
544  // Dump Test Vectors for this bx
545  if(m_dumpTestVectors) {
546  for(int i=m_minBxVectors; i<=m_maxBxVectors; i++) {
547 // if( (i>=egammas->getFirstBX() && i<=egammas->getLastBX())&&
548 // (i>=muons->getFirstBX() && i<=muons->getLastBX()) &&
549 // (i>=taus->getFirstBX() && i<=taus->getLastBX()) &&
550 // (i>=jets->getFirstBX() && i<=jets->getLastBX()) &&
551 // (i>=etsums->getFirstBX() && i<=etsums->getLastBX()) &&
552 // (i>=uGtAlg->getFirstBX() && i<=uGtAlg->getLastBX()) &&
553 // (i>=uGtAlg->getFirstBX() && i<=uGtAlg->getLastBX()) ) {
554  dumpTestVectors(i, m_testVectorFile, muons, egammas, taus, jets, etsums, uGtAlg, uGtExt);
555 // } else {
556 // edm::LogWarning("GtRecordDump") << "WARNING: Not enough information to dump test vectors for this bx=" << i << endl;
557 // }
558  }
559  }
560 
561 
562 
563  }
564 
565 // ------------ method called when ending the processing of a run ------------
566 
567 void
569 {
570  // Dump the results
571  cout << "=========================== Global Trigger Summary Report ==================================" << endl;
572  cout << " Algorithm Name Init aBXM Final " << endl;
573  cout << "=============================================================================================" << endl;
574  for (std::map<std::string, std::vector<int> >::const_iterator itAlgo = m_algoSummary.begin(); itAlgo != m_algoSummary.end(); itAlgo++) {
575 
576  std::string name = itAlgo->first;
577  int initCnt = (itAlgo->second).at(0);
578  int initPre = (itAlgo->second).at(1);
579  int initFnl = (itAlgo->second).at(2);
580  if(name != "NULL") cout << std::dec << setfill(' ') << setw(60) << name.c_str() << setw(10) << initCnt << setw(10) << initPre << setw(10) << initFnl << endl;
581  }
582  cout << "===========================================================================================================" << endl;
583 }
584 
585 
586 
587 void GtRecordDump::dumpTestVectors(int bx, std::ofstream& myOutFile,
589  Handle<BXVector<l1t::EGamma>> egammas,
595  ) {
596 
597 
598  const int empty = 0;
599 
600 // Dump Bx (4 digits)
601  myOutFile << std::dec << std::setw(4) << std::setfill('0') << m_absBx;
602 
603 // Dump 8 Muons (16 digits + space)
604  int nDumped = 0;
605  if(muons.isValid()){
606  for(std::vector<l1t::Muon>::const_iterator mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
607  cms_uint64_t packedWd = formatMuon(mu);
608  if(nDumped<8) {
609  myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
610  nDumped++;
611  }
612  }
613  }
614  for(int i=nDumped; i<8; i++) {
615  myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << empty;
616  }
617 
618 // Dump 12 EG (8 digits + space)
619  nDumped = 0;
620  if(egammas.isValid()){
621  for(std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(bx); eg != egammas->end(bx); ++eg) {
622  unsigned int packedWd = formatEG(eg);
623  if(nDumped<12) {
624  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
625  nDumped++;
626  }
627  }
628  }
629  for(int i=nDumped; i<12; i++) {
630  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
631  }
632 
633 
634 // Dump 8 tau (8 digits + space)
635  nDumped = 0;
636  int maxTau = 8;
637  if(m_tvVersion>1) maxTau = 12;
638  if(taus.isValid()) {
639  for(std::vector<l1t::Tau>::const_iterator tau = taus->begin(bx); tau != taus->end(bx); ++tau) {
640  unsigned int packedWd = formatTau(tau);
641  if(nDumped<maxTau) {
642  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
643  nDumped++;
644  }
645  }
646  }
647  for(int i=nDumped; i<maxTau; i++) {
648  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
649  }
650 
651 // Dump 12 Jets (8 digits + space)
652  nDumped = 0;
653  if(jets.isValid()) {
654  for(std::vector<l1t::Jet>::const_iterator jet = jets->begin(bx); jet != jets->end(bx); ++jet) {
655  unsigned int packedWd = formatJet(jet);
656  if(nDumped<12) {
657  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
658  nDumped++;
659  }
660  }
661  }
662  for(int i=nDumped; i<12; i++) {
663  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
664  }
665 
666 // Dump Et Sums (ETT, HT, ETM, ETMHF, HTM)
667  unsigned int ETTpackWd = 0;
668  unsigned int HTTpackWd = 0;
669  unsigned int ETMpackWd = 0;
670  unsigned int HTMpackWd = 0;
671  unsigned int ETMHFpackWd = 0;
672  unsigned int HTMHFpackWd = 0;
673 
674 // quantities packed into the words
675  unsigned int ETTempackWd = 0;
676  unsigned int HFP0packWd = 0;
677  unsigned int HFM0packWd = 0;
678  unsigned int HFP1packWd = 0;
679  unsigned int HFM1packWd = 0;
680  unsigned int TowerCountspackWd = 0; // ccla
681  unsigned int AsymEtpackWd = 0;
682  unsigned int AsymHtpackWd = 0;
683  unsigned int AsymEtHFpackWd = 0;
684  unsigned int AsymHtHFpackWd = 0;
685  unsigned int CENT30packWd = 0; // centrality bits 3:0 in ETMHF word
686  unsigned int CENT74packWd = 0; // centrality bits 7:4 in HTMHF word
687  std::pair<unsigned int, unsigned int> centrality(0,0);
688 
689  if(etsums.isValid()){
690  for(std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(bx); etsum != etsums->end(bx); ++etsum) {
691 
692  switch ( etsum->getType() ) {
694  ETMpackWd = formatMissET(etsum);
695  break;
697  ETMHFpackWd = formatMissET(etsum);
698  break;
700  HTMHFpackWd = formatMissET(etsum);
701  break;
703  HTMpackWd = formatMissET(etsum);
704  break;
706  ETTpackWd = formatTotalET(etsum);
707  break;
709  ETTempackWd = formatTotalET(etsum);
710  break;
712  HTTpackWd = formatTotalET(etsum);
713  break;
715  TowerCountspackWd = formatTowerCounts(etsum);
716  break;
718  HFP0packWd = formatHMB(etsum);
719  break;
721  HFM0packWd = formatHMB(etsum);
722  break;
724  HFP1packWd = formatHMB(etsum);
725  break;
727  HFM1packWd = formatHMB(etsum);
728  break;
730  centrality = formatCentrality(etsum);
731  CENT30packWd = centrality.first;
732  CENT74packWd = centrality.second;
733  break;
735  AsymEtpackWd = formatAsym(etsum);
736  break;
738  AsymHtpackWd = formatAsym(etsum);
739  break;
741  AsymEtHFpackWd = formatAsym(etsum);
742  break;
744  AsymHtHFpackWd = formatAsym(etsum);
745  break;
746  default:
747  break;
748  } //end switch statement
749  } //end loop over etsums
750  }
751 
752  // Put HMB bits in upper part of other SumEt Words
753  ETTpackWd |= HFP0packWd;
754  HTTpackWd |= HFM0packWd;
755  ETMpackWd |= HFP1packWd;
756  HTMpackWd |= HFM1packWd;
757 
758  // ETTem goes into ETT word bits 12 - 23
759  if(m_tvVersion>1) ETTpackWd |= ( ETTempackWd << 12);
760 
761  // ccla Towercounts go in HTT word, bits 12-24
762  if(m_tvVersion>1) HTTpackWd |= ( TowerCountspackWd << 12);
763  if(m_tvVersion>2){
764  ETMpackWd |= AsymEtpackWd;
765  HTMpackWd |= AsymHtpackWd;
766  ETMHFpackWd |= AsymEtHFpackWd;
767  HTMHFpackWd |= AsymHtHFpackWd;
768 
769  ETMHFpackWd |= CENT30packWd;
770  HTMHFpackWd |= CENT74packWd;
771 
772  }
773  // Fill in the words in appropriate order
774  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETTpackWd;
775  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTTpackWd;
776  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMpackWd;
777  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMpackWd;
778  if(m_tvVersion>1) {
779  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMHFpackWd;
780  if(m_tvVersion>2) {
781  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMHFpackWd;
782  } else{
783  myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
784  }
785  }
786 
787 
788 // If tvVersion > 1 put in placeholds for empty link (6 words (frames)) all zeros.
789  if(m_tvVersion>1) {
790  for(int i=0; i<6; i++) myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
791  }
792 
793 // External Condition (64 digits + space)
794  int digit = 0;
795  myOutFile << " ";
796  if(uGtExt.isValid()) {
797  for(std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(bx); extBlk != uGtExt->end(bx); ++extBlk) {
798  for(int i=255; i>-1; i--) {
799  if(extBlk->getExternalDecision(i)) digit |= (1 << (i%4));
800  if((i%4) == 0){
801  myOutFile << std::hex << std::setw(1) << digit;
802  digit = 0;
803  }
804  } //end loop over external bits
805  } //loop over objects
806  } else {
807  myOutFile << std::hex << std::setw(64) << std::setfill('0') << empty;
808  }
809 
810 // Algorithm Dump (128 digits + space)
811  digit = 0;
812  myOutFile << " ";
813  if(uGtAlg.isValid()) {
814  for(std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(bx); algBlk != uGtAlg->end(bx); ++algBlk) {
815  for(int i=511; i>-1; i--) {
816  if(algBlk->getAlgoDecisionFinal(i)) digit |= (1 << (i%4));
817  if((i%4) == 0){
818  myOutFile << std::hex << std::setw(1) << digit;
819  digit = 0;
820  }
821  } //end loop over algorithm bits
822 
823  // Final OR (1 digit + space)
824  unsigned int finalOr = (algBlk->getFinalOR() & 0x1);
825  myOutFile << " " << std::hex << std::setw(1) << std::setfill('0') << finalOr;
826  }
827  } else {
828  myOutFile << std::hex << std::setw(128) << std::setfill('0') << empty;
829  }
830 
831  myOutFile << endl;
832 
833  m_absBx++;
834 
835 }
836 
837 cms_uint64_t GtRecordDump::formatMuon(std::vector<l1t::Muon>::const_iterator mu){
838 
839  cms_uint64_t packedVal = 0;
840 
841 // Pack Bits
842  packedVal |= ((cms_uint64_t)(mu->hwPhi() & 0x3ff) <<43);
843  packedVal |= ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) <<0); // & 0x3ff) <<18);
844  packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) <<53);
845  packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) <<23); // & 0x1ff) <<9);
846  packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) <<10); // & 0x1ff) <<0);
847  packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) <<35); // & 0x1) <<28);
848  packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) <<34); // & 0x1) <<29);
849  packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) <<19); // & 0xf) <<30);
850  packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) <<32); // & 0x3) <<34);
851 
852  return packedVal;
853 }
854 
855 unsigned int GtRecordDump::formatEG(std::vector<l1t::EGamma>::const_iterator eg){
856 
857  unsigned int packedVal = 0;
858 
859 // Pack Bits
860  packedVal |= ((eg->hwPhi() & 0xff) <<17);
861  packedVal |= ((eg->hwEta() & 0xff) <<9);
862  packedVal |= ((eg->hwPt() & 0x1ff) <<0);
863  packedVal |= ((eg->hwIso() & 0x3) <<25);
864  packedVal |= ((eg->hwQual() & 0x31) <<27);
865 
866  return packedVal;
867 }
868 
869 unsigned int GtRecordDump::formatTau(std::vector<l1t::Tau>::const_iterator tau){
870 
871  unsigned int packedVal = 0;
872 
873 // Pack Bits
874  packedVal |= ((tau->hwPhi() & 0xff) <<17);
875  packedVal |= ((tau->hwEta() & 0xff) <<9);
876  packedVal |= ((tau->hwPt() & 0x1ff) <<0);
877  packedVal |= ((tau->hwIso() & 0x3) <<25);
878  packedVal |= ((tau->hwQual() & 0x31) <<27);
879 
880  return packedVal;
881 }
882 
883 unsigned int GtRecordDump::formatJet(std::vector<l1t::Jet>::const_iterator jet){
884 
885  unsigned int packedVal = 0;
886 
887 // Pack Bits
888  packedVal |= ((jet->hwPhi() & 0xff) <<19);
889  packedVal |= ((jet->hwEta() & 0xff) <<11);
890  packedVal |= ((jet->hwPt() & 0x7ff) <<0);
891  packedVal |= ((jet->hwQual() & 0x1) <<27);
892 
893  return packedVal;
894 }
895 
896 unsigned int GtRecordDump::formatMissET(std::vector<l1t::EtSum>::const_iterator etSum){
897 
898  unsigned int packedVal = 0;
899 
900 // Pack Bits
901  packedVal |= ((etSum->hwPhi() & 0xff) <<12);
902  packedVal |= ((etSum->hwPt() & 0xfff) <<0);
903 
904  return packedVal;
905 }
906 
907 unsigned int GtRecordDump::formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum){
908 
909  unsigned int packedVal = 0;
910 
911 // Pack Bits
912  packedVal |= ((etSum->hwPt() & 0xfff) <<0);
913 
914  return packedVal;
915 }
916 
917 unsigned int GtRecordDump::formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum){
918 
919  unsigned int packedVal = 0;
920  //unsigned int shift = 12;
921 
922  // Pack Bits
923  //packedVal |= ((etSum->hwPt() & 0xfff) << shift);
924 
925  //towercount takes 13 bits
926  packedVal |= ((etSum->hwPt() & 0x1fff) <<0);
927 
928  return packedVal;
929 }
930 
931 unsigned int GtRecordDump::formatAsym(std::vector<l1t::EtSum>::const_iterator etSum){
932 
933  //asym takes 8 bits, occupying bits 20-27 in ETM, HTM, ETMHF, and HTMHF etsums
934  unsigned int packedVal = 0;
935  unsigned int shift = 20;
936 
937  // Pack Bits
938  packedVal |= ((etSum->hwPt() & 0xff) << shift);
939 
940  return packedVal;
941 }
942 
943 unsigned int GtRecordDump::formatHMB(std::vector<l1t::EtSum>::const_iterator etSum){
944 
945  // 4 bits, occupying bits 28-31.
946  unsigned int packedVal = 0;
947  unsigned int shift = 28;
948 
949 // Pack Bits
950  packedVal |= ((etSum->hwPt() & 0xf) << shift);
951 
952  return packedVal;
953 }
954 
955 std::pair<unsigned int, unsigned int> GtRecordDump::formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum){
956 
957 
958  unsigned int centword = etSum->hwPt();
959 
960  // unpack word into 2 4 bit words
961  int firstfour = (centword & 0xF);
962  int lastfour = (centword >> 4) & 0xF;
963 
964  // 4 bits, occupying bits 28-31.
965  unsigned int packedValLN = 0;
966  unsigned int packedValUN = 0;
967  unsigned int shift = 28;
968 
969 // Pack Bits
970  packedValLN |= ((firstfour & 0xf) << shift);
971  packedValUN |= ((lastfour & 0xf) << shift);
972 
973  std::pair<unsigned int, unsigned int> centrality(packedValLN, packedValUN);
974  return centrality;
975 }
976 
977 
978 }
979 
980 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
EDGetToken uGtAlgToken
Definition: GtRecordDump.cc:81
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
L1TGlobalUtil * m_gtUtil
std::map< std::string, std::vector< int > > m_algoSummary
EDGetToken uGtObjectMapToken
Definition: GtRecordDump.cc:83
const std::vector< L1TObjectTypeInCond > & objectTypeVector() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
InputTag uGtAlgInputTag
Definition: GtRecordDump.cc:74
bool algoGtlResult() const
delete x;
Definition: CaloConfig.h:22
~GtRecordDump() override
Definition: GtRecordDump.cc:70
const std::vector< GlobalObjectMap > & gtObjectMap() const
get / set the vector of object maps
EDGetToken egToken
Definition: GtRecordDump.cc:76
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
U second(std::pair< T, U > const &p)
InputTag uGtExtInputTag
Definition: GtRecordDump.cc:75
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
EDGetToken jetToken
Definition: GtRecordDump.cc:79
vector< PseudoJet > jets
int algoBitNumber() const
get / set bit number for algorithm in the object map
const int mu
Definition: Constants.h:22
bool isValid() const
Definition: HandleBase.h:74
const std::vector< GlobalLogicParser::OperandToken > & operandTokenVector() const
EDGetToken uGtExtToken
Definition: GtRecordDump.cc:82
const std::string & algoName() const
destructor
EDGetToken muToken
Definition: GtRecordDump.cc:77
EDGetToken tauToken
Definition: GtRecordDump.cc:78
edm::EventID id() const
Definition: EventBase.h:59
const CombinationsInCond * getCombinationsInCond(const std::string &condNameVal) const
return all the combinations passing the requirements imposed in condition condNameVal ...
HLT enums.
static unsigned int const shift
unsigned long long cms_uint64_t
Definition: typedefs.h:17
T first(std::pair< T, U > const &p)
std::vector< SingleCombInCond > CombinationsInCond
all the object combinations evaluated to true in the condition
unsigned int m_absBx
std::ofstream m_testVectorFile
EDGetToken etsumToken
Definition: GtRecordDump.cc:80
Definition: Run.h:45