39 #include "TPaveStats.h" 49 const std::array<std::string, 5> factorString = {
50 {
"pixel geometry",
"column geometry",
"chip geometry",
"PU",
"invalid"}};
52 using FactorMap = std::map<unsigned int, double>;
53 using PUFactorMap = std::map<unsigned int, std::vector<double> >;
57 const int rocIdMaskBits = 0x1F;
59 struct packedBadRocFraction {
60 std::vector<int> badRocNumber;
61 std::vector<float> badRocFrac;
64 using BRFractions = std::unordered_map<uint32_t, packedBadRocFraction>;
67 BRFractions pbrf(std::shared_ptr<SiPixelDynamicInefficiency>
payload) {
69 const std::map<uint32_t, double>& PixelGeomFactorsDBIn =
payload->getPixelGeomFactors();
72 for (
const auto db_factor : PixelGeomFactorsDBIn) {
75 unsigned int rocMask = rocIdMaskBits <<
shift;
76 unsigned int rocId = (((db_factor.first) & rocMask) >>
shift);
77 uint32_t rawid = db_factor.first & (~rocMask);
79 if (
f.find(rawid) ==
f.end()) {
80 packedBadRocFraction
p;
81 f.insert(std::make_pair(rawid,
p));
86 double factor = db_factor.second;
87 double badFraction = 1 -
factor;
89 f.at(rawid).badRocNumber.emplace_back(rocId);
90 f.at(rawid).badRocFrac.emplace_back(badFraction);
97 bool isPhase0(
const BRFractions& fractions) {
100 const auto& p0detIds =
reader.getAllDetIds();
101 std::vector<uint32_t> ownDetIds;
105 std::back_inserter(ownDetIds),
106 [](std::pair<uint32_t, packedBadRocFraction>
d) -> uint32_t {
return d.first; });
108 for (
const auto& det : ownDetIds) {
110 if (
std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
118 double getMatchingGeomFactor(
const DetId& detid,
119 const std::map<unsigned int, double>& map_geomfactor,
120 const std::vector<uint32_t>& detIdmasks) {
121 double geomfactor_db = 1;
122 for (
auto map_element : map_geomfactor) {
127 for (; __i < detIdmasks.size(); __i++) {
135 if (__i != detIdmasks.size())
137 geomfactor_db *= map_element.second;
139 return geomfactor_db;
143 std::vector<double> getMatchingPUFactors(
const DetId& detid,
144 const std::map<
unsigned int, std::vector<double> >& map_pufactory,
145 const std::vector<uint32_t>& detIdmasks) {
146 std::vector<double> pufactors_db;
147 for (
const auto& map_element : map_pufactory) {
152 for (; __i < detIdmasks.size(); __i++) {
160 if (__i != detIdmasks.size())
162 pufactors_db = map_element.second;
190 inputFile =
"Geometry/TrackerCommonData/data/trackerParameters.xml";
193 inputFile =
"Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml";
196 inputFile =
"Geometry/TrackerCommonData/data/PhaseII/trackerParameters.xml";
207 std::vector<uint32_t> masks_geom;
210 masks_geom.push_back(tkTopo.pxbDetId(
max, 0, 0).rawId());
211 masks_geom.push_back(tkTopo.pxbDetId(0,
max, 0).rawId());
212 masks_geom.push_back(tkTopo.pxbDetId(0, 0,
max).rawId());
213 masks_geom.push_back(tkTopo.pxfDetId(
max, 0, 0, 0, 0).rawId());
214 masks_geom.push_back(tkTopo.pxfDetId(0,
max, 0, 0, 0).rawId());
215 masks_geom.push_back(tkTopo.pxfDetId(0, 0,
max, 0, 0).rawId());
216 masks_geom.push_back(tkTopo.pxfDetId(0, 0, 0,
max, 0).rawId());
217 masks_geom.push_back(tkTopo.pxfDetId(0, 0, 0, 0,
max).rawId());
219 return (masks_geom.size() == masks_db.size() &&
220 std::equal(masks_geom.begin(), masks_geom.end(), masks_db.begin()));
228 class SiPixelDynamicInefficiencyTest :
public Histogram1D<SiPixelDynamicInefficiency, SINGLE_IOV> {
230 SiPixelDynamicInefficiencyTest()
232 "SiPixelDynamicInefficiency test",
"SiPixelDynamicInefficiency test", 1, 0.0, 1.0) {}
234 bool fill()
override {
235 auto tag = PlotBase::getTag<0>();
236 for (
auto const& iov :
tag.iovs) {
237 std::shared_ptr<SiPixelDynamicInefficiency>
payload = Base::fetchPayload(std::get<1>(iov));
241 std::map<unsigned int, double> map_pixelgeomfactor =
payload->getPixelGeomFactors();
242 std::map<unsigned int, double> map_colgeomfactor =
payload->getColGeomFactors();
243 std::map<unsigned int, double> map_chipgeomfactor =
payload->getChipGeomFactors();
244 std::map<unsigned int, std::vector<double> > map_pufactor =
payload->getPUFactors();
245 std::vector<uint32_t> detIdmasks_db =
payload->getDetIdmasks();
246 double theInstLumiScaleFactor_db =
payload->gettheInstLumiScaleFactor_();
248 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
"-------------------------------------------------------";
249 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
"Printing out DB content:\n";
251 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" PixelGeomFactors:";
252 for (
auto pixel : map_pixelgeomfactor)
254 <<
" MapID = " <<
pixel.first <<
"\tFactor = " <<
pixel.second;
257 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" ColGeomFactors:";
258 for (
auto col : map_colgeomfactor)
260 <<
" MapID = " <<
col.first <<
"\tFactor = " <<
col.second;
263 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" ChipGeomFactors:";
264 for (
auto chip : map_chipgeomfactor)
266 <<
" MapID = " << chip.first <<
"\tFactor = " << chip.second;
269 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" PUFactors:";
270 for (
auto pu : map_pufactor) {
272 <<
" MapID = " <<
pu.first <<
"\t Factor" << (
pu.second.size() > 1 ?
"s" :
"") <<
" = ";
273 for (
size_t i = 0,
n =
pu.second.size();
i <
n; ++
i)
274 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
pu.second[
i] << ((
i ==
n - 1) ?
"\n" :
", ");
278 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" DetIdmasks:";
279 for (
auto mask : detIdmasks_db)
283 edm::LogPrint(
"SiPixelDynamicInefficiencyTest") <<
" theInstLumiScaleFactor = " << theInstLumiScaleFactor_db;
294 template <SiPixelPI::DetType myType>
295 class SiPixelIneffROCfromDynIneffMap :
public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
297 SiPixelIneffROCfromDynIneffMap()
302 bool fill()
override {
303 auto tag = PlotBase::getTag<0>();
304 auto iov =
tag.iovs.front();
306 std::shared_ptr<SiPixelDynamicInefficiency>
payload = fetchPayload(std::get<1>(iov));
308 const auto fr = SiPixDynIneff::pbrf(
payload);
310 if (SiPixDynIneff::isPhase0(fr)) {
312 <<
"SiPixelIneffROCfromDynIneff maps are not supported for non-Phase1 Pixel geometries !";
313 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
322 for (
const auto& element : fr) {
323 auto rawid = element.first;
325 auto packedinfo = element.second;
326 auto badRocs = packedinfo.badRocNumber;
327 auto badRocsF = packedinfo.badRocFrac;
329 for (
size_t i = 0;
i < badRocs.size();
i++) {
330 std::bitset<16> rocToMark;
331 rocToMark.set(badRocs[
i]);
335 theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[
i] * 100.
f);
340 gStyle->SetOptStat(0);
342 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
351 const auto headerText = fmt::sprintf(
"#color[4]{%s}, IOV: #color[4]{%s}",
tagname, IOVstring);
355 theMap.drawBarrelMaps(
canvas, headerText);
358 theMap.drawForwardMaps(
canvas, headerText);
361 theMap.drawMaps(
canvas, headerText);
364 throw cms::Exception(
"SiPixelIneffROCfromDynIneffMap") <<
"\nERROR: unrecognized Pixel Detector part ";
370 canvas.SaveAs(
"outAll.root");
377 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
381 using SiPixelBPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_barrel>;
382 using SiPixelFPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_forward>;
383 using SiPixelFullIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_all>;
388 template <SiPixelPI::DetType myType, IOVMultiplicity nIOVs,
int ntags>
389 class SiPixelIneffROCComparisonBase :
public PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags> {
391 SiPixelIneffROCComparisonBase()
393 Form(
"SiPixelDynamicInefficiency %s Pixel Map",
SiPixelPI::
DetNames[myType].c_str())),
397 bool fill()
override {
399 auto theIOVs = PlotBase::getTag<0>().iovs;
400 auto f_tagname = PlotBase::getTag<0>().
name;
402 auto firstiov = theIOVs.front();
403 std::tuple<cond::Time_t, cond::Hash> lastiov;
406 assert(this->m_plotAnnotations.ntags < 3);
408 if (this->m_plotAnnotations.ntags == 2) {
409 auto tag2iovs = PlotBase::getTag<1>().iovs;
410 l_tagname = PlotBase::getTag<1>().
name;
411 lastiov = tag2iovs.front();
413 lastiov = theIOVs.back();
416 std::shared_ptr<SiPixelDynamicInefficiency> last_payload = this->fetchPayload(std::get<1>(lastiov));
417 std::shared_ptr<SiPixelDynamicInefficiency> first_payload = this->fetchPayload(std::get<1>(firstiov));
419 const auto fp = SiPixDynIneff::pbrf(last_payload);
420 const auto lp = SiPixDynIneff::pbrf(first_payload);
422 if (SiPixDynIneff::isPhase0(
fp) || SiPixDynIneff::isPhase0(lp)) {
424 <<
"SiPixelDynamicInefficiency comparison maps are not supported for non-Phase1 Pixel geometries !";
425 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
434 gStyle->SetOptStat(0);
436 TCanvas
canvas(
"Summary",
"Summary", 1200, k_height[myType]);
452 if (this->m_plotAnnotations.ntags == 2) {
454 fmt::sprintf(
"#color[2]{A: %s, %s} - #color[4]{B: %s, %s}", f_tagname, f_IOVstring, l_tagname, l_IOVstring);
456 headerText = fmt::sprintf(
"%s,IOV #color[2]{A: %s} - #color[4]{B: %s} ", f_tagname, f_IOVstring, l_IOVstring);
461 theMap.drawBarrelMaps(
canvas, headerText);
464 theMap.drawForwardMaps(
canvas, headerText);
467 theMap.drawMaps(
canvas, headerText);
471 <<
"\nERROR: unrecognized Pixel Detector part ";
475 fillTheMapFromPayload(theMap,
fp,
false);
478 fillTheMapFromPayload(theMap, lp,
true);
483 canvas.SaveAs(
"outAll.root");
490 static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
495 for (
const auto& element : fr) {
496 auto rawid = element.first;
498 auto packedinfo = element.second;
499 auto badRocs = packedinfo.badRocNumber;
500 auto badRocsF = packedinfo.badRocFrac;
502 for (
size_t i = 0;
i < badRocs.size();
i++) {
503 std::bitset<16> rocToMark;
504 rocToMark.set(badRocs[
i]);
520 using SiPixelBPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, MULTI_IOV, 1>;
521 using SiPixelFPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, MULTI_IOV, 1>;
522 using SiPixelFullIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, MULTI_IOV, 1>;
524 using SiPixelBPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, SINGLE_IOV, 2>;
525 using SiPixelFPixIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, SINGLE_IOV, 2>;
526 using SiPixelFullIneffROCsMapCompareTwoTags = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, SINGLE_IOV, 2>;
531 template <SiPixDynIneff::factor theFactor>
532 class SiPixelDynamicInefficiencyFullPixelMap :
public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
534 SiPixelDynamicInefficiencyFullPixelMap()
536 label_ =
"SiPixelDynamicInefficiencyFullPixelMap";
537 payloadString = fmt::sprintf(
"%s Dynamic Inefficiency", SiPixDynIneff::factorString[theFactor]);
540 bool fill()
override {
541 gStyle->SetPalette(1);
542 auto tag = PlotBase::getTag<0>();
543 auto iov =
tag.iovs.front();
544 std::shared_ptr<SiPixelDynamicInefficiency>
payload = this->fetchPayload(std::get<1>(iov));
547 Phase1PixelSummaryMap fullMap(
"", fmt::sprintf(
"%s", payloadString), fmt::sprintf(
"%s", payloadString));
548 fullMap.createTrackerBaseMap();
550 SiPixDynIneff::FactorMap theMap{};
553 theMap =
payload->getPixelGeomFactors();
555 case SiPixDynIneff::colgeom:
556 theMap =
payload->getColGeomFactors();
558 case SiPixDynIneff::chipgeom:
559 theMap =
payload->getChipGeomFactors();
562 throw cms::Exception(label_) <<
"\nERROR: unrecognized type of geometry factor ";
565 std::vector<uint32_t> detIdmasks_db =
payload->getDetIdmasks();
568 edm::LogError(label_) << label_ <<
" maps are not supported for non-Phase1 Pixel geometries !";
569 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
578 const auto& p1detIds =
reader.getAllDetIds();
579 for (
const auto& det : p1detIds) {
580 const auto&
value = SiPixDynIneff::getMatchingGeomFactor(det, theMap, detIdmasks_db);
581 fullMap.fillTrackerMap(det,
value);
584 const auto&
range = fullMap.getZAxisRange();
588 fullMap.setZAxisRange(
range.first - 0.01,
range.second + 0.01);
591 TCanvas
canvas(
"Canv",
"Canv", 3000, 2000);
592 fullMap.printTrackerMap(
canvas);
596 ltx.SetTextSize(0.025);
597 ltx.SetTextAlign(11);
599 gPad->GetLeftMargin() + 0.01,
600 gPad->GetBottomMargin() + 0.01,
601 (
"#color[4]{" +
tag.name +
"}, IOV: #color[4]{" +
std::to_string(std::get<0>(iov)) +
"}").c_str());
614 using SiPixelDynamicInefficiencyGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::geom>;
615 using SiPixelDynamicInefficiencyColGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::colgeom>;
616 using SiPixelDynamicInefficiencyChipGeomFactorMap = SiPixelDynamicInefficiencyFullPixelMap<SiPixDynIneff::chipgeom>;
621 class SiPixelDynamicInefficiencyPUPixelMaps :
public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
623 SiPixelDynamicInefficiencyPUPixelMaps()
625 label_ =
"SiPixelDynamicInefficiencyFullPixelMap";
626 payloadString = fmt::sprintf(
"%s Dynamic Inefficiency", SiPixDynIneff::factorString[
SiPixDynIneff::pu]);
629 bool fill()
override {
630 gStyle->SetPalette(1);
631 auto tag = PlotBase::getTag<0>();
632 auto iov =
tag.iovs.front();
633 std::shared_ptr<SiPixelDynamicInefficiency>
payload = this->fetchPayload(std::get<1>(iov));
636 std::vector<Phase1PixelSummaryMap> maps;
638 SiPixDynIneff::PUFactorMap theMap =
payload->getPUFactors();
639 std::vector<uint32_t> detIdmasks_db =
payload->getDetIdmasks();
642 edm::LogError(label_) << label_ <<
" maps are not supported for non-Phase1 Pixel geometries !";
643 TCanvas
canvas(
"Canv",
"Canv", 1200, 1000);
650 unsigned int depth = maxDepthOfPUArray(theMap);
653 for (
unsigned int i = 0;
i <
depth;
i++) {
655 "", fmt::sprintf(
"%s, factor %i", payloadString,
i), fmt::sprintf(
"%s, factor %i", payloadString,
i));
656 maps[
i].createTrackerBaseMap();
662 const auto& p1detIds =
reader.getAllDetIds();
665 for (
const auto& det : p1detIds) {
666 const auto&
values = SiPixDynIneff::getMatchingPUFactors(det, theMap, detIdmasks_db);
676 for (
unsigned int i = 0;
i <
depth;
i++) {
677 const auto&
range = maps[
i].getZAxisRange();
679 maps[
i].setZAxisRange(
range.first - 0.01,
range.second + 0.01);
684 auto sides = getClosestFactors(
depth);
685 TCanvas
canvas(
"Canv",
"Canv", sides.second * 900, sides.first * 600);
686 canvas.Divide(sides.second, sides.first);
689 for (
unsigned int i = 0;
i <
depth;
i++) {
690 maps[
i].printTrackerMap(
canvas, 0.035,
i + 1);
693 ltx.SetTextSize(0.025);
694 ltx.SetTextAlign(11);
696 gPad->GetLeftMargin() + 0.01,
697 gPad->GetBottomMargin() + 0.01,
698 (
"#color[4]{" +
tag.name +
"}, IOV: #color[4]{" +
std::to_string(std::get<0>(iov)) +
"}").c_str());
712 unsigned int maxDepthOfPUArray(
const std::map<
unsigned int, std::vector<double> >& map_pufactor) {
713 unsigned int size{0};
714 for (
const auto& [
id, vec] : map_pufactor) {
715 if (vec.size() >
size)
721 std::pair<int, int> getClosestFactors(
int input) {
727 while (
input % testNum != 0) {
730 return std::make_pair(testNum,
input / testNum);
std::string to_string(const V &value)
static constexpr char const *const kPh1DefaultFile
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
constexpr Detector det() const
get the detector field from this detid
bool equal(const T &first, const T &second)
static std::string const input
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
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
const std::array< std::string, 3 > DetNames
constexpr uint32_t rawId() const
get the raw id
void displayNotSupported(TCanvas &canv, const unsigned int size)
void fillSelectedRocs(const uint32_t &detid, const std::bitset< 16 > &theROCs, double value)
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
static unsigned int const shift
static constexpr char const *const kPh0DefaultFile