CMS 3D CMS Logo

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