Skip to content

Commit fab1750

Browse files
committed
protect SiStripTkMaps in case of empty inputs, also test it in unit tests
1 parent 71f4491 commit fab1750

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

DQM/TrackerRemapper/src/SiStripTkMaps.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ void SiStripTkMaps::drawMap(TCanvas& canvas, std::string option) {
9696
}
9797

9898
// Adjust the color palette
99-
double minValue = *std::min_element(m_values.begin(), m_values.end());
100-
double maxValue = *std::max_element(m_values.begin(), m_values.end());
99+
if (!m_values.empty()) {
100+
double minValue = *std::min_element(m_values.begin(), m_values.end());
101+
double maxValue = *std::max_element(m_values.begin(), m_values.end());
101102

102-
// Setting a palette that skips the color for the emptyBinValue
103-
m_trackerMap->SetMinimum(minValue); // Set min to the smallest valid value
104-
m_trackerMap->SetMaximum(maxValue); // Set max to the largest valid value
103+
// Setting a palette that skips the color for the emptyBinValue
104+
m_trackerMap->SetMinimum(minValue); // Set min to the smallest valid value
105+
m_trackerMap->SetMaximum(maxValue); // Set max to the largest valid value
106+
}
105107

106108
canvas.cd();
107109
adjustCanvasMargins(canvas.cd(), tmargin_, bmargin_, lmargin_, rmargin_);
@@ -307,8 +309,8 @@ void SiStripTkMaps::readVertices(double& minx, double& maxx, double& miny, doubl
307309
}
308310
++iy;
309311
} // else
310-
} // else
311-
} // loop on entries
312+
} // else
313+
} // loop on entries
312314

313315
if (isPixel) {
314316
continue;

DQM/TrackerRemapper/test/test_catch2_SiStripTkMaps.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,13 @@ TEST_CASE("SiStripTkMaps testing", "[SiStripTkMaps]") {
2626
std::cout << "SiStripTkMaps filled " << filledIds.size() << " DetIds" << std::endl;
2727
REQUIRE(filledIds.size() == count);
2828
}
29+
//_____________________________________________________________
30+
SECTION("Check empty SiStripTkMaps") {
31+
SiStripTkMaps theMap("COLZA L");
32+
theMap.bookMap("testing SiStripTkMaps", "counts");
33+
TCanvas c = TCanvas("c", "c");
34+
theMap.drawMap(c, "");
35+
c.SaveAs("SiStripsEmptyTkMaps.png");
36+
REQUIRE(true);
37+
}
2938
}

0 commit comments

Comments
 (0)