File indexing completed on 2021-02-14 13:12:27
0001 #include <cassert>
0002 #include <sstream>
0003
0004 #include "DQM/TrigXMonitorClient/interface/L1ScalersClient.h"
0005
0006 #include "FWCore/Framework/interface/LuminosityBlock.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ServiceRegistry/interface/Service.h"
0010
0011 #include "DQMServices/Core/interface/DQMStore.h"
0012
0013 using edm::LogInfo;
0014 using edm::LogWarning;
0015
0016 #define SECS_PER_LUMI_SECTION 23.31040958083832;
0017 const int kPerHisto = 20;
0018 const int kNumAlgoHistos = MAX_ALGOS / kPerHisto;
0019 const int kNumTTHistos = MAX_TT / kPerHisto;
0020
0021
0022 L1ScalersClient::L1ScalersClient(const edm::ParameterSet &ps)
0023 : dbe_(nullptr),
0024 nLumi_(0),
0025 l1AlgoCurrentRate_(nullptr),
0026 l1TechTrigCurrentRate_(nullptr),
0027 selected_(nullptr),
0028 bxSelected_(nullptr),
0029 algoSelected_(ps.getUntrackedParameter<std::vector<int>>("algoMonitorBits", std::vector<int>())),
0030 techSelected_(ps.getUntrackedParameter<std::vector<int>>("techMonitorBits", std::vector<int>())),
0031 folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", "L1T/L1Scalers_EvF")),
0032 currentLumiBlockNumber_(0),
0033 first_algo(true),
0034 first_tt(true) {
0035 LogDebug("Status") << "constructor";
0036
0037 dbe_ = edm::Service<DQMStore>().operator->();
0038 assert(dbe_ != nullptr);
0039 dbe_->setCurrentFolder(folderName_);
0040
0041 l1AlgoCurrentRate_ =
0042 dbe_->book1D("algo_cur_rate", "current lumi section rate per Algo Bits", MAX_ALGOS, -0.5, MAX_ALGOS - 0.5);
0043
0044 l1TechTrigCurrentRate_ =
0045 dbe_->book1D("tt_cur_rate", "current lumi section rate per Tech. Trig.s", MAX_TT, -0.5, MAX_TT - 0.5);
0046
0047 numSelected_ = algoSelected_.size() + techSelected_.size();
0048 selected_ = dbe_->book1D("l1BitsSel",
0049 "Selected L1 Algorithm"
0050 " and tech Bits",
0051 numSelected_,
0052 -0.5,
0053 numSelected_ - 0.5);
0054 bxSelected_ = dbe_->book2D(
0055 "l1BitsBxSel", "Selected L1 Algorithm Bits vs Bx", 3600, -0.5, 3599.5, numSelected_, -0.5, numSelected_ - 0.5);
0056 int j = 1;
0057 for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
0058 char title[256];
0059 snprintf(title, 256, "Algo %d", algoSelected_[i]);
0060 selected_->setBinLabel(j, title);
0061 bxSelected_->setBinLabel(j, title, 2);
0062 ++j;
0063 }
0064 for (unsigned int i = 0; i < techSelected_.size(); ++i) {
0065 char title[256];
0066 snprintf(title, 256, "Tech %d", techSelected_[i]);
0067 selected_->setBinLabel(j, title);
0068 bxSelected_->setBinLabel(j, title, 2);
0069 ++j;
0070 }
0071
0072
0073 totalAlgoRate_ = dbe_->book1D("totAlgoRate", "Total Algo Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
0074 totalTtRate_ = dbe_->book1D("totTtRate", "Total Tech Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
0075
0076 totAlgoPrevCount = 0UL;
0077 totTtPrevCount = 0UL;
0078
0079 std::string algodir = "/AlgoRates";
0080 dbe_->setCurrentFolder(folderName_ + algodir);
0081
0082 for (int i = 0; i < MAX_ALGOS; ++i) {
0083 l1AlgoScalerCounters_[i] = 0UL;
0084 l1AlgoRateHistories_[i] = nullptr;
0085 char name[256];
0086 snprintf(name, 256, "rate_algobit%03d", i);
0087 LogDebug("Parameter") << "name " << i << " is " << name;
0088 l1AlgoRateHistories_[i] = dbe_->book1D(name, name, MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
0089 }
0090
0091
0092
0093 std::string techdir = "/TechRates";
0094 dbe_->setCurrentFolder(folderName_ + techdir);
0095
0096 for (int i = 0; i < MAX_TT; ++i) {
0097 l1TechTrigScalerCounters_[i] = 0UL;
0098 l1TechTrigRateHistories_[i] = nullptr;
0099 char name[256];
0100 snprintf(name, 256, "rate_ttbit%03d", i);
0101 LogDebug("Parameter") << "name " << i << " is " << name;
0102 l1TechTrigRateHistories_[i] = dbe_->book1D(name, name, MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
0103 }
0104
0105
0106 std::string algodir2 = "/AlgoBits";
0107 dbe_->setCurrentFolder(folderName_ + algodir2);
0108
0109 char metitle1[64];
0110 char mename1[64];
0111 for (int k = 0; k < kNumAlgoHistos; k++) {
0112 int npath_low = kPerHisto * k;
0113 int npath_high = kPerHisto * (k + 1) - 1;
0114 snprintf(mename1, 64, "L1AlgoBits_%0d", k);
0115 snprintf(metitle1, 64, "L1 rates - Algo Bits %d to %d", npath_low, npath_high);
0116 l1AlgoCurrentRatePerAlgo_[k] = dbe_->book1D(mename1, metitle1, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
0117 }
0118
0119
0120
0121 std::string techdir2 = "/TechBits";
0122 dbe_->setCurrentFolder(folderName_ + techdir2);
0123
0124 char metitle2[64];
0125 char mename2[64];
0126 for (int k = 0; k < kNumTTHistos; k++) {
0127 int npath_low = kPerHisto * k;
0128 int npath_high = kPerHisto * (k + 1) - 1;
0129 snprintf(mename2, 64, "L1TechBits_%0d", k);
0130 snprintf(metitle2, 64, "L1 rates - Tech. Trig. Bits %d to %d", npath_low, npath_high);
0131 l1TechTrigCurrentRatePerAlgo_[k] = dbe_->book1D(mename2, metitle2, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
0132 }
0133
0134 std::ostringstream params;
0135 params << "Algo: ";
0136 for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
0137 params << algoSelected_[i] << " ";
0138 }
0139 params << ", Tech: ";
0140 for (unsigned int i = 0; i < techSelected_.size(); ++i) {
0141 params << techSelected_[i] << " ";
0142 }
0143 LogDebug("Parameter") << "L1 bits to monitor are " << params.str();
0144 }
0145
0146
0147 void L1ScalersClient::beginJob(void) {
0148 LogDebug("Status") << "beingJob";
0149 if (dbe_) {
0150 dbe_->setCurrentFolder(folderName_);
0151 }
0152 }
0153
0154
0155 void L1ScalersClient::beginRun(const edm::Run &run, const edm::EventSetup &c) {}
0156
0157
0158 void L1ScalersClient::endRun(const edm::Run &run, const edm::EventSetup &c) {}
0159
0160
0161
0162 void L1ScalersClient::endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) {
0163 nLumi_ = lumiSeg.id().luminosityBlock();
0164
0165
0166
0167 MonitorElement *algoScalers = dbe_->get(folderName_ + std::string("/l1AlgoBits"));
0168 MonitorElement *ttScalers = dbe_->get(folderName_ + std::string("/l1TechBits"));
0169
0170 if (algoScalers == nullptr || ttScalers == nullptr) {
0171 LogInfo("Status") << "cannot get l1 scalers histogram, bailing out.";
0172 return;
0173 }
0174
0175 int nalgobits = algoScalers->getNbinsX();
0176 int nttbits = ttScalers->getNbinsX();
0177
0178 if (nalgobits > MAX_ALGOS)
0179 nalgobits = MAX_ALGOS;
0180 if (nttbits > MAX_TT)
0181 nttbits = MAX_TT;
0182
0183 LogDebug("Status") << "I see " << nalgobits << " algo paths. ";
0184 LogDebug("Status") << "I see " << nttbits << " tt paths. ";
0185
0186
0187 if (first_algo) {
0188 for (int i = 0; i < nalgobits; ++i) {
0189 int whichHisto = i / kPerHisto;
0190 int whichBin = i % kPerHisto + 1;
0191 char pname[256];
0192 snprintf(pname, 256, "AlgoBit%03d", i);
0193 l1AlgoCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
0194 snprintf(pname, 256, "Rate - Algorithm Bit %03d", i);
0195 l1AlgoRateHistories_[i]->setTitle(pname);
0196 }
0197 first_algo = false;
0198 }
0199
0200
0201 if (first_tt) {
0202 for (int i = 0; i < nttbits; ++i) {
0203 int whichHisto = i / kPerHisto;
0204 int whichBin = i % kPerHisto + 1;
0205 char pname[256];
0206 snprintf(pname, 256, "TechBit%03d", i);
0207 l1TechTrigCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
0208 snprintf(pname, 256, "Rate - Technical Bit %03d", i);
0209 l1TechTrigRateHistories_[i]->setTitle(pname);
0210 }
0211 first_tt = false;
0212 }
0213
0214 MonitorElement *nLumi = dbe_->get(folderName_ + std::string("nLumiBlock"));
0215
0216 int testval = (nLumi != nullptr ? nLumi->getIntValue() : -1);
0217 LogDebug("Parameter") << "Lumi Block from DQM: " << testval << ", local is " << nLumi_;
0218
0219 int nL = (nLumi != nullptr ? nLumi->getIntValue() : nLumi_);
0220 if (nL > MAX_LUMI_SEG) {
0221 LogDebug("Status") << "Too many Lumi segments, " << nL << " is greater than MAX_LUMI_SEG,"
0222 << " wrapping to " << (nL % MAX_LUMI_SEG);
0223 nL = nL % MAX_LUMI_SEG;
0224 }
0225 float delta_t = (nL - currentLumiBlockNumber_) * SECS_PER_LUMI_SECTION;
0226 if (delta_t < 0) {
0227 LogDebug("Status") << " time is negative ... " << delta_t;
0228 delta_t = -delta_t;
0229 } else if (nL == currentLumiBlockNumber_) {
0230 LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
0231 return;
0232 }
0233
0234 int currSlot = 1;
0235 MonitorElement *algoBx = dbe_->get(folderName_ + std::string("/l1AlgoBits_Vs_Bx"));
0236
0237 for (int i = 1; i <= nalgobits; ++i) {
0238 float current_count = algoScalers->getBinContent(i);
0239
0240 int bit = i - 1;
0241 if (std::find(algoSelected_.begin(), algoSelected_.end(), bit) != algoSelected_.end()) {
0242 selected_->setBinContent(currSlot, current_count);
0243 if (algoBx) {
0244 for (int j = 1; j <= 3600; ++j) {
0245 bxSelected_->setBinContent(j, currSlot, algoBx->getBinContent(j, i));
0246 }
0247 }
0248 ++currSlot;
0249 }
0250
0251 float rate = (current_count - l1AlgoScalerCounters_[i - 1]) / delta_t;
0252 if (rate > 1E-3) {
0253 LogDebug("Parameter") << "rate path " << i << " is " << rate;
0254 }
0255 l1AlgoCurrentRate_->setBinContent(i, rate);
0256 l1AlgoCurrentRatePerAlgo_[i / kPerHisto]->setBinContent(i % kPerHisto, rate);
0257
0258 l1AlgoScalerCounters_[i - 1] = (unsigned long)(current_count);
0259 l1AlgoRateHistories_[i - 1]->setBinContent(nL, rate);
0260 }
0261
0262 MonitorElement *techBx = dbe_->get(folderName_ + std::string("/l1TechBits_Vs_Bx"));
0263
0264
0265 for (int i = 1; i <= nttbits; ++i) {
0266 float current_count = ttScalers->getBinContent(i);
0267
0268 int bit = i - 1;
0269 if (std::find(techSelected_.begin(), techSelected_.end(), bit) != techSelected_.end()) {
0270 selected_->setBinContent(currSlot, current_count);
0271 if (techBx) {
0272 for (int j = 1; j <= 3600; ++j) {
0273 bxSelected_->setBinContent(j, currSlot, techBx->getBinContent(j, i));
0274 }
0275 }
0276 ++currSlot;
0277 }
0278
0279 float rate = (current_count - l1TechTrigScalerCounters_[i - 1]) / delta_t;
0280 if (rate > 1E-3) {
0281 LogDebug("Parameter") << "rate path " << i << " is " << rate;
0282 }
0283 l1TechTrigCurrentRate_->setBinContent(i, rate);
0284 l1TechTrigCurrentRatePerAlgo_[i / kPerHisto]->setBinContent(i % kPerHisto, rate);
0285
0286 l1TechTrigScalerCounters_[i - 1] = (unsigned long)(current_count);
0287 l1TechTrigRateHistories_[i - 1]->setBinContent(nL, rate);
0288 }
0289
0290
0291 MonitorElement *l1AlgoCounter = dbe_->get(folderName_ + std::string("/l1AlgoCounter"));
0292 MonitorElement *l1TtCounter = dbe_->get(folderName_ + std::string("/l1TtCounter"));
0293 if (l1AlgoCounter != nullptr && l1TtCounter != nullptr) {
0294 float totAlgoCount = l1AlgoCounter->getIntValue();
0295 float totTtCount = l1TtCounter->getIntValue();
0296 float totAlgRate = (totAlgoCount - totAlgoPrevCount) / delta_t;
0297 float totTtRate = (totTtCount - totTtPrevCount) / delta_t;
0298 totalAlgoRate_->setBinContent(nL, totAlgRate);
0299 totAlgoPrevCount = totAlgoCount;
0300 totalTtRate_->setBinContent(nL, totTtRate);
0301 totTtPrevCount = totTtCount;
0302 }
0303
0304 currentLumiBlockNumber_ = nL;
0305 }
0306
0307
0308 void L1ScalersClient::analyze(const edm::Event &e, const edm::EventSetup &c) {}