CMS 3D CMS Logo

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