CMS 3D CMS Logo

SiStripCertificationInfo.cc
Go to the documentation of this file.
19 
20 #include <iostream>
21 #include <fstream>
22 #include <string>
23 #include <vector>
24 #include <map>
25 
26 class SiStripDetCabling;
27 
29  : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
30 public:
33 
35 
36 private:
37  void beginRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
38  void beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override{};
39  void endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) override;
40  void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
41  void analyze(edm::Event const&, edm::EventSetup const&) override;
42 
43  void bookSiStripCertificationMEs(DQMStore& dqm_store);
44  void resetSiStripCertificationMEs(DQMStore& dqm_store);
45  void fillSiStripCertificationMEs(DQMStore& dqm_store, edm::EventSetup const& eSetup);
46 
47  void fillDummySiStripCertification(DQMStore& dqm_store);
49 
50  struct SubDetMEs {
54  int n_layer;
55  };
56 
59  std::map<std::string, SubDetMEs> SubDetMEsMap{};
61 
63 
65 
67 
71 };
72 
74  : detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
75  tTopoToken_(esConsumes<edm::Transition::EndRun>()),
76  runInfoToken_(esConsumes<edm::Transition::BeginRun>()) {
77  usesResource("DQMStore");
78  consumes<DQMToken, edm::InRun>(edm::InputTag("siStripOfflineAnalyser", "DQMGenerationSiStripAnalyserRun"));
79  consumes<DQMToken, edm::InLumi>(edm::InputTag("siStripOfflineAnalyser", "DQMGenerationSiStripAnalyserLumi"));
80 }
81 
83  edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: Begining of Run";
85 
86  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
87  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
88 
89  if (eSetup.tryToGet<RunInfoRcd>()) {
90  if (auto sumFED = eSetup.getHandle(runInfoToken_)) {
91  for (auto const fedID : sumFED->m_fed_in) {
92  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
94  }
95  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
96  }
97  }
98 
99  auto& dqm_store = *edm::Service<DQMStore>{};
100  bookSiStripCertificationMEs(dqm_store);
102 }
103 //
104 // -- Book MEs for SiStrip Sertification fractions
105 //
108  return;
109 
110  dqm_store.cd();
111  std::string strip_dir = "";
112  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
113  if (!strip_dir.empty())
114  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
115  else
116  dqm_store.setCurrentFolder("SiStrip/EventInfo");
117 
118  SiStripCertification = dqm_store.bookFloat("CertificationSummary");
119 
120  std::string hname = "CertificationReportMap";
121  std::string htitle = "SiStrip Certification for Good Detector Fraction";
122  SiStripCertificationSummaryMap = dqm_store.book2D(hname, htitle, 6, 0.5, 6.5, 9, 0.5, 9.5);
123  SiStripCertificationSummaryMap->setAxisTitle("Sub Detector Type", 1);
124  SiStripCertificationSummaryMap->setAxisTitle("Layer/Disc Number", 2);
125  int ibin = 0;
126  for (auto const& pr : SubDetMEsMap) {
127  ++ibin;
128  auto const& det = pr.first;
130  }
131 
132  SubDetMEs local_mes;
134  dqm_store.cd();
135  if (!strip_dir.empty())
136  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/CertificationContents");
137  else
138  dqm_store.setCurrentFolder("SiStrip/EventInfo/CertificationContents");
139  tag = "TIB";
140 
141  local_mes.folder_name = "TIB";
142  local_mes.subdet_tag = "TIB";
143  local_mes.n_layer = 4;
144  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
145  SubDetMEsMap.emplace(tag, local_mes);
146 
147  tag = "TOB";
148  local_mes.folder_name = "TOB";
149  local_mes.subdet_tag = "TOB";
150  local_mes.n_layer = 6;
151  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
152  SubDetMEsMap.emplace(tag, local_mes);
153 
154  tag = "TECF";
155  local_mes.folder_name = "TEC/PLUS";
156  local_mes.subdet_tag = "TEC+";
157  local_mes.n_layer = 9;
158  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
159  SubDetMEsMap.emplace(tag, local_mes);
160 
161  tag = "TECB";
162  local_mes.folder_name = "TEC/MINUS";
163  local_mes.subdet_tag = "TEC-";
164  local_mes.n_layer = 9;
165  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
166  SubDetMEsMap.emplace(tag, local_mes);
167 
168  tag = "TIDF";
169  local_mes.folder_name = "TID/PLUS";
170  local_mes.subdet_tag = "TID+";
171  local_mes.n_layer = 3;
172  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
173  SubDetMEsMap.emplace(tag, local_mes);
174 
175  tag = "TIDB";
176  local_mes.folder_name = "TID/MINUS";
177  local_mes.subdet_tag = "TID-";
178  local_mes.n_layer = 3;
179  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
180  SubDetMEsMap.emplace(tag, local_mes);
181 
182  dqm_store.cd();
183  if (!strip_dir.empty())
184  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
185 
187  dqm_store.cd();
188 }
189 
191 
193  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
194 
195  if (nFEDConnected_ > 0) {
196  auto& dqm_store = *edm::Service<DQMStore>{};
198  }
199 }
200 
202  edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: End Run";
203 
204  if (nFEDConnected_ > 0) {
205  auto& dqm_store = *edm::Service<DQMStore>{};
206  fillSiStripCertificationMEs(dqm_store, eSetup);
207  }
208 }
209 
210 //
211 // --Fill SiStrip Certification
212 //
215  edm::LogError("SiStripCertificationInfo")
216  << " SiStripCertificationInfo::fillSiStripCertificationMEs : MEs missing ";
217  return;
218  }
219 
220  //Retrieve tracker topology from geometry
221  const auto tTopo = &eSetup.getData(tTopoToken_);
222 
223  resetSiStripCertificationMEs(dqm_store);
224  std::string mdir = "MechanicalView";
225  dqm_store.cd();
226  if (!SiStripUtility::goToDir(dqm_store, mdir))
227  return;
228  std::string mechanical_dir = dqm_store.pwd();
229  uint16_t nDetTot = 0;
230  uint16_t nFaultyTot = 0;
231  uint16_t nSToNTot = 0;
232  float sToNTot = 0.0;
233  SiStripFolderOrganizer folder_organizer;
234  int xbin = 0;
235  for (auto const& [name, subDetME] : SubDetMEsMap) {
236  ++xbin;
237  MonitorElement* me = subDetME.det_fractionME;
238  if (!me)
239  continue;
240  std::string tag = subDetME.subdet_tag;
241  std::string bad_module_folder = mechanical_dir + "/" + subDetME.folder_name + "/" + "BadModuleList";
242  std::vector<MonitorElement*> faulty_detMEs = dqm_store.getContents(bad_module_folder);
243 
244  uint16_t ndet_subdet = 0;
245  uint16_t nfaulty_subdet = 0;
246  int nlayer = subDetME.n_layer;
247  int ybin = 0;
248  for (int ilayer = 0; ilayer < nlayer; ilayer++) {
249  uint16_t ndet_layer = detCabling_->connectedNumber(tag, ilayer + 1);
250  ndet_subdet += ndet_layer;
251  ybin++;
252  uint16_t nfaulty_layer = 0;
253  for (auto me : faulty_detMEs) {
254  if (me->kind() != MonitorElement::Kind::INT)
255  continue;
256  if (me->getIntValue() == 0)
257  continue;
258  uint32_t detId = atoi(me->getName().c_str());
259  std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detId, tTopo, false);
260  if (abs(det_layer_pair.second) == ilayer + 1)
261  nfaulty_layer++;
262  }
263 
264  nfaulty_subdet += nfaulty_layer;
265  float fraction_layer = -1.0;
266  if (ndet_layer > 0)
267  fraction_layer = 1 - ((nfaulty_layer * 1.0) / ndet_layer);
269  SiStripCertificationSummaryMap->Fill(xbin, ilayer + 1, fraction_layer);
270  }
271  if (ybin <= SiStripCertificationSummaryMap->getNbinsY()) {
272  for (int k = ybin + 1; k <= SiStripCertificationSummaryMap->getNbinsY(); k++)
273  SiStripCertificationSummaryMap->Fill(xbin, k, -1.0);
274  }
275  float fraction_subdet = -1.0;
276  if (ndet_subdet > 0)
277  fraction_subdet = 1 - ((nfaulty_subdet * 1.0) / ndet_subdet);
278  // Check S/N status flag and use the minimum between the two
279  std::string full_path = mechanical_dir.substr(0, mechanical_dir.find_last_of('/')) +
280  "/EventInfo/reportSummaryContents/SiStrip_SToNFlag_" + name;
281  MonitorElement* me_ston = dqm_store.get(full_path);
282  me->Reset();
283  if (me_ston && me_ston->kind() == MonitorElement::Kind::REAL) {
284  float ston_flg = me_ston->getFloatValue();
285  sToNTot += ston_flg;
286  nSToNTot++;
287  me->Fill(fminf(fraction_subdet, ston_flg));
288  } else
289  me->Fill(fraction_subdet);
290  nDetTot += ndet_subdet;
291  nFaultyTot += nfaulty_subdet;
292  }
293  float fraction_global = -1.0;
294  if (nDetTot > 0)
295  fraction_global = 1.0 - ((nFaultyTot * 1.0) / nDetTot);
296  float ston_frac_global = 1.0;
297  if (nSToNTot > 0)
298  ston_frac_global = sToNTot / nSToNTot;
299  SiStripCertification->Fill(fminf(fraction_global, ston_frac_global));
300 }
301 //
302 // --Fill SiStrip Certification
303 //
306  bookSiStripCertificationMEs(dqm_store);
307  }
309 
311  for (auto const& pr : SubDetMEsMap) {
312  pr.second.det_fractionME->Reset();
313  }
315 }
316 //
317 // -- Fill Dummy SiStrip Certification
318 //
320  resetSiStripCertificationMEs(dqm_store);
322  SiStripCertification->Fill(-1.0);
323  for (auto const& pr : SubDetMEsMap) {
324  pr.second.det_fractionME->Reset();
325  pr.second.det_fractionME->Fill(-1.0);
326  }
327 
328  for (int xbin = 1; xbin < SiStripCertificationSummaryMap->getNbinsX() + 1; xbin++) {
329  for (int ybin = 1; ybin < SiStripCertificationSummaryMap->getNbinsY() + 1; ybin++) {
330  SiStripCertificationSummaryMap->Fill(xbin, ybin, -1.0);
331  }
332  }
333  }
334 }
335 //
336 // --Fill SiStrip Certification
337 //
340  edm::LogError("SiStripCertificationInfo")
341  << " SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi : MEs missing ";
342  return;
343  }
344  resetSiStripCertificationMEs(dqm_store);
345  dqm_store.cd();
346  std::string strip_dir = "";
347  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
348  if (strip_dir.empty())
349  strip_dir = "SiStrip";
350 
351  std::string full_path;
352  float dcs_flag = 1.0;
353  float dqm_flag = 1.0;
354  for (auto const& [type, subDetME] : SubDetMEsMap) {
355  full_path = strip_dir + "/EventInfo/DCSContents/SiStrip_" + type;
356  MonitorElement* me_dcs = dqm_store.get(full_path);
357  if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
358  dcs_flag = me_dcs->getFloatValue();
359  full_path = strip_dir + "/EventInfo/reportSummaryContents/SiStrip_" + type;
360  MonitorElement* me_dqm = dqm_store.get(full_path);
361  if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
362  dqm_flag = me_dqm->getFloatValue();
363  subDetME.det_fractionME->Reset();
364  subDetME.det_fractionME->Fill(fminf(dqm_flag, dcs_flag));
365  }
366  dcs_flag = 1.0;
367  dqm_flag = 1.0;
368  full_path = strip_dir + "/EventInfo/reportSummary";
369  MonitorElement* me_dqm = dqm_store.get(full_path);
370  if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
371  dqm_flag = me_dqm->getFloatValue();
372  full_path = strip_dir + "/EventInfo/DCSSummary";
373  MonitorElement* me_dcs = dqm_store.get(full_path);
374  if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
375  dcs_flag = me_dcs->getFloatValue();
377  SiStripCertification->Fill(fminf(dqm_flag, dcs_flag));
378 }
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
dqm::harvesting::DQMStore DQMStore
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
std::optional< T > tryToGet() const
Definition: EventSetup.h:100
Kind kind() const
Get the type of the monitor element.
edm::ESHandle< SiStripDetCabling > detCabling_
std::string pwd() override
Definition: DQMStore.h:644
Log< level::Error, false > LogError
assert(be >=bs)
void fillSiStripCertificationMEsAtLumi(DQMStore &dqm_store)
void Fill(long long x)
const edm::ESGetToken< RunInfo, RunInfoRcd > runInfoToken_
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
std::map< std::string, SubDetMEs > SubDetMEsMap
virtual double getFloatValue() const
void resetSiStripCertificationMEs(DQMStore &dqm_store)
SiStripCertificationInfo(const edm::ParameterSet &ps)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Transition
Definition: Transition.h:12
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void fillDummySiStripCertification(DQMStore &dqm_store)
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
dqm::harvesting::MonitorElement MonitorElement
virtual int getNbinsY() const
get # of bins in Y-axis
Log< level::Info, false > LogInfo
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
const edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > detCablingToken_
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
void bookSiStripCertificationMEs(DQMStore &dqm_store)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
std::pair< std::string, int32_t > GetSubDetAndLayer(const uint32_t &detid, const TrackerTopology *tTopo, bool ring_flag=false)
MonitorElement * SiStripCertificationSummaryMap
HLT enums.
void fillSiStripCertificationMEs(DQMStore &dqm_store, edm::EventSetup const &eSetup)
static bool goToDir(DQMStore &dqm_store, std::string const &name)
virtual int getNbinsX() const
get # of bins in X-axis
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &eSetup) override
uint32_t connectedNumber(const std::string &subDet, const uint16_t layer) const
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
Definition: event.py:1
Definition: Run.h:45
void analyze(edm::Event const &, edm::EventSetup const &) override
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:625
#define LogDebug(id)
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)