CMS 3D CMS Logo

SiPixelDynamicInefficiency_PayloadInspector.cc
Go to the documentation of this file.
1 
10 
18 
19 // the data format of the condition to be inspected
25 
26 #include <memory>
27 #include <sstream>
28 #include <iostream>
29 
30 // include ROOT
31 #include "TH2F.h"
32 #include "TLegend.h"
33 #include "TCanvas.h"
34 #include "TLine.h"
35 #include "TGraph.h"
36 #include "TStyle.h"
37 #include "TLatex.h"
38 #include "TPave.h"
39 #include "TPaveStats.h"
40 
41 namespace {
42 
43  using namespace cond::payloadInspector;
44  namespace SiPixDynIneff {
45 
46  // constants for ROC level simulation for Phase1
47  enum shiftEnumerator { FPixRocIdShift = 3, BPixRocIdShift = 6 };
48  static const int rocIdMaskBits = 0x1F;
49 
50  struct packedBadRocFraction {
51  std::vector<int> badRocNumber;
52  std::vector<float> badRocFrac;
53  };
54 
55  using BRFractions = std::unordered_map<uint32_t, packedBadRocFraction>;
56 
57  //_________________________________________________
58  BRFractions pbrf(std::shared_ptr<SiPixelDynamicInefficiency> payload) {
59  BRFractions f;
60  const std::map<uint32_t, double>& PixelGeomFactorsDBIn = payload->getPixelGeomFactors();
61 
62  // first fill
63  for (const auto db_factor : PixelGeomFactorsDBIn) {
64  int subid = DetId(db_factor.first).subdetId();
65  int shift = (subid == static_cast<int>(PixelSubdetector::PixelBarrel)) ? BPixRocIdShift : FPixRocIdShift;
66  unsigned int rocMask = rocIdMaskBits << shift;
67  unsigned int rocId = (((db_factor.first) & rocMask) >> shift);
68  uint32_t rawid = db_factor.first & (~rocMask);
69 
70  if (f.find(rawid) == f.end()) {
71  packedBadRocFraction p;
72  f.insert(std::make_pair(rawid, p));
73  }
74 
75  if (rocId != 0) {
76  rocId--;
77  double factor = db_factor.second;
78  double badFraction = 1 - factor;
79 
80  f.at(rawid).badRocNumber.emplace_back(rocId);
81  f.at(rawid).badRocFrac.emplace_back(badFraction);
82  }
83  }
84  return f;
85  }
86 
87  //_________________________________________________
88  bool isPhase0(const BRFractions& fractions) {
91  const auto& p0detIds = reader.getAllDetIds();
92  std::vector<uint32_t> ownDetIds;
93 
94  std::transform(fractions.begin(),
95  fractions.end(),
96  std::back_inserter(ownDetIds),
97  [](std::pair<uint32_t, packedBadRocFraction> d) -> uint32_t { return d.first; });
98 
99  for (const auto& det : ownDetIds) {
100  // if found at least one phase-0 detId early return
101  if (std::find(p0detIds.begin(), p0detIds.end(), det) != p0detIds.end()) {
102  return true;
103  }
104  }
105  return false;
106  }
107  } // namespace SiPixDynIneff
108 
109  /************************************************
110  test class
111  *************************************************/
112 
113  class SiPixelDynamicInefficiencyTest : public Histogram1D<SiPixelDynamicInefficiency, SINGLE_IOV> {
114  public:
115  SiPixelDynamicInefficiencyTest()
117  "SiPixelDynamicInefficiency test", "SiPixelDynamicInefficiency test", 1, 0.0, 1.0) {}
118 
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));
123  if (payload.get()) {
124  fillWithValue(1.);
125 
126  const auto geomFactors = payload->getPixelGeomFactors();
127  for (const auto [ID, value] : geomFactors) {
128  std::cout << ID << " : " << value << std::endl;
129  ;
130  }
131  } // payload
132  } // iovs
133  return true;
134  } // fill
135  };
136 
137  /************************************************
138  occupancy style map whole Pixel of inefficient ROCs
139  *************************************************/
140  template <SiPixelPI::DetType myType>
141  class SiPixelIneffROCfromDynIneffMap : public PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV> {
142  public:
143  SiPixelIneffROCfromDynIneffMap()
144  : PlotImage<SiPixelDynamicInefficiency, SINGLE_IOV>("SiPixel Inefficient ROC from Dyn Ineff Pixel Map"),
146  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
147 
148  bool fill() override {
149  auto tag = PlotBase::getTag<0>();
150  auto iov = tag.iovs.front();
151  auto tagname = tag.name;
152  std::shared_ptr<SiPixelDynamicInefficiency> payload = fetchPayload(std::get<1>(iov));
153 
154  const auto fr = SiPixDynIneff::pbrf(payload);
155 
156  if (SiPixDynIneff::isPhase0(fr)) {
157  edm::LogError("SiPixelDynamicInefficiency_PayloadInspector")
158  << "SiPixelIneffROCfromDynIneff maps are not supported for non-Phase1 Pixel geometries !";
159  TCanvas canvas("Canv", "Canv", 1200, 1000);
161  std::string fileName(m_imageFileName);
162  canvas.SaveAs(fileName.c_str());
163  return false;
164  }
165 
166  Phase1PixelROCMaps theMap("", "bad pixel fraction in ROC [%]");
167 
168  for (const auto& element : fr) {
169  auto rawid = element.first;
170  int subid = DetId(rawid).subdetId();
171  auto packedinfo = element.second;
172  auto badRocs = packedinfo.badRocNumber;
173  auto badRocsF = packedinfo.badRocFrac;
174 
175  for (size_t i = 0; i < badRocs.size(); i++) {
176  std::bitset<16> rocToMark;
177  rocToMark.set(badRocs[i]);
178  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
179  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
180  (myType == SiPixelPI::t_all)) {
181  theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[i] * 100.f);
182  }
183  }
184  }
185 
186  gStyle->SetOptStat(0);
187  //=========================
188  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
189  canvas.cd();
190 
191  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
192 
193  std::string IOVstring = (unpacked.first == 0)
194  ? std::to_string(unpacked.second)
195  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second));
196 
197  const auto headerText = fmt::sprintf("#color[4]{%s}, IOV: #color[4]{%s}", tagname, IOVstring);
198 
199  switch (myType) {
200  case SiPixelPI::t_barrel:
201  theMap.drawBarrelMaps(canvas, headerText);
202  break;
204  theMap.drawForwardMaps(canvas, headerText);
205  break;
206  case SiPixelPI::t_all:
207  theMap.drawMaps(canvas, headerText);
208  break;
209  default:
210  throw cms::Exception("SiPixelIneffROCfromDynIneffMap")
211  << "\nERROR: unrecognized Pixel Detector part " << std::endl;
212  }
213 
214  std::string fileName(m_imageFileName);
215  canvas.SaveAs(fileName.c_str());
216 #ifdef MMDEBUG
217  canvas.SaveAs("outAll.root");
218 #endif
219 
220  return true;
221  }
222 
223  private:
224  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
225  TrackerTopology m_trackerTopo;
226  };
227 
228  using SiPixelBPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_barrel>;
229  using SiPixelFPixIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_forward>;
230  using SiPixelFullIneffROCfromDynIneffMap = SiPixelIneffROCfromDynIneffMap<SiPixelPI::t_all>;
231 
232  /************************************************
233  occupancy style map whole Pixel, difference of payloads
234  *************************************************/
235  template <SiPixelPI::DetType myType, IOVMultiplicity nIOVs, int ntags>
236  class SiPixelIneffROCComparisonBase : public PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags> {
237  public:
238  SiPixelIneffROCComparisonBase()
239  : PlotImage<SiPixelDynamicInefficiency, nIOVs, ntags>(
240  Form("SiPixelDynamicInefficiency %s Pixel Map", SiPixelPI::DetNames[myType].c_str())),
242  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {}
243 
244  bool fill() override {
245  // trick to deal with the multi-ioved tag and two tag case at the same time
246  auto theIOVs = PlotBase::getTag<0>().iovs;
247  auto f_tagname = PlotBase::getTag<0>().name;
248  std::string l_tagname = "";
249  auto firstiov = theIOVs.front();
250  std::tuple<cond::Time_t, cond::Hash> lastiov;
251 
252  // we don't support (yet) comparison with more than 2 tags
253  assert(this->m_plotAnnotations.ntags < 3);
254 
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();
259  } else {
260  lastiov = theIOVs.back();
261  }
262 
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));
265 
266  const auto fp = SiPixDynIneff::pbrf(last_payload);
267  const auto lp = SiPixDynIneff::pbrf(first_payload);
268 
269  if (SiPixDynIneff::isPhase0(fp) || SiPixDynIneff::isPhase0(lp)) {
270  edm::LogError("SiPixelDynamicInefficiency_PayloadInspector")
271  << "SiPixelDynamicInefficiency comparison maps are not supported for non-Phase1 Pixel geometries !";
272  TCanvas canvas("Canv", "Canv", 1200, 1000);
274  std::string fileName(this->m_imageFileName);
275  canvas.SaveAs(fileName.c_str());
276  return false;
277  }
278 
279  Phase1PixelROCMaps theMap("", "#Delta payload A - payload B");
280 
281  gStyle->SetOptStat(0);
282  //=========================
283  TCanvas canvas("Summary", "Summary", 1200, k_height[myType]);
284  canvas.cd();
285 
286  auto f_unpacked = SiPixelPI::unpack(std::get<0>(firstiov));
287  auto l_unpacked = SiPixelPI::unpack(std::get<0>(lastiov));
288 
289  std::string f_IOVstring = (f_unpacked.first == 0)
290  ? std::to_string(f_unpacked.second)
291  : (std::to_string(f_unpacked.first) + "," + std::to_string(f_unpacked.second));
292 
293  std::string l_IOVstring = (l_unpacked.first == 0)
294  ? std::to_string(l_unpacked.second)
295  : (std::to_string(l_unpacked.first) + "," + std::to_string(l_unpacked.second));
296 
297  std::string headerText;
298 
299  if (this->m_plotAnnotations.ntags == 2) {
300  headerText =
301  fmt::sprintf("#color[2]{A: %s, %s} - #color[4]{B: %s, %s}", f_tagname, f_IOVstring, l_tagname, l_IOVstring);
302  } else {
303  headerText = fmt::sprintf("%s,IOV #color[2]{A: %s} - #color[4]{B: %s} ", f_tagname, f_IOVstring, l_IOVstring);
304  }
305 
306  switch (myType) {
307  case SiPixelPI::t_barrel:
308  theMap.drawBarrelMaps(canvas, headerText);
309  break;
311  theMap.drawForwardMaps(canvas, headerText);
312  break;
313  case SiPixelPI::t_all:
314  theMap.drawMaps(canvas, headerText);
315  break;
316  default:
317  throw cms::Exception("SiPixelDynamicInefficiencyMapComparison")
318  << "\nERROR: unrecognized Pixel Detector part " << std::endl;
319  }
320 
321  // first loop on the first payload (newest)
322  fillTheMapFromPayload(theMap, fp, false);
323 
324  // then loop on the second payload (oldest)
325  fillTheMapFromPayload(theMap, lp, true); // true will subtract
326 
327  std::string fileName(this->m_imageFileName);
328  canvas.SaveAs(fileName.c_str());
329 #ifdef MMDEBUG
330  canvas.SaveAs("outAll.root");
331 #endif
332 
333  return true;
334  }
335 
336  private:
337  static constexpr std::array<int, 3> k_height = {{1200, 600, 1600}};
338  TrackerTopology m_trackerTopo;
339 
340  //____________________________________________________________________________________________
341  void fillTheMapFromPayload(Phase1PixelROCMaps& theMap, const SiPixDynIneff::BRFractions& fr, bool subtract) {
342  for (const auto& element : fr) {
343  auto rawid = element.first;
344  int subid = DetId(rawid).subdetId();
345  auto packedinfo = element.second;
346  auto badRocs = packedinfo.badRocNumber;
347  auto badRocsF = packedinfo.badRocFrac;
348 
349  for (size_t i = 0; i < badRocs.size(); i++) {
350  std::bitset<16> rocToMark;
351  rocToMark.set(badRocs[i]);
352  if ((subid == PixelSubdetector::PixelBarrel && myType == SiPixelPI::t_barrel) ||
353  (subid == PixelSubdetector::PixelEndcap && myType == SiPixelPI::t_forward) ||
354  (myType == SiPixelPI::t_all)) {
355  theMap.fillSelectedRocs(rawid, rocToMark, badRocsF[i] * (subtract ? -1. : 1.));
356  }
357  }
358  }
359  }
360  };
361 
362  /*
363  using SiPixelBPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_barrel, MULTI_IOV, 1>;
364  using SiPixelFPixIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_forward, MULTI_IOV, 1>;
365  using SiPixelFullIneffROCsMapCompareSingleTag = SiPixelIneffROCComparisonBase<SiPixelPI::t_all, MULTI_IOV, 1>;
366  */
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>;
370 
371 } // namespace
372 
373 // Register the classes as boost python plugin
375  PAYLOAD_INSPECTOR_CLASS(SiPixelDynamicInefficiencyTest);
376  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixIneffROCfromDynIneffMap);
377  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixIneffROCfromDynIneffMap);
378  PAYLOAD_INSPECTOR_CLASS(SiPixelFullIneffROCfromDynIneffMap);
379  PAYLOAD_INSPECTOR_CLASS(SiPixelBPixIneffROCsMapCompareTwoTags);
380  PAYLOAD_INSPECTOR_CLASS(SiPixelFPixIneffROCsMapCompareTwoTags);
381  PAYLOAD_INSPECTOR_CLASS(SiPixelFullIneffROCsMapCompareTwoTags);
382 }
SiPixelPI::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: SiPixelPayloadInspectorHelper.h:114
Phase1PixelROCMaps
Definition: Phase1PixelROCMaps.h:81
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelPI::t_barrel
Definition: SiPixelPayloadInspectorHelper.h:574
PixelSubdetector.h
MessageLogger.h
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
cond::payloadInspector::Histogram1
Definition: PayloadInspector.h:711
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
SiPixelPI
Definition: SiPixelPayloadInspectorHelper.h:37
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
TrackerTopology
Definition: TrackerTopology.h:16
PayloadInspector.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SiPixelPI::t_all
Definition: SiPixelPayloadInspectorHelper.h:574
cms::cuda::assert
assert(be >=bs)
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
personalPlayback.fp
fp
Definition: personalPlayback.py:523
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
SiPixelPI::displayNotSupported
void displayNotSupported(TCanvas &canv, const unsigned int size)
Definition: SiPixelPayloadInspectorHelper.h:782
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
SiPixelDetInfoFileReader::kPh0DefaultFile
constexpr static char const *const kPh0DefaultFile
Definition: SiPixelDetInfoFileReader.h:36
PayloadInspectorModule.h
SiPixelDynamicInefficiency
Definition: SiPixelDynamicInefficiency.h:11
DetId
Definition: DetId.h:17
SiPixelDetInfoFileReader
Definition: SiPixelDetInfoFileReader.h:28
edm::FileInPath
Definition: FileInPath.h:61
StandaloneTrackerTopology.h
DQM.reader
reader
Definition: DQM.py:105
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
jets_cff.payload
payload
Definition: jets_cff.py:32
cond::payloadInspector
Definition: PayloadInspector.h:42
electronEcalRecHitIsolationLcone_cfi.subtract
subtract
Definition: electronEcalRecHitIsolationLcone_cfi.py:24
PAYLOAD_INSPECTOR_MODULE
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Definition: PayloadInspectorModule.h:8
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
FileInPath.h
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
Time.h
align::ID
uint32_t ID
Definition: Definitions.h:24
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
Phase1PixelROCMaps::fillSelectedRocs
void fillSelectedRocs(const uint32_t &detid, const std::bitset< 16 > &theROCs, double value)
Definition: Phase1PixelROCMaps.cc:255
value
Definition: value.py:1
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
Phase1PixelROCMaps.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
createPayload.tagname
tagname
Definition: createPayload.py:183
SiPixelDetInfoFileReader.h
SiPixelPI::t_forward
Definition: SiPixelPayloadInspectorHelper.h:574
SiPixelDynamicInefficiency.h
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
shiftEnumerator
shiftEnumerator
Definition: SiPixelDynamicInefficiency_PayloadInspector.cc:47
DetId.h
Exception
Definition: hltDiff.cc:245
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:894
SiPixDynIneff
Definition: SiPixelDynamicInefficiency_PayloadInspector.cc:44
ztail.d
d
Definition: ztail.py:151
SiPixelPayloadInspectorHelper.h
SiPixelPI::DetNames
const std::array< std::string, 3 > DetNames
Definition: SiPixelPayloadInspectorHelper.h:575
cond::payloadInspector::SINGLE_IOV
Definition: PayloadInspector.h:295
StandaloneTrackerTopology::fromTrackerParametersXMLFile
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Definition: StandaloneTrackerTopology.cc:168