Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-14 23:16:58

0001 ///
0002 /// \class l1t::GtRecordDump.cc
0003 ///
0004 /// Description: Dump/Analyze Input Collections for GT.
0005 ///
0006 /// Implementation:
0007 ///    Based off of Michael Mulhearn's YellowParamTester
0008 ///
0009 /// \author: Brian Winer Ohio State
0010 ///
0011 
0012 //
0013 //  This simple module simply retreives the YellowParams object from the event
0014 //  setup, and sends its payload as an INFO message, for debugging purposes.
0015 //
0016 
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 
0019 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0020 //#include "FWCore/ParameterSet/interface/InputTag.h"
0021 
0022 // system include files
0023 #include <fstream>
0024 #include <iomanip>
0025 #include <memory>
0026 
0027 // user include files
0028 //   base class
0029 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0030 
0031 #include "FWCore/Framework/interface/Event.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/Utilities/interface/EDGetToken.h"
0034 #include "FWCore/Utilities/interface/InputTag.h"
0035 #include "FWCore/Framework/interface/EventSetup.h"
0036 #include "FWCore/Framework/interface/Frameworkfwd.h"
0037 
0038 #include "DataFormats/L1Trigger/interface/EGamma.h"
0039 #include "DataFormats/L1Trigger/interface/Muon.h"
0040 #include "DataFormats/L1Trigger/interface/MuonShower.h"
0041 #include "DataFormats/L1Trigger/interface/Tau.h"
0042 #include "DataFormats/L1Trigger/interface/Jet.h"
0043 #include "DataFormats/L1Trigger/interface/EtSum.h"
0044 
0045 #include "DataFormats/L1TGlobal/interface/GlobalAlgBlk.h"
0046 #include "DataFormats/L1TGlobal/interface/GlobalExtBlk.h"
0047 #include "DataFormats/L1TGlobal/interface/GlobalObject.h"
0048 
0049 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapFwd.h"
0050 #include "DataFormats/L1TGlobal/interface/GlobalObjectMap.h"
0051 #include "DataFormats/L1TGlobal/interface/GlobalObjectMapRecord.h"
0052 
0053 #include "L1Trigger/L1TGlobal/interface/L1TGlobalUtil.h"
0054 
0055 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0056 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0057 
0058 using namespace edm;
0059 using namespace std;
0060 
0061 namespace l1t {
0062 
0063   // class declaration
0064   class GtRecordDump : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0065   public:
0066     explicit GtRecordDump(const edm::ParameterSet&);
0067     ~GtRecordDump() override {}
0068     void beginRun(edm::Run const&, edm::EventSetup const&) override {}
0069     void analyze(const edm::Event&, const edm::EventSetup&) override;
0070     void endRun(edm::Run const&, edm::EventSetup const&) override;
0071 
0072     InputTag uGtAlgInputTag;
0073     InputTag uGtExtInputTag;
0074     EDGetToken egToken;
0075     EDGetToken muToken;
0076     EDGetToken muShowerToken;
0077     EDGetToken tauToken;
0078     EDGetToken jetToken;
0079     EDGetToken etsumToken;
0080     EDGetToken uGtAlgToken;
0081     EDGetToken uGtExtToken;
0082     EDGetToken uGtObjectMapToken;
0083 
0084     void dumpTestVectors(int bx,
0085                          std::ofstream& myCout,
0086                          Handle<BXVector<l1t::Muon>> muons,
0087                          Handle<BXVector<l1t::MuonShower>> muonShowers,
0088                          Handle<BXVector<l1t::EGamma>> egammas,
0089                          Handle<BXVector<l1t::Tau>> taus,
0090                          Handle<BXVector<l1t::Jet>> jets,
0091                          Handle<BXVector<l1t::EtSum>> etsums,
0092                          Handle<BXVector<GlobalAlgBlk>> uGtAlg,
0093                          Handle<BXVector<GlobalExtBlk>> uGtExt);
0094 
0095     cms_uint64_t formatMuon(std::vector<l1t::Muon>::const_iterator mu, int muShowerBit);
0096     cms_uint64_t formatNonExistantMuon(int muShowerBit);
0097     unsigned int formatEG(std::vector<l1t::EGamma>::const_iterator eg);
0098     unsigned int formatTau(std::vector<l1t::Tau>::const_iterator tau);
0099     unsigned int formatJet(std::vector<l1t::Jet>::const_iterator jet);
0100     unsigned int formatMissET(std::vector<l1t::EtSum>::const_iterator etSum);
0101     unsigned int formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum);
0102     unsigned int formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum);
0103     unsigned int formatAsym(std::vector<l1t::EtSum>::const_iterator etSum);
0104     unsigned int formatHMB(std::vector<l1t::EtSum>::const_iterator etSum);
0105     std::pair<unsigned int, unsigned int> formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum);
0106     std::map<std::string, std::vector<int>, std::less<>> m_algoSummary;
0107 
0108     unsigned int m_absBx;
0109     int m_bxOffset;
0110 
0111     std::ofstream m_testVectorFile;
0112 
0113     bool m_dumpTestVectors;
0114     bool m_dumpGTRecord;
0115     bool m_dumpObjectMap;
0116     bool m_dumpTriggerResults;
0117     int m_minBx;
0118     int m_maxBx;
0119     int m_minBxVectors;
0120     int m_maxBxVectors;
0121 
0122     std::unique_ptr<L1TGlobalUtil> m_gtUtil;
0123 
0124   private:
0125     int m_tvVersion;
0126   };
0127 
0128   GtRecordDump::GtRecordDump(const edm::ParameterSet& iConfig) {
0129     uGtAlgInputTag = iConfig.getParameter<InputTag>("uGtAlgInputTag");
0130     uGtExtInputTag = iConfig.getParameter<InputTag>("uGtExtInputTag");
0131     egToken = consumes<BXVector<l1t::EGamma>>(iConfig.getParameter<InputTag>("egInputTag"));
0132     muToken = consumes<BXVector<l1t::Muon>>(iConfig.getParameter<InputTag>("muInputTag"));
0133     muShowerToken = consumes<BXVector<l1t::MuonShower>>(iConfig.getParameter<InputTag>("muShowerInputTag"));
0134     tauToken = consumes<BXVector<l1t::Tau>>(iConfig.getParameter<InputTag>("tauInputTag"));
0135     jetToken = consumes<BXVector<l1t::Jet>>(iConfig.getParameter<InputTag>("jetInputTag"));
0136     etsumToken = consumes<BXVector<l1t::EtSum>>(iConfig.getParameter<InputTag>("etsumInputTag"));
0137     uGtAlgToken = consumes<BXVector<GlobalAlgBlk>>(uGtAlgInputTag);
0138     uGtExtToken = consumes<BXVector<GlobalExtBlk>>(uGtExtInputTag);
0139     uGtObjectMapToken = consumes<GlobalObjectMapRecord>(iConfig.getParameter<InputTag>("uGtObjectMapInputTag"));
0140 
0141     m_minBx = iConfig.getParameter<int>("minBx");
0142     m_maxBx = iConfig.getParameter<int>("maxBx");
0143     m_dumpGTRecord = iConfig.getParameter<bool>("dumpGTRecord");
0144     m_dumpObjectMap = iConfig.getParameter<bool>("dumpGTObjectMap");
0145     m_dumpTriggerResults = iConfig.getParameter<bool>("dumpTrigResults");
0146 
0147     m_minBxVectors = iConfig.getParameter<int>("minBxVec");
0148     m_maxBxVectors = iConfig.getParameter<int>("maxBxVec");
0149     m_dumpTestVectors = iConfig.getParameter<bool>("dumpVectors");
0150     std::string fileName = iConfig.getParameter<std::string>("tvFileName");
0151     if (m_dumpTestVectors)
0152       m_testVectorFile.open(fileName.c_str());
0153     m_tvVersion = iConfig.getParameter<int>("tvVersion");
0154 
0155     m_bxOffset = iConfig.getParameter<int>("bxOffset");
0156 
0157     m_absBx = 0;
0158     m_absBx += m_bxOffset;
0159 
0160     std::string preScaleFileName = iConfig.getParameter<std::string>("psFileName");
0161     unsigned int preScColumn = iConfig.getParameter<int>("psColumn");
0162 
0163     m_gtUtil = std::make_unique<L1TGlobalUtil>(
0164         iConfig, consumesCollector(), *this, uGtAlgInputTag, uGtExtInputTag, l1t::UseEventSetupIn::Event);
0165     m_gtUtil->OverridePrescalesAndMasks(preScaleFileName, preScColumn);
0166   }
0167 
0168   // loop over events
0169   void GtRecordDump::analyze(const edm::Event& iEvent, const edm::EventSetup& evSetup) {
0170     //inputs
0171     Handle<BXVector<l1t::EGamma>> egammas;
0172     iEvent.getByToken(egToken, egammas);
0173 
0174     Handle<BXVector<l1t::Muon>> muons;
0175     iEvent.getByToken(muToken, muons);
0176 
0177     Handle<BXVector<l1t::MuonShower>> muonShowers;
0178     iEvent.getByToken(muShowerToken, muonShowers);
0179 
0180     Handle<BXVector<l1t::Tau>> taus;
0181     iEvent.getByToken(tauToken, taus);
0182 
0183     Handle<BXVector<l1t::Jet>> jets;
0184     iEvent.getByToken(jetToken, jets);
0185 
0186     Handle<BXVector<l1t::EtSum>> etsums;
0187     iEvent.getByToken(etsumToken, etsums);
0188 
0189     Handle<BXVector<GlobalAlgBlk>> uGtAlg;
0190     iEvent.getByToken(uGtAlgToken, uGtAlg);
0191 
0192     Handle<BXVector<GlobalExtBlk>> uGtExt;
0193     iEvent.getByToken(uGtExtToken, uGtExt);
0194 
0195     Handle<GlobalObjectMapRecord> gtObjectMapRecord;
0196     iEvent.getByToken(uGtObjectMapToken, gtObjectMapRecord);
0197 
0198     //Fill the L1 result maps
0199     m_gtUtil->retrieveL1(iEvent, evSetup, uGtAlgToken);
0200 
0201     LogDebug("GtRecordDump") << "retrieved L1 data " << endl;
0202 
0203     // grab the map for the final decisions
0204     const auto& initialDecisions = m_gtUtil->decisionsInitial();
0205     const auto& intermDecisions = m_gtUtil->decisionsInterm();
0206     const auto& finalDecisions = m_gtUtil->decisionsFinal();
0207     const auto& prescales = m_gtUtil->prescales();
0208     const auto& masks = m_gtUtil->masks();
0209 
0210     LogDebug("GtRecordDump") << "retrieved all event vectors " << endl;
0211 
0212     // Dump the results
0213     if (m_dumpTriggerResults) {
0214       cout << "    Bit                  Algorithm Name                                      Init    aBXM  Final   PS "
0215               "Factor     Num Bx Masked    "
0216            << endl;
0217       cout << "========================================================================================================"
0218               "======================="
0219            << endl;
0220     }
0221     for (unsigned int i = 0; i < initialDecisions.size(); i++) {
0222       // get the name and trigger result
0223       string name{(initialDecisions.at(i)).first};
0224       bool resultInit = (initialDecisions.at(i)).second;
0225 
0226       //  put together our map of algorithms and counts across events
0227       if (m_algoSummary.count(name) == 0) {
0228         std::vector<int> tst;
0229         tst.resize(3);
0230         m_algoSummary[name] = tst;
0231       }
0232       if (resultInit)
0233         (m_algoSummary.find(name)->second).at(0) += 1;
0234 
0235       // get prescaled and final results (need some error checking here)
0236       bool resultInterm = (intermDecisions.at(i)).second;
0237       if (resultInterm)
0238         (m_algoSummary.find(name)->second).at(1) += 1;
0239       bool resultFin = (finalDecisions.at(i)).second;
0240       if (resultFin)
0241         (m_algoSummary.find(name)->second).at(2) += 1;
0242 
0243       // get the prescale and mask (needs some error checking here)
0244       double prescale = (prescales.at(i)).second;
0245       std::vector<int> mask = (masks.at(i)).second;
0246 
0247       if (m_dumpTriggerResults && name != "NULL")
0248         cout << std::dec << setfill(' ') << "   " << setw(5) << i << "   " << setw(60) << name.c_str() << "   "
0249              << setw(7) << resultInit << setw(7) << resultInterm << setw(7) << resultFin << setw(10) << prescale
0250              << setw(11) << mask.size() << endl;
0251     }
0252     bool finOR = m_gtUtil->getFinalOR();
0253     if (m_dumpTriggerResults) {
0254       cout << "                                                                                    FinalOR = " << finOR
0255            << endl;
0256       cout << "========================================================================================================"
0257               "========================"
0258            << endl;
0259     }
0260 
0261     if (m_dumpObjectMap) {
0262       if (!gtObjectMapRecord.isValid()) {
0263         edm::LogWarning("GtRecordDump")
0264             << " Warning: GlobalObjectMapRecord requested in configuration, but not found in the event." << std::endl;
0265       } else {
0266         const std::vector<GlobalObjectMap>& objMaps = gtObjectMapRecord->gtObjectMap();
0267         for (size_t imap = 0; imap < objMaps.size(); imap++) {
0268           GlobalObjectMap oMap = objMaps.at(imap);
0269 
0270           int bit = oMap.algoBitNumber();  //  same as bit from L1T Menu
0271           int mapDecision = oMap.algoGtlResult();
0272 
0273           // Check Object Map Result Agrees with GlobalAlgBlk result
0274           if (mapDecision != (finalDecisions.at(bit)).second) {
0275             std::cout << "WARNING: GlobalAlgBlk and ObjectMap Disagree on result for bit " << bit
0276                       << " Alg: " << oMap.algoName() << std::endl;
0277           }
0278 
0279           // dump only if we have a positive trigger
0280           if (mapDecision != 0) {
0281             // Header info
0282             std::cout
0283                 << " -------------------------------------------------------------------------------------------- \n"
0284                 << " Bit " << setw(3) << bit << " Decision " << setw(2) << mapDecision << " Alg Name " << setw(40)
0285                 << oMap.algoName() << std::endl;
0286 
0287             // Combination
0288             const std::vector<GlobalLogicParser::OperandToken>& opTokenVecObjMap = oMap.operandTokenVector();
0289             const std::vector<L1TObjectTypeInCond>& condObjTypeVec = oMap.objectTypeVector();
0290 
0291             for (size_t iCond = 0; iCond < opTokenVecObjMap.size(); iCond++) {
0292               std::cout << "       " << iCond << ") Condition Token: " << opTokenVecObjMap[iCond].tokenName
0293                         << "  Types: ";
0294               auto const& condObjType = condObjTypeVec[iCond];
0295               for (size_t iCondType = 0; iCondType < condObjType.size(); iCondType++) {
0296                 std::cout << condObjType.at(iCondType) << "  ";
0297               }
0298               std::cout << std::endl;
0299 
0300               const CombinationsWithBxInCond* condComb = oMap.getCombinationsInCond(iCond);
0301               std::cout << "            Combinations in Condition [" << condComb->size() << "] : ";
0302               for (auto const& itComb : *condComb) {
0303                 // loop over objects in a combination for a given condition
0304                 //
0305                 unsigned int iType = 0;
0306                 std::cout << "(";
0307                 for (auto const& [bxIdx, objIdx] : itComb) {
0308                   // loop over types for the object in a combination.  This object might have more then one type (i.e. mu-eg)
0309                   //
0310 
0311                   //                     for (size_t iType =0; iType < condObjType.size(); iType++) {
0312 
0313                   // get object type and push indices on the list
0314                   //
0315                   //const l1t::GlobalObject objTypeVal = condObjType.at(iType);
0316 
0317                   std::cout << bxIdx << ":" << objIdx;
0318                   //std::cout <<objTypeVal << "@" << bxIdx << ":" << objIdx;
0319                   if (iType < condObjType.size() - 1)
0320                     std::cout << ",";
0321                   //std::cout
0322                   //<< "\tAdd object of type " << objTypeVal << " and bx:index " << bxIdx << ":" << objIdx << " to the seed list."
0323                   //<< std::endl;
0324 
0325                   //                     } // end loop over objs in combination
0326                   iType++;
0327 
0328                 }  //end loop over objects for a condition
0329                 std::cout << ")  ";
0330               }
0331               std::cout << std::endl;
0332             }
0333           }  //end if alg fired
0334         }  //end loop over maps
0335       }  //end if valid record
0336     }  //end if dump maps
0337 
0338     if (m_dumpGTRecord) {
0339       cout << " -----------------------------------------------------  " << endl;
0340       cout << " *********** Run " << std::dec << iEvent.id().run() << " Event " << iEvent.id().event()
0341            << " **************  " << endl;
0342       cout << " ----------------------------------------------------- " << endl;
0343 
0344       //Loop over BX
0345       for (int i = m_minBx; i <= m_maxBx; ++i) {
0346         cout << " ========= Rel BX = " << std::dec << i << " ======  Total BX = " << m_absBx << "   ==========" << endl;
0347 
0348         //Loop over EGamma
0349         int nObj = 0;
0350         cout << " ------ EGammas -------- " << endl;
0351         if (egammas.isValid()) {
0352           if (i >= egammas->getFirstBX() && i <= egammas->getLastBX()) {
0353             for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(i); eg != egammas->end(i); ++eg) {
0354               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0355               cout << "   Pt " << std::dec << std::setw(3) << eg->hwPt() << " (0x" << std::hex << std::setw(3)
0356                    << std::setfill('0') << eg->hwPt() << ")";
0357               cout << "   Eta " << std::dec << std::setw(3) << eg->hwEta() << " (0x" << std::hex << std::setw(2)
0358                    << std::setfill('0') << (eg->hwEta() & 0xff) << ")";
0359               cout << "   Phi " << std::dec << std::setw(3) << eg->hwPhi() << " (0x" << std::hex << std::setw(2)
0360                    << std::setfill('0') << eg->hwPhi() << ")";
0361               cout << "   Iso " << std::dec << std::setw(1) << eg->hwIso();
0362               cout << "   Qual " << std::dec << std::setw(1) << eg->hwQual();
0363               cout << endl;
0364               nObj++;
0365             }
0366           } else {
0367             cout << "No EG stored for this bx " << i << endl;
0368           }
0369         } else {
0370           cout << "No EG Data in this event " << endl;
0371         }
0372 
0373         //Loop over Muons
0374         nObj = 0;
0375         cout << " ------ Muons --------" << endl;
0376         if (muons.isValid()) {
0377           if (i >= muons->getFirstBX() && i <= muons->getLastBX()) {
0378             for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(i); mu != muons->end(i); ++mu) {
0379               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0380               cout << "   Pt " << std::dec << std::setw(3) << mu->hwPt() << " (0x" << std::hex << std::setw(3)
0381                    << std::setfill('0') << mu->hwPt() << ")";
0382               cout << "   EtaAtVtx " << std::dec << std::setw(3) << mu->hwEtaAtVtx() << " (0x" << std::hex
0383                    << std::setw(3) << std::setfill('0') << (mu->hwEtaAtVtx() & 0x1ff) << ")";
0384               cout << "   Eta " << std::dec << std::setw(3) << mu->hwEta() << " (0x" << std::hex << std::setw(3)
0385                    << std::setfill('0') << (mu->hwEta() & 0x1ff) << ")";
0386               cout << "   PhiAtVtx " << std::dec << std::setw(3) << mu->hwPhiAtVtx() << " (0x" << std::hex
0387                    << std::setw(3) << std::setfill('0') << mu->hwPhiAtVtx() << ")";
0388               cout << "   Phi " << std::dec << std::setw(3) << mu->hwPhi() << " (0x" << std::hex << std::setw(3)
0389                    << std::setfill('0') << mu->hwPhi() << ")";
0390               cout << "   Iso " << std::dec << std::setw(1) << mu->hwIso();
0391               cout << "   Qual " << std::dec << std::setw(1) << mu->hwQual();
0392               cout << "   Chrg " << std::dec << std::setw(1) << mu->hwCharge();
0393               cout << endl;
0394               nObj++;
0395             }
0396           } else {
0397             cout << "No Muons stored for this bx " << i << endl;
0398           }
0399         } else {
0400           cout << "No Muon Data in this event " << endl;
0401         }
0402 
0403         //Loop over Muon Showers
0404         nObj = 0;
0405         cout << " ------ Muons Showers --------" << endl;
0406         if (muonShowers.isValid()) {
0407           std::cout << "========= MuonShower BX index = " << i << "; min BX = " << m_minBx << "; max BX = " << m_maxBx
0408                     << std::endl;
0409           if (i >= muonShowers->getFirstBX() && i <= muonShowers->getLastBX()) {
0410             for (std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(i);
0411                  muShower != muonShowers->end(i);
0412                  ++muShower) {
0413               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0414               cout << "   MUS0 " << std::dec << std::setw(1) << muShower->isOneNominalInTime();
0415               cout << ";  MUS1 " << std::dec << std::setw(1) << muShower->isOneTightInTime();
0416               cout << ";  MUS2 " << std::dec << std::setw(1) << muShower->isTwoLooseDiffSectorsInTime();
0417               cout << ";  MUSOOT0 " << std::dec << std::setw(1) << muShower->musOutOfTime0();
0418               cout << ";  MUSOOT1 " << std::dec << std::setw(1) << muShower->musOutOfTime1();
0419               cout << endl;
0420               nObj++;
0421             }
0422           } else {
0423             cout << "No MuonShowers stored for this bx " << i << endl;
0424           }
0425         } else {
0426           cout << "No MuonShower Data in this event " << endl;
0427         }
0428 
0429         //Loop over Taus
0430         nObj = 0;
0431         cout << " ------ Taus ----------" << endl;
0432         if (taus.isValid()) {
0433           if (i >= taus->getFirstBX() && i <= taus->getLastBX()) {
0434             for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(i); tau != taus->end(i); ++tau) {
0435               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0436               cout << "   Pt " << std::dec << std::setw(3) << tau->hwPt() << " (0x" << std::hex << std::setw(3)
0437                    << std::setfill('0') << tau->hwPt() << ")";
0438               cout << "   Eta " << std::dec << std::setw(3) << tau->hwEta() << " (0x" << std::hex << std::setw(2)
0439                    << std::setfill('0') << (tau->hwEta() & 0xff) << ")";
0440               cout << "   Phi " << std::dec << std::setw(3) << tau->hwPhi() << " (0x" << std::hex << std::setw(2)
0441                    << std::setfill('0') << tau->hwPhi() << ")";
0442               cout << "   Iso " << std::dec << std::setw(1) << tau->hwIso();
0443               cout << "   Qual " << std::dec << std::setw(1) << tau->hwQual();
0444               cout << endl;
0445               nObj++;
0446             }
0447           } else {
0448             cout << "No Taus stored for this bx " << i << endl;
0449           }
0450         } else {
0451           cout << "No Tau Data in this event " << endl;
0452         }
0453 
0454         //Loop over Jets
0455         nObj = 0;
0456         cout << " ------ Jets ----------" << endl;
0457         if (jets.isValid()) {
0458           if (i >= jets->getFirstBX() && i <= jets->getLastBX()) {
0459             for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(i); jet != jets->end(i); ++jet) {
0460               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0461               cout << "   Pt " << std::dec << std::setw(3) << jet->hwPt() << " (0x" << std::hex << std::setw(3)
0462                    << std::setfill('0') << jet->hwPt() << ")";
0463               cout << "   Eta " << std::dec << std::setw(3) << jet->hwEta() << " (0x" << std::hex << std::setw(2)
0464                    << std::setfill('0') << (jet->hwEta() & 0xff) << ")";
0465               cout << "   Phi " << std::dec << std::setw(3) << jet->hwPhi() << " (0x" << std::hex << std::setw(2)
0466                    << std::setfill('0') << jet->hwPhi() << ")";
0467               cout << "   Qual " << std::dec << std::setw(1) << jet->hwQual();
0468               cout << endl;
0469               nObj++;
0470             }
0471           } else {
0472             cout << "No Jets stored for this bx " << i << endl;
0473           }
0474         } else {
0475           cout << "No jet Data in this event " << endl;
0476         }
0477 
0478         //Dump Content
0479         cout << " ------ EtSums ----------" << endl;
0480         if (etsums.isValid()) {
0481           if (i >= etsums->getFirstBX() && i <= etsums->getLastBX()) {
0482             for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(i); etsum != etsums->end(i); ++etsum) {
0483               switch (etsum->getType()) {
0484                 case l1t::EtSum::EtSumType::kMissingEt:
0485                   cout << " ETM:  ";
0486                   break;
0487                 case l1t::EtSum::EtSumType::kMissingEtHF:
0488                   cout << " ETMHF:";
0489                   break;
0490                 case l1t::EtSum::EtSumType::kMissingHtHF:
0491                   cout << " HTMHF:";
0492                   break;
0493                 case l1t::EtSum::EtSumType::kMissingHt:
0494                   cout << " HTM:  ";
0495                   break;
0496                 case l1t::EtSum::EtSumType::kTotalEt:
0497                   cout << " ETT:  ";
0498                   break;
0499                 case l1t::EtSum::EtSumType::kTotalEtEm:
0500                   cout << " ETTem:";
0501                   break;
0502                 case l1t::EtSum::EtSumType::kTotalHt:
0503                   cout << " HTT:  ";
0504                   break;
0505                 case l1t::EtSum::EtSumType::kTowerCount:
0506                   cout << " TowerCounts:  ";
0507                   break;
0508                 case l1t::EtSum::EtSumType::kAsymEt:
0509                   cout << " AsymEt:  ";
0510                   break;
0511                 case l1t::EtSum::EtSumType::kAsymHt:
0512                   cout << " AsymHt:  ";
0513                   break;
0514                 case l1t::EtSum::EtSumType::kAsymEtHF:
0515                   cout << " AsymEtHF:  ";
0516                   break;
0517                 case l1t::EtSum::EtSumType::kAsymHtHF:
0518                   cout << " AsymHtHF:  ";
0519                   break;
0520                 case l1t::EtSum::EtSumType::kMinBiasHFP0:
0521                   cout << " HFP0: ";
0522                   break;
0523                 case l1t::EtSum::EtSumType::kMinBiasHFM0:
0524                   cout << " HFM0: ";
0525                   break;
0526                 case l1t::EtSum::EtSumType::kMinBiasHFP1:
0527                   cout << " HFP1: ";
0528                   break;
0529                 case l1t::EtSum::EtSumType::kMinBiasHFM1:
0530                   cout << " HFM1: ";
0531                   break;
0532                 case l1t::EtSum::EtSumType::kCentrality:
0533                   cout << " Centrality: ";
0534                   break;
0535                 default:
0536                   cout << " Unknown: ";
0537                   break;
0538               }
0539               cout << " Et " << std::dec << std::setw(3) << etsum->hwPt() << " (0x" << std::hex << std::setw(3)
0540                    << std::setfill('0') << etsum->hwPt() << ")";
0541               if (etsum->getType() == l1t::EtSum::EtSumType::kMissingEt ||
0542                   etsum->getType() == l1t::EtSum::EtSumType::kMissingHt ||
0543                   etsum->getType() == l1t::EtSum::EtSumType::kMissingEtHF ||
0544                   etsum->getType() == l1t::EtSum::EtSumType::kMissingHtHF)
0545                 cout << " Phi " << std::dec << std::setw(3) << etsum->hwPhi() << " (0x" << std::hex << std::setw(2)
0546                      << std::setfill('0') << etsum->hwPhi() << ")";
0547               cout << endl;
0548             }
0549           } else {
0550             cout << "No EtSums stored for this bx " << i << endl;
0551           }
0552         } else {
0553           cout << "No EtSum Data in this event " << endl;
0554         }
0555 
0556         // Dump the output record
0557         cout << " ------ uGtExt ----------" << endl;
0558         if (uGtExt.isValid()) {
0559           if (i >= uGtExt->getFirstBX() && i <= uGtExt->getLastBX()) {
0560             for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(i); extBlk != uGtExt->end(i);
0561                  ++extBlk) {
0562               extBlk->print(std::cout);
0563             }
0564           } else {
0565             cout << "No Ext Conditions stored for this bx " << i << endl;
0566           }
0567         } else {
0568           cout << "No uGtExt Data in this event " << endl;
0569         }
0570 
0571         // Dump the output record
0572         cout << " ------ uGtAlg ----------" << endl;
0573         if (uGtAlg.isValid()) {
0574           if (i >= uGtAlg->getFirstBX() && i <= uGtAlg->getLastBX()) {
0575             for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(i); algBlk != uGtAlg->end(i);
0576                  ++algBlk) {
0577               algBlk->print(std::cout);
0578             }
0579           } else {
0580             cout << "No Alg Decisions stored for this bx " << i << endl;
0581           }
0582         } else {
0583           cout << "No uGtAlg Data in this event " << endl;
0584         }
0585 
0586       }  //loop over Bx
0587       cout << std::dec << endl;
0588     }  //if dumpGtRecord
0589 
0590     // Dump Test Vectors for this bx
0591     if (m_dumpTestVectors) {
0592       for (int i = m_minBxVectors; i <= m_maxBxVectors; i++) {
0593         //         if(  (i>=egammas->getFirstBX() && i<=egammas->getLastBX())&&
0594         //        (i>=muons->getFirstBX()   && i<=muons->getLastBX())  &&
0595         //        (i>=taus->getFirstBX()    && i<=taus->getLastBX())   &&
0596         //        (i>=jets->getFirstBX()    && i<=jets->getLastBX())   &&
0597         //        (i>=etsums->getFirstBX()  && i<=etsums->getLastBX()) &&
0598         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) &&
0599         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) ) {
0600         dumpTestVectors(i, m_testVectorFile, muons, muonShowers, egammas, taus, jets, etsums, uGtAlg, uGtExt);
0601         //   } else {
0602         //        edm::LogWarning("GtRecordDump") << "WARNING: Not enough information to dump test vectors for this bx=" << i << endl;
0603         //   }
0604       }
0605     }
0606   }
0607 
0608   // ------------ method called when ending the processing of a run  ------------
0609 
0610   void GtRecordDump::endRun(edm::Run const&, edm::EventSetup const&) {
0611     // Dump the results
0612     cout << "=========================== Global Trigger Summary Report  ==================================" << endl;
0613     cout << "                       Algorithm Name                              Init     aBXM     Final   " << endl;
0614     cout << "=============================================================================================" << endl;
0615     for (std::map<std::string, std::vector<int>>::const_iterator itAlgo = m_algoSummary.begin();
0616          itAlgo != m_algoSummary.end();
0617          itAlgo++) {
0618       std::string name = itAlgo->first;
0619       int initCnt = (itAlgo->second).at(0);
0620       int initPre = (itAlgo->second).at(1);
0621       int initFnl = (itAlgo->second).at(2);
0622       if (name != "NULL")
0623         cout << std::dec << setfill(' ') << setw(60) << name.c_str() << setw(10) << initCnt << setw(10) << initPre
0624              << setw(10) << initFnl << endl;
0625     }
0626     cout
0627         << "==========================================================================================================="
0628         << endl;
0629   }
0630 
0631   void GtRecordDump::dumpTestVectors(int bx,
0632                                      std::ofstream& myOutFile,
0633                                      Handle<BXVector<l1t::Muon>> muons,
0634                                      Handle<BXVector<l1t::MuonShower>> muonShowers,
0635                                      Handle<BXVector<l1t::EGamma>> egammas,
0636                                      Handle<BXVector<l1t::Tau>> taus,
0637                                      Handle<BXVector<l1t::Jet>> jets,
0638                                      Handle<BXVector<l1t::EtSum>> etsums,
0639                                      Handle<BXVector<GlobalAlgBlk>> uGtAlg,
0640                                      Handle<BXVector<GlobalExtBlk>> uGtExt) {
0641     const int empty = 0;
0642 
0643     // Dump Bx (4 digits)
0644     myOutFile << std::dec << std::setw(4) << std::setfill('0') << m_absBx;
0645 
0646     // Dump 8 Muons (16 digits + space) + Muon Showers
0647     int nDumped = 0;
0648 
0649     int muNumber = 0;  //keeps track of which muons get which muon shower information
0650     if (muons.isValid() && muonShowers.isValid()) {
0651       for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
0652         // loop over valid muons in this bx (muon 0 up to max possible of muon 7)
0653         int muShowerBit = 0;  // default value for muon shower bit
0654         if (bx >= muonShowers->getFirstBX() && bx <= muonShowers->getLastBX()) {
0655           if (muonShowers->size(bx) > 0) {
0656             std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(bx);
0657             if (muNumber == 0)
0658               muShowerBit = muShower->isOneNominalInTime();
0659             if (muNumber == 2)
0660               muShowerBit = muShower->isOneTightInTime();
0661             if (muNumber == 3)
0662               muShowerBit = muShower->isTwoLooseDiffSectorsInTime();
0663             if (muNumber == 4)
0664               muShowerBit = muShower->musOutOfTime0();
0665             if (muNumber == 6)
0666               muShowerBit = muShower->musOutOfTime1();
0667           }
0668         }
0669         cms_uint64_t packedWd = formatMuon(mu, muShowerBit);
0670         if (nDumped < 8) {
0671           myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
0672           nDumped++;
0673         }
0674         ++muNumber;  //keeps track of how many muons have been processed
0675       }  // end loop over Muons in this bx
0676 
0677       // Muon Shower information can exist, even if a muon object does not exist.  Hence,
0678       // now loop over non-existant muons from muNumber up to max of 7 and add the muon shower info
0679       int start = muNumber;
0680       for (int nonExistantMuon = start; nonExistantMuon < 8; nonExistantMuon++) {
0681         int muShowerBit = 0;  // default value for muon shower bit
0682         if (bx >= muonShowers->getFirstBX() && bx <= muonShowers->getLastBX()) {
0683           if (muonShowers->size(bx) > 0) {
0684             std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(bx);
0685             if (muNumber == 0)
0686               muShowerBit = muShower->isOneNominalInTime();
0687             if (muNumber == 2)
0688               muShowerBit = muShower->isOneTightInTime();
0689             if (muNumber == 3)
0690               muShowerBit = muShower->isTwoLooseDiffSectorsInTime();
0691             if (muNumber == 4)
0692               muShowerBit = muShower->musOutOfTime0();
0693             if (muNumber == 6)
0694               muShowerBit = muShower->musOutOfTime1();
0695           }
0696         }
0697         cms_uint64_t packedWd = formatNonExistantMuon(muShowerBit);
0698         if (nDumped < 8) {
0699           myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
0700           nDumped++;
0701         }
0702         ++muNumber;  // keep track of the number of muons processed
0703       }  // end loop over non-existant muons
0704     }
0705     for (int i = nDumped; i < 8; i++) {
0706       myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << empty;
0707     }
0708     if (!muons.isValid())
0709       std::cout << "========= WARNING:  ALL MUONS INVALID ==========" << std::endl;
0710     if (!muonShowers.isValid())
0711       std::cout << "========= WARNING:  ALL MUON SHOWERS INVALID ==========" << std::endl;
0712     //===========================================
0713 
0714     // Dump 12 EG (8 digits + space)
0715     nDumped = 0;
0716     if (egammas.isValid()) {
0717       for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(bx); eg != egammas->end(bx); ++eg) {
0718         unsigned int packedWd = formatEG(eg);
0719         if (nDumped < 12) {
0720           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0721           nDumped++;
0722         }
0723       }
0724     }
0725     for (int i = nDumped; i < 12; i++) {
0726       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0727     }
0728 
0729     // Dump 8 tau (8 digits + space)
0730     nDumped = 0;
0731     int maxTau = 8;
0732     if (m_tvVersion > 1)
0733       maxTau = 12;
0734     if (taus.isValid()) {
0735       for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(bx); tau != taus->end(bx); ++tau) {
0736         unsigned int packedWd = formatTau(tau);
0737         if (nDumped < maxTau) {
0738           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0739           nDumped++;
0740         }
0741       }
0742     }
0743     for (int i = nDumped; i < maxTau; i++) {
0744       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0745     }
0746 
0747     // Dump 12 Jets (8 digits + space)
0748     nDumped = 0;
0749     if (jets.isValid()) {
0750       for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(bx); jet != jets->end(bx); ++jet) {
0751         unsigned int packedWd = formatJet(jet);
0752         if (nDumped < 12) {
0753           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0754           nDumped++;
0755         }
0756       }
0757     }
0758     for (int i = nDumped; i < 12; i++) {
0759       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0760     }
0761 
0762     // Dump Et Sums (ETT, HT, ETM, ETMHF, HTM)
0763     unsigned int ETTpackWd = 0;
0764     unsigned int HTTpackWd = 0;
0765     unsigned int ETMpackWd = 0;
0766     unsigned int HTMpackWd = 0;
0767     unsigned int ETMHFpackWd = 0;
0768     unsigned int HTMHFpackWd = 0;
0769 
0770     // quantities packed into the words
0771     unsigned int ETTempackWd = 0;
0772     unsigned int HFP0packWd = 0;
0773     unsigned int HFM0packWd = 0;
0774     unsigned int HFP1packWd = 0;
0775     unsigned int HFM1packWd = 0;
0776     unsigned int TowerCountspackWd = 0;  // ccla
0777     unsigned int AsymEtpackWd = 0;
0778     unsigned int AsymHtpackWd = 0;
0779     unsigned int AsymEtHFpackWd = 0;
0780     unsigned int AsymHtHFpackWd = 0;
0781     unsigned int CENT30packWd = 0;  // centrality bits 3:0 in ETMHF word
0782     unsigned int CENT74packWd = 0;  // centrality bits 7:4 in HTMHF word
0783     std::pair<unsigned int, unsigned int> centrality(0, 0);
0784 
0785     if (etsums.isValid()) {
0786       for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(bx); etsum != etsums->end(bx); ++etsum) {
0787         switch (etsum->getType()) {
0788           case l1t::EtSum::EtSumType::kMissingEt:
0789             ETMpackWd = formatMissET(etsum);
0790             break;
0791           case l1t::EtSum::EtSumType::kMissingEtHF:
0792             ETMHFpackWd = formatMissET(etsum);
0793             break;
0794           case l1t::EtSum::EtSumType::kMissingHtHF:
0795             HTMHFpackWd = formatMissET(etsum);
0796             break;
0797           case l1t::EtSum::EtSumType::kMissingHt:
0798             HTMpackWd = formatMissET(etsum);
0799             break;
0800           case l1t::EtSum::EtSumType::kTotalEt:
0801             ETTpackWd = formatTotalET(etsum);
0802             break;
0803           case l1t::EtSum::EtSumType::kTotalEtEm:
0804             ETTempackWd = formatTotalET(etsum);
0805             break;
0806           case l1t::EtSum::EtSumType::kTotalHt:
0807             HTTpackWd = formatTotalET(etsum);
0808             break;
0809           case l1t::EtSum::EtSumType::kTowerCount:
0810             TowerCountspackWd = formatTowerCounts(etsum);
0811             break;
0812           case l1t::EtSum::EtSumType::kMinBiasHFP0:
0813             HFP0packWd = formatHMB(etsum);
0814             break;
0815           case l1t::EtSum::EtSumType::kMinBiasHFM0:
0816             HFM0packWd = formatHMB(etsum);
0817             break;
0818           case l1t::EtSum::EtSumType::kMinBiasHFP1:
0819             HFP1packWd = formatHMB(etsum);
0820             break;
0821           case l1t::EtSum::EtSumType::kMinBiasHFM1:
0822             HFM1packWd = formatHMB(etsum);
0823             break;
0824           case l1t::EtSum::EtSumType::kCentrality:
0825             centrality = formatCentrality(etsum);
0826             CENT30packWd = centrality.first;
0827             CENT74packWd = centrality.second;
0828             break;
0829           case l1t::EtSum::EtSumType::kAsymEt:
0830             AsymEtpackWd = formatAsym(etsum);
0831             break;
0832           case l1t::EtSum::EtSumType::kAsymHt:
0833             AsymHtpackWd = formatAsym(etsum);
0834             break;
0835           case l1t::EtSum::EtSumType::kAsymEtHF:
0836             AsymEtHFpackWd = formatAsym(etsum);
0837             break;
0838           case l1t::EtSum::EtSumType::kAsymHtHF:
0839             AsymHtHFpackWd = formatAsym(etsum);
0840             break;
0841           default:
0842             break;
0843         }  //end switch statement
0844       }  //end loop over etsums
0845     }
0846 
0847     // Put HMB bits in upper part of other SumEt Words
0848     ETTpackWd |= HFP0packWd;
0849     HTTpackWd |= HFM0packWd;
0850     ETMpackWd |= HFP1packWd;
0851     HTMpackWd |= HFM1packWd;
0852 
0853     // ETTem goes into ETT word bits 12 - 23
0854     if (m_tvVersion > 1)
0855       ETTpackWd |= (ETTempackWd << 12);
0856 
0857     // ccla Towercounts go in HTT word, bits 12-24
0858     if (m_tvVersion > 1)
0859       HTTpackWd |= (TowerCountspackWd << 12);
0860     if (m_tvVersion > 2) {
0861       ETMpackWd |= AsymEtpackWd;
0862       HTMpackWd |= AsymHtpackWd;
0863       ETMHFpackWd |= AsymEtHFpackWd;
0864       HTMHFpackWd |= AsymHtHFpackWd;
0865 
0866       ETMHFpackWd |= CENT30packWd;
0867       HTMHFpackWd |= CENT74packWd;
0868     }
0869     // Fill in the words in appropriate order
0870     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETTpackWd;
0871     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTTpackWd;
0872     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMpackWd;
0873     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMpackWd;
0874     if (m_tvVersion > 1) {
0875       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMHFpackWd;
0876       if (m_tvVersion > 2) {
0877         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMHFpackWd;
0878       } else {
0879         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0880       }
0881     }
0882 
0883     // If tvVersion > 1 put in placeholds for empty link (6 words (frames)) all zeros.
0884     if (m_tvVersion > 1) {
0885       for (int i = 0; i < 6; i++)
0886         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0887     }
0888 
0889     // External Condition (64 digits + space)
0890     int digit = 0;
0891     myOutFile << " ";
0892     if (uGtExt.isValid()) {
0893       for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(bx); extBlk != uGtExt->end(bx); ++extBlk) {
0894         for (int i = 255; i > -1; i--) {
0895           if (extBlk->getExternalDecision(i))
0896             digit |= (1 << (i % 4));
0897           if ((i % 4) == 0) {
0898             myOutFile << std::hex << std::setw(1) << digit;
0899             digit = 0;
0900           }
0901         }  //end loop over external bits
0902       }  //loop over objects
0903     } else {
0904       myOutFile << std::hex << std::setw(64) << std::setfill('0') << empty;
0905     }
0906 
0907     // Algorithm Dump (128 digits + space)
0908     digit = 0;
0909     myOutFile << " ";
0910     if (uGtAlg.isValid()) {
0911       for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(bx); algBlk != uGtAlg->end(bx); ++algBlk) {
0912         for (int i = 511; i > -1; i--) {
0913           if (algBlk->getAlgoDecisionFinal(i))
0914             digit |= (1 << (i % 4));
0915           if ((i % 4) == 0) {
0916             myOutFile << std::hex << std::setw(1) << digit;
0917             digit = 0;
0918           }
0919         }  //end loop over algorithm bits
0920 
0921         // Final OR (1 digit + space)
0922         unsigned int finalOr = (algBlk->getFinalOR() & 0x1);
0923         myOutFile << " " << std::hex << std::setw(1) << std::setfill('0') << finalOr;
0924       }
0925     } else {
0926       myOutFile << std::hex << std::setw(128) << std::setfill('0') << empty;
0927     }
0928 
0929     myOutFile << endl;
0930 
0931     m_absBx++;
0932   }
0933 
0934   cms_uint64_t GtRecordDump::formatMuon(std::vector<l1t::Muon>::const_iterator mu, int muShowerBit) {
0935     cms_uint64_t packedVal = 0;
0936 
0937     // Pack Bits
0938     packedVal |= ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43);
0939     packedVal |= ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0);  // & 0x3ff) <<18);
0940     // packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);         // removed
0941     packedVal |= ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53);  // added
0942     packedVal |= ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62);               // added
0943     packedVal |= ((cms_uint64_t)(muShowerBit & 0x1) << 61);               // added
0944     packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23);        // & 0x1ff) <<9);
0945     packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10);              // & 0x1ff) <<0);
0946     packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35);       // & 0x1)   <<28);
0947     packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34);            // & 0x1)   <<29);
0948     packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) << 19);              // & 0xf)   <<30);
0949     packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) << 32);               // & 0x3)   <<34);
0950     packedVal |= ((cms_uint64_t)(mu->tfMuonIndex() & 0x7f) << 36);
0951 
0952     //    if (false) {  // for debugging purposes
0953     //      std::cout << "----------------------" << std::endl;
0954     //      std::cout << "<<  0; mu->hwPhiAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0955     //                << ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0) << std::endl;
0956     //      std::cout << "<< 10; mu->hwPt()              = " << std::hex << std::setw(16) << std::setfill('0')
0957     //                << ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10) << std::endl;
0958     //      std::cout << "<< 19; mu->hwQual()            = " << std::hex << std::setw(16) << std::setfill('0')
0959     //                << ((cms_uint64_t)(mu->hwQual() & 0xf) << 19) << std::endl;
0960     //      std::cout << "<< 23; mu->hwEtaAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0961     //                << ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23) << std::endl;
0962     //      std::cout << "<< 32; mu->hwIso()             = " << std::hex << std::setw(16) << std::setfill('0')
0963     //                << ((cms_uint64_t)(mu->hwIso() & 0x3) << 32) << std::endl;
0964     //      std::cout << "<< 34; mu->hwCharge()          = " << std::hex << std::setw(16) << std::setfill('0')
0965     //                << ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34) << std::endl;
0966     //      std::cout << "<< 35; mu->hwChargeValid()     = " << std::hex << std::setw(16) << std::setfill('0')
0967     //                << ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35) << std::endl;
0968     //      std::cout << "<< 43; mu->hwPhi()             = " << std::hex << std::setw(16) << std::setfill('0')
0969     //                << ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43) << std::endl;
0970     //      std::cout << "<< 53; mu->hwPtUnconstrained() = " << std::hex << std::setw(16) << std::setfill('0')
0971     //                << ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53) << std::endl;
0972     //      std::cout << "<< 61; muShowerBit             = " << std::hex << std::setw(16) << std::setfill('0')
0973     //                << ((cms_uint64_t)(muShowerBit & 0x1) << 61) << std::endl;
0974     //      std::cout << "<< 62; mu->hwDXY()             = " << std::hex << std::setw(16) << std::setfill('0')
0975     //                << ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62) << std::endl;
0976     //      std::cout << "packedWord                     = " << std::hex << std::setw(16) << std::setfill('0') << packedVal
0977     //                << std::endl;
0978     //      std::cout << "----------------------" << std::endl;
0979     //    }
0980 
0981     return packedVal;
0982   }
0983 
0984   cms_uint64_t GtRecordDump::formatNonExistantMuon(int muShowerBit) {
0985     cms_uint64_t packedVal = 0;
0986 
0987     // Pack Bits
0988     packedVal |= ((cms_uint64_t)(0 & 0x3ff) << 43);
0989     packedVal |= ((cms_uint64_t)(0 & 0x3ff) << 0);  // & 0x3ff) <<18);
0990     // packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);         // removed
0991     packedVal |= ((cms_uint64_t)(0 & 0xff) << 53);           // added
0992     packedVal |= ((cms_uint64_t)(0 & 0x3) << 62);            // added
0993     packedVal |= ((cms_uint64_t)(muShowerBit & 0x1) << 61);  // added
0994     packedVal |= ((cms_uint64_t)(0 & 0x1ff) << 23);          // & 0x1ff) <<9);
0995     packedVal |= ((cms_uint64_t)(0 & 0x1ff) << 10);          // & 0x1ff) <<0);
0996     packedVal |= ((cms_uint64_t)(0 & 0x1) << 35);            // & 0x1)   <<28);
0997     packedVal |= ((cms_uint64_t)(0 & 0x1) << 34);            // & 0x1)   <<29);
0998     packedVal |= ((cms_uint64_t)(0 & 0xf) << 19);            // & 0xf)   <<30);
0999     packedVal |= ((cms_uint64_t)(0 & 0x3) << 32);            // & 0x3)   <<34);
1000 
1001     return packedVal;
1002   }
1003 
1004   unsigned int GtRecordDump::formatEG(std::vector<l1t::EGamma>::const_iterator eg) {
1005     unsigned int packedVal = 0;
1006 
1007     // Pack Bits
1008     packedVal |= ((eg->hwPhi() & 0xff) << 17);
1009     packedVal |= ((eg->hwEta() & 0xff) << 9);
1010     packedVal |= ((eg->hwPt() & 0x1ff) << 0);
1011     packedVal |= ((eg->hwIso() & 0x3) << 25);
1012     packedVal |= ((eg->hwQual() & 0x31) << 27);
1013 
1014     return packedVal;
1015   }
1016 
1017   unsigned int GtRecordDump::formatTau(std::vector<l1t::Tau>::const_iterator tau) {
1018     unsigned int packedVal = 0;
1019 
1020     // Pack Bits
1021     packedVal |= ((tau->hwPhi() & 0xff) << 17);
1022     packedVal |= ((tau->hwEta() & 0xff) << 9);
1023     packedVal |= ((tau->hwPt() & 0x1ff) << 0);
1024     packedVal |= ((tau->hwIso() & 0x3) << 25);
1025     packedVal |= ((tau->hwQual() & 0x31) << 27);
1026 
1027     return packedVal;
1028   }
1029 
1030   unsigned int GtRecordDump::formatJet(std::vector<l1t::Jet>::const_iterator jet) {
1031     unsigned int packedVal = 0;
1032 
1033     // Pack Bits
1034     packedVal |= ((jet->hwPhi() & 0xff) << 19);
1035     packedVal |= ((jet->hwEta() & 0xff) << 11);
1036     packedVal |= ((jet->hwPt() & 0x7ff) << 0);
1037     packedVal |= ((jet->hwQual() & 0x1) << 27);
1038 
1039     return packedVal;
1040   }
1041 
1042   unsigned int GtRecordDump::formatMissET(std::vector<l1t::EtSum>::const_iterator etSum) {
1043     unsigned int packedVal = 0;
1044 
1045     // Pack Bits
1046     packedVal |= ((etSum->hwPhi() & 0xff) << 12);
1047     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
1048 
1049     return packedVal;
1050   }
1051 
1052   unsigned int GtRecordDump::formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum) {
1053     unsigned int packedVal = 0;
1054 
1055     // Pack Bits
1056     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
1057 
1058     return packedVal;
1059   }
1060 
1061   unsigned int GtRecordDump::formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum) {
1062     unsigned int packedVal = 0;
1063     //unsigned int shift = 12;
1064 
1065     // Pack Bits
1066     //packedVal |= ((etSum->hwPt()     & 0xfff)   << shift);
1067 
1068     //towercount takes 13 bits
1069     packedVal |= ((etSum->hwPt() & 0x1fff) << 0);
1070 
1071     return packedVal;
1072   }
1073 
1074   unsigned int GtRecordDump::formatAsym(std::vector<l1t::EtSum>::const_iterator etSum) {
1075     //asym takes 8 bits, occupying bits 20-27 in ETM, HTM, ETMHF, and HTMHF etsums
1076     unsigned int packedVal = 0;
1077     unsigned int shift = 20;
1078 
1079     // Pack Bits
1080     packedVal |= ((etSum->hwPt() & 0xff) << shift);
1081 
1082     return packedVal;
1083   }
1084 
1085   unsigned int GtRecordDump::formatHMB(std::vector<l1t::EtSum>::const_iterator etSum) {
1086     // 4 bits, occupying bits 28-31.
1087     unsigned int packedVal = 0;
1088     unsigned int shift = 28;
1089 
1090     // Pack Bits
1091     packedVal |= ((etSum->hwPt() & 0xf) << shift);
1092 
1093     return packedVal;
1094   }
1095 
1096   std::pair<unsigned int, unsigned int> GtRecordDump::formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum) {
1097     unsigned int centword = etSum->hwPt();
1098 
1099     // unpack word into 2 4 bit words
1100     int firstfour = (centword & 0xF);
1101     int lastfour = (centword >> 4) & 0xF;
1102 
1103     // 4 bits, occupying bits 28-31.
1104     unsigned int packedValLN = 0;
1105     unsigned int packedValUN = 0;
1106     unsigned int shift = 28;
1107 
1108     // Pack Bits
1109     packedValLN |= ((firstfour & 0xf) << shift);
1110     packedValUN |= ((lastfour & 0xf) << shift);
1111 
1112     std::pair<unsigned int, unsigned int> centrality(packedValLN, packedValUN);
1113     return centrality;
1114   }
1115 
1116 }  // namespace l1t
1117 
1118 DEFINE_FWK_MODULE(l1t::GtRecordDump);