CMS 3D CMS Logo

L1GetHistLimits.cc
Go to the documentation of this file.
1 
15 // this class header
17 
18 // system include files
19 #include <iostream>
20 #include <iomanip>
21 #include <string>
22 
23 // user include files
26 
30 
33 
34 // constructor
35 L1GetHistLimits::L1GetHistLimits(const edm::EventSetup& evSetup) : m_evSetup(evSetup) {
36  //
37 }
38 
39 // destructor
41  // empty
42 }
43 
49 
50  // number of objects is independent of the object type
51  // and hardcoded in the actual version
52  if (quantity == "NrObjects") {
56 
58 
59  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
63  }
64 
65  // set last bin upper edge
67 
68  return;
69  }
70 
71  switch (l1GtObject) {
72  case Mu: {
73  if (quantity == "PT") {
75  m_evSetup.get<L1MuTriggerPtScaleRcd>().get(muPtScale);
76 
77  m_l1HistLimits.nrBins = muPtScale->getPtScale()->getNBins();
80 
82 
83  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
84  m_l1HistLimits.binThresholds[iBin] = muPtScale->getPtScale()->getValue(iBin);
85  }
86 
87  // last limit for muon is set too high (10^6) - resize the last bin
88 
90 
91  // limit the size of the last bin to maximum 200 GeV
92  float maxLaxtBinsize = 200;
93  if (lastBinSize >= maxLaxtBinsize) {
97  LogDebug("L1GetHistLimits") << "\n L1ExtraMuon: PT histogram"
98  << "\nm_l1HistLimits.upperBinValue truncated to = "
99  << m_l1HistLimits.upperBinValue << std::endl;
100  }
101 
102  // set last bin upper edge
104 
105  } else if (quantity == "eta" || quantity == "phi") {
107  m_evSetup.get<L1MuTriggerScalesRcd>().get(muScales);
108 
109  if (quantity == "eta") {
110  // eta scale defined for positive values - need to be symmetrized
111  int histNrBinsHalf = muScales->getGMTEtaScale()->getNBins();
114 
115  m_l1HistLimits.nrBins = 2 * histNrBinsHalf;
117 
119 
120  int iBin = 0;
121  for (int j = histNrBinsHalf; j > 0; j--, iBin++) {
122  m_l1HistLimits.binThresholds[iBin] = (-1) * muScales->getGMTEtaScale()->getValue(j);
123  }
124  for (int j = 0; j <= histNrBinsHalf; j++, iBin++) {
125  m_l1HistLimits.binThresholds[iBin] = muScales->getGMTEtaScale()->getValue(j);
126  }
127 
128  // set last bin upper edge
130 
131  } else {
132  m_l1HistLimits.nrBins = muScales->getPhiScale()->getNBins();
135 
137 
138  for (int iBin = 0; iBin <= m_l1HistLimits.nrBins; iBin++) {
139  m_l1HistLimits.binThresholds[iBin] = rad2deg(muScales->getPhiScale()->getValue(iBin));
140  }
141 
142  // set last bin upper edge
144  }
145  }
146 
147  } break;
148  case NoIsoEG:
149  case IsoEG: {
150  // common scales for NoIsoEG and IsoEG
151  if (quantity == "ET") {
153  m_evSetup.get<L1EmEtScaleRcd>().get(emScale);
154 
155  std::vector<double> emThresholds = emScale->getThresholds();
156  m_l1HistLimits.nrBins = emThresholds.size();
157  m_l1HistLimits.lowerBinValue = emThresholds.at(0);
158 
159  // FIXME high edge retrieval in the scale definition
160  // now, last bin has the same width like the last but one
162  emThresholds[m_l1HistLimits.nrBins - 1] +
163  (emThresholds[m_l1HistLimits.nrBins - 1] - emThresholds[m_l1HistLimits.nrBins - 2]);
164 
166 
167  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
168  m_l1HistLimits.binThresholds[iBin] = static_cast<float>(emThresholds[iBin]);
169  }
170 
171  // set last bin upper edge
173 
174  } else if (quantity == "eta" || quantity == "phi") {
175  edm::ESHandle<L1CaloGeometry> caloGeomESH;
176  m_evSetup.get<L1CaloGeometryRecord>().get(caloGeomESH);
177  const L1CaloGeometry* caloGeomScales = caloGeomESH.product();
178 
179  if (quantity == "eta") {
181  2 * (caloGeomScales->numberGctCentralEtaBinsPerHalf() + caloGeomScales->numberGctForwardEtaBinsPerHalf());
182  m_l1HistLimits.lowerBinValue = caloGeomScales->globalEtaBinLowEdge(0);
184 
186 
187  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
188  m_l1HistLimits.binThresholds[iBin] = caloGeomScales->globalEtaBinLowEdge(iBin);
189  }
190 
191  // set last bin upper edge
193 
194  } else {
195  m_l1HistLimits.nrBins = caloGeomScales->numberGctEmJetPhiBins();
197 
198  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
199  m_l1HistLimits.binThresholds[iBin] = rad2deg(caloGeomScales->emJetPhiBinLowEdge(iBin));
200 
201  // treat correctly the 10 deg anti-clockwise rotation
202  if (rad2deg(caloGeomScales->emJetPhiBinHighEdge(iBin)) < m_l1HistLimits.binThresholds[iBin]) {
204  }
205  }
206 
208 
209  // last bin upper limit
211 
213  }
214  }
215 
216  } break;
217  case CenJet:
218  case ForJet:
219  case TauJet: {
220  // common scales for all jets
221  if (quantity == "ET") {
223  m_evSetup.get<L1JetEtScaleRcd>().get(jetScale);
224 
225  std::vector<double> jetThresholds = jetScale->getThresholds();
226  m_l1HistLimits.nrBins = jetThresholds.size();
227  m_l1HistLimits.lowerBinValue = jetThresholds.at(0);
228 
229  // FIXME high edge retrieval in the scale definition
230  // now, last bin has the same width like the last but one
232  jetThresholds[m_l1HistLimits.nrBins - 1] +
233  (jetThresholds[m_l1HistLimits.nrBins - 1] - jetThresholds[m_l1HistLimits.nrBins - 2]);
234 
236 
237  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
238  m_l1HistLimits.binThresholds[iBin] = static_cast<float>(jetThresholds[iBin]);
239  }
240 
241  // set last bin upper edge
243 
244  } else if (quantity == "eta" || quantity == "phi") {
245  edm::ESHandle<L1CaloGeometry> caloGeomESH;
246  m_evSetup.get<L1CaloGeometryRecord>().get(caloGeomESH);
247  const L1CaloGeometry* caloGeomScales = caloGeomESH.product();
248 
249  if (quantity == "eta") {
251  2 * (caloGeomScales->numberGctCentralEtaBinsPerHalf() + caloGeomScales->numberGctForwardEtaBinsPerHalf());
252  m_l1HistLimits.lowerBinValue = caloGeomScales->globalEtaBinLowEdge(0);
254 
256 
257  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
258  m_l1HistLimits.binThresholds[iBin] = caloGeomScales->globalEtaBinLowEdge(iBin);
259  }
260 
261  // set last bin upper edge
263 
264  } else {
265  m_l1HistLimits.nrBins = caloGeomScales->numberGctEmJetPhiBins();
267 
268  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
269  m_l1HistLimits.binThresholds[iBin] = rad2deg(caloGeomScales->emJetPhiBinLowEdge(iBin));
270 
271  // treat correctly the 10 deg anti-clockwise rotation
272  if (rad2deg(caloGeomScales->emJetPhiBinHighEdge(iBin)) < m_l1HistLimits.binThresholds[iBin]) {
274  }
275  }
276 
278 
279  // last bin upper limit
281 
283  }
284  }
285  } break;
286  case ETM: {
287  if (quantity == "ET") {
288  edm::ESHandle<L1CaloEtScale> etMissScale;
289  m_evSetup.get<L1JetEtScaleRcd>().get(etMissScale);
290 
291  const double etSumLSB = etMissScale->linearLsb();
292 
294 
297 
299 
300  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
301  m_l1HistLimits.binThresholds[iBin] = iBin * etSumLSB;
302  }
303 
304  // set last bin upper edge
306 
307  } else if (quantity == "eta" || quantity == "phi") {
308  edm::ESHandle<L1CaloGeometry> caloGeomESH;
309  m_evSetup.get<L1CaloGeometryRecord>().get(caloGeomESH);
310  const L1CaloGeometry* caloGeomScales = caloGeomESH.product();
311 
312  if (quantity == "eta") {
313  // do nothing, eta is not defined for ETM
314 
315  } else {
316  m_l1HistLimits.nrBins = caloGeomScales->numberGctEtSumPhiBins();
319 
321 
322  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
323  m_l1HistLimits.binThresholds[iBin] = rad2deg(caloGeomScales->etSumPhiBinLowEdge(iBin));
324  }
325 
326  // last bin upper limit
328  }
329  }
330 
331  } break;
332  case ETT: {
333  if (quantity == "ET") {
334  edm::ESHandle<L1CaloEtScale> etMissScale;
335  m_evSetup.get<L1JetEtScaleRcd>().get(etMissScale);
336 
337  const double etSumLSB = etMissScale->linearLsb();
338 
340 
343 
345 
346  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
347  m_l1HistLimits.binThresholds[iBin] = iBin * etSumLSB;
348  }
349 
350  // set last bin upper edge
352 
353  } else if (quantity == "eta" || quantity == "phi") {
354  // do nothing, eta and phi are not defined for ETT
355  }
356 
357  } break;
358  case HTT: {
359  if (quantity == "ET") {
360  edm::ESHandle<L1GctJetFinderParams> jetFinderParams;
361  m_evSetup.get<L1GctJetFinderParamsRcd>().get(jetFinderParams);
362  double htSumLSB = jetFinderParams->getHtLsbGeV();
363 
365 
368 
370 
371  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
372  m_l1HistLimits.binThresholds[iBin] = iBin * htSumLSB;
373  }
374 
375  // set last bin upper edge
377 
378  } else if (quantity == "eta" || quantity == "phi") {
379  // do nothing, eta and phi are not defined for HTT
380  }
381  } break;
382  case HTM: {
383  if (quantity == "ET") {
384  edm::ESHandle<L1CaloEtScale> htMissScale;
385  m_evSetup.get<L1HtMissScaleRcd>().get(htMissScale);
386 
387  const std::vector<double>& htThresholds = htMissScale->getThresholds();
388  m_l1HistLimits.nrBins = htThresholds.size();
389  m_l1HistLimits.lowerBinValue = htThresholds[0];
390 
391  // FIXME high edge retrieval in the scale definition
392  // now, last bin has the same width like the last but one
394  htThresholds[m_l1HistLimits.nrBins - 1] +
395  (htThresholds[m_l1HistLimits.nrBins - 1] - htThresholds[m_l1HistLimits.nrBins - 2]);
396 
398 
399  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
400  m_l1HistLimits.binThresholds[iBin] = static_cast<float>(htThresholds[iBin]);
401  }
402 
403  // set last bin upper edge
405 
406  } else if (quantity == "eta" || quantity == "phi") {
407  edm::ESHandle<L1CaloGeometry> caloGeomESH;
408  m_evSetup.get<L1CaloGeometryRecord>().get(caloGeomESH);
409  const L1CaloGeometry* caloGeomScales = caloGeomESH.product();
410 
411  if (quantity == "eta") {
412  // do nothing, eta is not defined for HTM
413 
414  } else {
415  m_l1HistLimits.nrBins = caloGeomScales->numberGctHtSumPhiBins();
418 
420 
421  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
422  m_l1HistLimits.binThresholds[iBin] = rad2deg(caloGeomScales->htSumPhiBinLowEdge(iBin));
423  }
424 
425  // last bin upper limit
427  }
428  }
429  } break;
430  case JetCounts: {
431  } break;
432  case HfBitCounts: {
433  // there are no scales for HfBitCounts, so one implements a fixed scale
434  // use same values as GCT for 3 bits
435  const unsigned int R3BINS = 8;
436  const float R3MIN = -0.5;
437  const float R3MAX = 7.5;
438 
442 
444 
445  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
446  m_l1HistLimits.binThresholds[iBin] = R3MIN + iBin * (R3MAX - R3MIN) / R3BINS;
447  }
448 
449  // last bin upper limit
451 
452  } break;
453  case HfRingEtSums: {
454  if (quantity == "ET") {
455  edm::ESHandle<L1CaloEtScale> hfRingEtScale;
456  m_evSetup.get<L1HfRingEtScaleRcd>().get(hfRingEtScale);
457 
458  const std::vector<double>& hfRingEtThresholds = hfRingEtScale->getThresholds();
459  m_l1HistLimits.nrBins = hfRingEtThresholds.size();
460  m_l1HistLimits.lowerBinValue = hfRingEtThresholds[0];
461 
462  // FIXME high edge retrieval in the scale definition
463  // now, last bin has the same width like the last but one
465  hfRingEtThresholds[m_l1HistLimits.nrBins - 1] +
466  (hfRingEtThresholds[m_l1HistLimits.nrBins - 1] - hfRingEtThresholds[m_l1HistLimits.nrBins - 2]);
467 
469 
470  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
471  m_l1HistLimits.binThresholds[iBin] = static_cast<float>(hfRingEtThresholds[iBin]);
472  }
473 
474  // set last bin upper edge
476 
477  } else if (quantity == "eta" || quantity == "phi") {
478  // do nothing, eta and phi are not defined for HfRingEtSums
479  }
480  } break;
481  case TechTrig:
482  case Castor:
483  case BPTX:
484  default: {
485  // do nothing, for these cases ET/PT, eta and phi are not defined
486 
487  } break;
488  }
489 }
490 
492  const std::string& quantity) {
493  getHistLimits(l1GtObject, quantity);
494 
495  if (edm::isDebugEnabled()) {
496  LogDebug("L1GetHistLimits") << "\n Histogram limits for L1GtObject " << l1GtObject << " and quantity " << quantity
497  << "\n Number of bins: " << m_l1HistLimits.nrBins
498  << "\n Lower limit of first bin: " << m_l1HistLimits.lowerBinValue
499  << "\n Upper limit of last bin: " << m_l1HistLimits.upperBinValue << std::endl;
500 
501  int binThreshSize = static_cast<int>(m_l1HistLimits.binThresholds.size());
502 
503  if (binThreshSize != (m_l1HistLimits.nrBins + 1)) {
504  LogTrace("L1GetHistLimits") << "\n Warning: inconsistent nrBins and binThresholds size"
505  << "\n Number of bins nrBins = " << m_l1HistLimits.nrBins
506  << "\n binThresholds size = " << binThreshSize
507  << "\n Please fix the L1GetLimits class.\n\n"
508  << std::endl;
509  }
510 
511  for (int iBin = 0; iBin < binThreshSize; ++iBin) {
512  LogTrace("L1GetHistLimits") << " Bin " << std::right << std::setw(5) << iBin << ": "
513  << m_l1HistLimits.binThresholds[iBin] << std::endl;
514  }
515  }
516 
517  return m_l1HistLimits;
518 }
519 
521  const std::string& quantity,
522  const double histMinValue,
523  const double histMaxValue) {
524  getHistLimits(l1GtObject, quantity);
525 
526  bool foundLowerBinValue = false;
527  bool foundUpperBinValue = false;
528 
529  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
530  if (m_l1HistLimits.binThresholds[iBin] <= histMinValue) {
532  foundLowerBinValue = true;
533  break;
534  }
535  }
536 
537  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
538  if (m_l1HistLimits.binThresholds[iBin] > histMaxValue) {
540  foundUpperBinValue = true;
541  break;
542  }
543  }
544 
545  if (foundLowerBinValue && foundUpperBinValue) {
546  int countBins = -1;
547  std::vector<float> binThresh;
548  binThresh.reserve(m_l1HistLimits.binThresholds.size());
549 
550  for (int iBin = 0; iBin < m_l1HistLimits.nrBins; ++iBin) {
551  if ((m_l1HistLimits.binThresholds[iBin] >= histMinValue) && m_l1HistLimits.binThresholds[iBin] < histMaxValue) {
553 
554  countBins++;
555  binThresh.push_back(m_l1HistLimits.binThresholds[iBin]);
556  }
557  }
558 
559  m_l1HistLimits.nrBins = countBins;
561  m_l1HistLimits.binThresholds = binThresh;
562 
563  // FIXME last bin untested.
564 
565  } else {
570 
571  LogDebug("L1GetHistLimits") << "\n Histogram limits for L1GtObject" << l1GtObject << " and quantity " << quantity
572  << " within the required range [" << histMinValue << ", " << histMaxValue
573  << "] not found."
574  << "\n The range is not included in the original histogram range." << std::endl;
575 
576  return m_l1HistLimits;
577  }
578 
579  if (edm::isDebugEnabled()) {
580  LogDebug("L1GetHistLimits") << "\n Histogram limits for L1GtObject" << l1GtObject << " and quantity " << quantity
581  << "\n Number of bins: " << m_l1HistLimits.nrBins
582  << "\n Lower limit of first bin: " << m_l1HistLimits.lowerBinValue
583  << "\n Upper limit of last bin: " << m_l1HistLimits.upperBinValue << std::endl;
584 
585  int binThreshSize = static_cast<int>(m_l1HistLimits.binThresholds.size());
586 
587  if (binThreshSize != (m_l1HistLimits.nrBins + 1)) {
588  LogTrace("L1GetHistLimits") << "\n Warning: inconsistent nrBins and binThresholds size"
589  << "\n Number of bins nrBins = " << m_l1HistLimits.nrBins
590  << "\n binThresholds size = " << binThreshSize
591  << "\n Please fix the L1GetLimits class.\n\n"
592  << std::endl;
593  }
594 
595  for (int iBin = 0; iBin < binThreshSize; ++iBin) {
596  LogTrace("L1GetHistLimits") << " Bin " << std::right << std::setw(5) << iBin << ": "
597  << m_l1HistLimits.binThresholds[iBin] << std::endl;
598  }
599  }
600 
601  return m_l1HistLimits;
602 }
603 
604 const int L1GetHistLimits::l1HistNrBins(const L1GtObject& l1GtObject, const std::string& quantity) {
605  getHistLimits(l1GtObject, quantity);
606  return m_l1HistLimits.nrBins;
607 }
608 
609 const double L1GetHistLimits::l1HistLowerBinValue(const L1GtObject& l1GtObject, const std::string& quantity) {
610  getHistLimits(l1GtObject, quantity);
612 }
613 
614 const double L1GetHistLimits::l1HistUpperBinValue(const L1GtObject& l1GtObject, const std::string& quantity) {
615  getHistLimits(l1GtObject, quantity);
617 }
618 
619 const std::vector<float>& L1GetHistLimits::l1HistBinThresholds(const L1GtObject& l1GtObject,
620  const std::string& quantity) {
621  getHistLimits(l1GtObject, quantity);
623 }
#define LogDebug(id)
double globalEtaBinLowEdge(unsigned int globalEtaIndex) const
bool isDebugEnabled()
unsigned int numberGctForwardEtaBinsPerHalf() const
void getHistLimits(const L1GtObject &l1GtObject, const std::string &quantity)
const edm::EventSetup & m_evSetup
Definition: L1GtObject.h:38
L1HistLimits m_l1HistLimits
all limits for a histogram
unsigned int numberGctHtSumPhiBins() const
const L1MuScale * getPtScale() const
get the Pt scale
double htSumPhiBinLowEdge(unsigned int phiIndex) const
const double l1HistUpperBinValue(const L1GtObject &l1GtObject, const std::string &quantity)
Definition: L1GtObject.h:35
unsigned int numberGctEtSumPhiBins() const
const std::vector< float > & l1HistBinThresholds(const L1GtObject &l1GtObject, const std::string &quantity)
unsigned int numberGctEmJetPhiBins() const
const int l1HistNrBins(const L1GtObject &l1GtObject, const std::string &quantity)
unsigned int numberGctCentralEtaBinsPerHalf() const
double getHtLsbGeV() const
double linearLsb() const
get LSB of linear input scale
Definition: L1CaloEtScale.h:54
virtual ~L1GetHistLimits()
Definition: L1GtObject.h:37
const std::vector< double > & getThresholds() const
get thresholds
Definition: L1CaloEtScale.h:66
const unsigned int R3BINS
Definition: L1TGCT.cc:44
const L1MuScale * getPhiScale() const
get the phi scale
virtual float getScaleMin() const =0
get the lower edge of the first bin
virtual unsigned getNBins() const =0
get number of bins
#define LogTrace(id)
std::vector< float > binThresholds
const double rad2deg(const double &)
convert phi from rad (-pi, pi] to deg (0, 360)
Definition: L1GtObject.h:29
double globalEtaBinHighEdge(unsigned int globalEtaIndex) const
double etSumPhiBinLowEdge(unsigned int phiIndex) const
Definition: L1GtObject.h:36
T get() const
Definition: EventSetup.h:73
const L1MuScale * getGMTEtaScale() const
get the GMT eta scale
double emJetPhiBinLowEdge(unsigned int phiIndex) const
double htSumPhiBinHighEdge(unsigned int phiIndex) const
L1GetHistLimits(const edm::EventSetup &evSetup)
T const * product() const
Definition: ESHandle.h:86
const float R3MAX
Definition: L1TGCT.cc:46
virtual float getScaleMax() const =0
get the upper edge of the last bin
const double l1HistLowerBinValue(const L1GtObject &l1GtObject, const std::string &quantity)
virtual float getValue(unsigned i) const =0
get value of the underlying vector for bin i
double emJetPhiBinHighEdge(unsigned int phiIndex) const
double etSumPhiBinHighEdge(unsigned int phiIndex) const
const float R3MIN
Definition: L1TGCT.cc:45
const L1HistLimits & l1HistLimits(const L1GtObject &l1GtObject, const std::string &quantity)