39 #include <fmt/printf.h>
51 #include "TPaveStats.h"
61 class SiPixelFEDChannelContainerTest :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
63 SiPixelFEDChannelContainerTest()
71 m_condDbCabling =
"frontier://FrontierProd/CMS_CONDITIONS";
72 m_CablingTagName =
"SiPixelFedCablingMap_phase1_v7";
74 m_connectionPool.setParameters(m_connectionPset);
75 m_connectionPool.configure();
78 bool fill()
override {
79 std::vector<std::string> the_scenarios = {};
82 auto ip = paramValues.find(
"Scenarios");
83 if (ip != paramValues.end()) {
84 auto input = boost::lexical_cast<std::string>(ip->second);
85 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
86 boost::char_separator<char> sep{
","};
87 tokenizer tok{
input, sep};
88 for (
const auto&
t : tok) {
89 the_scenarios.push_back(
t);
93 <<
"\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in "
95 <<
"\n Buckle your seatbelts... this might take a while... \n\n";
96 the_scenarios.push_back(
"all");
101 auto tag = PlotBase::getTag<0>();
102 auto iov =
tag.iovs.front();
105 edm::LogPrint(
"SiPixelFEDChannelContainerTest") <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] "
106 <<
"Query the condition database " << m_condDbCabling;
112 edm::LogPrint(
"SiPixelFEDChannelContainerTest") <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] "
113 <<
"Reading IOVs from tag " << m_CablingTagName;
119 std::vector<std::tuple<cond::Time_t, cond::Hash>> m_cabling_iovs;
122 std::vector<unsigned int> listOfCablingIOVs;
124 m_cabling_iovs.end(),
125 std::back_inserter(listOfCablingIOVs),
126 [](std::tuple<cond::Time_t, cond::Hash> myIOV2) ->
unsigned int {
return std::get<0>(myIOV2); });
129 <<
" Number of SiPixelFedCablngMap payloads: " << listOfCablingIOVs.size() << std::endl;
132 listOfCablingIOVs.begin(), listOfCablingIOVs.end(), closest_from_below(listOfCablingIOVs, std::get<0>(iov)));
136 <<
" using the SiPixelFedCablingMap with hash: " << std::get<1>(m_cabling_iovs.at(
index)) << std::endl;
139 theCablingMap->initializeRocs();
147 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
148 const auto& scenarioMap =
payload->getScenarioMap();
150 auto pIndexConverter =
PixelIndices(numColumns, numRows);
152 for (
const auto&
scenario : scenarioMap) {
155 if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
156 the_scenarios[0] ==
"all") {
157 edm::LogPrint(
"SiPixelFEDChannelContainerTest") <<
"\t Found Scenario: " << scenName <<
" ==> dumping it";
164 const auto& theDetSetBadPixelFedChannels =
payload->getDetSetBadPixelFedChannels(scenName);
165 for (
const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
166 const auto t_detid = disabledChannels.detId();
168 LogDebug(
"SiPixelFEDChannelContainerTest") << fmt::sprintf(
"DetId : %i \n", t_detid) << std::endl;
170 std::bitset<16> badRocsFromFEDChannels;
172 for (
const auto& ch : disabledChannels) {
173 std::string toOut_ = fmt::sprintf(
"fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
179 LogDebug(
"SiPixelFEDChannelContainerTest") << toOut_ << std::endl;
180 const std::vector<sipixelobjects::CablingPathToDetUnit>&
path =
181 theCablingMap->pathToDetUnit(disabledChannels.detId());
182 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
183 for (
const auto p :
path) {
185 if (myroc->
idInDetUnit() == static_cast<unsigned int>(i_roc)) {
188 int chipIndex(0), colROC(0), rowROC(0);
190 pIndexConverter.transformToROC(global.
col, global.
row, chipIndex, colROC, rowROC);
192 LogDebug(
"SiPixelFEDChannelContainerTest")
193 <<
" => i_roc:" << i_roc <<
" " << global.
col <<
"-" << global.
row <<
" | => " << chipIndex
194 <<
" : (" << colROC <<
"," << rowROC <<
")" << std::endl;
196 badRocsFromFEDChannels[chipIndex] =
true;
202 LogDebug(
"SiPixelFEDChannelContainerTest") << badRocsFromFEDChannels << std::endl;
204 auto myDetId =
DetId(t_detid);
207 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
210 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
213 throw cms::Exception(
"LogicError") <<
"Unknown Pixel SubDet ID " << std::endl;
218 gStyle->SetOptStat(0);
220 TCanvas
canvas(
"Summary",
"Summary", 1200, 1600);
221 theROCMap.drawMaps(
canvas);
225 for (
unsigned int lay = 1; lay <= n_layers; lay++) {
229 ltx.SetTextColor(kBlue);
230 ltx.SetTextSize(0.055);
231 ltx.SetTextAlign(11);
232 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
233 1 - gPad->GetTopMargin() + 0.01,
235 ? (
"IOV:" + std::to_string(unpacked.second)).c_str()
236 : (std::to_string(unpacked.first) +
"," + std::to_string(unpacked.second)).c_str());
243 ltx.SetTextColor(kBlue);
244 ltx.SetTextSize(0.050);
245 ltx.SetTextAlign(11);
246 ltx.DrawLatexNDC(gPad->GetLeftMargin(),
247 1 - gPad->GetTopMargin() + 0.01,
249 ? (
"IOV:" + std::to_string(unpacked.second)).c_str()
250 : (std::to_string(unpacked.first) +
"," + std::to_string(unpacked.second)).c_str());
263 inline unsigned int closest_from_above(std::vector<unsigned int>
const& vec,
unsigned int value) {
265 return vec.at(it - vec.begin() - 1);
268 inline unsigned int closest_from_below(std::vector<unsigned int>
const& vec,
unsigned int value) {
270 return vec.at(it - vec.begin() - 1);
283 static constexpr
int numColumns = 416;
284 static constexpr
int numRows = 160;
285 static constexpr
int n_rings = 2;
286 static constexpr
int n_layers = 4;
299 class SiPixelFEDChannelContainerScenarios :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
301 SiPixelFEDChannelContainerScenarios()
303 bool fill()
override {
304 auto tag = PlotBase::getTag<0>();
306 auto iov =
tag.iovs.front();
308 TGaxis::SetMaxDigits(3);
310 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
314 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
317 auto h1 = std::make_unique<TH1F>(
"Count",
318 "SiPixelFEDChannelContainer Bad Roc count;Scenario index;n. of bad ROCs",
324 canvas.SetTopMargin(0.06);
325 canvas.SetBottomMargin(0.12);
326 canvas.SetLeftMargin(0.12);
327 canvas.SetRightMargin(0.05);
330 int scenarioIndex = 0;
335 auto badChannelCollection =
payload->getDetSetBadPixelFedChannels(
scenario);
336 for (
const auto& disabledChannels : *badChannelCollection) {
337 for (
const auto& ch : disabledChannels) {
338 int local_bad_rocs = ch.roc_last - ch.roc_first;
339 badRocCount += local_bad_rocs;
343 h1->SetBinContent(scenarioIndex, badRocCount);
346 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
347 TGaxis::SetExponentOffset(-0.03, -0.10,
"x");
350 h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
351 h1->SetFillColor(kRed);
352 h1->SetMarkerStyle(20);
353 h1->SetMarkerSize(1);
360 TLegend
legend = TLegend(0.30, 0.88, 0.95, 0.94);
363 legend.SetHeader(fmt::sprintf(
"Payload hash: #bf{%s}", std::get<1>(iov)).c_str(),
"C");
364 legend.AddEntry(h1.get(), fmt::sprintf(
"total scenarios: #bf{%s}", std::to_string(scenarioIndex)).c_str(),
"F");
365 legend.SetTextSize(0.025);
372 ltx.SetTextSize(0.040);
374 gPad->GetLeftMargin(),
375 1 - gPad->GetTopMargin() + 0.01,
376 fmt::sprintf(
"#color[4]{%s} IOV: #color[4]{%s}",
tagname, std::to_string(std::get<0>(iov))).c_str());