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
37  usesResource("DQMStore");
39  assert(dbe_ != nullptr); // blammo!
41 
43  dbe_->book1D("algo_cur_rate", "current lumi section rate per Algo Bits", MAX_ALGOS, -0.5, MAX_ALGOS - 0.5);
44 
46  dbe_->book1D("tt_cur_rate", "current lumi section rate per Tech. Trig.s", MAX_TT, -0.5, MAX_TT - 0.5);
47  // ----------------------
48  numSelected_ = algoSelected_.size() + techSelected_.size();
49  selected_ = dbe_->book1D("l1BitsSel",
50  "Selected L1 Algorithm"
51  " and tech Bits",
53  -0.5,
54  numSelected_ - 0.5);
56  "l1BitsBxSel", "Selected L1 Algorithm Bits vs Bx", 3600, -0.5, 3599.5, numSelected_, -0.5, numSelected_ - 0.5);
57  int j = 1;
58  for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
59  char title[256];
60  snprintf(title, 256, "Algo %d", algoSelected_[i]);
63  ++j;
64  }
65  for (unsigned int i = 0; i < techSelected_.size(); ++i) {
66  char title[256];
67  snprintf(title, 256, "Tech %d", techSelected_[i]);
70  ++j;
71  }
72 
73  // book individual bit rates vs lumi for algo bits.
74  totalAlgoRate_ = dbe_->book1D("totAlgoRate", "Total Algo Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
75  totalTtRate_ = dbe_->book1D("totTtRate", "Total Tech Rate", MAX_LUMI_SEG, -0.5, MAX_LUMI_SEG - 0.5);
76 
77  totAlgoPrevCount = 0UL;
78  totTtPrevCount = 0UL;
79 
80  std::string algodir = "/AlgoRates";
81  dbe_->setCurrentFolder(folderName_ + algodir);
82 
83  for (int i = 0; i < MAX_ALGOS; ++i) {
84  l1AlgoScalerCounters_[i] = 0UL;
85  l1AlgoRateHistories_[i] = nullptr; // not really needed but ...
86  char name[256];
87  snprintf(name, 256, "rate_algobit%03d", i);
88  LogDebug("Parameter") << "name " << i << " is " << name;
90  }
91 
92  // book individual bit rates vs lumi for technical trigger bits.
93 
94  std::string techdir = "/TechRates";
95  dbe_->setCurrentFolder(folderName_ + techdir);
96 
97  for (int i = 0; i < MAX_TT; ++i) {
99  l1TechTrigRateHistories_[i] = nullptr; // not really needed but ...
100  char name[256];
101  snprintf(name, 256, "rate_ttbit%03d", i);
102  LogDebug("Parameter") << "name " << i << " is " << name;
104  }
105 
106  // split l1 scalers up into groups of 20, assuming total of 140 bits
107  std::string algodir2 = "/AlgoBits";
108  dbe_->setCurrentFolder(folderName_ + algodir2);
109 
110  char metitle1[64]; // histo name
111  char mename1[64]; // ME name
112  for (int k = 0; k < kNumAlgoHistos; k++) {
113  int npath_low = kPerHisto * k;
114  int npath_high = kPerHisto * (k + 1) - 1;
115  snprintf(mename1, 64, "L1AlgoBits_%0d", k);
116  snprintf(metitle1, 64, "L1 rates - Algo Bits %d to %d", npath_low, npath_high);
117  l1AlgoCurrentRatePerAlgo_[k] = dbe_->book1D(mename1, metitle1, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
118  }
119 
120  // split l1 scalers up into groups of 20, assuming total of 80 technical bits
121 
122  std::string techdir2 = "/TechBits";
123  dbe_->setCurrentFolder(folderName_ + techdir2);
124 
125  char metitle2[64]; // histo name
126  char mename2[64]; // ME name
127  for (int k = 0; k < kNumTTHistos; k++) {
128  int npath_low = kPerHisto * k;
129  int npath_high = kPerHisto * (k + 1) - 1;
130  snprintf(mename2, 64, "L1TechBits_%0d", k);
131  snprintf(metitle2, 64, "L1 rates - Tech. Trig. Bits %d to %d", npath_low, npath_high);
132  l1TechTrigCurrentRatePerAlgo_[k] = dbe_->book1D(mename2, metitle2, kPerHisto, -0.5 + npath_low, npath_high + 0.5);
133  }
134 
135  std::ostringstream params;
136  params << "Algo: ";
137  for (unsigned int i = 0; i < algoSelected_.size(); ++i) {
138  params << algoSelected_[i] << " ";
139  }
140  params << ", Tech: ";
141  for (unsigned int i = 0; i < techSelected_.size(); ++i) {
142  params << techSelected_[i] << " ";
143  }
144  LogDebug("Parameter") << "L1 bits to monitor are " << params.str();
145 }
146 
149  LogDebug("Status") << "beingJob";
150  if (dbe_) {
152  }
153 }
154 
157 
160 
164  nLumi_ = lumiSeg.id().luminosityBlock();
165 
166  // get EvF data
167 
168  MonitorElement *algoScalers = dbe_->get(folderName_ + std::string("/l1AlgoBits"));
169  MonitorElement *ttScalers = dbe_->get(folderName_ + std::string("/l1TechBits"));
170 
171  if (algoScalers == nullptr || ttScalers == nullptr) {
172  LogInfo("Status") << "cannot get l1 scalers histogram, bailing out.";
173  return;
174  }
175 
176  int nalgobits = algoScalers->getNbinsX();
177  int nttbits = ttScalers->getNbinsX();
178 
179  if (nalgobits > MAX_ALGOS)
180  nalgobits = MAX_ALGOS; // HARD CODE FOR NOW
181  if (nttbits > MAX_TT)
182  nttbits = MAX_TT; // HARD CODE FOR NOW
183 
184  LogDebug("Status") << "I see " << nalgobits << " algo paths. ";
185  LogDebug("Status") << "I see " << nttbits << " tt paths. ";
186 
187  // set the bin labels on the first go-through
188  if (first_algo) {
189  for (int i = 0; i < nalgobits; ++i) {
190  int whichHisto = i / kPerHisto;
191  int whichBin = i % kPerHisto + 1;
192  char pname[256];
193  snprintf(pname, 256, "AlgoBit%03d", i);
194  l1AlgoCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
195  snprintf(pname, 256, "Rate - Algorithm Bit %03d", i);
197  }
198  first_algo = false;
199  }
200 
201  // set the bin labels on the first go-through
202  if (first_tt) {
203  for (int i = 0; i < nttbits; ++i) {
204  int whichHisto = i / kPerHisto;
205  int whichBin = i % kPerHisto + 1;
206  char pname[256];
207  snprintf(pname, 256, "TechBit%03d", i);
208  l1TechTrigCurrentRatePerAlgo_[whichHisto]->setBinLabel(whichBin, pname);
209  snprintf(pname, 256, "Rate - Technical Bit %03d", i);
211  }
212  first_tt = false;
213  }
214 
215  MonitorElement *nLumi = dbe_->get(folderName_ + std::string("nLumiBlock"));
216 
217  int testval = (nLumi != nullptr ? nLumi->getIntValue() : -1);
218  LogDebug("Parameter") << "Lumi Block from DQM: " << testval << ", local is " << nLumi_;
219 
220  int nL = (nLumi != nullptr ? nLumi->getIntValue() : nLumi_);
221  if (nL > MAX_LUMI_SEG) {
222  LogDebug("Status") << "Too many Lumi segments, " << nL << " is greater than MAX_LUMI_SEG,"
223  << " wrapping to " << (nL % MAX_LUMI_SEG);
224  nL = nL % MAX_LUMI_SEG;
225  }
226  float delta_t = (nL - currentLumiBlockNumber_) * SECS_PER_LUMI_SECTION;
227  if (delta_t < 0) {
228  LogDebug("Status") << " time is negative ... " << delta_t;
229  delta_t = -delta_t;
230  } else if (nL == currentLumiBlockNumber_) { // divide-by-zero
231  LogInfo("Status") << "divide by zero: same lumi section 2x " << nL;
232  return;
233  }
234  // selected --------------------- fill in the rates for th
235  int currSlot = 1; // for selected bits histogram
236  MonitorElement *algoBx = dbe_->get(folderName_ + std::string("/l1AlgoBits_Vs_Bx"));
237  // selected --------------------- end
238  for (int i = 1; i <= nalgobits; ++i) { // bins start at 1
239  float current_count = algoScalers->getBinContent(i);
240  // selected -------------------- start
241  int bit = i - 1; //
242  if (std::find(algoSelected_.begin(), algoSelected_.end(), bit) != algoSelected_.end()) {
243  selected_->setBinContent(currSlot, current_count);
244  if (algoBx) {
245  for (int j = 1; j <= 3600; ++j) {
246  bxSelected_->setBinContent(j, currSlot, algoBx->getBinContent(j, i));
247  }
248  }
249  ++currSlot;
250  }
251  // selected -------------------- end
252  float rate = (current_count - l1AlgoScalerCounters_[i - 1]) / delta_t;
253  if (rate > 1E-3) {
254  LogDebug("Parameter") << "rate path " << i << " is " << rate;
255  }
258  // currentRate_->setBinError(i, error);
259  l1AlgoScalerCounters_[i - 1] = (unsigned long)(current_count);
261  }
262  // selected ----------------- start
263  MonitorElement *techBx = dbe_->get(folderName_ + std::string("/l1TechBits_Vs_Bx"));
264  // selected ----------------- end
265 
266  for (int i = 1; i <= nttbits; ++i) { // bins start at 1
267  float current_count = ttScalers->getBinContent(i);
268  // selected -------------------- start
269  int bit = i - 1; //
270  if (std::find(techSelected_.begin(), techSelected_.end(), bit) != techSelected_.end()) {
271  selected_->setBinContent(currSlot, current_count);
272  if (techBx) {
273  for (int j = 1; j <= 3600; ++j) {
274  bxSelected_->setBinContent(j, currSlot, techBx->getBinContent(j, i));
275  }
276  }
277  ++currSlot;
278  }
279  // selected -------------------- end
280  float rate = (current_count - l1TechTrigScalerCounters_[i - 1]) / delta_t;
281  if (rate > 1E-3) {
282  LogDebug("Parameter") << "rate path " << i << " is " << rate;
283  }
286  // currentRate_->setBinError(i, error);
287  l1TechTrigScalerCounters_[i - 1] = (unsigned long)(current_count);
289  }
290 
291  // compute total rate
292  MonitorElement *l1AlgoCounter = dbe_->get(folderName_ + std::string("/l1AlgoCounter"));
293  MonitorElement *l1TtCounter = dbe_->get(folderName_ + std::string("/l1TtCounter"));
294  if (l1AlgoCounter != nullptr && l1TtCounter != nullptr) {
295  float totAlgoCount = l1AlgoCounter->getIntValue();
296  float totTtCount = l1TtCounter->getIntValue();
297  float totAlgRate = (totAlgoCount - totAlgoPrevCount) / delta_t;
298  float totTtRate = (totTtCount - totTtPrevCount) / delta_t;
299  totalAlgoRate_->setBinContent(nL, totAlgRate);
300  totAlgoPrevCount = totAlgoCount;
301  totalTtRate_->setBinContent(nL, totTtRate);
302  totTtPrevCount = totTtCount;
303  }
304 
306 }
307 
308 // 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:647
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:712
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