1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELTEMPLATEHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELTEMPLATEHELPER_H
15 #include <type_traits>
18 #include <fmt/printf.h>
19 #include <boost/range/adaptor/indexed.hpp>
30 #include "TPaveStats.h"
38 template <
class PayloadType,
class StoreType,
class TransientType>
44 "Table of SiPixelTemplate/GenError titles") {
45 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
47 label_ =
"SiPixelGenErrorDBObject_PayloadInspector";
50 label_ =
"SiPixelTemplateDBObject_PayloadInspector";
55 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
56 auto iov =
tag.iovs.front();
58 std::vector<StoreType> thePixelTemp_;
61 std::string IOVsince = std::to_string(std::get<0>(iov));
64 if (!TransientType::pushfile(*
payload, thePixelTemp_)) {
66 <<
" not filled correctly."
67 <<
" Check the conditions. Using "
68 << (
isTemplate_ ?
"SiPixelTemplateDBObject" :
"SiPixelGenErrorDBObject")
69 <<
" version " <<
payload->version() <<
"\n\n";
72 unsigned int mapsize = thePixelTemp_.size();
73 float pitch = 1. / (mapsize * 1.1);
76 std::vector<float> y_x1, y_x2, y_line;
77 std::vector<std::string> s_x1, s_x2, s_x3;
87 s_x1.push_back(Form(
"#scale[1.2]{%s}", (
isTemplate_ ?
"Template ID" :
"GenError ID")));
89 s_x2.push_back(Form(
"#scale[1.2]{#color[4]{%s} in IOV: #color[4]{%s}}",
tagname.c_str(), IOVsince.c_str()));
94 for (
const auto& element : thePixelTemp_) {
97 s_x1.push_back(std::to_string(element.head.ID));
100 s_x2.push_back(Form(
"#color[2]{%s}", element.head.title));
102 y_line.push_back(y - (pitch / 2.));
105 const auto& c_title = fmt::sprintf(
"%s titles", (
isTemplate_ ?
"Template" :
"GenError"));
106 TCanvas
canvas(c_title.c_str(), c_title.c_str(), 2000,
std::max(y_x1.size(), y_x2.size()) * 40);
111 float newpitch = 1 / (
std::max(y_x1.size(), y_x2.size()) * 1.1);
112 float factor = newpitch / pitch;
113 l.SetTextSize(newpitch - 0.002);
115 for (
unsigned int i = 0;
i < y_x1.size();
i++) {
116 l.DrawLatexNDC(
x1, 1 - (1 - y_x1[
i]) *
factor, s_x1[
i].c_str());
119 for (
unsigned int i = 0;
i < y_x2.size();
i++) {
120 l.DrawLatexNDC(
x2, 1 - (1 - y_x2[
i]) *
factor, s_x2[
i].c_str());
126 TLine
lines[y_line.size()];
128 for (
const auto&
line : y_line) {
130 lines[iL].SetLineWidth(1);
131 lines[iL].SetLineStyle(9);
132 lines[iL].SetLineColor(2);
133 lines[iL].Draw(
"same");
152 template <
class PayloadType,
class StoreType,
class TransientType>
157 "SiPixel CPE Conditions Header summary") {
158 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
160 label_ =
"SiPixelGenErrorDBObject_PayloadInspector";
163 label_ =
"SiPixelTemplateDBObject_PayloadInspector";
168 gStyle->SetHistMinimumZero();
169 gStyle->SetPalette(kMint);
171 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
172 auto iov =
tag.iovs.front();
174 std::vector<StoreType> thePixelTemp_;
178 if (!TransientType::pushfile(*
payload, thePixelTemp_)) {
180 <<
" not filled correctly."
181 <<
" Check the conditions. Using "
182 << (
isTemplate_ ?
"SiPixelTemplateDBObject" :
"SiPixelGenErrorDBObject")
183 <<
payload->version() <<
"\n\n";
187 TransientType templ(thePixelTemp_);
188 TCanvas
canvas(
"Header Summary",
"Header summary", 1400, 1000);
191 unsigned int tempSize = thePixelTemp_.size();
193 canvas.SetTopMargin(0.07);
194 canvas.SetBottomMargin(0.06);
195 canvas.SetLeftMargin(0.17);
196 canvas.SetRightMargin(0.03);
200 auto h2_Header = std::make_unique<TH2F>(
"Header",
";;", tempSize, 0, tempSize, 12, 0., 12.);
201 auto h2_ghost = std::make_unique<TH2F>(
"ghost",
";;", tempSize, 0, tempSize, 12, 0., 12.);
202 h2_Header->SetStats(
false);
203 h2_ghost->SetStats(
false);
205 int tempVersion = -999;
207 for (
const auto& theTemp : thePixelTemp_ | boost::adaptors::indexed(1)) {
208 auto tempValue = theTemp.value();
209 auto idx = theTemp.index();
211 if (tempValue.head.Bfield != 0.) {
212 uH =
roundoff(tempValue.head.lorxwidth / tempValue.head.zsize / tempValue.head.Bfield, 4);
216 h2_Header->SetBinContent(
idx, 12, tempValue.head.ID);
217 h2_Header->SetBinContent(
idx, 11, tempValue.head.Bfield);
218 h2_Header->SetBinContent(
idx, 10, uH);
219 h2_Header->SetBinContent(
idx, 9, tempValue.head.xsize);
220 h2_Header->SetBinContent(
idx, 8, tempValue.head.ysize);
221 h2_Header->SetBinContent(
idx, 7, tempValue.head.zsize);
222 h2_Header->SetBinContent(
idx, 6, tempValue.head.NTy);
223 h2_Header->SetBinContent(
idx, 5, tempValue.head.NTyx);
224 h2_Header->SetBinContent(
idx, 4, tempValue.head.NTxx);
225 h2_Header->SetBinContent(
idx, 3, tempValue.head.Dtype);
226 h2_Header->SetBinContent(
idx, 2, tempValue.head.qscale);
227 h2_Header->SetBinContent(
idx, 1, tempValue.head.Vbias);
230 h2_Header->GetYaxis()->SetBinLabel(12, (
isTemplate_ ?
"TemplateID" :
"GenErrorID"));
231 h2_Header->GetYaxis()->SetBinLabel(11,
"B-field [T]");
232 h2_Header->GetYaxis()->SetBinLabel(10,
"#mu_{H} [1/T]");
233 h2_Header->GetYaxis()->SetBinLabel(9,
"x-size [#mum]");
234 h2_Header->GetYaxis()->SetBinLabel(8,
"y-size [#mum]");
235 h2_Header->GetYaxis()->SetBinLabel(7,
"z-size [#mum]");
236 h2_Header->GetYaxis()->SetBinLabel(6,
"NTy");
237 h2_Header->GetYaxis()->SetBinLabel(5,
"NTyx");
238 h2_Header->GetYaxis()->SetBinLabel(4,
"NTxx");
239 h2_Header->GetYaxis()->SetBinLabel(3,
"DetectorType");
240 h2_Header->GetYaxis()->SetBinLabel(2,
"qScale");
241 h2_Header->GetYaxis()->SetBinLabel(1,
"VBias [V]");
242 h2_Header->GetXaxis()->SetBinLabel(
idx,
"");
244 for (
unsigned int iy = 1; iy <= 12; iy++) {
245 if (tempValue.head.Dtype != 0 || uH < 0) {
246 h2_ghost->SetBinContent(
idx, iy, 1);
248 h2_ghost->SetBinContent(
idx, iy, -1);
250 h2_ghost->GetYaxis()->SetBinLabel(iy, h2_Header->GetYaxis()->GetBinLabel(iy));
251 h2_ghost->GetXaxis()->SetBinLabel(
idx,
"");
254 if (tempValue.head.templ_version != tempVersion) {
255 tempVersion = tempValue.head.templ_version;
259 h2_Header->GetXaxis()->LabelsOption(
"h");
260 h2_Header->GetXaxis()->SetNdivisions(500 + tempSize,
false);
261 h2_Header->GetYaxis()->SetLabelSize(0.05);
262 h2_Header->SetMarkerSize(1.5);
264 h2_ghost->GetXaxis()->LabelsOption(
"h");
265 h2_ghost->GetXaxis()->SetNdivisions(500 + tempSize,
false);
266 h2_ghost->GetYaxis()->SetLabelSize(0.05);
269 h2_ghost->Draw(
"col");
270 h2_Header->Draw(
"TEXTsame");
272 TPaveText ksPt(0, 0, 0.88, 0.04,
"NDC");
273 ksPt.SetBorderSize(0);
274 ksPt.SetFillColor(0);
275 const char* textToAdd = Form(
"%s Version: #color[2]{%i}. Payload hash: #color[2]{%s}",
278 (std::get<1>(iov)).c_str());
279 ksPt.AddText(textToAdd);
284 ltx.SetTextSize(0.040);
285 ltx.SetTextAlign(11);
287 gPad->GetLeftMargin(),
288 1 - gPad->GetTopMargin() + 0.01,
289 (
"#color[4]{" +
tagname +
"}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) +
"}").c_str());
298 float pow_10 =
pow(10.0
f, (
float)prec);
299 return round(
value * pow_10) / pow_10;
310 template <
class PayloadType, SiPixelPI::DetType myType>
315 "SiPixelMap of Template / GenError ID Values") {
316 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
318 label_ =
"SiPixelGenErrorDBObject_PayloadInspector";
321 label_ =
"SiPixelTemplateDBObject_PayloadInspector";
325 bool fill()
override {
326 gStyle->SetPalette(kRainBow);
328 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
329 auto iov =
tag.iovs.front();
347 std::map<unsigned int, short> templMap;
348 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
349 templMap =
payload->getGenErrorIDs();
351 templMap =
payload->getTemplateIDs();
356 <<
"There are " << templMap.size()
357 <<
" DetIds in this payload. SiPixelIDs maps are not supported for non-Phase1 Pixel geometries !";
358 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
366 <<
" DetIds in this payload !"
367 <<
"\n **************************** \n";
379 for (
auto const&
entry : templMap) {
380 COUT <<
"DetID: " <<
entry.first << fmt::sprintf(
"%s ID ", (
isTemplate_ ?
"Template" :
"GenError"))
381 <<
entry.second << std::endl;
415 template <
class PayloadType,
class StoreType,
class TransientType>
421 "SiPixel CPE conditions Map of IDs") {
422 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
424 label_ =
"SiPixelGenErrorDBObject_PayloadInspector";
427 label_ =
"SiPixelTemplateDBObject_PayloadInspector";
431 bool fill()
override {
432 gStyle->SetPalette(1);
433 auto tag = cond::payloadInspector::PlotBase::getTag<0>();
434 auto iov =
tag.iovs.front();
435 std::vector<StoreType> thePixelTemp_;
441 if (!TransientType::pushfile(*
payload, thePixelTemp_)) {
443 <<
" not filled correctly. Check the conditions. Using "
444 << (
isTemplate_ ?
"SiPixelTemplateDBObject" :
"SiPixelGenErrorDBObject")
445 <<
payload->version() <<
"\n\n";
448 Phase1PixelSummaryMap fullMap(
"", fmt::sprintf(
"%s IDs", payloadString), fmt::sprintf(
"%s ID", payloadString));
451 std::map<unsigned int, short> templMap;
452 if constexpr (std::is_same_v<PayloadType, SiPixelGenErrorDBObject>) {
453 templMap =
payload->getGenErrorIDs();
455 templMap =
payload->getTemplateIDs();
458 for (
const auto&
entry : templMap) {
464 <<
"There are " << templMap.size()
465 <<
" DetIds in this payload. SiPixelIDs maps are not supported for non-Phase1 Pixel geometries !";
466 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
474 <<
" DetIds in this payload !"
475 <<
"\n **************************** \n";
479 TCanvas
canvas(
"Canv",
"Canv", 3000, 2000);
486 ltx.SetTextSize(0.025);
487 ltx.SetTextAlign(11);
489 gPad->GetLeftMargin() + 0.01,
490 gPad->GetBottomMargin() + 0.01,
491 (
"#color[4]{" +
tag.name +
"}, IOV: #color[4]{" + std::to_string(std::get<0>(iov)) +
"}").c_str());