39 #include "TPaveStats.h"
48 static const int rocIdMaskBits = 0x1F;
50 struct packedBadRocFraction {
51 std::vector<int> badRocNumber;
52 std::vector<float> badRocFrac;
55 using BRFractions = std::unordered_map<uint32_t, packedBadRocFraction>;
58 BRFractions pbrf(std::shared_ptr<SiPixelDynamicInefficiency>
payload) {
60 const std::map<uint32_t, double>& PixelGeomFactorsDBIn =
payload->getPixelGeomFactors();
63 for (
const auto db_factor : PixelGeomFactorsDBIn) {
66 unsigned int rocMask = rocIdMaskBits <<
shift;
67 unsigned int rocId = (((db_factor.first) & rocMask) >>
shift);
68 uint32_t rawid = db_factor.first & (~rocMask);
70 if (
f.find(rawid) ==
f.end()) {
71 packedBadRocFraction
p;
72 f.insert(std::make_pair(rawid,
p));
77 double factor = db_factor.second;
78 double badFraction = 1 -
factor;
80 f.at(rawid).badRocNumber.emplace_back(rocId);
81 f.at(rawid).badRocFrac.emplace_back(badFraction);
88 bool isPhase0(
const BRFractions& fractions) {
91 const auto& p0detIds =
reader.getAllDetIds();
92 std::vector<uint32_t> ownDetIds;
96 std::back_inserter(ownDetIds),
97 [](std::pair<uint32_t, packedBadRocFraction>
d) -> uint32_t {
return d.first; });
99 for (
const auto& det : ownDetIds) {
101 if (
std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
113 class SiPixelDynamicInefficiencyTest :
public Histogram1D<SiPixelDynamicInefficiency, SINGLE_IOV> {
115 SiPixelDynamicInefficiencyTest()
117 "SiPixelDynamicInefficiency test",
"SiPixelDynamicInefficiency test", 1, 0.0, 1.0) {}
119 bool fill()
override {
120 auto tag = PlotBase::getTag<0>();
121 for (
auto const& iov :
tag.iovs) {
122 std::shared_ptr<SiPixelDynamicInefficiency>
payload = Base::fetchPayload(std::get<1>(iov));
126 const auto geomFactors =
payload->getPixelGeomFactors();
127 for (
const auto [
ID,
value] : geomFactors) {
140 template <SiPixelPI::DetType myType>
141 class SiPixelIneffROCfromDynIneffMap :
public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
143 SiPixelIneffROCfromDynIneffMap()
148 bool fill()
override {
149 auto tag = PlotBase::getTag<0>();
150 auto iov =
tag.iovs.front();
152 std::shared_ptr<SiPixelDynamicInefficiency>
payload = fetchPayload(std::get<1>(iov));
154 const auto fr = SiPixDynIneff::pbrf(
payload);
156 if (SiPixDynIneff::isPhase0(fr)) {
158 <<
"SiPixelIneffROCfromDynIneff maps are not supported for non-Phase1 Pixel geometries !";
159 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
168 for (
const auto& element : fr) {
169 auto rawid = element.first;
171 auto packedinfo = element.second;
172 auto badRocs = packedinfo.badRocNumber;
173 auto badRocsF = packedinfo.badRocFrac;
175 for (
size_t i = 0;
i < badRocs.size();
i++) {
176 std::bitset<16> rocToMark;
177 rocToMark.set(badRocs[
i]);
181 theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[
i] * 100.
f);
186 gStyle->SetOptStat(0);
188 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
194 ? std::to_string(unpacked.second)
195 : (std::to_string(unpacked.first) +
"," + std::to_string(unpacked.second));
197 const auto headerText = fmt::sprintf(
"#color[4]{%s}, IOV: #color[4]{%s}",
tagname, IOVstring);
201 theMap.drawBarrelMaps(
canvas, headerText);
204 theMap.drawForwardMaps(
canvas, headerText);
207 theMap.drawMaps(
canvas, headerText);
211 <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
217 canvas.SaveAs(
"outAll.root");
224 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
228 using SiPixelBPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_barrel>;
229 using SiPixelFPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_forward>;
230 using SiPixelFullIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_all>;
235 template <SiPixelPI::DetType myType, IOVMultiplicity nIOVs,
int ntags>
236 class SiPixelIneffROCComparisonBase :
public PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags> {
238 SiPixelIneffROCComparisonBase()
240 Form(
"SiPixelDynamicInefficiency %s Pixel Map",
SiPixelPI::
DetNames[myType].c_str())),
244 bool fill()
override {
246 auto theIOVs = PlotBase::getTag<0>().iovs;
247 auto f_tagname = PlotBase::getTag<0>().name;
249 auto firstiov = theIOVs.front();
250 std::tuple<cond::Time_t, cond::Hash> lastiov;
253 assert(this->m_plotAnnotations.ntags < 3);
255 if (this->m_plotAnnotations.ntags == 2) {
256 auto tag2iovs = PlotBase::getTag<1>().iovs;
257 l_tagname = PlotBase::getTag<1>().name;
258 lastiov = tag2iovs.front();
260 lastiov = theIOVs.back();
263 std::shared_ptr<SiPixelDynamicInefficiency> last_payload = this->fetchPayload(std::get<1>(lastiov));
264 std::shared_ptr<SiPixelDynamicInefficiency> first_payload = this->fetchPayload(std::get<1>(firstiov));
266 const auto fp = SiPixDynIneff::pbrf(last_payload);
267 const auto lp = SiPixDynIneff::pbrf(first_payload);
269 if (SiPixDynIneff::isPhase0(
fp) || SiPixDynIneff::isPhase0(lp)) {
271 <<
"SiPixelDynamicInefficiency comparison maps are not supported for non-Phase1 Pixel geometries !";
272 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
281 gStyle->SetOptStat(0);
283 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
290 ? std::to_string(f_unpacked.second)
291 : (std::to_string(f_unpacked.first) +
"," + std::to_string(f_unpacked.second));
294 ? std::to_string(l_unpacked.second)
295 : (std::to_string(l_unpacked.first) +
"," + std::to_string(l_unpacked.second));
299 if (this->m_plotAnnotations.ntags == 2) {
301 fmt::sprintf(
"#color[2]{A: %s, %s} - #color[4]{B: %s, %s}", f_tagname, f_IOVstring, l_tagname, l_IOVstring);
303 headerText = fmt::sprintf(
"%s,IOV #color[2]{A: %s} - #color[4]{B: %s} ", f_tagname, f_IOVstring, l_IOVstring);
308 theMap.drawBarrelMaps(
canvas, headerText);
311 theMap.drawForwardMaps(
canvas, headerText);
314 theMap.drawMaps(
canvas, headerText);
318 <<
"\nERROR: unrecognized Pixel Detector part " << std::endl;
322 fillTheMapFromPayload(theMap,
fp,
false);
325 fillTheMapFromPayload(theMap, lp,
true);
330 canvas.SaveAs(
"outAll.root");
337 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
342 for (
const auto& element : fr) {
343 auto rawid = element.first;
345 auto packedinfo = element.second;
346 auto badRocs = packedinfo.badRocNumber;
347 auto badRocsF = packedinfo.badRocFrac;
349 for (
size_t i = 0;
i < badRocs.size();
i++) {
350 std::bitset<16> rocToMark;
351 rocToMark.set(badRocs[
i]);
367 using SiPixelBPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, SINGLE_IOV, 2>;
368 using SiPixelFPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, SINGLE_IOV, 2>;
369 using SiPixelFullIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, SINGLE_IOV, 2>;