Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:49:27

0001 #include "DQM/L1TMonitor/interface/L1TdeGCT.h"
0002 #include <bitset>
0003 
0004 using namespace dedefs;
0005 
0006 const int L1TdeGCT::nGctColl_;
0007 const int L1TdeGCT::nerr;
0008 const int L1TdeGCT::nStage1Layer2Coll_;
0009 
0010 L1TdeGCT::L1TdeGCT(const edm::ParameterSet& iConfig) {
0011   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag", 0);
0012 
0013   if (verbose())
0014     std::cout << "L1TdeGCT::L1TdeGCT()...\n" << std::flush;
0015 
0016   DEsource_ = consumes<L1DataEmulRecord>(iConfig.getParameter<edm::InputTag>("DataEmulCompareSource"));
0017   histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder");
0018 
0019   histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
0020   if (iConfig.getUntrackedParameter<bool>("disableROOToutput", true))
0021     histFile_ = "";
0022 
0023   if (!histFile_.empty()) {
0024     edm::LogInfo("OutputRootFile") << "L1TEmulator GCT specific histograms will be saved to " << histFile_.c_str()
0025                                    << std::endl;
0026   }
0027 
0028   hasRecord_ = true;
0029 
0030   if (verbose())
0031     std::cout << "L1TdeGCT::L1TdeGCT()...done.\n" << std::flush;
0032   m_stage1_layer2_ = iConfig.getParameter<bool>("stage1_layer2_");
0033 }
0034 
0035 L1TdeGCT::~L1TdeGCT() {}
0036 
0037 void L1TdeGCT::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
0038   int rnkNBins = 63;
0039   double rnkMinim = 0.5;
0040   double rnkMaxim = 63.5;
0041 
0042   if (verbose())
0043     std::cout << "L1TdeGCT::beginRun()  start\n" << std::flush;
0044 
0045   ibooker.setCurrentFolder(histFolder_);
0046   //for Legacy GCT
0047   if (m_stage1_layer2_ == false) {
0048     sysrates = ibooker.book1D("sysrates", "RATE OF COMPARISON FAILURES", nGctColl_, 0, nGctColl_);
0049 
0050     for (int j = 0; j < 2; j++) {
0051       std::string lbl("sysncand");
0052       lbl += (j == 0 ? "Data" : "Emul");
0053       std::string title("GCT OBJECT MULTIPLICITY ");
0054       title += (j == 0 ? "(DATA)" : "(EMULATOR)");
0055       sysncand[j] = ibooker.book1D(lbl.data(), title.data(), nGctColl_, 0, nGctColl_);
0056     }
0057 
0058     for (int j = 0; j < nGctColl_; j++) {
0059       ibooker.setCurrentFolder(std::string(histFolder_ + "/" + cLabel[j]));
0060 
0061       std::string lbl("");
0062       std::string title("");
0063       lbl.clear();
0064       title.clear();
0065       lbl += cLabel[j];
0066       lbl += "ErrorFlag";
0067       title += cLabel[j];
0068       title += " ErrorFlag";
0069       errortype[j] = ibooker.book1D(lbl.data(), title.data(), nerr, 0, nerr);
0070 
0071       lbl.clear();
0072       title.clear();
0073       lbl += cLabel[j];
0074       lbl += "Eta";
0075       title += cLabel[j];
0076       title += " ETA OF COMPARISON FAILURES";
0077       eta[j] = ibooker.book1D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim);
0078       lbl.clear();
0079       title.clear();
0080       lbl += cLabel[j];
0081       lbl += "Phi";
0082       title += cLabel[j];
0083       title += " PHI OF COMPARISON FAILURES";
0084       phi[j] = ibooker.book1D(lbl.data(), title.data(), phiNBins, phiMinim, phiMaxim);
0085 
0086       lbl.clear();
0087       title.clear();
0088       lbl += cLabel[j];
0089       lbl += "Etaphi";
0090       title += cLabel[j];
0091       title += " ETA PHI OF COMPARISON FAILURES";
0092       etaphi[j] = ibooker.book2D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim, phiNBins, phiMinim, phiMaxim);
0093       lbl.clear();
0094       title.clear();
0095       lbl += cLabel[j];
0096       lbl += "Rank";
0097       title += cLabel[j];
0098       title += " RANK OF COMPARISON FAILURES";
0099       rnk[j] = ibooker.book1D(lbl.data(), title.data(), rnkNBins, rnkMinim, rnkMaxim);
0100       //
0101       lbl.clear();
0102       title.clear();
0103       lbl += cLabel[j];
0104       lbl += "Eta";
0105       lbl += "Data";
0106       title += cLabel[j];
0107       title += " ETA (DATA)";
0108       etaData[j] = ibooker.book1D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim);
0109       lbl.clear();
0110       title.clear();
0111       lbl += cLabel[j];
0112       lbl += "Phi";
0113       lbl += "Data";
0114       title += cLabel[j];
0115       title += " PHI (DATA)";
0116       phiData[j] = ibooker.book1D(lbl.data(), title.data(), phiNBins, phiMinim, phiMaxim);
0117 
0118       lbl.clear();
0119       title.clear();
0120       lbl += cLabel[j];
0121       lbl += "Rank";
0122       lbl += "Data";
0123       title += cLabel[j];
0124       title += " RANK (DATA)";
0125       rnkData[j] = ibooker.book1D(lbl.data(), title.data(), rnkNBins, rnkMinim, rnkMaxim);
0126       lbl.clear();
0127       lbl += cLabel[j];
0128       lbl += "Dword";
0129       dword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0130       lbl.clear();
0131       lbl += cLabel[j];
0132       lbl += "Eword";
0133       eword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0134       lbl.clear();
0135       lbl += cLabel[j];
0136       lbl += "DEword";
0137       deword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0138       //lbl.clear();
0139       //lbl+=cLabel[j];lbl+="Masked";
0140       //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
0141     }
0142 
0143     for (int i = 0; i < nGctColl_; i++) {
0144       sysrates->setBinLabel(i + 1, cLabel[i]);
0145       sysncand[0]->setBinLabel(i + 1, cLabel[i]);
0146       sysncand[1]->setBinLabel(i + 1, cLabel[i]);
0147     }
0148 
0149     for (int i = 0; i < nGctColl_; i++) {
0150       for (int j = 0; j < nerr; j++) {
0151         errortype[i]->setBinLabel(j + 1, errLabel[j]);
0152       }
0153     }
0154 
0155     for (int i = 0; i < nGctColl_; i++) {
0156       etaphi[i]->setAxisTitle("GCT #eta", 1);
0157       etaphi[i]->setAxisTitle("GCT #phi", 2);
0158       eta[i]->setAxisTitle("GCT #eta");
0159       phi[i]->setAxisTitle("GCT #phi");
0160       rnk[i]->setAxisTitle("Rank");
0161       etaData[i]->setAxisTitle("GCT #eta");
0162       phiData[i]->setAxisTitle("GCT #phi");
0163       rnkData[i]->setAxisTitle("Rank");
0164       dword[i]->setAxisTitle("trigger data word bit");
0165       eword[i]->setAxisTitle("trigger data word bit");
0166       deword[i]->setAxisTitle("trigger data word bit");
0167     }
0168 
0169     for (int i = 0; i < nGctColl_; i++) {
0170       colCount[i] = 0;
0171       nWithCol[i] = 0;
0172     }
0173   }
0174 
0175   // for stage 1 layer 2
0176 
0177   if (m_stage1_layer2_ == true) {
0178     sysrates = ibooker.book1D("sysrates", "RATE OF COMPARISON FAILURES", nStage1Layer2Coll_, 0, nStage1Layer2Coll_);
0179 
0180     for (int j = 0; j < 2; j++) {
0181       std::string lbl("sysncand");
0182       lbl += (j == 0 ? "Data" : "Emul");
0183       std::string title("Stage1Layer2 OBJECT MULTIPLICITY ");
0184       title += (j == 0 ? "(DATA)" : "(EMULATOR)");
0185       sysncand[j] = ibooker.book1D(lbl.data(), title.data(), nStage1Layer2Coll_, 0, nStage1Layer2Coll_);
0186     }
0187 
0188     for (int j = 0; j < nStage1Layer2Coll_; j++) {
0189       ibooker.setCurrentFolder(std::string(histFolder_ + "/" + sLabel[j]));
0190 
0191       if (sLabel[j] == "MHT") {
0192         rnkNBins = 127;
0193         rnkMinim = 0.5;
0194         rnkMaxim = 127.5;
0195       }
0196 
0197       if ((sLabel[j] == "HT") || (sLabel[j] == "ET") || (sLabel[j] == "MET")) {
0198         rnkNBins = 4096;
0199         rnkMinim = -0.5;
0200         rnkMaxim = 4095.5;
0201       }
0202 
0203       if (sLabel[j] == "Stage1HFSums") {
0204         rnkNBins = 9;
0205         rnkMinim = -0.5;
0206         rnkMaxim = 8.5;
0207       }
0208 
0209       if (sLabel[j] == "IsoTauJet") {
0210         rnkNBins = 64;
0211         rnkMinim = -0.5;
0212         rnkMaxim = 63.5;
0213       }
0214 
0215       std::string lbl("");
0216       std::string title("");
0217       lbl.clear();
0218       title.clear();
0219       lbl += sLabel[j];
0220       lbl += "ErrorFlag";
0221       title += sLabel[j];
0222       title += " ErrorFlag";
0223       errortype_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), nerr, 0, nerr);
0224 
0225       lbl.clear();
0226       title.clear();
0227       lbl += sLabel[j];
0228       lbl += "Eta";
0229       title += sLabel[j];
0230       title += " ETA OF COMPARISON FAILURES";
0231       eta_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim);
0232       lbl.clear();
0233       title.clear();
0234       lbl += sLabel[j];
0235       lbl += "Phi";
0236       title += sLabel[j];
0237       title += " PHI OF COMPARISON FAILURES";
0238       phi_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), phiNBins, phiMinim, phiMaxim);
0239 
0240       lbl.clear();
0241       title.clear();
0242       lbl += sLabel[j];
0243       lbl += "Etaphi";
0244       title += sLabel[j];
0245       title += " ETA PHI OF COMPARISON FAILURES";
0246       etaphi_stage1layer2[j] =
0247           ibooker.book2D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim, phiNBins, phiMinim, phiMaxim);
0248       lbl.clear();
0249       title.clear();
0250       lbl += sLabel[j];
0251       lbl += "Rank";
0252       title += sLabel[j];
0253       title += " RANK OF COMPARISON FAILURES";
0254       rnk_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), rnkNBins, rnkMinim, rnkMaxim);
0255       //
0256       lbl.clear();
0257       title.clear();
0258       lbl += sLabel[j];
0259       lbl += "Eta";
0260       lbl += "Data";
0261       title += sLabel[j];
0262       title += " ETA (DATA)";
0263       etaData_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), etaNBins, etaMinim, etaMaxim);
0264       lbl.clear();
0265       title.clear();
0266       lbl += sLabel[j];
0267       lbl += "Phi";
0268       lbl += "Data";
0269       title += sLabel[j];
0270       title += " PHI (DATA)";
0271       phiData_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), phiNBins, phiMinim, phiMaxim);
0272 
0273       lbl.clear();
0274       title.clear();
0275       lbl += sLabel[j];
0276       lbl += "Rank";
0277       lbl += "Data";
0278       title += sLabel[j];
0279       title += " RANK (DATA)";
0280       rnkData_stage1layer2[j] = ibooker.book1D(lbl.data(), title.data(), rnkNBins, rnkMinim, rnkMaxim);
0281       lbl.clear();
0282       lbl += sLabel[j];
0283       lbl += "Dword";
0284       dword_stage1layer2[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0285       lbl.clear();
0286       lbl += sLabel[j];
0287       lbl += "Eword";
0288       eword_stage1layer2[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0289       lbl.clear();
0290       lbl += sLabel[j];
0291       lbl += "DEword";
0292       deword_stage1layer2[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0293       //lbl.clear();
0294       //lbl+=cLabel[j];lbl+="Masked";
0295       //masked_stage1layer2[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
0296     }
0297 
0298     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0299       sysrates->setBinLabel(i + 1, sLabel[i]);
0300       sysncand[0]->setBinLabel(i + 1, sLabel[i]);
0301       sysncand[1]->setBinLabel(i + 1, sLabel[i]);
0302     }
0303 
0304     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0305       for (int j = 0; j < nerr; j++) {
0306         errortype_stage1layer2[i]->setBinLabel(j + 1, errLabel[j]);
0307       }
0308     }
0309 
0310     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0311       etaphi_stage1layer2[i]->setAxisTitle("Stage1Layer2 #eta", 1);
0312       etaphi_stage1layer2[i]->setAxisTitle("Stage1Layer2 #phi", 2);
0313       eta_stage1layer2[i]->setAxisTitle("Stage1Layer2 #eta");
0314       phi_stage1layer2[i]->setAxisTitle("Stage1Layer2 #phi");
0315       rnk_stage1layer2[i]->setAxisTitle("Rank");
0316       etaData_stage1layer2[i]->setAxisTitle("Stage1Layer2 #eta");
0317       phiData_stage1layer2[i]->setAxisTitle("Stage1Layer2 #phi");
0318       rnkData_stage1layer2[i]->setAxisTitle("Rank");
0319       dword_stage1layer2[i]->setAxisTitle("trigger data word bit");
0320       eword_stage1layer2[i]->setAxisTitle("trigger data word bit");
0321       deword_stage1layer2[i]->setAxisTitle("trigger data word bit");
0322     }
0323 
0324     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0325       colCount_stage1Layer2[i] = 0;
0326       nWithCol_stage1Layer2[i] = 0;
0327     }
0328   }
0329 
0330   if (verbose())
0331     std::cout << "L1TdeGCT::beginJob()  end.\n" << std::flush;
0332 }
0333 
0334 // ------------ method called to for each event  ------------
0335 
0336 void L1TdeGCT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0337   if (!hasRecord_)
0338     return;
0339 
0340   if (verbose())
0341     std::cout << "L1TdeGCT::analyze()  start\n" << std::flush;
0342 
0343   /// get the comparison results
0344   edm::Handle<L1DataEmulRecord> deRecord;
0345   iEvent.getByToken(DEsource_, deRecord);
0346 
0347   if (!deRecord.isValid()) {
0348     edm::LogInfo("DataNotFound") << "Cannot find L1DataEmulRecord"
0349                                  << " Please verify that comparator was successfully executed."
0350                                  << " Emulator DQM for GCT will be skipped!" << std::endl;
0351     hasRecord_ = false;
0352     return;
0353   }
0354 
0355   if (m_stage1_layer2_ == false) {
0356     bool isComp = deRecord->get_isComp(GCT);
0357     if (!isComp) {
0358       if (verbose())
0359         std::cout << "[L1TdeGCT] Gct information not generated in de-record."
0360                   << " Skiping event!\n"
0361                   << std::flush;
0362       return;
0363     }
0364 
0365     int DEncand[2] = {0};
0366     for (int j = 0; j < 2; j++)
0367       DEncand[j] = deRecord->getNCand(GCT, j);
0368 
0369     if (verbose())
0370       std::cout << "[L1TdeGCT] ncands"
0371                 << " data: " << DEncand[0] << " emul: " << DEncand[1] << std::endl;
0372 
0373     /// get the de candidates
0374     L1DEDigiCollection deColl;
0375     deColl = deRecord->getColl();
0376 
0377     // extract the GCT comparison digis
0378     L1DEDigiCollection gctColl;
0379 
0380     gctColl.reserve(20);
0381     gctColl.clear();
0382 
0383     for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
0384       if (!it->empty())
0385         if (it->sid() == GCT)
0386           gctColl.push_back(*it);
0387 
0388     if (verbose()) {
0389       std::cout << "[L1TdeGCT] record has " << gctColl.size() << " gct de digis\n" << std::flush;
0390       for (L1DEDigiCollection::const_iterator it = gctColl.begin(); it != gctColl.end(); it++)
0391         std::cout << "\t" << *it << std::endl;
0392     }
0393 
0394     const int nullVal = L1DataEmulDigi().reset();
0395 
0396     /// --- Fill histograms(me) ---
0397 
0398     // d|e candidate loop
0399     for (L1DEDigiCollection::const_iterator it = gctColl.begin(); it != gctColl.end(); it++) {
0400       // sid should be GCT
0401       int sid = it->sid();
0402       // cid: GCTisolaem, GCTnoisoem, GCTcenjets, GCTforjets, GCTtaujets
0403       int cid = it->cid();
0404       ///(note see L1Trigger/HardwareValidation/interface/DEtrait.h)
0405 
0406       if (verbose())
0407         std::cout << "[L1TdeGCT] processing digi "
0408                   << " sys:" << sid << " type:" << cid << " \n\t" << *it << "\n"
0409                   << std::flush;
0410 
0411       //assert(cid==GCT);
0412       if (sid != GCT || it->empty()) {
0413         LogDebug("L1TdeGCT") << "consistency check failure, non-gct digis!";
0414         continue;
0415       }
0416 
0417       int type = it->type();
0418       double phiv = it->x1();
0419       double etav = it->x2();
0420       float rankarr[2];
0421       it->rank(rankarr);
0422       float rnkv = rankarr[0];
0423 
0424       double wei;
0425 
0426       unsigned int mask = (~0x0);
0427 
0428       // shift coll type for starting at zero
0429       int ccid = cid - dedefs::GCTisolaem;
0430       if (ccid < 0 || ccid >= nGctColl_) {
0431         LogDebug("L1TdeGCT") << "consistency check failure, col type outbounds:" << ccid << "\n";
0432         ccid = 0;
0433       }
0434 
0435       //type: 0:agree 1:loc.agree, 2:loc.disagree, 3:data.only, 4:emul.only
0436       if (type < 4)
0437         sysncand[0]->Fill(ccid);
0438       if (type < 5 && type != 3)
0439         sysncand[1]->Fill(ccid);
0440 
0441       errortype[ccid]->Fill(type);
0442 
0443       wei = (type == 0) ? 0. : 1.;
0444       if (etav != nullVal && phiv != nullVal)
0445         etaphi[ccid]->Fill(etav, phiv, wei);
0446       if (etav != nullVal)
0447         eta[ccid]->Fill(etav, wei);
0448       if (phiv != nullVal)
0449         phi[ccid]->Fill(phiv, wei);
0450       rnk[ccid]->Fill(rnkv, wei);
0451 
0452       //exclude e-only cands (only data)
0453       wei = (type == 4) ? 0. : 1.;
0454       if (etav != nullVal)
0455         etaData[ccid]->Fill(etav, wei);
0456       if (phiv != nullVal)
0457         phiData[ccid]->Fill(phiv, wei);
0458       rnkData[ccid]->Fill(rnkv, wei);
0459 
0460       // GCT trigger bits
0461       unsigned int word[2];
0462       it->data(word);
0463       std::bitset<32> dbits(word[0]);
0464       std::bitset<32> ebits(word[1]);
0465       unsigned int dexor = ((word[0]) ^ (word[1]));
0466       //disagreeing bits
0467       std::bitset<32> debits(dexor);
0468       //disagreeing bits after masking
0469       std::bitset<32> dembits(((dexor) & (mask)));
0470 
0471       if (verbose())
0472         std::cout << "l1degct"
0473                   << " sid:" << sid << " cid:" << cid << "\n"
0474                   << " data:0x" << std::hex << word[0] << std::dec << " bitset:" << dbits << "\n"
0475                   << " emul:0x" << std::hex << word[1] << std::dec << " bitset:" << ebits << "\n"
0476                   << "  xor:0x" << std::hex << dexor << std::dec << " bitset:" << debits
0477                   << " bitset:" << ((dbits) ^ (ebits)) << "\n"
0478                   << std::flush;
0479 
0480       ///bitset loop
0481       for (int ibit = 0; ibit < 32; ibit++) {
0482         //comparison gives no info if there's only 1 candidate
0483         wei = (type == 3 || type == 4) ? 0. : 1.;
0484         if (dbits[ibit])
0485           dword[ccid]->Fill(ibit, wei);
0486         if (ebits[ibit])
0487           eword[ccid]->Fill(ibit, wei);
0488         if (debits[ibit])
0489           deword[ccid]->Fill(ibit, wei);
0490         //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
0491       }
0492     }
0493 
0494     //error rates per GCT trigger object type
0495     int hasCol[nGctColl_] = {0};
0496     int nagree[nGctColl_] = {0};
0497     for (L1DEDigiCollection::const_iterator it = gctColl.begin(); it != gctColl.end(); it++) {
0498       int ccid = it->cid() - dedefs::GCTisolaem;
0499       ccid = (ccid < 0 || ccid >= nGctColl_) ? 0 : ccid;
0500       hasCol[ccid]++;
0501       if (!it->type())
0502         nagree[ccid]++;
0503     }
0504     for (int i = 0; i < nGctColl_; i++) {
0505       if (!hasCol[i])
0506         continue;
0507       ///event based rate
0508       //nWithCol[i]++;
0509       //if(nagree[i]<hasCol[i]) colCount[i]++;
0510       ///object based rate
0511       nWithCol[i] += hasCol[i];  //#of objects
0512       colCount[i] += nagree[i];  //#of agreements
0513     }
0514     for (int i = 0; i < nGctColl_; i++) {
0515       int ibin = i + 1;
0516       double rate = nWithCol[i] ? 1. - 1. * colCount[i] / nWithCol[i] : 0.;
0517       sysrates->setBinContent(ibin, rate);
0518       if (verbose()) {
0519         std::cout << "[L1TDEMON] analyze rate computation\t\n"
0520                   << " colid:" << i << "(so far)"
0521                   << " nWithCol: " << nWithCol[i] << " colCount: " << colCount[i] << "(this event)"
0522                   << "hasCol: " << hasCol[i] << " nagree: " << nagree[i] << " rate:" << sysrates->getBinContent(ibin)
0523                   << "\n"
0524                   << std::flush;
0525         if (rate > 1. || rate < 0.)
0526           std::cout << "problem, error rate for " << SystLabel[i] << " is " << sysrates->getBinContent(ibin) << "\n"
0527                     << std::flush;
0528       }
0529     }
0530   }
0531 
0532   if (m_stage1_layer2_ == true) {
0533     bool isComp = deRecord->get_isComp(GCT);
0534     if (!isComp) {
0535       if (verbose())
0536         std::cout << "[L1TdeGCT] Gct information not generated in de-record."
0537                   << " Skiping event!\n"
0538                   << std::flush;
0539       return;
0540     }
0541 
0542     int DEncand[2] = {0};
0543     for (int j = 0; j < 2; j++)
0544       DEncand[j] = deRecord->getNCand(GCT, j);
0545 
0546     if (verbose())
0547       std::cout << "[L1TdeGCT] ncands"
0548                 << " data: " << DEncand[0] << " emul: " << DEncand[1] << std::endl;
0549 
0550     /// get the de candidates
0551     L1DEDigiCollection deColl;
0552     deColl = deRecord->getColl();
0553 
0554     // extract the GCT comparison digis
0555     L1DEDigiCollection stage1layer2Coll;
0556 
0557     stage1layer2Coll.reserve(21);
0558     stage1layer2Coll.clear();
0559 
0560     for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
0561       if (!it->empty())
0562         if (it->sid() == GCT)
0563           stage1layer2Coll.push_back(*it);
0564 
0565     if (verbose()) {
0566       std::cout << "[L1TdeSTAGE1LAYER2] record has " << stage1layer2Coll.size() << " stage1layer2 de digis\n"
0567                 << std::endl;
0568       for (L1DEDigiCollection::const_iterator it = stage1layer2Coll.begin(); it != stage1layer2Coll.end(); it++)
0569         std::cout << "\t" << *it << std::endl;
0570     }
0571 
0572     const int nullVal = L1DataEmulDigi().reset();
0573 
0574     /// --- Fill histograms(me) ---
0575 
0576     // d|e candidate loop
0577     for (L1DEDigiCollection::const_iterator it = stage1layer2Coll.begin(); it != stage1layer2Coll.end(); it++) {
0578       // sid should be GCT
0579       int sid = it->sid();
0580 
0581       int cid = it->cid();
0582       ///(note see L1Trigger/HardwareValidation/interface/DEtrait.h)
0583 
0584       if (verbose())
0585         std::cout << "[L1TdeStage1Layer2] processing digi "
0586                   << " sys:" << sid << " type:" << cid << " \n\t" << *it << "\n"
0587                   << std::endl;
0588 
0589       if (sid != GCT || it->empty()) {
0590         LogDebug("L1TdeGCT") << "consistency check failure, non-stage1layer2 digis!";
0591         continue;
0592       }
0593 
0594       int type = it->type();
0595       double phiv = it->x1();
0596       double etav = it->x2();
0597       float rankarr[2];
0598       it->rank(rankarr);
0599       float rnkv = rankarr[0];
0600 
0601       double wei;
0602 
0603       unsigned int mask = (~0x0);
0604 
0605       // shift coll type for starting at zero
0606       int ccid = cid - dedefs::GCTisolaem;
0607       if (ccid < 0 || ccid >= nStage1Layer2Coll_) {
0608         LogDebug("L1TdeGCT") << "consistency check failure, col type outbounds:" << ccid << "\n";
0609         ccid = 0;
0610       }
0611 
0612       //type: 0:agree 1:loc.agree, 2:loc.disagree, 3:data.only, 4:emul.only
0613       if (type < 4)
0614         sysncand[0]->Fill(ccid);
0615       if (type < 5 && type != 3)
0616         sysncand[1]->Fill(ccid);
0617       errortype_stage1layer2[ccid]->Fill(type);
0618       wei = (type == 0) ? 0. : 1.;
0619       if (etav != nullVal && phiv != nullVal)
0620         etaphi_stage1layer2[ccid]->Fill(etav, phiv, wei);
0621       if (etav != nullVal)
0622         eta_stage1layer2[ccid]->Fill(etav, wei);
0623       if (phiv != nullVal)
0624         phi_stage1layer2[ccid]->Fill(phiv, wei);
0625       rnk_stage1layer2[ccid]->Fill(rnkv, wei);
0626 
0627       //exclude e-only cands (only data)
0628       wei = (type == 4) ? 0. : 1.;
0629       if (etav != nullVal)
0630         etaData_stage1layer2[ccid]->Fill(etav, wei);
0631       if (phiv != nullVal)
0632         phiData_stage1layer2[ccid]->Fill(phiv, wei);
0633       rnkData_stage1layer2[ccid]->Fill(rnkv, wei);
0634 
0635       // GCT trigger bits
0636       unsigned int word_stage1layer2[2];
0637       it->data(word_stage1layer2);
0638       std::bitset<32> dbits(word_stage1layer2[0]);
0639       std::bitset<32> ebits(word_stage1layer2[1]);
0640       unsigned int dexor = ((word_stage1layer2[0]) ^ (word_stage1layer2[1]));
0641       //disagreeing bits
0642       std::bitset<32> debits(dexor);
0643       //disagreeing bits after masking
0644       std::bitset<32> dembits(((dexor) & (mask)));
0645 
0646       if (verbose())
0647         std::cout << "l1degct"
0648                   << " sid:" << sid << " cid:" << cid << "\n"
0649                   << " data:0x" << std::hex << word_stage1layer2[0] << std::dec << " bitset:" << dbits << "\n"
0650                   << " emul:0x" << std::hex << word_stage1layer2[1] << std::dec << " bitset:" << ebits << "\n"
0651                   << "  xor:0x" << std::hex << dexor << std::dec << " bitset:" << debits
0652                   << " bitset:" << ((dbits) ^ (ebits)) << "\n"
0653                   << std::flush;
0654 
0655       ///bitset loop
0656       for (int ibit = 0; ibit < 32; ibit++) {
0657         //comparison gives no info if there's only 1 candidate
0658         wei = (type == 3 || type == 4) ? 0. : 1.;
0659         if (dbits[ibit])
0660           dword_stage1layer2[ccid]->Fill(ibit, wei);
0661         if (ebits[ibit])
0662           eword_stage1layer2[ccid]->Fill(ibit, wei);
0663         if (debits[ibit])
0664           deword_stage1layer2[ccid]->Fill(ibit, wei);
0665         //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
0666       }
0667     }
0668     //error rates per GCT trigger object type
0669     int hasCol[nStage1Layer2Coll_] = {0};
0670     int nagree[nStage1Layer2Coll_] = {0};
0671     for (L1DEDigiCollection::const_iterator it = stage1layer2Coll.begin(); it != stage1layer2Coll.end(); it++) {
0672       int ccid = it->cid() - dedefs::GCTisolaem;
0673       ccid = (ccid < 0 || ccid >= nStage1Layer2Coll_) ? 0 : ccid;
0674       hasCol[ccid]++;
0675       if (!it->type())
0676         nagree[ccid]++;
0677     }
0678     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0679       if (!hasCol[i])
0680         continue;
0681       ///event based rate
0682       //nWithCol[i]++;
0683       //if(nagree[i]<hasCol[i]) colCount[i]++;
0684       ///object based rate
0685       nWithCol_stage1Layer2[i] += hasCol[i];  //#of objects
0686       colCount_stage1Layer2[i] += nagree[i];  //#of agreements
0687     }
0688     for (int i = 0; i < nStage1Layer2Coll_; i++) {
0689       int ibin = i + 1;
0690       double rate = nWithCol_stage1Layer2[i] ? 1. - 1. * colCount_stage1Layer2[i] / nWithCol_stage1Layer2[i] : 0.;
0691       sysrates->setBinContent(ibin, rate);
0692       if (verbose()) {
0693         std::cout << "[L1TDEMON] analyze rate computation\t\n"
0694                   << " colid:" << i << "(so far)"
0695                   << " nWithCol: " << nWithCol_stage1Layer2[i] << " colCount: " << colCount_stage1Layer2[i]
0696                   << "(this event)"
0697                   << "hasCol: " << hasCol[i] << " nagree: " << nagree[i] << " rate:" << sysrates->getBinContent(ibin)
0698                   << "\n"
0699                   << std::flush;
0700         if (rate > 1. || rate < 0.)
0701           std::cout << "problem, error rate for " << SystLabel[i] << " is " << sysrates->getBinContent(ibin) << "\n"
0702                     << std::flush;
0703       }
0704     }
0705   }
0706 }