CMS 3D CMS Logo

L1ScalersClient.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <sstream>
3 
5 
10 
12 
13 using edm::LogInfo;
14 using edm::LogWarning;
15 
16 #define SECS_PER_LUMI_SECTION 23.31040958083832;
17 const int kPerHisto = 20;
18 const int kNumAlgoHistos = MAX_ALGOS / kPerHisto; // this hasta be w/o remainders
19 const int kNumTTHistos = MAX_TT / kPerHisto; // this hasta be w/o remainders
20 
23  : dbe_(nullptr),
24  nLumi_(0),
25  l1AlgoCurrentRate_(nullptr),
26  l1TechTrigCurrentRate_(nullptr),
27  selected_(nullptr),
28  bxSelected_(nullptr),
29  algoSelected_(ps.getUntrackedParameter<std::vector<int>>("algoMonitorBits", std::vector<int>())),
30  techSelected_(ps.getUntrackedParameter<std::vector<int>>("techMonitorBits", std::vector<int>())),
31  folderName_(ps.getUntrackedParameter<std::string>("dqmFolder", "L1T/L1Scalers_EvF")),
32  currentLumiBlockNumber_(0),
33  first_algo(true),
34  first_tt(true) {
35  LogDebug("Status") << "constructor";
36  // get back-end interface
38  assert(dbe_ != nullptr); // blammo!
40 
42  dbe_->book1D("algo_cur_rate", "current lumi section rate per Algo Bits", MAX_ALGOS, -0.5, MAX_ALGOS - 0.5);
43 
45  dbe_->book1D("tt_cur_rate", "current lumi section rate per Tech. Trig.s", MAX_TT, -0.5, MAX_TT - 0.5);
46  // ----------------------
47  numSelected_ = algoSelected_.size() + techSelected_.size();
48  selected_ = dbe_->book1D("l1BitsSel",
49  "Selected L1 Algorithm"
50  " and tech Bits",
52  -0.5,
53  numSelected_ - 0.5);
55  "l1BitsBxSel", "Selected L1 Algorithm Bits vs Bx", 3600, -0.5, 3599.5, numSelected_, -0.5, numSelected_ - 0.5);
56  int j = 1;
57  for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
58  char title[256];
59  snprintf(title, 256, "Algo %d", algoSelected_[i]);
62  ++j;
63  }
64  for (unsigned int i = 0; i < techSelected_.size(); ++i) {
65  char title[256];
66  snprintf(title, 256, "Tech %d", techSelected_[i]);
69  ++j;
70  }
71 
72  // book individual bit rates vs lumi for algo bits.
73  totalAlgoRate_ = dbe_->book1D("totAlgoRate", "Total Algo Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
74  totalTtRate_ = dbe_->book1D("totTtRate", "Total Tech Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
75 
76  totAlgoPrevCount = 0UL;
77  totTtPrevCount = 0UL;
78 
79  std::string algodir = "/AlgoRates";
80  dbe_->setCurrentFolder(folderName_ + algodir);
81 
82  for (int i = 0; i < MAX_ALGOS; ++i) {
83  l1AlgoScalerCounters_[i] = 0UL;
84  l1AlgoRateHistories_[i] = nullptr; // not really needed but ...
85  char name[256];
86  snprintf(name, 256, "rate_algobit%03d", i);
87  LogDebug("Parameter") << "name " << i << " is " << name;
89  }
90 
91  // book individual bit rates vs lumi for technical trigger bits.
92 
93  std::string techdir = "/TechRates";
94  dbe_->setCurrentFolder(folderName_ + techdir);
95 
96  for (int i = 0; i < MAX_TT; ++i) {
98  l1TechTrigRateHistories_[i] = nullptr; // not really needed but ...
99  char name[256];
100  snprintf(name, 256, "rate_ttbit%03d", i);
101  LogDebug("Parameter") << "name " << i << " is " << name;
103  }
104 
105  // split l1 scalers up into groups of 20, assuming total of 140 bits
106  std::string algodir2 = "/AlgoBits";
107  dbe_->setCurrentFolder(folderName_ + algodir2);
108 
109  char metitle1[64]; // histo name
110  char mename1[64]; // ME name
111  for (int k = 0; k < kNumAlgoHistos; k++) {
112  int npath_low = kPerHisto * k;
113  int npath_high = kPerHisto * (k + 1) - 1;
114  snprintf(mename1, 64, "L1AlgoBits_%0d", k);
115  snprintf(metitle1, 64, "L1 rates - Algo Bits %d to %d", npath_low, npath_high);
116  l1AlgoCurrentRatePerAlgo_[k] = dbe_->book1D(mename1, metitle1, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
117  }
118 
119  // split l1 scalers up into groups of 20, assuming total of 80 technical bits
120 
121  std::string techdir2 = "/TechBits";
122  dbe_->setCurrentFolder(folderName_ + techdir2);
123 
124  char metitle2[64]; // histo name
125  char mename2[64]; // ME name
126  for (int k = 0; k < kNumTTHistos; k++) {
127  int npath_low = kPerHisto * k;
128  int npath_high = kPerHisto * (k + 1) - 1;
129  snprintf(mename2, 64, "L1TechBits_%0d", k);
130  snprintf(metitle2, 64, "L1 rates - Tech. Trig. Bits %d to %d", npath_low, npath_high);
131  l1TechTrigCurrentRatePerAlgo_[k] = dbe_->book1D(mename2, metitle2, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
132  }
133 
134  std::ostringstream params;
135  params << "Algo: ";
136  for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
137  params << algoSelected_[i] << " ";
138  }
139  params << ", Tech: ";
140  for (unsigned int i = 0; i < techSelected_.size(); ++i) {
141  params << techSelected_[i] << " ";
142  }
143  LogDebug("Parameter") << "L1 bits to monitor are " << params.str();
144 }
145 
148  LogDebug("Status") << "beingJob";
149  if (dbe_) {
151  }
152 }
153 
156 
159 
163  nLumi_ = lumiSeg.id().luminosityBlock();
164 
165  // get EvF data
166 
167  MonitorElement *algoScalers = dbe_->get(folderName_ + std::string("/l1AlgoBits"));
168  MonitorElement *ttScalers = dbe_->get(folderName_ + std::string("/l1TechBits"));
169 
170  if (algoScalers == nullptr || ttScalers == nullptr) {
171  LogInfo("Status") << "cannot get l1 scalers histogram, bailing out.";
172  return;
173  }
174 
175  int nalgobits = algoScalers->getNbinsX();
176  int nttbits = ttScalers->getNbinsX();
177 
178  if (nalgobits > MAX_ALGOS)
179  nalgobits = MAX_ALGOS; // HARD CODE FOR NOW
180  if (nttbits > MAX_TT)
181  nttbits = MAX_TT; // HARD CODE FOR NOW
182 
183  LogDebug("Status") << "I see " << nalgobits << " algo paths. ";
184  LogDebug("Status") << "I see " << nttbits << " tt paths. ";
185 
186  // set the bin labels on the first go-through
187  if (first_algo) {
188  for (int i = 0; i < nalgobits; ++i) {
189  int whichHisto = i / kPerHisto;
190  int whichBin = i % kPerHisto + 1;
191  char pname[256];
192  snprintf(pname, 256, "AlgoBit%03d", i);
193  l1AlgoCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
194  snprintf(pname, 256, "Rate - Algorithm Bit %03d", i);
196  }
197  first_algo = false;
198  }
199 
200  // set the bin labels on the first go-through
201  if (first_tt) {
202  for (int i = 0; i < nttbits; ++i) {
203  int whichHisto = i / kPerHisto;
204  int whichBin = i % kPerHisto + 1;
205  char pname[256];
206  snprintf(pname, 256, "TechBit%03d", i);
207  l1TechTrigCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
208  snprintf(pname, 256, "Rate - Technical Bit %03d", i);
210  }
211  first_tt = false;
212  }
213 
214  MonitorElement *nLumi = dbe_->get(folderName_ + std::string("nLumiBlock"));
215 
216  int testval = (nLumi != nullptr ? nLumi->getIntValue() : -1);
217  LogDebug("Parameter") << "Lumi Block from DQM: " << testval << ", local is " << nLumi_;
218 
219  int nL = (nLumi != nullptr ? nLumi->getIntValue() : nLumi_);
220  if (nL > MAX_LUMI_SEG) {
221  LogDebug("Status") << "Too many Lumi segments, " << nL << " is greater than MAX_LUMI_SEG,"
222  << " wrapping to " << (nL % MAX_LUMI_SEG);
223  nL = nL % MAX_LUMI_SEG;
224  }
225  float delta_t = (nL - currentLumiBlockNumber_) * SECS_PER_LUMI_SECTION;
226  if (delta_t < 0) {
227  LogDebug("Status") << " time is negative ... " << delta_t;
228  delta_t = -delta_t;
229  } else if (nL == currentLumiBlockNumber_) { // divide-by-zero
230  LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
231  return;
232  }
233  // selected --------------------- fill in the rates for th
234  int currSlot = 1; // for selected bits histogram
235  MonitorElement *algoBx = dbe_->get(folderName_ + std::string("/l1AlgoBits_Vs_Bx"));
236  // selected --------------------- end
237  for (int i = 1; i <= nalgobits; ++i) { // bins start at 1
238  float current_count = algoScalers->getBinContent(i);
239  // selected -------------------- start
240  int bit = i - 1; //
241  if (std::find(algoSelected_.begin(), algoSelected_.end(), bit) != algoSelected_.end()) {
242  selected_->setBinContent(currSlot, current_count);
243  if (algoBx) {
244  for (int j = 1; j <= 3600; ++j) {
245  bxSelected_->setBinContent(j, currSlot, algoBx->getBinContent(j, i));
246  }
247  }
248  ++currSlot;
249  }
250  // selected -------------------- end
251  float rate = (current_count - l1AlgoScalerCounters_[i - 1]) / delta_t;
252  if (rate > 1E-3) {
253  LogDebug("Parameter") << "rate path " << i << " is " << rate;
254  }
257  // currentRate_->setBinError(i, error);
258  l1AlgoScalerCounters_[i - 1] = (unsigned long)(current_count);
260  }
261  // selected ----------------- start
262  MonitorElement *techBx = dbe_->get(folderName_ + std::string("/l1TechBits_Vs_Bx"));
263  // selected ----------------- end
264 
265  for (int i = 1; i <= nttbits; ++i) { // bins start at 1
266  float current_count = ttScalers->getBinContent(i);
267  // selected -------------------- start
268  int bit = i - 1; //
269  if (std::find(techSelected_.begin(), techSelected_.end(), bit) != techSelected_.end()) {
270  selected_->setBinContent(currSlot, current_count);
271  if (techBx) {
272  for (int j = 1; j <= 3600; ++j) {
273  bxSelected_->setBinContent(j, currSlot, techBx->getBinContent(j, i));
274  }
275  }
276  ++currSlot;
277  }
278  // selected -------------------- end
279  float rate = (current_count - l1TechTrigScalerCounters_[i - 1]) / delta_t;
280  if (rate > 1E-3) {
281  LogDebug("Parameter") << "rate path " << i << " is " << rate;
282  }
285  // currentRate_->setBinError(i, error);
286  l1TechTrigScalerCounters_[i - 1] = (unsigned long)(current_count);
288  }
289 
290  // compute total rate
291  MonitorElement *l1AlgoCounter = dbe_->get(folderName_ + std::string("/l1AlgoCounter"));
292  MonitorElement *l1TtCounter = dbe_->get(folderName_ + std::string("/l1TtCounter"));
293  if (l1AlgoCounter != nullptr && l1TtCounter != nullptr) {
294  float totAlgoCount = l1AlgoCounter->getIntValue();
295  float totTtCount = l1TtCounter->getIntValue();
296  float totAlgRate = (totAlgoCount - totAlgoPrevCount) / delta_t;
297  float totTtRate = (totTtCount - totTtPrevCount) / delta_t;
298  totalAlgoRate_->setBinContent(nL, totAlgRate);
299  totAlgoPrevCount = totAlgoCount;
300  totalTtRate_->setBinContent(nL, totTtRate);
301  totTtPrevCount = totTtCount;
302  }
303 
305 }
306 
307 // unused
virtual void setTitle(const std::string &title)
set (ie. change) histogram/profile title
LuminosityBlockNumber_t luminosityBlock() const
unsigned long int l1AlgoScalerCounters_[140]
const int kPerHisto
std::vector< int > algoSelected_
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
dqm::legacy::DQMStore * dbe_
L1ScalersClient(const edm::ParameterSet &ps)
Constructors.
MonitorElement * l1TechTrigCurrentRatePerAlgo_[80]
#define SECS_PER_LUMI_SECTION
void beginJob(void) override
BeginJob.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const int kNumAlgoHistos
assert(be >=bs)
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
const int kNumTTHistos
#define MAX_LUMI_SEG
Definition: L1Scalers.h:13
std::string folderName_
void endRun(const edm::Run &run, const edm::EventSetup &c) override
EndRun.
MonitorElement * l1AlgoCurrentRatePerAlgo_[140]
MonitorElement * l1AlgoCurrentRate_
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
BeginRun.
void analyze(const edm::Event &e, const edm::EventSetup &c) override
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
unsigned long int l1TechTrigScalerCounters_[80]
Log< level::Info, false > LogInfo
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
LuminosityBlockID id() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
std::vector< int > techSelected_
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
double rate(double x)
Definition: Constants.cc:3
MonitorElement * totalTtRate_
#define MAX_ALGOS
virtual int getNbinsX() const
get # of bins in X-axis
MonitorElement * totalAlgoRate_
MonitorElement * l1TechTrigRateHistories_[80]
MonitorElement * bxSelected_
MonitorElement * l1AlgoRateHistories_[140]
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
#define MAX_TT
Definition: Run.h:45
MonitorElement * selected_
MonitorElement * l1TechTrigCurrentRate_
#define LogDebug(id)
virtual double getBinContent(int binx) const
get content of bin (1-D)
virtual int64_t getIntValue() const