Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-02 00:53:52

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>> 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 std::vector<std::pair<std::string, bool>> initialDecisions = m_gtUtil->decisionsInitial();
0205     const std::vector<std::pair<std::string, bool>> intermDecisions = m_gtUtil->decisionsInterm();
0206     const std::vector<std::pair<std::string, bool>> finalDecisions = m_gtUtil->decisionsFinal();
0207     const std::vector<std::pair<std::string, double>> prescales = m_gtUtil->prescales();
0208     const std::vector<std::pair<std::string, std::vector<int>>> 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       std::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             //         const std::vector<CombinationsInCond>& condCombinations = oMapcombinationVector();
0291 
0292             for (size_t iCond = 0; iCond < opTokenVecObjMap.size(); iCond++) {
0293               std::cout << "       " << iCond << ") Condition Token: " << opTokenVecObjMap.at(iCond).tokenName
0294                         << "  Types: ";
0295               std::vector<l1t::GlobalObject> condObjType = condObjTypeVec[iCond];
0296               for (size_t iCondType = 0; iCondType < condObjType.size(); iCondType++) {
0297                 std::cout << condObjType.at(iCondType) << "  ";
0298               }
0299               std::cout << std::endl;
0300 
0301               const CombinationsInCond* condComb = oMap.getCombinationsInCond(iCond);
0302               std::cout << "            Combinations in Condition [" << condComb->size() << "] : ";
0303               for (std::vector<SingleCombInCond>::const_iterator itComb = (*condComb).begin();
0304                    itComb != (*condComb).end();
0305                    itComb++) {
0306                 // loop over objects in a combination for a given condition
0307                 //
0308                 unsigned int iType = 0;
0309                 std::cout << "(";
0310                 for (SingleCombInCond::const_iterator itObject = (*itComb).begin(); itObject != (*itComb).end();
0311                      itObject++) {
0312                   // loop over types for the object in a combination.  This object might have more then one type (i.e. mu-eg)
0313                   //
0314 
0315                   //                     for (size_t iType =0; iType < condObjType.size(); iType++) {
0316 
0317                   // get object type and push indices on the list
0318                   //
0319                   //const l1t::GlobalObject objTypeVal = condObjType.at(iType);
0320 
0321                   std::cout << (*itObject);
0322                   //std::cout <<objTypeVal << "@" << (*itObject);
0323                   if (iType < condObjType.size() - 1)
0324                     std::cout << ",";
0325                   //std::cout
0326                   //<< "\tAdd object of type " << objTypeVal << " and index " << (*itObject) << " to the seed list."
0327                   //<< std::endl;
0328 
0329                   //                     } // end loop over objs in combination
0330                   iType++;
0331 
0332                 }  //end loop over objects for a condition
0333                 std::cout << ")  ";
0334               }
0335               std::cout << std::endl;
0336             }
0337           }  //end if alg fired
0338         }    //end loop over maps
0339       }      //end if valid record
0340     }        //end if dump maps
0341 
0342     if (m_dumpGTRecord) {
0343       cout << " -----------------------------------------------------  " << endl;
0344       cout << " *********** Run " << std::dec << iEvent.id().run() << " Event " << iEvent.id().event()
0345            << " **************  " << endl;
0346       cout << " ----------------------------------------------------- " << endl;
0347 
0348       //Loop over BX
0349       for (int i = m_minBx; i <= m_maxBx; ++i) {
0350         cout << " ========= Rel BX = " << std::dec << i << " ======  Total BX = " << m_absBx << "   ==========" << endl;
0351 
0352         //Loop over EGamma
0353         int nObj = 0;
0354         cout << " ------ EGammas -------- " << endl;
0355         if (egammas.isValid()) {
0356           if (i >= egammas->getFirstBX() && i <= egammas->getLastBX()) {
0357             for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(i); eg != egammas->end(i); ++eg) {
0358               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0359               cout << "   Pt " << std::dec << std::setw(3) << eg->hwPt() << " (0x" << std::hex << std::setw(3)
0360                    << std::setfill('0') << eg->hwPt() << ")";
0361               cout << "   Eta " << std::dec << std::setw(3) << eg->hwEta() << " (0x" << std::hex << std::setw(2)
0362                    << std::setfill('0') << (eg->hwEta() & 0xff) << ")";
0363               cout << "   Phi " << std::dec << std::setw(3) << eg->hwPhi() << " (0x" << std::hex << std::setw(2)
0364                    << std::setfill('0') << eg->hwPhi() << ")";
0365               cout << "   Iso " << std::dec << std::setw(1) << eg->hwIso();
0366               cout << "   Qual " << std::dec << std::setw(1) << eg->hwQual();
0367               cout << endl;
0368               nObj++;
0369             }
0370           } else {
0371             cout << "No EG stored for this bx " << i << endl;
0372           }
0373         } else {
0374           cout << "No EG Data in this event " << endl;
0375         }
0376 
0377         //Loop over Muons
0378         nObj = 0;
0379         cout << " ------ Muons --------" << endl;
0380         if (muons.isValid()) {
0381           if (i >= muons->getFirstBX() && i <= muons->getLastBX()) {
0382             for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(i); mu != muons->end(i); ++mu) {
0383               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0384               cout << "   Pt " << std::dec << std::setw(3) << mu->hwPt() << " (0x" << std::hex << std::setw(3)
0385                    << std::setfill('0') << mu->hwPt() << ")";
0386               cout << "   EtaAtVtx " << std::dec << std::setw(3) << mu->hwEtaAtVtx() << " (0x" << std::hex
0387                    << std::setw(3) << std::setfill('0') << (mu->hwEtaAtVtx() & 0x1ff) << ")";
0388               cout << "   Eta " << std::dec << std::setw(3) << mu->hwEta() << " (0x" << std::hex << std::setw(3)
0389                    << std::setfill('0') << (mu->hwEta() & 0x1ff) << ")";
0390               cout << "   PhiAtVtx " << std::dec << std::setw(3) << mu->hwPhiAtVtx() << " (0x" << std::hex
0391                    << std::setw(3) << std::setfill('0') << mu->hwPhiAtVtx() << ")";
0392               cout << "   Phi " << std::dec << std::setw(3) << mu->hwPhi() << " (0x" << std::hex << std::setw(3)
0393                    << std::setfill('0') << mu->hwPhi() << ")";
0394               cout << "   Iso " << std::dec << std::setw(1) << mu->hwIso();
0395               cout << "   Qual " << std::dec << std::setw(1) << mu->hwQual();
0396               cout << "   Chrg " << std::dec << std::setw(1) << mu->hwCharge();
0397               cout << endl;
0398               nObj++;
0399             }
0400           } else {
0401             cout << "No Muons stored for this bx " << i << endl;
0402           }
0403         } else {
0404           cout << "No Muon Data in this event " << endl;
0405         }
0406 
0407         //Loop over Muon Showers
0408         nObj = 0;
0409         cout << " ------ Muons Showers --------" << endl;
0410         if (muonShowers.isValid()) {
0411           std::cout << "========= MuonShower BX index = " << i << "; min BX = " << m_minBx << "; max BX = " << m_maxBx
0412                     << std::endl;
0413           if (i >= muonShowers->getFirstBX() && i <= muonShowers->getLastBX()) {
0414             for (std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(i);
0415                  muShower != muonShowers->end(i);
0416                  ++muShower) {
0417               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0418               cout << "   MUS0 " << std::dec << std::setw(1) << muShower->isOneNominalInTime();
0419               cout << ";  MUS1 " << std::dec << std::setw(1) << muShower->isOneTightInTime();
0420               cout << ";  MUS2 " << std::dec << std::setw(1) << muShower->isTwoLooseDiffSectorsInTime();
0421               cout << ";  MUSOOT0 " << std::dec << std::setw(1) << muShower->musOutOfTime0();
0422               cout << ";  MUSOOT1 " << std::dec << std::setw(1) << muShower->musOutOfTime1();
0423               cout << endl;
0424               nObj++;
0425             }
0426           } else {
0427             cout << "No MuonShowers stored for this bx " << i << endl;
0428           }
0429         } else {
0430           cout << "No MuonShower Data in this event " << endl;
0431         }
0432 
0433         //Loop over Taus
0434         nObj = 0;
0435         cout << " ------ Taus ----------" << endl;
0436         if (taus.isValid()) {
0437           if (i >= taus->getFirstBX() && i <= taus->getLastBX()) {
0438             for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(i); tau != taus->end(i); ++tau) {
0439               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0440               cout << "   Pt " << std::dec << std::setw(3) << tau->hwPt() << " (0x" << std::hex << std::setw(3)
0441                    << std::setfill('0') << tau->hwPt() << ")";
0442               cout << "   Eta " << std::dec << std::setw(3) << tau->hwEta() << " (0x" << std::hex << std::setw(2)
0443                    << std::setfill('0') << (tau->hwEta() & 0xff) << ")";
0444               cout << "   Phi " << std::dec << std::setw(3) << tau->hwPhi() << " (0x" << std::hex << std::setw(2)
0445                    << std::setfill('0') << tau->hwPhi() << ")";
0446               cout << "   Iso " << std::dec << std::setw(1) << tau->hwIso();
0447               cout << "   Qual " << std::dec << std::setw(1) << tau->hwQual();
0448               cout << endl;
0449               nObj++;
0450             }
0451           } else {
0452             cout << "No Taus stored for this bx " << i << endl;
0453           }
0454         } else {
0455           cout << "No Tau Data in this event " << endl;
0456         }
0457 
0458         //Loop over Jets
0459         nObj = 0;
0460         cout << " ------ Jets ----------" << endl;
0461         if (jets.isValid()) {
0462           if (i >= jets->getFirstBX() && i <= jets->getLastBX()) {
0463             for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(i); jet != jets->end(i); ++jet) {
0464               cout << "  " << std::dec << std::setw(2) << std::setfill(' ') << nObj << std::setfill('0') << ")";
0465               cout << "   Pt " << std::dec << std::setw(3) << jet->hwPt() << " (0x" << std::hex << std::setw(3)
0466                    << std::setfill('0') << jet->hwPt() << ")";
0467               cout << "   Eta " << std::dec << std::setw(3) << jet->hwEta() << " (0x" << std::hex << std::setw(2)
0468                    << std::setfill('0') << (jet->hwEta() & 0xff) << ")";
0469               cout << "   Phi " << std::dec << std::setw(3) << jet->hwPhi() << " (0x" << std::hex << std::setw(2)
0470                    << std::setfill('0') << jet->hwPhi() << ")";
0471               cout << "   Qual " << std::dec << std::setw(1) << jet->hwQual();
0472               cout << endl;
0473               nObj++;
0474             }
0475           } else {
0476             cout << "No Jets stored for this bx " << i << endl;
0477           }
0478         } else {
0479           cout << "No jet Data in this event " << endl;
0480         }
0481 
0482         //Dump Content
0483         cout << " ------ EtSums ----------" << endl;
0484         if (etsums.isValid()) {
0485           if (i >= etsums->getFirstBX() && i <= etsums->getLastBX()) {
0486             for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(i); etsum != etsums->end(i); ++etsum) {
0487               switch (etsum->getType()) {
0488                 case l1t::EtSum::EtSumType::kMissingEt:
0489                   cout << " ETM:  ";
0490                   break;
0491                 case l1t::EtSum::EtSumType::kMissingEtHF:
0492                   cout << " ETMHF:";
0493                   break;
0494                 case l1t::EtSum::EtSumType::kMissingHtHF:
0495                   cout << " HTMHF:";
0496                   break;
0497                 case l1t::EtSum::EtSumType::kMissingHt:
0498                   cout << " HTM:  ";
0499                   break;
0500                 case l1t::EtSum::EtSumType::kTotalEt:
0501                   cout << " ETT:  ";
0502                   break;
0503                 case l1t::EtSum::EtSumType::kTotalEtEm:
0504                   cout << " ETTem:";
0505                   break;
0506                 case l1t::EtSum::EtSumType::kTotalHt:
0507                   cout << " HTT:  ";
0508                   break;
0509                 case l1t::EtSum::EtSumType::kTowerCount:
0510                   cout << " TowerCounts:  ";
0511                   break;
0512                 case l1t::EtSum::EtSumType::kAsymEt:
0513                   cout << " AsymEt:  ";
0514                   break;
0515                 case l1t::EtSum::EtSumType::kAsymHt:
0516                   cout << " AsymHt:  ";
0517                   break;
0518                 case l1t::EtSum::EtSumType::kAsymEtHF:
0519                   cout << " AsymEtHF:  ";
0520                   break;
0521                 case l1t::EtSum::EtSumType::kAsymHtHF:
0522                   cout << " AsymHtHF:  ";
0523                   break;
0524                 case l1t::EtSum::EtSumType::kMinBiasHFP0:
0525                   cout << " HFP0: ";
0526                   break;
0527                 case l1t::EtSum::EtSumType::kMinBiasHFM0:
0528                   cout << " HFM0: ";
0529                   break;
0530                 case l1t::EtSum::EtSumType::kMinBiasHFP1:
0531                   cout << " HFP1: ";
0532                   break;
0533                 case l1t::EtSum::EtSumType::kMinBiasHFM1:
0534                   cout << " HFM1: ";
0535                   break;
0536                 case l1t::EtSum::EtSumType::kCentrality:
0537                   cout << " Centrality: ";
0538                   break;
0539                 default:
0540                   cout << " Unknown: ";
0541                   break;
0542               }
0543               cout << " Et " << std::dec << std::setw(3) << etsum->hwPt() << " (0x" << std::hex << std::setw(3)
0544                    << std::setfill('0') << etsum->hwPt() << ")";
0545               if (etsum->getType() == l1t::EtSum::EtSumType::kMissingEt ||
0546                   etsum->getType() == l1t::EtSum::EtSumType::kMissingHt ||
0547                   etsum->getType() == l1t::EtSum::EtSumType::kMissingEtHF ||
0548                   etsum->getType() == l1t::EtSum::EtSumType::kMissingHtHF)
0549                 cout << " Phi " << std::dec << std::setw(3) << etsum->hwPhi() << " (0x" << std::hex << std::setw(2)
0550                      << std::setfill('0') << etsum->hwPhi() << ")";
0551               cout << endl;
0552             }
0553           } else {
0554             cout << "No EtSums stored for this bx " << i << endl;
0555           }
0556         } else {
0557           cout << "No EtSum Data in this event " << endl;
0558         }
0559 
0560         // Dump the output record
0561         cout << " ------ uGtExt ----------" << endl;
0562         if (uGtExt.isValid()) {
0563           if (i >= uGtExt->getFirstBX() && i <= uGtExt->getLastBX()) {
0564             for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(i); extBlk != uGtExt->end(i);
0565                  ++extBlk) {
0566               extBlk->print(std::cout);
0567             }
0568           } else {
0569             cout << "No Ext Conditions stored for this bx " << i << endl;
0570           }
0571         } else {
0572           cout << "No uGtExt Data in this event " << endl;
0573         }
0574 
0575         // Dump the output record
0576         cout << " ------ uGtAlg ----------" << endl;
0577         if (uGtAlg.isValid()) {
0578           if (i >= uGtAlg->getFirstBX() && i <= uGtAlg->getLastBX()) {
0579             for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(i); algBlk != uGtAlg->end(i);
0580                  ++algBlk) {
0581               algBlk->print(std::cout);
0582             }
0583           } else {
0584             cout << "No Alg Decisions stored for this bx " << i << endl;
0585           }
0586         } else {
0587           cout << "No uGtAlg Data in this event " << endl;
0588         }
0589 
0590       }  //loop over Bx
0591       cout << std::dec << endl;
0592     }  //if dumpGtRecord
0593 
0594     // Dump Test Vectors for this bx
0595     if (m_dumpTestVectors) {
0596       for (int i = m_minBxVectors; i <= m_maxBxVectors; i++) {
0597         //         if(  (i>=egammas->getFirstBX() && i<=egammas->getLastBX())&&
0598         //        (i>=muons->getFirstBX()   && i<=muons->getLastBX())  &&
0599         //        (i>=taus->getFirstBX()    && i<=taus->getLastBX())   &&
0600         //        (i>=jets->getFirstBX()    && i<=jets->getLastBX())   &&
0601         //        (i>=etsums->getFirstBX()  && i<=etsums->getLastBX()) &&
0602         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) &&
0603         //        (i>=uGtAlg->getFirstBX()  && i<=uGtAlg->getLastBX()) ) {
0604         dumpTestVectors(i, m_testVectorFile, muons, muonShowers, egammas, taus, jets, etsums, uGtAlg, uGtExt);
0605         //   } else {
0606         //        edm::LogWarning("GtRecordDump") << "WARNING: Not enough information to dump test vectors for this bx=" << i << endl;
0607         //   }
0608       }
0609     }
0610   }
0611 
0612   // ------------ method called when ending the processing of a run  ------------
0613 
0614   void GtRecordDump::endRun(edm::Run const&, edm::EventSetup const&) {
0615     // Dump the results
0616     cout << "=========================== Global Trigger Summary Report  ==================================" << endl;
0617     cout << "                       Algorithm Name                              Init     aBXM     Final   " << endl;
0618     cout << "=============================================================================================" << endl;
0619     for (std::map<std::string, std::vector<int>>::const_iterator itAlgo = m_algoSummary.begin();
0620          itAlgo != m_algoSummary.end();
0621          itAlgo++) {
0622       std::string name = itAlgo->first;
0623       int initCnt = (itAlgo->second).at(0);
0624       int initPre = (itAlgo->second).at(1);
0625       int initFnl = (itAlgo->second).at(2);
0626       if (name != "NULL")
0627         cout << std::dec << setfill(' ') << setw(60) << name.c_str() << setw(10) << initCnt << setw(10) << initPre
0628              << setw(10) << initFnl << endl;
0629     }
0630     cout
0631         << "==========================================================================================================="
0632         << endl;
0633   }
0634 
0635   void GtRecordDump::dumpTestVectors(int bx,
0636                                      std::ofstream& myOutFile,
0637                                      Handle<BXVector<l1t::Muon>> muons,
0638                                      Handle<BXVector<l1t::MuonShower>> muonShowers,
0639                                      Handle<BXVector<l1t::EGamma>> egammas,
0640                                      Handle<BXVector<l1t::Tau>> taus,
0641                                      Handle<BXVector<l1t::Jet>> jets,
0642                                      Handle<BXVector<l1t::EtSum>> etsums,
0643                                      Handle<BXVector<GlobalAlgBlk>> uGtAlg,
0644                                      Handle<BXVector<GlobalExtBlk>> uGtExt) {
0645     const int empty = 0;
0646 
0647     // Dump Bx (4 digits)
0648     myOutFile << std::dec << std::setw(4) << std::setfill('0') << m_absBx;
0649 
0650     // Dump 8 Muons (16 digits + space) + Muon Showers
0651     int nDumped = 0;
0652 
0653     int muNumber = 0;  //keeps track of which muons get which muon shower information
0654     if (muons.isValid() && muonShowers.isValid()) {
0655       for (std::vector<l1t::Muon>::const_iterator mu = muons->begin(bx); mu != muons->end(bx); ++mu) {
0656         // loop over valid muons in this bx (muon 0 up to max possible of muon 7)
0657         int muShowerBit = 0;  // default value for muon shower bit
0658         if (bx >= muonShowers->getFirstBX() && bx <= muonShowers->getLastBX()) {
0659           if (muonShowers->size(bx) > 0) {
0660             std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(bx);
0661             if (muNumber == 0)
0662               muShowerBit = muShower->isOneNominalInTime();
0663             if (muNumber == 2)
0664               muShowerBit = muShower->isOneTightInTime();
0665             if (muNumber == 3)
0666               muShowerBit = muShower->isTwoLooseDiffSectorsInTime();
0667             if (muNumber == 4)
0668               muShowerBit = muShower->musOutOfTime0();
0669             if (muNumber == 6)
0670               muShowerBit = muShower->musOutOfTime1();
0671           }
0672         }
0673         cms_uint64_t packedWd = formatMuon(mu, muShowerBit);
0674         if (nDumped < 8) {
0675           myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
0676           nDumped++;
0677         }
0678         ++muNumber;  //keeps track of how many muons have been processed
0679       }              // end loop over Muons in this bx
0680 
0681       // Muon Shower information can exist, even if a muon object does not exist.  Hence,
0682       // now loop over non-existant muons from muNumber up to max of 7 and add the muon shower info
0683       int start = muNumber;
0684       for (int nonExistantMuon = start; nonExistantMuon < 8; nonExistantMuon++) {
0685         int muShowerBit = 0;  // default value for muon shower bit
0686         if (bx >= muonShowers->getFirstBX() && bx <= muonShowers->getLastBX()) {
0687           if (muonShowers->size(bx) > 0) {
0688             std::vector<l1t::MuonShower>::const_iterator muShower = muonShowers->begin(bx);
0689             if (muNumber == 0)
0690               muShowerBit = muShower->isOneNominalInTime();
0691             if (muNumber == 2)
0692               muShowerBit = muShower->isOneTightInTime();
0693             if (muNumber == 3)
0694               muShowerBit = muShower->isTwoLooseDiffSectorsInTime();
0695             if (muNumber == 4)
0696               muShowerBit = muShower->musOutOfTime0();
0697             if (muNumber == 6)
0698               muShowerBit = muShower->musOutOfTime1();
0699           }
0700         }
0701         cms_uint64_t packedWd = formatNonExistantMuon(muShowerBit);
0702         if (nDumped < 8) {
0703           myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << packedWd;
0704           nDumped++;
0705         }
0706         ++muNumber;  // keep track of the number of muons processed
0707       }              // end loop over non-existant muons
0708     }
0709     for (int i = nDumped; i < 8; i++) {
0710       myOutFile << " " << std::hex << std::setw(16) << std::setfill('0') << empty;
0711     }
0712     if (!muons.isValid())
0713       std::cout << "========= WARNING:  ALL MUONS INVALID ==========" << std::endl;
0714     if (!muonShowers.isValid())
0715       std::cout << "========= WARNING:  ALL MUON SHOWERS INVALID ==========" << std::endl;
0716     //===========================================
0717 
0718     // Dump 12 EG (8 digits + space)
0719     nDumped = 0;
0720     if (egammas.isValid()) {
0721       for (std::vector<l1t::EGamma>::const_iterator eg = egammas->begin(bx); eg != egammas->end(bx); ++eg) {
0722         unsigned int packedWd = formatEG(eg);
0723         if (nDumped < 12) {
0724           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0725           nDumped++;
0726         }
0727       }
0728     }
0729     for (int i = nDumped; i < 12; i++) {
0730       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0731     }
0732 
0733     // Dump 8 tau (8 digits + space)
0734     nDumped = 0;
0735     int maxTau = 8;
0736     if (m_tvVersion > 1)
0737       maxTau = 12;
0738     if (taus.isValid()) {
0739       for (std::vector<l1t::Tau>::const_iterator tau = taus->begin(bx); tau != taus->end(bx); ++tau) {
0740         unsigned int packedWd = formatTau(tau);
0741         if (nDumped < maxTau) {
0742           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0743           nDumped++;
0744         }
0745       }
0746     }
0747     for (int i = nDumped; i < maxTau; i++) {
0748       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0749     }
0750 
0751     // Dump 12 Jets (8 digits + space)
0752     nDumped = 0;
0753     if (jets.isValid()) {
0754       for (std::vector<l1t::Jet>::const_iterator jet = jets->begin(bx); jet != jets->end(bx); ++jet) {
0755         unsigned int packedWd = formatJet(jet);
0756         if (nDumped < 12) {
0757           myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << packedWd;
0758           nDumped++;
0759         }
0760       }
0761     }
0762     for (int i = nDumped; i < 12; i++) {
0763       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0764     }
0765 
0766     // Dump Et Sums (ETT, HT, ETM, ETMHF, HTM)
0767     unsigned int ETTpackWd = 0;
0768     unsigned int HTTpackWd = 0;
0769     unsigned int ETMpackWd = 0;
0770     unsigned int HTMpackWd = 0;
0771     unsigned int ETMHFpackWd = 0;
0772     unsigned int HTMHFpackWd = 0;
0773 
0774     // quantities packed into the words
0775     unsigned int ETTempackWd = 0;
0776     unsigned int HFP0packWd = 0;
0777     unsigned int HFM0packWd = 0;
0778     unsigned int HFP1packWd = 0;
0779     unsigned int HFM1packWd = 0;
0780     unsigned int TowerCountspackWd = 0;  // ccla
0781     unsigned int AsymEtpackWd = 0;
0782     unsigned int AsymHtpackWd = 0;
0783     unsigned int AsymEtHFpackWd = 0;
0784     unsigned int AsymHtHFpackWd = 0;
0785     unsigned int CENT30packWd = 0;  // centrality bits 3:0 in ETMHF word
0786     unsigned int CENT74packWd = 0;  // centrality bits 7:4 in HTMHF word
0787     std::pair<unsigned int, unsigned int> centrality(0, 0);
0788 
0789     if (etsums.isValid()) {
0790       for (std::vector<l1t::EtSum>::const_iterator etsum = etsums->begin(bx); etsum != etsums->end(bx); ++etsum) {
0791         switch (etsum->getType()) {
0792           case l1t::EtSum::EtSumType::kMissingEt:
0793             ETMpackWd = formatMissET(etsum);
0794             break;
0795           case l1t::EtSum::EtSumType::kMissingEtHF:
0796             ETMHFpackWd = formatMissET(etsum);
0797             break;
0798           case l1t::EtSum::EtSumType::kMissingHtHF:
0799             HTMHFpackWd = formatMissET(etsum);
0800             break;
0801           case l1t::EtSum::EtSumType::kMissingHt:
0802             HTMpackWd = formatMissET(etsum);
0803             break;
0804           case l1t::EtSum::EtSumType::kTotalEt:
0805             ETTpackWd = formatTotalET(etsum);
0806             break;
0807           case l1t::EtSum::EtSumType::kTotalEtEm:
0808             ETTempackWd = formatTotalET(etsum);
0809             break;
0810           case l1t::EtSum::EtSumType::kTotalHt:
0811             HTTpackWd = formatTotalET(etsum);
0812             break;
0813           case l1t::EtSum::EtSumType::kTowerCount:
0814             TowerCountspackWd = formatTowerCounts(etsum);
0815             break;
0816           case l1t::EtSum::EtSumType::kMinBiasHFP0:
0817             HFP0packWd = formatHMB(etsum);
0818             break;
0819           case l1t::EtSum::EtSumType::kMinBiasHFM0:
0820             HFM0packWd = formatHMB(etsum);
0821             break;
0822           case l1t::EtSum::EtSumType::kMinBiasHFP1:
0823             HFP1packWd = formatHMB(etsum);
0824             break;
0825           case l1t::EtSum::EtSumType::kMinBiasHFM1:
0826             HFM1packWd = formatHMB(etsum);
0827             break;
0828           case l1t::EtSum::EtSumType::kCentrality:
0829             centrality = formatCentrality(etsum);
0830             CENT30packWd = centrality.first;
0831             CENT74packWd = centrality.second;
0832             break;
0833           case l1t::EtSum::EtSumType::kAsymEt:
0834             AsymEtpackWd = formatAsym(etsum);
0835             break;
0836           case l1t::EtSum::EtSumType::kAsymHt:
0837             AsymHtpackWd = formatAsym(etsum);
0838             break;
0839           case l1t::EtSum::EtSumType::kAsymEtHF:
0840             AsymEtHFpackWd = formatAsym(etsum);
0841             break;
0842           case l1t::EtSum::EtSumType::kAsymHtHF:
0843             AsymHtHFpackWd = formatAsym(etsum);
0844             break;
0845           default:
0846             break;
0847         }  //end switch statement
0848       }    //end loop over etsums
0849     }
0850 
0851     // Put HMB bits in upper part of other SumEt Words
0852     ETTpackWd |= HFP0packWd;
0853     HTTpackWd |= HFM0packWd;
0854     ETMpackWd |= HFP1packWd;
0855     HTMpackWd |= HFM1packWd;
0856 
0857     // ETTem goes into ETT word bits 12 - 23
0858     if (m_tvVersion > 1)
0859       ETTpackWd |= (ETTempackWd << 12);
0860 
0861     // ccla Towercounts go in HTT word, bits 12-24
0862     if (m_tvVersion > 1)
0863       HTTpackWd |= (TowerCountspackWd << 12);
0864     if (m_tvVersion > 2) {
0865       ETMpackWd |= AsymEtpackWd;
0866       HTMpackWd |= AsymHtpackWd;
0867       ETMHFpackWd |= AsymEtHFpackWd;
0868       HTMHFpackWd |= AsymHtHFpackWd;
0869 
0870       ETMHFpackWd |= CENT30packWd;
0871       HTMHFpackWd |= CENT74packWd;
0872     }
0873     // Fill in the words in appropriate order
0874     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETTpackWd;
0875     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTTpackWd;
0876     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMpackWd;
0877     myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMpackWd;
0878     if (m_tvVersion > 1) {
0879       myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << ETMHFpackWd;
0880       if (m_tvVersion > 2) {
0881         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << HTMHFpackWd;
0882       } else {
0883         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0884       }
0885     }
0886 
0887     // If tvVersion > 1 put in placeholds for empty link (6 words (frames)) all zeros.
0888     if (m_tvVersion > 1) {
0889       for (int i = 0; i < 6; i++)
0890         myOutFile << " " << std::hex << std::setw(8) << std::setfill('0') << empty;
0891     }
0892 
0893     // External Condition (64 digits + space)
0894     int digit = 0;
0895     myOutFile << " ";
0896     if (uGtExt.isValid()) {
0897       for (std::vector<GlobalExtBlk>::const_iterator extBlk = uGtExt->begin(bx); extBlk != uGtExt->end(bx); ++extBlk) {
0898         for (int i = 255; i > -1; i--) {
0899           if (extBlk->getExternalDecision(i))
0900             digit |= (1 << (i % 4));
0901           if ((i % 4) == 0) {
0902             myOutFile << std::hex << std::setw(1) << digit;
0903             digit = 0;
0904           }
0905         }  //end loop over external bits
0906       }    //loop over objects
0907     } else {
0908       myOutFile << std::hex << std::setw(64) << std::setfill('0') << empty;
0909     }
0910 
0911     // Algorithm Dump (128 digits + space)
0912     digit = 0;
0913     myOutFile << " ";
0914     if (uGtAlg.isValid()) {
0915       for (std::vector<GlobalAlgBlk>::const_iterator algBlk = uGtAlg->begin(bx); algBlk != uGtAlg->end(bx); ++algBlk) {
0916         for (int i = 511; i > -1; i--) {
0917           if (algBlk->getAlgoDecisionFinal(i))
0918             digit |= (1 << (i % 4));
0919           if ((i % 4) == 0) {
0920             myOutFile << std::hex << std::setw(1) << digit;
0921             digit = 0;
0922           }
0923         }  //end loop over algorithm bits
0924 
0925         // Final OR (1 digit + space)
0926         unsigned int finalOr = (algBlk->getFinalOR() & 0x1);
0927         myOutFile << " " << std::hex << std::setw(1) << std::setfill('0') << finalOr;
0928       }
0929     } else {
0930       myOutFile << std::hex << std::setw(128) << std::setfill('0') << empty;
0931     }
0932 
0933     myOutFile << endl;
0934 
0935     m_absBx++;
0936   }
0937 
0938   cms_uint64_t GtRecordDump::formatMuon(std::vector<l1t::Muon>::const_iterator mu, int muShowerBit) {
0939     cms_uint64_t packedVal = 0;
0940 
0941     // Pack Bits
0942     packedVal |= ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43);
0943     packedVal |= ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0);  // & 0x3ff) <<18);
0944     // packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);         // removed
0945     packedVal |= ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53);  // added
0946     packedVal |= ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62);               // added
0947     packedVal |= ((cms_uint64_t)(muShowerBit & 0x1) << 61);               // added
0948     packedVal |= ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23);        // & 0x1ff) <<9);
0949     packedVal |= ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10);              // & 0x1ff) <<0);
0950     packedVal |= ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35);       // & 0x1)   <<28);
0951     packedVal |= ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34);            // & 0x1)   <<29);
0952     packedVal |= ((cms_uint64_t)(mu->hwQual() & 0xf) << 19);              // & 0xf)   <<30);
0953     packedVal |= ((cms_uint64_t)(mu->hwIso() & 0x3) << 32);               // & 0x3)   <<34);
0954     packedVal |= ((cms_uint64_t)(mu->tfMuonIndex() & 0x7f) << 36);
0955 
0956     //    if (false) {  // for debugging purposes
0957     //      std::cout << "----------------------" << std::endl;
0958     //      std::cout << "<<  0; mu->hwPhiAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0959     //                << ((cms_uint64_t)(mu->hwPhiAtVtx() & 0x3ff) << 0) << std::endl;
0960     //      std::cout << "<< 10; mu->hwPt()              = " << std::hex << std::setw(16) << std::setfill('0')
0961     //                << ((cms_uint64_t)(mu->hwPt() & 0x1ff) << 10) << std::endl;
0962     //      std::cout << "<< 19; mu->hwQual()            = " << std::hex << std::setw(16) << std::setfill('0')
0963     //                << ((cms_uint64_t)(mu->hwQual() & 0xf) << 19) << std::endl;
0964     //      std::cout << "<< 23; mu->hwEtaAtVtx()        = " << std::hex << std::setw(16) << std::setfill('0')
0965     //                << ((cms_uint64_t)(mu->hwEtaAtVtx() & 0x1ff) << 23) << std::endl;
0966     //      std::cout << "<< 32; mu->hwIso()             = " << std::hex << std::setw(16) << std::setfill('0')
0967     //                << ((cms_uint64_t)(mu->hwIso() & 0x3) << 32) << std::endl;
0968     //      std::cout << "<< 34; mu->hwCharge()          = " << std::hex << std::setw(16) << std::setfill('0')
0969     //                << ((cms_uint64_t)(mu->hwCharge() & 0x1) << 34) << std::endl;
0970     //      std::cout << "<< 35; mu->hwChargeValid()     = " << std::hex << std::setw(16) << std::setfill('0')
0971     //                << ((cms_uint64_t)(mu->hwChargeValid() & 0x1) << 35) << std::endl;
0972     //      std::cout << "<< 43; mu->hwPhi()             = " << std::hex << std::setw(16) << std::setfill('0')
0973     //                << ((cms_uint64_t)(mu->hwPhi() & 0x3ff) << 43) << std::endl;
0974     //      std::cout << "<< 53; mu->hwPtUnconstrained() = " << std::hex << std::setw(16) << std::setfill('0')
0975     //                << ((cms_uint64_t)(mu->hwPtUnconstrained() & 0xff) << 53) << std::endl;
0976     //      std::cout << "<< 61; muShowerBit             = " << std::hex << std::setw(16) << std::setfill('0')
0977     //                << ((cms_uint64_t)(muShowerBit & 0x1) << 61) << std::endl;
0978     //      std::cout << "<< 62; mu->hwDXY()             = " << std::hex << std::setw(16) << std::setfill('0')
0979     //                << ((cms_uint64_t)(mu->hwDXY() & 0x3) << 62) << std::endl;
0980     //      std::cout << "packedWord                     = " << std::hex << std::setw(16) << std::setfill('0') << packedVal
0981     //                << std::endl;
0982     //      std::cout << "----------------------" << std::endl;
0983     //    }
0984 
0985     return packedVal;
0986   }
0987 
0988   cms_uint64_t GtRecordDump::formatNonExistantMuon(int muShowerBit) {
0989     cms_uint64_t packedVal = 0;
0990 
0991     // Pack Bits
0992     packedVal |= ((cms_uint64_t)(0 & 0x3ff) << 43);
0993     packedVal |= ((cms_uint64_t)(0 & 0x3ff) << 0);  // & 0x3ff) <<18);
0994     // packedVal |= ((cms_uint64_t)(mu->hwEta() & 0x1ff) << 53);         // removed
0995     packedVal |= ((cms_uint64_t)(0 & 0xff) << 53);           // added
0996     packedVal |= ((cms_uint64_t)(0 & 0x3) << 62);            // added
0997     packedVal |= ((cms_uint64_t)(muShowerBit & 0x1) << 61);  // added
0998     packedVal |= ((cms_uint64_t)(0 & 0x1ff) << 23);          // & 0x1ff) <<9);
0999     packedVal |= ((cms_uint64_t)(0 & 0x1ff) << 10);          // & 0x1ff) <<0);
1000     packedVal |= ((cms_uint64_t)(0 & 0x1) << 35);            // & 0x1)   <<28);
1001     packedVal |= ((cms_uint64_t)(0 & 0x1) << 34);            // & 0x1)   <<29);
1002     packedVal |= ((cms_uint64_t)(0 & 0xf) << 19);            // & 0xf)   <<30);
1003     packedVal |= ((cms_uint64_t)(0 & 0x3) << 32);            // & 0x3)   <<34);
1004 
1005     return packedVal;
1006   }
1007 
1008   unsigned int GtRecordDump::formatEG(std::vector<l1t::EGamma>::const_iterator eg) {
1009     unsigned int packedVal = 0;
1010 
1011     // Pack Bits
1012     packedVal |= ((eg->hwPhi() & 0xff) << 17);
1013     packedVal |= ((eg->hwEta() & 0xff) << 9);
1014     packedVal |= ((eg->hwPt() & 0x1ff) << 0);
1015     packedVal |= ((eg->hwIso() & 0x3) << 25);
1016     packedVal |= ((eg->hwQual() & 0x31) << 27);
1017 
1018     return packedVal;
1019   }
1020 
1021   unsigned int GtRecordDump::formatTau(std::vector<l1t::Tau>::const_iterator tau) {
1022     unsigned int packedVal = 0;
1023 
1024     // Pack Bits
1025     packedVal |= ((tau->hwPhi() & 0xff) << 17);
1026     packedVal |= ((tau->hwEta() & 0xff) << 9);
1027     packedVal |= ((tau->hwPt() & 0x1ff) << 0);
1028     packedVal |= ((tau->hwIso() & 0x3) << 25);
1029     packedVal |= ((tau->hwQual() & 0x31) << 27);
1030 
1031     return packedVal;
1032   }
1033 
1034   unsigned int GtRecordDump::formatJet(std::vector<l1t::Jet>::const_iterator jet) {
1035     unsigned int packedVal = 0;
1036 
1037     // Pack Bits
1038     packedVal |= ((jet->hwPhi() & 0xff) << 19);
1039     packedVal |= ((jet->hwEta() & 0xff) << 11);
1040     packedVal |= ((jet->hwPt() & 0x7ff) << 0);
1041     packedVal |= ((jet->hwQual() & 0x1) << 27);
1042 
1043     return packedVal;
1044   }
1045 
1046   unsigned int GtRecordDump::formatMissET(std::vector<l1t::EtSum>::const_iterator etSum) {
1047     unsigned int packedVal = 0;
1048 
1049     // Pack Bits
1050     packedVal |= ((etSum->hwPhi() & 0xff) << 12);
1051     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
1052 
1053     return packedVal;
1054   }
1055 
1056   unsigned int GtRecordDump::formatTotalET(std::vector<l1t::EtSum>::const_iterator etSum) {
1057     unsigned int packedVal = 0;
1058 
1059     // Pack Bits
1060     packedVal |= ((etSum->hwPt() & 0xfff) << 0);
1061 
1062     return packedVal;
1063   }
1064 
1065   unsigned int GtRecordDump::formatTowerCounts(std::vector<l1t::EtSum>::const_iterator etSum) {
1066     unsigned int packedVal = 0;
1067     //unsigned int shift = 12;
1068 
1069     // Pack Bits
1070     //packedVal |= ((etSum->hwPt()     & 0xfff)   << shift);
1071 
1072     //towercount takes 13 bits
1073     packedVal |= ((etSum->hwPt() & 0x1fff) << 0);
1074 
1075     return packedVal;
1076   }
1077 
1078   unsigned int GtRecordDump::formatAsym(std::vector<l1t::EtSum>::const_iterator etSum) {
1079     //asym takes 8 bits, occupying bits 20-27 in ETM, HTM, ETMHF, and HTMHF etsums
1080     unsigned int packedVal = 0;
1081     unsigned int shift = 20;
1082 
1083     // Pack Bits
1084     packedVal |= ((etSum->hwPt() & 0xff) << shift);
1085 
1086     return packedVal;
1087   }
1088 
1089   unsigned int GtRecordDump::formatHMB(std::vector<l1t::EtSum>::const_iterator etSum) {
1090     // 4 bits, occupying bits 28-31.
1091     unsigned int packedVal = 0;
1092     unsigned int shift = 28;
1093 
1094     // Pack Bits
1095     packedVal |= ((etSum->hwPt() & 0xf) << shift);
1096 
1097     return packedVal;
1098   }
1099 
1100   std::pair<unsigned int, unsigned int> GtRecordDump::formatCentrality(std::vector<l1t::EtSum>::const_iterator etSum) {
1101     unsigned int centword = etSum->hwPt();
1102 
1103     // unpack word into 2 4 bit words
1104     int firstfour = (centword & 0xF);
1105     int lastfour = (centword >> 4) & 0xF;
1106 
1107     // 4 bits, occupying bits 28-31.
1108     unsigned int packedValLN = 0;
1109     unsigned int packedValUN = 0;
1110     unsigned int shift = 28;
1111 
1112     // Pack Bits
1113     packedValLN |= ((firstfour & 0xf) << shift);
1114     packedValUN |= ((lastfour & 0xf) << shift);
1115 
1116     std::pair<unsigned int, unsigned int> centrality(packedValLN, packedValUN);
1117     return centrality;
1118   }
1119 
1120 }  // namespace l1t
1121 
1122 DEFINE_FWK_MODULE(l1t::GtRecordDump);