CMS 3D CMS Logo

SiStripCertificationInfo.cc
Go to the documentation of this file.
4 
9 
13 
17 
18 //Run Info
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <cstdio>
26 #include <string>
27 #include <sstream>
28 #include <cmath>
29 
31 
33  edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: Begining of Run";
34  unsigned long long cacheID = eSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
35  if (m_cacheID_ != cacheID) {
36  m_cacheID_ = cacheID;
37  }
38  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
39 
40  constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
41  constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
42 
43  if (auto runInfoRec = eSetup.tryToGet<RunInfoRcd>()) {
45  runInfoRec->get(sumFED);
46 
47  if (sumFED.isValid()) {
48  for (auto const fedID : sumFED->m_fed_in) {
49  if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
51  }
52  LogDebug("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
53  }
54  }
55 
56  auto& dqm_store = *edm::Service<DQMStore>{};
57  bookSiStripCertificationMEs(dqm_store);
59 }
60 //
61 // -- Book MEs for SiStrip Sertification fractions
62 //
65  return;
66 
67  dqm_store.cd();
68  std::string strip_dir = "";
69  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
70  if (!strip_dir.empty())
71  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
72  else
73  dqm_store.setCurrentFolder("SiStrip/EventInfo");
74 
75  SiStripCertification = dqm_store.bookFloat("CertificationSummary");
76 
77  std::string hname = "CertificationReportMap";
78  std::string htitle = "SiStrip Certification for Good Detector Fraction";
79  SiStripCertificationSummaryMap = dqm_store.book2D(hname, htitle, 6, 0.5, 6.5, 9, 0.5, 9.5);
80  SiStripCertificationSummaryMap->setAxisTitle("Sub Detector Type", 1);
81  SiStripCertificationSummaryMap->setAxisTitle("Layer/Disc Number", 2);
82  int ibin = 0;
83  for (auto const& pr : SubDetMEsMap) {
84  ++ibin;
85  auto const& det = pr.first;
87  }
88 
89  SubDetMEs local_mes;
91  dqm_store.cd();
92  if (!strip_dir.empty())
93  dqm_store.setCurrentFolder(strip_dir + "/EventInfo/CertificationContents");
94  else
95  dqm_store.setCurrentFolder("SiStrip/EventInfo/CertificationContents");
96  tag = "TIB";
97 
98  local_mes.folder_name = "TIB";
99  local_mes.subdet_tag = "TIB";
100  local_mes.n_layer = 4;
101  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
102  SubDetMEsMap.emplace(tag, local_mes);
103 
104  tag = "TOB";
105  local_mes.folder_name = "TOB";
106  local_mes.subdet_tag = "TOB";
107  local_mes.n_layer = 6;
108  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
109  SubDetMEsMap.emplace(tag, local_mes);
110 
111  tag = "TECF";
112  local_mes.folder_name = "TEC/PLUS";
113  local_mes.subdet_tag = "TEC+";
114  local_mes.n_layer = 9;
115  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
116  SubDetMEsMap.emplace(tag, local_mes);
117 
118  tag = "TECB";
119  local_mes.folder_name = "TEC/MINUS";
120  local_mes.subdet_tag = "TEC-";
121  local_mes.n_layer = 9;
122  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
123  SubDetMEsMap.emplace(tag, local_mes);
124 
125  tag = "TIDF";
126  local_mes.folder_name = "TID/PLUS";
127  local_mes.subdet_tag = "TID+";
128  local_mes.n_layer = 3;
129  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
130  SubDetMEsMap.emplace(tag, local_mes);
131 
132  tag = "TIDB";
133  local_mes.folder_name = "TID/MINUS";
134  local_mes.subdet_tag = "TID-";
135  local_mes.n_layer = 3;
136  local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
137  SubDetMEsMap.emplace(tag, local_mes);
138 
139  dqm_store.cd();
140  if (!strip_dir.empty())
141  dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
142 
144  dqm_store.cd();
145 }
146 
148 
150  edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
151 
152  if (nFEDConnected_ > 0) {
153  auto& dqm_store = *edm::Service<DQMStore>{};
155  }
156 }
157 
159  edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: End Run";
160 
161  if (nFEDConnected_ > 0) {
162  auto& dqm_store = *edm::Service<DQMStore>{};
163  fillSiStripCertificationMEs(dqm_store, eSetup);
164  }
165 }
166 
167 //
168 // --Fill SiStrip Certification
169 //
172  edm::LogError("SiStripCertificationInfo")
173  << " SiStripCertificationInfo::fillSiStripCertificationMEs : MEs missing ";
174  return;
175  }
176 
177  //Retrieve tracker topology from geometry
178  edm::ESHandle<TrackerTopology> tTopoHandle;
179  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
180  const TrackerTopology* const tTopo = tTopoHandle.product();
181 
182  resetSiStripCertificationMEs(dqm_store);
183  std::string mdir = "MechanicalView";
184  dqm_store.cd();
185  if (!SiStripUtility::goToDir(dqm_store, mdir))
186  return;
187  std::string mechanical_dir = dqm_store.pwd();
188  uint16_t nDetTot = 0;
189  uint16_t nFaultyTot = 0;
190  uint16_t nSToNTot = 0;
191  float sToNTot = 0.0;
192  SiStripFolderOrganizer folder_organizer;
193  int xbin = 0;
194  for (auto const& [name, subDetME] : SubDetMEsMap) {
195  ++xbin;
196  MonitorElement* me = subDetME.det_fractionME;
197  if (!me)
198  continue;
199  std::string tag = subDetME.subdet_tag;
200  std::string bad_module_folder = mechanical_dir + "/" + subDetME.folder_name + "/" + "BadModuleList";
201  std::vector<MonitorElement*> faulty_detMEs = dqm_store.getContents(bad_module_folder);
202 
203  uint16_t ndet_subdet = 0;
204  uint16_t nfaulty_subdet = 0;
205  int nlayer = subDetME.n_layer;
206  int ybin = 0;
207  for (int ilayer = 0; ilayer < nlayer; ilayer++) {
208  uint16_t ndet_layer = detCabling_->connectedNumber(tag, ilayer + 1);
209  ndet_subdet += ndet_layer;
210  ybin++;
211  uint16_t nfaulty_layer = 0;
212  for (auto me : faulty_detMEs) {
213  if (me->kind() != MonitorElement::Kind::INT)
214  continue;
215  if (me->getIntValue() == 0)
216  continue;
217  uint32_t detId = atoi(me->getName().c_str());
218  std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detId, tTopo, false);
219  if (abs(det_layer_pair.second) == ilayer + 1)
220  nfaulty_layer++;
221  }
222 
223  nfaulty_subdet += nfaulty_layer;
224  float fraction_layer = -1.0;
225  if (ndet_layer > 0)
226  fraction_layer = 1 - ((nfaulty_layer * 1.0) / ndet_layer);
228  SiStripCertificationSummaryMap->Fill(xbin, ilayer + 1, fraction_layer);
229  }
230  if (ybin <= SiStripCertificationSummaryMap->getNbinsY()) {
231  for (int k = ybin + 1; k <= SiStripCertificationSummaryMap->getNbinsY(); k++)
232  SiStripCertificationSummaryMap->Fill(xbin, k, -1.0);
233  }
234  float fraction_subdet = -1.0;
235  if (ndet_subdet > 0)
236  fraction_subdet = 1 - ((nfaulty_subdet * 1.0) / ndet_subdet);
237  // Check S/N status flag and use the minimum between the two
238  std::string full_path = mechanical_dir.substr(0, mechanical_dir.find_last_of("/")) +
239  "/EventInfo/reportSummaryContents/SiStrip_SToNFlag_" + name;
240  MonitorElement* me_ston = dqm_store.get(full_path);
241  me->Reset();
242  if (me_ston && me_ston->kind() == MonitorElement::Kind::REAL) {
243  float ston_flg = me_ston->getFloatValue();
244  sToNTot += ston_flg;
245  nSToNTot++;
246  me->Fill(fminf(fraction_subdet, ston_flg));
247  } else
248  me->Fill(fraction_subdet);
249  nDetTot += ndet_subdet;
250  nFaultyTot += nfaulty_subdet;
251  }
252  float fraction_global = -1.0;
253  if (nDetTot > 0)
254  fraction_global = 1.0 - ((nFaultyTot * 1.0) / nDetTot);
255  float ston_frac_global = 1.0;
256  if (nSToNTot > 0)
257  ston_frac_global = sToNTot / nSToNTot;
258  SiStripCertification->Fill(fminf(fraction_global, ston_frac_global));
259 }
260 //
261 // --Fill SiStrip Certification
262 //
265  bookSiStripCertificationMEs(dqm_store);
266  }
268 
270  for (auto const& pr : SubDetMEsMap) {
271  pr.second.det_fractionME->Reset();
272  }
274 }
275 //
276 // -- Fill Dummy SiStrip Certification
277 //
279  resetSiStripCertificationMEs(dqm_store);
281  SiStripCertification->Fill(-1.0);
282  for (auto const& pr : SubDetMEsMap) {
283  pr.second.det_fractionME->Reset();
284  pr.second.det_fractionME->Fill(-1.0);
285  }
286 
287  for (int xbin = 1; xbin < SiStripCertificationSummaryMap->getNbinsX() + 1; xbin++) {
288  for (int ybin = 1; ybin < SiStripCertificationSummaryMap->getNbinsY() + 1; ybin++) {
289  SiStripCertificationSummaryMap->Fill(xbin, ybin, -1.0);
290  }
291  }
292  }
293 }
294 //
295 // --Fill SiStrip Certification
296 //
299  edm::LogError("SiStripCertificationInfo")
300  << " SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi : MEs missing ";
301  return;
302  }
303  resetSiStripCertificationMEs(dqm_store);
304  dqm_store.cd();
305  std::string strip_dir = "";
306  SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
307  if (strip_dir.empty())
308  strip_dir = "SiStrip";
309 
310  std::string full_path;
311  float dcs_flag = 1.0;
312  float dqm_flag = 1.0;
313  for (auto const& [type, subDetME] : SubDetMEsMap) {
314  full_path = strip_dir + "/EventInfo/DCSContents/SiStrip_" + type;
315  MonitorElement* me_dcs = dqm_store.get(full_path);
316  if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
317  dcs_flag = me_dcs->getFloatValue();
318  full_path = strip_dir + "/EventInfo/reportSummaryContents/SiStrip_" + type;
319  MonitorElement* me_dqm = dqm_store.get(full_path);
320  if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
321  dqm_flag = me_dqm->getFloatValue();
322  subDetME.det_fractionME->Reset();
323  subDetME.det_fractionME->Fill(fminf(dqm_flag, dcs_flag));
324  }
325  dcs_flag = 1.0;
326  dqm_flag = 1.0;
327  full_path = strip_dir + "/EventInfo/reportSummary";
328  MonitorElement* me_dqm = dqm_store.get(full_path);
329  if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
330  dqm_flag = me_dqm->getFloatValue();
331  full_path = strip_dir + "/EventInfo/DCSSummary";
332  MonitorElement* me_dcs = dqm_store.get(full_path);
333  if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
334  dcs_flag = me_dcs->getFloatValue();
336  SiStripCertification->Fill(fminf(dqm_flag, dcs_flag));
337 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
std::optional< T > tryToGet() const
Definition: EventSetup.h:94
MonitorElement * book2D(char_string const &name, char_string const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1178
virtual int getNbinsY() const
get # of bins in Y-axis
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
std::vector< MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:1520
virtual int64_t getIntValue() const
Kind kind() const
Get the type of the monitor element.
const std::string & getName() const
get name of ME
std::string const & pwd() const
Definition: DQMStore.cc:618
edm::ESHandle< SiStripDetCabling > detCabling_
uint32_t connectedNumber(const std::string &subDet, const uint16_t layer) const
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:621
void fillSiStripCertificationMEsAtLumi(DQMStore &dqm_store)
void Fill(long long x)
virtual void Reset()
reset ME (ie. contents, errors, etc)
MonitorElement * get(std::string const &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1509
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual int getNbinsX() const
get # of bins in X-axis
std::map< std::string, SubDetMEs > SubDetMEsMap
std::vector< int > m_fed_in
Definition: RunInfo.h:25
void resetSiStripCertificationMEs(DQMStore &dqm_store)
SiStripCertificationInfo(const edm::ParameterSet &ps)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
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)
void endRun(edm::Run const &run, edm::EventSetup const &eSetup) override
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
void bookSiStripCertificationMEs(DQMStore &dqm_store)
std::pair< std::string, int32_t > GetSubDetAndLayer(const uint32_t &detid, const TrackerTopology *tTopo, bool ring_flag=false)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:639
MonitorElement * SiStripCertificationSummaryMap
virtual double getFloatValue() const
void fillSiStripCertificationMEs(DQMStore &dqm_store, edm::EventSetup const &eSetup)
static bool goToDir(DQMStore &dqm_store, std::string const &name)
T get() const
Definition: EventSetup.h:73
MonitorElement * bookFloat(char_string const &name)
Book float.
Definition: DQMStore.cc:1087
bool isValid() const
Definition: ESHandle.h:44
T const * product() const
Definition: ESHandle.h:86
static void getTopFolderPath(DQMStore &dqm_store, std::string const &top_dir, std::string &path)
#define constexpr
Definition: event.py:1
Definition: Run.h:45
void analyze(edm::Event const &, edm::EventSetup const &) override
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)