Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:10:34

0001 #include "DQM/L1TMonitor/interface/BxTiming.h"
0002 #include <cstdio>
0003 
0004 BxTiming::BxTiming(const edm::ParameterSet &iConfig) {
0005   verbose_ = iConfig.getUntrackedParameter<int>("VerboseFlag", 0);
0006   if (verbose())
0007     std::cout << "BxTiming::BxTiming()...\n" << std::flush;
0008 
0009   fedRef_ = iConfig.getUntrackedParameter<int>("ReferenceFedId", 813);
0010   fedSource_ = iConfig.getUntrackedParameter<edm::InputTag>("FedSource", edm::InputTag("source"));
0011   fedSource_token_ = consumes<FEDRawDataCollection>(
0012       iConfig.getUntrackedParameter<edm::InputTag>("FedSource", edm::InputTag("source")));
0013   gtSource_ = iConfig.getUntrackedParameter<edm::InputTag>("GtSource", edm::InputTag("gtUnpack"));
0014   gtSource_token_ = consumes<L1GlobalTriggerReadoutRecord>(
0015       iConfig.getUntrackedParameter<edm::InputTag>("GtSource", edm::InputTag("gtUnpack")));
0016   histFile_ = iConfig.getUntrackedParameter<std::string>("HistFile", "");
0017   histFolder_ = iConfig.getUntrackedParameter<std::string>("HistFolder", "L1T/BXSynch");
0018 
0019   runInFF_ = iConfig.getUntrackedParameter<bool>("RunInFilterFarm", true);
0020   if (runInFF_)
0021     histFolder_ = "L1T/BXSynch_EvF";
0022   if (verbose())
0023     std::cout << "Filter farm run setting?" << runInFF_ << "\n" << std::flush;
0024 
0025   listGtBits_ = iConfig.getUntrackedParameter<std::vector<int> >("GtBitList", std::vector<int>(1, 0));
0026   if (listGtBits_.size() == 1 && listGtBits_.at(0) == -1) {
0027     int ngtbits = 128;
0028     listGtBits_.reserve(ngtbits);
0029     for (int i = 0; i < ngtbits; i++)
0030       listGtBits_[i] = i;
0031   }
0032 
0033   if (verbose()) {
0034     std::cout << "BxTiming: gt bits set for timing dqm:";
0035     std::cout << "nbits:" << listGtBits_.size() << " list: ";
0036     for (size_t i = 0; i != listGtBits_.size(); i++)
0037       std::cout << listGtBits_.at(i) << " ";
0038     std::cout << "\n" << std::flush;
0039   }
0040 
0041   nEvt_ = 0;
0042 
0043   if (verbose())
0044     std::cout << "BxTiming::BxTiming constructor...done.\n" << std::flush;
0045 }
0046 
0047 BxTiming::~BxTiming() {}
0048 
0049 void BxTiming::bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &, edm::EventSetup const &) {
0050   ibooker.setCurrentFolder(histFolder_);
0051 
0052   /// initialize counters
0053   for (int i = 0; i < nfed_; i++) {
0054     nBxDiff[i][0] = 0;
0055     nBxDiff[i][1] = nbig_;
0056     nBxDiff[i][2] = -1 * nbig_;
0057     nBxOccy[i][0] = 0;
0058     nBxOccy[i][1] = nbig_;
0059     nBxOccy[i][2] = -1 * nbig_;
0060   }
0061 
0062   std::string lbl("");
0063   std::string SysLabel[NSYS] = {"PreShower", "ECAL", "HCAL", "GCT", "CSCTPG", "CSCTF", "DTTPG", "DTTF", "RPC", "GT"};
0064 
0065   typedef std::pair<int, int> FEDRange;
0066 
0067   std::pair<int, int> fedRange[NSYS] = {
0068       FEDRange(FEDNumbering::MINPreShowerFEDID, FEDNumbering::MAXPreShowerFEDID),     //520..575
0069       FEDRange(FEDNumbering::MINECALFEDID, FEDNumbering::MAXECALFEDID),               //600..670
0070       FEDRange(FEDNumbering::MINHCALFEDID, FEDNumbering::MAXHCALFEDID),               //700..731
0071       FEDRange(FEDNumbering::MINTriggerGCTFEDID, FEDNumbering::MAXTriggerEGTPFEDID),  //745..749
0072       FEDRange(FEDNumbering::MINCSCFEDID, FEDNumbering::MAXCSCFEDID),                 //750..757
0073       FEDRange(FEDNumbering::MINCSCTFFEDID, FEDNumbering::MAXCSCTFFEDID),             //760..760
0074       FEDRange(FEDNumbering::MINDTFEDID, FEDNumbering::MAXDTFEDID),                   //770..775
0075       FEDRange(FEDNumbering::MINDTTFFEDID, FEDNumbering::MAXDTTFFEDID),               //780..780
0076       FEDRange(FEDNumbering::MINRPCFEDID, FEDNumbering::MAXRPCFEDID),                 //790..795
0077       FEDRange(FEDNumbering::MINTriggerGTPFEDID, FEDNumbering::MAXTriggerGTPFEDID)    //812..813
0078   };
0079   for (int i = 0; i < NSYS; i++)
0080     fedRange_[i] = fedRange[i];
0081 
0082   int fedRefSys = -1;
0083   for (int i = 0; i < NSYS; i++)
0084     if (fedRef_ >= fedRange_[i].first && fedRef_ <= fedRange_[i].second) {
0085       fedRefSys = i;
0086       break;
0087     }
0088   std::string refName("");
0089   std::string spreadLabel[nspr_] = {"Spread", "Min", "Max"};
0090   if (fedRefSys >= 0)
0091     refName += SysLabel[fedRefSys];
0092   else
0093     refName += fedRef_;
0094 
0095   /// book the histograms
0096 
0097   const int dbx = nbig_;
0098 
0099   ibooker.setCurrentFolder(histFolder_);
0100 
0101   hBxDiffAllFed = ibooker.bookProfile(
0102       "BxDiffAllFed", "BxDiffAllFed", nfed_ + 1, -0.5, nfed_ + 0.5, 2 * dbx + 1, -1 * dbx - 0.5, dbx + 0.5);
0103 
0104   for (int i = 0; i < nspr_; i++) {
0105     lbl.clear();
0106     lbl += "BxDiffAllFed";
0107     lbl += spreadLabel[i];
0108     hBxDiffAllFedSpread[i] = ibooker.book1D(lbl.data(), lbl.data(), nfed_ + 1, -0.5, nfed_ + 0.5);
0109     lbl.clear();
0110     lbl += "BxOccyAllFed";
0111     lbl += spreadLabel[i];
0112     hBxOccyAllFedSpread[i] = ibooker.book1D(lbl.data(), lbl.data(), nfed_ + 1, -0.5, nfed_ + 0.5);
0113 
0114     lbl.clear();
0115     lbl += "BxOccyAllFed";
0116     hBxOccyAllFed = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
0117   }
0118 
0119   // following histos defined only when not runing in the ff
0120   if (!runInFF_) {
0121     ibooker.setCurrentFolder(histFolder_);
0122 
0123     for (int i = 0; i < NSYS; i++) {
0124       lbl.clear();
0125       lbl += SysLabel[i];
0126       lbl += "FedBxDiff";
0127       int nfeds = fedRange_[i].second - fedRange_[i].first + 1;
0128       nfeds = (nfeds > 0) ? nfeds : 1;
0129       hBxDiffSysFed[i] = ibooker.bookProfile(lbl.data(),
0130                                              lbl.data(),
0131                                              nfeds,
0132                                              fedRange_[i].first - 0.5,
0133                                              fedRange_[i].second + 0.5,
0134                                              2 * dbx + 1,
0135                                              -1 * dbx - 0.5,
0136                                              dbx + 0.5);
0137     }
0138 
0139     lbl.clear();
0140     lbl += "BxOccyAllFed";
0141     hBxOccyOneFed = new MonitorElement *[nfed_];
0142     ibooker.setCurrentFolder(histFolder_ + "/SingleFed");
0143     for (int i = 0; i < nfed_; i++) {
0144       lbl.clear();
0145       lbl += "BxOccyOneFed";
0146       lbl += std::to_string(i);
0147       hBxOccyOneFed[i] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
0148     }
0149 
0150     ibooker.setCurrentFolder(histFolder_);
0151     for (int i = 0; i < nttype_; i++) {
0152       lbl.clear();
0153       lbl += "BxOccyGtTrigType";
0154       lbl += std::to_string(i + 1);
0155       hBxOccyGtTrigType[i] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
0156     }
0157 
0158     ibooker.setCurrentFolder(histFolder_ + "/SingleBit");
0159     for (int i = 0; i < NSYS; i++) {
0160       hBxOccyTrigBit[i] = new MonitorElement *[listGtBits_.size()];
0161       for (size_t j = 0; j < listGtBits_.size(); j++) {
0162         lbl.clear();
0163         lbl += SysLabel[i];
0164         lbl += "BxOccyGtBit";
0165         lbl += std::to_string(listGtBits_.at(j));
0166         hBxOccyTrigBit[i][j] = ibooker.book1D(lbl.data(), lbl.data(), norb_ + 1, -0.5, norb_ + 0.5);
0167       }
0168     }
0169   }
0170 
0171   /// labeling (cosmetics added here)
0172   hBxDiffAllFed->setAxisTitle("FED ID", 1);
0173   lbl.clear();
0174   lbl += "BX(fed)-BX(";
0175   lbl += refName;
0176   lbl += ")";
0177   hBxDiffAllFed->setAxisTitle(lbl, 2);
0178   for (int i = 0; i < nspr_; i++) {
0179     lbl.clear();
0180     lbl += "BX(fed)-BX(";
0181     lbl += refName;
0182     lbl += ") " + spreadLabel[i];
0183     hBxDiffAllFedSpread[i]->setAxisTitle("FED ID", 1);
0184     hBxDiffAllFedSpread[i]->setAxisTitle(lbl, 2);
0185     lbl.clear();
0186     lbl += "Bx FED occupancy";
0187     lbl += " ";
0188     lbl += spreadLabel[i];
0189     hBxOccyAllFedSpread[i]->setAxisTitle("FED ID", 1);
0190     hBxOccyAllFedSpread[i]->setAxisTitle(lbl, 2);
0191   }
0192 
0193   hBxOccyAllFed->setAxisTitle("bx", 1);
0194   lbl.clear();
0195   lbl += "Combined FED occupancy";
0196   hBxOccyAllFed->setAxisTitle(lbl, 2);
0197 
0198   // skip next if running in filter farm
0199   if (runInFF_)
0200     return;
0201 
0202   for (int i = 0; i < NSYS; i++) {
0203     lbl.clear();
0204     lbl += SysLabel[i];
0205     lbl += " FED ID";
0206     hBxDiffSysFed[i]->setAxisTitle(lbl, 1);
0207     lbl.clear();
0208     lbl += "BX(";
0209     lbl += SysLabel[i];
0210     lbl += ")-BX(";
0211     lbl += refName;
0212     lbl += ")";
0213     hBxDiffSysFed[i]->setAxisTitle(lbl, 2);
0214   }
0215 
0216   for (int i = 0; i < nfed_; i++) {
0217     hBxOccyOneFed[i]->setAxisTitle("bx", 1);
0218     lbl.clear();
0219     lbl += " FED ";
0220     lbl += std::to_string(i);
0221     lbl += " occupancy";
0222     hBxOccyOneFed[i]->setAxisTitle(lbl, 2);
0223   }
0224   for (int i = 0; i < nttype_; i++) {
0225     hBxOccyGtTrigType[i]->setAxisTitle("bx", 1);
0226     lbl.clear();
0227     lbl += "GT occupancy for trigger type ";
0228     lbl += std::to_string(i + 1);
0229     hBxOccyGtTrigType[i]->setAxisTitle(lbl, 2);
0230   }
0231 
0232   for (int i = 0; i < NSYS; i++) {
0233     for (size_t j = 0; j < listGtBits_.size(); j++) {
0234       hBxOccyTrigBit[i][j]->setAxisTitle("bx", 1);
0235       lbl.clear();
0236       lbl += SysLabel[i];
0237       lbl += " Bx occupancy for Trigger bit ";
0238       lbl += std::to_string(listGtBits_.at(j));
0239       hBxOccyTrigBit[i][j]->setAxisTitle(lbl, 2);
0240     }
0241   }
0242 }
0243 
0244 // ------------ method called to for each event  ------------
0245 void BxTiming::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0246   if (verbose())
0247     std::cout << "BxTiming::analyze()  start\n" << std::flush;
0248 
0249   nEvt_++;
0250 
0251   /// get the raw data - if not found, return
0252   edm::Handle<FEDRawDataCollection> rawdata;
0253   iEvent.getByToken(fedSource_token_, rawdata);
0254 
0255   if (!rawdata.isValid()) {
0256     if (verbose())
0257       std::cout << "BxTiming::analyze() | FEDRawDataCollection with input tag " << fedSource_ << " not found.";
0258 
0259     return;
0260   }
0261 
0262   // get the GT bits
0263   edm::Handle<L1GlobalTriggerReadoutRecord> gtdata;
0264   iEvent.getByToken(gtSource_token_, gtdata);
0265   std::vector<bool> gtbits;
0266   int ngtbits = 128;
0267   gtbits.reserve(ngtbits);
0268   for (int i = 0; i < ngtbits; i++)
0269     gtbits[i] = false;
0270   if (gtdata.isValid())
0271     gtbits = gtdata->decisionWord();
0272 
0273   if (gtbits.empty()) {
0274     gtbits.push_back(true);  // gtdata->decision();
0275     if (verbose())
0276       std::cout << "BxTiming::analyze() | unexpected empty decision bits!";
0277   }
0278 
0279   if (verbose()) {
0280     std::cout << "BxTiming::analyze()  gt data valid:" << (int)(gtdata.isValid() ? 0 : 1)
0281               << " decision word size:" << (int)(gtbits.size()) << "  bits: ";
0282     for (size_t i = 0; i != gtbits.size(); i++) {
0283       int ii = gtbits.at(i) ? 1 : 0;
0284       std::cout << ii;
0285     }
0286     std::cout << ".\n" << std::flush;
0287   }
0288 
0289   // get reference bx
0290   int bxRef = FEDHeader(rawdata->FEDData(fedRef_).data()).bxID();
0291 
0292   // triggerType
0293   // trigger types: physics (1), calibration (2), random (3), traced physics (5),  test (6)
0294   int ttype = static_cast<double>(iEvent.eventAuxiliary().experimentType());
0295 
0296   // loop over feds
0297   for (int i = 0; i < FEDNumbering::MAXFEDID + 1; i++) {
0298     const FEDRawData &data = rawdata->FEDData(i);
0299     size_t size = data.size();
0300 
0301     if (!size)
0302       continue;
0303     FEDHeader header(data.data());
0304     //int lvl1id = header.lvl1ID(); //Level-1 event number generated by the TTC system
0305     int bx = header.bxID();  // The bunch crossing number
0306 
0307     int bxDiff = calcBxDiff(bx, bxRef);  // deviation from reference bx
0308 
0309     //min
0310     if (nBxDiff[i][1] > bxDiff)
0311       nBxDiff[i][1] = bxDiff;
0312     if (nBxOccy[i][1] > bx)
0313       nBxOccy[i][1] = bx;
0314     //max
0315     if (nBxDiff[i][2] < bxDiff)
0316       nBxDiff[i][2] = bxDiff;
0317     if (nBxOccy[i][2] < bx)
0318       nBxOccy[i][2] = bx;
0319 
0320     if (verbose())
0321       std::cout << " fed:" << i << " bx:" << bx << " bxRef:" << bxRef << " diff:" << bxDiff << " nBxDiff"
0322                 << " del:" << nBxDiff[i][0] << " min:" << nBxDiff[i][1] << " max:" << nBxDiff[i][2] << " nBxOccy"
0323                 << " del:" << nBxOccy[i][0] << " min:" << nBxOccy[i][1] << " max:" << nBxOccy[i][2] << "\n"
0324                 << std::flush;
0325 
0326     hBxDiffAllFed->Fill(i, bxDiff);
0327 
0328     //if(ttype==1) //skip if not a physics trigger
0329     hBxOccyAllFed->Fill(bx);
0330 
0331     // done if running in filter farm
0332     if (runInFF_)
0333       continue;
0334 
0335     for (int j = 0; j < NSYS; j++)
0336       if (i >= fedRange_[j].first && i <= fedRange_[j].second)
0337         hBxDiffSysFed[j]->Fill(i, bxDiff);
0338 
0339     for (size_t k = 0; k != listGtBits_.size(); k++) {
0340       if ((int)gtbits.size() <= listGtBits_.at(k)) {
0341         if (verbose())
0342           std::cout << "BxTiming analyze | problem with vector size!\n" << std::endl;
0343         continue;
0344       } else if (!gtbits.at(listGtBits_.at(k)))
0345         continue;
0346       for (int j = 0; j < NSYS; j++) {
0347         if (i >= fedRange_[j].first && i <= fedRange_[j].second) {
0348           hBxOccyTrigBit[j][k]->Fill(bx);
0349         }
0350       }
0351     }
0352 
0353     if (i >= fedRange_[GLT].first && i <= fedRange_[GLT].second)  //GT fed
0354       if (ttype < nttype_)
0355         hBxOccyGtTrigType[ttype - 1]->Fill(bx);
0356 
0357     if (ttype != 1)
0358       continue;  //skip if not a physics trigger
0359     //hBxOccyAllFed->Fill(bx);
0360     hBxOccyOneFed[i]->Fill(bx);
0361   }
0362 
0363   for (int i = 0; i < nfed_; i++) {
0364     nBxDiff[i][0] = nBxDiff[i][2] - nBxDiff[i][1];
0365     nBxOccy[i][0] = nBxOccy[i][2] - nBxOccy[i][1];
0366     if (nBxDiff[i][0] < 0 || nBxOccy[i][0] < 0)
0367       continue;
0368     for (int j = 0; j < nspr_; j++) {
0369       hBxDiffAllFedSpread[j]->setBinContent(i, nBxDiff[i][j]);
0370       hBxOccyAllFedSpread[j]->setBinContent(i, nBxOccy[i][j]);
0371     }
0372     if (verbose())
0373       std::cout << "BxTiming fed:" << i << " Bx-Bx(" << fedRef_ << ")::"
0374                 << " del:" << nBxDiff[i][0] << " min:" << nBxDiff[i][1] << " max:" << nBxDiff[i][2] << " Occy: "
0375                 << " del:" << nBxOccy[i][0] << " min:" << nBxOccy[i][1] << " max:" << nBxOccy[i][2] << "\n"
0376                 << std::flush;
0377   }
0378 
0379   if (verbose())
0380     std::cout << "BxTiming::analyze() end.\n" << std::flush;
0381 }
0382 
0383 //----------------------------------------------------------------------
0384 
0385 int BxTiming::calcBxDiff(int bx1, int bx2) {
0386   int diff = bx1 - bx2;
0387 
0388   while (diff < -half_norb_)
0389     diff += norb_;
0390 
0391   while (diff > half_norb_)
0392     diff -= norb_;
0393 
0394   return diff;
0395 }
0396 
0397 //----------------------------------------------------------------------