40 #include <fmt/printf.h> 52 #include "TPaveStats.h" 62 template <SiPixelPI::DetType myType>
63 class SiPixelFEDChannelContainerMap :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
65 SiPixelFEDChannelContainerMap()
67 "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios"),
74 m_condDbCabling =
"frontier://FrontierProd/CMS_CONDITIONS";
75 m_CablingTagName =
"SiPixelFedCablingMap_phase1_v7";
77 m_connectionPool.setParameters(m_connectionPset);
78 m_connectionPool.configure();
81 bool fill()
override {
82 std::vector<std::string> the_scenarios = {};
85 auto ip = paramValues.find(
"Scenarios");
86 if (ip != paramValues.end()) {
87 auto input = ip->second;
88 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
89 boost::char_separator<char> sep{
","};
90 tokenizer tok{
input, sep};
91 for (
const auto&
t : tok) {
92 the_scenarios.push_back(
t);
96 <<
"\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in " 98 <<
"\n Buckle your seatbelts... this might take a while... \n\n";
99 the_scenarios.push_back(
"all");
104 auto tag = PlotBase::getTag<0>();
106 auto iov =
tag.iovs.front();
109 edm::LogPrint(k_ClassName) <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] " 110 <<
"Query the condition database " << m_condDbCabling;
116 edm::LogPrint(k_ClassName) <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] " 117 <<
"Reading IOVs from tag " << m_CablingTagName;
123 std::vector<std::tuple<cond::Time_t, cond::Hash>> m_cabling_iovs;
126 std::vector<unsigned int> listOfCablingIOVs;
128 m_cabling_iovs.end(),
129 std::back_inserter(listOfCablingIOVs),
130 [](std::tuple<cond::Time_t, cond::Hash> myIOV2) ->
unsigned int {
return std::get<0>(myIOV2); });
132 edm::LogPrint(k_ClassName) <<
" Number of SiPixelFedCablngMap payloads: " << listOfCablingIOVs.size()
136 listOfCablingIOVs.begin(), listOfCablingIOVs.end(), closest_from_below(listOfCablingIOVs, std::get<0>(iov)));
139 edm::LogPrint(k_ClassName) <<
" using the SiPixelFedCablingMap with hash: " 140 << std::get<1>(m_cabling_iovs.at(
index)) << std::endl;
143 theCablingMap->initializeRocs();
151 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
152 const auto& scenarioMap =
payload->getScenarioMap();
154 auto pIndexConverter =
PixelIndices(numColumns, numRows);
156 for (
const auto&
scenario : scenarioMap) {
159 if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
160 the_scenarios[0] ==
"all") {
161 edm::LogPrint(k_ClassName) <<
"\t Found Scenario: " << scenName <<
" ==> dumping it";
168 const auto& theDetSetBadPixelFedChannels =
payload->getDetSetBadPixelFedChannels(scenName);
169 for (
const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
170 const auto t_detid = disabledChannels.detId();
172 LogDebug(k_ClassName) << fmt::sprintf(
"DetId : %i \n", t_detid) << std::endl;
174 std::bitset<16> badRocsFromFEDChannels;
176 for (
const auto& ch : disabledChannels) {
177 std::string toOut_ = fmt::sprintf(
"fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
183 LogDebug(k_ClassName) << toOut_ << std::endl;
184 const std::vector<sipixelobjects::CablingPathToDetUnit>&
path =
185 theCablingMap->pathToDetUnit(disabledChannels.detId());
186 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
187 for (
const auto p :
path) {
189 if (myroc->
idInDetUnit() ==
static_cast<unsigned int>(i_roc)) {
192 int chipIndex(0), colROC(0), rowROC(0);
194 pIndexConverter.transformToROC(global.
col, global.
row, chipIndex, colROC, rowROC);
196 LogDebug(k_ClassName) <<
" => i_roc:" << i_roc <<
" " << global.
col <<
"-" << global.
row <<
" | => " 197 << chipIndex <<
" : (" << colROC <<
"," << rowROC <<
")" << std::endl;
199 badRocsFromFEDChannels[chipIndex] =
true;
205 LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
207 auto myDetId =
DetId(t_detid);
210 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
213 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
216 throw cms::Exception(
"LogicError") <<
"Unknown Pixel SubDet ID " << std::endl;
221 gStyle->SetOptStat(0);
223 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
232 const auto headerText = fmt::sprintf(
"#color[4]{%s}, IOV: #color[4]{%s}",
tagname, IOVstring);
236 theROCMap.drawBarrelMaps(
canvas, headerText);
239 theROCMap.drawForwardMaps(
canvas, headerText);
242 theROCMap.drawMaps(
canvas, headerText);
245 throw cms::Exception(
"LogicError") <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
258 inline unsigned int closest_from_above(std::vector<unsigned int>
const& vec,
unsigned int value) {
260 return vec.at(
it - vec.begin() - 1);
263 inline unsigned int closest_from_below(std::vector<unsigned int>
const& vec,
unsigned int value) {
265 return vec.at(
it - vec.begin() - 1);
284 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
285 static constexpr const char* k_ClassName =
"SiPixelFEDChannelContainerMap";
298 template <SiPixelPI::DetType myType>
299 class SiPixelFEDChannelContainerMapSimple :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
301 SiPixelFEDChannelContainerMapSimple()
303 "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios)") {
308 bool fill()
override {
309 std::vector<std::string> the_scenarios = {};
312 auto ip = paramValues.find(
"Scenarios");
313 if (ip != paramValues.end()) {
314 auto input = ip->second;
315 typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
316 boost::char_separator<char> sep{
","};
317 tokenizer tok{
input, sep};
318 for (
const auto&
t : tok) {
319 the_scenarios.push_back(
t);
323 <<
"\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in " 325 <<
"\n Buckle your seatbelts... this might take a while... \n\n";
326 the_scenarios.push_back(
"all");
331 auto tag = PlotBase::getTag<0>();
333 auto iov =
tag.iovs.front();
335 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
336 const auto& scenarioMap =
payload->getScenarioMap();
338 for (
const auto&
scenario : scenarioMap) {
341 if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
342 the_scenarios[0] ==
"all") {
343 edm::LogPrint(k_ClassName) <<
"\t Found Scenario: " << scenName <<
" ==> dumping it";
348 const auto& theDetSetBadPixelFedChannels =
payload->getDetSetBadPixelFedChannels(scenName);
349 for (
const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
350 const auto t_detid = disabledChannels.detId();
352 LogDebug(k_ClassName) << fmt::sprintf(
"DetId : %i \n", t_detid) << std::endl;
354 std::bitset<16> badRocsFromFEDChannels;
356 for (
const auto& ch : disabledChannels) {
357 std::string toOut_ = fmt::sprintf(
"fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
363 LogDebug(k_ClassName) << toOut_ << std::endl;
364 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
365 badRocsFromFEDChannels.set(i_roc);
369 LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
371 const auto& myDetId =
DetId(t_detid);
374 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
377 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
380 throw cms::Exception(
"LogicError") <<
"Unknown Pixel SubDet ID " << std::endl;
385 gStyle->SetOptStat(0);
387 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
396 const auto headerText = fmt::sprintf(
"#color[4]{%s}, IOV: #color[4]{%s}",
tagname, IOVstring);
400 theROCMap.drawBarrelMaps(
canvas, headerText);
403 theROCMap.drawForwardMaps(
canvas, headerText);
406 theROCMap.drawMaps(
canvas, headerText);
409 throw cms::Exception(
"LogicError") <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
417 ltx.SetTextSize(0.023);
419 gPad->GetLeftMargin() - 0.09,
420 gPad->GetBottomMargin() - 0.09,
421 (
"scenarios: #color[4]{" +
422 std::accumulate(the_scenarios.begin(),
445 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
446 static constexpr const char* k_ClassName =
"SiPixelFEDChannelContainerMapSimple";
449 using SiPixelBPixFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_barrel>;
450 using SiPixelFPixFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_forward>;
451 using SiPixelFullFEDChannelContainerMap = SiPixelFEDChannelContainerMapSimple<SiPixelPI::t_all>;
459 template <SiPixelPI::DetType myType>
460 class SiPixelFEDChannelContainerMapWeigthed :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
462 SiPixelFEDChannelContainerMapWeigthed()
464 "SiPixelFEDChannelContainer Pixel Track Map of one (or more scenarios)") {
469 m_condSiPixelProb =
"frontier://FrontierProd/CMS_CONDITIONS";
470 m_connectionPool.setParameters(m_connectionPset);
471 m_connectionPool.configure();
474 bool fill()
override {
476 auto ip = paramValues.find(
"SiPixelQualityProbabilitiesTag");
477 if (ip != paramValues.end()) {
478 m_SiPixelProbTagName = ip->second;
480 edm::LogWarning(k_ClassName) <<
"\n WARNING!!!! \n The needed parameter SiPixelQualityProbabilitiesTag was not " 481 "inputed from the user \n Display will be aborted \n\n";
487 auto tag = PlotBase::getTag<0>();
489 auto iov =
tag.iovs.front();
492 edm::LogPrint(k_ClassName) <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] " 493 <<
"Query the condition database " << m_condSiPixelProb;
499 edm::LogPrint(k_ClassName) <<
"[SiPixelFEDChannelContainerTest::" << __func__ <<
"] " 500 <<
"Reading IOVs from tag " << m_SiPixelProbTagName;
506 std::vector<std::tuple<cond::Time_t, cond::Hash>> m_pixelProb_iovs;
510 edm::LogPrint(k_ClassName) <<
" using the SiPixelQualityProbabilities with hash: " 511 << std::get<1>(m_pixelProb_iovs.front()) << std::endl;
513 auto probabilitiesPayload =
516 const auto& PUbins = probabilitiesPayload->getPileUpBins();
521 std::map<std::string, float> puAvgedProbabilities;
522 for (
const auto& [PUbin, ProbMap] : m_probabilities) {
523 float totProbInPUbin = 0.f;
524 for (
const auto& [scenName,
prob] : ProbMap) {
525 totProbInPUbin +=
prob;
526 if (puAvgedProbabilities.find(scenName) == puAvgedProbabilities.end()) {
527 puAvgedProbabilities[scenName] +=
prob;
529 puAvgedProbabilities.insert({scenName,
prob});
532 LogDebug(k_ClassName) <<
"PU bin: " << PUbin <<
" tot probability " << totProbInPUbin << std::endl;
535 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
536 const auto& scenarioMap =
payload->getScenarioMap();
539 for (
const auto& [scenName,
prob] : puAvgedProbabilities) {
541 if (scenarioMap.find(scenName) != scenarioMap.end()) {
542 LogDebug(k_ClassName) << scenName <<
" : " <<
prob << std::endl;
547 LogDebug(k_ClassName) <<
"Total probability to normalize to: " << totProb << std::endl;
550 for (
auto& pair : puAvgedProbabilities) {
551 pair.second /= totProb;
554 for (
const auto&
scenario : scenarioMap) {
556 LogDebug(k_ClassName) <<
"\t Found Scenario: " << scenName <<
" ==> dumping it";
560 if (puAvgedProbabilities.find(scenName) != puAvgedProbabilities.end()) {
561 w_frac = puAvgedProbabilities[scenName];
568 LogDebug(k_ClassName) <<
"scen: " << scenName <<
" weight: " << w_frac <<
" log(weight):" << log10(w_frac)
571 const auto& theDetSetBadPixelFedChannels =
payload->getDetSetBadPixelFedChannels(scenName);
572 for (
const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
573 const auto t_detid = disabledChannels.detId();
575 LogDebug(k_ClassName) << fmt::sprintf(
"DetId : %i \n", t_detid) << std::endl;
577 std::bitset<16> badRocsFromFEDChannels;
579 for (
const auto& ch : disabledChannels) {
580 std::string toOut_ = fmt::sprintf(
"fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
586 LogDebug(k_ClassName) << toOut_ << std::endl;
587 for (
unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
588 badRocsFromFEDChannels.set(i_roc);
592 LogDebug(k_ClassName) << badRocsFromFEDChannels << std::endl;
594 const auto& myDetId =
DetId(t_detid);
597 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, w_frac * 100);
600 theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, w_frac * 100);
603 throw cms::Exception(
"LogicError") <<
"Unknown Pixel SubDet ID " << std::endl;
608 gStyle->SetOptStat(0);
610 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
619 const auto headerText =
620 fmt::sprintf(
"#bf{#scale[0.6]{#color[2]{%s}, #color[4]{%s}}}",
tagname, m_SiPixelProbTagName);
624 theROCMap.drawBarrelMaps(
canvas, headerText);
627 theROCMap.drawForwardMaps(
canvas, headerText);
630 theROCMap.drawMaps(
canvas, headerText);
633 throw cms::Exception(
"LogicError") <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
641 ltx.SetTextSize(0.023);
642 ltx.DrawLatexNDC(gPad->GetLeftMargin() - 0.09, gPad->GetBottomMargin() - 0.09,
"");
651 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
652 static constexpr const char* k_ClassName =
"SiPixelFEDChannelContainerMapWeigthed";
661 using SiPixelBPixFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_barrel>;
662 using SiPixelFPixFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_forward>;
663 using SiPixelFullFEDChannelContainerWeightedMap = SiPixelFEDChannelContainerMapWeigthed<SiPixelPI::t_all>;
669 class SiPixelFEDChannelContainerScenarios :
public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
671 SiPixelFEDChannelContainerScenarios()
673 bool fill()
override {
674 auto tag = PlotBase::getTag<0>();
676 auto iov =
tag.iovs.front();
678 TGaxis::SetMaxDigits(3);
680 std::shared_ptr<SiPixelFEDChannelContainer>
payload = fetchPayload(std::get<1>(iov));
684 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
687 auto h1 = std::make_unique<TH1F>(
"Count",
688 "SiPixelFEDChannelContainer Bad Roc count;Scenario index;n. of bad ROCs",
694 canvas.SetTopMargin(0.06);
695 canvas.SetBottomMargin(0.12);
696 canvas.SetLeftMargin(0.12);
697 canvas.SetRightMargin(0.05);
700 int scenarioIndex = 0;
705 auto badChannelCollection =
payload->getDetSetBadPixelFedChannels(
scenario);
706 for (
const auto& disabledChannels : *badChannelCollection) {
707 for (
const auto& ch : disabledChannels) {
708 int local_bad_rocs = ch.roc_last - ch.roc_first;
709 badRocCount += local_bad_rocs;
713 h1->SetBinContent(scenarioIndex, badRocCount);
716 TGaxis::SetExponentOffset(-0.1, 0.01,
"y");
717 TGaxis::SetExponentOffset(-0.03, -0.10,
"x");
720 h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
721 h1->SetFillColor(kRed);
722 h1->SetMarkerStyle(20);
723 h1->SetMarkerSize(1);
730 TLegend
legend = TLegend(0.30, 0.88, 0.95, 0.94);
733 legend.SetHeader(fmt::sprintf(
"Payload hash: #bf{%s}", std::get<1>(iov)).c_str(),
"C");
734 legend.AddEntry(h1.get(), fmt::sprintf(
"total scenarios: #bf{%s}",
std::to_string(scenarioIndex)).c_str(),
"F");
735 legend.SetTextSize(0.025);
742 ltx.SetTextSize(0.040);
744 gPad->GetLeftMargin(),
745 1 - gPad->GetTopMargin() + 0.01,
746 fmt::sprintf(
"#color[4]{%s} IOV: #color[4]{%s}",
tagname,
std::to_string(std::get<0>(iov))).c_str());
const TimeTypeSpecs timeTypeSpecs[]
std::map< unsigned int, probabilityVec > probabilityMap
void start(bool readOnly=true)
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Transaction & transaction()
identify pixel inside single ROC
static std::string to_string(const XMLCh *ch)
static std::string const input
global coordinates (row and column in DetUnit, as in PixelDigi)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
GlobalPixel toGlobal(const LocalPixel &loc) const
key
prepare the HTCondor submission files and eventually submit them
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Log< level::Warning, true > LogPrint
IOVProxy readIov(const std::string &tag)
const std::map< std::string, std::string > & inputParamValues() const
void addInputParam(const std::string ¶mName)
void makeNicePlotStyle(TH1 *hist)
row and collumn in ROC representation
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Log< level::Warning, false > LogWarning
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path