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"
12 
13 namespace SiStripPI {
14 
15  enum estimator {
16  min,
17  max,
20  };
21 
22  /*--------------------------------------------------------------------*/
24  /*--------------------------------------------------------------------*/
25  {
26  switch(e){
27  case SiStripPI::min : return "minimum";
28  case SiStripPI::max : return "maximum";
29  case SiStripPI::mean : return "mean";
30  case SiStripPI::rms : return "RMS";
31  default: return "should never be here";
32  }
33  }
34 
35  /*--------------------------------------------------------------------*/
37  /*-------------------------------------------------------------------*/
38  {
39  switch(sub){
40  case StripSubdetector::TIB : return "TIB";
41  case StripSubdetector::TOB : return "TOB";
42  case StripSubdetector::TID : return "TID";
43  case StripSubdetector::TEC : return "TEC";
44  default : return "should never be here";
45  }
46  }
47 
48  enum TrackerRegion {
49  TIB1r = 1010, TIB1s = 1011,
50  TIB2r = 1020, TIB2s = 1021,
51  TIB3r = 1030,
52  TIB4r = 1040,
53  TOB1r = 2010, TOB1s = 2011,
54  TOB2r = 2020, TOB2s = 2021,
55  TOB3r = 2030,
56  TOB4r = 2040,
57  TOB5r = 2050,
58  TOB6r = 2060,
59  TEC1r = 3010, TEC1s = 3011,
60  TEC2r = 3020, TEC2s = 3021,
61  TEC3r = 3030, TEC3s = 3031,
62  TEC4r = 3040, TEC4s = 3041,
63  TEC5r = 3050, TEC5s = 3051,
64  TEC6r = 3060, TEC6s = 3061,
65  TEC7r = 3070, TEC7s = 3071,
66  TEC8r = 3080, TEC8s = 3081,
67  TEC9r = 3090, TEC9s = 3091,
68  TID1r = 4010, TID1s = 4011,
69  TID2r = 4020, TID2s = 4021,
70  TID3r = 4030, TID3s = 4031,
72  };
73 
74  /*--------------------------------------------------------------------*/
75  const char * regionType(int index)
76  /*--------------------------------------------------------------------*/
77  {
78 
79  auto region = static_cast<std::underlying_type_t<SiStripPI::TrackerRegion> >(index);
80 
81  switch(region){
82  case SiStripPI::TIB1r: return "TIB L1 r-#varphi";
83  case SiStripPI::TIB1s: return "TIB L1 stereo";
84  case SiStripPI::TIB2r: return "TIB L2 r-#varphi";
85  case SiStripPI::TIB2s: return "TIB L2 stereo";
86  case SiStripPI::TIB3r: return "TIB L3";
87  case SiStripPI::TIB4r: return "TIB L4";
88  case SiStripPI::TOB1r: return "TOB L1 r-#varphi";
89  case SiStripPI::TOB1s: return "TOB L1 stereo";
90  case SiStripPI::TOB2r: return "TOB L2 r-#varphi";
91  case SiStripPI::TOB2s: return "TOB L2 stereo";
92  case SiStripPI::TOB3r: return "TOB L3 r-#varphi";
93  case SiStripPI::TOB4r: return "TOB L4";
94  case SiStripPI::TOB5r: return "TOB L5";
95  case SiStripPI::TOB6r: return "TOB L6";
96  case SiStripPI::TEC1r: return "TEC D1 r-#varphi";
97  case SiStripPI::TEC1s: return "TEC D1 stereo";
98  case SiStripPI::TEC2r: return "TEC D2 r-#varphi";
99  case SiStripPI::TEC2s: return "TEC D2 stereo";
100  case SiStripPI::TEC3r: return "TEC D3 r-#varphi";
101  case SiStripPI::TEC3s: return "TEC D3 stereo";
102  case SiStripPI::TEC4r: return "TEC D4 r-#varphi";
103  case SiStripPI::TEC4s: return "TEC D4 stereo";
104  case SiStripPI::TEC5r: return "TEC D5 r-#varphi";
105  case SiStripPI::TEC5s: return "TEC D5 stereo";
106  case SiStripPI::TEC6r: return "TEC D6 r-#varphi";
107  case SiStripPI::TEC6s: return "TEC D6 stereo";
108  case SiStripPI::TEC7r: return "TEC D7 r-#varphi";
109  case SiStripPI::TEC7s: return "TEC D7 stereo";
110  case SiStripPI::TEC8r: return "TEC D8 r-#varphi";
111  case SiStripPI::TEC8s: return "TEC D8 stereo";
112  case SiStripPI::TEC9r: return "TEC D9 r-#varphi";
113  case SiStripPI::TEC9s: return "TEC D9 stereo";
114  case SiStripPI::TID1r: return "TID D1 r-#varphi";
115  case SiStripPI::TID1s: return "TID D1 stereo";
116  case SiStripPI::TID2r: return "TID D2 r-#varphi";
117  case SiStripPI::TID2s: return "TID D2 stereo";
118  case SiStripPI::TID3r: return "TID D3 r-#varphi";
119  case SiStripPI::TID3s: return "TID D3 stereo";
120  case SiStripPI::END_OF_REGIONS : return "undefined";
121  default : return "should never be here";
122  }
123  }
124 
125  /*--------------------------------------------------------------------*/
126  std::pair<float,float> getTheRange(std::map<uint32_t,float> values)
127  /*--------------------------------------------------------------------*/
128  {
129  float sum = std::accumulate(std::begin(values),
130  std::end(values),
131  0.0,
132  [] (float value, const std::map<uint32_t,float>::value_type& p)
133  { return value + p.second; }
134  );
135 
136  float m = sum / values.size();
137 
138  float accum = 0.0;
139  std::for_each (std::begin(values),
140  std::end(values),
142  {accum += (p.second - m) * (p.second - m);}
143  );
144 
145  float stdev = sqrt(accum / (values.size()-1));
146 
147  return std::make_pair(m-2*stdev,m+2*stdev);
148 
149  }
150 
151  /*--------------------------------------------------------------------*/
152  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)
153  /*--------------------------------------------------------------------*/
154  {
155  char buffer[255];
156 
157  int i=0;
158  for ( const auto &element : legend ){
159  TPaveText* stat = new TPaveText(X,Y-(i*H), X+W, Y-(i+1)*H, "NDC");
160  i++;
161  auto Histo = histos[element];
162  sprintf(buffer,"Entries : %i\n",(int)Histo->GetEntries());
163  stat->AddText(buffer);
164 
165  sprintf(buffer,"Mean : %6.2f\n",Histo->GetMean());
166  stat->AddText(buffer);
167 
168  sprintf(buffer,"RMS : %6.2f\n",Histo->GetRMS());
169  stat->AddText(buffer);
170 
171  stat->SetFillColor(0);
172  stat->SetLineColor(colormap[element]);
173  stat->SetTextColor(colormap[element]);
174  stat->SetTextSize(0.03);
175  stat->SetBorderSize(0);
176  stat->SetMargin(0.05);
177  stat->SetTextAlign(12);
178  stat->Draw();
179  }
180  }
181 
182  /*--------------------------------------------------------------------*/
183  std::pair<float,float> getExtrema(TH1 *h1,TH1 *h2)
184  /*--------------------------------------------------------------------*/
185  {
186  float theMax(-9999.);
187  float theMin(9999.);
188  theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
189  theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
190 
191  float add_min = theMin>0. ? -0.05 : 0.05;
192  float add_max = theMax>0. ? 0.05 : -0.05;
193 
194  auto result = std::make_pair(theMin*(1+add_min),theMax*(1+add_max));
195  return result;
196 
197  }
198 
199 
200  /*--------------------------------------------------------------------*/
202  /*--------------------------------------------------------------------*/
203  {
204  hist->SetStats(kFALSE);
205  hist->SetLineWidth(2);
206  hist->GetXaxis()->CenterTitle(true);
207  hist->GetYaxis()->CenterTitle(true);
208  hist->GetXaxis()->SetTitleFont(42);
209  hist->GetYaxis()->SetTitleFont(42);
210  hist->GetXaxis()->SetTitleSize(0.05);
211  hist->GetYaxis()->SetTitleSize(0.05);
212  hist->GetXaxis()->SetTitleOffset(0.9);
213  hist->GetYaxis()->SetTitleOffset(1.3);
214  hist->GetXaxis()->SetLabelFont(42);
215  hist->GetYaxis()->SetLabelFont(42);
216  hist->GetYaxis()->SetLabelSize(.05);
217  hist->GetXaxis()->SetLabelSize(.05);
218  }
219 
220 
221  /*--------------------------------------------------------------------*/
222  void printSummary(const std::map<unsigned int, SiStripDetSummary::Values>& map)
223  /*--------------------------------------------------------------------*/
224  {
225  for (const auto &element : map){
226  int count = element.second.count;
227  double mean = count>0 ? (element.second.mean)/count : 0. ;
228  double rms = count>0 ? (element.second.rms)/count - mean*mean : 0.;
229  if(rms <= 0)
230  rms = 0;
231  else
232  rms = sqrt(rms);
233 
235 
236  switch ((element.first)/1000)
237  {
238  case 1:
239  detector = "TIB ";
240  break;
241  case 2:
242  detector = "TOB ";
243  break;
244  case 3:
245  detector = "TEC ";
246  break;
247  case 4:
248  detector = "TID ";
249  break;
250  }
251 
252  int layer = (element.first)/10 - (element.first)/1000*100;
253  int stereo = (element.first) - (layer*10) -(element.first)/1000*1000;
254 
255  std::cout<<"key of the map:"<<element.first <<" ( region: "<<regionType(element.first) <<" ) "
256  << detector<<" layer: "<<layer<<" stereo:"<<stereo
257  <<"| count:"<<count<<" mean: "<<mean<<" rms: "<<rms<<std::endl;
258 
259  }
260  }
261 
262  // code is mutuated from CalibTracker/SiStripQuality/plugins/SiStripQualityStatistics
263 
264  /*--------------------------------------------------------------------*/
265  void setBadComponents(int i, int component, SiStripQuality::BadComponent& BC,int NBadComponent[4][19][4])
266  /*--------------------------------------------------------------------*/
267  {
268 
269  if (BC.BadApvs){
270  NBadComponent[i][0][2]+= std::bitset<16>(BC.BadApvs&0x3f).count();
271  NBadComponent[i][component][2]+= std::bitset<16>(BC.BadApvs&0x3f).count();
272  }
273 
274  if (BC.BadFibers){
275  NBadComponent[i][0][1]+= std::bitset<4>(BC.BadFibers&0x7).count();
276  NBadComponent[i][component][1]+= std::bitset<4>(BC.BadFibers&0x7).count();
277  }
278 
279  if (BC.BadModule){
280  NBadComponent[i][0][0]++;
281  NBadComponent[i][component][0]++;
282  }
283  }
284 
285 };
286 
287 #endif
const char * regionType(int index)
std::pair< float, float > getTheRange(std::map< uint32_t, float > values)
#define X(str)
Definition: MuonsGrabber.cc:48
void printSummary(const std::map< unsigned int, SiStripDetSummary::Values > &map)
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:37
std::string getStringFromSubdet(StripSubdetector::SubDetector sub)
Definition: value.py:1
std::string estimatorType(SiStripPI::estimator e)
#define begin
Definition: vmac.h:30
def stdev(xlist)
Definition: plotscripts.py:67