CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SiStripPayloadInspectorHelper.h
Go to the documentation of this file.
1 #ifndef CONDCORE_SISTRIPPLUGINS_SISTRIPPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_SISTRIPPLUGINS_SISTRIPPAYLOADINSPECTORHELPER_H
3 
4 #include <vector>
5 #include <numeric>
6 #include <string>
7 #include "TH1.h"
8 #include "TH2.h"
9 #include "TPaveText.h"
10 #include "TStyle.h"
19 
22 
23 namespace SiStripPI {
24 
25  //##### for plotting
26 
28 
29  class Entry {
30  public:
31  Entry() : entries(0), sum(0), sq_sum(0) {}
32 
33  double mean() { return sum / entries; }
34  double std_dev() {
35  double tmean = mean();
36  return sqrt((sq_sum - entries * tmean * tmean) / (entries - 1));
37  }
38  double mean_rms() { return std_dev() / sqrt(entries); }
39 
40  void add(double val) {
41  entries++;
42  sum += val;
43  sq_sum += val * val;
44  }
45 
46  void reset() {
47  entries = 0;
48  sum = 0;
49  sq_sum = 0;
50  }
51 
52  private:
53  long int entries;
54  double sum, sq_sum;
55  };
56 
57  // class Monitor1D
58 
59  class Monitor1D {
60  public:
61  Monitor1D(OpMode mode, const char* name, const char* title, int nbinsx, double xmin, double xmax)
62  : entry_(), mode_(mode), obj_(name, title, nbinsx, xmin, xmax) {}
63 
65 
67 
68  void Fill(int apv, int det, double vx) {
69  switch (mode_) {
70  case (OpMode::APV_BASED):
71  if (!((apv == prev_apv_ && det == prev_det_) || prev_apv_ == 0)) {
72  flush();
73  }
74  prev_apv_ = apv;
75  prev_det_ = det;
76  break;
77  case (OpMode::MODULE_BASED):
78  if (!(det == prev_det_ || prev_det_ == 0)) {
79  flush();
80  }
81  prev_det_ = det;
82  break;
83  case (OpMode::STRIP_BASED):
84  flush();
85  break;
86  }
87  entry_.add(vx);
88  }
89 
90  void flush() {
91  obj_.Fill(entry_.mean());
92  entry_.reset();
93  }
94 
95  TH1F& hist() {
96  flush();
97  return obj_;
98  }
99 
100  TH1F& getHist() { return obj_; }
101 
102  private:
103  int prev_apv_ = 0, prev_det_ = 0;
106  TH1F obj_;
107  };
108 
109  // class monitor 2D
110 
111  class Monitor2D {
112  public:
114  const char* name,
115  const char* title,
116  int nbinsx,
117  double xmin,
118  double xmax,
119  int nbinsy,
120  double ymin,
121  double ymax)
122  : entryx_(), entryy_(), mode_(mode), obj_(name, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax) {}
123 
125 
127 
128  void Fill(int apv, int det, double vx, double vy) {
129  switch (mode_) {
130  case (OpMode::APV_BASED):
131  if (!((apv == prev_apv_ && det == prev_det_) || prev_apv_ == 0)) {
132  flush();
133  }
134  prev_apv_ = apv;
135  prev_det_ = det;
136  break;
137  case (OpMode::MODULE_BASED):
138  if (!(det == prev_det_ || prev_det_ == 0)) {
139  flush();
140  }
141  prev_det_ = det;
142  break;
143  case (OpMode::STRIP_BASED):
144  flush();
145  break;
146  }
147  entryx_.add(vx);
148  entryy_.add(vy);
149  }
150 
151  void flush() {
152  obj_.Fill(entryx_.mean(), entryy_.mean());
153  entryx_.reset();
154  entryy_.reset();
155  }
156 
157  TH2F& hist() {
158  flush();
159  return obj_;
160  }
161 
162  private:
163  int prev_apv_ = 0, prev_det_ = 0;
166  TH2F obj_;
167  };
168 
169  enum estimator { min, max, mean, rms };
170 
171  /*--------------------------------------------------------------------*/
173  /*--------------------------------------------------------------------*/
174  {
175  switch (e) {
176  case SiStripPI::min:
177  return "minimum";
178  case SiStripPI::max:
179  return "maximum";
180  case SiStripPI::mean:
181  return "mean";
182  case SiStripPI::rms:
183  return "RMS";
184  default:
185  return "should never be here";
186  }
187  }
188 
189  /*--------------------------------------------------------------------*/
191  /*-------------------------------------------------------------------*/
192  {
193  switch (sub) {
195  return "TIB";
197  return "TOB";
199  return "TID";
201  return "TEC";
202  default:
203  return "should never be here";
204  }
205  }
206 
208  TIB1r = 1010,
209  TIB1s = 1011,
210  TIB2r = 1020,
211  TIB2s = 1021,
212  TIB3r = 1030,
213  TIB4r = 1040,
214  TOB1r = 2010,
215  TOB1s = 2011,
216  TOB2r = 2020,
217  TOB2s = 2021,
218  TOB3r = 2030,
219  TOB4r = 2040,
220  TOB5r = 2050,
221  TOB6r = 2060,
222  TEC1r = 3010,
223  TEC1s = 3011,
224  TEC2r = 3020,
225  TEC2s = 3021,
226  TEC3r = 3030,
227  TEC3s = 3031,
228  TEC4r = 3040,
229  TEC4s = 3041,
230  TEC5r = 3050,
231  TEC5s = 3051,
232  TEC6r = 3060,
233  TEC6s = 3061,
234  TEC7r = 3070,
235  TEC7s = 3071,
236  TEC8r = 3080,
237  TEC8s = 3081,
238  TEC9r = 3090,
239  TEC9s = 3091,
240  TID1r = 4010,
241  TID1s = 4011,
242  TID2r = 4020,
243  TID2s = 4021,
244  TID3r = 4030,
245  TID3s = 4031,
247  };
248 
249  /*--------------------------------------------------------------------*/
250  inline std::pair<int, const char*> regionType(int index)
251  /*--------------------------------------------------------------------*/
252  {
253  auto region = static_cast<std::underlying_type_t<SiStripPI::TrackerRegion>>(index);
254 
255  switch (region) {
256  case SiStripPI::TIB1r:
257  return std::make_pair(1, "TIB L1 r-#varphi");
258  case SiStripPI::TIB1s:
259  return std::make_pair(2, "TIB L1 stereo");
260  case SiStripPI::TIB2r:
261  return std::make_pair(3, "TIB L2 r-#varphi");
262  case SiStripPI::TIB2s:
263  return std::make_pair(4, "TIB L2 stereo");
264  case SiStripPI::TIB3r:
265  return std::make_pair(5, "TIB L3");
266  case SiStripPI::TIB4r:
267  return std::make_pair(6, "TIB L4");
268  case SiStripPI::TOB1r:
269  return std::make_pair(7, "TOB L1 r-#varphi");
270  case SiStripPI::TOB1s:
271  return std::make_pair(8, "TOB L1 stereo");
272  case SiStripPI::TOB2r:
273  return std::make_pair(9, "TOB L2 r-#varphi");
274  case SiStripPI::TOB2s:
275  return std::make_pair(10, "TOB L2 stereo");
276  case SiStripPI::TOB3r:
277  return std::make_pair(11, "TOB L3 r-#varphi");
278  case SiStripPI::TOB4r:
279  return std::make_pair(12, "TOB L4");
280  case SiStripPI::TOB5r:
281  return std::make_pair(13, "TOB L5");
282  case SiStripPI::TOB6r:
283  return std::make_pair(14, "TOB L6");
284  case SiStripPI::TEC1r:
285  return std::make_pair(15, "TEC D1 r-#varphi");
286  case SiStripPI::TEC1s:
287  return std::make_pair(16, "TEC D1 stereo");
288  case SiStripPI::TEC2r:
289  return std::make_pair(17, "TEC D2 r-#varphi");
290  case SiStripPI::TEC2s:
291  return std::make_pair(18, "TEC D2 stereo");
292  case SiStripPI::TEC3r:
293  return std::make_pair(19, "TEC D3 r-#varphi");
294  case SiStripPI::TEC3s:
295  return std::make_pair(20, "TEC D3 stereo");
296  case SiStripPI::TEC4r:
297  return std::make_pair(21, "TEC D4 r-#varphi");
298  case SiStripPI::TEC4s:
299  return std::make_pair(22, "TEC D4 stereo");
300  case SiStripPI::TEC5r:
301  return std::make_pair(23, "TEC D5 r-#varphi");
302  case SiStripPI::TEC5s:
303  return std::make_pair(24, "TEC D5 stereo");
304  case SiStripPI::TEC6r:
305  return std::make_pair(25, "TEC D6 r-#varphi");
306  case SiStripPI::TEC6s:
307  return std::make_pair(26, "TEC D6 stereo");
308  case SiStripPI::TEC7r:
309  return std::make_pair(27, "TEC D7 r-#varphi");
310  case SiStripPI::TEC7s:
311  return std::make_pair(28, "TEC D7 stereo");
312  case SiStripPI::TEC8r:
313  return std::make_pair(29, "TEC D8 r-#varphi");
314  case SiStripPI::TEC8s:
315  return std::make_pair(30, "TEC D8 stereo");
316  case SiStripPI::TEC9r:
317  return std::make_pair(31, "TEC D9 r-#varphi");
318  case SiStripPI::TEC9s:
319  return std::make_pair(32, "TEC D9 stereo");
320  case SiStripPI::TID1r:
321  return std::make_pair(33, "TID D1 r-#varphi");
322  case SiStripPI::TID1s:
323  return std::make_pair(34, "TID D1 stereo");
324  case SiStripPI::TID2r:
325  return std::make_pair(35, "TID D2 r-#varphi");
326  case SiStripPI::TID2s:
327  return std::make_pair(36, "TID D2 stereo");
328  case SiStripPI::TID3r:
329  return std::make_pair(37, "TID D3 r-#varphi");
330  case SiStripPI::TID3s:
331  return std::make_pair(38, "TID D3 stereo");
333  return std::make_pair(-1, "undefined");
334  default:
335  return std::make_pair(999, "should never be here");
336  }
337  }
338 
339  /*--------------------------------------------------------------------*/
340  inline std::pair<float, float> getTheRange(std::map<uint32_t, float> values, const float nsigma)
341  /*--------------------------------------------------------------------*/
342  {
343  float sum = std::accumulate(
344  std::begin(values), std::end(values), 0.0, [](float value, const std::map<uint32_t, float>::value_type& p) {
345  return value + p.second;
346  });
347 
348  float m = sum / values.size();
349 
350  float accum = 0.0;
351  std::for_each(std::begin(values), std::end(values), [&](const std::map<uint32_t, float>::value_type& p) {
352  accum += (p.second - m) * (p.second - m);
353  });
354 
355  float stdev = sqrt(accum / (values.size() - 1));
356 
357  if (stdev != 0.) {
358  return std::make_pair(m - nsigma * stdev, m + nsigma * stdev);
359  } else {
360  return std::make_pair(m > 0. ? 0.95 * m : 1.05 * m, m > 0 ? 1.05 * m : 0.95 * m);
361  }
362  }
363 
364  /*--------------------------------------------------------------------*/
365  inline void drawStatBox(std::map<std::string, std::shared_ptr<TH1F>> histos,
366  std::map<std::string, int> colormap,
367  std::vector<std::string> legend,
368  double X = 0.15,
369  double Y = 0.93,
370  double W = 0.15,
371  double H = 0.10)
372  /*--------------------------------------------------------------------*/
373  {
374  char buffer[255];
375 
376  int i = 0;
377  for (const auto& element : legend) {
378  TPaveText* stat = new TPaveText(X, Y - (i * H), X + W, Y - (i + 1) * H, "NDC");
379  i++;
380  auto Histo = histos[element];
381  sprintf(buffer, "Entries : %i\n", (int)Histo->GetEntries());
382  stat->AddText(buffer);
383 
384  sprintf(buffer, "Mean : %6.2f\n", Histo->GetMean());
385  stat->AddText(buffer);
386 
387  sprintf(buffer, "RMS : %6.2f\n", Histo->GetRMS());
388  stat->AddText(buffer);
389 
390  stat->SetFillColor(0);
391  stat->SetLineColor(colormap[element]);
392  stat->SetTextColor(colormap[element]);
393  stat->SetTextSize(0.03);
394  stat->SetBorderSize(0);
395  stat->SetMargin(0.05);
396  stat->SetTextAlign(12);
397  stat->Draw();
398  }
399  }
400 
401  /*--------------------------------------------------------------------*/
402  inline std::pair<float, float> getExtrema(TH1* h1, TH1* h2)
403  /*--------------------------------------------------------------------*/
404  {
405  float theMax(-9999.);
406  float theMin(9999.);
407  theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
408  theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
409 
410  float add_min = theMin > 0. ? -0.05 : 0.05;
411  float add_max = theMax > 0. ? 0.05 : -0.05;
412 
413  auto result = std::make_pair(theMin * (1 + add_min), theMax * (1 + add_max));
414  return result;
415  }
416 
417  /*--------------------------------------------------------------------*/
418  inline void makeNicePlotStyle(TH1* hist)
419  /*--------------------------------------------------------------------*/
420  {
421  hist->SetStats(kFALSE);
422  hist->SetLineWidth(2);
423  hist->GetXaxis()->CenterTitle(true);
424  hist->GetYaxis()->CenterTitle(true);
425  hist->GetXaxis()->SetTitleFont(42);
426  hist->GetYaxis()->SetTitleFont(42);
427  hist->GetXaxis()->SetTitleSize(0.05);
428  hist->GetYaxis()->SetTitleSize(0.05);
429  hist->GetXaxis()->SetTitleOffset(0.9);
430  hist->GetYaxis()->SetTitleOffset(1.3);
431  hist->GetXaxis()->SetLabelFont(42);
432  hist->GetYaxis()->SetLabelFont(42);
433  hist->GetYaxis()->SetLabelSize(.05);
434  hist->GetXaxis()->SetLabelSize(.05);
435  }
436 
437  /*--------------------------------------------------------------------*/
438  inline void printSummary(const std::map<unsigned int, SiStripDetSummary::Values>& map)
439  /*--------------------------------------------------------------------*/
440  {
441  for (const auto& element : map) {
442  int count = element.second.count;
443  double mean = count > 0 ? (element.second.mean) / count : 0.;
444  double rms = count > 0 ? (element.second.rms) / count - mean * mean : 0.;
445  if (rms <= 0)
446  rms = 0;
447  else
448  rms = sqrt(rms);
449 
450  std::string detector;
451 
452  switch ((element.first) / 1000) {
453  case 1:
454  detector = "TIB ";
455  break;
456  case 2:
457  detector = "TOB ";
458  break;
459  case 3:
460  detector = "TEC ";
461  break;
462  case 4:
463  detector = "TID ";
464  break;
465  }
466 
467  int layer = (element.first) / 10 - (element.first) / 1000 * 100;
468  int stereo = (element.first) - (layer * 10) - (element.first) / 1000 * 1000;
469 
470  std::cout << "key of the map:" << element.first << " ( region: " << regionType(element.first).second << " ) "
471  << detector << " layer: " << layer << " stereo:" << stereo << "| count:" << count << " mean: " << mean
472  << " rms: " << rms << std::endl;
473  }
474  }
475 
476  // code is mutuated from CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics
477 
478  /*--------------------------------------------------------------------*/
479  inline void setBadComponents(int i, int component, const SiStripQuality::BadComponent& BC, int NBadComponent[4][19][4])
480  /*--------------------------------------------------------------------*/
481  {
482  if (BC.BadApvs) {
483  NBadComponent[i][0][2] += std::bitset<16>(BC.BadApvs & 0x3f).count();
484  NBadComponent[i][component][2] += std::bitset<16>(BC.BadApvs & 0x3f).count();
485  }
486 
487  if (BC.BadFibers) {
488  NBadComponent[i][0][1] += std::bitset<4>(BC.BadFibers & 0x7).count();
489  NBadComponent[i][component][1] += std::bitset<4>(BC.BadFibers & 0x7).count();
490  }
491 
492  if (BC.BadModule) {
493  NBadComponent[i][0][0]++;
494  NBadComponent[i][component][0]++;
495  }
496  }
497 
498  // generic code to fill a SiStripDetSummary with Noise payload info
499  /*--------------------------------------------------------------------*/
500  inline void fillNoiseDetSummary(SiStripDetSummary& summaryNoise,
501  std::shared_ptr<SiStripNoises> payload,
503  /*--------------------------------------------------------------------*/
504  {
505  SiStripNoises::RegistryIterator rit = payload->getRegistryVectorBegin(), erit = payload->getRegistryVectorEnd();
506  uint16_t Nstrips;
507  std::vector<float> vstripnoise;
508  double mean, rms, min, max;
509  for (; rit != erit; ++rit) {
510  Nstrips = (rit->iend - rit->ibegin) * 8 / 9; //number of strips = number of chars * char size / strip noise size
511  vstripnoise.resize(Nstrips);
512  payload->allNoises(
513  vstripnoise,
514  make_pair(payload->getDataVectorBegin() + rit->ibegin, payload->getDataVectorBegin() + rit->iend));
515 
516  mean = 0;
517  rms = 0;
518  min = 10000;
519  max = 0;
520 
521  DetId detId(rit->detid);
522 
523  for (size_t i = 0; i < Nstrips; ++i) {
524  mean += vstripnoise[i];
525  rms += vstripnoise[i] * vstripnoise[i];
526  if (vstripnoise[i] < min)
527  min = vstripnoise[i];
528  if (vstripnoise[i] > max)
529  max = vstripnoise[i];
530  }
531 
532  mean /= Nstrips;
533  if ((rms / Nstrips - mean * mean) > 0.) {
534  rms = sqrt(rms / Nstrips - mean * mean);
535  } else {
536  rms = 0.;
537  }
538 
539  switch (est) {
540  case SiStripPI::min:
541  summaryNoise.add(detId, min);
542  break;
543  case SiStripPI::max:
544  summaryNoise.add(detId, max);
545  break;
546  case SiStripPI::mean:
547  summaryNoise.add(detId, mean);
548  break;
549  case SiStripPI::rms:
550  summaryNoise.add(detId, rms);
551  break;
552  default:
553  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
554  break;
555  }
556  }
557  }
558 
559  /*--------------------------------------------------------------------*/
560  inline void fillTotalComponents(int NTkComponents[4], int NComponents[4][19][4], const TrackerTopology m_trackerTopo)
561  /*--------------------------------------------------------------------*/
562  {
563  const auto detInfo =
565  for (const auto& det : detInfo.getAllData()) {
566  int nAPVs = detInfo.getNumberOfApvsAndStripLength(det.first).first;
567  // one fiber connects to 2 APVs
568  int nFibers = nAPVs / 2;
569  int nStrips = (128 * detInfo.getNumberOfApvsAndStripLength(det.first).first);
570  NTkComponents[0]++;
571  NTkComponents[1] += nFibers;
572  NTkComponents[2] += nAPVs;
573  NTkComponents[3] += nStrips;
574 
575  DetId detectorId = DetId(det.first);
576  int subDet = detectorId.subdetId();
577 
578  int subDetIndex = -1;
579  int component = -1;
580  if (subDet == StripSubdetector::TIB) {
581  subDetIndex = 0;
582  component = m_trackerTopo.tibLayer(det.first);
583  } else if (subDet == StripSubdetector::TID) {
584  subDetIndex = 1;
585  component = m_trackerTopo.tidSide(det.first) == 2 ? m_trackerTopo.tidWheel(det.first)
586  : m_trackerTopo.tidWheel(det.first) + 3;
587  } else if (subDet == StripSubdetector::TOB) {
588  subDetIndex = 2;
589  component = m_trackerTopo.tobLayer(det.first);
590  } else if (subDet == StripSubdetector::TEC) {
591  subDetIndex = 3;
592  component = m_trackerTopo.tecSide(det.first) == 2 ? m_trackerTopo.tecWheel(det.first)
593  : m_trackerTopo.tecWheel(det.first) + 9;
594  }
595 
596  NComponents[subDetIndex][0][0]++;
597  NComponents[subDetIndex][0][1] += nFibers;
598  NComponents[subDetIndex][0][2] += nAPVs;
599  NComponents[subDetIndex][0][3] += nStrips;
600 
601  NComponents[subDetIndex][component][0]++;
602  NComponents[subDetIndex][component][1] += nFibers;
603  NComponents[subDetIndex][component][2] += nAPVs;
604  NComponents[subDetIndex][component][3] += nStrips;
605  }
606  }
607 
608  // generic code to fill the vectors of bad components
609  /*--------------------------------------------------------------------*/
610  inline void fillBCArrays(const SiStripQuality* siStripQuality_,
611  int NTkBadComponent[4],
612  int NBadComponent[4][19][4],
613  const TrackerTopology m_trackerTopo)
614  /*--------------------------------------------------------------------*/
615  {
616  std::vector<SiStripQuality::BadComponent> BC = siStripQuality_->getBadComponentList();
617 
618  for (size_t i = 0; i < BC.size(); ++i) {
619  //&&&&&&&&&&&&&
620  //Full Tk
621  //&&&&&&&&&&&&&
622 
623  if (BC.at(i).BadModule)
624  NTkBadComponent[0]++;
625  if (BC.at(i).BadFibers)
626  NTkBadComponent[1] +=
627  ((BC.at(i).BadFibers >> 2) & 0x1) + ((BC.at(i).BadFibers >> 1) & 0x1) + ((BC.at(i).BadFibers) & 0x1);
628  if (BC.at(i).BadApvs)
629  NTkBadComponent[2] += ((BC.at(i).BadApvs >> 5) & 0x1) + ((BC.at(i).BadApvs >> 4) & 0x1) +
630  ((BC.at(i).BadApvs >> 3) & 0x1) + ((BC.at(i).BadApvs >> 2) & 0x1) +
631  ((BC.at(i).BadApvs >> 1) & 0x1) + ((BC.at(i).BadApvs) & 0x1);
632 
633  //&&&&&&&&&&&&&&&&&
634  //Single SubSyste
635  //&&&&&&&&&&&&&&&&&
636  int component;
637  DetId detectorId = DetId(BC.at(i).detid);
638  int subDet = detectorId.subdetId();
639  if (subDet == StripSubdetector::TIB) {
640  //&&&&&&&&&&&&&&&&&
641  //TIB
642  //&&&&&&&&&&&&&&&&&
643 
644  component = m_trackerTopo.tibLayer(BC.at(i).detid);
645  SiStripPI::setBadComponents(0, component, BC.at(i), NBadComponent);
646 
647  } else if (subDet == StripSubdetector::TID) {
648  //&&&&&&&&&&&&&&&&&
649  //TID
650  //&&&&&&&&&&&&&&&&&
651 
652  component = m_trackerTopo.tidSide(BC.at(i).detid) == 2 ? m_trackerTopo.tidWheel(BC.at(i).detid)
653  : m_trackerTopo.tidWheel(BC.at(i).detid) + 3;
654  SiStripPI::setBadComponents(1, component, BC.at(i), NBadComponent);
655 
656  } else if (subDet == StripSubdetector::TOB) {
657  //&&&&&&&&&&&&&&&&&
658  //TOB
659  //&&&&&&&&&&&&&&&&&
660 
661  component = m_trackerTopo.tobLayer(BC.at(i).detid);
662  SiStripPI::setBadComponents(2, component, BC.at(i), NBadComponent);
663 
664  } else if (subDet == StripSubdetector::TEC) {
665  //&&&&&&&&&&&&&&&&&
666  //TEC
667  //&&&&&&&&&&&&&&&&&
668 
669  component = m_trackerTopo.tecSide(BC.at(i).detid) == 2 ? m_trackerTopo.tecWheel(BC.at(i).detid)
670  : m_trackerTopo.tecWheel(BC.at(i).detid) + 9;
671  SiStripPI::setBadComponents(3, component, BC.at(i), NBadComponent);
672  }
673  }
674 
675  //&&&&&&&&&&&&&&&&&&
676  // Single Strip Info
677  //&&&&&&&&&&&&&&&&&&
678 
679  const auto detInfo =
681 
682  float percentage = 0;
683 
684  SiStripQuality::RegistryIterator rbegin = siStripQuality_->getRegistryVectorBegin();
685  SiStripQuality::RegistryIterator rend = siStripQuality_->getRegistryVectorEnd();
686 
687  for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
688  uint32_t detid = rp->detid;
689 
690  int subdet = -999;
691  int component = -999;
692  DetId detectorId = DetId(detid);
693  int subDet = detectorId.subdetId();
694  if (subDet == StripSubdetector::TIB) {
695  subdet = 0;
696  component = m_trackerTopo.tibLayer(detid);
697  } else if (subDet == StripSubdetector::TID) {
698  subdet = 1;
699  component =
700  m_trackerTopo.tidSide(detid) == 2 ? m_trackerTopo.tidWheel(detid) : m_trackerTopo.tidWheel(detid) + 3;
701  } else if (subDet == StripSubdetector::TOB) {
702  subdet = 2;
703  component = m_trackerTopo.tobLayer(detid);
704  } else if (subDet == StripSubdetector::TEC) {
705  subdet = 3;
706  component =
707  m_trackerTopo.tecSide(detid) == 2 ? m_trackerTopo.tecWheel(detid) : m_trackerTopo.tecWheel(detid) + 9;
708  }
709 
710  SiStripQuality::Range sqrange = SiStripQuality::Range(siStripQuality_->getDataVectorBegin() + rp->ibegin,
711  siStripQuality_->getDataVectorBegin() + rp->iend);
712 
713  percentage = 0;
714  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
715  unsigned int range = siStripQuality_->decode(*(sqrange.first + it)).range;
716  NTkBadComponent[3] += range;
717  NBadComponent[subdet][0][3] += range;
718  NBadComponent[subdet][component][3] += range;
719  percentage += range;
720  }
721  if (percentage != 0)
722  percentage /= 128. * detInfo.getNumberOfApvsAndStripLength(detid).first;
723  if (percentage > 1)
724  edm::LogError("SiStripBadStrip_PayloadInspector")
725  << "PROBLEM detid " << detid << " value " << percentage << std::endl;
726  }
727  }
728 
729  /*--------------------------------------------------------------------*/
730  inline void printBCDebug(int NTkBadComponent[4], int NBadComponent[4][19][4])
731  /*--------------------------------------------------------------------*/
732  {
733  //&&&&&&&&&&&&&&&&&&
734  // printout
735  //&&&&&&&&&&&&&&&&&&
736 
737  std::stringstream ss;
738  ss.str("");
739  ss << "\n-----------------\nGlobal Info\n-----------------";
740  ss << "\nBadComponent \t Modules \tFibers "
741  "\tApvs\tStrips\n----------------------------------------------------------------";
742  ss << "\nTracker:\t\t" << NTkBadComponent[0] << "\t" << NTkBadComponent[1] << "\t" << NTkBadComponent[2] << "\t"
743  << NTkBadComponent[3];
744  ss << "\n";
745  ss << "\nTIB:\t\t\t" << NBadComponent[0][0][0] << "\t" << NBadComponent[0][0][1] << "\t" << NBadComponent[0][0][2]
746  << "\t" << NBadComponent[0][0][3];
747  ss << "\nTID:\t\t\t" << NBadComponent[1][0][0] << "\t" << NBadComponent[1][0][1] << "\t" << NBadComponent[1][0][2]
748  << "\t" << NBadComponent[1][0][3];
749  ss << "\nTOB:\t\t\t" << NBadComponent[2][0][0] << "\t" << NBadComponent[2][0][1] << "\t" << NBadComponent[2][0][2]
750  << "\t" << NBadComponent[2][0][3];
751  ss << "\nTEC:\t\t\t" << NBadComponent[3][0][0] << "\t" << NBadComponent[3][0][1] << "\t" << NBadComponent[3][0][2]
752  << "\t" << NBadComponent[3][0][3];
753  ss << "\n";
754 
755  for (int i = 1; i < 5; ++i)
756  ss << "\nTIB Layer " << i << " :\t\t" << NBadComponent[0][i][0] << "\t" << NBadComponent[0][i][1] << "\t"
757  << NBadComponent[0][i][2] << "\t" << NBadComponent[0][i][3];
758  ss << "\n";
759  for (int i = 1; i < 4; ++i)
760  ss << "\nTID+ Disk " << i << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
761  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
762  for (int i = 4; i < 7; ++i)
763  ss << "\nTID- Disk " << i - 3 << " :\t\t" << NBadComponent[1][i][0] << "\t" << NBadComponent[1][i][1] << "\t"
764  << NBadComponent[1][i][2] << "\t" << NBadComponent[1][i][3];
765  ss << "\n";
766  for (int i = 1; i < 7; ++i)
767  ss << "\nTOB Layer " << i << " :\t\t" << NBadComponent[2][i][0] << "\t" << NBadComponent[2][i][1] << "\t"
768  << NBadComponent[2][i][2] << "\t" << NBadComponent[2][i][3];
769  ss << "\n";
770  for (int i = 1; i < 10; ++i)
771  ss << "\nTEC+ Disk " << i << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
772  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
773  for (int i = 10; i < 19; ++i)
774  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << NBadComponent[3][i][0] << "\t" << NBadComponent[3][i][1] << "\t"
775  << NBadComponent[3][i][2] << "\t" << NBadComponent[3][i][3];
776  ss << "\n";
777 
778  //edm::LogInfo("SiStripBadStrip_PayloadInspector") << ss.str() << std::endl;
779  std::cout << ss.str() << std::endl;
780  }
781 
783 
784  /*--------------------------------------------------------------------*/
786  /*--------------------------------------------------------------------*/
787  {
788  TStyle* palettestyle = new TStyle("palettestyle", "Style for P-TDR");
789 
790  const int NRGBs = 5;
791  const int NCont = 255;
792 
793  switch (palette) {
794  case HALFGRAY: {
795  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
796  double red[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
797  double green[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
798  double blue[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
799  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
800  } break;
801 
802  case GRAY: {
803  double stops[NRGBs] = {0.00, 0.01, 0.05, 0.09, 0.1};
804  double red[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
805  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
806  double blue[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
807  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
808  } break;
809 
810  case BLUES: {
811  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
812  double red[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
813  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
814  double blue[NRGBs] = {1.00, 1.00, 1.00, 1.00, 1.00};
815  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
816 
817  } break;
818 
819  case REDS: {
820  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
821  double red[NRGBs] = {1.00, 1.00, 1.00, 1.00, 1.00};
822  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
823  double blue[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
824  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
825  } break;
826 
827  case ANTIGRAY: {
828  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
829  double red[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
830  double green[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
831  double blue[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
832  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
833  } break;
834 
835  case FIRE: {
836  const int NCOLs = 4;
837  double stops[NCOLs] = {0.00, 0.20, 0.80, 1.00};
838  double red[NCOLs] = {1.00, 1.00, 1.00, 0.50};
839  double green[NCOLs] = {1.00, 1.00, 0.00, 0.00};
840  double blue[NCOLs] = {0.20, 0.00, 0.00, 0.00};
841  TColor::CreateGradientColorTable(NCOLs, stops, red, green, blue, NCont);
842  } break;
843 
844  case ANTIFIRE: {
845  const int NCOLs = 4;
846  double stops[NCOLs] = {0.00, 0.20, 0.80, 1.00};
847  double red[NCOLs] = {0.50, 1.00, 1.00, 1.00};
848  double green[NCOLs] = {0.00, 0.00, 1.00, 1.00};
849  double blue[NCOLs] = {0.00, 0.00, 0.00, 0.20};
850  TColor::CreateGradientColorTable(NCOLs, stops, red, green, blue, NCont);
851  } break;
852 
853  case LOGREDBLUE: {
854  double stops[NRGBs] = {0.0001, 0.0010, 0.0100, 0.1000, 1.0000};
855  double red[NRGBs] = {1.00, 0.75, 0.50, 0.25, 0.00};
856  double green[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
857  double blue[NRGBs] = {0.00, 0.25, 0.50, 0.75, 1.00};
858  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
859  } break;
860 
861  case LOGBLUERED: {
862  double stops[NRGBs] = {0.0001, 0.0010, 0.0100, 0.1000, 1.0000};
863  double red[NRGBs] = {0.00, 0.25, 0.50, 0.75, 1.00};
864  double green[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
865  double blue[NRGBs] = {1.00, 0.75, 0.50, 0.25, 0.00};
866  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
867  } break;
868 
869  case BLUERED: {
870  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
871  double red[NRGBs] = {0.00, 0.25, 0.50, 0.75, 1.00};
872  double green[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
873  double blue[NRGBs] = {1.00, 0.75, 0.50, 0.25, 0.00};
874  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
875  } break;
876 
877  case DEFAULT: {
878  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
879  double red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
880  double green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
881  double blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
882  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
883  } break;
884  default:
885  std::cout << "should nevere be here" << std::endl;
886  break;
887  }
888 
889  palettestyle->SetNumberContours(NCont);
890  }
891 
892 }; // namespace SiStripPI
893 #endif
unsigned short range
static constexpr auto TEC
const std::vector< BadComponent > & getBadComponentList() const
unsigned int tibLayer(const DetId &id) const
std::pair< int, const char * > regionType(int index)
#define X(str)
Definition: MuonsGrabber.cc:38
void Fill(int apv, int det, double vx)
unsigned int tidWheel(const DetId &id) const
Registry::const_iterator RegistryIterator
Log< level::Error, false > LogError
void setPaletteStyle(SiStripPI::palette palette)
void fillBCArrays(const SiStripQuality *siStripQuality_, int NTkBadComponent[4], int NBadComponent[4][19][4], const TrackerTopology m_trackerTopo)
tuple nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
constexpr std::array< uint8_t, layerIndexSize > layer
const uint16_t range(const Frame &aFrame)
void printSummary(const std::map< unsigned int, SiStripDetSummary::Values > &map)
tuple result
Definition: mps_fire.py:311
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
void fillNoiseDetSummary(SiStripDetSummary &summaryNoise, std::shared_ptr< SiStripNoises > payload, SiStripPI::estimator est)
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
RegistryIterator getRegistryVectorEnd() const
unsigned int tidSide(const DetId &id) const
void drawStatBox(std::map< std::string, std::shared_ptr< TH1F >> histos, std::map< std::string, int > colormap, std::vector< std::string > legend, double X=0.15, double Y=0.93, double W=0.15, double H=0.10)
void Fill(int apv, int det, double vx, double vy)
void printBCDebug(int NTkBadComponent[4], int NBadComponent[4][19][4])
T sqrt(T t)
Definition: SSEVec.h:19
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:49
void add(DetId detid, float value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
void makeNicePlotStyle(TH1 *hist)
SiStripDetInfo read(std::string filePath)
std::string getStringFromSubdet(StripSubdetector::SubDetector sub)
static constexpr auto TOB
std::string estimatorType(SiStripPI::estimator e)
ContainerIterator getDataVectorBegin() const
__shared__ Hist hist
Definition: DetId.h:17
void setBadComponents(int i, int component, const SiStripQuality::BadComponent &BC, int NBadComponent[4][19][4])
static constexpr auto TIB
Monitor1D(OpMode mode, const char *name, const char *title, int nbinsx, double xmin, double xmax)
RegistryIterator getRegistryVectorBegin() const
void fillTotalComponents(int NTkComponents[4], int NComponents[4][19][4], const TrackerTopology m_trackerTopo)
std::pair< ContainerIterator, ContainerIterator > Range
string end
Definition: dataset.py:937
static constexpr char const *const kDefaultFile
tuple cout
Definition: gather_cfg.py:144
Monitor2D(OpMode mode, const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax)
Log< level::Warning, false > LogWarning
unsigned int tecWheel(const DetId &id) const
static constexpr auto TID
data decode(const unsigned int &value) const
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const