CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SiStripHitEfficiencyHarvester.cc
Go to the documentation of this file.
1 // user includes
24 
25 //system includes
26 #include <boost/type_index.hpp>
27 #include <fmt/printf.h>
28 #include <numeric> // for std::accumulate
29 #include <sstream>
30 
31 // ROOT includes
32 #include "TCanvas.h"
33 #include "TEfficiency.h"
34 #include "TGraphAsymmErrors.h"
35 #include "TLegend.h"
36 #include "TStyle.h"
37 #include "TTree.h"
38 
39 // custom made printout
40 #define LOGPRINT edm::LogPrint("SiStripHitEfficiencyHarvester")
41 
43 public:
45  ~SiStripHitEfficiencyHarvester() override = default;
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48  void endRun(edm::Run const&, edm::EventSetup const&) override;
50 
51 private:
54  const bool isAtPCL_;
56  const bool doStoreOnTree_;
58  const unsigned int nTEClayers_;
59  const double threshold_;
60  const int nModsMin_;
61  const float effPlotMin_;
62  const double tkMapMin_;
64 
69 
70  std::unique_ptr<TrackerTopology> tTopo_;
71  std::unique_ptr<TkDetMap> tkDetMap_;
72  std::unique_ptr<SiStripQuality> stripQuality_;
73  std::vector<DetId> stripDetIds_;
74 
75  int goodlayertotal[bounds::k_END_OF_LAYS_AND_RINGS];
76  int goodlayerfound[bounds::k_END_OF_LAYS_AND_RINGS];
77  int alllayertotal[bounds::k_END_OF_LAYS_AND_RINGS];
78  int alllayerfound[bounds::k_END_OF_LAYS_AND_RINGS];
79 
80  // information for the TTree
81  TTree* tree;
82  unsigned int t_DetId, t_found, t_total;
83  unsigned char t_layer;
85  float t_threshold;
86 
87  void writeBadStripPayload(const SiStripQuality& quality) const;
88  void printTotalStatistics(const std::array<long, bounds::k_END_OF_LAYERS>& layerFound,
89  const std::array<long, bounds::k_END_OF_LAYERS>& layerTotal) const;
90  void printAndWriteBadModules(const SiStripQuality& quality, const SiStripDetInfo& detInfo) const;
91  bool checkMapsValidity(const std::vector<MonitorElement*>& maps, const std::string& type) const;
92  unsigned int countTotalHits(const std::vector<MonitorElement*>& maps); /* to check if TK was ON */
93  void makeSummary(DQMStore::IGetter& getter, DQMStore::IBooker& booker, bool doProfiles = false) const;
94  template <typename T>
95  void setEffBinLabels(const T gr, const T gr2, const unsigned int nLayers) const;
96  void makeSummaryVsVariable(DQMStore::IGetter& getter, DQMStore::IBooker& booker, ::projections theProj) const;
97 };
98 
100  : inputFolder_(conf.getParameter<std::string>("inputFolder")),
101  isAtPCL_(conf.getParameter<bool>("isAtPCL")),
102  autoIneffModTagging_(conf.getUntrackedParameter<bool>("AutoIneffModTagging", false)),
103  doStoreOnDB_(conf.getParameter<bool>("doStoreOnDB")),
104  doStoreOnTree_(conf.getUntrackedParameter<bool>("doStoreOnTree")),
105  showRings_(conf.getUntrackedParameter<bool>("ShowRings", false)),
106  showEndcapSides_(conf.getUntrackedParameter<bool>("ShowEndcapSides", true)),
107  showTOB6TEC9_(conf.getUntrackedParameter<bool>("ShowTOB6TEC9", false)),
108  showOnlyGoodModules_(conf.getUntrackedParameter<bool>("ShowOnlyGoodModules", false)),
109  nTEClayers_(showRings_ ? 7 : 9), // number of rings or wheels
110  threshold_(conf.getParameter<double>("Threshold")),
111  nModsMin_(conf.getParameter<int>("nModsMin")),
112  effPlotMin_(conf.getUntrackedParameter<double>("EffPlotMin", 0.9)),
113  tkMapMin_(conf.getUntrackedParameter<double>("TkMapMin", 0.9)),
114  title_(conf.getParameter<std::string>("Title")),
115  record_(conf.getParameter<std::string>("Record")),
116  tTopoToken_(esConsumes<edm::Transition::EndRun>()),
117  tkDetMapToken_(esConsumes<edm::Transition::EndRun>()),
118  stripQualityToken_(esConsumes<edm::Transition::EndRun>()),
119  tkGeomToken_(esConsumes<edm::Transition::EndRun>()) {
120  // zero in all counts
121  for (int l = 0; l < bounds::k_END_OF_LAYS_AND_RINGS; l++) {
122  goodlayertotal[l] = 0;
123  goodlayerfound[l] = 0;
124  alllayertotal[l] = 0;
125  alllayerfound[l] = 0;
126  }
127 }
128 
130  if (!tTopo_) {
131  tTopo_ = std::make_unique<TrackerTopology>(iSetup.getData(tTopoToken_));
132  }
133  if (!tkDetMap_) {
134  tkDetMap_ = std::make_unique<TkDetMap>(iSetup.getData(tkDetMapToken_));
135  }
136  if (!stripQuality_) {
137  stripQuality_ = std::make_unique<SiStripQuality>(iSetup.getData(stripQualityToken_));
138  }
139  if (stripDetIds_.empty()) {
140  const auto& tkGeom = iSetup.getData(tkGeomToken_);
141  for (const auto& det : tkGeom.detUnits()) {
142  if (dynamic_cast<const StripGeomDetUnit*>(det)) {
143  stripDetIds_.push_back(det->geographicalId());
144  }
145  }
146  }
147 }
148 
149 bool SiStripHitEfficiencyHarvester::checkMapsValidity(const std::vector<MonitorElement*>& maps,
150  const std::string& type) const {
151  std::vector<bool> isThere;
152  isThere.reserve(maps.size());
153  std::transform(maps.begin() + 1, maps.end(), std::back_inserter(isThere), [](auto& x) { return !(x == nullptr); });
154 
155  int count{0};
156  for (const auto& it : isThere) {
157  count++;
158  LogDebug("SiStripHitEfficiencyHarvester") << " layer: " << count << " " << it << std::endl;
159  if (it)
160  LogDebug("SiStripHitEfficiencyHarvester") << "resolving to " << maps[count]->getName() << std::endl;
161  }
162 
163  // check on the input TkHistoMap
164  bool areMapsAvailable{true};
165  int layerCount{0};
166  for (const auto& it : isThere) {
167  layerCount++;
168  if (!it) {
169  edm::LogError("SiStripHitEfficiencyHarvester")
170  << type << " TkHistoMap for layer " << layerCount << " was not found.\n -> Aborting!";
171  areMapsAvailable = false;
172  break;
173  }
174  }
175  return areMapsAvailable;
176 }
177 
178 unsigned int SiStripHitEfficiencyHarvester::countTotalHits(const std::vector<MonitorElement*>& maps) {
179  return std::accumulate(maps.begin() + 1, maps.end(), 0, [](unsigned int total, MonitorElement* item) {
180  return total + item->getEntries();
181  });
182 }
183 
185  if (!isAtPCL_) {
187  if (!fs.isAvailable()) {
188  throw cms::Exception("BadConfig") << "TFileService unavailable: "
189  << "please add it to config file";
190  }
191 
192  if (doStoreOnTree_) {
193  // store information per DetId in the output tree
194  tree = fs->make<TTree>("ModEff", "ModEff");
195  tree->Branch("DetId", &t_DetId, "DetId/i");
196  tree->Branch("Layer", &t_layer, "Layer/b");
197  tree->Branch("FoundHits", &t_found, "FoundHits/i");
198  tree->Branch("AllHits", &t_total, "AllHits/i");
199  tree->Branch("IsTaggedIneff", &t_isTaggedIneff, "IsTaggedIneff/O");
200  tree->Branch("TagThreshold", &t_threshold, "TagThreshold/F");
201  }
202  }
203 
205  LOGPRINT << "A module is bad if efficiency < " << threshold_ << " and has at least " << nModsMin_ << " nModsMin.";
206  else
207  LOGPRINT << "A module is bad if the upper limit on the efficiency is < to the avg in the layer - " << threshold_
208  << " and has at least " << nModsMin_ << " nModsMin.";
209 
210  auto h_module_total = std::make_unique<TkHistoMap>(tkDetMap_.get());
211  h_module_total->loadTkHistoMap(fmt::format("{}/TkDetMaps", inputFolder_), "perModule_total");
212  auto h_module_found = std::make_unique<TkHistoMap>(tkDetMap_.get());
213  h_module_found->loadTkHistoMap(fmt::format("{}/TkDetMaps", inputFolder_), "perModule_found");
214 
215  // collect how many layers are missing
216  const auto& totalMaps = h_module_total->getAllMaps();
217  const auto& foundMaps = h_module_found->getAllMaps();
218 
219  LogDebug("SiStripHitEfficiencyHarvester")
220  << "totalMaps.size(): " << totalMaps.size() << " foundMaps.size() " << foundMaps.size() << std::endl;
221 
222  // check on the input TkHistoMaps
223  bool isTotalMapAvailable = this->checkMapsValidity(totalMaps, std::string("Total"));
224  bool isFoundMapAvailable = this->checkMapsValidity(foundMaps, std::string("Found"));
225 
226  LogDebug("SiStripHitEfficiencyHarvester")
227  << "isTotalMapAvailable: " << isTotalMapAvailable << " isFoundMapAvailable " << isFoundMapAvailable << std::endl;
228 
229  // no input TkHistoMaps -> early return
230  if (!isTotalMapAvailable or !isFoundMapAvailable)
231  return;
232 
233  LogDebug("SiStripHitEfficiencyHarvester")
234  << "Entries in total TkHistoMap for layer 3: " << h_module_total->getMap(3)->getEntries() << ", found "
235  << h_module_found->getMap(3)->getEntries();
236 
237  // count how many hits in the denominator we have
238  const unsigned int totalHits = this->countTotalHits(totalMaps);
239 
240  // set colz
241  for (size_t i = 1; i < totalMaps.size(); i++) {
242  h_module_total->getMap(i)->setOption("colz");
243  h_module_found->getMap(i)->setOption("colz");
244  }
245 
246  // come back to the main folder
248 
249  std::vector<MonitorElement*> hEffInLayer(std::size_t(1), nullptr);
250  hEffInLayer.reserve(bounds::k_END_OF_LAYERS);
251  for (std::size_t i = 1; i != bounds::k_END_OF_LAYERS; ++i) {
252  const auto lyrName = ::layerName(i, showRings_, nTEClayers_);
253  hEffInLayer.push_back(booker.book1D(
254  Form("eff_layer%i", int(i)), Form("Module efficiency in layer %s", lyrName.c_str()), 201, 0, 1.005));
255  }
256  std::array<long, bounds::k_END_OF_LAYERS> layerTotal{};
257  std::array<long, bounds::k_END_OF_LAYERS> layerFound{};
258  layerTotal.fill(0);
259  layerFound.fill(0);
260 
262  // Effiency calculation, bad module tagging, and tracker maps //
264 
265  TrackerMap tkMap{" Detector Inefficiency "};
266  TrackerMap tkMapBad{" Inefficient Modules "};
267  TrackerMap tkMapEff{title_};
268  TrackerMap tkMapNum{" Detector numerator "};
269  TrackerMap tkMapDen{" Detector denominator "};
270  std::map<unsigned int, double> badModules;
271 
272  // load the FEDError map
273  const auto& EventStats = getter.get(fmt::format("{}/EventInfo/EventStats", inputFolder_));
274  const int totalEvents = EventStats->getBinContent(1., 1.); // first bin contains info on number of events run
275  calibData_.FEDErrorOccupancy = std::make_unique<TkHistoMap>(tkDetMap_.get());
276  calibData_.FEDErrorOccupancy->loadTkHistoMap(fmt::format("{}/FEDErrorTkDetMaps", inputFolder_),
277  "perModule_FEDErrors");
278 
279  // tag as bad from FEDErrors the modules that have an error on 75% of the events
280  calibData_.fillMapFromTkMap(totalEvents, 0.75, stripDetIds_);
281 
282  for (const auto& [badId, fraction] : calibData_.fedErrorCounts) {
283  LogDebug("SiStripHitEfficiencyHarvester")
284  << __PRETTY_FUNCTION__ << " bad module from FEDError " << badId << "," << fraction << std::endl;
285  }
286 
287  for (auto det : stripDetIds_) {
288  auto layer = ::checkLayer(det, tTopo_.get());
289  const auto num = h_module_found->getValue(det);
290  const auto denom = h_module_total->getValue(det);
291  if (denom) {
292  // use only the "good" modules
293  if (stripQuality_->getBadApvs(det) == 0 && calibData_.checkFedError(det)) {
294  const auto eff = num / denom;
295  hEffInLayer[layer]->Fill(eff);
296  if (!autoIneffModTagging_) {
297  if ((denom >= nModsMin_) && (eff < threshold_)) {
298  // We have a bad module, put it in the list!
299  badModules[det] = eff;
300  tkMapBad.fillc(det, 255, 0, 0);
301  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
302  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom;
303  } else {
304  //Fill the bad list with empty results for every module
305  tkMapBad.fillc(det, 255, 255, 255);
306  }
307  if (eff < threshold_)
308  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
309  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom;
310 
311  if (denom < nModsMin_) {
312  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
313  << det.rawId() << " is under occupancy at " << denom;
314  }
315 
316  if (doStoreOnTree_ && !isAtPCL_) {
317  t_DetId = det.rawId();
318  t_layer = layer;
319  t_found = num;
320  t_total = denom;
321  t_isTaggedIneff = false;
322  t_threshold = 0;
323  tree->Fill();
324  }
325  }
326 
327  //Put any module into the TKMap
328  tkMap.fill(det, 1. - eff);
329  tkMapEff.fill(det, eff);
330  tkMapNum.fill(det, num);
331  tkMapDen.fill(det, denom);
332 
333  layerTotal[layer] += denom;
334  layerFound[layer] += num;
335 
336  // for the summary
337  // Have to do the decoding for which side to go on (ugh)
338  if (layer <= bounds::k_LayersAtTOBEnd) {
341  } else if (layer > bounds::k_LayersAtTOBEnd && layer <= bounds::k_LayersAtTIDEnd) {
342  if (tTopo_->tidSide(det) == 1) {
345  } else if (tTopo_->tidSide(det) == 2) {
346  goodlayerfound[layer + 3] += num;
347  goodlayertotal[layer + 3] += denom;
348  }
349  } else if (layer > bounds::k_LayersAtTIDEnd && layer <= bounds::k_LayersAtTECEnd) {
350  if (tTopo_->tecSide(det) == 1) {
351  goodlayerfound[layer + 3] += num;
352  goodlayertotal[layer + 3] += denom;
353  } else if (tTopo_->tecSide(det) == 2) {
356  }
357  }
358  } // if the module is good!
359 
360  //Do the one where we don't exclude bad modules!
361  if (layer <= bounds::k_LayersAtTOBEnd) {
362  alllayerfound[layer] += num;
364  } else if (layer > bounds::k_LayersAtTOBEnd && layer <= bounds::k_LayersAtTIDEnd) {
365  if (tTopo_->tidSide(det) == 1) {
366  alllayerfound[layer] += num;
368  } else if (tTopo_->tidSide(det) == 2) {
369  alllayerfound[layer + 3] += num;
370  alllayertotal[layer + 3] += denom;
371  }
372  } else if (layer > bounds::k_LayersAtTIDEnd && layer <= bounds::k_LayersAtTECEnd) {
373  if (tTopo_->tecSide(det) == 1) {
374  alllayerfound[layer + 3] += num;
375  alllayertotal[layer + 3] += denom;
376  } else if (tTopo_->tecSide(det) == 2) {
379  }
380  }
381 
382  } // if denom
383  } // loop on DetIds
384 
385  if (autoIneffModTagging_) {
386  for (unsigned int i = 1; i <= k_LayersAtTECEnd; i++) {
387  //Compute threshold to use for each layer
388  hEffInLayer[i]->getTH1()->GetXaxis()->SetRange(
389  3, hEffInLayer[i]->getNbinsX() + 1); // Remove from the avg modules below 1%
390  const double layer_min_eff = hEffInLayer[i]->getMean() - std::max(2.5 * hEffInLayer[i]->getRMS(), threshold_);
391  LOGPRINT << "Layer " << i << " threshold for bad modules: <" << layer_min_eff
392  << " (layer mean: " << hEffInLayer[i]->getMean() << " rms: " << hEffInLayer[i]->getRMS() << ")";
393 
394  hEffInLayer[i]->getTH1()->GetXaxis()->SetRange(1, hEffInLayer[i]->getNbinsX() + 1);
395 
396  for (auto det : stripDetIds_) {
397  // use only the "good" modules
398  if (stripQuality_->getBadApvs(det) == 0 && calibData_.checkFedError(det)) {
399  const auto layer = ::checkLayer(det, tTopo_.get());
400  if (layer == i) {
401  const auto num = h_module_found->getValue(det);
402  const auto denom = h_module_total->getValue(det);
403  if (denom) {
404  const auto eff = num / denom;
405  const auto eff_up = TEfficiency::Bayesian(denom, num, .99, 1, 1, true);
406 
407  if ((denom >= nModsMin_) && (eff_up < layer_min_eff)) {
408  //We have a bad module, put it in the list!
409  badModules[det] = eff;
410  tkMapBad.fillc(det, 255, 0, 0);
411  if (!isAtPCL_ && doStoreOnTree_) {
412  t_isTaggedIneff = true;
413  }
414  } else {
415  //Fill the bad list with empty results for every module
416  tkMapBad.fillc(det, 255, 255, 255);
417  if (!isAtPCL_ && doStoreOnTree_) {
418  t_isTaggedIneff = false;
419  }
420  }
421  if (eff_up < layer_min_eff + 0.08) {
422  // printing message also for modules sligthly above (8%) the limit
423  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
424  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom
425  << " , upper limit: " << eff_up;
426  }
427  if (denom < nModsMin_) {
428  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
429  << det.rawId() << " layer " << layer << " is under occupancy at " << denom;
430  }
431 
432  if (!isAtPCL_ && doStoreOnTree_) {
433  t_DetId = det.rawId();
434  t_layer = layer;
435  t_found = num;
436  t_total = denom;
437  t_threshold = layer_min_eff;
438  tree->Fill();
439  } // if storing tree
440  } // if denom
441  } // layer = i
442  } // if there are no bad APVs
443  } // loop on detids
444  } // loop on layers
445  } // if auto tagging
446 
447  tkMap.save(true, 0, 0, "SiStripHitEffTKMap_NEW.png");
448  tkMapBad.save(true, 0, 0, "SiStripHitEffTKMapBad_NEW.png");
449  tkMapEff.save(true, tkMapMin_, 1., "SiStripHitEffTKMapEff_NEW.png");
450  tkMapNum.save(true, 0, 0, "SiStripHitEffTKMapNum_NEW.png");
451  tkMapDen.save(true, 0, 0, "SiStripHitEffTKMapDen_NEW.png");
452 
453  const auto detInfo =
455  SiStripQuality pQuality{detInfo};
456  //This is the list of the bad strips, use to mask out entire APVs
457  //Now simply go through the bad hit list and mask out things that
458  //are bad!
459  for (const auto it : badModules) {
460  const auto det = it.first;
461  std::vector<unsigned int> badStripList;
462  //We need to figure out how many strips are in this particular module
463  //To Mask correctly!
464  const auto nStrips = detInfo.getNumberOfApvsAndStripLength(det).first * sistrip::STRIPS_PER_APV;
465  LOGPRINT << "Number of strips module " << det << " is " << nStrips;
466  badStripList.push_back(pQuality.encode(0, nStrips, 0));
467  //Now compact into a single bad module
468  LOGPRINT << "ID1 shoudl match list of modules above " << det;
469  pQuality.compact(det, badStripList);
470  pQuality.put(det, SiStripQuality::Range(badStripList.begin(), badStripList.end()));
471  }
472  pQuality.fillBadComponents();
473  if (doStoreOnDB_) {
474  if (totalHits > 0u) {
475  writeBadStripPayload(pQuality);
476  } else {
477  edm::LogPrint("SiStripHitEfficiencyHarvester")
478  << __PRETTY_FUNCTION__ << " There are no SiStrip hits for a valid measurement, skipping!";
479  }
480  } else {
481  edm::LogInfo("SiStripHitEfficiencyHarvester") << "Will not produce payload!";
482  }
483 
484  printTotalStatistics(layerFound, layerTotal); // statistics by layer and subdetector
485  //LOGPRINT << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event()
486  // << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
487  printAndWriteBadModules(pQuality, detInfo); // TODO
488 
489  // make summary plots
490  makeSummary(getter, booker);
491  makeSummaryVsVariable(getter, booker, projections::k_vs_LUMI);
492  makeSummaryVsVariable(getter, booker, projections::k_vs_PU);
493  makeSummaryVsVariable(getter, booker, projections::k_vs_BX);
494 }
495 
497  const std::array<long, bounds::k_END_OF_LAYERS>& layerFound,
498  const std::array<long, bounds::k_END_OF_LAYERS>& layerTotal) const {
499  //Calculate the statistics by layer
500  int totalfound = 0;
501  int totaltotal = 0;
502  double layereff;
503  int subdetfound[5] = {0, 0, 0, 0, 0};
504  int subdettotal[5] = {0, 0, 0, 0, 0};
505 
506  for (unsigned int i = 1; i <= bounds::k_LayersAtTECEnd; i++) {
507  layereff = double(layerFound[i]) / double(layerTotal[i]);
508  LOGPRINT << "Layer " << i << " (" << ::layerName(i, showRings_, nTEClayers_) << ") has total efficiency "
509  << layereff << " " << layerFound[i] << "/" << layerTotal[i];
510  totalfound += layerFound[i];
511  totaltotal += layerTotal[i];
512  if (i <= bounds::k_LayersAtTIBEnd) {
513  subdetfound[1] += layerFound[i];
514  subdettotal[1] += layerTotal[i];
515  }
516  if (i > bounds::k_LayersAtTIBEnd && i <= bounds::k_LayersAtTOBEnd) {
517  subdetfound[2] += layerFound[i];
518  subdettotal[2] += layerTotal[i];
519  }
520  if (i > bounds::k_LayersAtTOBEnd && i <= bounds::k_LayersAtTIDEnd) {
521  subdetfound[3] += layerFound[i];
522  subdettotal[3] += layerTotal[i];
523  }
524  if (i > bounds::k_LayersAtTIDEnd) {
525  subdetfound[4] += layerFound[i];
526  subdettotal[4] += layerTotal[i];
527  }
528  }
529 
530  LOGPRINT << "The total efficiency is " << double(totalfound) / double(totaltotal);
531  LOGPRINT << " TIB: " << double(subdetfound[1]) / subdettotal[1] << " " << subdetfound[1] << "/"
532  << subdettotal[1];
533  LOGPRINT << " TOB: " << double(subdetfound[2]) / subdettotal[2] << " " << subdetfound[2] << "/"
534  << subdettotal[2];
535  LOGPRINT << " TID: " << double(subdetfound[3]) / subdettotal[3] << " " << subdetfound[3] << "/"
536  << subdettotal[3];
537  LOGPRINT << " TEC: " << double(subdetfound[4]) / subdettotal[4] << " " << subdetfound[4] << "/"
538  << subdettotal[4];
539 }
540 
542  SiStripBadStrip pBadStrip{};
543  const auto pQdvBegin = quality.getDataVectorBegin();
544  for (auto rIt = quality.getRegistryVectorBegin(); rIt != quality.getRegistryVectorEnd(); ++rIt) {
545  const auto range = SiStripBadStrip::Range(pQdvBegin + rIt->ibegin, pQdvBegin + rIt->iend);
546  if (!pBadStrip.put(rIt->detid, range))
547  edm::LogError("SiStripHitEfficiencyHarvester") << "detid already exists in SiStripBadStrip";
548  }
550  if (poolDbService.isAvailable()) {
551  poolDbService->writeOneIOV(pBadStrip, poolDbService->currentTime(), record_);
552  } else {
553  throw cms::Exception("PoolDBService required");
554  }
555 }
556 
558  DQMStore::IBooker& booker,
559  bool doProfiles) const {
560  // use goodlayer_total/found and alllayer_total/found, collapse side and/or ring if needed
561  unsigned int nLayers{34}; // default
562  if (showRings_)
563  nLayers = 30;
564  if (!showEndcapSides_) {
565  if (!showRings_)
566  nLayers = 22;
567  else
568  nLayers = 20;
569  }
570 
571  // come back to the main folder and create a final efficiency folder
572  booker.setCurrentFolder(fmt::format("{}/EfficiencySummary", inputFolder_));
573  MonitorElement* found = booker.book1D("found", "found", nLayers + 1, 0, nLayers + 1);
574  MonitorElement* all = booker.book1D("all", "all", nLayers + 1, 0, nLayers + 1);
575  MonitorElement* found2 = booker.book1D("found2", "found", nLayers + 1, 0, nLayers + 1);
576  MonitorElement* all2 = booker.book1D("all2", "all2", nLayers + 1, 0, nLayers + 1);
577 
578  // first bin only to keep real data off the y axis so set to -1
579  found->setBinContent(0, -1);
580  all->setBinContent(0, 1);
581 
582  // new ROOT version: TGraph::Divide don't handle null or negative values
583  for (unsigned int i = 1; i < nLayers + 2; ++i) {
584  found->setBinContent(i, 1e-6);
585  all->setBinContent(i, 1);
586  found2->setBinContent(i, 1e-6);
587  all2->setBinContent(i, 1);
588  }
589 
590  TCanvas* c7 = new TCanvas("c7", " test ", 10, 10, 800, 600);
591  c7->SetFillColor(0);
592  c7->SetGrid();
593 
594  unsigned int nLayers_max = nLayers + 1; // barrel+endcap
595  if (!showEndcapSides_)
596  nLayers_max = 11; // barrel
597  for (unsigned int i = 1; i < nLayers_max; ++i) {
598  LOGPRINT << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i]
599  << " B = " << goodlayertotal[i];
600  if (goodlayertotal[i] > 5) {
601  found->setBinContent(i, goodlayerfound[i]);
602  all->setBinContent(i, goodlayertotal[i]);
603  }
604 
605  LOGPRINT << "Filling all modules layer " << i << ": S = " << alllayerfound[i] << " B = " << alllayertotal[i];
606  if (alllayertotal[i] > 5) {
607  found2->setBinContent(i, alllayerfound[i]);
608  all2->setBinContent(i, alllayertotal[i]);
609  }
610  }
611 
612  // endcap - merging sides
613  if (!showEndcapSides_) {
614  for (unsigned int i = 11; i < 14; ++i) { // TID disks
615  LOGPRINT << "Fill only good modules layer " << i << ": S = " << goodlayerfound[i] + goodlayerfound[i + 3]
616  << " B = " << goodlayertotal[i] + goodlayertotal[i + 3];
617  if (goodlayertotal[i] + goodlayertotal[i + 3] > 5) {
618  found->setBinContent(i, goodlayerfound[i] + goodlayerfound[i + 3]);
619  all->setBinContent(i, goodlayertotal[i] + goodlayertotal[i + 3]);
620  }
621  LOGPRINT << "Filling all modules layer " << i << ": S = " << alllayerfound[i] + alllayerfound[i + 3]
622  << " B = " << alllayertotal[i] + alllayertotal[i + 3];
623  if (alllayertotal[i] + alllayertotal[i + 3] > 5) {
624  found2->setBinContent(i, alllayerfound[i] + alllayerfound[i + 3]);
625  all2->setBinContent(i, alllayertotal[i] + alllayertotal[i + 3]);
626  }
627  }
628  for (unsigned int i = 17; i < 17 + nTEClayers_; ++i) { // TEC disks
629  LOGPRINT << "Fill only good modules layer " << i - 3
630  << ": S = " << goodlayerfound[i] + goodlayerfound[i + nTEClayers_]
631  << " B = " << goodlayertotal[i] + goodlayertotal[i + nTEClayers_];
632  if (goodlayertotal[i] + goodlayertotal[i + nTEClayers_] > 5) {
633  found->setBinContent(i - 3, goodlayerfound[i] + goodlayerfound[i + nTEClayers_]);
634  all->setBinContent(i - 3, goodlayertotal[i] + goodlayertotal[i + nTEClayers_]);
635  }
636  LOGPRINT << "Filling all modules layer " << i - 3
637  << ": S = " << alllayerfound[i] + alllayerfound[i + nTEClayers_]
638  << " B = " << alllayertotal[i] + alllayertotal[i + nTEClayers_];
639  if (alllayertotal[i] + alllayertotal[i + nTEClayers_] > 5) {
642  }
643  }
644  }
645 
646  found->getTH1F()->Sumw2();
647  all->getTH1F()->Sumw2();
648 
649  found2->getTH1F()->Sumw2();
650  all2->getTH1F()->Sumw2();
651 
652  MonitorElement* h_eff_all =
653  booker.book1D("eff_all", "Strip hit efficiency for all modules", nLayers + 1, 0, nLayers + 1);
654  MonitorElement* h_eff_good =
655  booker.book1D("eff_good", "Strip hit efficiency for good modules", nLayers + 1, 0, nLayers + 1);
656 
657  if (doProfiles) {
658  // now do the profile
659  TProfile* profile_all = ::computeEff(found2->getTH1F(), all2->getTH1F(), "all");
660  profile_all->SetMinimum(tkMapMin_);
661  profile_all->SetTitle("Strip hit efficiency for all modules");
662  booker.bookProfile(profile_all->GetName(), profile_all);
663 
664  TProfile* profile_good = ::computeEff(found->getTH1F(), all->getTH1F(), "good");
665  profile_good->SetMinimum(tkMapMin_);
666  profile_good->SetTitle("Strip hit efficiency for good modules");
667  booker.bookProfile(profile_good->GetName(), profile_good);
668 
669  // clean the house
670  delete profile_all;
671  delete profile_good;
672  }
673 
674  for (int i = 1; i < found->getNbinsX(); i++) {
675  const auto& den_all = all2->getBinContent(i);
676  const auto& num_all = found2->getBinContent(i);
677  const auto& den_good = all->getBinContent(i);
678  const auto& num_good = found->getBinContent(i);
679 
680  // fill all modules efficiency
681  if (den_all > 0.) {
682  // naive binomial errors
683  //float eff_all = num_all / den_all;
684  //float err_eff_all = (eff_all * (1 - eff_all)) / den_all;
685 
686  // use Clopper-Pearson errors
687  const auto& effPair_all = ::computeCPEfficiency(num_all, den_all);
688  h_eff_all->setBinContent(i, effPair_all.value());
689  h_eff_all->setBinError(i, effPair_all.error());
690  }
691 
692  // fill good modules efficiency
693  if (den_good > 0.) {
694  // naive binomial errors
695  //float eff_good = num_good / den_good;
696  //float err_eff_good = (eff_good * (1 - eff_good)) / den_good;
697 
698  // use Clopper-Pearson errors
699  const auto& effPair_good = ::computeCPEfficiency(num_good, den_good);
700  h_eff_good->setBinContent(i, effPair_good.value());
701  h_eff_good->setBinError(i, effPair_good.error());
702  }
703  }
704 
705  h_eff_all->getTH1F()->SetMinimum(effPlotMin_);
706  h_eff_good->getTH1F()->SetMinimum(effPlotMin_);
707 
708  // set the histogram bin labels
709  this->setEffBinLabels(h_eff_all->getTH1F(), h_eff_good->getTH1F(), nLayers);
710 
711  if (!isAtPCL_) {
712  // if TFileService is not avaible, just go on
714  if (!fs.isAvailable()) {
715  throw cms::Exception("BadConfig") << "TFileService unavailable: "
716  << "please add it to config file";
717  }
718 
719  TGraphAsymmErrors* gr = (*fs).make<TGraphAsymmErrors>(nLayers + 1);
720  gr->SetName("eff_good");
721  gr->BayesDivide(found->getTH1F(), all->getTH1F());
722 
723  TGraphAsymmErrors* gr2 = (*fs).make<TGraphAsymmErrors>(nLayers + 1);
724  gr2->SetName("eff_all");
725  gr2->BayesDivide(found2->getTH1F(), all2->getTH1F());
726 
727  for (unsigned int j = 0; j < nLayers + 1; j++) {
728  gr->SetPointError(j, 0., 0., gr->GetErrorYlow(j), gr->GetErrorYhigh(j));
729  gr2->SetPointError(j, 0., 0., gr2->GetErrorYlow(j), gr2->GetErrorYhigh(j));
730  }
731 
732  this->setEffBinLabels(gr, gr2, nLayers);
733 
734  gr->GetXaxis()->SetLimits(0, nLayers);
735  gr->SetMarkerColor(2);
736  gr->SetMarkerSize(1.2);
737  gr->SetLineColor(2);
738  gr->SetLineWidth(4);
739  gr->SetMarkerStyle(20);
740  gr->SetMinimum(effPlotMin_);
741  gr->SetMaximum(1.001);
742  gr->GetYaxis()->SetTitle("Efficiency");
743  gStyle->SetTitleFillColor(0);
744  gStyle->SetTitleBorderSize(0);
745  gr->SetTitle("SiStripHitEfficiency by Layer");
746 
747  gr2->GetXaxis()->SetLimits(0, nLayers);
748  gr2->SetMarkerColor(1);
749  gr2->SetMarkerSize(1.2);
750  gr2->SetLineColor(1);
751  gr2->SetLineWidth(4);
752  gr2->SetMarkerStyle(21);
753  gr2->SetMinimum(effPlotMin_);
754  gr2->SetMaximum(1.001);
755  gr2->GetYaxis()->SetTitle("Efficiency");
756  gr2->SetTitle("SiStripHitEfficiency by Layer");
757 
758  gr->Draw("AP");
759  gr->GetXaxis()->SetNdivisions(36);
760 
761  c7->cd();
762  TPad* overlay = new TPad("overlay", "", 0, 0, 1, 1);
763  overlay->SetFillStyle(4000);
764  overlay->SetFillColor(0);
765  overlay->SetFrameFillStyle(4000);
766  overlay->Draw("same");
767  overlay->cd();
769  gr2->Draw("AP");
770 
771  TLegend* leg = new TLegend(0.70, 0.27, 0.88, 0.40);
772  leg->AddEntry(gr, "Good Modules", "p");
774  leg->AddEntry(gr2, "All Modules", "p");
775  leg->SetTextSize(0.020);
776  leg->SetFillColor(0);
777  leg->Draw("same");
778 
779  c7->SaveAs("Summary.png");
780  c7->SaveAs("Summary.root");
781  } // if it's not run at PCL
782 }
783 
784 template <typename T>
785 void SiStripHitEfficiencyHarvester::setEffBinLabels(const T gr, const T gr2, const unsigned int nLayers) const {
786  LogDebug("SiStripHitEfficiencyHarvester")
787  << "nLayers = " << nLayers << " number of bins, gr1: " << gr->GetXaxis()->GetNbins()
788  << " number of bins, gr2: " << gr2->GetXaxis()->GetNbins() << " showRings: " << showRings_
789  << " showEndcapSides: " << showEndcapSides_ << " type of object is "
790  << boost::typeindex::type_id<T>().pretty_name();
791 
792  for (unsigned int k = 1; k < nLayers + 1; k++) {
793  std::string label{};
794  if (showEndcapSides_)
795  label = ::layerSideName(k, showRings_, nTEClayers_);
796  else
797  label = ::layerName(k, showRings_, nTEClayers_);
798  if (!showTOB6TEC9_) {
799  if (k == 10)
800  label = "";
801  if (!showRings_ && k == nLayers)
802  label = "";
803  if (!showRings_ && showEndcapSides_ && k == 25)
804  label = "";
805  }
806 
807  int bin{-1};
808  if constexpr (std::is_same_v<T, TGraphAsymmErrors*>) {
809  edm::LogInfo("SiStripHitEfficiencyHarvester")
810  << "class name: " << gr->ClassName() << " expected TGraphAsymErrors" << std::endl;
811  if (!showRings_) {
812  if (showEndcapSides_) {
813  bin = (((k + 1) * 100 + 2) / (nLayers)-4);
814  } else {
815  bin = ((k + 1) * 100 / (nLayers)-6);
816  }
817  } else {
818  if (showEndcapSides_) {
819  bin = ((k + 1) * 100 / (nLayers)-4);
820  } else {
821  bin = ((k + 1) * 100 / (nLayers)-7);
822  }
823  }
824  } else {
825  edm::LogInfo("SiStripHitEfficiencyHarvester")
826  << "class name: " << gr->ClassName() << " expected TH1F" << std::endl;
827  bin = k;
828  }
829  gr->GetXaxis()->SetBinLabel(bin, label.data());
830  gr2->GetXaxis()->SetBinLabel(bin, label.data());
831  }
832 }
833 
835  DQMStore::IBooker& booker,
836  ::projections theProj) const {
837  std::vector<MonitorElement*> effVsVariable;
838  effVsVariable.reserve(showRings_ ? 20 : 22);
839 
840  const auto& folderString = ::projFolder[theProj];
841  const auto& foundHistoString = ::projFoundHisto[theProj];
842  const auto& totalHistoString = ::projTotalHisto[theProj];
843  const auto& titleString = ::projTitle[theProj];
844  const auto& titleXString = ::projXtitle[theProj];
845 
846  LogDebug("SiStripHitEfficiencyHarvester")
847  << " inside" << __PRETTY_FUNCTION__ << " from " << ::projFolder[theProj] << " " << __LINE__ << std::endl;
848 
849  for (unsigned int iLayer = 1; iLayer != (showRings_ ? 20 : 22); ++iLayer) {
850  LogDebug("SiStripHitEfficiencyHarvester")
851  << "iLayer " << iLayer << " " << fmt::format("{}/{}/{}{}", inputFolder_, folderString, foundHistoString, iLayer)
852  << std::endl;
853 
854  const auto lyrName = ::layerName(iLayer, showRings_, nTEClayers_);
855  auto hfound = getter.get(fmt::format("{}/{}/{}{}", inputFolder_, folderString, foundHistoString, iLayer));
856  auto htotal = getter.get(fmt::format("{}/{}/{}{}", inputFolder_, folderString, totalHistoString, iLayer));
857 
858  if (hfound == nullptr or htotal == nullptr) {
859  if (hfound == nullptr)
860  edm::LogError("SiStripHitEfficiencyHarvester")
861  << fmt::format("{}/{}/{}{}", inputFolder_, folderString, foundHistoString, iLayer) << " was not found!";
862  if (htotal == nullptr)
863  edm::LogError("SiStripHitEfficiencyHarvester")
864  << fmt::format("{}/{}/{}{}", inputFolder_, folderString, totalHistoString, iLayer) << " was not found!";
865  // no input histograms -> continue in the loop
866  continue;
867  }
868 
869  // in order to display correct errors when taking the ratio
870  if (!hfound->getTH1F()->GetSumw2())
871  hfound->getTH1F()->Sumw2();
872  if (!htotal->getTH1F()->GetSumw2())
873  htotal->getTH1F()->Sumw2();
874 
875  // prevent dividing by 0
876  for (int i = 0; i != hfound->getNbinsX() + 1; ++i) {
877  if (hfound->getBinContent(i) == 0)
878  hfound->setBinContent(i, 1e-6);
879  if (htotal->getBinContent(i) == 0)
880  htotal->setBinContent(i, 1);
881  }
882  LogDebug("SiStripHitEfficiencyHarvester") << "Total hits for layer " << iLayer << " (" << folderString
883  << "): " << htotal->getEntries() << ", found " << hfound->getEntries();
884 
885  booker.setCurrentFolder(fmt::format("{}/EfficiencySummary{}", inputFolder_, folderString));
886  effVsVariable[iLayer] = booker.book1D(
887  fmt::sprintf("eff%sLayer%s", folderString, lyrName),
888  fmt::sprintf("Efficiency vs %s for layer %s;%s;SiStrip Hit efficiency", titleString, lyrName, titleXString),
889  hfound->getNbinsX(),
890  hfound->getAxisMin(),
891  hfound->getAxisMax());
892 
893  LogDebug("SiStripHitEfficiencyHarvester")
894  << " bin 0 " << hfound->getAxisMin() << " bin last: " << hfound->getAxisMax() << std::endl;
895 
896  for (int i = 0; i != hfound->getNbinsX() + 1; ++i) {
897  const auto& den = htotal->getBinContent(i);
898  const auto& num = hfound->getBinContent(i);
899 
900  // fill all modules efficiency
901  if (den > 0.) {
902  const auto& effPair = ::computeCPEfficiency(num, den);
903  effVsVariable[iLayer]->setBinContent(i, effPair.value());
904  effVsVariable[iLayer]->setBinError(i, effPair.error());
905 
906  LogDebug("SiStripHitEfficiencyHarvester")
907  << __PRETTY_FUNCTION__ << " " << lyrName << " bin:" << i << " err:" << effPair.error() << std::endl;
908  }
909  }
910 
911  // graphics adjustment
912  effVsVariable[iLayer]->getTH1F()->SetMinimum(tkMapMin_);
913 
914  // now do the profile
915  TProfile* profile = ::computeEff(hfound->getTH1F(), htotal->getTH1F(), lyrName);
916  TString title =
917  fmt::sprintf("Efficiency vs %s for layer %s;%s;SiStrip Hit efficiency", titleString, lyrName, titleXString);
918  profile->SetMinimum(tkMapMin_);
919 
920  profile->SetTitle(title.Data());
921  booker.bookProfile(profile->GetName(), profile);
922 
923  delete profile;
924  } // loop on layers
925 }
926 
927 namespace {
928  void setBadComponents(int i,
929  int comp,
931  std::stringstream ssV[4][19],
932  int nBad[4][19][4],
933  int nAPV) {
934  ssV[i][comp] << "\n\t\t " << bc.detid << " \t " << bc.BadModule << " \t " << ((bc.BadFibers) & 0x1) << " ";
935  if (nAPV == 4)
936  ssV[i][comp] << "x " << ((bc.BadFibers >> 1) & 0x1);
937 
938  if (nAPV == 6)
939  ssV[i][comp] << ((bc.BadFibers >> 1) & 0x1) << " " << ((bc.BadFibers >> 2) & 0x1);
940  ssV[i][comp] << " \t " << ((bc.BadApvs) & 0x1) << " " << ((bc.BadApvs >> 1) & 0x1) << " ";
941  if (nAPV == 4)
942  ssV[i][comp] << "x x " << ((bc.BadApvs >> 2) & 0x1) << " " << ((bc.BadApvs >> 3) & 0x1);
943  if (nAPV == 6)
944  ssV[i][comp] << ((bc.BadApvs >> 2) & 0x1) << " " << ((bc.BadApvs >> 3) & 0x1) << " " << ((bc.BadApvs >> 4) & 0x1)
945  << " " << ((bc.BadApvs >> 5) & 0x1) << " ";
946 
947  if (bc.BadApvs) {
948  nBad[i][0][2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
949  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
950  nBad[i][comp][2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
951  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
952  }
953  if (bc.BadFibers) {
954  nBad[i][0][1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
955  nBad[i][comp][1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
956  }
957  if (bc.BadModule) {
958  nBad[i][0][0]++;
959  nBad[i][comp][0]++;
960  }
961  }
962 } // namespace
963 
965  const SiStripDetInfo& detInfo) const {
967  //try to write out what's in the quality record
969  int nTkBadComp[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
970  int nBadComp[4][19][4];
971  //legend: nBadComp[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
972  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
973  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
974  std::stringstream ssV[4][19];
975 
976  for (int i = 0; i < 4; ++i) {
977  nTkBadComp[i] = 0;
978  for (int j = 0; j < 19; ++j) {
979  ssV[i][j].str("");
980  for (int k = 0; k < 4; ++k)
981  nBadComp[i][j][k] = 0;
982  }
983  }
984 
985  for (const auto& bc : quality.getBadComponentList()) {
986  // Full Tk
987  if (bc.BadModule)
988  nTkBadComp[0]++;
989  if (bc.BadFibers)
990  nTkBadComp[1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
991  if (bc.BadApvs)
992  nTkBadComp[2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
993  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
994  // single subsystem
995  DetId det(bc.detid);
996  if ((det.subdetId() >= SiStripSubdetector::TIB) && (det.subdetId() <= SiStripSubdetector::TEC)) {
997  const auto nAPV = detInfo.getNumberOfApvsAndStripLength(det).first;
998  switch (det.subdetId()) {
1000  setBadComponents(0, tTopo_->tibLayer(det), bc, ssV, nBadComp, nAPV);
1001  break;
1003  setBadComponents(1,
1004  (tTopo_->tidSide(det) == 2 ? tTopo_->tidWheel(det) : tTopo_->tidWheel(det) + 3),
1005  bc,
1006  ssV,
1007  nBadComp,
1008  nAPV);
1009  break;
1011  setBadComponents(2, tTopo_->tobLayer(det), bc, ssV, nBadComp, nAPV);
1012  break;
1014  setBadComponents(3,
1015  (tTopo_->tecSide(det) == 2 ? tTopo_->tecWheel(det) : tTopo_->tecWheel(det) + 9),
1016  bc,
1017  ssV,
1018  nBadComp,
1019  nAPV);
1020  break;
1021  default:
1022  break;
1023  }
1024  }
1025  }
1026  // single strip info
1027  for (auto rp = quality.getRegistryVectorBegin(); rp != quality.getRegistryVectorEnd(); ++rp) {
1028  DetId det{rp->detid};
1029  int subdet = -999;
1030  int component = -999;
1031  switch (det.subdetId()) {
1033  subdet = 0;
1034  component = tTopo_->tibLayer(det);
1035  break;
1037  subdet = 1;
1038  component = tTopo_->tidSide(det) == 2 ? tTopo_->tidWheel(det) : tTopo_->tidWheel(det) + 3;
1039  break;
1041  subdet = 2;
1042  component = tTopo_->tobLayer(det);
1043  break;
1045  subdet = 3;
1046  component = tTopo_->tecSide(det) == 2 ? tTopo_->tecWheel(det) : tTopo_->tecWheel(det) + 9;
1047  break;
1048  default:
1049  break;
1050  }
1051 
1052  const auto pQdvBegin = quality.getDataVectorBegin();
1053  const auto sqrange = SiStripQuality::Range(pQdvBegin + rp->ibegin, pQdvBegin + rp->iend);
1054  float percentage = 0;
1055  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
1056  unsigned int range = quality.decode(*(sqrange.first + it)).range;
1057  nTkBadComp[3] += range;
1058  nBadComp[subdet][0][3] += range;
1059  nBadComp[subdet][component][3] += range;
1060  percentage += range;
1061  }
1062  if (percentage != 0)
1063  percentage /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first);
1064  if (percentage > 1)
1065  edm::LogError("SiStripHitEfficiencyHarvester") << "PROBLEM detid " << det.rawId() << " value " << percentage;
1066  }
1067 
1068  // printout
1069  std::ostringstream ss;
1070  ss << "\n-----------------\nGlobal Info\n-----------------";
1071  ss << "\nBadComp \t Modules \tFibers "
1072  "\tApvs\tStrips\n----------------------------------------------------------------";
1073  ss << "\nTracker:\t\t" << nTkBadComp[0] << "\t" << nTkBadComp[1] << "\t" << nTkBadComp[2] << "\t" << nTkBadComp[3];
1074  ss << "\nTIB:\t\t\t" << nBadComp[0][0][0] << "\t" << nBadComp[0][0][1] << "\t" << nBadComp[0][0][2] << "\t"
1075  << nBadComp[0][0][3];
1076  ss << "\nTID:\t\t\t" << nBadComp[1][0][0] << "\t" << nBadComp[1][0][1] << "\t" << nBadComp[1][0][2] << "\t"
1077  << nBadComp[1][0][3];
1078  ss << "\nTOB:\t\t\t" << nBadComp[2][0][0] << "\t" << nBadComp[2][0][1] << "\t" << nBadComp[2][0][2] << "\t"
1079  << nBadComp[2][0][3];
1080  ss << "\nTEC:\t\t\t" << nBadComp[3][0][0] << "\t" << nBadComp[3][0][1] << "\t" << nBadComp[3][0][2] << "\t"
1081  << nBadComp[3][0][3];
1082  ss << "\n";
1083 
1084  for (int i = 1; i < 5; ++i)
1085  ss << "\nTIB Layer " << i << " :\t\t" << nBadComp[0][i][0] << "\t" << nBadComp[0][i][1] << "\t" << nBadComp[0][i][2]
1086  << "\t" << nBadComp[0][i][3];
1087  ss << "\n";
1088  for (int i = 1; i < 4; ++i)
1089  ss << "\nTID+ Disk " << i << " :\t\t" << nBadComp[1][i][0] << "\t" << nBadComp[1][i][1] << "\t" << nBadComp[1][i][2]
1090  << "\t" << nBadComp[1][i][3];
1091  for (int i = 4; i < 7; ++i)
1092  ss << "\nTID- Disk " << i - 3 << " :\t\t" << nBadComp[1][i][0] << "\t" << nBadComp[1][i][1] << "\t"
1093  << nBadComp[1][i][2] << "\t" << nBadComp[1][i][3];
1094  ss << "\n";
1095  for (int i = 1; i < 7; ++i)
1096  ss << "\nTOB Layer " << i << " :\t\t" << nBadComp[2][i][0] << "\t" << nBadComp[2][i][1] << "\t" << nBadComp[2][i][2]
1097  << "\t" << nBadComp[2][i][3];
1098  ss << "\n";
1099  for (int i = 1; i < 10; ++i)
1100  ss << "\nTEC+ Disk " << i << " :\t\t" << nBadComp[3][i][0] << "\t" << nBadComp[3][i][1] << "\t" << nBadComp[3][i][2]
1101  << "\t" << nBadComp[3][i][3];
1102  for (int i = 10; i < 19; ++i)
1103  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << nBadComp[3][i][0] << "\t" << nBadComp[3][i][1] << "\t"
1104  << nBadComp[3][i][2] << "\t" << nBadComp[3][i][3];
1105  ss << "\n";
1106 
1107  ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
1108  "Apvs\n----------------------------------------------------------------";
1109  for (int i = 1; i < 5; ++i)
1110  ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
1111  ss << "\n";
1112  for (int i = 1; i < 4; ++i)
1113  ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
1114  for (int i = 4; i < 7; ++i)
1115  ss << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
1116  ss << "\n";
1117  for (int i = 1; i < 7; ++i)
1118  ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
1119  ss << "\n";
1120  for (int i = 1; i < 10; ++i)
1121  ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
1122  for (int i = 10; i < 19; ++i)
1123  ss << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
1124 
1125  LOGPRINT << ss.str();
1126 
1127  // store also bad modules in log file
1128  std::ofstream badModules;
1129  badModules.open("BadModules_NEW.log");
1130  badModules << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
1131  "Apvs\n----------------------------------------------------------------";
1132  for (int i = 1; i < 5; ++i)
1133  badModules << "\nTIB Layer " << i << " :" << ssV[0][i].str();
1134  badModules << "\n";
1135  for (int i = 1; i < 4; ++i)
1136  badModules << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
1137  for (int i = 4; i < 7; ++i)
1138  badModules << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
1139  badModules << "\n";
1140  for (int i = 1; i < 7; ++i)
1141  badModules << "\nTOB Layer " << i << " :" << ssV[2][i].str();
1142  badModules << "\n";
1143  for (int i = 1; i < 10; ++i)
1144  badModules << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
1145  for (int i = 10; i < 19; ++i)
1146  badModules << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
1147  badModules.close();
1148 }
1149 
1152  desc.add<std::string>("inputFolder", "AlCaReco/SiStripHitEfficiency");
1153  desc.add<bool>("isAtPCL", false);
1154  desc.add<bool>("doStoreOnDB", false);
1155  desc.add<std::string>("Record", "SiStripBadStrip");
1156  desc.add<double>("Threshold", 0.1);
1157  desc.add<std::string>("Title", "Hit Efficiency");
1158  desc.add<int>("nModsMin", 5);
1159  desc.addUntracked<bool>("doStoreOnTree", false);
1160  desc.addUntracked<bool>("AutoIneffModTagging", false);
1161  desc.addUntracked<double>("TkMapMin", 0.9);
1162  desc.addUntracked<double>("EffPlotMin", 0.9);
1163  desc.addUntracked<bool>("ShowRings", false);
1164  desc.addUntracked<bool>("ShowEndcapSides", true);
1165  desc.addUntracked<bool>("ShowTOB6TEC9", false);
1166  desc.addUntracked<bool>("ShowOnlyGoodModules", false);
1167  descriptions.addWithDefaultLabel(desc);
1168 }
1169 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void setEffBinLabels(const T gr, const T gr2, const unsigned int nLayers) const
void makeSummary(DQMStore::IGetter &getter, DQMStore::IBooker &booker, bool doProfiles=false) const
int goodlayerfound[bounds::k_END_OF_LAYS_AND_RINGS]
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
int goodlayertotal[bounds::k_END_OF_LAYS_AND_RINGS]
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
std::unique_ptr< TrackerTopology > tTopo_
void endRun(edm::Run const &, edm::EventSetup const &) override
int alllayertotal[bounds::k_END_OF_LAYS_AND_RINGS]
void printAndWriteBadModules(const SiStripQuality &quality, const SiStripDetInfo &detInfo) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Error, false > LogError
std::unordered_map< uint32_t, int > fedErrorCounts
const edm::ESGetToken< SiStripQuality, SiStripQualityRcd > stripQualityToken_
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
std::unique_ptr< TkHistoMap > FEDErrorOccupancy
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
char const * label
string quality
def overlay(hists, ytitle, header, addon)
Definition: compare.py:122
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
const bool checkFedError(const DetId det)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void printTotalStatistics(const std::array< long, bounds::k_END_OF_LAYERS > &layerFound, const std::array< long, bounds::k_END_OF_LAYERS > &layerTotal) const
unsigned int countTotalHits(const std::vector< MonitorElement *> &maps)
void writeBadStripPayload(const SiStripQuality &quality) const
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
SiStripDetInfo read(std::string filePath)
Log< level::Warning, true > LogPrint
SiStripHitEfficiencyHarvester(const edm::ParameterSet &)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
void setBadComponents(int i, int component, const SiStripQuality::BadComponent &BC, int NBadComponent[4][19][4])
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
void fillMapFromTkMap(const int nevents, const float threshold, const std::vector< DetId > &stripDetIds)
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
Constants and enumerated types for FED/FEC systems.
virtual TH1F * getTH1F() const
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
~SiStripHitEfficiencyHarvester() override=default
HLT enums.
static const uint16_t STRIPS_PER_APV
std::pair< ContainerIterator, ContainerIterator > Range
std::unique_ptr< SiStripQuality > stripQuality_
int alllayerfound[bounds::k_END_OF_LAYS_AND_RINGS]
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Definition: tree.py:1
void makeSummaryVsVariable(DQMStore::IGetter &getter, DQMStore::IBooker &booker, ::projections theProj) const
const edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
bool checkMapsValidity(const std::vector< MonitorElement *> &maps, const std::string &type) const
#define str(s)
long double T
Definition: Run.h:45
#define LogDebug(id)
virtual double getBinContent(int binx) const
get content of bin (1-D)
unsigned transform(const HcalDetId &id, unsigned transformCode)