Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:50

0001 #include "DQM/L1TMonitor/interface/L1TDEMON.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003 #include <bitset>
0004 
0005 using namespace dedefs;
0006 
0007 L1TDEMON::L1TDEMON(const edm::ParameterSet& iConfig) {
0008   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag", 0);
0009 
0010   if (verbose())
0011     std::cout << "L1TDEMON::L1TDEMON()...\n" << std::flush;
0012 
0013   DEsource_ = iConfig.getParameter<edm::InputTag>("DataEmulCompareSource");
0014   histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1TEMU");
0015   histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
0016 
0017   runInFF_ = iConfig.getUntrackedParameter<bool>("RunInFilterFarm", false);
0018   if (verbose())
0019     std::cout << "Filter farm run setting? " << runInFF_ << "\n" << std::flush;
0020 
0021   if (iConfig.getUntrackedParameter<bool>("disableROOToutput", true))
0022     histFile_ = "";
0023 
0024   if (!histFile_.empty()) {
0025     edm::LogInfo("OutputRootFile") << "L1TEmulator Monitoring histograms will be saved to " << histFile_.c_str()
0026                                    << std::endl;
0027   }
0028 
0029   // copied from HardwareValidation/L1Comparator
0030   // check on size are done there
0031   std::vector<unsigned int> dosys(0, DEnsys);
0032   dosys = iConfig.getUntrackedParameter<std::vector<unsigned int> >("COMPARE_COLLS", dosys);
0033 
0034   for (int i = 0; i < DEnsys; i++) {
0035     m_doSys[i] = dosys[i];
0036   }
0037 
0038   //
0039 
0040   nEvt_ = 0;
0041   for (int i = 0; i < DEnsys; i++) {
0042     deSysCount[i] = 0;
0043     nEvtWithSys[i] = 0;
0044   }
0045 
0046   hasRecord_ = true;
0047 
0048   if (verbose())
0049     std::cout << "L1TDEMON::L1TDEMON constructor...done.\n" << std::flush;
0050 
0051   //set Tokens(-s)
0052   DEsourceToken_ = consumes<L1DataEmulRecord>(iConfig.getParameter<edm::InputTag>("DataEmulCompareSource"));
0053 }
0054 
0055 L1TDEMON::~L1TDEMON() {}
0056 
0057 void L1TDEMON::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const&, edm::EventSetup const&) {
0058   if (verbose())
0059     std::cout << "L1TDEMON::beginJob()  start\n" << std::flush;
0060 
0061   ibooker.setCurrentFolder(histFolder_);
0062 
0063   //physical values disabled now, waiting for scale procedure
0064   //const double tpi = 6.2832;
0065   //const double amin=   -0.5;
0066   //const double amax=tpi+0.5;
0067 
0068   //                           ETP,  HTP,  RCT, GCT, DTP, DTF,  CTP, CTF, RPC,LTC, GMT,GLT
0069   int phiNBins[DEnsys] = {71, 71, 18, 18, 12, 255, 160, 255, 144, 0, 255, 0};
0070   double phiMinim[DEnsys] = {0.5, 0.5, -0.5, -0.5, -0.5, 0, -0.5, 0, -0.5, 0, 0, 0};
0071   double phiMaxim[DEnsys] = {71.5, 71.5, 17.5, 17.5, 11.5, 255, 159.5, 255, 143.5, 0, 255, 0};
0072 
0073   int etaNBins[DEnsys] = {35, 35, 22, 22, 5, 20, 120, 20, 64, 0, 20, 0};
0074   double etaMinim[DEnsys] = {-17.5, -17.5, -0.5, -0.5, -2.5, 0, -0.5, 0, -0.5, 0, 0, 0};
0075   double etaMaxim[DEnsys] = {17.5, 17.5, 21.5, 21.5, 2.5, 63, 119.5, 63, 63.5, 0, 63, 0};
0076 
0077   int x3NBins[DEnsys] = {0, 0, 7, 0, 4, 0, 0, 0, 0, 0, 0, 0};
0078   double x3Minim[DEnsys] = {0, 0, -0.5, 0, 0.5, 0, 0, 0, 0, 0, 0, 0};
0079   double x3Maxim[DEnsys] = {0, 0, 6.5, 0, 4.5, 0, 0, 0, 0, 0, 0, 0};
0080 
0081   int rnkNBins[DEnsys] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0082   double rnkMinim[DEnsys] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0083   double rnkMaxim[DEnsys] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
0084   //assume for
0085   for (int i = 0; i < DEnsys; i++) {
0086     rnkNBins[i] = 63;
0087     rnkMinim[i] = 0.5;
0088     rnkMaxim[i] = 63.5;
0089   }  //rank 0x3f->63
0090   rnkNBins[DTP] = 7;
0091   rnkMinim[DTP] = -0.5;
0092   rnkMaxim[DTP] = 6.5;  //rank 0-6
0093   rnkNBins[CTP] = 16;
0094   rnkMinim[CTP] = -0.5;
0095   rnkMaxim[CTP] = 15.5;  //quality 0-15
0096 
0097   /*--notes
0098      RCT: global index ieta (0-21)=[22,-0.5,21.5] , iphi (0-17)=[18,-0.5,17.5]; card (0-6)
0099      GCT: phi index (0-17); eta = -6 to -0, +0 to +6. Sign is bit 3, 1 means -ve Z, 0 means +ve Z -> 0.17
0100      DTP: usc 0..11; uwh -2..2; ust 1..4;
0101      CTP: rank is quality 0..15
0102      */
0103 
0104   if (!runInFF_)
0105     ibooker.setCurrentFolder(std::string(histFolder_ + "/common"));
0106 
0107   for (int j = 0; j < 2; j++) {
0108     std::string lbl("sysncand");
0109     lbl += (j == 0 ? "Data" : "Emul");
0110     sysncand[j] = ibooker.book1D(lbl.data(), lbl.data(), DEnsys, 0, DEnsys);
0111   }
0112 
0113   sysrates = ibooker.book1D("sysrates", "sysrates", DEnsys, 0, DEnsys);
0114   const int nerr = 5;
0115   errordist = ibooker.book1D("errorflag", "errorflag", nerr, 0, nerr);
0116 
0117   for (int j = 0; j < DEnsys; j++) {
0118     // skip if system disabled
0119     if (!m_doSys[j]) {
0120       continue;
0121     }
0122 
0123     if (!runInFF_) {
0124       ibooker.setCurrentFolder(std::string(histFolder_ + "/" + SystLabelExt[j]));
0125     }
0126 
0127     std::string lbl("");
0128     lbl.clear();
0129     lbl += SystLabel[j];
0130     lbl += "ErrorFlag";
0131     errortype[j] = ibooker.book1D(lbl.data(), lbl.data(), nerr, 0, nerr);
0132 
0133     // skip next histos if running in filter farm
0134     if (runInFF_) {
0135       continue;
0136     }
0137 
0138     //
0139     lbl.clear();
0140     lbl += SystLabel[j];
0141     lbl += "eta";
0142     eta[j] = ibooker.book1D(lbl.data(), lbl.data(), etaNBins[j], etaMinim[j], etaMaxim[j]);
0143     lbl.clear();
0144     lbl += SystLabel[j];
0145     lbl += "phi";
0146     phi[j] = ibooker.book1D(lbl.data(), lbl.data(), phiNBins[j], phiMinim[j], phiMaxim[j]);
0147     lbl.clear();
0148     lbl += SystLabel[j];
0149     lbl += "x3";
0150     x3[j] = ibooker.book1D(lbl.data(), lbl.data(), x3NBins[j], x3Minim[j], x3Maxim[j]);
0151     lbl.clear();
0152     lbl += SystLabel[j];
0153     lbl += "etaphi";
0154     etaphi[j] = ibooker.book2D(
0155         lbl.data(), lbl.data(), etaNBins[j], etaMinim[j], etaMaxim[j], phiNBins[j], phiMinim[j], phiMaxim[j]);
0156     //
0157     lbl.clear();
0158     lbl += SystLabel[j];
0159     lbl += "eta";
0160     lbl += "Data";
0161     etaData[j] = ibooker.book1D(lbl.data(), lbl.data(), etaNBins[j], etaMinim[j], etaMaxim[j]);
0162     lbl.clear();
0163     lbl += SystLabel[j];
0164     lbl += "phi";
0165     lbl += "Data";
0166     phiData[j] = ibooker.book1D(lbl.data(), lbl.data(), phiNBins[j], phiMinim[j], phiMaxim[j]);
0167     lbl.clear();
0168     lbl += SystLabel[j];
0169     lbl += "x3";
0170     lbl += "Data";
0171     x3Data[j] = ibooker.book1D(lbl.data(), lbl.data(), x3NBins[j], x3Minim[j], x3Maxim[j]);
0172     lbl.clear();
0173     lbl += SystLabel[j];
0174     lbl += "rank";
0175     lbl += "Data";
0176     rnkData[j] = ibooker.book1D(lbl.data(), lbl.data(), rnkNBins[j], rnkMinim[j], rnkMaxim[j]);
0177 
0178     const int nbit = (j == GLT) ? 128 : 32;
0179     lbl.clear();
0180     lbl += SystLabel[j];
0181     lbl += "dword";
0182     dword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0183     lbl.clear();
0184     lbl += SystLabel[j];
0185     lbl += "eword";
0186     eword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0187     lbl.clear();
0188     lbl += SystLabel[j];
0189     lbl += "deword";
0190     deword[j] = ibooker.book1D(lbl.data(), lbl.data(), nbit, 0, nbit);
0191     //lbl.clear();
0192     //lbl+=SystLabel[j];lbl+="masked";
0193     //masked[j] = dbe->book1D(lbl.data(),lbl.data(),nbit,0,nbit);
0194   }
0195 
0196   /// labeling (temporary cosmetics added here)
0197   for (int i = 0; i < DEnsys; i++) {
0198     sysrates->setBinLabel(i + 1, SystLabel[i]);
0199     sysncand[0]->setBinLabel(i + 1, SystLabel[i]);
0200     sysncand[1]->setBinLabel(i + 1, SystLabel[i]);
0201   }
0202   //const int nerr = 5;
0203   std::string errLabel[nerr] = {"Agree", "Loc. Agree", "L.Disagree", "Data only", "Emul only"};
0204   for (int j = 0; j < nerr; j++) {
0205     errordist->setBinLabel(j + 1, errLabel[j]);
0206   }
0207   for (int i = 0; i < DEnsys; i++) {
0208     // skip if system disabled
0209     if (!m_doSys[i]) {
0210       continue;
0211     }
0212 
0213     for (int j = 0; j < nerr; j++) {
0214       errortype[i]->setBinLabel(j + 1, errLabel[j]);
0215     }
0216   }
0217 
0218   // done if running in filter farm
0219   if (runInFF_)
0220     return;
0221 
0222   for (int i = 0; i < DEnsys; i++) {
0223     // skip if system disabled
0224     if (!m_doSys[i]) {
0225       continue;
0226     }
0227 
0228     etaphi[i]->setAxisTitle("eta", 1);
0229     etaphi[i]->setAxisTitle("phi", 2);
0230     eta[i]->setAxisTitle("eta");
0231     phi[i]->setAxisTitle("phi");
0232     x3[i]->setAxisTitle("x3");
0233     etaData[i]->setAxisTitle("eta");
0234     phiData[i]->setAxisTitle("phi");
0235     x3Data[i]->setAxisTitle("x3");
0236     rnkData[i]->setAxisTitle("rank");
0237     dword[i]->setAxisTitle("trigger data word bit");
0238     eword[i]->setAxisTitle("trigger data word bit");
0239     deword[i]->setAxisTitle("trigger data word bit");
0240     //masked [i]->setAxisTitle("trigger data word bit");
0241   }
0242 
0243   // assertions/temporary
0244   assert(ETP == 0);
0245   assert(HTP == 1);
0246   assert(RCT == 2);
0247   assert(GCT == 3);
0248   assert(DTP == 4);
0249   assert(DTF == 5);
0250   assert(CTP == 6);
0251   assert(CTF == 7);
0252   assert(RPC == 8);
0253   assert(LTC == 9);
0254   assert(GMT == 10);
0255   assert(GLT == 11);
0256 
0257   if (verbose())
0258     std::cout << "L1TDEMON::bookHistograms()  end.\n" << std::flush;
0259 }
0260 
0261 // ------------ method called to for each event  ------------
0262 void L1TDEMON::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0263   if (!hasRecord_)
0264     return;
0265 
0266   if (verbose())
0267     std::cout << "L1TDEMON::analyze()  start\n" << std::flush;
0268 
0269   nEvt_++;
0270 
0271   /// get the comparison results
0272   edm::Handle<L1DataEmulRecord> deRecord;
0273   iEvent.getByToken(DEsourceToken_, deRecord);
0274 
0275   if (!deRecord.isValid()) {
0276     edm::LogInfo("DataNotFound") << "Cannot find L1DataEmulRecord with label " << DEsource_.label()
0277                                  << " Please verify that comparator was successfully executed."
0278                                  << " Emulator DQM will be skipped!" << std::endl;
0279     hasRecord_ = false;
0280     return;
0281   }
0282 
0283   bool deMatch[DEnsys];
0284   deRecord->get_status(deMatch);
0285   if (verbose()) {
0286     std::cout << "[L1TDEMON] verbose sys match?: ";
0287     for (int i = 0; i < DEnsys; i++)
0288       std::cout << deMatch[i] << " ";
0289     std::cout << std::endl;
0290   }
0291 
0292   bool isComp[DEnsys];
0293   for (int i = 0; i < DEnsys; i++)
0294     isComp[i] = deRecord->get_isComp(i);
0295   if (verbose()) {
0296     std::cout << "[L1TDEMON] verbose dosys?: ";
0297     for (int i = 0; i < DEnsys; i++)
0298       std::cout << isComp[i];
0299     std::cout << std::endl;
0300   }
0301 
0302   int DEncand[DEnsys][2];
0303   for (int i = 0; i < DEnsys; i++)
0304     for (int j = 0; j < 2; j++)
0305       DEncand[i][j] = deRecord->getNCand(i, j);
0306 
0307   if (verbose()) {
0308     std::cout << "[L1TDEMON] ncands d: ";
0309     for (int i = 0; i < DEnsys; i++)
0310       std::cout << DEncand[i][0] << " ";
0311     std::cout << "\n[L1TDEMON] ncands e: ";
0312     for (int i = 0; i < DEnsys; i++)
0313       std::cout << DEncand[i][1] << " ";
0314     std::cout << std::endl;
0315   }
0316 
0317   const int nullVal = L1DataEmulDigi().reset();
0318 
0319   /// get the de candidates
0320   L1DEDigiCollection deColl;
0321   deColl = deRecord->getColl();
0322 
0323   // global counters
0324   int hasSys[DEnsys] = {0};
0325   for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
0326     if (!it->empty())
0327       hasSys[it->sid()]++;
0328   for (int i = 0; i < DEnsys; i++) {
0329     if (!hasSys[i])
0330       continue;
0331     nEvtWithSys[i]++;
0332     if (deMatch[i])
0333       deSysCount[i]++;
0334   }
0335 
0336   if (verbose()) {
0337     std::cout << "[L1TDEMON] digis: \n";
0338     for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++)
0339       std::cout << "\t" << *it << std::endl;
0340   }
0341 
0342   /// --- Fill histograms(me) ---
0343 
0344   // global, sub-systems d|e match, ncands
0345   for (int i = 0; i < DEnsys; i++) {
0346     // skip if system disabled
0347     if (!m_doSys[i]) {
0348       continue;
0349     }
0350 
0351     if (!isComp[i])
0352       continue;
0353 
0354     for (int j = 0; j < 2; j++)
0355       sysncand[j]->Fill(i, DEncand[i][j]);
0356 
0357     //sysrates->Fill(i,(int)!deMatch[i]);
0358     int ibin = i + 1;
0359     double rate = nEvtWithSys[i] ? (nEvtWithSys[i] - 1. * deSysCount[i]) / nEvtWithSys[i] : 0.;
0360     sysrates->setBinContent(ibin, rate);
0361 
0362     if (verbose()) {
0363       std::cout << "[L1TDEMON] analyze "
0364                 << " sysid:" << i << " nEvt:" << nEvt_ << " match?" << deMatch[i] << " ncands:" << hasSys[i]
0365                 << " nevtwsys:" << nEvtWithSys[i] << " nevtgood:" << deSysCount[i]
0366                 << " rate:" << sysrates->getBinContent(ibin) << "\n";
0367 
0368       if (rate > 1)
0369         std::cout << "problem, error rate for " << SystLabel[i] << " is " << sysrates->getBinContent(ibin) << std::endl;
0370     }
0371   }
0372 
0373   // container for subsystem's leading candidate
0374   const int ncorr = 3;
0375   float LeadCandVal[DEnsys][ncorr] = {{(float)nullVal}};
0376   for (int i = 0; i < DEnsys; i++)
0377     for (int j = 0; j < ncorr; j++)
0378       LeadCandVal[i][j] = nullVal;
0379 
0380   // d|e candidate loop
0381   for (L1DEDigiCollection::const_iterator it = deColl.begin(); it != deColl.end(); it++) {
0382     int sid = it->sid();
0383     int cid = it->cid();
0384 
0385     if (it->empty())
0386       continue;
0387     assert(isComp[sid]);
0388 
0389     int type = it->type();
0390     double phiv = it->x1();
0391     double etav = it->x2();
0392     double x3v = it->x3();
0393 
0394     float rankarr[2];
0395     it->rank(rankarr);
0396     float rnkv = rankarr[0];
0397 
0398     double wei = 1.;
0399 
0400     unsigned int mask = (~0x0);
0401 
0402     if (sid == RCT) {
0403       //if(cid!=RCTem)  continue;
0404       //if(cid!=RCTrgn) continue;
0405     }
0406     //     if(sid==GCT) {
0407     //       // For the moment just include EM and jet objects, energy sums being debugged in the expert DQM first.
0408     //       if(cid!=GCTisolaem &&
0409     //          cid!=GCTnoisoem &&
0410     //          cid!=GCTcenjets &&
0411     //          cid!=GCTforjets &&
0412     //          cid!=GCTtaujets) continue;
0413     //     }
0414     if (sid == DTP) {
0415       //tbd cols:th,ph; plots per wheel
0416       //if(it->x3()!=0) continue;
0417     }
0418     if (sid == GMT) {
0419       //select gmt cands only for GMT sys
0420       if (cid != GMTcnd)
0421         continue;
0422       //masking: gres -- I.Mikulec: mask bits 0,5,16,21,22,23
0423       //mask = (~(0x0e10021));
0424     }
0425     if (sid == DTF) {
0426       if (cid != DTtftrk)
0427         continue;
0428     }
0429     if (sid == RPC || sid == CTF || sid == RPC) {
0430       //select mu regional cands only for dtf,ctf,rpc
0431       //if(cid!=MUrtf) continue;
0432       //masking: gres dttf only -- I.Mikulec: lowest 16 bits only
0433       //if(sid==DTF) mask = 0xffff;
0434     }
0435 
0436     errordist->Fill(type);
0437     errortype[sid]->Fill(type);
0438 
0439     // skip next if running in filter farm
0440     if (runInFF_)
0441       continue;
0442 
0443     //exclude agreeing cands
0444     wei = 1.;
0445     if (!type)
0446       wei = 0.;
0447     if (etav != nullVal && phiv != nullVal)
0448       etaphi[sid]->Fill(etav, phiv, wei);
0449     if (etav != nullVal)
0450       eta[sid]->Fill(etav, wei);
0451     if (phiv != nullVal)
0452       phi[sid]->Fill(phiv, wei);
0453     if (sid == DTP)
0454       if (x3v != nullVal)
0455         x3[sid]->Fill(x3v, wei);
0456 
0457     unsigned int word[2];
0458     it->data(word);
0459     std::bitset<32> dbits(word[0]);
0460     std::bitset<32> ebits(word[1]);
0461     unsigned int dexor = ((word[0]) ^ (word[1]));
0462     //disagreeing bits
0463     std::bitset<32> debits(dexor);
0464     //disagreeing bits after masking
0465     std::bitset<32> dembits(((dexor) & (mask)));
0466 
0467     if (verbose())
0468       std::cout << "l1demon"
0469                 << " sid:" << sid << " cid:" << cid << "\n"
0470                 << " data:0x" << std::hex << word[0] << std::dec << " bitset:" << dbits << "\n"
0471                 << " emul:0x" << std::hex << word[1] << std::dec << " bitset:" << ebits << "\n"
0472                 << "  xor:0x" << std::hex << dexor << std::dec << " bitset:" << debits
0473                 << " bitset:" << ((dbits) ^ (ebits)) << "\n"
0474                 << std::flush;
0475 
0476     ///bitset loop
0477     for (int ibit = 0; ibit < 32; ibit++) {
0478       wei = 1.;
0479       //comparison gives no info if there's only 1 candidate
0480       if (type == 3 || type == 4)
0481         wei = 0.;
0482       if (dbits[ibit])
0483         dword[sid]->Fill(ibit, wei);
0484       if (ebits[ibit])
0485         eword[sid]->Fill(ibit, wei);
0486       if (debits[ibit])
0487         deword[sid]->Fill(ibit, wei);
0488       //if(dembits[ibit])masked[sid]->Fill(ibit,wei);
0489     }
0490 
0491     //exclude e-only cands (only data)
0492     wei = 1.;
0493     if (type == 4)
0494       wei = 0.;
0495     if (etav != nullVal)
0496       etaData[sid]->Fill(etav, wei);
0497     if (phiv != nullVal)
0498       phiData[sid]->Fill(phiv, wei);
0499     if (sid == DTP)
0500       if (x3v != nullVal)
0501         x3Data[sid]->Fill(x3v, wei);
0502     rnkData[sid]->Fill(rnkv, wei);
0503 
0504     //correlations: store leading candidate
0505     if (type == 4)
0506       continue;  //exclude e-only cands
0507     bool islead = false;
0508     if (rnkv > LeadCandVal[sid][2])
0509       islead = true;
0510     else if (rnkv == LeadCandVal[sid][2]) {
0511       if (phiv > LeadCandVal[sid][0])
0512         islead = true;
0513       else if (phiv == LeadCandVal[sid][0])
0514         if (etav > LeadCandVal[sid][1])
0515           islead = true;
0516     }
0517 
0518     if (islead) {
0519       LeadCandVal[sid][0] = phiv;
0520       LeadCandVal[sid][1] = etav;
0521       LeadCandVal[sid][2] = rnkv;
0522     }
0523 
0524   }  //close loop over dedigi-cands
0525 }