CMS 3D CMS Logo

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