CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AlignPCLThresholds_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
13 // the data format of the condition to be inspected
15 
16 #include <memory>
17 #include <sstream>
18 #include <iostream>
19 #include <functional>
20 
21 // include ROOT
22 #include "TH2F.h"
23 #include "TLegend.h"
24 #include "TCanvas.h"
25 #include "TLine.h"
26 #include "TStyle.h"
27 
28 namespace {
29 
30  enum types { DELTA, SIG, MAXMOVE, MAXERR, END_OF_TYPES };
31 
32  /************************************************
33  Display of AlignPCLThresholds
34  *************************************************/
35  class AlignPCLThresholds_Display : public cond::payloadInspector::PlotImage<AlignPCLThresholds> {
36  public:
37  AlignPCLThresholds_Display()
38  : cond::payloadInspector::PlotImage<AlignPCLThresholds>("Display of threshold parameters for SiPixelAli PCL") {
39  setSingleIov(true);
40  }
41 
42  bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
43  auto iov = iovs.front();
44  std::shared_ptr<AlignPCLThresholds> payload = fetchPayload(std::get<1>(iov));
45  auto alignables = payload->getAlignableList();
46 
47  TCanvas canvas("Alignment PCL thresholds summary", "Alignment PCL thresholds summary", 1500, 800);
48  canvas.cd();
49 
50  canvas.SetTopMargin(0.07);
51  canvas.SetBottomMargin(0.06);
52  canvas.SetLeftMargin(0.11);
53  canvas.SetRightMargin(0.05);
54  canvas.Modified();
55  canvas.SetGrid();
56 
57  auto Thresholds = std::make_unique<TH2F>(
58  "Thresholds", "Alignment parameter thresholds", alignables.size(), 0, alignables.size(), 24, 0, 24);
59  Thresholds->SetStats(false);
60 
61  std::function<float(types, std::string, AlignPCLThresholds::coordType)> cutFunctor =
62  [&payload](types my_type, std::string alignable, AlignPCLThresholds::coordType coord) {
63  float ret(-999.);
64  switch (my_type) {
65  case DELTA:
66  return payload->getCut(alignable, coord);
67  case SIG:
68  return payload->getSigCut(alignable, coord);
69  case MAXMOVE:
70  return payload->getMaxMoveCut(alignable, coord);
71  case MAXERR:
72  return payload->getMaxErrorCut(alignable, coord);
73  case END_OF_TYPES:
74  return ret;
75  default:
76  return ret;
77  }
78  };
79 
80  unsigned int xBin = 0;
81  for (const auto& alignable : alignables) {
82  xBin++;
83 
84  auto xLabel = replaceAll(replaceAll(alignable, "minus", "(-)"), "plus", "(+)");
85  Thresholds->GetXaxis()->SetBinLabel(xBin, (xLabel).c_str());
86  unsigned int yBin = 24;
87  for (int foo = AlignPCLThresholds::X; foo != AlignPCLThresholds::extra_DOF; foo++) {
89  for (int bar = types::DELTA; bar != types::END_OF_TYPES; bar++) {
90  types type = static_cast<types>(bar);
91  std::string theLabel = getStringFromTypeEnum(type) + getStringFromCoordEnum(coord);
92  if (xBin == 1) {
93  Thresholds->GetYaxis()->SetBinLabel(yBin, theLabel.c_str());
94  }
95 
96  Thresholds->SetBinContent(xBin, yBin, cutFunctor(type, alignable, coord));
97 
98  yBin--;
99  } // loop on types
100  } // loop on coordinates
101  } // loop on alignables
102 
103  Thresholds->GetXaxis()->LabelsOption("h");
104  Thresholds->Draw("TEXT");
105 
106  std::string fileName(m_imageFileName);
107  canvas.SaveAs(fileName.c_str());
108 
109  return true;
110  }
111 
112  /************************************************/
113  std::string getStringFromCoordEnum(const AlignPCLThresholds::coordType& coord) {
114  switch (coord) {
116  return "X";
118  return "Y";
120  return "Z";
122  return "#theta_{X}";
124  return "#theta_{Y}";
126  return "#theta_{Z}";
127  default:
128  return "should never be here";
129  }
130  }
131 
132  /************************************************/
134  switch (type) {
135  case types::DELTA:
136  return "#Delta";
137  case types::SIG:
138  return "#Delta/#sigma ";
139  case types::MAXMOVE:
140  return "max. move ";
141  case types::MAXERR:
142  return "max. err ";
143  default:
144  return "should never be here";
145  }
146  }
147 
148  /************************************************/
149  std::string replaceAll(const std::string& str, const std::string& from, const std::string& to) {
150  std::string out(str);
151 
152  if (from.empty())
153  return out;
154  size_t start_pos = 0;
155  while ((start_pos = out.find(from, start_pos)) != std::string::npos) {
156  out.replace(start_pos, from.length(), to);
157  start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
158  }
159  return out;
160  }
161  };
162 } // namespace
163 
164 // Register the classes as boost python plugin
tuple ret
prodAgent to be discontinued
tuple yBin
Definition: cuy.py:892
def canvas
Definition: svgfig.py:482
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
void replaceAll(std::string &str, const std::string &from, const std::string &to)
std::string getStringFromTypeEnum(const parameters &parameter)
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
double const DELTA
Definition: Constants.h:19
#define str(s)
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)