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