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 
46 namespace {
47 
48  /************************************************
49  test class
50  *************************************************/
51 
52  class SiStripNoisesTest : public cond::payloadInspector::Histogram1D<SiStripNoises> {
53 
54  public:
55  SiStripNoisesTest() : cond::payloadInspector::Histogram1D<SiStripNoises>("SiStrip Noise test",
56  "SiStrip Noise test", 10,0.0,10.0),
57  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
58  {
59  Base::setSingleIov( true );
60  }
61 
62  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
63  for ( auto const & iov: iovs) {
64  std::shared_ptr<SiStripNoises> payload = Base::fetchPayload( std::get<1>(iov) );
65  if( payload.get() ){
66 
67  fillWithValue(1.);
68 
69  std::stringstream ss;
70  ss << "Summary of strips noises:" << std::endl;
71 
72  //payload->printDebug(ss);
73  payload->printSummary(ss,&m_trackerTopo);
74 
75  std::vector<uint32_t> detid;
76  payload->getDetIds(detid);
77 
78  // for (const auto & d : detid) {
79  // int nstrip=0;
80  // SiStripNoises::Range range=payload->getRange(d);
81  // for( int it=0; it < (range.second-range.first)*8/9; ++it ){
82  // auto noise = payload->getNoise(it,range);
83  // nstrip++;
84  // ss << "DetId="<< d << " Strip=" << nstrip <<": "<< noise << std::endl;
85  // } // end of loop on strips
86  // } // end of loop on detIds
87 
88  std::cout<<ss.str()<<std::endl;
89 
90  }// payload
91  }// iovs
92  return true;
93  }// fill
94  private:
95  TrackerTopology m_trackerTopo;
96  };
97 
98  /************************************************
99  1d histogram of SiStripNoises of 1 IOV
100  *************************************************/
101 
102  // inherit from one of the predefined plot class: Histogram1D
103  class SiStripNoiseValue : public cond::payloadInspector::Histogram1D<SiStripNoises> {
104 
105  public:
106  SiStripNoiseValue() : cond::payloadInspector::Histogram1D<SiStripNoises>("SiStrip Noise values",
107  "SiStrip Noise values", 100,0.0,10.0){
108  Base::setSingleIov( true );
109  }
110 
111  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
112  for ( auto const & iov: iovs) {
113  std::shared_ptr<SiStripNoises> payload = Base::fetchPayload( std::get<1>(iov) );
114  if( payload.get() ){
115 
116  std::vector<uint32_t> detid;
117  payload->getDetIds(detid);
118 
119  for (const auto & d : detid) {
120  SiStripNoises::Range range=payload->getRange(d);
121  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
122  auto noise = payload->getNoise(it,range);
123  //to be used to fill the histogram
124  fillWithValue(noise);
125  }// loop over APVs
126  } // loop over detIds
127  }// payload
128  }// iovs
129  return true;
130  }// fill
131  };
132 
133  /************************************************
134  1d histogram comparison of SiStripNoises of 1 IOV
135  *************************************************/
136 
137  // inherit from one of the predefined plot class: PlotImage
138  class SiStripNoiseValueComparison : public cond::payloadInspector::PlotImage<SiStripNoises> {
139 
140  public:
141  SiStripNoiseValueComparison() : cond::payloadInspector::PlotImage<SiStripNoises>("SiStrip Noise values comparison"){
142  setSingleIov( false );
143  }
144 
145  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
146 
147  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
148 
149  // make absolute sure the IOVs are sortd by since
150  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
151  return std::get<0>(t1) < std::get<0>(t2);
152  });
153 
154  auto firstiov = sorted_iovs.front();
155  auto lastiov = sorted_iovs.back();
156 
157  std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
158  std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
159 
160  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.));
161  h_first->SetStats(false);
162 
163  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.));
164  h_last->SetStats(false);
165 
166  std::vector<uint32_t> f_detid;
167  f_payload->getDetIds(f_detid);
168 
169  // loop on first payload
170  for (const auto & d : f_detid) {
171  SiStripNoises::Range range=f_payload->getRange(d);
172  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
173  float noise = f_payload->getNoise(it,range);
174  //to be used to fill the histogram
175  h_first->Fill(noise);
176  }// loop over strips
177  }
178 
179  std::vector<uint32_t> l_detid;
180  l_payload->getDetIds(l_detid);
181 
182  // loop on first payload
183  for (const auto & d : l_detid) {
184  SiStripNoises::Range range=l_payload->getRange(d);
185  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
186  float noise = l_payload->getNoise(it,range);
187  //to be used to fill the histogram
188  h_last->Fill(noise);
189  }// loop over strips
190  }
191 
192 
193  h_first->GetYaxis()->CenterTitle(true);
194  h_last->GetYaxis()->CenterTitle(true);
195 
196  h_first->GetXaxis()->CenterTitle(true);
197  h_last->GetXaxis()->CenterTitle(true);
198 
199  h_first->SetLineWidth(2);
200  h_last->SetLineWidth(2);
201 
202  h_first->SetLineColor(kBlack);
203  h_last->SetLineColor(kBlue);
204 
205  //=========================
206  TCanvas canvas("Partion summary","partition summary",1200,1000);
207  canvas.cd();
208  canvas.SetBottomMargin(0.11);
209  canvas.SetLeftMargin(0.13);
210  canvas.SetRightMargin(0.05);
211  canvas.Modified();
212 
213  float theMax = (h_first->GetMaximum() > h_last->GetMaximum()) ? h_first->GetMaximum() : h_last->GetMaximum();
214 
215  h_first->SetMaximum(theMax*1.30);
216  h_last->SetMaximum(theMax*1.30);
217 
218  h_first->Draw();
219  h_last->Draw("same");
220 
221  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
222  legend.SetHeader("SiStrip Noise comparison","C"); // option "C" allows to center the header
223  legend.AddEntry(h_first.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"F");
224  legend.AddEntry(h_last.get(), ("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"F");
225  legend.SetTextSize(0.025);
226  legend.Draw("same");
227 
228  std::string fileName(m_imageFileName);
229  canvas.SaveAs(fileName.c_str());
230 
231  return true;
232 
233  }
234  };
235 
236  /************************************************
237  SiStrip Noise Tracker Map
238  *************************************************/
239 
240  template<SiStripPI::estimator est> class SiStripNoiseTrackerMap : public cond::payloadInspector::PlotImage<SiStripNoises> {
241 
242  public:
243  SiStripNoiseTrackerMap() : cond::payloadInspector::PlotImage<SiStripNoises> ( "Tracker Map of SiStripNoise "+estimatorType(est)+" per module" )
244  {
245  setSingleIov( true );
246  }
247 
248  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
249  auto iov = iovs.front();
250  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
251 
252  std::string titleMap = "Tracker Map of Noise "+estimatorType(est)+" per module (payload : "+std::get<1>(iov)+")";
253 
254  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripNoises"));
255  tmap->setTitle(titleMap);
256  tmap->setPalette(1);
257 
258  // storage of info
259  std::map<unsigned int,float> info_per_detid;
260 
261  SiStripNoises::RegistryIterator rit=payload->getRegistryVectorBegin(), erit=payload->getRegistryVectorEnd();
262  uint16_t Nstrips;
263  std::vector<float> vstripnoise;
264  double mean,rms,min, max;
265  for(;rit!=erit;++rit){
266  Nstrips = (rit->iend-rit->ibegin)*8/9; //number of strips = number of chars * char size / strip noise size
267  vstripnoise.resize(Nstrips);
268  payload->allNoises(vstripnoise,make_pair(payload->getDataVectorBegin()+rit->ibegin,payload->getDataVectorBegin()+rit->iend));
269  mean=0; rms=0; min=10000; max=0;
270 
271  DetId detId(rit->detid);
272 
273  for(size_t i=0;i<Nstrips;++i){
274  mean+=vstripnoise[i];
275  rms+=vstripnoise[i]*vstripnoise[i];
276  if(vstripnoise[i]<min) min=vstripnoise[i];
277  if(vstripnoise[i]>max) max=vstripnoise[i];
278  }
279 
280  mean/=Nstrips;
281  if((rms/Nstrips-mean*mean)>0.){
282  rms = sqrt(rms/Nstrips-mean*mean);
283  } else {
284  rms=0.;
285  }
286 
287  switch(est){
288  case SiStripPI::min:
289  info_per_detid[rit->detid]=min;
290  break;
291  case SiStripPI::max:
292  info_per_detid[rit->detid]=max;
293  break;
294  case SiStripPI::mean:
295  info_per_detid[rit->detid]=mean;
296  break;
297  case SiStripPI::rms:
298  info_per_detid[rit->detid]=rms;
299  break;
300  default:
301  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
302  break;
303  }
304  }
305 
306  // loop on the map
307  for (const auto &item : info_per_detid){
308  tmap->fill(item.first,item.second);
309  }
310 
311  auto range = SiStripPI::getTheRange(info_per_detid,2);
312 
313  //=========================
314 
315  std::string fileName(m_imageFileName);
316  if(est==SiStripPI::rms && (range.first<0.)){
317  tmap->save(true,0.,range.second,fileName);
318  } else {
319  tmap->save(true,range.first,range.second,fileName);
320  }
321 
322  return true;
323  }
324  };
325 
326  typedef SiStripNoiseTrackerMap<SiStripPI::min> SiStripNoiseMin_TrackerMap;
327  typedef SiStripNoiseTrackerMap<SiStripPI::max> SiStripNoiseMax_TrackerMap;
328  typedef SiStripNoiseTrackerMap<SiStripPI::mean> SiStripNoiseMean_TrackerMap;
329  typedef SiStripNoiseTrackerMap<SiStripPI::rms> SiStripNoiseRMS_TrackerMap;
330 
331  /************************************************
332  SiStrip Noise Tracker Summaries
333  *************************************************/
334 
335  template<SiStripPI::estimator est> class SiStripNoiseByRegion : public cond::payloadInspector::PlotImage<SiStripNoises> {
336  public:
337  SiStripNoiseByRegion() : cond::payloadInspector::PlotImage<SiStripNoises>( "SiStrip Noise "+estimatorType(est)+" by Region" ),
338  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
339  {
340  setSingleIov( true );
341  }
342 
343  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
344  auto iov = iovs.front();
345  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
346 
347  SiStripDetSummary summaryNoise{&m_trackerTopo};
348 
349  SiStripPI::fillNoiseDetSummary(summaryNoise,payload,est);
350 
351  std::map<unsigned int, SiStripDetSummary::Values> map = summaryNoise.getCounts();
352  //=========================
353 
354  TCanvas canvas("Partion summary","partition summary",1200,1000);
355  canvas.cd();
356  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()));
357  h1->SetStats(false);
358  canvas.SetBottomMargin(0.18);
359  canvas.SetLeftMargin(0.17);
360  canvas.SetRightMargin(0.05);
361  canvas.Modified();
362 
363  std::vector<int> boundaries;
364  unsigned int iBin=0;
365 
367  std::string currentDetector;
368 
369  for (const auto &element : map){
370  iBin++;
371  int count = element.second.count;
372  double mean = (element.second.mean)/count;
373  double rms = (element.second.rms)/count - mean*mean;
374 
375  if(rms <= 0)
376  rms = 0;
377  else
378  rms = sqrt(rms);
379 
380  if(currentDetector.empty()) currentDetector="TIB";
381 
382  switch ((element.first)/1000)
383  {
384  case 1:
385  detector = "TIB";
386  break;
387  case 2:
388  detector = "TOB";
389  break;
390  case 3:
391  detector = "TEC";
392  break;
393  case 4:
394  detector = "TID";
395  break;
396  }
397 
398  h1->SetBinContent(iBin,mean);
399  h1->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
400  h1->GetXaxis()->LabelsOption("v");
401 
402  if(detector!=currentDetector) {
403  boundaries.push_back(iBin);
404  currentDetector=detector;
405  }
406  }
407 
408  h1->SetMarkerStyle(20);
409  h1->SetMarkerSize(1);
410  h1->SetMaximum(h1->GetMaximum()*1.1);
411  h1->Draw("HIST");
412  h1->Draw("Psame");
413 
414  canvas.Update();
415 
416  TLine l[boundaries.size()];
417  unsigned int i=0;
418  for (const auto & line : boundaries){
419  l[i] = TLine(h1->GetBinLowEdge(line),canvas.GetUymin(),h1->GetBinLowEdge(line),canvas.GetUymax());
420  l[i].SetLineWidth(1);
421  l[i].SetLineStyle(9);
422  l[i].SetLineColor(2);
423  l[i].Draw("same");
424  i++;
425  }
426 
427  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
428  legend.SetHeader((std::get<1>(iov)).c_str(),"C"); // option "C" allows to center the header
429  legend.AddEntry(h1.get(),("IOV: "+std::to_string(std::get<0>(iov))).c_str(),"PL");
430  legend.SetTextSize(0.025);
431  legend.Draw("same");
432 
433  std::string fileName(m_imageFileName);
434  canvas.SaveAs(fileName.c_str());
435 
436  return true;
437  }
438  private:
439  TrackerTopology m_trackerTopo;
440  };
441 
442  typedef SiStripNoiseByRegion<SiStripPI::mean> SiStripNoiseMeanByRegion;
443  typedef SiStripNoiseByRegion<SiStripPI::min> SiStripNoiseMinByRegion;
444  typedef SiStripNoiseByRegion<SiStripPI::max> SiStripNoiseMaxByRegion;
445  typedef SiStripNoiseByRegion<SiStripPI::rms> SiStripNoiseRMSByRegion;
446 
447  /************************************************
448  SiStrip Noise Comparator
449  *************************************************/
450 
451  template<SiStripPI::estimator est> class SiStripNoiseComparatorByRegion : public cond::payloadInspector::PlotImage<SiStripNoises> {
452  public:
453  SiStripNoiseComparatorByRegion() : cond::payloadInspector::PlotImage<SiStripNoises>( "SiStrip Noise "+estimatorType(est)+" comparator by Region" ),
454  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
455  {
456  setSingleIov( false );
457  }
458 
459  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
460 
461  std::vector<std::tuple<cond::Time_t,cond::Hash> > sorted_iovs = iovs;
462 
463  // make absolute sure the IOVs are sortd by since
464  std::sort(begin(sorted_iovs), end(sorted_iovs), [](auto const &t1, auto const &t2) {
465  return std::get<0>(t1) < std::get<0>(t2);
466  });
467 
468  auto firstiov = sorted_iovs.front();
469  auto lastiov = sorted_iovs.back();
470 
471  std::shared_ptr<SiStripNoises> f_payload = fetchPayload( std::get<1>(firstiov) );
472  std::shared_ptr<SiStripNoises> l_payload = fetchPayload( std::get<1>(lastiov) );
473 
474  SiStripDetSummary f_summaryNoise{&m_trackerTopo};
475  SiStripDetSummary l_summaryNoise{&m_trackerTopo};
476 
477  SiStripPI::fillNoiseDetSummary(f_summaryNoise,f_payload,est);
478  SiStripPI::fillNoiseDetSummary(l_summaryNoise,l_payload,est);
479 
480  std::map<unsigned int, SiStripDetSummary::Values> f_map = f_summaryNoise.getCounts();
481  std::map<unsigned int, SiStripDetSummary::Values> l_map = l_summaryNoise.getCounts();
482 
483  //=========================
484  TCanvas canvas("Partion summary","partition summary",1200,1000);
485  canvas.cd();
486 
487  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()));
488  hfirst->SetStats(false);
489 
490  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()));
491  hlast->SetStats(false);
492 
493  canvas.SetBottomMargin(0.18);
494  canvas.SetLeftMargin(0.17);
495  canvas.SetRightMargin(0.05);
496  canvas.Modified();
497 
498  std::vector<int> boundaries;
499  unsigned int iBin=0;
500 
502  std::string currentDetector;
503 
504  for (const auto &element : f_map){
505  iBin++;
506  int count = element.second.count;
507  double mean = (element.second.mean)/count;
508  double rms = (element.second.rms)/count - mean*mean;
509 
510  if(rms <= 0)
511  rms = 0;
512  else
513  rms = sqrt(rms);
514 
515  if(currentDetector.empty()) currentDetector="TIB";
516 
517  switch ((element.first)/1000)
518  {
519  case 1:
520  detector = "TIB";
521  break;
522  case 2:
523  detector = "TOB";
524  break;
525  case 3:
526  detector = "TEC";
527  break;
528  case 4:
529  detector = "TID";
530  break;
531  }
532 
533  hfirst->SetBinContent(iBin,mean);
534  //hfirst->SetBinError(iBin,rms);
535  hfirst->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
536  hfirst->GetXaxis()->LabelsOption("v");
537 
538  if(detector!=currentDetector) {
539  boundaries.push_back(iBin);
540  currentDetector=detector;
541  }
542  }
543 
544  // second payload
545  // reset the counter
546  iBin=0;
547  for (const auto &element : l_map){
548  iBin++;
549  int count = element.second.count;
550  double mean = (element.second.mean)/count;
551  double rms = (element.second.rms)/count - mean*mean;
552 
553  if(rms <= 0)
554  rms = 0;
555  else
556  rms = sqrt(rms);
557 
558  hlast->SetBinContent(iBin,mean);
559  //hlast->SetBinError(iBin,rms);
560  hlast->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(element.first).second);
561  hlast->GetXaxis()->LabelsOption("v");
562  }
563 
564  float theMax = (hfirst->GetMaximum() > hlast->GetMaximum()) ? hfirst->GetMaximum() : hlast->GetMaximum();
565  float theMin = (hfirst->GetMinimum() < hlast->GetMinimum()) ? hfirst->GetMinimum() : hlast->GetMinimum();
566 
567  hfirst->SetMarkerStyle(20);
568  hfirst->SetMarkerSize(1);
569  hfirst->GetYaxis()->SetTitleOffset(1.3);
570  hfirst->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
571  hfirst->Draw("HIST");
572  hfirst->Draw("Psame");
573 
574  hlast->SetMarkerStyle(21);
575  hlast->SetMarkerSize(1);
576  hlast->SetMarkerColor(kBlue);
577  hlast->SetLineColor(kBlue);
578  hlast->GetYaxis()->SetTitleOffset(1.3);
579  hlast->GetYaxis()->SetRangeUser(theMin*0.9,theMax*1.1);
580  hlast->Draw("HISTsame");
581  hlast->Draw("Psame");
582 
583  canvas.Update();
584 
585  TLine l[boundaries.size()];
586  unsigned int i=0;
587  for (const auto & line : boundaries){
588  l[i] = TLine(hfirst->GetBinLowEdge(line),canvas.GetUymin(),hfirst->GetBinLowEdge(line),canvas.GetUymax());
589  l[i].SetLineWidth(1);
590  l[i].SetLineStyle(9);
591  l[i].SetLineColor(2);
592  l[i].Draw("same");
593  i++;
594  }
595 
596  TLegend legend = TLegend(0.52,0.82,0.95,0.9);
597  legend.SetHeader(("SiStrip Noise "+estimatorType(est)+" by region").c_str(),"C"); // option "C" allows to center the header
598  legend.AddEntry(hfirst.get(),("IOV: "+std::to_string(std::get<0>(firstiov))).c_str(),"PL");
599  legend.AddEntry(hlast.get(), ("IOV: "+std::to_string(std::get<0>(lastiov))).c_str(),"PL");
600  legend.SetTextSize(0.025);
601  legend.Draw("same");
602 
603  std::string fileName(m_imageFileName);
604  canvas.SaveAs(fileName.c_str());
605 
606  return true;
607  }
608  private:
609  TrackerTopology m_trackerTopo;
610  };
611 
612  typedef SiStripNoiseComparatorByRegion<SiStripPI::mean> SiStripNoiseComparatorMeanByRegion;
613  typedef SiStripNoiseComparatorByRegion<SiStripPI::min> SiStripNoiseComparatorMinByRegion;
614  typedef SiStripNoiseComparatorByRegion<SiStripPI::max> SiStripNoiseComparatorMaxByRegion;
615  typedef SiStripNoiseComparatorByRegion<SiStripPI::rms> SiStripNoiseComparatorRMSByRegion;
616 
617  /************************************************
618  Noise linearity
619  *************************************************/
620  class SiStripNoiseLinearity : public cond::payloadInspector::PlotImage<SiStripNoises> {
621  public:
622  SiStripNoiseLinearity() : cond::payloadInspector::PlotImage<SiStripNoises>( "Linearity of Strip Noise as a fuction of strip length" ){
623  setSingleIov( true );
624  }
625 
626  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
627  auto iov = iovs.front();
628  std::shared_ptr<SiStripNoises> payload = fetchPayload( std::get<1>(iov) );
629 
630  edm::FileInPath fp_ = edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
632 
633  std::vector<uint32_t> detid;
634  payload->getDetIds(detid);
635 
636  std::map<float,std::tuple<int,float,float> > noisePerStripLength;
637 
638  for (const auto & d : detid) {
639  SiStripNoises::Range range=payload->getRange(d);
640  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
641  auto noise = payload->getNoise(it,range);
642  //to be used to fill the histogram
643  float stripL = reader->getNumberOfApvsAndStripLength(d).second;
644  std::get<0>(noisePerStripLength[stripL])+=1;
645  std::get<1>(noisePerStripLength[stripL])+=noise;
646  std::get<2>(noisePerStripLength[stripL])+=(noise*noise);
647  }// loop over strips
648  } // loop over detIds
649 
650  TCanvas canvas("Noise linearity","noise linearity",1200,1000);
651  canvas.cd();
652 
653  std::vector<float> x; x.reserve(noisePerStripLength.size());
654  std::vector<float> y; y.reserve(noisePerStripLength.size());
655  std::vector<float> ex; ex.reserve(noisePerStripLength.size());
656  std::vector<float> ey; ey.reserve(noisePerStripLength.size());
657 
658  for (const auto &element : noisePerStripLength ){
659  x.push_back(element.first);
660  ex.push_back(0.);
661  float sum = std::get<1>(element.second);
662  float sum2 = std::get<2>(element.second);
663  float nstrips = std::get<0>(element.second);
664  float mean = sum/nstrips;
665  float rms = (sum2/nstrips-mean*mean)>0. ? sqrt(sum2/nstrips-mean*mean) : 0.;
666  y.push_back(mean);
667  ey.push_back(rms);
668  //std::cout<<" strip lenght: " << element.first << " avg noise=" << mean <<" +/-" << rms << std::endl;
669  }
670 
671  auto graph = std::unique_ptr<TGraphErrors>(new TGraphErrors(noisePerStripLength.size(),&x[0], &y[0],&ex[0],&ey[0]));
672  graph->SetTitle("SiStrip Noise Linearity");
673  graph->GetXaxis()->SetTitle("Strip length [cm]");
674  graph->GetYaxis()->SetTitle("Average Strip Noise [ADC counts]");
675  graph->SetMarkerColor(kBlue);
676  graph->SetMarkerStyle(20);
677  graph->SetMarkerSize(1.5);
678  canvas.SetBottomMargin(0.13);
679  canvas.SetLeftMargin(0.17);
680  canvas.SetTopMargin(0.08);
681  canvas.SetRightMargin(0.05);
682  canvas.Modified();
683  canvas.cd();
684 
685  graph->GetXaxis()->CenterTitle(true);
686  graph->GetYaxis()->CenterTitle(true);
687  graph->GetXaxis()->SetTitleFont(42);
688  graph->GetYaxis()->SetTitleFont(42);
689  graph->GetXaxis()->SetTitleSize(0.05);
690  graph->GetYaxis()->SetTitleSize(0.05);
691  graph->GetXaxis()->SetTitleOffset(1.1);
692  graph->GetYaxis()->SetTitleOffset(1.3);
693  graph->GetXaxis()->SetLabelFont(42);
694  graph->GetYaxis()->SetLabelFont(42);
695  graph->GetYaxis()->SetLabelSize(.05);
696  graph->GetXaxis()->SetLabelSize(.05);
697 
698  graph->Draw("AP");
699  graph->Fit("pol1");
700  //Access the fit resuts
701  TF1 *f1 = graph->GetFunction("pol1");
702  f1->SetLineWidth(2);
703  f1->SetLineColor(kBlue);
704  f1->Draw("same");
705 
706  auto fits = std::unique_ptr<TPaveText>(new TPaveText(0.2,0.72,0.6,0.9,"NDC"));
707  char buffer[255];
708  sprintf(buffer,"fit function: p_{0} + p_{1} * l_{strip}");
709  fits->AddText(buffer);
710  sprintf(buffer,"p_{0} : %5.2f [ADC counts]",f1->GetParameter(0));
711  fits->AddText(buffer);
712  sprintf(buffer,"p_{1} : %5.2f [ADC counts/cm]",f1->GetParameter(1));
713  fits->AddText(buffer);
714  sprintf(buffer,"#chi^{2}/ndf = %5.2f / %i ",f1->GetChisquare(),f1->GetNDF());
715  fits->AddText(buffer);
716  fits->SetTextFont(42);
717  fits->SetTextColor(kBlue);
718  fits->SetFillColor(0);
719  fits->SetTextSize(0.03);
720  fits->SetBorderSize(1);
721  fits->SetLineColor(kBlue);
722  fits->SetMargin(0.05);
723  fits->SetTextAlign(12);
724  fits->Draw();
725 
726 
727  std::string fileName(m_imageFileName);
728  canvas.SaveAs(fileName.c_str());
729 
730  delete f1;
731  delete reader;
732  return true;
733  }
734  };
735 
736  /************************************************
737  template Noise history per subdetector
738  *************************************************/
739 
740  template <StripSubdetector::SubDetector sub> class NoiseHistory : public cond::payloadInspector::HistoryPlot<SiStripNoises,std::pair<double,double> > {
741  public:
742  NoiseHistory(): cond::payloadInspector::HistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
743  }
744 
745  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
746 
747  std::vector<uint32_t> detid;
748  payload.getDetIds(detid);
749 
750  int nStrips=0;
751  float sum=0., sum2=0.;
752  for (const auto & d : detid) {
753  int subid = DetId(d).subdetId();
754  if(subid!=sub) continue;
755  SiStripNoises::Range range=payload.getRange(d);
756  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
757  nStrips++;
758  auto noise = payload.getNoise(it,range);
759  sum+=noise;
760  sum2+=(noise*noise);
761  } // loop on strips
762  } // loop on detIds
763 
764  float mean = sum/nStrips;
765  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
766 
767  return std::make_pair(mean,rms);
768 
769  } // close getFromPayload
770  };
771 
772  typedef NoiseHistory<StripSubdetector::TIB> TIBNoiseHistory;
773  typedef NoiseHistory<StripSubdetector::TOB> TOBNoiseHistory;
774  typedef NoiseHistory<StripSubdetector::TID> TIDNoiseHistory;
775  typedef NoiseHistory<StripSubdetector::TEC> TECNoiseHistory;
776 
777 
778  /************************************************
779  template Noise run history per subdetector
780  *************************************************/
781 
782  template <StripSubdetector::SubDetector sub> class NoiseRunHistory : public cond::payloadInspector::RunHistoryPlot<SiStripNoises,std::pair<double,double> > {
783  public:
784  NoiseRunHistory(): cond::payloadInspector::RunHistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
785  }
786 
787  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
788 
789  std::vector<uint32_t> detid;
790  payload.getDetIds(detid);
791 
792  int nStrips=0;
793  float sum=0., sum2=0.;
794  for (const auto & d : detid) {
795  int subid = DetId(d).subdetId();
796  if(subid!=sub) continue;
797  SiStripNoises::Range range=payload.getRange(d);
798  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
799  nStrips++;
800  auto noise = payload.getNoise(it,range);
801  sum+=noise;
802  sum2+=(noise*noise);
803  } // loop on strips
804  } // loop on detIds
805 
806  float mean = sum/nStrips;
807  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
808 
809  return std::make_pair(mean,rms);
810 
811  } // close getFromPayload
812  };
813 
814  typedef NoiseRunHistory<StripSubdetector::TIB> TIBNoiseRunHistory;
815  typedef NoiseRunHistory<StripSubdetector::TOB> TOBNoiseRunHistory;
816  typedef NoiseRunHistory<StripSubdetector::TID> TIDNoiseRunHistory;
817  typedef NoiseRunHistory<StripSubdetector::TEC> TECNoiseRunHistory;
818 
819  /************************************************
820  template Noise Time history per subdetector
821  *************************************************/
822 
823  template <StripSubdetector::SubDetector sub> class NoiseTimeHistory : public cond::payloadInspector::TimeHistoryPlot<SiStripNoises,std::pair<double,double> > {
824  public:
825  NoiseTimeHistory(): cond::payloadInspector::TimeHistoryPlot<SiStripNoises,std::pair<double,double> >( "Average "+SiStripPI::getStringFromSubdet(sub)+" noise vs run number", "average "+SiStripPI::getStringFromSubdet(sub)+" Noise"){
826  }
827 
828  std::pair<double,double> getFromPayload( SiStripNoises& payload ) override{
829 
830  std::vector<uint32_t> detid;
831  payload.getDetIds(detid);
832 
833  int nStrips=0;
834  float sum=0., sum2=0.;
835  for (const auto & d : detid) {
836  int subid = DetId(d).subdetId();
837  if(subid!=sub) continue;
838  SiStripNoises::Range range=payload.getRange(d);
839  for( int it=0; it < (range.second-range.first)*8/9; ++it ){
840  nStrips++;
841  auto noise = payload.getNoise(it,range);
842  sum+=noise;
843  sum2+=(noise*noise);
844  } // loop on strips
845  } // loop on detIds
846 
847  float mean = sum/nStrips;
848  float rms = (sum2/nStrips-mean*mean)>0. ? sqrt(sum2/nStrips-mean*mean) : 0.;
849 
850  return std::make_pair(mean,rms);
851 
852  } // close getFromPayload
853  };
854 
855  typedef NoiseTimeHistory<StripSubdetector::TIB> TIBNoiseTimeHistory;
856  typedef NoiseTimeHistory<StripSubdetector::TOB> TOBNoiseTimeHistory;
857  typedef NoiseTimeHistory<StripSubdetector::TID> TIDNoiseTimeHistory;
858  typedef NoiseTimeHistory<StripSubdetector::TEC> TECNoiseTimeHistory;
859 
860 } // close namespace
861 
863  PAYLOAD_INSPECTOR_CLASS(SiStripNoisesTest);
864  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValue);
865  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseValueComparison);
866  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMin_TrackerMap);
867  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMax_TrackerMap);
868  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMean_TrackerMap);
869  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRMS_TrackerMap);
870  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMeanByRegion);
871  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMinByRegion);
872  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseMaxByRegion);
873  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseRMSByRegion);
874  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMeanByRegion);
875  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMinByRegion);
876  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorMaxByRegion);
877  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseComparatorRMSByRegion);
878  PAYLOAD_INSPECTOR_CLASS(SiStripNoiseLinearity);
879  PAYLOAD_INSPECTOR_CLASS(TIBNoiseHistory);
880  PAYLOAD_INSPECTOR_CLASS(TOBNoiseHistory);
881  PAYLOAD_INSPECTOR_CLASS(TIDNoiseHistory);
882  PAYLOAD_INSPECTOR_CLASS(TECNoiseHistory);
883  PAYLOAD_INSPECTOR_CLASS(TIBNoiseRunHistory);
884  PAYLOAD_INSPECTOR_CLASS(TOBNoiseRunHistory);
885  PAYLOAD_INSPECTOR_CLASS(TIDNoiseRunHistory);
886  PAYLOAD_INSPECTOR_CLASS(TECNoiseRunHistory);
887  PAYLOAD_INSPECTOR_CLASS(TIBNoiseTimeHistory);
888  PAYLOAD_INSPECTOR_CLASS(TOBNoiseTimeHistory);
889  PAYLOAD_INSPECTOR_CLASS(TIDNoiseTimeHistory);
890  PAYLOAD_INSPECTOR_CLASS(TECNoiseTimeHistory);
891 }
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)
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
T sqrt(T t)
Definition: SSEVec.h:18
Registry::const_iterator RegistryIterator
Definition: SiStripNoises.h:52
#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)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
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:481
std::string fullPath() const
Definition: FileInPath.cc:197
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripNoises.h:50