CMS 3D CMS Logo

SiPixelTemplateDBObject_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
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 
32 // include ROOT
33 #include "TH2.h"
34 #include "TProfile2D.h"
35 #include "TH2Poly.h"
36 #include "TGraph.h"
37 #include "TH2F.h"
38 #include "TLegend.h"
39 #include "TCanvas.h"
40 #include "TLine.h"
41 #include "TGraph.h"
42 #include "TStyle.h"
43 #include "TLatex.h"
44 #include "TPave.h"
45 #include "TPaveStats.h"
46 #include "TGaxis.h"
47 
48 namespace {
49 
50  using namespace cond::payloadInspector;
51 
52  /************************************************
53  test class
54  *************************************************/
55  class SiPixelTemplateDBObjectTest : public Histogram1D<SiPixelTemplateDBObject, SINGLE_IOV> {
56  public:
57  SiPixelTemplateDBObjectTest()
59  "SiPixelTemplateDBObject test", "SiPixelTemplateDBObject test", 10, 0.0, 100.) {}
60 
61  bool fill() override {
62  auto tag = PlotBase::getTag<0>();
63  for (auto const& iov : tag.iovs) {
64  std::vector<SiPixelTemplateStore> thePixelTemp_;
65  std::shared_ptr<SiPixelTemplateDBObject> payload = Base::fetchPayload(std::get<1>(iov));
66  if (payload.get()) {
67  if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
68  throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
69  << "\nERROR: Templates not filled correctly. Check the conditions. Using "
70  "SiPixelTemplateDBObject version "
71  << payload->version() << "\n\n";
72  }
73 
74  SiPixelTemplate templ(thePixelTemp_);
75 
76  for (const auto& theTemp : thePixelTemp_) {
77  std::cout << "\n\n"
78  << "Template ID = " << theTemp.head.ID << ", Template Version " << theTemp.head.templ_version
79  << ", Bfield = " << theTemp.head.Bfield << ", NTy = " << theTemp.head.NTy
80  << ", NTyx = " << theTemp.head.NTyx << ", NTxx = " << theTemp.head.NTxx
81  << ", Dtype = " << theTemp.head.Dtype << ", Bias voltage " << theTemp.head.Vbias
82  << ", temperature " << theTemp.head.temperature << ", fluence " << theTemp.head.fluence
83  << ", Q-scaling factor " << theTemp.head.qscale << ", 1/2 multi dcol threshold "
84  << theTemp.head.s50 << ", 1/2 single dcol threshold " << theTemp.head.ss50 << ", y Lorentz Width "
85  << theTemp.head.lorywidth << ", y Lorentz Bias " << theTemp.head.lorybias << ", x Lorentz width "
86  << theTemp.head.lorxwidth << ", x Lorentz Bias " << theTemp.head.lorxbias
87  << ", Q/Q_avg fractions for Qbin defs " << theTemp.head.fbin[0] << ", " << theTemp.head.fbin[1]
88  << ", " << theTemp.head.fbin[2] << ", pixel x-size " << theTemp.head.xsize << ", y-size "
89  << theTemp.head.ysize << ", zsize " << theTemp.head.zsize << "\n"
90  << std::endl;
91  }
92 
93  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
94  for (auto const& entry : templMap) {
95  std::cout << "DetID: " << entry.first << " template ID: " << entry.second << std::endl;
96  templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
97 
98  std::cout << "\t lorywidth " << templ.lorywidth() << " lorxwidth: " << templ.lorxwidth() << " lorybias "
99  << templ.lorybias() << " lorxbias: " << templ.lorxbias() << "\n"
100  << std::endl;
101  }
102 
103  fillWithValue(1.);
104 
105  } // payload
106  } // iovs
107  return true;
108  } // fill
109  };
110 
111  /************************************************
112  // testing TH2Poly classes for plotting
113  *************************************************/
114  template <SiPixelPI::DetType myType>
115  class SiPixelTemplateLA : public PlotImage<SiPixelTemplateDBObject, SINGLE_IOV> {
116  struct header_info {
117  int ID;
118  float lorywidth;
119  float lorxwidth;
120  float lorybias;
121  float lorxbias;
122  float Vbias;
123  float temperature;
124  int templ_version;
125  float Bfield;
126  float xsize;
127  float ysize;
128  float zsize;
129  };
130 
131  public:
132  SiPixelTemplateLA() : PlotImage<SiPixelTemplateDBObject, SINGLE_IOV>("SiPixelTemplate assumed value of uH") {}
133 
134  bool fill() override {
135  gStyle->SetPalette(kRainBow);
136  TGaxis::SetMaxDigits(2);
137 
138  auto tag = PlotBase::getTag<0>();
139  auto iov = tag.iovs.front();
140  const auto& tagname = tag.name;
141  std::vector<SiPixelTemplateStore> thePixelTemp_;
142  std::shared_ptr<SiPixelTemplateDBObject> payload = fetchPayload(std::get<1>(iov));
143 
144  if (payload.get()) {
145  if (!SiPixelTemplate::pushfile(*payload, thePixelTemp_)) {
146  throw cms::Exception("SiPixelTemplateDBObject_PayloadInspector")
147  << "\nERROR: Templates not filled correctly. Check the conditions. Using "
148  "SiPixelTemplateDBObject version "
149  << payload->version() << "\n\n";
150  }
151 
152  // store the map of ID / interesting quantities
153  SiPixelTemplate templ(thePixelTemp_);
154  std::map<int, header_info> theInfos;
155  for (const auto& theTemp : thePixelTemp_) {
156  header_info info;
157  info.ID = theTemp.head.ID;
158  info.lorywidth = theTemp.head.lorywidth;
159  info.lorxwidth = theTemp.head.lorxwidth;
160  info.lorybias = theTemp.head.lorybias;
161  info.lorxbias = theTemp.head.lorxbias;
162  info.Vbias = theTemp.head.Vbias;
163  info.temperature = theTemp.head.temperature;
164  info.templ_version = theTemp.head.templ_version;
165  info.Bfield = theTemp.head.Bfield;
166  info.xsize = theTemp.head.xsize;
167  info.ysize = theTemp.head.ysize;
168  info.zsize = theTemp.head.zsize;
169 
170  theInfos[theTemp.head.ID] = info;
171  }
172 
173  // Book the TH2Poly
174  Phase1PixelMaps theMaps("");
175  if (myType == SiPixelPI::t_all) {
176  theMaps.resetOption("COLZA L");
177  } else {
178  theMaps.resetOption("COLZL");
179  }
180 
181  if (myType == SiPixelPI::t_barrel) {
182  theMaps.bookBarrelHistograms("templateLABarrel", "#muH", "#mu_{H} [1/T]");
183  } else if (myType == SiPixelPI::t_forward) {
184  theMaps.bookForwardHistograms("templateLAForward", "#muH", "#mu_{H} [1/T]");
185  } else if (myType == SiPixelPI::t_all) {
186  theMaps.bookBarrelHistograms("templateLA", "#muH", "#mu_{H} [1/T]");
187  theMaps.bookForwardHistograms("templateLA", "#muH", "#mu_{H} [1/T]");
188  } else {
189  edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
190  << " un-recognized detector type " << myType << std::endl;
191  return false;
192  }
193 
194  std::map<unsigned int, short> templMap = payload->getTemplateIDs();
195  if (templMap.size() == SiPixelPI::phase0size || templMap.size() > SiPixelPI::phase1size) {
196  edm::LogError("SiPixelTemplateDBObject_PayloadInspector")
197  << "There are " << templMap.size()
198  << " DetIds in this payload. SiPixelTempate Lorentz Angle maps are not supported for non-Phase1 Pixel "
199  "geometries !";
200  TCanvas canvas("Canv", "Canv", 1200, 1000);
201  SiPixelPI::displayNotSupported(canvas, templMap.size());
202  std::string fileName(m_imageFileName);
203  canvas.SaveAs(fileName.c_str());
204  return false;
205  } else {
206  if (templMap.size() < SiPixelPI::phase1size) {
207  edm::LogWarning("SiPixelTemplateDBObject_PayloadInspector")
208  << "\n ********* WARNING! ********* \n There are " << templMap.size() << " DetIds in this payload !"
209  << "\n **************************** \n";
210  }
211  }
212 
213  for (auto const& entry : templMap) {
214  templ.interpolate(entry.second, 0.f, 0.f, 1.f, 1.f);
215 
216  //mu_H = lorentz width / sensor thickness / B field
217  float uH = templ.lorxwidth() / theInfos[entry.second].zsize / theInfos[entry.second].Bfield;
218  COUT << "uH: " << uH << " lor x width:" << templ.lorxwidth() << " z size: " << theInfos[entry.second].zsize
219  << " B-field: " << theInfos[entry.second].Bfield << std::endl;
220 
221  auto detid = DetId(entry.first);
222  if (myType == SiPixelPI::t_all) {
223  if ((detid.subdetId() == PixelSubdetector::PixelBarrel)) {
224  theMaps.fillBarrelBin("templateLA", entry.first, uH);
225  }
226  if ((detid.subdetId() == PixelSubdetector::PixelEndcap)) {
227  theMaps.fillForwardBin("templateLA", entry.first, uH);
228  }
229  } else if ((detid.subdetId() == PixelSubdetector::PixelBarrel) && (myType == SiPixelPI::t_barrel)) {
230  theMaps.fillBarrelBin("templateLABarrel", entry.first, uH);
231  } else if ((detid.subdetId() == PixelSubdetector::PixelEndcap) && (myType == SiPixelPI::t_forward)) {
232  theMaps.fillForwardBin("templateLAForward", entry.first, uH);
233  }
234  }
235 
236  theMaps.beautifyAllHistograms();
237 
238  TCanvas canvas("Canv", "Canv", (myType == SiPixelPI::t_barrel) ? 1200 : 1600, 1000);
239  if (myType == SiPixelPI::t_barrel) {
240  theMaps.drawBarrelMaps("templateLABarrel", canvas);
241  } else if (myType == SiPixelPI::t_forward) {
242  theMaps.drawForwardMaps("templateLAForward", canvas);
243  } else if (myType == SiPixelPI::t_all) {
244  theMaps.drawSummaryMaps("templateLA", canvas);
245  }
246 
247  canvas.cd();
248  TPaveText ksPt(0, 0, 0.88, 0.04, "NDC");
249  ksPt.SetBorderSize(0);
250  ksPt.SetFillColor(0);
251  const char* textToAdd = Form("Template Tag: #color[2]{%s}, IOV: #color[2]{%s}. Payload hash: #color[2]{%s}",
252  tagname.c_str(),
253  std::to_string(std::get<0>(iov)).c_str(),
254  (std::get<1>(iov)).c_str());
255  ksPt.AddText(textToAdd);
256  ksPt.Draw();
257 
258  canvas.cd();
259  std::string fileName(m_imageFileName);
260  canvas.SaveAs(fileName.c_str());
261  }
262  return true;
263  } // fill
264  };
265 
266  using SiPixelTemplateLABPixMap = SiPixelTemplateLA<SiPixelPI::t_barrel>;
267  using SiPixelTemplateLAFPixMap = SiPixelTemplateLA<SiPixelPI::t_forward>;
268  using SiPixelTemplateLAMap = SiPixelTemplateLA<SiPixelPI::t_all>;
269 
270  using namespace templateHelper;
271 
272  //************************************************
273  // Full Pixel Tracker Map of Template IDs
274  // ***********************************************/
275  using SiPixelTemplateIDsFullPixelMap =
277 
278  //************************************************
279  // Display of Template Titles
280  // **********************************************/
281  using SiPixelTemplateTitles_Display =
283 
284  //***********************************************
285  // Display of Template Header
286  // **********************************************/
288 
289  //***********************************************
290  // TH2Poly Map of IDs
291  //***********************************************/
292  using SiPixelTemplateIDsBPixMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_barrel>;
293  using SiPixelTemplateIDsFPixMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_forward>;
294  using SiPixelTemplateIDsMap = SiPixelIDs<SiPixelTemplateDBObject, SiPixelPI::t_all>;
295 
296  //************************************************
297  // TH2Poly Map of qScale
298  //***********************************************/
299  using SiPixelTemplateQScaleBPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
304  using SiPixelTemplateQScaleFPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
309  using SiPixelTemplateQScaleMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
314 
315  //************************************************
316  // TH2Poly Map of Vbias
317  //***********************************************/
318  using SiPixelTemplateVbiasBPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
323  using SiPixelTemplateVbiasFPixMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
328  using SiPixelTemplateVbiasMap = SiPixelTemplateHeaderInfo<SiPixelTemplateDBObject,
333 } // namespace
334 
335 // Register the classes as boost python plugin
337  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateDBObjectTest);
338  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsFullPixelMap);
339  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateTitles_Display);
340  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateHeaderTable);
341  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsMap);
342  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsBPixMap);
343  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateIDsFPixMap);
344  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAMap);
345  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLABPixMap);
346  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateLAFPixMap);
347  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleBPixMap);
348  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleFPixMap);
349  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateQScaleMap);
350  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasBPixMap);
351  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasFPixMap);
352  PAYLOAD_INSPECTOR_CLASS(SiPixelTemplateVbiasMap);
353 }
static const TGPicture * info(bool iBackgroundIsBlack)
static const unsigned int phase0size
uint32_t ID
Definition: Definitions.h:24
const Int_t ysize
Log< level::Error, false > LogError
static std::string to_string(const XMLCh *ch)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
static const unsigned int phase1size
constexpr float Bfield
Definition: Config.h:55
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
#define COUT
Definition: DetId.h:17
void displayNotSupported(TCanvas &canv, const unsigned int size)
static bool pushfile(int filenum, std::vector< SiPixelTemplateStore > &pixelTemp, std::string dir="CalibTracker/SiPixelESProducers/data/")
def canvas(sub, attr)
Definition: svgfig.py:482
Log< level::Warning, false > LogWarning
const Int_t xsize