CMS 3D CMS Logo

SiPixelTemplateDBObject_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
16 
18 
19 // the data format of the condition to be inspected
25 
26 #include <memory>
27 #include <map>
28 #include <sstream>
29 #include <iostream>
30 #include <algorithm>
31 #include <boost/range/adaptor/indexed.hpp>
32 
33 // include ROOT
34 #include "TH2.h"
35 #include "TProfile2D.h"
36 #include "TH2Poly.h"
37 #include "TGraph.h"
38 #include "TH2F.h"
39 #include "TLegend.h"
40 #include "TCanvas.h"
41 #include "TLine.h"
42 #include "TGraph.h"
43 #include "TStyle.h"
44 #include "TLatex.h"
45 #include "TPave.h"
46 #include "TPaveStats.h"
47 #include "TGaxis.h"
48 
49 namespace {
50 
51  enum MapType { t_barrel = 0, t_forward = 1 };
52 
53  /************************************************
54  test class
55  *************************************************/
56  class SiPixelTemplateDBObjectTest
57  : public cond::payloadInspector::Histogram1D<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV> {
58  public:
59  SiPixelTemplateDBObjectTest()
60  : cond::payloadInspector::Histogram1D<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV>(
61  "SiPixelTemplateDBObject test", "SiPixelTemplateDBObject test", 10, 0.0, 100.) {}
62 
63  bool fill() override {
64  auto tag = PlotBase::getTag<0>();
65  for (auto const& iov : tag.iovs) {
66  std::vector<SiPixelTemplateStore> thePixelTemp_;
67  std::shared_ptr<SiPixelTemplateDBObject> payload = Base::fetchPayload(std::get<1>(iov));
68  if (payload.get()) {
69  if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
70  throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
71  << "\nERROR: Templates not filled correctly. Check the conditions. Using "
72  "SiPixelTemplateDBObject version "
73  << payload->version() << "\n\n";
74  }
75 
76  SiPixelTemplate templ(thePixelTemp_);
77 
78  for (const auto& theTemp : thePixelTemp_) {
79  std::cout << "\n\n"
80  << "Template ID = " << theTemp.head.ID << ", Template Version " << theTemp.head.templ_version
81  << ", Bfield = " << theTemp.head.Bfield << ", NTy = " << theTemp.head.NTy
82  << ", NTyx = " << theTemp.head.NTyx << ", NTxx = " << theTemp.head.NTxx
83  << ", Dtype = " << theTemp.head.Dtype << ", Bias voltage " << theTemp.head.Vbias
84  << ", temperature " << theTemp.head.temperature << ", fluence " << theTemp.head.fluence
85  << ", Q-scaling factor " << theTemp.head.qscale << ", 1/2 multi dcol threshold "
86  << theTemp.head.s50 << ", 1/2 single dcol threshold " << theTemp.head.ss50 << ", y Lorentz Width "
87  << theTemp.head.lorywidth << ", y Lorentz Bias " << theTemp.head.lorybias << ", x Lorentz width "
88  << theTemp.head.lorxwidth << ", x Lorentz Bias " << theTemp.head.lorxbias
89  << ", Q/Q_avg fractions for Qbin defs " << theTemp.head.fbin[0] << ", " << theTemp.head.fbin[1]
90  << ", " << theTemp.head.fbin[2] << ", pixel x-size " << theTemp.head.xsize << ", y-size "
91  << theTemp.head.ysize << ", zsize " << theTemp.head.zsize << "\n"
92  << std::endl;
93  }
94 
95  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
96  for (auto const& entry : templMap) {
97  std::cout << "DetID: " << entry.first << " template ID: " << entry.second << std::endl;
98  templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
99 
100  std::cout << "\t lorywidth " << templ.lorywidth() << " lorxwidth: " << templ.lorxwidth() << " lorybias "
101  << templ.lorybias() << " lorxbias: " << templ.lorxbias() << "\n"
102  << std::endl;
103  }
104 
105  fillWithValue(1.);
106 
107  } // payload
108  } // iovs
109  return true;
110  } // fill
111  };
112 
113  /************************************************
114  // header plotting
115  *************************************************/
116  class SiPixelTemplateHeaderTable
117  : public cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV> {
118  public:
119  SiPixelTemplateHeaderTable()
120  : cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV>(
121  "SiPixelTemplateDBObject Header summary") {}
122 
123  bool fill() override {
124  auto tag = PlotBase::getTag<0>();
125  auto iov = tag.iovs.front();
126  auto tagname = tag.name;
127  std::vector<SiPixelTemplateStore> thePixelTemp_;
128  std::shared_ptr<SiPixelTemplateDBObject> payload = fetchPayload(std::get<1>(iov));
129 
130  if (payload.get()) {
131  if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
132  throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
133  << "\nERROR: Templates not filled correctly. Check the conditions. Using "
134  "SiPixelTemplateDBObject version "
135  << payload->version() << "\n\n";
136  }
137 
138  // store the map of ID / interesting quantities
139  SiPixelTemplate templ(thePixelTemp_);
140  TCanvas canvas("Template Header Summary", "Template Header summary", 1400, 1000);
141  canvas.cd();
142 
143  unsigned int tempSize = thePixelTemp_.size();
144 
145  canvas.SetTopMargin(0.07);
146  canvas.SetBottomMargin(0.06);
147  canvas.SetLeftMargin(0.17);
148  canvas.SetRightMargin(0.03);
149  canvas.Modified();
150  canvas.SetGrid();
151 
152  auto h2_TemplateHeaders = std::unique_ptr<TH2F>(new TH2F("Header", ";;", tempSize, 0, tempSize, 6, 0., 6.));
153  h2_TemplateHeaders->SetStats(false);
154 
155  for (const auto& theTemp : thePixelTemp_ | boost::adaptors::indexed(1)) {
156  auto tempValue = theTemp.value();
157  auto tempIndex = theTemp.index();
158  float uH = roundoff(tempValue.head.lorxwidth / tempValue.head.zsize / tempValue.head.Bfield, 4);
159  h2_TemplateHeaders->SetBinContent(tempIndex, 6, tempValue.head.ID);
160  h2_TemplateHeaders->SetBinContent(tempIndex, 5, tempValue.head.Bfield);
161  h2_TemplateHeaders->SetBinContent(tempIndex, 4, uH);
162  h2_TemplateHeaders->SetBinContent(tempIndex, 3, tempValue.head.xsize);
163  h2_TemplateHeaders->SetBinContent(tempIndex, 2, tempValue.head.ysize);
164  h2_TemplateHeaders->SetBinContent(tempIndex, 1, tempValue.head.zsize);
165  h2_TemplateHeaders->GetYaxis()->SetBinLabel(6, "TemplateID");
166  h2_TemplateHeaders->GetYaxis()->SetBinLabel(5, "B-field [T]");
167  h2_TemplateHeaders->GetYaxis()->SetBinLabel(4, "#mu_{H} [1/T]");
168  h2_TemplateHeaders->GetYaxis()->SetBinLabel(3, "x-size [#mum]");
169  h2_TemplateHeaders->GetYaxis()->SetBinLabel(2, "y-size [#mum]");
170  h2_TemplateHeaders->GetYaxis()->SetBinLabel(1, "z-size [#mum]");
171  h2_TemplateHeaders->GetXaxis()->SetBinLabel(tempIndex, "");
172  }
173 
174  h2_TemplateHeaders->GetXaxis()->LabelsOption("h");
175  h2_TemplateHeaders->GetXaxis()->SetNdivisions(500 + tempSize, false);
176  h2_TemplateHeaders->GetYaxis()->SetLabelSize(0.05);
177  h2_TemplateHeaders->SetMarkerSize(1.5);
178 
179  canvas.cd();
180  h2_TemplateHeaders->Draw("TEXT");
181 
182  auto ltx = TLatex();
183  ltx.SetTextFont(62);
184  ltx.SetTextColor(kBlue);
185  ltx.SetTextSize(0.045);
186  ltx.SetTextAlign(11);
187  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
188  1 - gPad->GetTopMargin() + 0.01,
189  (tagname + ", IOV:" + std::to_string(std::get<0>(iov))).c_str());
190 
191  std::string fileName(m_imageFileName);
192  canvas.SaveAs(fileName.c_str());
193  }
194  return true;
195  }
196 
197  float roundoff(float value, unsigned char prec) {
198  float pow_10 = pow(10.0f, (float)prec);
199  return round(value * pow_10) / pow_10;
200  }
201  };
202 
203  /************************************************
204  // testing TH2Poly classes for plotting
205  *************************************************/
206  template <MapType myType>
207  class SiPixelTemplateLA
208  : public cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV> {
209  struct header_info {
210  int ID;
211  float lorywidth;
212  float lorxwidth;
213  float lorybias;
214  float lorxbias;
215  float Vbias;
216  float temperature;
217  int templ_version;
218  float Bfield;
219  float xsize;
220  float ysize;
221  float zsize;
222  };
223 
224  public:
225  SiPixelTemplateLA()
226  : cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV>(
227  "SiPixelTemplate assumed value of uH") {}
228 
229  bool fill() override {
230  gStyle->SetPalette(kRainBow);
231  TGaxis::SetMaxDigits(2);
232 
233  auto tag = PlotBase::getTag<0>();
234  auto iov = tag.iovs.front();
235  std::vector<SiPixelTemplateStore> thePixelTemp_;
236  std::shared_ptr<SiPixelTemplateDBObject> payload = fetchPayload(std::get<1>(iov));
237 
238  if (payload.get()) {
239  if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
240  throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
241  << "\nERROR: Templates not filled correctly. Check the conditions. Using "
242  "SiPixelTemplateDBObject version "
243  << payload->version() << "\n\n";
244  }
245 
246  // store the map of ID / interesting quantities
247  SiPixelTemplate templ(thePixelTemp_);
248  std::map<int, header_info> theInfos;
249  for (const auto& theTemp : thePixelTemp_) {
250  header_info info;
251  info.ID = theTemp.head.ID;
252  info.lorywidth = theTemp.head.lorywidth;
253  info.lorxwidth = theTemp.head.lorxwidth;
254  info.lorybias = theTemp.head.lorybias;
255  info.lorxbias = theTemp.head.lorxbias;
256  info.Vbias = theTemp.head.Vbias;
257  info.temperature = theTemp.head.temperature;
258  info.templ_version = theTemp.head.templ_version;
259  info.Bfield = theTemp.head.Bfield;
260  info.xsize = theTemp.head.xsize;
261  info.ysize = theTemp.head.ysize;
262  info.zsize = theTemp.head.zsize;
263 
264  theInfos[theTemp.head.ID] = info;
265  }
266 
267  // Book the TH2Poly
268  Phase1PixelMaps theMaps("COLZ L");
269 
270  if (myType == t_barrel) {
271  theMaps.bookBarrelHistograms("templateLABarrel", "#muH", "#mu_{H} [1/T]");
272  theMaps.bookBarrelBins("templateLABarrel");
273  } else if (myType == t_forward) {
274  theMaps.bookForwardHistograms("templateLAForward", "#muH", "#mu_{H} [1/T]");
275  theMaps.bookForwardBins("templateLAForward");
276  }
277 
278  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
279  if (templMap.size() != SiPixelPI::phase1size) {
280  edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
281  << "SiPixelTempateLA maps are not supported for non-Phase1 Pixel geometries !";
282  TCanvas canvas("Canv", "Canv", 1200, 1000);
283  SiPixelPI::displayNotSupported(canvas, templMap.size());
284  std::string fileName(m_imageFileName);
285  canvas.SaveAs(fileName.c_str());
286  return false;
287  }
288 
289  for (auto const& entry : templMap) {
290  templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
291 
292  //mu_H = lorentz width / sensor thickness / B field
293  float uH = templ.lorxwidth() / theInfos[entry.second].zsize / theInfos[entry.second].Bfield;
294  COUT << "uH: " << uH << " lor x width:" << templ.lorxwidth() << " z size: " << theInfos[entry.second].zsize
295  << " B-field: " << theInfos[entry.second].Bfield << std::endl;
296 
297  auto detid = DetId(entry.first);
298  if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == t_barrel)) {
299  theMaps.fillBarrelBin("templateLABarrel", entry.first, uH);
300  } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == t_forward)) {
301  theMaps.fillForwardBin("templateLAForward", entry.first, uH);
302  }
303  }
304 
305  theMaps.beautifyAllHistograms();
306 
307  TCanvas canvas("Canv", "Canv", (myType == t_barrel) ? 1200 : 1600, 1000);
308  if (myType == t_barrel) {
309  theMaps.DrawBarrelMaps("templateLABarrel", canvas);
310  } else if (myType == t_forward) {
311  theMaps.DrawForwardMaps("templateLAForward", canvas);
312  }
313 
314  canvas.cd();
315  std::string fileName(m_imageFileName);
316  canvas.SaveAs(fileName.c_str());
317  }
318  return true;
319  } // fill
320  };
321 
322  using SiPixelTemplateLABPixMap = SiPixelTemplateLA<t_barrel>;
323  using SiPixelTemplateLAFPixMap = SiPixelTemplateLA<t_forward>;
324 
325  /************************************************
326  // testing TH2Poly classes for plotting
327  *************************************************/
328  template <MapType myType>
329  class SiPixelTemplateIDs
330  : public cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV> {
331  public:
332  SiPixelTemplateIDs()
333  : cond::payloadInspector::PlotImage<SiPixelTemplateDBObject, cond::payloadInspector::SINGLE_IOV>(
334  "SiPixelTemplate ID Values") {}
335 
336  bool fill() override {
337  gStyle->SetPalette(kRainBow);
338 
339  auto tag = PlotBase::getTag<0>();
340  auto iov = tag.iovs.front();
341  std::shared_ptr<SiPixelTemplateDBObject> payload = fetchPayload(std::get<1>(iov));
342 
343  if (payload.get()) {
344  // Book the TH2Poly
345  Phase1PixelMaps theMaps("text");
346  if (myType == t_barrel) {
347  theMaps.bookBarrelHistograms("templateIDsBarrel", "IDs", "template IDs");
348  // book the barrel bins of the TH2Poly
349  theMaps.bookBarrelBins("templateIDsBarrel");
350  } else if (myType == t_forward) {
351  theMaps.bookForwardHistograms("templateIDsForward", "IDs", "template IDs");
352  // book the forward bins of the TH2Poly
353  theMaps.bookForwardBins("templateIDsForward");
354  }
355 
356  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
357  if (templMap.size() != SiPixelPI::phase1size) {
358  edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
359  << "SiPixelTempateIDs maps are not supported for non-Phase1 Pixel geometries !";
360  TCanvas canvas("Canv", "Canv", 1200, 1000);
361  SiPixelPI::displayNotSupported(canvas, templMap.size());
362  std::string fileName(m_imageFileName);
363  canvas.SaveAs(fileName.c_str());
364  return false;
365  }
366 
367  /*
368  std::vector<unsigned int> detids;
369  std::transform(templMap.begin(),
370  templMap.end(),
371  std::back_inserter(detids),
372  [](const std::map<unsigned int, short>::value_type& pair) { return pair.first; });
373  */
374 
375  for (auto const& entry : templMap) {
376  COUT << "DetID: " << entry.first << " template ID: " << entry.second << std::endl;
377  auto detid = DetId(entry.first);
378  if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == t_barrel)) {
379  theMaps.fillBarrelBin("templateIDsBarrel", entry.first, entry.second);
380  } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == t_forward)) {
381  theMaps.fillForwardBin("templateIDsForward", entry.first, entry.second);
382  }
383  }
384 
385  theMaps.beautifyAllHistograms();
386 
387  TCanvas canvas("Canv", "Canv", (myType == t_barrel) ? 1200 : 1500, 1000);
388  if (myType == t_barrel) {
389  theMaps.DrawBarrelMaps("templateIDsBarrel", canvas);
390  } else if (myType == t_forward) {
391  theMaps.DrawForwardMaps("templateIDsForward", canvas);
392  }
393 
394  canvas.cd();
395 
396  std::string fileName(m_imageFileName);
397  canvas.SaveAs(fileName.c_str());
398  }
399  return true;
400  }
401  };
402 
403  using SiPixelTemplateIDsBPixMap = SiPixelTemplateIDs<t_barrel>;
404  using SiPixelTemplateIDsFPixMap = SiPixelTemplateIDs<t_forward>;
405 
406 } // namespace
407 
408 // Register the classes as boost python plugin
410  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateDBObjectTest);
411  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateHeaderTable);
412  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsBPixMap);
413  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsFPixMap);
414  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLABPixMap);
415  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAFPixMap);
416 }
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
PixelSubdetector.h
SiPixelTemplate::pushfile
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
Definition: SiPixelTemplate.cc:129
MessageLogger.h
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
cond::payloadInspector::Histogram1D::fillWithValue
void fillWithValue(float value, float weight=1)
Definition: PayloadInspector.h:708
SiPixelTemplate
Definition: SiPixelTemplate.h:255
mps_splice.entry
entry
Definition: mps_splice.py:68
PayloadInspector.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
cond::payloadInspector::Histogram1D
Definition: PayloadInspector.h:682
ysize
const Int_t ysize
Definition: trackSplitPlot.h:43
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
xsize
const Int_t xsize
Definition: trackSplitPlot.h:42
SiPixelPI::displayNotSupported
void displayNotSupported(TCanvas &canv, const unsigned int size)
Definition: SiPixelPayloadInspectorHelper.h:971
PayloadInspectorModule.h
DetId
Definition: DetId.h:17
SiPixelTemplate.h
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
Phase1PixelMaps
Definition: Phase1PixelMaps.h:11
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Phase1PixelMaps.h
cond
Definition: plugin.cc:23
Time.h
edm::LogError
Definition: MessageLogger.h:183
SiPixelTemplateDBObject.h
align::ID
uint32_t ID
Definition: Definitions.h:24
SiPixelPI::phase1size
static const unsigned int phase1size
Definition: SiPixelPayloadInspectorHelper.h:41
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
SiPixelTemplateDBObject
Definition: SiPixelTemplateDBObject.h:16
value
Definition: value.py:1
jvcParameters_cfi.temperature
temperature
Definition: jvcParameters_cfi.py:7
createPayload.tagname
tagname
Definition: createPayload.py:183
COUT
#define COUT
Definition: PVValidationHelpers.h:13
DetId.h
cond::payloadInspector::PlotImpl::fill
virtual bool fill()=0
Exception
Definition: hltDiff.cc:246
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:829
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
SiPixelPayloadInspectorHelper.h
cond::payloadInspector::SINGLE_IOV
Definition: PayloadInspector.h:265
MapType
MapType
Definition: SiPixelTemplateDBObject_PayloadInspector.cc:51