CMS 3D CMS Logo

SiPixelFEDChannelContainer_PayloadInspector.cc
Go to the documentation of this file.
1 
11 
19 
28 
29 // the data format of the condition to be inspected
35 
36 #include <memory>
37 #include <sstream>
38 #include <iostream>
39 #include <fmt/printf.h>
40 
41 // include ROOT
42 #include "TH2F.h"
43 #include "TLegend.h"
44 #include "TCanvas.h"
45 #include "TLine.h"
46 #include "TGraph.h"
47 #include "TGaxis.h"
48 #include "TStyle.h"
49 #include "TLatex.h"
50 #include "TPave.h"
51 #include "TPaveStats.h"
52 
53 namespace {
54 
55  using namespace cond::payloadInspector;
56 
57  /************************************************
58  1d histogram of SiPixelFEDChannelContainer of 1 IOV
59  *************************************************/
60 
61  class SiPixelFEDChannelContainerTest : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
62  public:
63  SiPixelFEDChannelContainerTest()
64  : PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV>("SiPixelFEDChannelContainer scenarios count"),
66  edm::FileInPath("Geometry/TrackerCommonData/data/PhaseI/trackerParameters.xml").fullPath())} {
67  // for inputs
68  PlotBase::addInputParam("Scenarios");
69 
70  // hardcoded connection to the MC cabling tag, though luck
71  m_condDbCabling = "frontier://FrontierProd/CMS_CONDITIONS";
72  m_CablingTagName = "SiPixelFedCablingMap_phase1_v7";
73 
74  m_connectionPool.setParameters(m_connectionPset);
75  m_connectionPool.configure();
76  }
77 
78  bool fill() override {
79  std::vector<std::string> the_scenarios = {};
80 
81  auto paramValues = PlotBase::inputParamValues();
82  auto ip = paramValues.find("Scenarios");
83  if (ip != paramValues.end()) {
84  auto input = boost::lexical_cast<std::string>(ip->second);
85  typedef boost::tokenizer<boost::char_separator<char>> tokenizer;
86  boost::char_separator<char> sep{","};
87  tokenizer tok{input, sep};
88  for (const auto& t : tok) {
89  the_scenarios.push_back(t);
90  }
91  } else {
92  edm::LogWarning("SiPixelFEDChannelContainerTest")
93  << "\n WARNING!!!! \n The needed parameter Scenarios has not been passed. Will use all the scenarios in "
94  "the file!"
95  << "\n Buckle your seatbelts... this might take a while... \n\n";
96  the_scenarios.push_back("all");
97  }
98 
99  Phase1PixelROCMaps theROCMap("");
100 
101  auto tag = PlotBase::getTag<0>();
102  auto iov = tag.iovs.front();
103 
104  // open db session for the cabling map
105  edm::LogPrint("SiPixelFEDChannelContainerTest") << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
106  << "Query the condition database " << m_condDbCabling;
107 
108  cond::persistency::Session condDbSession = m_connectionPool.createSession(m_condDbCabling);
109  condDbSession.transaction().start(true);
110 
111  // query the database
112  edm::LogPrint("SiPixelFEDChannelContainerTest") << "[SiPixelFEDChannelContainerTest::" << __func__ << "] "
113  << "Reading IOVs from tag " << m_CablingTagName;
114 
117 
118  // get the list of payloads for the Cabling Map
119  std::vector<std::tuple<cond::Time_t, cond::Hash>> m_cabling_iovs;
120  condDbSession.readIov(m_CablingTagName).selectRange(MIN_VAL, MAX_VAL, m_cabling_iovs);
121 
122  std::vector<unsigned int> listOfCablingIOVs;
123  std::transform(m_cabling_iovs.begin(),
124  m_cabling_iovs.end(),
125  std::back_inserter(listOfCablingIOVs),
126  [](std::tuple<cond::Time_t, cond::Hash> myIOV2) -> unsigned int { return std::get<0>(myIOV2); });
127 
128  edm::LogPrint("SiPixelFEDChannelContainerTest")
129  << " Number of SiPixelFedCablngMap payloads: " << listOfCablingIOVs.size() << std::endl;
130 
131  auto it = std::find(
132  listOfCablingIOVs.begin(), listOfCablingIOVs.end(), closest_from_below(listOfCablingIOVs, std::get<0>(iov)));
133  int index = std::distance(listOfCablingIOVs.begin(), it);
134 
135  edm::LogPrint("SiPixelFEDChannelContainerTest")
136  << " using the SiPixelFedCablingMap with hash: " << std::get<1>(m_cabling_iovs.at(index)) << std::endl;
137 
138  auto theCablingMap = condDbSession.fetchPayload<SiPixelFedCablingMap>(std::get<1>(m_cabling_iovs.at(index)));
139  theCablingMap->initializeRocs();
140  // auto theCablingTree = (*theCablingMap).cablingTree();
141 
142  //auto map = theCablingMap->det2fedMap();
143  //for (const auto &element : map){
144  // std::cout << element.first << " " << element.second << std::endl;
145  //}
146 
147  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
148  const auto& scenarioMap = payload->getScenarioMap();
149 
150  auto pIndexConverter = PixelIndices(numColumns, numRows);
151 
152  for (const auto& scenario : scenarioMap) {
153  std::string scenName = scenario.first;
154 
155  if (std::find_if(the_scenarios.begin(), the_scenarios.end(), compareKeys(scenName)) != the_scenarios.end() ||
156  the_scenarios[0] == "all") {
157  edm::LogPrint("SiPixelFEDChannelContainerTest") << "\t Found Scenario: " << scenName << " ==> dumping it";
158  } else {
159  continue;
160  }
161 
162  //if (strcmp(scenName.c_str(),"320824_103") != 0) continue;
163 
164  const auto& theDetSetBadPixelFedChannels = payload->getDetSetBadPixelFedChannels(scenName);
165  for (const auto& disabledChannels : *theDetSetBadPixelFedChannels) {
166  const auto t_detid = disabledChannels.detId();
167  int subid = DetId(t_detid).subdetId();
168  LogDebug("SiPixelFEDChannelContainerTest") << fmt::sprintf("DetId : %i \n", t_detid) << std::endl;
169 
170  std::bitset<16> badRocsFromFEDChannels;
171 
172  for (const auto& ch : disabledChannels) {
173  std::string toOut_ = fmt::sprintf("fed : %i | link : %2i | roc_first : %2i | roc_last: %2i \n",
174  ch.fed,
175  ch.link,
176  ch.roc_first,
177  ch.roc_last);
178 
179  LogDebug("SiPixelFEDChannelContainerTest") << toOut_ << std::endl;
180  const std::vector<sipixelobjects::CablingPathToDetUnit>& path =
181  theCablingMap->pathToDetUnit(disabledChannels.detId());
182  for (unsigned int i_roc = ch.roc_first; i_roc <= ch.roc_last; ++i_roc) {
183  for (const auto p : path) {
184  const sipixelobjects::PixelROC* myroc = theCablingMap->findItem(p);
185  if (myroc->idInDetUnit() == static_cast<unsigned int>(i_roc)) {
186  sipixelobjects::LocalPixel::RocRowCol local = {39, 25}; //corresponding to center of ROC row,col
188  int chipIndex(0), colROC(0), rowROC(0);
189 
190  pIndexConverter.transformToROC(global.col, global.row, chipIndex, colROC, rowROC);
191 
192  LogDebug("SiPixelFEDChannelContainerTest")
193  << " => i_roc:" << i_roc << " " << global.col << "-" << global.row << " | => " << chipIndex
194  << " : (" << colROC << "," << rowROC << ")" << std::endl;
195 
196  badRocsFromFEDChannels[chipIndex] = true;
197  }
198  }
199  }
200  }
201 
202  LogDebug("SiPixelFEDChannelContainerTest") << badRocsFromFEDChannels << std::endl;
203 
204  auto myDetId = DetId(t_detid);
205 
206  if (subid == PixelSubdetector::PixelBarrel) {
207  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
208  } // if it's barrel
209  else if (subid == PixelSubdetector::PixelEndcap) {
210  theROCMap.fillSelectedRocs(myDetId, badRocsFromFEDChannels, 1.);
211  } // if it's endcap
212  else {
213  throw cms::Exception("LogicError") << "Unknown Pixel SubDet ID " << std::endl;
214  } // else nonsense
215  } // loop on the channels
216  } // loop on the scenarios
217 
218  gStyle->SetOptStat(0);
219  //=========================
220  TCanvas canvas("Summary", "Summary", 1200, 1600);
221  theROCMap.drawMaps(canvas);
222 
223  auto unpacked = SiPixelPI::unpack(std::get<0>(iov));
224 
225  for (unsigned int lay = 1; lay <= n_layers; lay++) {
226  canvas.cd(lay);
227  auto ltx = TLatex();
228  ltx.SetTextFont(62);
229  ltx.SetTextColor(kBlue);
230  ltx.SetTextSize(0.055);
231  ltx.SetTextAlign(11);
232  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
233  1 - gPad->GetTopMargin() + 0.01,
234  unpacked.first == 0
235  ? ("IOV:" + std::to_string(unpacked.second)).c_str()
236  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second)).c_str());
237  }
238 
239  for (unsigned int ring = 1; ring <= n_rings; ring++) {
240  canvas.cd(n_layers + ring);
241  auto ltx = TLatex();
242  ltx.SetTextFont(62);
243  ltx.SetTextColor(kBlue);
244  ltx.SetTextSize(0.050);
245  ltx.SetTextAlign(11);
246  ltx.DrawLatexNDC(gPad->GetLeftMargin(),
247  1 - gPad->GetTopMargin() + 0.01,
248  unpacked.first == 0
249  ? ("IOV:" + std::to_string(unpacked.second)).c_str()
250  : (std::to_string(unpacked.first) + "," + std::to_string(unpacked.second)).c_str());
251  }
252 
253  std::string fileName(m_imageFileName);
254  canvas.SaveAs(fileName.c_str());
255 
256  // close the DB session
257  condDbSession.transaction().commit();
258 
259  return true;
260  }
261 
262  public:
263  inline unsigned int closest_from_above(std::vector<unsigned int> const& vec, unsigned int value) {
264  auto const it = std::lower_bound(vec.begin(), vec.end(), value);
265  return vec.at(it - vec.begin() - 1);
266  }
267 
268  inline unsigned int closest_from_below(std::vector<unsigned int> const& vec, unsigned int value) {
269  auto const it = std::upper_bound(vec.begin(), vec.end(), value);
270  return vec.at(it - vec.begin() - 1);
271  }
272 
273  // auxilliary check
274  struct compareKeys {
276  compareKeys(std::string const& i) : key(i) {}
277 
278  bool operator()(std::string const& i) { return (key == i); }
279  };
280 
281  private:
282  // tough luck, we can only do phase-1...
283  static constexpr int numColumns = 416;
284  static constexpr int numRows = 160;
285  static constexpr int n_rings = 2;
286  static constexpr int n_layers = 4;
287 
288  TrackerTopology m_trackerTopo;
289  edm::ParameterSet m_connectionPset;
290  cond::persistency::ConnectionPool m_connectionPool;
291  std::string m_CablingTagName;
292  std::string m_condDbCabling;
293  };
294 
295  /************************************************
296  1d histogram of SiPixelFEDChannelContainer of 1 IOV
297  *************************************************/
298 
299  class SiPixelFEDChannelContainerScenarios : public PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV> {
300  public:
301  SiPixelFEDChannelContainerScenarios()
302  : PlotImage<SiPixelFEDChannelContainer, SINGLE_IOV>("SiPixelFEDChannelContainer scenarios count") {}
303  bool fill() override {
304  auto tag = PlotBase::getTag<0>();
305  auto tagname = tag.name;
306  auto iov = tag.iovs.front();
307 
308  TGaxis::SetMaxDigits(3);
309 
310  std::shared_ptr<SiPixelFEDChannelContainer> payload = fetchPayload(std::get<1>(iov));
311  std::vector<std::string> scenarios = payload->getScenarioList();
312  sort(scenarios.begin(), scenarios.end());
313 
314  TCanvas canvas("Canv", "Canv", 1200, 1000);
315  canvas.cd();
316  canvas.SetGrid();
317  auto h1 = std::make_unique<TH1F>("Count",
318  "SiPixelFEDChannelContainer Bad Roc count;Scenario index;n. of bad ROCs",
319  scenarios.size(),
320  1,
321  scenarios.size());
322  h1->SetStats(false);
323 
324  canvas.SetTopMargin(0.06);
325  canvas.SetBottomMargin(0.12);
326  canvas.SetLeftMargin(0.12);
327  canvas.SetRightMargin(0.05);
328  canvas.Modified();
329 
330  int scenarioIndex = 0;
331  for (const auto& scenario : scenarios) {
332  scenarioIndex++;
333  int badRocCount = 0;
334  LogDebug("SiPixelFEDChannelContainerScenarios") << scenario << std::endl;
335  auto badChannelCollection = payload->getDetSetBadPixelFedChannels(scenario);
336  for (const auto& disabledChannels : *badChannelCollection) {
337  for (const auto& ch : disabledChannels) {
338  int local_bad_rocs = ch.roc_last - ch.roc_first;
339  badRocCount += local_bad_rocs;
340  } // loop on the channels
341  } // loop on the DetSetVector
342 
343  h1->SetBinContent(scenarioIndex, badRocCount);
344  } // loop on scenarios
345 
346  TGaxis::SetExponentOffset(-0.1, 0.01, "y"); // Y offset
347  TGaxis::SetExponentOffset(-0.03, -0.10, "x"); // Y and Y offset for X axis
348 
349  h1->SetTitle("");
350  h1->GetYaxis()->SetRangeUser(0., h1->GetMaximum() * 1.30);
351  h1->SetFillColor(kRed);
352  h1->SetMarkerStyle(20);
353  h1->SetMarkerSize(1);
354  h1->Draw("bar2");
355 
357 
358  canvas.Update();
359 
360  TLegend legend = TLegend(0.30, 0.88, 0.95, 0.94);
361  //legend.SetHeader(("#splitline{Payload hash: #bf{" + (std::get<1>(iov)) + "}}{Total Scenarios:"+std::to_string(scenarioIndex)+"}").c_str(),"C"); // option "C" allows to center the header
362 
363  legend.SetHeader(fmt::sprintf("Payload hash: #bf{%s}", std::get<1>(iov)).c_str(), "C");
364  legend.AddEntry(h1.get(), fmt::sprintf("total scenarios: #bf{%s}", std::to_string(scenarioIndex)).c_str(), "F");
365  legend.SetTextSize(0.025);
366  legend.Draw("same");
367 
368  auto ltx = TLatex();
369  ltx.SetTextFont(62);
370  //ltx.SetTextColor(kBlue);
371  //ltx.SetTextAlign(11);
372  ltx.SetTextSize(0.040);
373  ltx.DrawLatexNDC(
374  gPad->GetLeftMargin(),
375  1 - gPad->GetTopMargin() + 0.01,
376  fmt::sprintf("#color[4]{%s} IOV: #color[4]{%s}", tagname, std::to_string(std::get<0>(iov))).c_str());
377 
378  std::string fileName(m_imageFileName);
379  canvas.SaveAs(fileName.c_str());
380 
381  return true;
382 
383  } // fill
384  };
385 
386 } // namespace
387 
388 // Register the classes as boost python plugin
390  PAYLOAD_INSPECTOR_CLASS(SiPixelFEDChannelContainerTest);
391  PAYLOAD_INSPECTOR_CLASS(SiPixelFEDChannelContainerScenarios);
392 }
SiPixelPI::unpack
std::pair< unsigned int, unsigned int > unpack(cond::Time_t since)
Definition: SiPixelPayloadInspectorHelper.h:114
Phase1PixelROCMaps
Definition: Phase1PixelROCMaps.h:80
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
pfDeepBoostedJetPreprocessParams_cfi.upper_bound
upper_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:16
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
mps_fire.i
i
Definition: mps_fire.py:428
ConnectionPool.h
PixelSubdetector.h
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
cond::TimeTypeSpecs::beginValue
Time_t beginValue
Definition: Time.h:41
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
TrackerTopology
Definition: TrackerTopology.h:16
PayloadInspector.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SiPixelFEDChannelContainer
Definition: SiPixelFEDChannelContainer.h:12
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
SiPixelFEDChannelContainer.h
cond::persistency::IOVProxy::selectRange
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:191
SiPixelFedCablingMap.h
cond::payloadInspector::PlotBase::inputParamValues
const std::map< std::string, std::string > & inputParamValues() const
Definition: PayloadInspector.cc:139
sipixelobjects::GlobalPixel::row
int row
Definition: GlobalPixel.h:7
PAYLOAD_INSPECTOR_CLASS
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
Definition: PayloadInspectorModule.h:10
SiPixelFedCablingTree.h
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
sipixelobjects::GlobalPixel::col
int col
Definition: GlobalPixel.h:8
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PayloadInspectorModule.h
sipixelobjects::LocalPixel
identify pixel inside single ROC
Definition: LocalPixel.h:7
FileInPath.h
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
visualization-live-secondInstance_cfg.scenarios
scenarios
Definition: visualization-live-secondInstance_cfg.py:22
cond::timeTypeSpecs
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
sipixelobjects::GlobalPixel
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
StandaloneTrackerTopology.h
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
cond::persistency::ConnectionPool
Definition: ConnectionPool.h:35
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
cmsdt::scenario
scenario
Definition: constants.h:167
SiPixelFedCabling.h
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
SiPixelFrameConverter.h
Time.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
PixelROC.h
CablingPathToDetUnit.h
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
cond::runnumber
Definition: Time.h:19
cond::persistency::Session
Definition: Session.h:63
listHistos.legend
legend
Definition: listHistos.py:41
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
LocalPixel.h
cond::time::MAX_VAL
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
value
Definition: value.py:1
cond::TimeTypeSpecs::endValue
Time_t endValue
Definition: Time.h:42
sipixelobjects::PixelROC::toGlobal
GlobalPixel toGlobal(const LocalPixel &loc) const
Definition: PixelROC.h:55
Phase1PixelROCMaps.h
createPayload.tagname
tagname
Definition: createPayload.py:183
PixelIndices.h
SiPixelFedCablingMap
Definition: SiPixelFedCablingMap.h:19
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
sipixelobjects::PixelROC
Definition: PixelROC.h:23
sipixelobjects::LocalPixel::RocRowCol
row and collumn in ROC representation
Definition: LocalPixel.h:13
DetId.h
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:245
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
cond::payloadInspector::PlotImage
Definition: PayloadInspector.h:894
SiPixelPI::makeNicePlotStyle
void makeNicePlotStyle(TH1 *hist)
Definition: SiPixelPayloadInspectorHelper.h:548
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
SiPixelPayloadInspectorHelper.h
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
DTRecHitClients_cfi.local
local
Definition: DTRecHitClients_cfi.py:10
ParameterSet.h
cond::payloadInspector::PlotBase::addInputParam
void addInputParam(const std::string &paramName)
Definition: PayloadInspector.cc:35
cond::payloadInspector::SINGLE_IOV
Definition: PayloadInspector.h:295
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
crabWrapper.key
key
Definition: crabWrapper.py:19
StandaloneTrackerTopology::fromTrackerParametersXMLFile
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
Definition: StandaloneTrackerTopology.cc:168
sipixelobjects::PixelROC::idInDetUnit
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:37
PixelIndices
Definition: PixelIndices.h:40