CMS 3D CMS Logo

SiStripNoises_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
19 
20 // needed for the tracker map
22 
23 // auxilliary functions
26 
29 
30 #include <memory>
31 #include <sstream>
32 #include <iostream>
33 
34 // include ROOT
35 #include "TH2F.h"
36 #include "TF1.h"
37 #include "TGraphErrors.h"
38 #include "TLegend.h"
39 #include "TCanvas.h"
40 #include "TLine.h"
41 #include "TStyle.h"
42 #include "TLatex.h"
43 #include "TPave.h"
44 #include "TPaveStats.h"
45 #include "TGaxis.h"
46 
47 namespace {
48 
49  /************************************************
50  test class
51  *************************************************/
52 
53  class SiStripNoisesTest : public cond::payloadInspector::Histogram1D<SiStripNoises> {
54 
55  public:
56  SiStripNoisesTest() : cond::payloadInspector::Histogram1D<SiStripNoises>("SiStrip Noise test",
57  "SiStrip Noise test", 10,0.0,10.0),
58  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
59  {
60  Base::setSingleIov( true );
61  }
62 
63  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
64  for ( auto const & iov: iovs) {
65  std::shared_ptr<SiStripNoises> payload = Base::fetchPayload( std::get<1>(iov) );
66  if( payload.get() ){
67 
68  fillWithValue(1.);
69 
70  std::stringstream ss;
71  ss << "Summary of strips noises:" << std::endl;
72 
73  //payload->printDebug(ss);
74  payload->printSummary(ss,&m_trackerTopo);
75 
76  std::vector<uint32_t> detid;
77  payload->getDetIds(detid);
78 
79  // for (const auto & d : detid) {
80  // int nstrip=0;
81  // SiStripNoises::Range range=payload->getRange(d);
82  // for( int it=0; it < (range.second-range.first)*8/9; ++it ){
83  // auto noise = payload->getNoise(it,range);
84  // nstrip++;
85  // ss << "DetId="<< d << " Strip=" << nstrip <<": "<< noise << std::endl;
86  // } // end of loop on strips
87  // } // end of loop on detIds
88 
89  std::cout<<ss.str()<<std::endl;
90 
91  }// payload
92  }// iovs
93  return true;
94  }// fill
95  private:
96  TrackerTopology m_trackerTopo;
97  };
98 
99  /************************************************
100  1d histogram of SiStripNoises of 1 IOV
101  *************************************************/
102 
103  // inherit from one of the predefined plot class: Histogram1D
104  class SiStripNoiseValue : public cond::payloadInspector::Histogram1D<SiStripNoises> {
105 
106  public:
107  SiStripNoiseValue() : cond::payloadInspector::Histogram1D<SiStripNoises>("SiStrip Noise values",
108  "SiStrip Noise values", 100,0.0,10.0){
109  Base::setSingleIov( true );
110  }
111 
112  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
113  for ( auto const & iov: iovs) {
114  std::shared_ptr<SiStripNoises> payload = Base::fetchPayload( std::get<1>(iov) );
115  if( payload.get() ){
116 
117  std::vector<uint32_t> detid;
118  payload->getDetIds(detid);
119 
120  for (const auto & d : detid) {
121  SiStripNoises::Range range=payload->getRange(d);
122  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
123  auto noise = payload->getNoise(it,range);
124  //to be used to fill the histogram
125  fillWithValue(noise);
126  }// loop over APVs
127  } // loop over detIds
128  }// payload
129  }// iovs
130  return true;
131  }// fill
132  };
133 
134 
135  /************************************************
136  templated 1d histogram of SiStripNoises of 1 IOV
137  *************************************************/
138 
139  // inherit from one of the predefined plot class: PlotImage
140  template<SiStripPI::OpMode op_mode_> class SiStripNoiseDistribution : public cond::payloadInspector::PlotImage<SiStripNoises> {
141 
142  public:
143  SiStripNoiseDistribution() : cond::payloadInspector::PlotImage<SiStripNoises>("SiStrip Noise values"){
144  setSingleIov( true );
145  }
146 
147  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
148  auto iov = iovs.front();
149 
150  TGaxis::SetMaxDigits(3);
151  gStyle->SetOptStat("emr");
152 
153  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
154 
155  auto mon1D = std::unique_ptr<SiStripPI::Monitor1D>(new SiStripPI::Monitor1D(op_mode_,
156  "Noise",
157  Form("#LT Strip Noise #GT per %s for IOV [%s];#LTStrip Noise per %s#GT [ADC counts];n. %ss",
158  opType(op_mode_).c_str(),std::to_string(std::get<0>(iov)).c_str(),opType(op_mode_).c_str(),opType(op_mode_).c_str())
159  ,100,0.1,10.));
160 
161  unsigned int prev_det=0, prev_apv=0;
162  SiStripPI::Entry enoise;
163 
164  std::vector<uint32_t> detids;
165  payload->getDetIds(detids);
166 
167  // loop on payload
168  for (const auto & d : detids) {
169  SiStripNoises::Range range=payload->getRange(d);
170 
171  unsigned int istrip=0;
172 
173  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
174  auto noise = payload->getNoise(it,range);
175  bool flush = false;
176  switch(op_mode_) {
177  case (SiStripPI::APV_BASED):
178  flush = (prev_det != 0 && prev_apv != istrip/128);
179  break;
181  flush = (prev_det != 0 && prev_det != d);
182  break;
183  case (SiStripPI::STRIP_BASED):
184  flush = (istrip != 0);
185  break;
186  }
187 
188  if(flush){
189  mon1D->Fill(prev_apv,prev_det,enoise.mean());
190  enoise.reset();
191  }
192 
193  enoise.add(std::min<float>(noise, 30.5));
194  prev_apv = istrip/128;
195  istrip++;
196  }
197  prev_det = d;
198  }
199 
200  //=========================
201  TCanvas canvas("Partion summary","partition summary",1200,1000);
202  canvas.cd();
203  canvas.SetBottomMargin(0.11);
204  canvas.SetTopMargin(0.07);
205  canvas.SetLeftMargin(0.13);
206  canvas.SetRightMargin(0.05);
207  canvas.Modified();
208 
209  auto hist = mon1D->getHist();
211  hist.SetStats(kTRUE);
212  hist.SetFillColorAlpha(kRed,0.35);
213  hist.Draw();
214 
215  canvas.Update();
216 
217  TPaveStats *st = (TPaveStats*)hist.GetListOfFunctions()->FindObject("stats");
218  st->SetLineColor(kRed);
219  st->SetTextColor(kRed);
220  st->SetX1NDC(.75); st->SetX2NDC(.95);
221  st->SetY1NDC(.83); st->SetY2NDC(.93);
222 
223  TLegend legend = TLegend(0.13,0.83,0.43,0.93);
224  legend.SetHeader(Form("SiStrip Noise values per %s",opType(op_mode_).c_str()),"C"); // option "C" allows to center the header
225  legend.AddEntry(&hist,("IOV: "+std::to_string(std::get<0>(iov))).c_str(),"F");
226  legend.SetTextSize(0.025);
227  legend.Draw("same");
228 
229  std::string fileName(m_imageFileName);
230  canvas.SaveAs(fileName.c_str());
231 
232  return true;
233 
234  }
235 
237  std::string types[3] = {"Strip","APV","Module"};
238  return types[mode];
239  }
240 
241  };
242 
243  typedef SiStripNoiseDistribution<SiStripPI::STRIP_BASED> SiStripNoiseValuePerStrip;
244  typedef SiStripNoiseDistribution<SiStripPI::APV_BASED> SiStripNoiseValuePerAPV;
245  typedef SiStripNoiseDistribution<SiStripPI::MODULE_BASED> SiStripNoiseValuePerModule;
246 
247  /************************************************
248  template 1d histogram comparison of SiStripNoises of 1 IOV
249  *************************************************/
250 
251  // inherit from one of the predefined plot class: PlotImage
252  template<SiStripPI::OpMode op_mode_> class SiStripNoiseDistributionComparison : public cond::payloadInspector::PlotImage<SiStripNoises> {
253 
254  public:
255  SiStripNoiseDistributionComparison() : cond::payloadInspector::PlotImage<SiStripNoises>("SiStrip Noise values comparison"){
256  setSingleIov( false );
257  }
258 
259  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
260 
261  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
262 
263  // make absolute sure the IOVs are sortd by since
264  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
265  return std::get<0>(t1) < std::get<0>(t2);
266  });
267 
268  auto firstiov = sorted_iovs.front();
269  auto lastiov = sorted_iovs.back();
270 
271  std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
272  std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
273 
274  auto f_mon = std::unique_ptr<SiStripPI::Monitor1D>(new SiStripPI::Monitor1D(op_mode_,
275  "f_Noise",
276  Form("#LT Strip Noise #GT per %s for IOV [%s,%s];#LTStrip Noise per %s#GT [ADC counts];n. %ss",
277  opType(op_mode_).c_str(),std::to_string(std::get<0>(firstiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str(),opType(op_mode_).c_str(),opType(op_mode_).c_str())
278  ,100,0.1,10.));
279 
280  auto l_mon = std::unique_ptr<SiStripPI::Monitor1D>(new SiStripPI::Monitor1D(op_mode_,
281  "l_Noise",
282  Form("#LT Strip Noise #GT per %s for IOV [%s,%s];#LTStrip Noise per %s#GT [ADC counts];n. %ss",
283  opType(op_mode_).c_str(),std::to_string(std::get<0>(lastiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str(),opType(op_mode_).c_str(),opType(op_mode_).c_str())
284  ,100,0.1,10.));
285 
286  unsigned int prev_det=0, prev_apv=0;
287  SiStripPI::Entry enoise;
288 
289  std::vector<uint32_t> f_detid;
290  f_payload->getDetIds(f_detid);
291 
292  // loop on first payload
293  for (const auto & d : f_detid) {
294  SiStripNoises::Range range=f_payload->getRange(d);
295 
296  unsigned int istrip=0;
297  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
298  float noise = f_payload->getNoise(it,range);
299  //to be used to fill the histogram
300 
301  bool flush = false;
302  switch(op_mode_) {
303  case (SiStripPI::APV_BASED):
304  flush = (prev_det != 0 && prev_apv != istrip/128);
305  break;
307  flush = (prev_det != 0 && prev_det != d);
308  break;
309  case (SiStripPI::STRIP_BASED):
310  flush = (istrip != 0);
311  break;
312  }
313 
314  if(flush){
315  f_mon->Fill(prev_apv,prev_det,enoise.mean());
316  enoise.reset();
317  }
318  enoise.add(std::min<float>(noise, 30.5));
319  prev_apv = istrip/128;
320  istrip++;
321  }
322  prev_det = d;
323  }
324 
325  prev_det=0, prev_apv=0;
326  enoise.reset();
327 
328  std::vector<uint32_t> l_detid;
329  l_payload->getDetIds(l_detid);
330 
331  // loop on first payload
332  for (const auto & d : l_detid) {
333  SiStripNoises::Range range=l_payload->getRange(d);
334 
335  unsigned int istrip=0;
336  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
337  float noise = l_payload->getNoise(it,range);
338 
339  bool flush = false;
340  switch(op_mode_) {
341  case (SiStripPI::APV_BASED):
342  flush = (prev_det != 0 && prev_apv != istrip/128);
343  break;
345  flush = (prev_det != 0 && prev_det != d);
346  break;
347  case (SiStripPI::STRIP_BASED):
348  flush = (istrip != 0);
349  break;
350  }
351 
352  if(flush){
353  l_mon->Fill(prev_apv,prev_det,enoise.mean());
354  enoise.reset();
355  }
356 
357  enoise.add(std::min<float>(noise, 30.5));
358  prev_apv = istrip/128;
359  istrip++;
360  }
361  prev_det = d;
362  }
363 
364  auto h_first = f_mon->getHist();
365  h_first.SetStats(kFALSE);
366  auto h_last = l_mon->getHist();
367  h_last.SetStats(kFALSE);
368 
371 
372  h_first.GetYaxis()->CenterTitle(true);
373  h_last.GetYaxis()->CenterTitle(true);
374 
375  h_first.GetXaxis()->CenterTitle(true);
376  h_last.GetXaxis()->CenterTitle(true);
377 
378  h_first.SetLineWidth(2);
379  h_last.SetLineWidth(2);
380 
381  h_first.SetLineColor(kBlack);
382  h_last.SetLineColor(kBlue);
383 
384  //=========================
385  TCanvas canvas("Partion summary","partition summary",1200,1000);
386  canvas.cd();
387  canvas.SetBottomMargin(0.11);
388  canvas.SetLeftMargin(0.13);
389  canvas.SetRightMargin(0.05);
390  canvas.Modified();
391 
392  float theMax = (h_first.GetMaximum() > h_last.GetMaximum()) ? h_first.GetMaximum() : h_last.GetMaximum();
393 
394  h_first.SetMaximum(theMax*1.30);
395  h_last.SetMaximum(theMax*1.30);
396 
397  h_first.Draw();
398  h_last.Draw("same");
399 
400  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
401  legend.SetHeader("SiStrip Noise comparison","C"); // option "C" allows to center the header
402  legend.AddEntry(&h_first,("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"F");
403  legend.AddEntry(&h_last, ("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"F");
404  legend.SetTextSize(0.025);
405  legend.Draw("same");
406 
407  std::string fileName(m_imageFileName);
408  canvas.SaveAs(fileName.c_str());
409 
410  return true;
411 
412  }
413 
415  std::string types[3] = {"Strip","APV","Module"};
416  return types[mode];
417  }
418 
419  };
420 
421  typedef SiStripNoiseDistributionComparison<SiStripPI::STRIP_BASED> SiStripNoiseValueComparisonPerStrip;
422  typedef SiStripNoiseDistributionComparison<SiStripPI::APV_BASED> SiStripNoiseValueComparisonPerAPV;
423  typedef SiStripNoiseDistributionComparison<SiStripPI::MODULE_BASED> SiStripNoiseValueComparisonPerModule;
424 
425 
426  /************************************************
427  1d histogram comparison of SiStripNoises of 1 IOV
428  *************************************************/
429 
430  // inherit from one of the predefined plot class: PlotImage
431  class SiStripNoiseValueComparison : public cond::payloadInspector::PlotImage<SiStripNoises> {
432 
433  public:
434  SiStripNoiseValueComparison() : cond::payloadInspector::PlotImage<SiStripNoises>("SiStrip Noise values comparison"){
435  setSingleIov( false );
436  }
437 
438  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
439 
440  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
441 
442  // make absolute sure the IOVs are sortd by since
443  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
444  return std::get<0>(t1) < std::get<0>(t2);
445  });
446 
447  auto firstiov = sorted_iovs.front();
448  auto lastiov = sorted_iovs.back();
449 
450  std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
451  std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
452 
453  auto h_first = std::unique_ptr<TH1F>(new TH1F("f_Noise",Form("Strip noise values comparison [%s,%s];Strip Noise [ADC counts];n. strips",std::to_string(std::get<0>(firstiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str()),100,0.1,10.));
454  h_first->SetStats(false);
455 
456  auto h_last = std::unique_ptr<TH1F>(new TH1F("l_Noise",Form("Strip noise values comparison [%s,%s];Strip Noise [ADC counts];n. strips",std::to_string(std::get<0>(firstiov)).c_str(),std::to_string(std::get<0>(lastiov)).c_str()),100,0.1,10.));
457  h_last->SetStats(false);
458 
459  std::vector<uint32_t> f_detid;
460  f_payload->getDetIds(f_detid);
461 
462  // loop on first payload
463  for (const auto & d : f_detid) {
464  SiStripNoises::Range range=f_payload->getRange(d);
465  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
466  float noise = f_payload->getNoise(it,range);
467  //to be used to fill the histogram
468  h_first->Fill(noise);
469  }// loop over strips
470  }
471 
472  std::vector<uint32_t> l_detid;
473  l_payload->getDetIds(l_detid);
474 
475  // loop on first payload
476  for (const auto & d : l_detid) {
477  SiStripNoises::Range range=l_payload->getRange(d);
478  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
479  float noise = l_payload->getNoise(it,range);
480  //to be used to fill the histogram
481  h_last->Fill(noise);
482  }// loop over strips
483  }
484 
485 
486  h_first->GetYaxis()->CenterTitle(true);
487  h_last->GetYaxis()->CenterTitle(true);
488 
489  h_first->GetXaxis()->CenterTitle(true);
490  h_last->GetXaxis()->CenterTitle(true);
491 
492  h_first->SetLineWidth(2);
493  h_last->SetLineWidth(2);
494 
495  h_first->SetLineColor(kBlack);
496  h_last->SetLineColor(kBlue);
497 
498  //=========================
499  TCanvas canvas("Partion summary","partition summary",1200,1000);
500  canvas.cd();
501  canvas.SetBottomMargin(0.11);
502  canvas.SetLeftMargin(0.13);
503  canvas.SetRightMargin(0.05);
504  canvas.Modified();
505 
506  float theMax = (h_first->GetMaximum() > h_last->GetMaximum()) ? h_first->GetMaximum() : h_last->GetMaximum();
507 
508  h_first->SetMaximum(theMax*1.30);
509  h_last->SetMaximum(theMax*1.30);
510 
511  h_first->Draw();
512  h_last->Draw("same");
513 
514  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
515  legend.SetHeader("SiStrip Noise comparison","C"); // option "C" allows to center the header
516  legend.AddEntry(h_first.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"F");
517  legend.AddEntry(h_last.get(), ("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"F");
518  legend.SetTextSize(0.025);
519  legend.Draw("same");
520 
521  std::string fileName(m_imageFileName);
522  canvas.SaveAs(fileName.c_str());
523 
524  return true;
525 
526  }
527  };
528 
529  /************************************************
530  SiStrip Noise Tracker Map
531  *************************************************/
532 
533  template<SiStripPI::estimator est> class SiStripNoiseTrackerMap : public cond::payloadInspector::PlotImage<SiStripNoises> {
534 
535  public:
536  SiStripNoiseTrackerMap() : cond::payloadInspector::PlotImage<SiStripNoises> ( "Tracker Map of SiStripNoise "+estimatorType(est)+" per module" )
537  {
538  setSingleIov( true );
539  }
540 
541  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
542  auto iov = iovs.front();
543  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
544 
545  std::string titleMap = "Tracker Map of Noise "+estimatorType(est)+" per module (payload : "+std::get<1>(iov)+")";
546 
547  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripNoises"));
548  tmap->setTitle(titleMap);
549  tmap->setPalette(1);
550 
551  // storage of info
552  std::map<unsigned int,float> info_per_detid;
553 
554  SiStripNoises::RegistryIterator rit=payload->getRegistryVectorBegin(), erit=payload->getRegistryVectorEnd();
555  uint16_t Nstrips;
556  std::vector<float> vstripnoise;
557  double mean,rms,min, max;
558  for(;rit!=erit;++rit){
559  Nstrips = (rit->iend-rit->ibegin)*8/9; //number of strips = number of chars * char size / strip noise size
560  vstripnoise.resize(Nstrips);
561  payload->allNoises(vstripnoise,make_pair(payload->getDataVectorBegin()+rit->ibegin,payload->getDataVectorBegin()+rit->iend));
562  mean=0; rms=0; min=10000; max=0;
563 
564  DetId detId(rit->detid);
565 
566  for(size_t i=0;i<Nstrips;++i){
567  mean+=vstripnoise[i];
568  rms+=vstripnoise[i]*vstripnoise[i];
569  if(vstripnoise[i]<min) min=vstripnoise[i];
570  if(vstripnoise[i]>max) max=vstripnoise[i];
571  }
572 
573  mean/=Nstrips;
574  if((rms/Nstrips-mean*mean)>0.){
575  rms = sqrt(rms/Nstrips-mean*mean);
576  } else {
577  rms=0.;
578  }
579 
580  switch(est){
581  case SiStripPI::min:
582  info_per_detid[rit->detid]=min;
583  break;
584  case SiStripPI::max:
585  info_per_detid[rit->detid]=max;
586  break;
587  case SiStripPI::mean:
588  info_per_detid[rit->detid]=mean;
589  break;
590  case SiStripPI::rms:
591  info_per_detid[rit->detid]=rms;
592  break;
593  default:
594  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
595  break;
596  }
597  }
598 
599 
600  // loop on the map
601  for (const auto &item : info_per_detid){
602  tmap->fill(item.first,item.second);
603  }
604 
605  auto range = SiStripPI::getTheRange(info_per_detid,2);
606 
607  //=========================
608 
609  std::string fileName(m_imageFileName);
610  if(est==SiStripPI::rms && (range.first<0.)){
611  tmap->save(true,0.,range.second,fileName);
612  } else {
613  tmap->save(true,range.first,range.second,fileName);
614  }
615 
616  return true;
617  }
618  };
619 
620  typedef SiStripNoiseTrackerMap<SiStripPI::min> SiStripNoiseMin_TrackerMap;
621  typedef SiStripNoiseTrackerMap<SiStripPI::max> SiStripNoiseMax_TrackerMap;
622  typedef SiStripNoiseTrackerMap<SiStripPI::mean> SiStripNoiseMean_TrackerMap;
623  typedef SiStripNoiseTrackerMap<SiStripPI::rms> SiStripNoiseRMS_TrackerMap;
624 
625 
626 
627  /************************************************
628  SiStrip Noise Tracker Map (ratio with previous gain per detid)
629  *************************************************/
630  template<SiStripPI::estimator est,int nsigma> class SiStripNoiseRatioWithPreviousIOVTrackerMap : public cond::payloadInspector::PlotImage<SiStripNoises> {
631  public:
632  SiStripNoiseRatioWithPreviousIOVTrackerMap() : cond::payloadInspector::PlotImage<SiStripNoises>( "Tracker Map of ratio of SiStripNoises "+estimatorType(est)+ "with previous IOV"){
633  setSingleIov( false );
634  }
635 
636  std::map<unsigned int,float>computeEstimator(std::shared_ptr<SiStripNoises> payload){
637 
638  std::map<unsigned int,float> info_per_detid;
639  SiStripNoises::RegistryIterator rit=payload->getRegistryVectorBegin(), erit=payload->getRegistryVectorEnd();
640  uint16_t Nstrips;
641  std::vector<float> vstripnoise;
642  double mean,rms,min, max;
643  for(;rit!=erit;++rit){
644  Nstrips = (rit->iend-rit->ibegin)*8/9; //number of strips = number of chars * char size / strip noise size
645  vstripnoise.resize(Nstrips);
646  payload->allNoises(vstripnoise,make_pair(payload->getDataVectorBegin()+rit->ibegin,payload->getDataVectorBegin()+rit->iend));
647  mean=0; rms=0; min=10000; max=0;
648 
649  DetId detId(rit->detid);
650 
651  for(size_t i=0;i<Nstrips;++i){
652  mean+=vstripnoise[i];
653  rms+=vstripnoise[i]*vstripnoise[i];
654  if(vstripnoise[i]<min) min=vstripnoise[i];
655  if(vstripnoise[i]>max) max=vstripnoise[i];
656  }
657 
658  mean/=Nstrips;
659  if((rms/Nstrips-mean*mean)>0.){
660  rms = sqrt(rms/Nstrips-mean*mean);
661  } else {
662  rms=0.;
663  }
664  switch(est){
665  case SiStripPI::min:
666  info_per_detid[rit->detid]=min;
667  break;
668  case SiStripPI::max:
669  info_per_detid[rit->detid]=max;
670  break;
671  case SiStripPI::mean:
672  info_per_detid[rit->detid]=mean;
673  break;
674  case SiStripPI::rms:
675  info_per_detid[rit->detid]=rms;
676  break;
677  default:
678  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
679  break;
680  }
681  }
682  return info_per_detid;
683  }
684 
685 
686 
687  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
688 
689  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
690 
691  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
692  return std::get<0>(t1) < std::get<0>(t2); //J: ???????
693  });
694 
695  auto firstiov = sorted_iovs.front();
696  auto lastiov = sorted_iovs.back();
697 
698  std::shared_ptr<SiStripNoises> last_payload = fetchPayload( std::get<1>(lastiov) );
699  std::shared_ptr<SiStripNoises> first_payload = fetchPayload( std::get<1>(firstiov) );
700 
701  std::string titleMap = "SiStripNoise " +estimatorType(est)+ " ratio per module average (IOV: ";
702 
703  titleMap+=std::to_string(std::get<0>(firstiov));
704  titleMap+="/ IOV:";
705  titleMap+=std::to_string(std::get<0>(lastiov));
706  titleMap+=")";
707 
708  titleMap+=+" "+std::to_string(nsigma)+" std. dev. saturation";
709 
710 
711  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripNoises"));
712  tmap->setTitle(titleMap);
713  tmap->setPalette(1);
714 
715 
716  std::map<unsigned int,float> map_first,map_second;
717 
718  map_first = computeEstimator(first_payload);
719  map_second = computeEstimator(last_payload);
720  std::map<unsigned int,float> cachedRatio;
721 
722  for (auto entry : map_first){
723  auto it2 = map_second.find(entry.first);
724  if (it2==map_second.end() || it2->second==0) continue;
725  tmap->fill(entry.first,entry.second/it2->second);
726  cachedRatio[entry.first]=(entry.second/it2->second);
727  }
728 
729  auto range = SiStripPI::getTheRange(cachedRatio,nsigma);
730  std::string fileName(m_imageFileName);
731  if(est==SiStripPI::rms && (range.first<0.)){
732  tmap->save(true,0.,range.second,fileName);
733  } else {
734  tmap->save(true,range.first,range.second,fileName);
735  }
736 
737  return true;
738 
739  }
740  };
741 
742  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::min,1> SiStripNoiseMin_RatioWithPreviousIOV1sigmaTrackerMap;
743  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::max,1> SiStripNoiseMax_RatioWithPreviousIOV1sigmaTrackerMap;
744  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::mean,1> SiStripNoiseMean_RatioWithPreviousIOV1sigmaTrackerMap;
745  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::rms,1> SiStripNoiseRms_RatioWithPreviousIOV1sigmaTrackerMap;
746  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::min,2> SiStripNoiseMin_RatioWithPreviousIOV2sigmaTrackerMap;
747  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::max,2> SiStripNoiseMax_RatioWithPreviousIOV2sigmaTrackerMap;
748  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::mean,2> SiStripNoiseMean_RatioWithPreviousIOV2sigmaTrackerMap;
749  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::rms,2> SiStripNoiseRms_RatioWithPreviousIOV2sigmaTrackerMap;
750  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::min,3> SiStripNoiseMin_RatioWithPreviousIOV3sigmaTrackerMap;
751  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::max,3> SiStripNoiseMax_RatioWithPreviousIOV3sigmaTrackerMap;
752  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::mean,3> SiStripNoiseMean_RatioWithPreviousIOV3sigmaTrackerMap;
753  typedef SiStripNoiseRatioWithPreviousIOVTrackerMap<SiStripPI::rms,3> SiStripNoiseRms_RatioWithPreviousIOV3sigmaTrackerMap;
754 
755  /************************************************
756  SiStrip Noise Tracker Summaries
757  *************************************************/
758 
759  template<SiStripPI::estimator est> class SiStripNoiseByRegion : public cond::payloadInspector::PlotImage<SiStripNoises> {
760  public:
761  SiStripNoiseByRegion() : cond::payloadInspector::PlotImage<SiStripNoises>( "SiStrip Noise "+estimatorType(est)+" by Region" ),
762  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
763  {
764  setSingleIov( true );
765  }
766 
767  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
768  auto iov = iovs.front();
769  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
770 
771  SiStripDetSummary summaryNoise{&m_trackerTopo};
772 
773  SiStripPI::fillNoiseDetSummary(summaryNoise,payload,est);
774 
775  std::map<unsigned int, SiStripDetSummary::Values> map = summaryNoise.getCounts();
776  //=========================
777 
778  TCanvas canvas("Partion summary","partition summary",1200,1000);
779  canvas.cd();
780  auto h1 = std::unique_ptr<TH1F>(new TH1F("byRegion",Form("Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",estimatorType(est).c_str(),estimatorType(est).c_str()),map.size(),0.,map.size()));
781  h1->SetStats(false);
782  canvas.SetBottomMargin(0.18);
783  canvas.SetLeftMargin(0.17);
784  canvas.SetRightMargin(0.05);
785  canvas.Modified();
786 
787  std::vector<int> boundaries;
788  unsigned int iBin=0;
789 
791  std::string currentDetector;
792 
793  for (const auto &element : map){
794  iBin++;
795  int count = element.second.count;
796  double mean = (element.second.mean)/count;
797  double rms = (element.second.rms)/count - mean*mean;
798 
799  if(rms <= 0)
800  rms = 0;
801  else
802  rms = sqrt(rms);
803 
804  if(currentDetector.empty()) currentDetector="TIB";
805 
806  switch ((element.first)/1000)
807  {
808  case 1:
809  detector = "TIB";
810  break;
811  case 2:
812  detector = "TOB";
813  break;
814  case 3:
815  detector = "TEC";
816  break;
817  case 4:
818  detector = "TID";
819  break;
820  }
821 
822  h1->SetBinContent(iBin,mean);
823  h1->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
824  h1->GetXaxis()->LabelsOption("v");
825 
826  if(detector!=currentDetector) {
827  boundaries.push_back(iBin);
828  currentDetector=detector;
829  }
830  }
831 
832  h1->SetMarkerStyle(20);
833  h1->SetMarkerSize(1);
834  h1->SetMaximum(h1->GetMaximum()*1.1);
835  h1->Draw("HIST");
836  h1->Draw("Psame");
837 
838  canvas.Update();
839 
840  TLine l[boundaries.size()];
841  unsigned int i=0;
842  for (const auto & line : boundaries){
843  l[i] = TLine(h1->GetBinLowEdge(line),canvas.GetUymin(),h1->GetBinLowEdge(line),canvas.GetUymax());
844  l[i].SetLineWidth(1);
845  l[i].SetLineStyle(9);
846  l[i].SetLineColor(2);
847  l[i].Draw("same");
848  i++;
849  }
850 
851  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
852  legend.SetHeader((std::get<1>(iov)).c_str(),"C"); // option "C" allows to center the header
853  legend.AddEntry(h1.get(),("IOV: "+std::to_string(std::get<0>(iov))).c_str(),"PL");
854  legend.SetTextSize(0.025);
855  legend.Draw("same");
856 
857  std::string fileName(m_imageFileName);
858  canvas.SaveAs(fileName.c_str());
859 
860  return true;
861  }
862  private:
863  TrackerTopology m_trackerTopo;
864  };
865 
866  typedef SiStripNoiseByRegion<SiStripPI::mean> SiStripNoiseMeanByRegion;
867  typedef SiStripNoiseByRegion<SiStripPI::min> SiStripNoiseMinByRegion;
868  typedef SiStripNoiseByRegion<SiStripPI::max> SiStripNoiseMaxByRegion;
869  typedef SiStripNoiseByRegion<SiStripPI::rms> SiStripNoiseRMSByRegion;
870 
871  /************************************************
872  SiStrip Noise Comparator
873  *************************************************/
874 
875  template<SiStripPI::estimator est> class SiStripNoiseComparatorByRegion : public cond::payloadInspector::PlotImage<SiStripNoises> {
876  public:
877  SiStripNoiseComparatorByRegion() : cond::payloadInspector::PlotImage<SiStripNoises>( "SiStrip Noise "+estimatorType(est)+" comparator by Region" ),
878  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
879  {
880  setSingleIov( false );
881  }
882 
883  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
884 
885  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
886 
887  // make absolute sure the IOVs are sortd by since
888  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
889  return std::get<0>(t1) < std::get<0>(t2);
890  });
891 
892  auto firstiov = sorted_iovs.front();
893  auto lastiov = sorted_iovs.back();
894 
895  std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
896  std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
897 
898  SiStripDetSummary f_summaryNoise{&m_trackerTopo};
899  SiStripDetSummary l_summaryNoise{&m_trackerTopo};
900 
901  SiStripPI::fillNoiseDetSummary(f_summaryNoise,f_payload,est);
902  SiStripPI::fillNoiseDetSummary(l_summaryNoise,l_payload,est);
903 
904  std::map<unsigned int, SiStripDetSummary::Values> f_map = f_summaryNoise.getCounts();
905  std::map<unsigned int, SiStripDetSummary::Values> l_map = l_summaryNoise.getCounts();
906 
907  //=========================
908  TCanvas canvas("Partion summary","partition summary",1200,1000);
909  canvas.cd();
910 
911  auto hfirst = std::unique_ptr<TH1F>(new TH1F("f_byRegion",Form("Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",estimatorType(est).c_str(),estimatorType(est).c_str()),f_map.size(),0.,f_map.size()));
912  hfirst->SetStats(false);
913 
914  auto hlast = std::unique_ptr<TH1F>(new TH1F("l_byRegion",Form("Average by partition of %s SiStrip Noise per module;;average SiStrip Noise %s [ADC counts]",estimatorType(est).c_str(),estimatorType(est).c_str()),l_map.size(),0.,l_map.size()));
915  hlast->SetStats(false);
916 
917  canvas.SetBottomMargin(0.18);
918  canvas.SetLeftMargin(0.17);
919  canvas.SetRightMargin(0.05);
920  canvas.Modified();
921 
922  std::vector<int> boundaries;
923  unsigned int iBin=0;
924 
926  std::string currentDetector;
927 
928  for (const auto &element : f_map){
929  iBin++;
930  int count = element.second.count;
931  double mean = (element.second.mean)/count;
932  double rms = (element.second.rms)/count - mean*mean;
933 
934  if(rms <= 0)
935  rms = 0;
936  else
937  rms = sqrt(rms);
938 
939  if(currentDetector.empty()) currentDetector="TIB";
940 
941  switch ((element.first)/1000)
942  {
943  case 1:
944  detector = "TIB";
945  break;
946  case 2:
947  detector = "TOB";
948  break;
949  case 3:
950  detector = "TEC";
951  break;
952  case 4:
953  detector = "TID";
954  break;
955  }
956 
957  hfirst->SetBinContent(iBin,mean);
958  //hfirst->SetBinError(iBin,rms);
959  hfirst->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
960  hfirst->GetXaxis()->LabelsOption("v");
961 
962  if(detector!=currentDetector) {
963  boundaries.push_back(iBin);
964  currentDetector=detector;
965  }
966  }
967 
968  // second payload
969  // reset the counter
970  iBin=0;
971  for (const auto &element : l_map){
972  iBin++;
973  int count = element.second.count;
974  double mean = (element.second.mean)/count;
975  double rms = (element.second.rms)/count - mean*mean;
976 
977  if(rms <= 0)
978  rms = 0;
979  else
980  rms = sqrt(rms);
981 
982  hlast->SetBinContent(iBin,mean);
983  //hlast->SetBinError(iBin,rms);
984  hlast->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
985  hlast->GetXaxis()->LabelsOption("v");
986  }
987 
988  float theMax = (hfirst->GetMaximum() > hlast->GetMaximum()) ? hfirst->GetMaximum() : hlast->GetMaximum();
989  float theMin = (hfirst->GetMinimum() < hlast->GetMinimum()) ? hfirst->GetMinimum() : hlast->GetMinimum();
990 
991  hfirst->SetMarkerStyle(20);
992  hfirst->SetMarkerSize(1);
993  hfirst->GetYaxis()->SetTitleOffset(1.3);
994  hfirst->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
995  hfirst->Draw("HIST");
996  hfirst->Draw("Psame");
997 
998  hlast->SetMarkerStyle(21);
999  hlast->SetMarkerSize(1);
1000  hlast->SetMarkerColor(kBlue);
1001  hlast->SetLineColor(kBlue);
1002  hlast->GetYaxis()->SetTitleOffset(1.3);
1003  hlast->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
1004  hlast->Draw("HISTsame");
1005  hlast->Draw("Psame");
1006 
1007  canvas.Update();
1008 
1009  TLine l[boundaries.size()];
1010  unsigned int i=0;
1011  for (const auto & line : boundaries){
1012  l[i] = TLine(hfirst->GetBinLowEdge(line),canvas.GetUymin(),hfirst->GetBinLowEdge(line),canvas.GetUymax());
1013  l[i].SetLineWidth(1);
1014  l[i].SetLineStyle(9);
1015  l[i].SetLineColor(2);
1016  l[i].Draw("same");
1017  i++;
1018  }
1019 
1020  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
1021  legend.SetHeader(("SiStrip Noise "+estimatorType(est)+" by region").c_str(),"C"); // option "C" allows to center the header
1022  legend.AddEntry(hfirst.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"PL");
1023  legend.AddEntry(hlast.get(), ("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"PL");
1024  legend.SetTextSize(0.025);
1025  legend.Draw("same");
1026 
1027  std::string fileName(m_imageFileName);
1028  canvas.SaveAs(fileName.c_str());
1029 
1030  return true;
1031  }
1032  private:
1033  TrackerTopology m_trackerTopo;
1034  };
1035 
1036  typedef SiStripNoiseComparatorByRegion<SiStripPI::mean> SiStripNoiseComparatorMeanByRegion;
1037  typedef SiStripNoiseComparatorByRegion<SiStripPI::min> SiStripNoiseComparatorMinByRegion;
1038  typedef SiStripNoiseComparatorByRegion<SiStripPI::max> SiStripNoiseComparatorMaxByRegion;
1039  typedef SiStripNoiseComparatorByRegion<SiStripPI::rms> SiStripNoiseComparatorRMSByRegion;
1040 
1041  /************************************************
1042  Noise linearity
1043  *************************************************/
1044  class SiStripNoiseLinearity : public cond::payloadInspector::PlotImage<SiStripNoises> {
1045  public:
1046  SiStripNoiseLinearity() : cond::payloadInspector::PlotImage<SiStripNoises>( "Linearity of Strip Noise as a fuction of strip length" ){
1047  setSingleIov( true );
1048  }
1049 
1050  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
1051  auto iov = iovs.front();
1052  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
1053 
1054  edm::FileInPath fp_ = edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
1056 
1057  std::vector<uint32_t> detid;
1058  payload->getDetIds(detid);
1059 
1060  std::map<float,std::tuple<int,float,float> > noisePerStripLength;
1061 
1062  for (const auto & d : detid) {
1063  SiStripNoises::Range range=payload->getRange(d);
1064  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
1065  auto noise = payload->getNoise(it,range);
1066  //to be used to fill the histogram
1067  float stripL = reader->getNumberOfApvsAndStripLength(d).second;
1068  std::get<0>(noisePerStripLength[stripL])+=1;
1069  std::get<1>(noisePerStripLength[stripL])+=noise;
1070  std::get<2>(noisePerStripLength[stripL])+=(noise*noise);
1071  }// loop over strips
1072  } // loop over detIds
1073 
1074  TCanvas canvas("Noise linearity","noise linearity",1200,1000);
1075  canvas.cd();
1076 
1077  std::vector<float> x; x.reserve(noisePerStripLength.size());
1078  std::vector<float> y; y.reserve(noisePerStripLength.size());
1079  std::vector<float> ex; ex.reserve(noisePerStripLength.size());
1080  std::vector<float> ey; ey.reserve(noisePerStripLength.size());
1081 
1082  for (const auto &element : noisePerStripLength ){
1083  x.push_back(element.first);
1084  ex.push_back(0.);
1085  float sum = std::get<1>(element.second);
1086  float sum2 = std::get<2>(element.second);
1087  float nstrips = std::get<0>(element.second);
1088  float mean = sum/nstrips;
1089  float rms = (sum2/nstrips-mean*mean)>0. ? sqrt(sum2/nstrips-mean*mean) : 0.;
1090  y.push_back(mean);
1091  ey.push_back(rms);
1092  //std::cout<<" strip lenght: " << element.first << " avg noise=" << mean <<" +/-" << rms << std::endl;
1093  }
1094 
1095  auto graph = std::unique_ptr<TGraphErrors>(new TGraphErrors(noisePerStripLength.size(),&x[0], &y[0],&ex[0],&ey[0]));
1096  graph->SetTitle("SiStrip Noise Linearity");
1097  graph->GetXaxis()->SetTitle("Strip length [cm]");
1098  graph->GetYaxis()->SetTitle("Average Strip Noise [ADC counts]");
1099  graph->SetMarkerColor(kBlue);
1100  graph->SetMarkerStyle(20);
1101  graph->SetMarkerSize(1.5);
1102  canvas.SetBottomMargin(0.13);
1103  canvas.SetLeftMargin(0.17);
1104  canvas.SetTopMargin(0.08);
1105  canvas.SetRightMargin(0.05);
1106  canvas.Modified();
1107  canvas.cd();
1108 
1109  graph->GetXaxis()->CenterTitle(true);
1110  graph->GetYaxis()->CenterTitle(true);
1111  graph->GetXaxis()->SetTitleFont(42);
1112  graph->GetYaxis()->SetTitleFont(42);
1113  graph->GetXaxis()->SetTitleSize(0.05);
1114  graph->GetYaxis()->SetTitleSize(0.05);
1115  graph->GetXaxis()->SetTitleOffset(1.1);
1116  graph->GetYaxis()->SetTitleOffset(1.3);
1117  graph->GetXaxis()->SetLabelFont(42);
1118  graph->GetYaxis()->SetLabelFont(42);
1119  graph->GetYaxis()->SetLabelSize(.05);
1120  graph->GetXaxis()->SetLabelSize(.05);
1121 
1122  graph->Draw("AP");
1123  graph->Fit("pol1");
1124  //Access the fit resuts
1125  TF1 *f1 = graph->GetFunction("pol1");
1126  f1->SetLineWidth(2);
1127  f1->SetLineColor(kBlue);
1128  f1->Draw("same");
1129 
1130  auto fits = std::unique_ptr<TPaveText>(new TPaveText(0.2,0.72,0.6,0.9,"NDC"));
1131  char buffer[255];
1132  sprintf(buffer,"fit function: p_{0} + p_{1} * l_{strip}");
1133  fits->AddText(buffer);
1134  sprintf(buffer,"p_{0} : %5.2f [ADC counts]",f1->GetParameter(0));
1135  fits->AddText(buffer);
1136  sprintf(buffer,"p_{1} : %5.2f [ADC counts/cm]",f1->GetParameter(1));
1137  fits->AddText(buffer);
1138  sprintf(buffer,"#chi^{2}/ndf = %5.2f / %i ",f1->GetChisquare(),f1->GetNDF());
1139  fits->AddText(buffer);
1140  fits->SetTextFont(42);
1141  fits->SetTextColor(kBlue);
1142  fits->SetFillColor(0);
1143  fits->SetTextSize(0.03);
1144  fits->SetBorderSize(1);
1145  fits->SetLineColor(kBlue);
1146  fits->SetMargin(0.05);
1147  fits->SetTextAlign(12);
1148  fits->Draw();
1149 
1150 
1151  std::string fileName(m_imageFileName);
1152  canvas.SaveAs(fileName.c_str());
1153 
1154  delete f1;
1155  delete reader;
1156  return true;
1157  }
1158  };
1159 
1160  /************************************************
1161  template Noise history per subdetector
1162  *************************************************/
1163 
1164  template <StripSubdetector::SubDetector sub> class NoiseHistory : public cond::payloadInspector::HistoryPlot<SiStripNoises,std::pair<double,double> > {
1165  public:
1166  NoiseHistory(): cond::payloadInspector::HistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
1167  }
1168 
1169  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
1170 
1171  std::vector<uint32_t> detid;
1172  payload.getDetIds(detid);
1173 
1174  int nStrips=0;
1175  float sum=0., sum2=0.;
1176  for (const auto & d : detid) {
1177  int subid = DetId(d).subdetId();
1178  if(subid!=sub) continue;
1179  SiStripNoises::Range range=payload.getRange(d);
1180  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
1181  nStrips++;
1182  auto noise = payload.getNoise(it,range);
1183  sum+=noise;
1184  sum2+=(noise*noise);
1185  } // loop on strips
1186  } // loop on detIds
1187 
1188  float mean = sum/nStrips;
1189  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
1190 
1191  return std::make_pair(mean,rms);
1192 
1193  } // close getFromPayload
1194  };
1195 
1196  typedef NoiseHistory<StripSubdetector::TIB> TIBNoiseHistory;
1197  typedef NoiseHistory<StripSubdetector::TOB> TOBNoiseHistory;
1198  typedef NoiseHistory<StripSubdetector::TID> TIDNoiseHistory;
1199  typedef NoiseHistory<StripSubdetector::TEC> TECNoiseHistory;
1200 
1201 
1202  /************************************************
1203  template Noise run history per subdetector
1204  *************************************************/
1205 
1206  template <StripSubdetector::SubDetector sub> class NoiseRunHistory : public cond::payloadInspector::RunHistoryPlot<SiStripNoises,std::pair<double,double> > {
1207  public:
1208  NoiseRunHistory(): cond::payloadInspector::RunHistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
1209  }
1210 
1211  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
1212 
1213  std::vector<uint32_t> detid;
1214  payload.getDetIds(detid);
1215 
1216  int nStrips=0;
1217  float sum=0., sum2=0.;
1218  for (const auto & d : detid) {
1219  int subid = DetId(d).subdetId();
1220  if(subid!=sub) continue;
1221  SiStripNoises::Range range=payload.getRange(d);
1222  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
1223  nStrips++;
1224  auto noise = payload.getNoise(it,range);
1225  sum+=noise;
1226  sum2+=(noise*noise);
1227  } // loop on strips
1228  } // loop on detIds
1229 
1230  float mean = sum/nStrips;
1231  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
1232 
1233  return std::make_pair(mean,rms);
1234 
1235  } // close getFromPayload
1236  };
1237 
1238  typedef NoiseRunHistory<StripSubdetector::TIB> TIBNoiseRunHistory;
1239  typedef NoiseRunHistory<StripSubdetector::TOB> TOBNoiseRunHistory;
1240  typedef NoiseRunHistory<StripSubdetector::TID> TIDNoiseRunHistory;
1241  typedef NoiseRunHistory<StripSubdetector::TEC> TECNoiseRunHistory;
1242 
1243  /************************************************
1244  template Noise Time history per subdetector
1245  *************************************************/
1246 
1247  template <StripSubdetector::SubDetector sub> class NoiseTimeHistory : public cond::payloadInspector::TimeHistoryPlot<SiStripNoises,std::pair<double,double> > {
1248  public:
1249  NoiseTimeHistory(): cond::payloadInspector::TimeHistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
1250  }
1251 
1252  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
1253 
1254  std::vector<uint32_t> detid;
1255  payload.getDetIds(detid);
1256 
1257  int nStrips=0;
1258  float sum=0., sum2=0.;
1259  for (const auto & d : detid) {
1260  int subid = DetId(d).subdetId();
1261  if(subid!=sub) continue;
1262  SiStripNoises::Range range=payload.getRange(d);
1263  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
1264  nStrips++;
1265  auto noise = payload.getNoise(it,range);
1266  sum+=noise;
1267  sum2+=(noise*noise);
1268  } // loop on strips
1269  } // loop on detIds
1270 
1271  float mean = sum/nStrips;
1272  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
1273 
1274  return std::make_pair(mean,rms);
1275 
1276  } // close getFromPayload
1277  };
1278 
1279  typedef NoiseTimeHistory<StripSubdetector::TIB> TIBNoiseTimeHistory;
1280  typedef NoiseTimeHistory<StripSubdetector::TOB> TOBNoiseTimeHistory;
1281  typedef NoiseTimeHistory<StripSubdetector::TID> TIDNoiseTimeHistory;
1282  typedef NoiseTimeHistory<StripSubdetector::TEC> TECNoiseTimeHistory;
1283 
1284 } // close namespace
1285 
1287  PAYLOAD_INSPECTOR_CLASS(SiStripNoisesTest);
1288  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValue);
1289  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValuePerStrip);
1290  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValuePerAPV);
1291  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValuePerModule);
1292  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValueComparison);
1293  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValueComparisonPerStrip);
1294  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValueComparisonPerAPV);
1295  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValueComparisonPerModule);
1296  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMin_TrackerMap);
1297  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMax_TrackerMap);
1298  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMean_TrackerMap);
1299  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRMS_TrackerMap);
1300  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMeanByRegion);
1301  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMinByRegion);
1302  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMaxByRegion);
1303  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRMSByRegion);
1304  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMeanByRegion);
1305  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMinByRegion);
1306  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMaxByRegion);
1307  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorRMSByRegion);
1308  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMin_RatioWithPreviousIOV1sigmaTrackerMap);
1309  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMax_RatioWithPreviousIOV1sigmaTrackerMap);
1310  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMean_RatioWithPreviousIOV1sigmaTrackerMap);
1311  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRms_RatioWithPreviousIOV1sigmaTrackerMap);
1312  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMin_RatioWithPreviousIOV2sigmaTrackerMap);
1313  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMax_RatioWithPreviousIOV2sigmaTrackerMap);
1314  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMean_RatioWithPreviousIOV2sigmaTrackerMap);
1315  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRms_RatioWithPreviousIOV2sigmaTrackerMap);
1316  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMin_RatioWithPreviousIOV3sigmaTrackerMap);
1317  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMax_RatioWithPreviousIOV3sigmaTrackerMap);
1318  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMean_RatioWithPreviousIOV3sigmaTrackerMap);
1319  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRms_RatioWithPreviousIOV3sigmaTrackerMap);
1320  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseLinearity);
1321  PAYLOAD_INSPECTOR_CLASS(TIBNoiseHistory);
1322  PAYLOAD_INSPECTOR_CLASS(TOBNoiseHistory);
1323  PAYLOAD_INSPECTOR_CLASS(TIDNoiseHistory);
1324  PAYLOAD_INSPECTOR_CLASS(TECNoiseHistory);
1325  PAYLOAD_INSPECTOR_CLASS(TIBNoiseRunHistory);
1326  PAYLOAD_INSPECTOR_CLASS(TOBNoiseRunHistory);
1327  PAYLOAD_INSPECTOR_CLASS(TIDNoiseRunHistory);
1328  PAYLOAD_INSPECTOR_CLASS(TECNoiseRunHistory);
1329  PAYLOAD_INSPECTOR_CLASS(TIBNoiseTimeHistory);
1330  PAYLOAD_INSPECTOR_CLASS(TOBNoiseTimeHistory);
1331  PAYLOAD_INSPECTOR_CLASS(TIDNoiseTimeHistory);
1332  PAYLOAD_INSPECTOR_CLASS(TECNoiseTimeHistory);
1333 }
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
void fillNoiseDetSummary(SiStripDetSummary &summaryNoise, std::shared_ptr< SiStripNoises > payload, SiStripPI::estimator est)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static float getNoise(uint16_t strip, const Range &range)
Definition: SiStripNoises.h:74
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
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
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:52
void makeNicePlotStyle(TH1 *hist)
#define end
Definition: vmac.h:39
std::string getStringFromSubdet(StripSubdetector::SubDetector sub)
void fillWithValue(float value, float weight=1)
T min(T a, T b)
Definition: MathUtil.h:58
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::string estimatorType(SiStripPI::estimator e)
std::pair< int, const char * > regionType(int index)
Definition: DetId.h:18
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: plugin.cc:24
#define begin
Definition: vmac.h:32
const Range getRange(const uint32_t detID) const
bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs) override
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
std::string fullPath() const
Definition: FileInPath.cc:163
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:50