CMS 3D CMS Logo

SiPixelQuality_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
17 
18 // the data format of the condition to be inspected
23 
24 #include <memory>
25 #include <sstream>
26 #include <iostream>
27 
28 // include ROOT
29 #include "TH2F.h"
30 #include "TLegend.h"
31 #include "TCanvas.h"
32 #include "TLine.h"
33 #include "TGraph.h"
34 #include "TStyle.h"
35 #include "TLatex.h"
36 #include "TPave.h"
37 #include "TPaveStats.h"
38 
39 namespace {
40 
41  /************************************************
42  test class
43  *************************************************/
44 
45  class SiPixelQualityTest
46  : public cond::payloadInspector::Histogram1D<SiPixelQuality, cond::payloadInspector::SINGLE_IOV> {
47  public:
48  SiPixelQualityTest()
49  : cond::payloadInspector::Histogram1D<SiPixelQuality, cond::payloadInspector::SINGLE_IOV>(
50  "SiPixelQuality test", "SiPixelQuality test", 10, 0.0, 10.0) {}
51 
52  bool fill() override {
53  auto tag = PlotBase::getTag<0>();
54  for (auto const& iov : tag.iovs) {
55  std::shared_ptr<SiPixelQuality> payload = Base::fetchPayload(std::get<1>(iov));
56  if (payload.get()) {
57  fillWithValue(1.);
58 
59  auto theDisabledModules = payload->getBadComponentList();
60  for (const auto& mod : theDisabledModules) {
61  int BadRocCount(0);
62  for (unsigned short n = 0; n < 16; n++) {
63  unsigned short mask = 1 << n; // 1 << n = 2^{n} using bitwise shift
64  if (mod.BadRocs & mask)
65  BadRocCount++;
66  }
67  COUT << "detId:" << mod.DetID << " error type:" << mod.errorType << " BadRocs:" << BadRocCount << std::endl;
68  }
69  } // payload
70  } // iovs
71  return true;
72  } // fill
73  };
74 
75  /************************************************
76  summary class
77  *************************************************/
78 
79  class SiPixelQualityBadRocsSummary
80  : public cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::MULTI_IOV, 1> {
81  public:
82  SiPixelQualityBadRocsSummary()
83  : cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::MULTI_IOV, 1>(
84  "SiPixel Quality Summary") {}
85 
86  bool fill() override {
87  auto tag = PlotBase::getTag<0>();
88  for (const auto& iov : tag.iovs) {
89  std::shared_ptr<SiPixelQuality> payload = fetchPayload(std::get<1>(iov));
90  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
91 
92  COUT << "======================= " << unpacked.first << " : " << unpacked.second << std::endl;
93  auto theDisabledModules = payload->getBadComponentList();
94  for (const auto& mod : theDisabledModules) {
95  COUT << "detId: " << mod.DetID << " |error type: " << mod.errorType << " |BadRocs: " << mod.BadRocs
96  << std::endl;
97  }
98  }
99 
100  //=========================
101  TCanvas canvas("Partion summary", "partition summary", 1200, 1000);
102  canvas.cd();
103  canvas.SetBottomMargin(0.11);
104  canvas.SetLeftMargin(0.13);
105  canvas.SetRightMargin(0.05);
106  canvas.Modified();
107 
108  std::string fileName(m_imageFileName);
109  canvas.SaveAs(fileName.c_str());
110 
111  return true;
112  }
113  };
114 
115  /************************************************
116  time history class
117  *************************************************/
118 
119  class SiPixelQualityBadRocsTimeHistory
120  : public cond::payloadInspector::TimeHistoryPlot<SiPixelQuality, std::pair<double, double> > {
121  public:
122  SiPixelQualityBadRocsTimeHistory()
123  : cond::payloadInspector::TimeHistoryPlot<SiPixelQuality, std::pair<double, double> >("bad ROCs count vs time",
124  "bad ROCs count") {}
125 
126  std::pair<double, double> getFromPayload(SiPixelQuality& payload) override {
127  return std::make_pair(extractBadRocCount(payload), 0.);
128  }
129 
130  unsigned int extractBadRocCount(SiPixelQuality& payload) {
131  unsigned int BadRocCount(0);
132  auto theDisabledModules = payload.getBadComponentList();
133  for (const auto& mod : theDisabledModules) {
134  for (unsigned short n = 0; n < 16; n++) {
135  unsigned short mask = 1 << n; // 1 << n = 2^{n} using bitwise shift
136  if (mod.BadRocs & mask)
137  BadRocCount++;
138  }
139  }
140  return BadRocCount;
141  }
142  };
143 
144  /************************************************
145  occupancy style map BPix
146  *************************************************/
147 
148  class SiPixelBPixQualityMap
149  : public cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::SINGLE_IOV> {
150  public:
151  SiPixelBPixQualityMap()
152  : cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::SINGLE_IOV>(
153  "SiPixelQuality Barrel Pixel Map"),
155  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
156 
157  bool fill() override {
158  auto tag = PlotBase::getTag<0>();
159  auto iov = tag.iovs.front();
160  std::shared_ptr<SiPixelQuality> payload = fetchPayload(std::get<1>(iov));
161 
162  static const int n_layers = 4;
163  int nlad_list[n_layers] = {6, 14, 22, 32};
164  int divide_roc = 1;
165 
166  // --------------------- BOOK HISTOGRAMS
167  std::array<TH2D*, n_layers> h_bpix_occ;
168 
169  for (unsigned int lay = 1; lay <= 4; lay++) {
170  int nlad = nlad_list[lay - 1];
171 
172  std::string name = "occ_Layer_" + std::to_string(lay);
173  std::string title = "; Module # ; Ladder #";
174  h_bpix_occ[lay - 1] = new TH2D(name.c_str(),
175  title.c_str(),
176  72 * divide_roc,
177  -4.5,
178  4.5,
179  (nlad * 4 + 2) * divide_roc,
180  -nlad - 0.5,
181  nlad + 0.5);
182  }
183 
184  auto theDisabledModules = payload->getBadComponentList();
185  for (const auto& mod : theDisabledModules) {
186  int coded_badRocs = mod.BadRocs;
187  int subid = DetId(mod.DetID).subdetId();
188  std::bitset<16> bad_rocs(coded_badRocs);
189  if (subid == PixelSubdetector::PixelBarrel) {
190  auto layer = m_trackerTopo.pxbLayer(DetId(mod.DetID));
191  auto s_ladder = SiPixelPI::signed_ladder(DetId(mod.DetID), m_trackerTopo, true);
192  auto s_module = SiPixelPI::signed_module(DetId(mod.DetID), m_trackerTopo, true);
193 
194  bool isFlipped = SiPixelPI::isBPixOuterLadder(DetId(mod.DetID), m_trackerTopo, false);
195  if ((layer > 1 && s_module < 0))
196  isFlipped = !isFlipped;
197 
198  auto ladder = m_trackerTopo.pxbLadder(DetId(mod.DetID));
199  auto module = m_trackerTopo.pxbModule(DetId(mod.DetID));
200  COUT << "layer:" << layer << " ladder:" << ladder << " module:" << module << " signed ladder: " << s_ladder
201  << " signed module: " << s_module << std::endl;
202 
203  if (payload->IsModuleBad(mod.DetID)) {
204  auto rocsToMask = SiPixelPI::maskedBarrelRocsToBins(layer, s_ladder, s_module);
205  for (const auto& bin : rocsToMask) {
206  h_bpix_occ[layer - 1]->SetBinContent(bin.first, bin.second, 1);
207  }
208  } else {
209  auto rocsToMask = SiPixelPI::maskedBarrelRocsToBins(layer, s_ladder, s_module, bad_rocs, isFlipped);
210  for (const auto& bin : rocsToMask) {
211  h_bpix_occ[layer - 1]->SetBinContent(std::get<0>(bin), std::get<1>(bin), 1);
212  }
213  }
214  }
215  }
216 
217  gStyle->SetOptStat(0);
218  //=========================
219  TCanvas canvas("Summary", "Summary", 1200, 1200);
220  canvas.Divide(2, 2);
221  canvas.SetBottomMargin(0.11);
222  canvas.SetLeftMargin(0.13);
223  canvas.SetRightMargin(0.05);
224  canvas.Modified();
225 
226  for (unsigned int lay = 1; lay <= 4; lay++) {
227  SiPixelPI::dress_occup_plot(canvas, h_bpix_occ[lay - 1], lay, 0, 1);
228  }
229 
230  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
231 
232  for (unsigned int lay = 1; lay <= 4; lay++) {
233  canvas.cd(lay);
234  auto ltx = TLatex();
235  ltx.SetTextFont(62);
236  ltx.SetTextColor(kBlue);
237  ltx.SetTextSize(0.055);
238  ltx.SetTextAlign(11);
239  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
240  1 - gPad->GetTopMargin() + 0.01,
241  unpacked.first == 0
242  ? ("IOV:" + std::to_string(unpacked.second)).c_str()
243  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second)).c_str());
244  }
245 
246  std::string fileName(m_imageFileName);
247  canvas.SaveAs(fileName.c_str());
248 #ifdef MMDEBUG
249  canvas.SaveAs("outBPix.root");
250 #endif
251 
252  return true;
253  }
254 
255  private:
256  TrackerTopology m_trackerTopo;
257  };
258 
259  /************************************************
260  occupancy style map FPix
261  *************************************************/
262 
263  class SiPixelFPixQualityMap
264  : public cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::SINGLE_IOV> {
265  public:
266  SiPixelFPixQualityMap()
267  : cond::payloadInspector::PlotImage<SiPixelQuality, cond::payloadInspector::SINGLE_IOV>(
268  "SiPixelQuality Forward Pixel Map"),
270  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
271 
272  bool fill() override {
273  auto tag = PlotBase::getTag<0>();
274  auto iov = tag.iovs.front();
275  std::shared_ptr<SiPixelQuality> payload = fetchPayload(std::get<1>(iov));
276 
277  static const int n_rings = 2;
278  std::array<TH2D*, n_rings> h_fpix_occ;
279  int divide_roc = 1;
280 
281  // --------------------- BOOK HISTOGRAMS
282  for (unsigned int ring = 1; ring <= n_rings; ring++) {
283  int n = ring == 1 ? 92 : 140;
284  float y = ring == 1 ? 11.5 : 17.5;
285  std::string name = "occ_ring_" + std::to_string(ring);
286  std::string title = "; Disk # ; Blade/Panel #";
287 
288  h_fpix_occ[ring - 1] = new TH2D(name.c_str(), title.c_str(), 56 * divide_roc, -3.5, 3.5, n * divide_roc, -y, y);
289  }
290 
291  auto theDisabledModules = payload->getBadComponentList();
292  for (const auto& mod : theDisabledModules) {
293  int coded_badRocs = mod.BadRocs;
294  int subid = DetId(mod.DetID).subdetId();
295  std::bitset<16> bad_rocs(coded_badRocs);
296  if (subid == PixelSubdetector::PixelEndcap) {
297  auto ring = SiPixelPI::ring(DetId(mod.DetID), m_trackerTopo, true);
298  auto s_blade = SiPixelPI::signed_blade(DetId(mod.DetID), m_trackerTopo, true);
299  auto s_disk = SiPixelPI::signed_disk(DetId(mod.DetID), m_trackerTopo, true);
300  auto s_blade_panel = SiPixelPI::signed_blade_panel(DetId(mod.DetID), m_trackerTopo, true);
301  auto panel = m_trackerTopo.pxfPanel(mod.DetID);
302 
303  //bool isFlipped = (s_disk > 0) ? (std::abs(s_blade)%2==0) : (std::abs(s_blade)%2==1);
304  bool isFlipped = (s_disk > 0) ? (panel == 1) : (panel == 2);
305 
306  COUT << "ring:" << ring << " blade: " << s_blade << " panel: " << panel
307  << " signed blade/panel: " << s_blade_panel << " disk: " << s_disk << std::endl;
308 
309  if (payload->IsModuleBad(mod.DetID)) {
310  auto rocsToMask = SiPixelPI::maskedForwardRocsToBins(ring, s_blade, panel, s_disk);
311  for (const auto& bin : rocsToMask) {
312  h_fpix_occ[ring - 1]->SetBinContent(bin.first, bin.second, 1);
313  }
314  } else {
315  auto rocsToMask = SiPixelPI::maskedForwardRocsToBins(ring, s_blade, panel, s_disk, bad_rocs, isFlipped);
316  for (const auto& bin : rocsToMask) {
317  h_fpix_occ[ring - 1]->SetBinContent(std::get<0>(bin), std::get<1>(bin), 1);
318  }
319  }
320  } // if it's endcap
321  } // loop on disable moduels
322 
323  gStyle->SetOptStat(0);
324  //=========================
325  TCanvas canvas("Summary", "Summary", 1200, 600);
326  canvas.Divide(2, 1);
327  canvas.SetBottomMargin(0.11);
328  canvas.SetLeftMargin(0.13);
329  canvas.SetRightMargin(0.05);
330  canvas.Modified();
331 
332  for (unsigned int ring = 1; ring <= n_rings; ring++) {
333  SiPixelPI::dress_occup_plot(canvas, h_fpix_occ[ring - 1], 0, ring, 1);
334  }
335 
336  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
337 
338  for (unsigned int ring = 1; ring <= n_rings; ring++) {
339  canvas.cd(ring);
340  auto ltx = TLatex();
341  ltx.SetTextFont(62);
342  ltx.SetTextColor(kBlue);
343  ltx.SetTextSize(0.050);
344  ltx.SetTextAlign(11);
345  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
346  1 - gPad->GetTopMargin() + 0.01,
347  unpacked.first == 0
348  ? ("IOV:" + std::to_string(unpacked.second)).c_str()
349  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second)).c_str());
350  }
351 
352  std::string fileName(m_imageFileName);
353  canvas.SaveAs(fileName.c_str());
354 #ifdef MMDEBUG
355  canvas.SaveAs("outFPix.root");
356 #endif
357  return true;
358  }
359 
360  private:
361  TrackerTopology m_trackerTopo;
362  };
363 
364 } // namespace
365 
366 // Register the classes as boost python plugin
368  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityTest);
369  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityBadRocsSummary);
370  PAYLOAD_INSPECTOR_CLASS(SiPixelQualityBadRocsTimeHistory);
371  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixQualityMap);
372  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixQualityMap);
373 }
SiPixelPI::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: SiPixelPayloadInspectorHelper.h:44
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
DDAxes::y
PixelSubdetector.h
SiPixelPI::signed_disk
int signed_disk(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:128
MessageLogger.h
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
cond::payloadInspector::Histogram1D::fillWithValue
void fillWithValue(float value, float weight=1)
Definition: PayloadInspector.h:708
SiPixelPI::ring
int ring(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:93
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
TrackerTopology
Definition: TrackerTopology.h:16
PayloadInspector.h
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
cond::payloadInspector::Histogram1D
Definition: PayloadInspector.h:682
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
PayloadInspectorModule.h
FileInPath.h
cond::payloadInspector::TimeHistoryPlot::getFromPayload
virtual Y getFromPayload(PayloadType &payload)=0
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
SiPixelPI::isBPixOuterLadder
bool isBPixOuterLadder(const DetId &detid, const TrackerTopology &tTopo, bool isPhase0)
Definition: SiPixelPayloadInspectorHelper.h:559
SiPixelPI::signed_blade
int signed_blade(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:108
StandaloneTrackerTopology.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
jets_cff.payload
payload
Definition: jets_cff.py:34
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
cond::payloadInspector::Plot2D< PayloadType, float, float, IOV_M, 1 >::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:460
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
Time.h
SiPixelQuality
Definition: SiPixelQuality.h:27
SiPixelPI::maskedBarrelRocsToBins
std::vector< std::pair< int, int > > maskedBarrelRocsToBins(int layer, int ladder, int module)
Definition: SiPixelPayloadInspectorHelper.h:697
cond::payloadInspector::Histogram1D::fill
bool fill() override
Definition: PayloadInspector.h:724
cond::payloadInspector::PlotImage::fetchPayload
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
Definition: PayloadInspector.h:840
cond::payloadInspector::MULTI_IOV
Definition: PayloadInspector.h:265
cond::payloadInspector::TimeHistoryPlot
Definition: PayloadInspector.h:598
SiPixelPI::signed_blade_panel
int signed_blade_panel(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:118
module
Definition: vlib.h:198
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
SiPixelPI::signed_module
int signed_module(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:77
COUT
#define COUT
Definition: PVValidationHelpers.h:13
std
Definition: JetResolutionObject.h:76
DetId.h
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
PVValHelper::ladder
Definition: PVValidationHelpers.h:72
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
SiPixelQuality.h
SiPixelPI::dress_occup_plot
void dress_occup_plot(TCanvas &canv, TH2 *h, int lay, int ring=0, int phase=0, bool half_shift=true, bool mark_zero=true, bool standard_palette=true)
Definition: SiPixelPayloadInspectorHelper.h:148
SiPixelPayloadInspectorHelper.h
cond::payloadInspector::SINGLE_IOV
Definition: PayloadInspector.h:265
SiPixelPI::signed_ladder
int signed_ladder(const DetId &detid, const TrackerTopology &tTopo_, bool phase_)
Definition: SiPixelPayloadInspectorHelper.h:65
StandaloneTrackerTopology::fromTrackerParametersXMLFile
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Definition: StandaloneTrackerTopology.cc:168
SiPixelPI::maskedForwardRocsToBins
std::vector< std::pair< int, int > > maskedForwardRocsToBins(int ring, int blade, int panel, int disk)
Definition: SiPixelPayloadInspectorHelper.h:803