CMS 3D CMS Logo

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 
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++) {
88  AlignPCLThresholds::coordType coord = static_cast<AlignPCLThresholds::coordType>(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) {
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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
AlignPCLThresholds::theta_Y
Definition: AlignPCLThresholds.h:14
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
photonAnalyzer_cfi.xBin
xBin
Definition: photonAnalyzer_cfi.py:81
PayloadInspector.h
to
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
AlignPCLThresholds
Definition: AlignPCLThresholds.h:11
photonAnalyzer_cfi.yBin
yBin
Definition: photonAnalyzer_cfi.py:85
AlignPCLThresholds::X
Definition: AlignPCLThresholds.h:14
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
AlignPCLThresholds::theta_Z
Definition: AlignPCLThresholds.h:14
PayloadInspectorModule.h
PVValHelper::END_OF_TYPES
Definition: PVValidationHelpers.h:65
str
#define str(s)
Definition: TestProcessor.cc:52
jets_cff.payload
payload
Definition: jets_cff.py:32
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
Time.h
AlignPCLThresholds.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
cond::payloadInspector::PlotImage::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:905
AlignPCLThresholds::Z
Definition: AlignPCLThresholds.h:14
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
AlignPCLThresholds::Y
Definition: AlignPCLThresholds.h:14
HLT_FULL_cff.Thresholds
Thresholds
Definition: HLT_FULL_cff.py:35523
types
types
Definition: AlignPCLThresholds_PayloadInspector.cc:30
hcaldqm::constants::DELTA
const double DELTA
Definition: Constants.h:19
AlignPCLThresholds::coordType
coordType
Definition: AlignPCLThresholds.h:14
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
MTDTopologyMode::Mode::bar
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:894
AlignPCLThresholds::theta_X
Definition: AlignPCLThresholds.h:14
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
AlignPCLThresholds::extra_DOF
Definition: AlignPCLThresholds.h:14
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
RunInfoPI::getStringFromTypeEnum
std::string getStringFromTypeEnum(const parameters &parameter)
Definition: RunInfoPayloadInspectoHelper.h:74