1 #ifndef CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
2 #define CONDCORE_SIPIXELPLUGINS_SIPIXELPAYLOADINSPECTORHELPER_H
7 #include <boost/tokenizer.hpp>
8 #include <boost/range/adaptor/indexed.hpp>
16 #include "TPaveStats.h"
17 #include "TPaveText.h"
32 #define COUT std::cout << "MM "
34 #define COUT edm::LogVerbatim("")
48 return std::make_pair(
run,
lumi);
69 if (
quadrant(detid, &tTopo_, phase_) % 2)
81 if (
quadrant(detid, &tTopo_, phase_) < 3)
99 }
else if (phase_ == 1) {
112 if (
quadrant(detid, &tTopo_, phase_) % 2)
132 if (
quadrant(detid, &tTopo_, phase_) < 3)
140 l->SetBit(kCanDelete);
143 l->SetLineColor(color);
153 bool half_shift =
true,
154 bool mark_zero =
true,
155 bool standard_palette =
true) {
160 s_title =
"Barrel Pixel Layer" + std::to_string(lay);
163 s_title =
"Forward Pixel Ring" + std::to_string(
ring);
166 gStyle->SetPadRightMargin(0.125);
168 if (standard_palette) {
169 gStyle->SetPalette(1);
172 const Int_t NRGBs = 5;
173 const Int_t NCont = 255;
175 Double_t stops[NRGBs] = {0.00, 0.34, 0.61, 0.84, 1.00};
176 Double_t
red[NRGBs] = {0.00, 0.00, 0.87, 1.00, 0.51};
177 Double_t green[NRGBs] = {0.00, 0.81, 1.00, 0.20, 0.00};
178 Double_t
blue[NRGBs] = {0.51, 1.00, 0.12, 0.00, 0.00};
179 TColor::CreateGradientColorTable(NRGBs, stops,
red, green,
blue, NCont);
180 gStyle->SetNumberContours(NCont);
183 h->SetMarkerSize(0.7);
189 ltx.SetTextSize(0.06);
190 ltx.SetTextAlign(31);
191 ltx.DrawLatexNDC(1 - gPad->GetRightMargin(), 1 - gPad->GetTopMargin() + 0.01, (s_title).c_str());
195 std::vector<std::vector<int>> nladder = {{10, 16, 22}, {6, 14, 22, 32}};
196 int nlad = nladder[
phase][lay - 1];
197 for (
int xsign = -1; xsign <= 1; xsign += 2)
198 for (
int ysign = -1; ysign <= 1; ysign += 2) {
199 float xlow = xsign * (half_shift * 0.5);
200 float xhigh = xsign * (half_shift * 0.5 + 4);
201 float ylow = ysign * (half_shift * 0.5 + (
phase == 0) * 0.5);
202 float yhigh = ysign * (half_shift * 0.5 - (
phase == 0) * 0.5 + nlad);
209 for (
int lad = 1; lad < nlad; ++lad) {
210 float y = ysign * (lad + half_shift * 0.5);
213 for (
int lad = 1; lad <= nlad; ++lad)
214 if (!(
phase == 0 && (lad == 1 || lad == nlad))) {
215 float y = ysign * (lad + half_shift * 0.5 - 0.5);
220 float x = xsign * (
mod + half_shift * 0.5);
228 for (
int lad = 1; lad <= nlad; ++lad) {
229 bool flipped = ysign == 1 ? lad % 2 == 0 : lad % 2 == 1;
232 int roc0_orientation = flipped ? -1 : 1;
234 roc0_orientation *= -1;
236 roc0_orientation *= -1;
237 float x1 = xsign * (
mod + half_shift * 0.5);
238 float x2 = xsign * (
mod + half_shift * 0.5 - 1. / 8);
239 float y1 = ysign * (lad + half_shift * 0.5 - 0.5);
240 float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 1. / 2);
241 if (!(
phase == 0 && (lad == 1 || lad == nlad) && xsign == -1)) {
242 if (lay == 1 && xsign <= -1) {
243 float x1 = xsign * ((
mod - 1) + half_shift * 0.5);
244 float x2 = xsign * ((
mod - 1) + half_shift * 0.5 + 1. / 8);
245 float y1 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation);
246 float y2 = ysign * (lad + half_shift * 0.5 - 0.5 + roc0_orientation * 3. / 2);
261 for (
int dsk = 1, ndsk = 2 + (
phase == 1); dsk <= ndsk; ++dsk) {
262 for (
int xsign = -1; xsign <= 1; xsign += 2)
263 for (
int ysign = -1; ysign <= 1; ysign += 2) {
265 int first_roc = 3,
nbin = 16;
266 for (
int bld = 1, nbld = 12; bld <= nbld; ++bld) {
268 for (
int plq = 1, nplq = 7; plq <= nplq; ++plq) {
270 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (
float)
nbin);
272 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * (plq + 1) - (plq == 7)) / (
float)
nbin);
273 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + plq / 2) * 0.1);
274 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + plq / 2) * 0.1);
279 for (
int plq = 1, nplq = 7 + 1; plq <= nplq; ++plq) {
280 float x = xsign * (half_shift * 0.5 + dsk - 1 +
281 (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8)) / (
float)
nbin);
282 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
283 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
287 for (
int plq = 2, nplq = 6; plq <= nplq; ++plq)
289 float x = xsign * (half_shift * 0.5 + dsk - 1 +
290 (first_roc - 3 + 2 * plq + (plq == 1) - (plq == 8) + 1) / (
float)
nbin);
291 float ylow = ysign * (half_shift * 0.5 + (bld - 0.5) - (2 + (plq - (plq == 8)) / 2) * 0.1);
292 float yhigh = ysign * (half_shift * 0.5 + (bld - 0.5) + (2 + (plq - (plq == 8)) / 2) * 0.1);
296 for (
int plq = 1, nplq = 7; plq <= nplq; ++plq) {
298 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1)) / (
float)
nbin);
300 xsign * (half_shift * 0.5 + dsk - 1 + (first_roc - 3 + 2 * plq + (plq == 1) + 1) / (
float)
nbin);
301 int sign = xsign * ysign * ((plq % 2) ? 1 : -1);
302 float y1 = ysign * (half_shift * 0.5 + (bld - 0.5) +
sign * (2 + plq / 2) * 0.1);
303 float y2 = ysign * (half_shift * 0.5 + (bld - 0.5) +
sign * (plq / 2) * 0.1);
310 }
else if (
phase == 1) {
313 for (
int bld = 1, nbld = 5 +
ring * 6; bld <= nbld; ++bld) {
315 Color_t p1_color = 1, p2_color = 1;
318 float x1 = xsign * (half_shift * 0.5 + dsk - 1 + (
ring - 1) * 0.5);
319 float x2 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5);
321 float y1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.5);
323 float y2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld);
324 float yp2_mid = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25);
325 float y3 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.5);
332 float x = xsign * (half_shift * 0.5 + dsk - 1 + (
ring - 1) * 0.5);
337 x = xsign * (half_shift * 0.5 + dsk);
342 x1 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5 - 1 / 16.);
343 x2 = xsign * (half_shift * 0.5 + dsk - 1 +
ring * 0.5);
344 float y1_p1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.25);
345 float y2_p1 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld +
sign * 0.25 + xsign * ysign * 0.25);
350 float y1_p2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25);
351 float y2_p2 = ysign * (half_shift * 0.5 - 0.5 +
scale * bld -
sign * 0.25 - xsign * ysign * 0.25);
358 for (
int bld = 1, nbld = 5 +
ring * 6; bld <= nbld; ++bld) {
359 Color_t p1_color = 1, p2_color = 1;
362 float x1 = xsign * (half_shift * 0.5 + dsk - 1);
363 float x2 = xsign * (half_shift * 0.5 + dsk);
365 float y1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.5);
367 float y2 = ysign * (half_shift * 0.5 - 0.5 + bld);
368 float yp2_mid = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25);
369 float y3 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.5);
376 float x = xsign * (half_shift * 0.5 + dsk - 1);
381 x = xsign * (half_shift * 0.5 + dsk);
386 x1 = xsign * (half_shift * 0.5 + dsk - 1 / 8.);
387 x2 = xsign * (half_shift * 0.5 + dsk);
388 float y1_p1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.25);
389 float y2_p1 = ysign * (half_shift * 0.5 - 0.5 + bld +
sign * 0.25 + xsign * ysign * 0.25);
394 float y1_p2 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25);
395 float y2_p2 = ysign * (half_shift * 0.5 - 0.5 + bld -
sign * 0.25 - xsign * ysign * 0.25);
411 if (
phase == 0 &&
h->GetNbinsY() == 250 &&
h->GetNbinsX() == 80) {
412 int nentries =
h->GetEntries();
413 for (
int binx = 1; binx <= 80; ++binx) {
415 for (
int biny = 1; biny <= 250; ++biny) {
416 bool odd_nrocy = (binx - 1 < 40) != (((binx - 1) / 4) % 2);
417 if (biny % 2 == odd_nrocy)
418 sum +=
h->GetBinContent(binx, biny);
420 sum +=
h->GetBinContent(binx, biny);
422 h->SetBinContent(binx, biny, sum);
423 h->SetBinContent(binx, biny - 1, sum);
429 h->SetEntries(nentries);
439 pad->SetTopMargin(top);
441 pad->SetBottomMargin(bottom);
443 pad->SetLeftMargin(left);
445 pad->SetRightMargin(right);
462 float theMax(-9999.);
464 theMax = h1->GetMaximum() > h2->GetMaximum() ? h1->GetMaximum() : h2->GetMaximum();
465 theMin = h1->GetMinimum() < h2->GetMaximum() ? h1->GetMinimum() : h2->GetMinimum();
467 float add_min = theMin > 0. ? -0.05 : 0.05;
468 float add_max = theMax > 0. ? 0.05 : -0.05;
470 auto result = std::make_pair(theMin * (1 + add_min), theMax * (1 + add_max));
478 hist->SetStats(kFALSE);
479 hist->SetLineWidth(2);
480 hist->GetXaxis()->CenterTitle(
true);
481 hist->GetYaxis()->CenterTitle(
true);
482 hist->GetXaxis()->SetTitleFont(42);
483 hist->GetYaxis()->SetTitleFont(42);
484 hist->GetXaxis()->SetTitleSize(0.05);
485 hist->GetYaxis()->SetTitleSize(0.05);
486 hist->GetXaxis()->SetTitleOffset(1.1);
487 hist->GetYaxis()->SetTitleOffset(1.3);
488 hist->GetXaxis()->SetLabelFont(42);
489 hist->GetYaxis()->SetLabelFont(42);
490 hist->GetYaxis()->SetLabelSize(.05);
491 hist->GetXaxis()->SetLabelSize(.05);
494 hist->GetZaxis()->SetLabelFont(42);
495 hist->GetZaxis()->SetLabelFont(42);
496 hist->GetZaxis()->SetLabelSize(.05);
497 hist->GetZaxis()->SetLabelSize(.05);
562 bool isOuter =
false;
567 isOuter = !odd_ladder;
569 isOuter = odd_ladder;
572 isOuter = odd_ladder;
574 isOuter = !odd_ladder;
634 unsigned int subdetId = static_cast<unsigned int>(detId.
subdetId());
700 std::vector<std::pair<int, int>> rocsToMask;
702 int nlad_list[4] = {6, 14, 22, 32};
703 int nlad = nlad_list[layer - 1];
708 int end_x = start_x + 7;
709 int end_y = start_y + 1;
711 COUT <<
"module: " <<
module <<
" start_x:" << start_x <<
" end_x:" << end_x << std::endl;
712 COUT <<
"ladder: " <<
ladder <<
" start_y:" << start_y <<
" end_y:" << end_y << std::endl;
713 COUT <<
"==================================================================" << std::endl;
715 for (
int bin_x = 1; bin_x <= 72; bin_x++) {
716 for (
int bin_y = 1; bin_y <= (nlad * 4 + 2); bin_y++) {
717 if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
718 rocsToMask.push_back(std::make_pair(bin_x, bin_y));
728 int layer,
int ladder,
int module, std::bitset<16> bad_rocs,
bool isFlipped)
731 std::vector<std::tuple<int, int, int>> rocsToMask;
733 int nlad_list[4] = {6, 14, 22, 32};
734 int nlad = nlad_list[layer - 1];
739 int roc0_x = ((layer == 1) || (layer > 1 &&
module > 0)) ? start_x + 7 : start_x;
740 int roc0_y = start_y - 1;
743 while (
idx < bad_rocs.size()) {
744 if (bad_rocs.test(
idx)) {
768 int roc_x(0), roc_y(0);
770 if ((layer == 1) || (layer > 1 &&
module > 0)) {
772 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
773 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
775 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
776 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
780 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
781 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
783 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
784 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
788 COUT << bad_rocs <<
" : (idx)= " <<
idx << std::endl;
789 COUT <<
" layer: " << layer << std::endl;
790 COUT <<
"module: " <<
module <<
" roc_x:" << roc_x << std::endl;
791 COUT <<
"ladder: " <<
ladder <<
" roc_y:" << roc_y << std::endl;
792 COUT <<
"==================================================================" << std::endl;
794 rocsToMask.push_back(std::make_tuple(roc_x, roc_y,
idx));
806 std::vector<std::pair<int, int>> rocsToMask;
807 int nybins_list[2] = {92, 140};
808 int nybins = nybins_list[
ring - 1];
810 int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (
std::abs(disk))) * 8) + 1;
811 int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
812 : ((nybins / 2) - (
std::abs(blade) * 4) - panel * 2) + 3;
814 int end_x = start_x + 7;
815 int end_y = start_y + 1;
817 COUT <<
"==================================================================" << std::endl;
818 COUT <<
"disk: " << disk <<
" start_x:" << start_x <<
" end_x:" << end_x << std::endl;
819 COUT <<
"blade: " << blade <<
" start_y:" << start_y <<
" end_y:" << end_y << std::endl;
821 for (
int bin_x = 1; bin_x <= 56; bin_x++) {
822 for (
int bin_y = 1; bin_y <= nybins; bin_y++) {
823 if (bin_x >= start_x && bin_x <= end_x && bin_y >= start_y && bin_y <= end_y) {
824 rocsToMask.push_back(std::make_pair(bin_x, bin_y));
834 int ring,
int blade,
int panel,
int disk, std::bitset<16> bad_rocs,
bool isFlipped)
837 std::vector<std::tuple<int, int, int>> rocsToMask;
838 int nybins_list[2] = {92, 140};
839 int nybins = nybins_list[
ring - 1];
841 int start_x = disk > 0 ? ((disk + 3) * 8) + 1 : ((3 - (
std::abs(disk))) * 8) + 1;
842 int start_y = blade > 0 ? (nybins / 2) + (blade * 4) - (panel * 2) + 3
843 : ((nybins / 2) - (
std::abs(blade) * 4) - panel * 2) + 3;
845 int roc0_x = disk > 0 ? start_x + 7 : start_x;
846 int roc0_y = start_y - 1;
849 while (
idx < bad_rocs.size()) {
850 if (bad_rocs.test(
idx)) {
851 int roc_x(0), roc_y(0);
878 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
879 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
881 roc_x =
idx < 8 ? roc0_x -
idx : (start_x - 8) +
idx;
882 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
886 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
887 roc_y =
idx < 8 ? roc0_y + 1 : roc0_y + 2;
889 roc_x =
idx < 8 ? roc0_x +
idx : (roc0_x + 7) - (
idx - 8);
890 roc_y =
idx < 8 ? roc0_y + 2 : roc0_y + 1;
894 COUT << bad_rocs <<
" : (idx)= " <<
idx << std::endl;
895 COUT <<
" panel: " << panel <<
" isFlipped: " << isFlipped << std::endl;
896 COUT <<
" disk: " << disk <<
" roc_x:" << roc_x << std::endl;
897 COUT <<
" blade: " << blade <<
" roc_y:" << roc_y << std::endl;
898 COUT <<
"===============================" << std::endl;
900 rocsToMask.push_back(std::make_tuple(roc_x, roc_y,
idx));
907 using indexedCorners = std::map<unsigned int, std::pair<std::vector<float>, std::vector<float>>>;
915 for (
const auto&
file : cornerFiles) {
916 auto cornerFileName =
file.fullPath();
917 std::ifstream cornerFile(cornerFileName.c_str());
918 if (!cornerFile.good()) {
919 throw cms::Exception(
"FileError") <<
"Problem opening corner file: " << cornerFileName;
922 while (std::getline(cornerFile,
line)) {
924 std::istringstream iss(
line);
927 std::vector<std::string> corners(reads,
"");
928 std::vector<float> xP, yP;
931 for (
unsigned int i = 0;
i < reads; ++
i) {
932 iss >> corners.at(
i);
936 for (
unsigned int i = 0;
i < reads;
i++) {
939 COUT << corners.at(
i) <<
" ";
940 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
941 boost::char_separator<char> sep{
","};
942 tokenizer tok{corners.at(
i), sep};
943 for (
const auto&
t : tok | boost::adaptors::indexed(0)) {
944 if (
t.index() == 0) {
945 xP.push_back(atof((
t.value()).c_str()));
946 }
else if (
t.index() == 1) {
947 yP.push_back(atof((
t.value()).c_str()));
949 edm::LogError(
"LogicError") <<
"There should not be any token with index " <<
t.index() << std::endl;
955 xP.push_back(xP.front());
956 yP.push_back(yP.front());
958 for (
unsigned int i = 0;
i < xP.size();
i++) {
959 COUT <<
"x[" <<
i <<
"]=" << xP[
i] <<
" y[" <<
i <<
"]" << yP[
i] << std::endl;
962 theOutMap[
id] = std::make_pair(xP, yP);
980 t2.SetTextColor(kRed);
981 t2.DrawLatexNDC(0.6, 0.50, Form(
"%s NOT SUPPORTED!",
phase.c_str()));
985 template <
typename T>
989 using pairtype = std::pair<unsigned int, T>;
990 auto max = *std::max_element(
991 theMap.begin(), theMap.end(), [](
const pairtype&
p1,
const pairtype&
p2) {
return p1.second <
p2.second; });
992 auto min = *std::min_element(
993 theMap.begin(), theMap.end(), [](
const pairtype&
p1,
const pairtype&
p2) {
return p1.second <
p2.second; });
994 return std::make_pair(
min.second,
max.second);
1007 return answer_valid;