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 "TPaveText.h"
9 #include "TStyle.h"
14 
15 namespace SiStripPI {
16 
17  enum estimator {
18  min,
19  max,
22  };
23 
24  /*--------------------------------------------------------------------*/
26  /*--------------------------------------------------------------------*/
27  {
28  switch(e){
29  case SiStripPI::min : return "minimum";
30  case SiStripPI::max : return "maximum";
31  case SiStripPI::mean : return "mean";
32  case SiStripPI::rms : return "RMS";
33  default: return "should never be here";
34  }
35  }
36 
37  /*--------------------------------------------------------------------*/
39  /*-------------------------------------------------------------------*/
40  {
41  switch(sub){
42  case StripSubdetector::TIB : return "TIB";
43  case StripSubdetector::TOB : return "TOB";
44  case StripSubdetector::TID : return "TID";
45  case StripSubdetector::TEC : return "TEC";
46  default : return "should never be here";
47  }
48  }
49 
50  enum TrackerRegion {
51  TIB1r = 1010, TIB1s = 1011,
52  TIB2r = 1020, TIB2s = 1021,
53  TIB3r = 1030,
54  TIB4r = 1040,
55  TOB1r = 2010, TOB1s = 2011,
56  TOB2r = 2020, TOB2s = 2021,
57  TOB3r = 2030,
58  TOB4r = 2040,
59  TOB5r = 2050,
60  TOB6r = 2060,
61  TEC1r = 3010, TEC1s = 3011,
62  TEC2r = 3020, TEC2s = 3021,
63  TEC3r = 3030, TEC3s = 3031,
64  TEC4r = 3040, TEC4s = 3041,
65  TEC5r = 3050, TEC5s = 3051,
66  TEC6r = 3060, TEC6s = 3061,
67  TEC7r = 3070, TEC7s = 3071,
68  TEC8r = 3080, TEC8s = 3081,
69  TEC9r = 3090, TEC9s = 3091,
70  TID1r = 4010, TID1s = 4011,
71  TID2r = 4020, TID2s = 4021,
72  TID3r = 4030, TID3s = 4031,
74  };
75 
76  /*--------------------------------------------------------------------*/
77  std::pair<int,const char *> regionType(int index)
78  /*--------------------------------------------------------------------*/
79  {
80 
81  auto region = static_cast<std::underlying_type_t<SiStripPI::TrackerRegion> >(index);
82 
83  switch(region){
84  case SiStripPI::TIB1r: return std::make_pair(1 ,"TIB L1 r-#varphi");
85  case SiStripPI::TIB1s: return std::make_pair(2 ,"TIB L1 stereo");
86  case SiStripPI::TIB2r: return std::make_pair(3 ,"TIB L2 r-#varphi");
87  case SiStripPI::TIB2s: return std::make_pair(4 ,"TIB L2 stereo");
88  case SiStripPI::TIB3r: return std::make_pair(5 ,"TIB L3");
89  case SiStripPI::TIB4r: return std::make_pair(6 ,"TIB L4");
90  case SiStripPI::TOB1r: return std::make_pair(7 ,"TOB L1 r-#varphi");
91  case SiStripPI::TOB1s: return std::make_pair(8 ,"TOB L1 stereo");
92  case SiStripPI::TOB2r: return std::make_pair(9 ,"TOB L2 r-#varphi");
93  case SiStripPI::TOB2s: return std::make_pair(10,"TOB L2 stereo");
94  case SiStripPI::TOB3r: return std::make_pair(11,"TOB L3 r-#varphi");
95  case SiStripPI::TOB4r: return std::make_pair(12,"TOB L4");
96  case SiStripPI::TOB5r: return std::make_pair(13,"TOB L5");
97  case SiStripPI::TOB6r: return std::make_pair(14,"TOB L6");
98  case SiStripPI::TEC1r: return std::make_pair(15,"TEC D1 r-#varphi");
99  case SiStripPI::TEC1s: return std::make_pair(16,"TEC D1 stereo");
100  case SiStripPI::TEC2r: return std::make_pair(17,"TEC D2 r-#varphi");
101  case SiStripPI::TEC2s: return std::make_pair(18,"TEC D2 stereo");
102  case SiStripPI::TEC3r: return std::make_pair(19,"TEC D3 r-#varphi");
103  case SiStripPI::TEC3s: return std::make_pair(20,"TEC D3 stereo");
104  case SiStripPI::TEC4r: return std::make_pair(21,"TEC D4 r-#varphi");
105  case SiStripPI::TEC4s: return std::make_pair(22,"TEC D4 stereo");
106  case SiStripPI::TEC5r: return std::make_pair(23,"TEC D5 r-#varphi");
107  case SiStripPI::TEC5s: return std::make_pair(24,"TEC D5 stereo");
108  case SiStripPI::TEC6r: return std::make_pair(25,"TEC D6 r-#varphi");
109  case SiStripPI::TEC6s: return std::make_pair(26,"TEC D6 stereo");
110  case SiStripPI::TEC7r: return std::make_pair(27,"TEC D7 r-#varphi");
111  case SiStripPI::TEC7s: return std::make_pair(28,"TEC D7 stereo");
112  case SiStripPI::TEC8r: return std::make_pair(29,"TEC D8 r-#varphi");
113  case SiStripPI::TEC8s: return std::make_pair(30,"TEC D8 stereo");
114  case SiStripPI::TEC9r: return std::make_pair(31,"TEC D9 r-#varphi");
115  case SiStripPI::TEC9s: return std::make_pair(32,"TEC D9 stereo");
116  case SiStripPI::TID1r: return std::make_pair(33,"TID D1 r-#varphi");
117  case SiStripPI::TID1s: return std::make_pair(34,"TID D1 stereo");
118  case SiStripPI::TID2r: return std::make_pair(35,"TID D2 r-#varphi");
119  case SiStripPI::TID2s: return std::make_pair(36,"TID D2 stereo");
120  case SiStripPI::TID3r: return std::make_pair(37,"TID D3 r-#varphi");
121  case SiStripPI::TID3s: return std::make_pair(38,"TID D3 stereo");
122  case SiStripPI::END_OF_REGIONS : std::make_pair(-1,"undefined");
123  default : return std::make_pair(999,"should never be here");
124  }
125  }
126 
127  /*--------------------------------------------------------------------*/
128  std::pair<float,float> getTheRange(std::map<uint32_t,float> values,const float nsigma)
129  /*--------------------------------------------------------------------*/
130  {
131  float sum = std::accumulate(std::begin(values),
132  std::end(values),
133  0.0,
134  [] (float value, const std::map<uint32_t,float>::value_type& p)
135  { return value + p.second; }
136  );
137 
138  float m = sum / values.size();
139 
140  float accum = 0.0;
141  std::for_each (std::begin(values),
142  std::end(values),
144  {accum += (p.second - m) * (p.second - m);}
145  );
146 
147  float stdev = sqrt(accum / (values.size()-1));
148 
149  if(stdev!=0.){
150  return std::make_pair(m-nsigma*stdev,m+nsigma*stdev);
151  } else {
152  return std::make_pair(m>0.? 0.95*m : 1.05*m, m>0? 1.05*m : 0.95*m);
153  }
154  }
155 
156  /*--------------------------------------------------------------------*/
157  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)
158  /*--------------------------------------------------------------------*/
159  {
160  char buffer[255];
161 
162  int i=0;
163  for ( const auto &element : legend ){
164  TPaveText* stat = new TPaveText(X,Y-(i*H), X+W, Y-(i+1)*H, "NDC");
165  i++;
166  auto Histo = histos[element];
167  sprintf(buffer,"Entries : %i\n",(int)Histo->GetEntries());
168  stat->AddText(buffer);
169 
170  sprintf(buffer,"Mean : %6.2f\n",Histo->GetMean());
171  stat->AddText(buffer);
172 
173  sprintf(buffer,"RMS : %6.2f\n",Histo->GetRMS());
174  stat->AddText(buffer);
175 
176  stat->SetFillColor(0);
177  stat->SetLineColor(colormap[element]);
178  stat->SetTextColor(colormap[element]);
179  stat->SetTextSize(0.03);
180  stat->SetBorderSize(0);
181  stat->SetMargin(0.05);
182  stat->SetTextAlign(12);
183  stat->Draw();
184  }
185  }
186 
187  /*--------------------------------------------------------------------*/
188  std::pair<float,float> getExtrema(TH1 *h1,TH1 *h2)
189  /*--------------------------------------------------------------------*/
190  {
191  float theMax(-9999.);
192  float theMin(9999.);
193  theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
194  theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
195 
196  float add_min = theMin>0. ? -0.05 : 0.05;
197  float add_max = theMax>0. ? 0.05 : -0.05;
198 
199  auto result = std::make_pair(theMin*(1+add_min),theMax*(1+add_max));
200  return result;
201 
202  }
203 
204 
205  /*--------------------------------------------------------------------*/
207  /*--------------------------------------------------------------------*/
208  {
209  hist->SetStats(kFALSE);
210  hist->SetLineWidth(2);
211  hist->GetXaxis()->CenterTitle(true);
212  hist->GetYaxis()->CenterTitle(true);
213  hist->GetXaxis()->SetTitleFont(42);
214  hist->GetYaxis()->SetTitleFont(42);
215  hist->GetXaxis()->SetTitleSize(0.05);
216  hist->GetYaxis()->SetTitleSize(0.05);
217  hist->GetXaxis()->SetTitleOffset(0.9);
218  hist->GetYaxis()->SetTitleOffset(1.3);
219  hist->GetXaxis()->SetLabelFont(42);
220  hist->GetYaxis()->SetLabelFont(42);
221  hist->GetYaxis()->SetLabelSize(.05);
222  hist->GetXaxis()->SetLabelSize(.05);
223  }
224 
225 
226  /*--------------------------------------------------------------------*/
227  void printSummary(const std::map<unsigned int, SiStripDetSummary::Values>& map)
228  /*--------------------------------------------------------------------*/
229  {
230  for (const auto &element : map){
231  int count = element.second.count;
232  double mean = count>0 ? (element.second.mean)/count : 0. ;
233  double rms = count>0 ? (element.second.rms)/count - mean*mean : 0.;
234  if(rms <= 0)
235  rms = 0;
236  else
237  rms = sqrt(rms);
238 
240 
241  switch ((element.first)/1000)
242  {
243  case 1:
244  detector = "TIB ";
245  break;
246  case 2:
247  detector = "TOB ";
248  break;
249  case 3:
250  detector = "TEC ";
251  break;
252  case 4:
253  detector = "TID ";
254  break;
255  }
256 
257  int layer = (element.first)/10 - (element.first)/1000*100;
258  int stereo = (element.first) - (layer*10) -(element.first)/1000*1000;
259 
260  std::cout<<"key of the map:"<<element.first <<" ( region: "<<regionType(element.first).second <<" ) "
261  << detector<<" layer: "<<layer<<" stereo:"<<stereo
262  <<"| count:"<<count<<" mean: "<<mean<<" rms: "<<rms<<std::endl;
263 
264  }
265  }
266 
267  // code is mutuated from CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics
268 
269  /*--------------------------------------------------------------------*/
270  void setBadComponents(int i, int component, SiStripQuality::BadComponent& BC,int NBadComponent[4][19][4])
271  /*--------------------------------------------------------------------*/
272  {
273 
274  if (BC.BadApvs){
275  NBadComponent[i][0][2]+= std::bitset<16>(BC.BadApvs&0x3f).count();
276  NBadComponent[i][component][2]+= std::bitset<16>(BC.BadApvs&0x3f).count();
277  }
278 
279  if (BC.BadFibers){
280  NBadComponent[i][0][1]+= std::bitset<4>(BC.BadFibers&0x7).count();
281  NBadComponent[i][component][1]+= std::bitset<4>(BC.BadFibers&0x7).count();
282  }
283 
284  if (BC.BadModule){
285  NBadComponent[i][0][0]++;
286  NBadComponent[i][component][0]++;
287  }
288  }
289 
291 
292  /*--------------------------------------------------------------------*/
294  /*--------------------------------------------------------------------*/
295  {
296 
297  TStyle *palettestyle = new TStyle("palettestyle","Style for P-TDR");
298 
299  const int NRGBs = 5;
300  const int NCont = 255;
301 
302  switch(palette){
303 
304  case HALFGRAY:
305  {
306  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
307  double red[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
308  double green[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
309  double blue[NRGBs] = {1.00, 0.91, 0.80, 0.67, 1.00};
310  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
311  }
312  break;
313 
314  case GRAY:
315  {
316  double stops[NRGBs] = {0.00, 0.01, 0.05, 0.09, 0.1};
317  double red[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
318  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
319  double blue[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
320  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
321  }
322  break;
323 
324  case BLUES:
325  {
326  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
327  double red[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
328  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
329  double blue[NRGBs] = {1.00, 1.00, 1.00, 1.00, 1.00};
330  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
331 
332  }
333  break;
334 
335  case REDS:
336  {
337  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
338  double red[NRGBs] = {1.00, 1.00, 1.00, 1.00, 1.00};
339  double green[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
340  double blue[NRGBs] = {1.00, 0.84, 0.61, 0.34, 0.00};
341  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
342  }
343  break;
344 
345  case ANTIGRAY:
346  {
347  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
348  double red[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
349  double green[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
350  double blue[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
351  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
352  }
353  break;
354 
355  case FIRE:
356  {
357  double stops[NRGBs] = {0.00, 0.20, 0.80, 1.00};
358  double red[NRGBs] = {1.00, 1.00, 1.00, 0.50};
359  double green[NRGBs] = {1.00, 1.00, 0.00, 0.00};
360  double blue[NRGBs] = {0.20, 0.00, 0.00, 0.00};
361  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
362  }
363  break;
364 
365  case ANTIFIRE:
366  {
367  double stops[NRGBs] = {0.00, 0.20, 0.80, 1.00};
368  double red[NRGBs] = {0.50, 1.00, 1.00, 1.00};
369  double green[NRGBs] = {0.00, 0.00, 1.00, 1.00};
370  double blue[NRGBs] = {0.00, 0.00, 0.00, 0.20};
371  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
372  }
373  break;
374 
375  case LOGREDBLUE:
376  {
377  double stops[NRGBs] = {0.0001, 0.0010, 0.0100, 0.1000, 1.0000};
378  double red[NRGBs] = {1.00, 0.75, 0.50, 0.25, 0.00};
379  double green[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
380  double blue[NRGBs] = {0.00, 0.25, 0.50, 0.75, 1.00};
381  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
382  }
383  break;
384 
385  case LOGBLUERED:
386  {
387  double stops[NRGBs] = {0.0001, 0.0010, 0.0100, 0.1000, 1.0000};
388  double red[NRGBs] = {0.00, 0.25, 0.50, 0.75, 1.00};
389  double green[NRGBs] = {0.00, 0.00, 0.00, 0.00, 0.00};
390  double blue[NRGBs] = {1.00, 0.75, 0.50, 0.25, 0.00};
391  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
392  }
393  break;
394 
395  case DEFAULT:
396  {
397  double stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
398  double red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
399  double green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
400  double blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
401  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
402  }
403  break;
404  default:
405  std::cout<<"should nevere be here" << std::endl;
406  break;
407  }
408 
409  palettestyle->SetNumberContours(NCont);
410  }
411 
412 };
413 #endif
#define X(str)
Definition: MuonsGrabber.cc:48
void setPaletteStyle(SiStripPI::palette palette)
void printSummary(const std::map< unsigned int, SiStripDetSummary::Values > &map)
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)
T sqrt(T t)
Definition: SSEVec.h:18
void setBadComponents(int i, int component, SiStripQuality::BadComponent &BC, int NBadComponent[4][19][4])
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
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)
def green(string)
#define begin
Definition: vmac.h:32
def stdev(xlist)
Definition: plotscripts.py:67