1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
16 #include "TPaveStats.h"
17 #include "TPaveText.h"
32 #define COUT std::cout << "MM "
34 #define COUT edm::LogVerbatim("")
65 edm::LogError(
"PhaseInfo") <<
"undefined phase: " << thePhase;
83 return "Geometry/TrackerCommonData/data/trackerParameters.xml";
85 return "Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
87 return "Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
118 return std::make_pair(
run,
lumi);
139 if (
quadrant(detid, &tTopo_, phase_) % 2)
151 if (
quadrant(detid, &tTopo_, phase_) < 3)
169 }
else if (phase_ == 1) {
182 if (
quadrant(detid, &tTopo_, phase_) % 2)
202 if (
quadrant(detid, &tTopo_, phase_) < 3)
210 l->SetBit(kCanDelete);
213 l->SetLineColor(color);
223 bool half_shift =
true,
224 bool mark_zero =
true,
225 bool standard_palette =
true) {
230 s_title =
"Barrel Pixel Layer" + std::to_string(lay);
233 s_title =
"Forward Pixel Ring" + std::to_string(
ring);
236 gStyle->SetPadRightMargin(0.125);
238 if (standard_palette) {
239 gStyle->SetPalette(1);
242 const Int_t NRGBs = 5;
243 const Int_t NCont = 255;
245 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
246 Double_t
red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
247 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
248 Double_t
blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
249 TColor::CreateGradientColorTable(NRGBs, stops,
red, green,
blue, NCont);
250 gStyle->SetNumberContours(NCont);
253 h->SetMarkerSize(0.7);
259 ltx.SetTextSize(0.06);
260 ltx.SetTextAlign(31);
261 ltx.DrawLatexNDC(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, (s_title).c_str());
265 std::vector<std::vector<int>> nladder = {{10, 16, 22}, {6, 14, 22, 32}};
266 int nlad = nladder[
phase][lay - 1];
267 for (
int xsign = -1; xsign <= 1; xsign += 2)
268 for (
int ysign = -1; ysign <= 1; ysign += 2) {
269 float xlow = xsign * (half_shift * 0.5);
270 float xhigh = xsign * (half_shift * 0.5 + 4);
271 float ylow = ysign * (half_shift * 0.5 + (
phase == 0) * 0.5);
272 float yhigh = ysign * (half_shift * 0.5 - (
phase == 0) * 0.5 + nlad);
279 for (
int lad = 1; lad < nlad; ++lad) {
280 float y = ysign * (lad + half_shift * 0.5);
283 for (
int lad = 1; lad <= nlad; ++lad)
284 if (!(
phase == 0 && (lad == 1 || lad == nlad))) {
285 float y = ysign * (lad + half_shift * 0.5 - 0.5);
290 float x = xsign * (
mod + half_shift * 0.5);
298 for (
int lad = 1; lad <= nlad; ++lad) {
299 bool flipped = ysign == 1 ? lad % 2 == 0 : lad % 2 == 1;
302 int roc0_orientation = flipped ? -1 : 1;
304 roc0_orientation *= -1;
306 roc0_orientation *= -1;
307 float x1 = xsign * (
mod + half_shift * 0.5);
308 float x2 = xsign * (
mod + half_shift * 0.5 - 1. / 8);
309 float y1 = ysign * (lad + half_shift * 0.5 - 0.5);
310 float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 1. / 2);
311 if (!(
phase == 0 && (lad == 1 || lad == nlad) && xsign == -1)) {
312 if (lay == 1 && xsign <= -1) {
313 float x1 = xsign * ((
mod - 1) + half_shift * 0.5);
314 float x2 = xsign * ((
mod - 1) + half_shift * 0.5 + 1. / 8);
315 float y1 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation);
316 float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 3. / 2);
331 for (
int dsk = 1, ndsk = 2 + (
phase == 1); dsk <= ndsk; ++dsk) {
332 for (
int xsign = -1; xsign <= 1; xsign += 2)
333 for (
int ysign = -1; ysign <= 1; ysign += 2) {
335 int first_roc = 3,
nbin = 16;
336 for (
int bld = 1, nbld = 12; bld <= nbld; ++bld) {
338 for (
int plq = 1, nplq = 7; plq <= nplq; ++plq) {
340 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (
float)
nbin);
342 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * (plq + 1) - (plq == 7)) / (
float)
nbin);
343 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + plq / 2) * 0.1);
344 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + plq / 2) * 0.1);
349 for (
int plq = 1, nplq = 7 + 1; plq <= nplq; ++plq) {
350 float x = xsign * (half_shift * 0.5 + dsk - 1 +
351 (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8)) / (
float)
nbin);
352 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
353 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
357 for (
int plq = 2, nplq = 6; plq <= nplq; ++plq)
359 float x = xsign * (half_shift * 0.5 + dsk - 1 +
360 (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8) + 1) / (
float)
nbin);
361 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
362 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
366 for (
int plq = 1, nplq = 7; plq <= nplq; ++plq) {
368 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (
float)
nbin);
370 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1) + 1) / (
float)
nbin);
371 int sign = xsign * ysign * ((plq % 2) ? 1 : -1);
372 float y1 = ysign * (half_shift * 0.5 + (bld - 0.5) +
sign * (2 + plq / 2) * 0.1);
373 float y2 = ysign * (half_shift * 0.5 + (bld - 0.5) +
sign * (plq / 2) * 0.1);
380 }
else if (
phase == 1) {
383 for (
int bld = 1, nbld = 5 +
ring * 6; bld <= nbld; ++bld) {
385 Color_t p1_color = 1, p2_color = 1;
388 float x1 = xsign * (half_shift * 0.5 + dsk - 1 + (
ring - 1) * 0.5);
389 float x2 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5);
391 float y1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.5);
393 float y2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld);
394 float yp2_mid = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25);
395 float y3 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.5);
402 float x = xsign * (half_shift * 0.5 + dsk - 1 + (
ring - 1) * 0.5);
407 x = xsign * (half_shift * 0.5 + dsk);
412 x1 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5 - 1 / 16.);
413 x2 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5);
414 float y1_p1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.25);
415 float y2_p1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.25 + xsign * ysign * 0.25);
420 float y1_p2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25);
421 float y2_p2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25 - xsign * ysign * 0.25);
428 for (
int bld = 1, nbld = 5 +
ring * 6; bld <= nbld; ++bld) {
429 Color_t p1_color = 1, p2_color = 1;
432 float x1 = xsign * (half_shift * 0.5 + dsk - 1);
433 float x2 = xsign * (half_shift * 0.5 + dsk);
435 float y1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.5);
437 float y2 = ysign * (half_shift * 0.5 - 0.5 + bld);
438 float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25);
439 float y3 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.5);
446 float x = xsign * (half_shift * 0.5 + dsk - 1);
451 x = xsign * (half_shift * 0.5 + dsk);
456 x1 = xsign * (half_shift * 0.5 + dsk - 1 / 8.);
457 x2 = xsign * (half_shift * 0.5 + dsk);
458 float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.25);
459 float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.25 + xsign * ysign * 0.25);
464 float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25);
465 float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25 - xsign * ysign * 0.25);
481 if (
phase == 0 &&
h->GetNbinsY() == 250 &&
h->GetNbinsX() == 80) {
482 int nentries =
h->GetEntries();
483 for (
int binx = 1; binx <= 80; ++binx) {
485 for (
int biny = 1; biny <= 250; ++biny) {
486 bool odd_nrocy = (binx - 1 < 40) != (((binx - 1) / 4) % 2);
487 if (biny % 2 == odd_nrocy)
488 sum +=
h->GetBinContent(binx, biny);
490 sum +=
h->GetBinContent(binx, biny);
492 h->SetBinContent(binx, biny, sum);
493 h->SetBinContent(binx, biny - 1, sum);
499 h->SetEntries(nentries);
509 pad->SetTopMargin(top);
511 pad->SetBottomMargin(bottom);
513 pad->SetLeftMargin(left);
515 pad->SetRightMargin(right);
532 float theMax(-9999.);
534 theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
535 theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
537 float add_min = theMin > 0. ? -0.05 : 0.05;
538 float add_max = theMax > 0. ? 0.05 : -0.05;
540 auto result = std::make_pair(theMin * (1 + add_min), theMax * (1 + add_max));
548 hist->SetStats(kFALSE);
549 hist->SetLineWidth(2);
550 hist->GetXaxis()->CenterTitle(
true);
551 hist->GetYaxis()->CenterTitle(
true);
552 hist->GetXaxis()->SetTitleFont(42);
553 hist->GetYaxis()->SetTitleFont(42);
554 hist->GetXaxis()->SetTitleSize(0.05);
555 hist->GetYaxis()->SetTitleSize(0.05);
556 hist->GetXaxis()->SetTitleOffset(1.1);
557 hist->GetYaxis()->SetTitleOffset(1.3);
558 hist->GetXaxis()->SetLabelFont(42);
559 hist->GetYaxis()->SetLabelFont(42);
560 hist->GetYaxis()->SetLabelSize(.05);
561 hist->GetXaxis()->SetLabelSize(.05);
564 hist->GetZaxis()->SetLabelFont(42);
565 hist->GetZaxis()->SetLabelFont(42);
566 hist->GetZaxis()->SetLabelSize(.05);
567 hist->GetZaxis()->SetLabelSize(.05);
634 bool isOuter =
false;
639 isOuter = !odd_ladder;
641 isOuter = odd_ladder;
644 isOuter = odd_ladder;
646 isOuter = !odd_ladder;
708 m_Phase = const_cast<SiPixelPI::phase*>(&ph);
709 unsigned int subdetId = static_cast<unsigned int>(detId.
subdetId());
732 throw cms::Exception(
"LogicError") <<
"Cannot call filterThePartition BEFORE filling the geometry info!";
782 std::vector<std::pair<int, int>> rocsToMask;
784 int nlad_list[4] = {6, 14, 22, 32};
785 int nlad = nlad_list[layer - 1];
787 int start_x = module > 0 ? ((module + 4) * 8) + 1 : ((4 - (
std::abs(module))) * 8) + 1;
790 int end_x = start_x + 7;
791 int end_y = start_y + 1;
793 COUT <<
"module: " << module <<
" start_x:" << start_x <<
" end_x:" << end_x << std::endl;
794 COUT <<
"ladder: " <<
ladder <<
" start_y:" << start_y <<
" end_y:" << end_y << std::endl;
795 COUT <<
"==================================================================" << std::endl;
797 for (
int bin_x = 1; bin_x <= 72; bin_x++) {
798 for (
int bin_y = 1; bin_y <= (nlad * 4 + 2); bin_y++) {
799 if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
800 rocsToMask.push_back(std::make_pair(bin_x, bin_y));
810 int layer,
int ladder,
int module, std::bitset<16> bad_rocs,
bool isFlipped)
813 std::vector<std::tuple<int, int, int>> rocsToMask;
815 int nlad_list[4] = {6, 14, 22, 32};
816 int nlad = nlad_list[layer - 1];
818 int start_x = module > 0 ? ((module + 4) * 8) + 1 : ((4 - (
std::abs(module))) * 8) + 1;
821 int roc0_x = ((layer == 1) || (layer > 1 && module > 0)) ? start_x + 7 : start_x;
822 int roc0_y = start_y - 1;
825 while (
idx < bad_rocs.size()) {
826 if (bad_rocs.test(
idx)) {
850 int roc_x(0), roc_y(0);
852 if ((layer == 1) || (layer > 1 && module > 0)) {
854 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
855 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
857 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
858 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
862 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
863 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
865 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
866 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
870 COUT << bad_rocs <<
" : (idx)= " <<
idx << std::endl;
871 COUT <<
" layer: " << layer << std::endl;
872 COUT <<
"module: " << module <<
" roc_x:" << roc_x << std::endl;
873 COUT <<
"ladder: " <<
ladder <<
" roc_y:" << roc_y << std::endl;
874 COUT <<
"==================================================================" << std::endl;
876 rocsToMask.push_back(std::make_tuple(roc_x, roc_y,
idx));
888 std::vector<std::pair<int, int>> rocsToMask;
889 int nybins_list[2] = {92, 140};
890 int nybins = nybins_list[
ring - 1];
892 int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (
std::abs(disk))) * 8) + 1;
893 int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
894 : ((nybins / 2) - (
std::abs(blade) * 4) - panel * 2) + 3;
896 int end_x = start_x + 7;
897 int end_y = start_y + 1;
899 COUT <<
"==================================================================" << std::endl;
900 COUT <<
"disk: " << disk <<
" start_x:" << start_x <<
" end_x:" << end_x << std::endl;
901 COUT <<
"blade: " << blade <<
" start_y:" << start_y <<
" end_y:" << end_y << std::endl;
903 for (
int bin_x = 1; bin_x <= 56; bin_x++) {
904 for (
int bin_y = 1; bin_y <= nybins; bin_y++) {
905 if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
906 rocsToMask.push_back(std::make_pair(bin_x, bin_y));
916 int ring,
int blade,
int panel,
int disk, std::bitset<16> bad_rocs,
bool isFlipped)
919 std::vector<std::tuple<int, int, int>> rocsToMask;
920 int nybins_list[2] = {92, 140};
921 int nybins = nybins_list[
ring - 1];
923 int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (
std::abs(disk))) * 8) + 1;
924 int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
925 : ((nybins / 2) - (
std::abs(blade) * 4) - panel * 2) + 3;
927 int roc0_x = disk > 0 ? start_x + 7 : start_x;
928 int roc0_y = start_y - 1;
931 while (
idx < bad_rocs.size()) {
932 if (bad_rocs.test(
idx)) {
933 int roc_x(0), roc_y(0);
960 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
961 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
963 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
964 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
968 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
969 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
971 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
972 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
976 COUT << bad_rocs <<
" : (idx)= " <<
idx << std::endl;
977 COUT <<
" panel: " << panel <<
" isFlipped: " << isFlipped << std::endl;
978 COUT <<
" disk: " << disk <<
" roc_x:" << roc_x << std::endl;
979 COUT <<
" blade: " << blade <<
" roc_y:" << roc_y << std::endl;
980 COUT <<
"===============================" << std::endl;
982 rocsToMask.push_back(std::make_tuple(roc_x, roc_y,
idx));
999 t2.SetTextColor(kRed);
1000 t2.DrawLatexNDC(0.6, 0.50, Form(
"%s NOT SUPPORTED!",
phase.c_str()));
1004 template <
typename T>
1008 using pairtype = std::pair<unsigned int, T>;
1009 auto max = *std::max_element(
1010 theMap.begin(), theMap.end(), [](
const pairtype&
p1,
const pairtype&
p2) {
return p1.second <
p2.second; });
1011 auto min = *std::min_element(
1012 theMap.begin(), theMap.end(), [](
const pairtype&
p1,
const pairtype&
p2) {
return p1.second <
p2.second; });
1013 return std::make_pair(
min.second,
max.second);
1026 return answer_valid;