CMS 3D CMS Logo

SiStripCondObjectRepresent.h
Go to the documentation of this file.
1 #ifndef CondCore_SiStripPlugins_SiStripCondObjectRepresent_h
2 #define CondCore_SiStripPlugins_SiStripCondObjectRepresent_h
3 
4 // system includes
5 #include <fstream>
6 #include <iostream>
7 #include <sstream>
8 #include <string>
9 #include <vector>
10 #include <fmt/printf.h>
11 
12 // user includes
18 
19 // ROOT includes
20 #include "TCanvas.h"
21 #include "TColor.h"
22 #include "TGaxis.h"
23 #include "TH1F.h"
24 #include "TH2F.h"
25 #include "TLatex.h"
26 #include "TLegend.h"
27 #include "TLine.h"
28 #include "TPaveLabel.h"
29 #include "TProfile.h"
30 #include "TROOT.h"
31 #include "TStyle.h"
32 
33 //functions for correct representation of data in summary and plot
35 
36  static const std::map<std::string, int> k_colormap = {
37  {"TIB", kRed}, {"TOB", kGreen}, {"TID", kBlack}, {"TEC", kBlue}};
38  static const std::map<std::string, int> k_markermap = {
39  {"TIB", kFullCircle}, {"TOB", kFullTriangleUp}, {"TID", kFullSquare}, {"TEC", kFullTriangleDown}};
40 
43 
44  template <class type>
46  public:
48 
49  virtual ~SiStripCondDataItem() = default;
50 
51  void fillAll(unsigned int detid, const std::vector<type> &store) {
52  m_info[detid] = store;
53  m_cached = true;
54  return;
55  }
56 
57  void fillByPushBack(unsigned int detid, const type &value) {
58  m_info[detid].push_back(value);
59  m_cached = true;
60  }
61 
62  void divide(unsigned int detid, const std::vector<type> &denominator) {
63  if (m_info[detid].size() != denominator.size()) {
64  throw cms::Exception("Unaligned Conditions")
65  << "data size of numerator mismatched the data size of denominator";
66  }
67 
68  unsigned int counter = 0;
69  for (const auto &den : denominator) {
70  m_info[detid].at(counter) /= den;
71  counter++;
72  }
73  }
74 
75  void subtract(unsigned int detid, const std::vector<type> &subtractor) {
76  if (m_info[detid].size() != subtractor.size()) {
77  throw cms::Exception("Unaligned Conditions")
78  << "data size of numerator mismatched the data size of denominator";
79  }
80 
81  unsigned int counter = 0;
82  for (const auto &sub : subtractor) {
83  m_info[detid].at(counter) -= sub;
84  counter++;
85  }
86  }
87 
88  std::vector<type> data(unsigned int detid) { return m_info[detid]; }
89 
90  std::pair<std::vector<type>, std::vector<type> > demuxedData(unsigned int detid) {
91  if (m_compared) {
92  std::vector<type> v1(m_info[detid].begin(), m_info[detid].begin() + m_info[detid].size() / 2);
93  std::vector<type> v2(m_info[detid].begin() + m_info[detid].size() / 2, m_info[detid].end());
94  assert(v1.size() == v2.size());
95  return std::make_pair(v1, v2);
96  } else {
97  throw cms::Exception("Logic error") << "not being in compared mode, data cannot be demultiplexed";
98  }
99  }
100 
101  void fillMonitor1D(const SiStripPI::OpMode &mymode,
104  std::vector<type> &values,
105  const unsigned int prev_det,
106  unsigned int &prev_apv,
107  const unsigned int detid) {
108  unsigned int istrip = 0;
109  for (const auto &value : values) {
110  bool flush = false;
111  switch (mymode) {
112  case (SiStripPI::APV_BASED):
113  flush = (prev_det != 0 && prev_apv != istrip / sistrip::STRIPS_PER_APV);
114  break;
116  flush = (prev_det != 0 && prev_det != detid);
117  break;
118  case (SiStripPI::STRIP_BASED):
119  flush = (istrip != 0);
120  break;
121  }
122 
123  if (flush) {
124  mon->Fill(prev_apv, prev_det, entry.mean());
125  entry.reset();
126  }
127 
128  entry.add(value);
129 
130  prev_apv = istrip / sistrip::STRIPS_PER_APV;
131  istrip++;
132  }
133  }
134 
135  void setGranularity(bool isPerStrip, bool isPerAPV) {
136  m_servedPerStrip = isPerStrip;
137  m_servedPerAPV = isPerAPV;
138  }
139 
140  bool isCached() { return m_cached; }
141 
142  void setComparedBit() { m_compared = true; }
143 
144  std::vector<unsigned int> detIds(bool verbose) {
145  std::vector<unsigned int> v;
146  for (const auto &element : m_info) {
147  if (verbose) {
148  std::cout << element.first << "\n";
149  }
150  v.push_back(element.first);
151  }
152 
153  return v;
154  }
155 
156  private:
157  std::map<unsigned int, std::vector<type> > m_info;
160  bool m_cached;
162 
163  void init() {
164  m_servedPerStrip = false;
165  m_servedPerAPV = false;
166  m_info.clear();
167  m_cached = false;
168  m_compared = false;
169  }
170  };
171 
172  //used to produce all display objects for payload inspector
173  template <class Item, class type>
175  public:
176  SiStripDataContainer(const std::shared_ptr<Item> &payload,
178  const std::string &tagname)
179  : payload_(payload),
180  run_(std::get<0>(metadata)),
181  hash_(std::get<1>(metadata)),
182  tagname_(tagname),
184  edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())) {
188  additionalIOV_ = std::make_tuple(-1, "", "");
189  }
190 
191  virtual ~SiStripDataContainer() = default;
192 
194  const unsigned int run() const { return run_; }
195  const unsigned int run2() const { return std::get<0>(additionalIOV_); }
196  const std::string &hash() const { return hash_; }
197  const std::string &hash2() const { return std::get<1>(additionalIOV_); }
198  const SiStripPI::MetaData metaData() const { return std::make_tuple(run_, hash_); }
199  const std::string &tagName() const { return tagname_; }
200  const std::string &tagName2() const { return std::get<2>(additionalIOV_); }
201  const std::string &topoMode() const { return TopoMode_; }
202  const std::string &payloadName() const { return payloadType_; }
203  const plotType &getPlotType() const { return plotMode_; }
204  const bool isMultiTag() { return (tagname_ != this->tagName2() && !(this->tagName2()).empty()); }
205 
206  void setPlotType(plotType myType) { plotMode_ = myType; }
207  void setPayloadType(std::string myPayloadType) { payloadType_ = myPayloadType; }
208  void setGranularity(granularity myGranularity) {
209  granularity_ = myGranularity;
210 
211  switch (myGranularity) {
212  case PERSTRIP:
213  SiStripCondData_.setGranularity(true, false);
214  break;
215  case PERAPV:
216  SiStripCondData_.setGranularity(false, true);
217  break;
218  case PERMODULE:
219  SiStripCondData_.setGranularity(false, false);
220  break;
221  default:
222  edm::LogError("LogicError") << "Unknown granularity type: " << myGranularity;
223  }
224  }
225 
226  void setAdditionalIOV(const unsigned int run, const std::string &hash, const std::string &tagname) {
227  std::get<0>(additionalIOV_) = run;
228  std::get<1>(additionalIOV_) = hash;
229  std::get<2>(additionalIOV_) = tagname;
230  };
231 
233  virtual void storeAllValues() {
234  throw cms::Exception("Value definition not found")
235  << "storeAllValues definition not found for " << payloadName() << "\n;";
236  };
237 
239 
240  /***********************************************************************/
241  const char *plotDescriptor()
242  /***********************************************************************/
243  {
244  const char *thePlotType = "";
245  switch (plotMode_) {
246  case STANDARD:
247  thePlotType = Form("Display - IOV: %i", run_);
248  break;
249  case COMPARISON:
250  thePlotType = "Display";
251  break;
252  case DIFF:
253  thePlotType = Form("#Delta (%i-%i)", run_, std::get<0>(additionalIOV_));
254  break;
255  case RATIO:
256  thePlotType = Form("Ratio (%i/%i)", run_, std::get<0>(additionalIOV_));
257  break;
258  case MAP:
259  thePlotType = Form("TrackerMap - %s", hash_.c_str());
260  break;
261  case END_OF_TYPES:
262  edm::LogError("LogicError") << "Unknown plot type: " << plotMode_;
263  break;
264  default:
265  edm::LogError("LogicError") << "Unknown plot type: " << plotMode_;
266  break;
267  }
268 
269  return thePlotType;
270  }
271 
272  // all methods needed for comparison of 2 IOVs
273 
274  /***********************************************************************/
275  void compare(SiStripDataContainer *dataCont2)
276  /***********************************************************************/
277  {
279  dataCont2->setPlotType(COMPARISON);
280  SiStripCondData_.setComparedBit();
281 
282  setAdditionalIOV(dataCont2->run(), dataCont2->hash(), dataCont2->tagName());
283 
284  if (!SiStripCondData_.isCached())
285  storeAllValues();
286  dataCont2->storeAllValues();
287  auto SiStripCondData2_ = dataCont2->siStripCondData();
288 
289  auto listOfDetIds = SiStripCondData_.detIds(false);
290  for (const auto &detId : listOfDetIds) {
291  auto entriesToAdd = SiStripCondData2_.data(detId);
292  for (const auto &entry : entriesToAdd) {
293  SiStripCondData_.fillByPushBack(detId, entry);
294  }
295  }
296  }
297 
298  /***********************************************************************/
299  void divide(SiStripDataContainer *dataCont2)
300  /***********************************************************************/
301  {
302  plotMode_ = RATIO;
303  dataCont2->setPlotType(RATIO);
304 
305  setAdditionalIOV(dataCont2->run(), dataCont2->hash(), dataCont2->tagName());
306 
307  if (!SiStripCondData_.isCached())
308  storeAllValues();
309  dataCont2->storeAllValues();
310  auto SiStripCondData2_ = dataCont2->siStripCondData();
311 
312  auto listOfDetIds = SiStripCondData_.detIds(false);
313  for (const auto &detId : listOfDetIds) {
314  SiStripCondData_.divide(detId, SiStripCondData2_.data(detId));
315  }
316  }
317 
318  /***********************************************************************/
320  /***********************************************************************/
321  {
322  plotMode_ = DIFF;
323  dataCont2->setPlotType(DIFF);
324 
325  setAdditionalIOV(dataCont2->run(), dataCont2->hash(), dataCont2->tagName());
326 
327  if (!SiStripCondData_.isCached())
328  storeAllValues();
329  dataCont2->storeAllValues();
330  auto SiStripCondData2_ = dataCont2->siStripCondData();
331 
332  auto listOfDetIds = SiStripCondData_.detIds(false);
333  for (const auto &detId : listOfDetIds) {
334  SiStripCondData_.subtract(detId, SiStripCondData2_.data(detId));
335  }
336  }
337 
338  /***********************************************************************/
339  void printAll()
340  /***********************************************************************/
341  {
342  if (!SiStripCondData_.isCached())
343  storeAllValues();
344  auto listOfDetIds = SiStripCondData_.detIds(false);
345  for (const auto &detId : listOfDetIds) {
346  std::cout << detId << ": ";
347  auto values = SiStripCondData_.data(detId);
348  for (const auto &value : values) {
349  std::cout << value << " ";
350  }
351  std::cout << "\n";
352  }
353  }
354 
355  /***********************************************************************/
357  std::pair<float, float> &range,
358  const SiStripPI::estimator &est,
359  const int nsigmas_of_saturation)
360  /***********************************************************************/
361  {
362  std::string titleMap;
363  if (plotMode_ != DIFF && plotMode_ != RATIO) {
364  titleMap =
365  "Tracker Map of " + payloadType_ + " " + estimatorType(est) + " per module (payload : " + hash_ + ")";
366  } else {
367  titleMap = "Tracker Map of " + payloadType_ + " " + Form("%s", plotDescriptor()) + " " + estimatorType(est) +
368  " per module";
369  }
370 
371  tmap = new TrackerMap(payloadType_);
372  tmap->setTitle(titleMap);
373  tmap->setPalette(1);
374 
375  // storage of info
376  std::map<unsigned int, float> info_per_detid;
377 
378  if (!SiStripCondData_.isCached())
379  storeAllValues();
380  auto listOfDetIds = SiStripCondData_.detIds(false);
381  for (const auto &detId : listOfDetIds) {
382  auto values = SiStripCondData_.data(detId);
383 
384  unsigned int nElements = values.size();
385  double mean(0.), rms(0.), min(10000.), max(0.);
386 
387  for (const auto &value : values) {
388  mean += value;
389  rms += value * value;
390  if (value < min)
391  min = value;
392  if (value > max)
393  max = value;
394  }
395 
396  mean /= nElements;
397  if ((rms / nElements - mean * mean) > 0.) {
398  rms = sqrt(rms / nElements - mean * mean);
399  } else {
400  rms = 0.;
401  }
402 
403  switch (est) {
404  case SiStripPI::min:
405  info_per_detid[detId] = min;
406  break;
407  case SiStripPI::max:
408  info_per_detid[detId] = max;
409  break;
410  case SiStripPI::mean:
411  info_per_detid[detId] = mean;
412  break;
413  case SiStripPI::rms:
414  info_per_detid[detId] = rms;
415  break;
416  default:
417  edm::LogWarning("LogicError") << "Unknown estimator: " << est;
418  break;
419  }
420  }
421 
422  // loop on the map
423  for (const auto &item : info_per_detid) {
424  tmap->fill(item.first, item.second);
425  }
426 
427  range = SiStripPI::getTheRange(info_per_detid, nsigmas_of_saturation);
428  }
429 
430  /***********************************************************************/
431  void fillValuePlot(TCanvas &canvas, const SiStripPI::OpMode &op_mode_, int nbins, float min, float max)
432  /***********************************************************************/
433  {
434  auto myMode = op_mode_;
435  // check the consistency first
436 
437  if (granularity_ == PERAPV) {
438  switch (op_mode_) {
440  edm::LogError("LogicError") << " Cannot display average per " << opType(op_mode_).c_str()
441  << " in a conditions served per APV";
442  return;
444  myMode = SiStripPI::STRIP_BASED;
445  break;
446  default:
447  break;
448  }
449  } else if (granularity_ == PERMODULE) {
450  if (op_mode_ == SiStripPI::STRIP_BASED || op_mode_ == SiStripPI::APV_BASED) {
451  edm::LogError("LogicError") << " Cannot display average per " << opType(op_mode_).c_str()
452  << " in a conditions served per module";
453  return;
454  }
455  }
456 
457  SiStripPI::Monitor1D *f_mon = nullptr;
458  SiStripPI::Monitor1D *l_mon = nullptr;
459 
460  f_mon = new SiStripPI::Monitor1D(myMode,
461  "first",
462  Form("#LT %s #GT per %s;#LT%s per %s#GT %s;n. %ss",
463  payloadType_.c_str(),
464  opType(op_mode_).c_str(),
465  payloadType_.c_str(),
466  opType(op_mode_).c_str(),
467  (units_[payloadType_]).c_str(),
468  opType(op_mode_).c_str()),
469  nbins,
470  min,
471  max);
472 
473  if (plotMode_ == COMPARISON) {
474  l_mon = new SiStripPI::Monitor1D(myMode,
475  "last",
476  Form("#LT %s #GT per %s;#LT%s per %s#GT %s;n. %ss",
477  payloadType_.c_str(),
478  opType(op_mode_).c_str(),
479  payloadType_.c_str(),
480  opType(op_mode_).c_str(),
481  (units_[payloadType_]).c_str(),
482  opType(op_mode_).c_str()),
483  nbins,
484  min,
485  max);
486  }
487 
488  // retrieve the data
489  if (!SiStripCondData_.isCached())
490  storeAllValues();
491  auto listOfDetIds = SiStripCondData_.detIds(false);
492 
493  unsigned int prev_det = 0;
494  unsigned int prev_apv = 0;
495  SiStripPI::Entry f_entryContainer;
496  SiStripPI::Entry l_entryContainer;
497 
498  std::cout << "mode:" << opType(myMode) << " granularity: " << granularity_
499  << " listOfDetIds.size(): " << listOfDetIds.size() << std::endl;
500 
501  for (const auto &detId : listOfDetIds) {
502  if (plotMode_ == COMPARISON) {
503  auto values = SiStripCondData_.demuxedData(detId);
504  SiStripCondData_.fillMonitor1D(myMode, f_mon, f_entryContainer, values.first, prev_det, prev_apv, detId);
505  SiStripCondData_.fillMonitor1D(myMode, l_mon, l_entryContainer, values.second, prev_det, prev_apv, detId);
506  } else {
507  auto values = SiStripCondData_.data(detId);
508  SiStripCondData_.fillMonitor1D(myMode, f_mon, l_entryContainer, values, prev_det, prev_apv, detId);
509  }
510  prev_det = detId;
511  }
512 
513  TH1F *h_first = (TH1F *)(f_mon->getHist()).Clone("h_first");
514  h_first->SetStats(kFALSE);
516  h_first->GetYaxis()->CenterTitle(true);
517  h_first->GetXaxis()->CenterTitle(true);
518  h_first->SetLineWidth(2);
519  h_first->SetLineColor(kBlack);
520 
521  //=========================
522  canvas.cd();
523  canvas.SetBottomMargin(0.11);
524  canvas.SetLeftMargin(0.13);
525  canvas.SetRightMargin(0.05);
526  //canvas.Modified();
527 
528  TLegend *legend = new TLegend(0.52, 0.82, 0.95, 0.9);
529  legend->SetTextSize(0.025);
530 
531  if (plotMode_ != COMPARISON) {
532  float theMax = h_first->GetMaximum();
533  h_first->SetMaximum(theMax * 1.30);
534  h_first->Draw();
535 
536  legend->AddEntry(h_first, Form("IOV: %i", run_), "L");
537 
538  } else {
539  TH1F *h_last = (TH1F *)(l_mon->getHist()).Clone("h_last");
540  h_last->SetStats(kFALSE);
542  h_last->GetYaxis()->CenterTitle(true);
543  h_last->GetXaxis()->CenterTitle(true);
544  h_last->SetLineWidth(2);
545  h_last->SetLineColor(kBlue);
546 
547  std::cout << h_first->GetEntries() << " ---- " << h_last->GetEntries() << std::endl;
548 
549  float theMax = (h_first->GetMaximum() > h_last->GetMaximum()) ? h_first->GetMaximum() : h_last->GetMaximum();
550 
551  h_first->SetMaximum(theMax * 1.30);
552  h_last->SetMaximum(theMax * 1.30);
553 
554  h_first->Draw();
555  h_last->Draw("same");
556 
557  legend->SetHeader(Form("%s comparison", payloadType_.c_str()), "C"); // option "C" allows to center the header
558  legend->AddEntry(h_first, Form("IOV: %i", run_), "F");
559  legend->AddEntry(h_last, Form("IOV: %i", (std::get<0>(additionalIOV_))), "F");
560  }
561 
562  legend->Draw("same");
563  }
564 
565  /***********************************************************************/
566  void fillSummary(TCanvas &canvas)
567  /***********************************************************************/
568  {
569  std::map<unsigned int, SiStripDetSummary::Values> f_map;
570  std::map<unsigned int, SiStripDetSummary::Values> l_map;
571 
572  if (!SiStripCondData_.isCached())
573  storeAllValues();
574  auto listOfDetIds = SiStripCondData_.detIds(false);
575 
576  if (plotMode_ == COMPARISON) {
577  for (const auto &detId : listOfDetIds) {
578  auto values = SiStripCondData_.demuxedData(detId);
579  for (const auto &value : values.first) {
580  summary.add(detId, value);
581  }
582  }
583 
584  f_map = summary.getCounts();
585  summary.clear();
586 
587  for (const auto &detId : listOfDetIds) {
588  auto values = SiStripCondData_.demuxedData(detId);
589  for (const auto &value : values.second) {
590  summary.add(detId, value);
591  }
592  }
593 
594  l_map = summary.getCounts();
595 
596  } else {
597  for (const auto &detId : listOfDetIds) {
598  auto values = SiStripCondData_.data(detId);
599  for (const auto &value : values) {
600  summary.add(detId, value);
601  }
602  }
603  f_map = summary.getCounts();
604  }
605 
606  if (plotMode_ == COMPARISON) {
607  std::cout << "f map size: " << f_map.size() << " l map size:" << l_map.size() << std::endl;
608  assert(f_map.size() == l_map.size());
609  }
610  //=========================
611 
612  canvas.cd();
613  auto h1 = new TH1F(
614  "byRegion1",
615  Form("SiStrip %s average by region;; average SiStrip %s", payloadType_.c_str(), payloadType_.c_str()),
616  f_map.size(),
617  0.,
618  f_map.size());
619  h1->SetStats(false);
620 
621  auto h2 = new TH1F(
622  "byRegion2",
623  Form("SiStrip %s average by region;; average SiStrip %s", payloadType_.c_str(), payloadType_.c_str()),
624  f_map.size(),
625  0.,
626  f_map.size());
627  h2->SetStats(false);
628 
629  canvas.SetBottomMargin(0.18);
630  canvas.SetLeftMargin(0.17);
631  canvas.SetRightMargin(0.05);
632  canvas.Modified();
633 
634  std::vector<int> boundaries;
635  unsigned int iBin = 0;
636 
638  std::string currentDetector;
639 
640  for (const auto &element : f_map) {
641  iBin++;
642  int count = element.second.count;
643  double mean = (element.second.mean) / count;
644 
645  if (currentDetector.empty())
646  currentDetector = "TIB";
647 
648  switch ((element.first) / 1000) {
649  case 1:
650  detector = "TIB";
651  break;
652  case 2:
653  detector = "TOB";
654  break;
655  case 3:
656  detector = "TEC";
657  break;
658  case 4:
659  detector = "TID";
660  break;
661  }
662 
663  h1->SetBinContent(iBin, mean);
664  h1->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
665  h1->GetXaxis()->LabelsOption("v");
666 
667  if (detector != currentDetector) {
668  boundaries.push_back(iBin);
669  currentDetector = detector;
670  }
671  }
672 
673  iBin = 0;
674  if (plotMode_ == COMPARISON) {
675  for (const auto &element : l_map) {
676  iBin++;
677  int count = element.second.count;
678  double mean = (element.second.mean) / count;
679 
680  h2->SetBinContent(iBin, mean);
681  h2->GetXaxis()->SetBinLabel(iBin, SiStripPI::regionType(element.first).second);
682  h2->GetXaxis()->LabelsOption("v");
683  }
684  }
685 
686  h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
687  h1->SetMarkerStyle(20);
688  h1->SetMarkerSize(1.5);
689  h1->Draw("HIST");
690  h1->Draw("Psame");
691 
692  if (plotMode_ == COMPARISON) {
693  h2->GetYaxis()->SetRangeUser(0., h2->GetMaximum() * 1.30);
694  h2->SetMarkerStyle(25);
695  h2->SetMarkerColor(kBlue);
696  h2->SetLineColor(kBlue);
697  h2->SetMarkerSize(1.5);
698  h2->Draw("HISTsame");
699  h2->Draw("Psame");
700  }
701 
702  canvas.Update();
703 
704  TLine *l[boundaries.size()];
705  unsigned int i = 0;
706  for (const auto &line : boundaries) {
707  l[i] = new TLine(h1->GetBinLowEdge(line), canvas.GetUymin(), h1->GetBinLowEdge(line), canvas.GetUymax());
708  l[i]->SetLineWidth(1);
709  l[i]->SetLineStyle(9);
710  l[i]->SetLineColor(2);
711  l[i]->Draw("same");
712  i++;
713  }
714 
715  TLegend *legend = new TLegend(0.52, 0.82, 0.95, 0.9);
716  legend->SetHeader(hash_.c_str(), "C"); // option "C" allows to center the header
717  legend->AddEntry(h1, Form("IOV: %i", run_), "PL");
718  if (plotMode_ == COMPARISON) {
719  legend->AddEntry(h2, Form("IOV: %i", std::get<0>(additionalIOV_)), "PL");
720  }
721  legend->SetTextSize(0.025);
722  legend->Draw("same");
723  }
724 
725  /***********************************************************************/
726  void fillByPartition(TCanvas &canvas, int nbins, float min, float max)
727  /***********************************************************************/
728  {
729  std::map<std::string, TH1F *> h_parts;
730  std::map<std::string, TH1F *> h_parts2;
731  std::vector<std::string> parts = {"TEC", "TOB", "TIB", "TID"};
732 
733  const char *device;
734  switch (granularity_) {
735  case PERSTRIP:
736  device = "strips";
737  break;
738  case PERAPV:
739  device = "APVs";
740  break;
741  case PERMODULE:
742  device = "modules";
743  break;
744  default:
745  device = "unrecognized device";
746  break;
747  }
748 
749  for (const auto &part : parts) {
750  TString globalTitle = Form("%s - %s %s;%s %s;n. %s",
751  plotDescriptor(),
752  payloadType_.c_str(),
753  part.c_str(),
754  payloadType_.c_str(),
755  (units_[payloadType_]).c_str(),
756  device);
757 
758  h_parts[part] = new TH1F(Form("h_%s", part.c_str()), globalTitle, nbins, min, max);
759  h_parts[part]->SetTitle(""); /* remove the title from display */
760  if (plotMode_ == COMPARISON) {
761  h_parts2[part] = new TH1F(Form("h2_%s", part.c_str()), globalTitle, nbins, min, max);
762  h_parts2[part]->SetTitle(""); /* remove the title from display */
763  }
764  }
765 
766  if (!SiStripCondData_.isCached())
767  storeAllValues();
768  auto listOfDetIds = SiStripCondData_.detIds(false);
769  for (const auto &detId : listOfDetIds) {
770  auto values = SiStripCondData_.data(detId);
771  int subid = DetId(detId).subdetId();
772  unsigned int counter{0};
773  for (const auto &value : values) {
774  counter++;
775  switch (subid) {
777  if ((plotMode_ == COMPARISON) && (counter > (values.size() / 2))) {
778  h_parts2["TIB"]->Fill(value);
779  } else {
780  h_parts["TIB"]->Fill(value);
781  }
782  break;
784  if ((plotMode_ == COMPARISON) && (counter > (values.size() / 2))) {
785  h_parts2["TID"]->Fill(value);
786  } else {
787  h_parts["TID"]->Fill(value);
788  }
789  break;
791  if ((plotMode_ == COMPARISON) && (counter > (values.size() / 2))) {
792  h_parts2["TOB"]->Fill(value);
793  } else {
794  h_parts["TOB"]->Fill(value);
795  }
796  break;
798  if ((plotMode_ == COMPARISON) && (counter > (values.size() / 2))) {
799  h_parts2["TEC"]->Fill(value);
800  } else {
801  h_parts["TEC"]->Fill(value);
802  }
803  break;
804  default:
805  edm::LogError("LogicError") << "Unknown partition: " << subid;
806  break;
807  }
808  }
809  }
810 
811  canvas.Divide(2, 2);
812 
813  auto ltx = TLatex();
814  ltx.SetTextFont(62);
815  ltx.SetTextSize(0.05);
816  ltx.SetTextAlign(31);
817 
818  int index = 0;
819  for (const auto &part : parts) {
820  index++;
821  canvas.cd(index)->SetTopMargin(0.07);
822  canvas.cd(index)->SetLeftMargin(0.13);
823  canvas.cd(index)->SetRightMargin(0.08);
824 
826  h_parts[part]->SetMinimum(1.);
827  h_parts[part]->SetStats(false);
828  h_parts[part]->SetLineWidth(2);
829 
830  if (plotMode_ != COMPARISON) {
831  h_parts[part]->SetLineColor(k_colormap.at(part));
832  h_parts[part]->SetFillColorAlpha(k_colormap.at(part), 0.15);
833  float theMax = h_parts[part]->GetMaximum();
834  h_parts[part]->SetMaximum(theMax * 1.30);
835  } else {
836  h_parts[part]->SetLineColor(kBlack);
837 
839  h_parts2[part]->SetMinimum(1.);
840  h_parts2[part]->SetStats(false);
841  h_parts2[part]->SetLineWidth(2);
842  h_parts2[part]->SetLineColor(kBlue);
843  h_parts2[part]->SetFillColorAlpha(kBlue, 0.15);
844 
845  float theMax = (h_parts[part]->GetMaximum() > h_parts2[part]->GetMaximum()) ? h_parts[part]->GetMaximum()
846  : h_parts2[part]->GetMaximum();
847 
848  h_parts[part]->SetMaximum(theMax * 1.30);
849  h_parts2[part]->SetMaximum(theMax * 1.30);
850  }
851 
852  h_parts[part]->Draw();
853  if (plotMode_ == COMPARISON) {
854  h_parts2[part]->Draw("same");
855  }
856 
857  TLegend *leg = new TLegend(.13, 0.81, 0.92, 0.93);
858  if (plotMode_ != COMPARISON) {
859  // it means it's a difference
860  if (this->isMultiTag()) {
861  leg->SetHeader("#bf{Two Tags Difference}", "C"); // option "C" allows to center the header
862  leg->AddEntry(h_parts[part],
863  (fmt::sprintf("#splitline{%s : %i}{%s : %i}", tagName(), run(), tagName2(), run2())).c_str(),
864  "F");
865  } else {
866  leg->SetHeader(("tag: #bf{" + tagName() + "}").c_str(), "C"); // option "C" allows to center the header
867  leg->AddEntry(h_parts[part], (fmt::sprintf("%s", plotDescriptor())).c_str(), "F");
868  }
869  leg->SetTextSize(0.04);
870  leg->Draw("same");
871  ltx.DrawLatexNDC(
872  0.35,
873  0.7,
874  (fmt::sprintf("#splitline{#mu = %.2f}{r.m.s. = %.2f}", h_parts[part]->GetMean(), h_parts[part]->GetRMS()))
875  .c_str());
876  ltx.DrawLatexNDC(1 - gPad->GetRightMargin(),
877  1 - gPad->GetTopMargin() + 0.01,
878  (fmt::sprintf("#color[2]{%s} %s Values %s", part, payloadType_, plotDescriptor())).c_str());
879  } else {
880  if (this->isMultiTag()) {
881  leg->SetHeader("#bf{Two Tags Comparison}", "C"); // option "C" allows to center the header
882  leg->AddEntry(h_parts[part], (fmt::sprintf("%s : %i", tagName(), run())).c_str(), "F");
883  leg->AddEntry(h_parts2[part], (fmt::sprintf("%s : %i", tagName2(), run2())).c_str(), "F");
884  } else {
885  leg->SetHeader(("tag: #bf{" + tagName() + "}").c_str(), "C"); // option "C" allows to center the header
886  leg->AddEntry(h_parts[part], (fmt::sprintf("IOV since: %i", this->run())).c_str(), "F");
887  leg->AddEntry(h_parts2[part], (fmt::sprintf("IOV since: %i", this->run2())).c_str(), "F");
888  }
889  leg->SetTextSize(0.035);
890  leg->Draw("same");
891  ltx.DrawLatexNDC(1 - gPad->GetRightMargin(),
892  1 - gPad->GetTopMargin() + 0.01,
893  (fmt::sprintf("#color[2]{%s} %s Values Comparison", part, payloadType_)).c_str());
894  }
895  }
896  }
897 
898  /***********************************************************************/
899  void fillCorrelationByPartition(TCanvas &canvas, int nbins, float min, float max)
900  /***********************************************************************/
901  {
902  SiStripPI::setPaletteStyle(SiStripPI::DEFAULT); /* better looking palette ;)*/
903 
904  if (plotMode_ != COMPARISON) {
905  throw cms::Exception("Logic error") << "not being in compared mode, cannot plot correlations";
906  }
907 
908  std::map<std::string, TH2F *> h2_parts;
909  std::vector<std::string> parts = {"TEC", "TOB", "TIB", "TID"};
910 
911  const char *device;
912  switch (granularity_) {
913  case PERSTRIP:
914  device = "strips";
915  break;
916  case PERAPV:
917  device = "APVs";
918  break;
919  case PERMODULE:
920  device = "modules";
921  break;
922  default:
923  device = "unrecognized device";
924  break;
925  }
926 
927  for (const auto &part : parts) {
928  TString globalTitle = Form("%s - %s %s;%s %s (#color[4]{%s});%s %s (#color[4]{%s});n. %s",
929  "Correlation", // FIXME: can use the plotDescriptor()
930  payloadType_.c_str(),
931  part.c_str(),
932  payloadType_.c_str(),
933  (units_[payloadType_]).c_str(),
934  std::to_string(run_).c_str(),
935  payloadType_.c_str(),
936  (units_[payloadType_]).c_str(),
937  std::to_string(std::get<0>(additionalIOV_)).c_str(),
938  device);
939 
940  h2_parts[part] = new TH2F(Form("h2_%s", part.c_str()), globalTitle, nbins, min, max, nbins, min, max);
941  }
942 
943  if (!SiStripCondData_.isCached())
944  storeAllValues();
945  auto listOfDetIds = SiStripCondData_.detIds(false);
946  for (const auto &detId : listOfDetIds) {
947  auto values = SiStripCondData_.demuxedData(detId);
948  int subid = DetId(detId).subdetId();
949  unsigned int counter{0};
950  for (const auto &value : values.first) {
951  switch (subid) {
953  h2_parts["TIB"]->Fill(value, (values.second)[counter]);
954  break;
956  h2_parts["TID"]->Fill(value, (values.second)[counter]);
957  break;
959  h2_parts["TOB"]->Fill(value, (values.second)[counter]);
960  break;
962  h2_parts["TEC"]->Fill(value, (values.second)[counter]);
963  break;
964  default:
965  edm::LogError("LogicError") << "Unknown partition: " << subid;
966  break;
967  }
968  counter++;
969  }
970  }
971 
972  canvas.Divide(2, 2);
973 
974  int index = 0;
975  for (const auto &part : parts) {
976  index++;
977  canvas.cd(index)->SetTopMargin(0.07);
978  canvas.cd(index)->SetLeftMargin(0.13);
979  canvas.cd(index)->SetRightMargin(0.17);
980 
982  h2_parts[part]->GetZaxis()->SetTitleOffset(1.6);
983  h2_parts[part]->GetZaxis()->SetTitleSize(0.04);
984  h2_parts[part]->GetZaxis()->CenterTitle();
985  h2_parts[part]->GetZaxis()->SetMaxDigits(2); /* exponentiate z-axis */
986 
987  //h2_parts[part]->SetMarkerColor(k_colormap.at(part));
988  //h2_parts[part]->SetMarkerStyle(k_markermap.at(part));
989  //h2_parts[part]->SetStats(false);
990  //h2_parts[part]->Draw("P");
991  h2_parts[part]->Draw("colz");
992 
993  TLegend *leg = new TLegend(.13, 0.87, 0.27, 0.93);
994  leg->SetTextSize(0.045);
995  leg->SetHeader(Form("#bf{%s}", part.c_str()), "C"); // option "C" allows to center the header
996  //leg->AddEntry(h2_parts[part], Form("#DeltaIOV: #splitline{%i}{%i}", run_, std::get<0>(additionalIOV_)),"P");
997  leg->Draw("same");
998  }
999  }
1000 
1001  protected:
1002  std::shared_ptr<Item> payload_;
1005 
1006  private:
1007  unsigned int run_;
1014  // "Map", "Ratio", or "Diff"
1016  std::tuple<int, std::string, std::string> additionalIOV_;
1017 
1018  std::map<std::string, std::string> units_ = {{"SiStripPedestals", "[ADC counts]"},
1019  {"SiStripApvGain", ""}, //dimensionless TODO: verify
1020  {"SiStripNoises", "[ADC counts]"},
1021  {"SiStripLorentzAngle", "[1/T}]"},
1022  {"SiStripBackPlaneCorrection", ""},
1023  {"SiStripBadStrip", ""}, // dimensionless
1024  {"SiStripDetVOff", ""}}; // dimensionless
1025 
1027  std::string types[3] = {"Strip", "APV", "Module"};
1028  return types[mode];
1029  }
1030  };
1031 
1032 } // namespace SiStripCondObjectRepresent
1033 
1034 #endif
size
Write out results.
static constexpr auto TEC
std::map< unsigned int, Values > getCounts()
std::pair< int, const char * > regionType(int index)
bool verbose
void setAdditionalIOV(const unsigned int run, const std::string &hash, const std::string &tagname)
void divide(unsigned int detid, const std::vector< type > &denominator)
std::pair< std::vector< type >, std::vector< type > > demuxedData(unsigned int detid)
std::string to_string(const V &value)
Definition: OMSAccess.h:77
void fillValuePlot(TCanvas &canvas, const SiStripPI::OpMode &op_mode_, int nbins, float min, float max)
Log< level::Error, false > LogError
static const std::map< std::string, int > k_markermap
void setPaletteStyle(SiStripPI::palette palette)
assert(be >=bs)
std::map< unsigned int, std::vector< type > > m_info
void setTitle(std::string s)
Definition: TrackerMap.h:158
void fillCorrelationByPartition(TCanvas &canvas, int nbins, float min, float max)
std::vector< unsigned int > detIds(bool verbose)
std::tuple< cond::Time_t, cond::Hash > MetaData
std::pair< float, float > getTheRange(std::map< uint32_t, float > values, const float nsigma)
SiStripDataContainer(const std::shared_ptr< Item > &payload, const SiStripPI::MetaData &metadata, const std::string &tagname)
T sqrt(T t)
Definition: SSEVec.h:19
void setPalette(int numpalette)
Definition: TrackerMap.h:155
void fillByPushBack(unsigned int detid, const type &value)
void add(DetId detid, float value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
void makeNicePlotStyle(TH1 *hist)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void fillMonitor1D(const SiStripPI::OpMode &mymode, SiStripPI::Monitor1D *&mon, SiStripPI::Entry &entry, std::vector< type > &values, const unsigned int prev_det, unsigned int &prev_apv, const unsigned int detid)
Definition: value.py:1
static constexpr auto TOB
std::string estimatorType(SiStripPI::estimator e)
Definition: DetId.h:17
static constexpr auto TIB
void fillByPartition(TCanvas &canvas, int nbins, float min, float max)
void fillAll(unsigned int detid, const std::vector< type > &store)
part
Definition: HCALResponse.h:20
static const std::map< std::string, int > k_colormap
HLT enums.
std::vector< type > data(unsigned int detid)
static const uint16_t STRIPS_PER_APV
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:482
void fillTrackerMap(TrackerMap *&tmap, std::pair< float, float > &range, const SiStripPI::estimator &est, const int nsigmas_of_saturation)
#define get
Log< level::Warning, false > LogWarning
std::tuple< int, std::string, std::string > additionalIOV_
static constexpr auto TID
void fill(int layer, int ring, int nmod, float x)
Definition: TrackerMap.cc:3289
void subtract(unsigned int detid, const std::vector< type > &subtractor)