CMS 3D CMS Logo

SiStripHitEfficiencyHarvester.cc
Go to the documentation of this file.
1 // user includes
23 
24 //system includes
25 #include <sstream>
26 
27 // ROOT includes
28 #include "TEfficiency.h"
29 
30 // custom made printout
31 #define LOGPRINT edm::LogPrint("SiStripHitEfficiencyHarvester")
32 
34 public:
36  ~SiStripHitEfficiencyHarvester() override = default;
37  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
38 
39  void endRun(edm::Run const&, edm::EventSetup const&) override;
41 
42 private:
44  const bool isAtPCL_;
46  const unsigned int nTEClayers_;
47  const double threshold_;
48  const int nModsMin_;
49  const double tkMapMin_;
51 
56 
57  std::unique_ptr<TrackerTopology> tTopo_;
58  std::unique_ptr<TkDetMap> tkDetMap_;
59  std::unique_ptr<SiStripQuality> stripQuality_;
60  std::vector<DetId> stripDetIds_;
61 
62  void writeBadStripPayload(const SiStripQuality& quality) const;
63  void printTotalStatistics(const std::array<long, bounds::k_END_OF_LAYERS>& layerFound,
64  const std::array<long, bounds::k_END_OF_LAYERS>& layerTotal) const;
65  void printAndWriteBadModules(const SiStripQuality& quality, const SiStripDetInfo& detInfo) const;
66  bool checkMapsValidity(const std::vector<MonitorElement*>& maps, const std::string& type) const;
67  void makeSummary(DQMStore::IGetter& getter, TFileService& fs) const;
68  void makeSummaryVsBX(DQMStore::IGetter& getter, TFileService& fs) const;
69  void makeSummaryVsLumi(DQMStore::IGetter& getter) const;
70  void makeSummaryVsCM(DQMStore::IGetter& getter, TFileService& fs) const;
71 };
72 
74  : inputFolder_(conf.getParameter<std::string>("inputFolder")),
75  isAtPCL_(conf.getParameter<bool>("isAtPCL")),
76  showRings_(conf.getUntrackedParameter<bool>("ShowRings", false)),
77  autoIneffModTagging_(conf.getUntrackedParameter<bool>("AutoIneffModTagging", false)),
78  doStoreOnDB_(conf.getParameter<bool>("doStoreOnDB")),
79  nTEClayers_(showRings_ ? 7 : 9), // number of rings or wheels
80  threshold_(conf.getParameter<double>("Threshold")),
81  nModsMin_(conf.getParameter<int>("nModsMin")),
82  tkMapMin_(conf.getUntrackedParameter<double>("TkMapMin", 0.9)),
83  title_(conf.getParameter<std::string>("Title")),
84  record_(conf.getParameter<std::string>("Record")),
85  tTopoToken_(esConsumes<edm::Transition::EndRun>()),
86  tkDetMapToken_(esConsumes<edm::Transition::EndRun>()),
87  stripQualityToken_(esConsumes<edm::Transition::EndRun>()),
88  tkGeomToken_(esConsumes<edm::Transition::EndRun>()) {}
89 
91  if (!tTopo_) {
92  tTopo_ = std::make_unique<TrackerTopology>(iSetup.getData(tTopoToken_));
93  }
94  if (!tkDetMap_) {
95  tkDetMap_ = std::make_unique<TkDetMap>(iSetup.getData(tkDetMapToken_));
96  }
97  if (!stripQuality_) {
98  stripQuality_ = std::make_unique<SiStripQuality>(iSetup.getData(stripQualityToken_));
99  }
100  if (stripDetIds_.empty()) {
101  const auto& tkGeom = iSetup.getData(tkGeomToken_);
102  for (const auto& det : tkGeom.detUnits()) {
103  if (dynamic_cast<const StripGeomDetUnit*>(det)) {
104  stripDetIds_.push_back(det->geographicalId());
105  }
106  }
107  }
108 }
109 
110 bool SiStripHitEfficiencyHarvester::checkMapsValidity(const std::vector<MonitorElement*>& maps,
111  const std::string& type) const {
112  std::vector<bool> isAvailable;
113  isAvailable.reserve(maps.size());
115  maps.begin() + 1, maps.end(), std::back_inserter(isAvailable), [](auto& x) { return !(x == nullptr); });
116 
117  int count{0};
118  for (const auto& it : isAvailable) {
119  count++;
120  LogDebug("SiStripHitEfficiencyHarvester") << " layer: " << count << " " << it << std::endl;
121  if (it)
122  LogDebug("SiStripHitEfficiencyHarvester") << "resolving to " << maps[count]->getName() << std::endl;
123  }
124 
125  // check on the input TkHistoMap
126  bool areMapsAvailable{true};
127  int layerCount{0};
128  for (const auto& it : isAvailable) {
129  layerCount++;
130  if (!it) {
131  edm::LogError("SiStripHitEfficiencyHarvester")
132  << type << " TkHistoMap for layer " << layerCount << " was not found.\n -> Aborting!";
133  areMapsAvailable = false;
134  break;
135  }
136  }
137  return areMapsAvailable;
138 }
139 
142  LOGPRINT << "A module is bad if efficiency < " << threshold_ << " and has at least " << nModsMin_ << " nModsMin.";
143  else
144  LOGPRINT << "A module is bad if the upper limit on the efficiency is < to the avg in the layer - " << threshold_
145  << " and has at least " << nModsMin_ << " nModsMin.";
146 
147  auto h_module_total = std::make_unique<TkHistoMap>(tkDetMap_.get());
148  h_module_total->loadTkHistoMap(fmt::format("{}/TkDetMaps", inputFolder_), "perModule_total");
149  auto h_module_found = std::make_unique<TkHistoMap>(tkDetMap_.get());
150  h_module_found->loadTkHistoMap(fmt::format("{}/TkDetMaps", inputFolder_), "perModule_found");
151 
152  // collect how many layers are missing
153  const auto& totalMaps = h_module_total->getAllMaps();
154  const auto& foundMaps = h_module_found->getAllMaps();
155 
156  LogDebug("SiStripHitEfficiencyHarvester")
157  << "totalMaps.size(): " << totalMaps.size() << " foundMaps.size() " << foundMaps.size() << std::endl;
158 
159  // check on the input TkHistoMaps
160  bool isTotalMapAvailable = this->checkMapsValidity(totalMaps, std::string("Total"));
161  bool isFoundMapAvailable = this->checkMapsValidity(foundMaps, std::string("Found"));
162 
163  LogDebug("SiStripHitEfficiencyHarvester")
164  << "isTotalMapAvailable: " << isTotalMapAvailable << " isFoundMapAvailable " << isFoundMapAvailable << std::endl;
165 
166  // no input TkHistoMaps -> early return
167  if (!isTotalMapAvailable or !isFoundMapAvailable)
168  return;
169 
170  LogDebug("SiStripHitEfficiencyHarvester")
171  << "Entries in total TkHistoMap for layer 3: " << h_module_total->getMap(3)->getEntries() << ", found "
172  << h_module_found->getMap(3)->getEntries();
173 
174  // come back to the main folder
176 
177  std::vector<MonitorElement*> hEffInLayer(std::size_t(1), nullptr);
178  hEffInLayer.reserve(bounds::k_END_OF_LAYERS);
179  for (std::size_t i = 1; i != bounds::k_END_OF_LAYERS; ++i) {
180  const auto lyrName = ::layerName(i, showRings_, nTEClayers_);
181  hEffInLayer.push_back(booker.book1D(
182  Form("eff_layer%i", int(i)), Form("Module efficiency in layer %s", lyrName.c_str()), 201, 0, 1.005));
183  }
184  std::array<long, bounds::k_END_OF_LAYERS> layerTotal{};
185  std::array<long, bounds::k_END_OF_LAYERS> layerFound{};
186  layerTotal.fill(0);
187  layerFound.fill(0);
188 
190  // Effiency calculation, bad module tagging, and tracker maps //
192 
193  TrackerMap tkMap{" Detector Inefficiency "};
194  TrackerMap tkMapBad{" Inefficient Modules "};
195  TrackerMap tkMapEff{title_};
196  TrackerMap tkMapNum{" Detector numerator "};
197  TrackerMap tkMapDen{" Detector denominator "};
198  std::map<unsigned int, double> badModules;
199 
200  for (auto det : stripDetIds_) {
201  auto layer = ::checkLayer(det, tTopo_.get());
202  const auto num = h_module_found->getValue(det);
203  const auto denom = h_module_total->getValue(det);
204  if (denom) {
205  const auto eff = num / denom;
206  hEffInLayer[layer]->Fill(eff);
207  if (!autoIneffModTagging_) {
208  if ((denom >= nModsMin_) && (eff < threshold_)) {
209  // We have a bad module, put it in the list!
210  badModules[det] = eff;
211  tkMapBad.fillc(det, 255, 0, 0);
212  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
213  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom;
214  } else {
215  //Fill the bad list with empty results for every module
216  tkMapBad.fillc(det, 255, 255, 255);
217  }
218  if (eff < threshold_)
219  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
220  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom;
221 
222  if (denom < nModsMin_) {
223  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
224  << det.rawId() << " is under occupancy at " << denom;
225  }
226  }
227  //Put any module into the TKMap
228  tkMap.fill(det, 1. - eff);
229  tkMapEff.fill(det, eff);
230  tkMapNum.fill(det, num);
231  tkMapDen.fill(det, denom);
232 
233  layerTotal[layer] += denom;
234  layerFound[layer] += num;
235  }
236  }
237 
238  if (autoIneffModTagging_) {
239  for (Long_t i = 1; i <= k_LayersAtTECEnd; i++) {
240  //Compute threshold to use for each layer
241  hEffInLayer[i]->getTH1()->GetXaxis()->SetRange(
242  3, hEffInLayer[i]->getNbinsX() + 1); // Remove from the avg modules below 1%
243  const double layer_min_eff = hEffInLayer[i]->getMean() - std::max(2.5 * hEffInLayer[i]->getRMS(), threshold_);
244  LOGPRINT << "Layer " << i << " threshold for bad modules: <" << layer_min_eff
245  << " (layer mean: " << hEffInLayer[i]->getMean() << " rms: " << hEffInLayer[i]->getRMS() << ")";
246 
247  hEffInLayer[i]->getTH1()->GetXaxis()->SetRange(1, hEffInLayer[i]->getNbinsX() + 1);
248 
249  for (auto det : stripDetIds_) {
250  const auto layer = ::checkLayer(det, tTopo_.get());
251  if (layer == i) {
252  const auto num = h_module_found->getValue(det);
253  const auto denom = h_module_total->getValue(det);
254  if (denom) {
255  const auto eff = num / denom;
256  const auto eff_up = TEfficiency::Bayesian(denom, num, .99, 1, 1, true);
257 
258  if ((denom >= nModsMin_) && (eff_up < layer_min_eff)) {
259  //We have a bad module, put it in the list!
260  badModules[det] = eff;
261  tkMapBad.fillc(det, 255, 0, 0);
262  } else {
263  //Fill the bad list with empty results for every module
264  tkMapBad.fillc(det, 255, 255, 255);
265  }
266  if (eff_up < layer_min_eff + 0.08) // printing message also for modules sligthly above (8%) the limit
267 
268  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
269  << det.rawId() << " efficiency: " << eff << " , " << num << "/" << denom
270  << " , upper limit: " << eff_up;
271  if (denom < nModsMin_) {
272  LOGPRINT << "Layer " << layer << " (" << ::layerName(layer, showRings_, nTEClayers_) << ") module "
273  << det.rawId() << " layer " << layer << " is under occupancy at " << denom;
274  }
275  }
276  }
277  }
278  }
279  }
280 
281  tkMap.save(true, 0, 0, "SiStripHitEffTKMap_NEW.png");
282  tkMapBad.save(true, 0, 0, "SiStripHitEffTKMapBad_NEW.png");
283  tkMapEff.save(true, tkMapMin_, 1., "SiStripHitEffTKMapEff_NEW.png");
284  tkMapNum.save(true, 0, 0, "SiStripHitEffTKMapNum_NEW.png");
285  tkMapDen.save(true, 0, 0, "SiStripHitEffTKMapDen_NEW.png");
286 
287  const auto detInfo =
289  SiStripQuality pQuality{detInfo};
290  //This is the list of the bad strips, use to mask out entire APVs
291  //Now simply go through the bad hit list and mask out things that
292  //are bad!
293  for (const auto it : badModules) {
294  const auto det = it.first;
295  std::vector<unsigned int> badStripList;
296  //We need to figure out how many strips are in this particular module
297  //To Mask correctly!
298  const auto nStrips = detInfo.getNumberOfApvsAndStripLength(det).first * sistrip::STRIPS_PER_APV;
299  LOGPRINT << "Number of strips module " << det << " is " << nStrips;
300  badStripList.push_back(pQuality.encode(0, nStrips, 0));
301  //Now compact into a single bad module
302  LOGPRINT << "ID1 shoudl match list of modules above " << det;
303  pQuality.compact(det, badStripList);
304  pQuality.put(det, SiStripQuality::Range(badStripList.begin(), badStripList.end()));
305  }
306  pQuality.fillBadComponents();
307  if (doStoreOnDB_) {
308  writeBadStripPayload(pQuality);
309  } else {
310  edm::LogInfo("SiStripHitEfficiencyHarvester") << "Will not produce payload!";
311  }
312 
313  printTotalStatistics(layerFound, layerTotal); // statistics by layer and subdetector
314  //LOGPRINT << "\n-----------------\nNew IOV starting from run " << e.id().run() << " event " << e.id().event()
315  // << " lumiBlock " << e.luminosityBlock() << " time " << e.time().value() << "\n-----------------\n";
316  printAndWriteBadModules(pQuality, detInfo); // TODO
317 
318  if (!isAtPCL_) {
320  makeSummary(getter, *fs); // TODO
321  makeSummaryVsBX(getter, *fs); // TODO
322  makeSummaryVsCM(getter, *fs); // TODO
323  }
324 
325  makeSummaryVsLumi(getter); // TODO
326 }
327 
329  const std::array<long, bounds::k_END_OF_LAYERS>& layerFound,
330  const std::array<long, bounds::k_END_OF_LAYERS>& layerTotal) const {
331  //Calculate the statistics by layer
332  int totalfound = 0;
333  int totaltotal = 0;
334  double layereff;
335  int subdetfound[5];
336  int subdettotal[5];
337 
338  for (Long_t i = 1; i < 5; i++) {
339  subdetfound[i] = 0;
340  subdettotal[i] = 0;
341  }
342 
343  for (Long_t i = 1; i <= bounds::k_LayersAtTECEnd; i++) {
344  layereff = double(layerFound[i]) / double(layerTotal[i]);
345  LOGPRINT << "Layer " << i << " (" << ::layerName(i, showRings_, nTEClayers_) << ") has total efficiency "
346  << layereff << " " << layerFound[i] << "/" << layerTotal[i];
347  totalfound += layerFound[i];
348  totaltotal += layerTotal[i];
349  if (i <= bounds::k_LayersAtTIBEnd) {
350  subdetfound[1] += layerFound[i];
351  subdettotal[1] += layerTotal[i];
352  }
353  if (i > bounds::k_LayersAtTIBEnd && i <= bounds::k_LayersAtTOBEnd) {
354  subdetfound[2] += layerFound[i];
355  subdettotal[2] += layerTotal[i];
356  }
357  if (i > bounds::k_LayersAtTOBEnd && i <= bounds::k_LayersAtTIDEnd) {
358  subdetfound[3] += layerFound[i];
359  subdettotal[3] += layerTotal[i];
360  }
361  if (i > bounds::k_LayersAtTIDEnd) {
362  subdetfound[4] += layerFound[i];
363  subdettotal[4] += layerTotal[i];
364  }
365  }
366 
367  LOGPRINT << "The total efficiency is " << double(totalfound) / double(totaltotal);
368  LOGPRINT << " TIB: " << double(subdetfound[1]) / subdettotal[1] << " " << subdetfound[1] << "/"
369  << subdettotal[1];
370  LOGPRINT << " TOB: " << double(subdetfound[2]) / subdettotal[2] << " " << subdetfound[2] << "/"
371  << subdettotal[2];
372  LOGPRINT << " TID: " << double(subdetfound[3]) / subdettotal[3] << " " << subdetfound[3] << "/"
373  << subdettotal[3];
374  LOGPRINT << " TEC: " << double(subdetfound[4]) / subdettotal[4] << " " << subdetfound[4] << "/"
375  << subdettotal[4];
376 }
377 
379  SiStripBadStrip pBadStrip{};
380  const auto pQdvBegin = quality.getDataVectorBegin();
381  for (auto rIt = quality.getRegistryVectorBegin(); rIt != quality.getRegistryVectorEnd(); ++rIt) {
382  const auto range = SiStripBadStrip::Range(pQdvBegin + rIt->ibegin, pQdvBegin + rIt->iend);
383  if (!pBadStrip.put(rIt->detid, range))
384  edm::LogError("SiStripHitEfficiencyHarvester") << "detid already exists in SiStripBadStrip";
385  }
387  if (poolDbService.isAvailable()) {
388  poolDbService->writeOneIOV(pBadStrip, poolDbService->currentTime(), record_);
389  } else {
390  throw cms::Exception("PoolDBService required");
391  }
392 }
393 
395  // use goodlayer_total/found and alllayer_total/found, collapse side and/or ring if needed
396 }
397 
399  // use found/totalVsBx_layer%i [0,23)
400 }
401 
403  for (unsigned int iLayer = 1; iLayer != (showRings_ ? 20 : 22); ++iLayer) {
404  auto hfound = getter.get(fmt::format("{}/VsLumi/layerfound_vsLumi_layer_{}", inputFolder_, iLayer))->getTH1F();
405  auto htotal = getter.get(fmt::format("{}/VsLumi/layertotal_vsLumi_layer_{}", inputFolder_, iLayer))->getTH1F();
406 
407  if (hfound == nullptr or htotal == nullptr) {
408  if (hfound == nullptr)
409  edm::LogError("SiStripHitEfficiencyHarvester")
410  << fmt::format("{}/VsLumi/layerfound_vsLumi_layer_{}", inputFolder_, iLayer) << " was not found!";
411  if (htotal == nullptr)
412  edm::LogError("SiStripHitEfficiencyHarvester")
413  << fmt::format("{}/VsLumi/layertotal_vsLumi_layer_{}", inputFolder_, iLayer) << " was not found!";
414  // no input histograms -> continue in the loop
415  continue;
416  }
417 
418  if (!hfound->GetSumw2())
419  hfound->Sumw2();
420  if (!htotal->GetSumw2())
421  htotal->Sumw2();
422  for (Long_t i = 0; i != hfound->GetNbinsX() + 1; ++i) {
423  if (hfound->GetBinContent(i) == 0)
424  hfound->SetBinContent(i, 1e-6);
425  if (htotal->GetBinContent(i) == 0)
426  htotal->SetBinContent(i, 1);
427  }
428  LogDebug("SiStripHitEfficiencyHarvester")
429  << "Total hits for layer " << iLayer << " (vs lumi): " << htotal->GetEntries() << ", found "
430  << hfound->GetEntries();
431  }
432  // continue
433 }
434 
436 
437 namespace {
438  void setBadComponents(int i,
439  int comp,
441  std::stringstream ssV[4][19],
442  int nBad[4][19][4],
443  int nAPV) {
444  ssV[i][comp] << "\n\t\t " << bc.detid << " \t " << bc.BadModule << " \t " << ((bc.BadFibers) & 0x1) << " ";
445  if (nAPV == 4)
446  ssV[i][comp] << "x " << ((bc.BadFibers >> 1) & 0x1);
447 
448  if (nAPV == 6)
449  ssV[i][comp] << ((bc.BadFibers >> 1) & 0x1) << " " << ((bc.BadFibers >> 2) & 0x1);
450  ssV[i][comp] << " \t " << ((bc.BadApvs) & 0x1) << " " << ((bc.BadApvs >> 1) & 0x1) << " ";
451  if (nAPV == 4)
452  ssV[i][comp] << "x x " << ((bc.BadApvs >> 2) & 0x1) << " " << ((bc.BadApvs >> 3) & 0x1);
453  if (nAPV == 6)
454  ssV[i][comp] << ((bc.BadApvs >> 2) & 0x1) << " " << ((bc.BadApvs >> 3) & 0x1) << " " << ((bc.BadApvs >> 4) & 0x1)
455  << " " << ((bc.BadApvs >> 5) & 0x1) << " ";
456 
457  if (bc.BadApvs) {
458  nBad[i][0][2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
459  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
460  nBad[i][comp][2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
461  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
462  }
463  if (bc.BadFibers) {
464  nBad[i][0][1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
465  nBad[i][comp][1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
466  }
467  if (bc.BadModule) {
468  nBad[i][0][0]++;
469  nBad[i][comp][0]++;
470  }
471  }
472 } // namespace
473 
475  const SiStripDetInfo& detInfo) const {
477  //try to write out what's in the quality record
479  int nTkBadComp[4]; //k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
480  int nBadComp[4][19][4];
481  //legend: nBadComp[i][j][k]= SubSystem i, layer/disk/wheel j, BadModule/Fiber/Apv k
482  // i: 0=TIB, 1=TID, 2=TOB, 3=TEC
483  // k: 0=BadModule, 1=BadFiber, 2=BadApv, 3=BadStrips
484  std::stringstream ssV[4][19];
485 
486  for (int i = 0; i < 4; ++i) {
487  nTkBadComp[i] = 0;
488  for (int j = 0; j < 19; ++j) {
489  ssV[i][j].str("");
490  for (int k = 0; k < 4; ++k)
491  nBadComp[i][j][k] = 0;
492  }
493  }
494 
495  for (const auto& bc : quality.getBadComponentList()) {
496  // Full Tk
497  if (bc.BadModule)
498  nTkBadComp[0]++;
499  if (bc.BadFibers)
500  nTkBadComp[1] += ((bc.BadFibers >> 2) & 0x1) + ((bc.BadFibers >> 1) & 0x1) + ((bc.BadFibers) & 0x1);
501  if (bc.BadApvs)
502  nTkBadComp[2] += ((bc.BadApvs >> 5) & 0x1) + ((bc.BadApvs >> 4) & 0x1) + ((bc.BadApvs >> 3) & 0x1) +
503  ((bc.BadApvs >> 2) & 0x1) + ((bc.BadApvs >> 1) & 0x1) + ((bc.BadApvs) & 0x1);
504  // single subsystem
505  DetId det(bc.detid);
506  if ((det.subdetId() >= SiStripSubdetector::TIB) && (det.subdetId() <= SiStripSubdetector::TEC)) {
507  const auto nAPV = detInfo.getNumberOfApvsAndStripLength(det).first;
508  switch (det.subdetId()) {
510  setBadComponents(0, tTopo_->tibLayer(det), bc, ssV, nBadComp, nAPV);
511  break;
514  (tTopo_->tidSide(det) == 2 ? tTopo_->tidWheel(det) : tTopo_->tidWheel(det) + 3),
515  bc,
516  ssV,
517  nBadComp,
518  nAPV);
519  break;
521  setBadComponents(2, tTopo_->tobLayer(det), bc, ssV, nBadComp, nAPV);
522  break;
525  (tTopo_->tecSide(det) == 2 ? tTopo_->tecWheel(det) : tTopo_->tecWheel(det) + 9),
526  bc,
527  ssV,
528  nBadComp,
529  nAPV);
530  break;
531  default:
532  break;
533  }
534  }
535  }
536  // single strip info
537  for (auto rp = quality.getRegistryVectorBegin(); rp != quality.getRegistryVectorEnd(); ++rp) {
538  DetId det{rp->detid};
539  int subdet = -999;
540  int component = -999;
541  switch (det.subdetId()) {
543  subdet = 0;
544  component = tTopo_->tibLayer(det);
545  break;
547  subdet = 1;
548  component = tTopo_->tidSide(det) == 2 ? tTopo_->tidWheel(det) : tTopo_->tidWheel(det) + 3;
549  break;
551  subdet = 2;
552  component = tTopo_->tobLayer(det);
553  break;
555  subdet = 3;
556  component = tTopo_->tecSide(det) == 2 ? tTopo_->tecWheel(det) : tTopo_->tecWheel(det) + 9;
557  break;
558  default:
559  break;
560  }
561 
562  const auto pQdvBegin = quality.getDataVectorBegin();
563  const auto sqrange = SiStripQuality::Range(pQdvBegin + rp->ibegin, pQdvBegin + rp->iend);
564  float percentage = 0;
565  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
566  unsigned int range = quality.decode(*(sqrange.first + it)).range;
567  nTkBadComp[3] += range;
568  nBadComp[subdet][0][3] += range;
569  nBadComp[subdet][component][3] += range;
570  percentage += range;
571  }
572  if (percentage != 0)
573  percentage /= (sistrip::STRIPS_PER_APV * detInfo.getNumberOfApvsAndStripLength(det).first);
574  if (percentage > 1)
575  edm::LogError("SiStripHitEfficiencyHarvester") << "PROBLEM detid " << det.rawId() << " value " << percentage;
576  }
577 
578  // printout
579  std::ostringstream ss;
580  ss << "\n-----------------\nGlobal Info\n-----------------";
581  ss << "\nBadComp \t Modules \tFibers "
582  "\tApvs\tStrips\n----------------------------------------------------------------";
583  ss << "\nTracker:\t\t" << nTkBadComp[0] << "\t" << nTkBadComp[1] << "\t" << nTkBadComp[2] << "\t" << nTkBadComp[3];
584  ss << "\nTIB:\t\t\t" << nBadComp[0][0][0] << "\t" << nBadComp[0][0][1] << "\t" << nBadComp[0][0][2] << "\t"
585  << nBadComp[0][0][3];
586  ss << "\nTID:\t\t\t" << nBadComp[1][0][0] << "\t" << nBadComp[1][0][1] << "\t" << nBadComp[1][0][2] << "\t"
587  << nBadComp[1][0][3];
588  ss << "\nTOB:\t\t\t" << nBadComp[2][0][0] << "\t" << nBadComp[2][0][1] << "\t" << nBadComp[2][0][2] << "\t"
589  << nBadComp[2][0][3];
590  ss << "\nTEC:\t\t\t" << nBadComp[3][0][0] << "\t" << nBadComp[3][0][1] << "\t" << nBadComp[3][0][2] << "\t"
591  << nBadComp[3][0][3];
592  ss << "\n";
593 
594  for (int i = 1; i < 5; ++i)
595  ss << "\nTIB Layer " << i << " :\t\t" << nBadComp[0][i][0] << "\t" << nBadComp[0][i][1] << "\t" << nBadComp[0][i][2]
596  << "\t" << nBadComp[0][i][3];
597  ss << "\n";
598  for (int i = 1; i < 4; ++i)
599  ss << "\nTID+ Disk " << i << " :\t\t" << nBadComp[1][i][0] << "\t" << nBadComp[1][i][1] << "\t" << nBadComp[1][i][2]
600  << "\t" << nBadComp[1][i][3];
601  for (int i = 4; i < 7; ++i)
602  ss << "\nTID- Disk " << i - 3 << " :\t\t" << nBadComp[1][i][0] << "\t" << nBadComp[1][i][1] << "\t"
603  << nBadComp[1][i][2] << "\t" << nBadComp[1][i][3];
604  ss << "\n";
605  for (int i = 1; i < 7; ++i)
606  ss << "\nTOB Layer " << i << " :\t\t" << nBadComp[2][i][0] << "\t" << nBadComp[2][i][1] << "\t" << nBadComp[2][i][2]
607  << "\t" << nBadComp[2][i][3];
608  ss << "\n";
609  for (int i = 1; i < 10; ++i)
610  ss << "\nTEC+ Disk " << i << " :\t\t" << nBadComp[3][i][0] << "\t" << nBadComp[3][i][1] << "\t" << nBadComp[3][i][2]
611  << "\t" << nBadComp[3][i][3];
612  for (int i = 10; i < 19; ++i)
613  ss << "\nTEC- Disk " << i - 9 << " :\t\t" << nBadComp[3][i][0] << "\t" << nBadComp[3][i][1] << "\t"
614  << nBadComp[3][i][2] << "\t" << nBadComp[3][i][3];
615  ss << "\n";
616 
617  ss << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
618  "Apvs\n----------------------------------------------------------------";
619  for (int i = 1; i < 5; ++i)
620  ss << "\nTIB Layer " << i << " :" << ssV[0][i].str();
621  ss << "\n";
622  for (int i = 1; i < 4; ++i)
623  ss << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
624  for (int i = 4; i < 7; ++i)
625  ss << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
626  ss << "\n";
627  for (int i = 1; i < 7; ++i)
628  ss << "\nTOB Layer " << i << " :" << ssV[2][i].str();
629  ss << "\n";
630  for (int i = 1; i < 10; ++i)
631  ss << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
632  for (int i = 10; i < 19; ++i)
633  ss << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
634 
635  LOGPRINT << ss.str();
636 
637  // store also bad modules in log file
638  std::ofstream badModules;
639  badModules.open("BadModules_NEW.log");
640  badModules << "\n----------------------------------------------------------------\n\t\t Detid \tModules Fibers "
641  "Apvs\n----------------------------------------------------------------";
642  for (int i = 1; i < 5; ++i)
643  badModules << "\nTIB Layer " << i << " :" << ssV[0][i].str();
644  badModules << "\n";
645  for (int i = 1; i < 4; ++i)
646  badModules << "\nTID+ Disk " << i << " :" << ssV[1][i].str();
647  for (int i = 4; i < 7; ++i)
648  badModules << "\nTID- Disk " << i - 3 << " :" << ssV[1][i].str();
649  badModules << "\n";
650  for (int i = 1; i < 7; ++i)
651  badModules << "\nTOB Layer " << i << " :" << ssV[2][i].str();
652  badModules << "\n";
653  for (int i = 1; i < 10; ++i)
654  badModules << "\nTEC+ Disk " << i << " :" << ssV[3][i].str();
655  for (int i = 10; i < 19; ++i)
656  badModules << "\nTEC- Disk " << i - 9 << " :" << ssV[3][i].str();
657  badModules.close();
658 }
659 
662  desc.add<std::string>("inputFolder", "AlCaReco/SiStripHitEfficiency");
663  desc.add<bool>("isAtPCL", false);
664  desc.add<bool>("doStoreOnDB", false);
665  desc.add<std::string>("Record", "SiStripBadStrip");
666  desc.add<double>("Threshold", 0.1);
667  desc.add<std::string>("Title", "Hit Efficiency");
668  desc.add<int>("nModsMin", 5);
669  desc.addUntracked<bool>("AutoIneffModTagging", false);
670  desc.addUntracked<double>("TkMapMin", 0.9);
671  desc.addUntracked<bool>("ShowRings", false);
672  descriptions.addWithDefaultLabel(desc);
673 }
674 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
constexpr char const * layerName[numberOfLayers]
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
std::unique_ptr< TrackerTopology > tTopo_
void endRun(edm::Run const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void printAndWriteBadModules(const SiStripQuality &quality, const SiStripDetInfo &detInfo) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void makeSummaryVsLumi(DQMStore::IGetter &getter) const
Log< level::Error, false > LogError
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...
constexpr std::array< uint8_t, layerIndexSize > layer
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
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
void writeBadStripPayload(const SiStripQuality &quality) const
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
Transition
Definition: Transition.h:12
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void makeSummaryVsBX(DQMStore::IGetter &getter, TFileService &fs) const
SiStripDetInfo read(std::string filePath)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void makeSummaryVsCM(DQMStore::IGetter &getter, TFileService &fs) const
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
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
Constants and enumerated types for FED/FEC systems.
virtual TH1F * getTH1F() const
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
~SiStripHitEfficiencyHarvester() override=default
HLT enums.
static const uint16_t STRIPS_PER_APV
std::pair< ContainerIterator, ContainerIterator > Range
std::unique_ptr< SiStripQuality > stripQuality_
static constexpr char const *const kDefaultFile
bool isAvailable() const
Definition: Service.h:40
const edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
string quality
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)
void makeSummary(DQMStore::IGetter &getter, TFileService &fs) const
Definition: Run.h:45
#define LogDebug(id)
unsigned transform(const HcalDetId &id, unsigned transformCode)