CMS 3D CMS Logo

TrackingCertificationInfo.cc
Go to the documentation of this file.
4 
10 
14 
16 
17 //Run Info
21 
22 #include <iostream>
23 #include <iomanip>
24 #include <cstdio>
25 #include <string>
26 #include <sstream>
27 #include <cmath>
28 //
29 // -- Contructor
30 //
32  : pSet_(pSet)
33  , trackingCertificationBooked_(false)
34  , trackingLSCertificationBooked_(false)
35  , nFEDConnected_(0)
36  , allPixelFEDConnected_(true)
37  , m_cacheID_(0)
38 {
39  // Create MessageSender
40  edm::LogInfo( "TrackingCertificationInfo") << "TrackingCertificationInfo::Deleting TrackingCertificationInfo ";
41 
42  verbose_ = pSet_.getUntrackedParameter<bool>("verbose",false);
43  TopFolderName_ = pSet_.getUntrackedParameter<std::string>("TopFolderName","Tracking");
44  if (verbose_) std::cout << "[TrackingCertificationInfo::TrackingCertificationInfo] TopFolderName_: " << TopFolderName_ << std::endl;
45 
46  TrackingMEs tracking_mes;
47  // load variables for Global certification
48 
49  checkPixelFEDs_ = pSet_.getParameter<bool>("checkPixelFEDs");
50  if ( checkPixelFEDs_ ) {
51  std::string QTname = "pixel";
52  tracking_mes.TrackingFlag = nullptr;
53  TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>(QTname, tracking_mes));
54  }
55 
56  std::vector<edm::ParameterSet> TrackingGlobalQualityMEs = pSet_.getParameter< std::vector<edm::ParameterSet> >("TrackingGlobalQualityPSets" );
57  for ( auto meQTset : TrackingGlobalQualityMEs ) {
58 
59  std::string QTname = meQTset.getParameter<std::string>("QT");
60  tracking_mes.TrackingFlag = nullptr;
61 
62  if (verbose_) std::cout<< "[TrackingQualityChecker::TrackingCertificationInfo] inserting " << QTname << " in TrackingMEsMap" << std::endl;
63  TrackingMEsMap.insert(std::pair<std::string, TrackingMEs>(QTname, tracking_mes));
64  }
65 
66  TrackingLSMEs tracking_ls_mes;
67  // load variables for LS certification
68  std::vector<edm::ParameterSet> TrackingLSQualityMEs = pSet_.getParameter< std::vector<edm::ParameterSet> >("TrackingLSQualityMEs" );
69  for ( auto meQTset : TrackingLSQualityMEs ) {
70 
71  std::string QTname = meQTset.getParameter<std::string>("QT");
72  tracking_ls_mes.TrackingFlag = nullptr;
73 
74  if (verbose_) std::cout<< "[TrackingQualityChecker::TrackingCertificationInfo] inserting " << QTname << " in TrackingMEsMap" << std::endl;
75  TrackingLSMEsMap.insert(std::pair<std::string, TrackingLSMEs>(QTname, tracking_ls_mes));
76  }
77 
78 
79  // define sub-detectors which affect the quality
80  SubDetFolder.push_back("SiStrip");
81  SubDetFolder.push_back("Pixel");
82 
83 }
84 
86  edm::LogInfo("TrackingCertificationInfo") << "TrackingCertificationInfo::Deleting TrackingCertificationInfo ";
87 
88 }
89 //
90 // -- Begin Job
91 //
93 
94 }
95 //
96 // -- Begin Run
97 //
99 
100  if (verbose_) std::cout << "[TrackingCertificationInfo::beginRun] starting .." << std::endl;
101 
102  edm::LogInfo ("TrackingCertificationInfo") <<"TrackingCertificationInfo:: Begining of Run";
103  unsigned long long cacheID = eSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
104  if (m_cacheID_ != cacheID) {
105  m_cacheID_ = cacheID;
106  }
107  eSetup.get<SiStripDetCablingRcd>().get(detCabling_);
108 
109  nFEDConnected_ = 0;
110  int nPixelFEDConnected_ = 0;
111  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
112  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
113  const int siPixelFedIdMin = FEDNumbering::MINSiPixelFEDID;
114  const int siPixelFedIdMax = FEDNumbering::MAXSiPixelFEDID;
115  const int siPixelFeds = (siPixelFedIdMax-siPixelFedIdMin+1);
116 
117  if(auto runInfoRec = eSetup.tryToGet<RunInfoRcd>()) {
118 
119  edm::ESHandle<RunInfo> sumFED;
120  runInfoRec->get(sumFED);
121 
122  if ( sumFED.isValid() ) {
123 
124  std::vector<int> FedsInIds= sumFED->m_fed_in;
125  for ( auto fedID : FedsInIds ) {
126  if ( fedID >= siPixelFedIdMin && fedID <= siPixelFedIdMax ) {
127  ++nFEDConnected_;
128  ++nPixelFEDConnected_;
129  }
130  else if ( fedID >= siStripFedIdMin && fedID <= siStripFedIdMax )
131  ++nFEDConnected_;
132  }
133  LogDebug ("TrackingDcsInfo") << " TrackingDcsInfo :: Connected FEDs " << nFEDConnected_;
134  }
135  }
136 
137  allPixelFEDConnected_ = ( nPixelFEDConnected_ == siPixelFeds );
138 
139 }
140 
141 //
142 // -- Book MEs for Tracking Certification fractions
143 //
145 
146  if (verbose_) std::cout << "[TrackingCertificationInfo::bookTrackingCertificationMEs] starting .. trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
147 
149 
150  ibooker_.cd();
151  std::string tracking_dir = "";
152  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
153 
154  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(tracking_dir+"/EventInfo");
155  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo");
156 
157  TrackingCertification = ibooker_.bookFloat("CertificationSummary");
158 
159  std::string hname, htitle;
160  hname = "CertificationReportMap";
161  htitle = "Tracking Certification Summary Map";
162  size_t nQT = TrackingMEsMap.size();
163  TrackingCertificationSummaryMap = ibooker_.book2D(hname, htitle, nQT,0.5,float(nQT)+0.5,1,0.5,1.5);
164  TrackingCertificationSummaryMap->setAxisTitle("Track Quality Type", 1);
166  size_t ibin =0;
167  for ( auto meQTset : TrackingMEsMap ) {
168  TrackingCertificationSummaryMap->setBinLabel(ibin+1,meQTset.first);
169  ibin++;
170  }
171 
172 
173  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
174  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
175 
176  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
177  it != TrackingMEsMap.end(); it++) {
178  std::string meQTname = it->first;
179  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] meQTname: " << meQTname << std::endl;
180  it->second.TrackingFlag = ibooker_.bookFloat("Track"+meQTname);
181  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
182  }
183 
185  ibooker_.cd();
186  }
187 
188  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
189 }
190 
191 //
192 // -- Book MEs for Tracking Certification per LS
193 //
195 
196  if (verbose_) std::cout << "[TrackingCertificationInfo::bookTrackingCertificationMEs] starting .. trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
197 
199 
200  ibooker_.cd();
201  std::string tracking_dir = "";
202  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
203 
204  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(tracking_dir+"/EventInfo");
205  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo");
206 
207  TrackingLSCertification = ibooker_.bookFloat("CertificationSummary");
208 
209  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
210  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
211 
212  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
213  it != TrackingLSMEsMap.end(); it++) {
214  std::string meQTname = it->first;
215  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] meQTname: " << meQTname << std::endl;
216  it->second.TrackingFlag = ibooker_.bookFloat("Track"+meQTname);
217  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
218  }
219 
221  ibooker_.cd();
222  }
223 
224  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
225 }
226 //
227 
228 //
229 // -- End Luminosity Block
230 //
232 
233  edm::LogInfo( "TrackingDaqInfo") << "TrackingDaqInfo::endLuminosityBlock";
234  bookTrackingCertificationMEsAtLumi(ibooker_,igetter_);
235  fillDummyTrackingCertificationAtLumi(ibooker_,igetter_);
236 
237  if ( nFEDConnected_ > 0 ) fillTrackingCertificationMEsAtLumi(ibooker_,igetter_);
238  else fillDummyTrackingCertificationAtLumi(ibooker_,igetter_);
239 }
240 
241 //
242 // -- End of Run
243 //
245 
246  if (verbose_) std::cout << "[TrackingCertificationInfo::dqmEndJob]" << std::endl;
247 
248  edm::LogInfo ("TrackingCertificationInfo") <<"TrackingCertificationInfo:: End Run";
249  bookTrackingCertificationMEs(ibooker_,igetter_);
250  fillDummyTrackingCertification(ibooker_,igetter_);
251 
252  if ( nFEDConnected_ > 0 ) fillTrackingCertificationMEs(ibooker_,igetter_);
253  else fillDummyTrackingCertification(ibooker_,igetter_);
254 
255  if (verbose_) std::cout << "[TrackingCertificationInfo::endRun] DONE" << std::endl;
256 
257 }
258 //
259 // --Fill Tracking Certification
260 //
263  // edm::LogError("TrackingCertificationInfo") << " TrackingCertificationInfo::fillTrackingCertificationMEs : MEs missing ";
264  return;
265  }
266 
267  ibooker_.cd();
268  std::string tracking_dir = "";
269  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
270  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] tracking_dir: " << tracking_dir << std::endl;
271  std::vector<MonitorElement*> all_mes = igetter_.getContents(tracking_dir+"/EventInfo/reportSummaryContents");
272  float fval = 1.0;
273 
274  if (verbose_) std::cout << "all_mes: " << all_mes.size() << std::endl;
275 
276  if ( checkPixelFEDs_ ) {
277  float val = 1.;
278  if ( allPixelFEDConnected_ ) val = 0.;
279  int xbin = 0;
280  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
281  it != TrackingMEsMap.end(); it++) {
282  std::string type = it->first;
283  if ( type == "pixel" ) {
284  it->second.TrackingFlag->Fill(val);
286  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] xbin: " << xbin << " val: " << val << std::endl;
287  th2d->SetBinContent(xbin+1,1,val);
288  }
289  xbin++;
290  }
291  fval = fminf(fval,val);
292  }
293 
294  int xbin = ( checkPixelFEDs_ ? 1 : 0);
295  for (std::vector<MonitorElement *>::const_iterator ime = all_mes.begin();
296  ime!= all_mes.end(); ime++) {
297  MonitorElement * me = (*ime);
298  if (!me) continue;
299  if (verbose_) std::cout<< "[TrackingCertificationInfo::fillTrackingCertificationMEs] me: " << me->getName() << std::endl;
300  if (me->kind() == MonitorElement::DQM_KIND_REAL) {
301  const std::string& name = me->getName();
302  float val = me->getFloatValue();
303 
304  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
305  it != TrackingMEsMap.end(); it++) {
306 
307  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
308 
309  std::string type = it->first;
310  if (name.find(type) != std::string::npos) {
311  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] type: " << type << " <---> name: " << name << std::endl;
312  it->second.TrackingFlag->Fill(val);
313  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] xbin: " << xbin << " val: " << val << std::endl;
315  th2d->SetBinContent(xbin+1,1,val);
316  xbin++;
317  break;
318  }
319  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
320 
321  }
322  fval = fminf(fval,val);
323  }
324  }
325  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] TrackingCertification: " << fval << std::endl;
326  TrackingCertification->Fill(fval);
327 }
328 
329 //
330 // --Reset Tracking Certification
331 //
335  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
336  it != TrackingMEsMap.end(); it++) {
337  it->second.TrackingFlag->Reset();
338  }
339 }
340 
341 //
342 // --Reset Tracking Certification per LS
343 //
347  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
348  it != TrackingLSMEsMap.end(); it++) {
349  it->second.TrackingFlag->Reset();
350  }
351 }
352 
353 //
354 // -- Fill Dummy Tracking Certification
355 //
357  resetTrackingCertificationMEs(ibooker_,igetter_);
360  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
361  it != TrackingMEsMap.end(); it++) {
362  it->second.TrackingFlag->Fill(-1.0);
363  }
364 
365  for (int xbin = 1; xbin < TrackingCertificationSummaryMap->getNbinsX()+1; xbin++ )
366  for (int ybin = 1; ybin < TrackingCertificationSummaryMap->getNbinsY()+1; ybin++ )
367  TrackingCertificationSummaryMap->Fill(xbin,ybin,-1);
368 
369 
370  }
371 }
372 
373 //
374 // -- Fill Dummy Tracking Certification per LS
375 //
377  resetTrackingCertificationMEsAtLumi(ibooker_,igetter_);
380  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
381  it != TrackingLSMEsMap.end(); it++) {
382  it->second.TrackingFlag->Fill(-1.0);
383  }
384 
385  }
386 }
387 
388 //
389 // --Fill Tracking Certification per LS
390 //
392  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] starting .." << std::endl;
394  return;
395  }
396  resetTrackingCertificationMEsAtLumi(ibooker_,igetter_);
397 
398  ibooker_.cd();
399  std::string tracking_dir = "";
400  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
401  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] tracking_dir: " << tracking_dir << std::endl;
402 
403 
404  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] tracking_dir: " << tracking_dir << std::endl;
405  std::vector<MonitorElement*> all_mes = igetter_.getContents(tracking_dir+"/EventInfo/reportSummaryContents");
406 
407  if (verbose_) std::cout << "all_mes: " << all_mes.size() << std::endl;
408 
409  for (std::vector<MonitorElement *>::const_iterator ime = all_mes.begin();
410  ime!= all_mes.end(); ime++) {
411  MonitorElement * me = (*ime);
412  if (!me) continue;
413  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] me: " << me->getName() << std::endl;
414  if (me->kind() == MonitorElement::DQM_KIND_REAL) {
415  const std::string& name = me->getName();
416  float val = me->getFloatValue();
417  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] val: " << val << std::endl;
418 
419  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
420  it != TrackingLSMEsMap.end(); it++) {
421 
422  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
423 
424  std::string type = it->first;
425  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] type: " << type << std::endl;
426  if (name.find(type) != std::string::npos) {
427  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] type: " << type << " <---> name: " << name << std::endl;
428  it->second.TrackingFlag->Fill(val);
429  break;
430  }
431  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
432  }
433  }
434  }
435 
436  float global_dqm_flag = 1.0;
437  std::string full_path = tracking_dir + "/EventInfo/reportSummary";
438  MonitorElement* me_dqm = igetter_.get(full_path);
439  if (me_dqm && me_dqm->kind() == MonitorElement::DQM_KIND_REAL) global_dqm_flag = me_dqm->getFloatValue();
440  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] global_dqm_flag: " << global_dqm_flag << std::endl;
441 
443  TrackingLSCertification->Fill(global_dqm_flag);
444 }
#define LogDebug(id)
std::map< std::string, TrackingLSMEs > TrackingLSMEsMap
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::optional< T > tryToGet() const
Definition: EventSetup.h:87
void dqmEndJob(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_) override
EndJob.
void beginRun(edm::Run const &run, edm::EventSetup const &eSetup) override
Begin Run.
void fillDummyTrackingCertification(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
double getFloatValue() const
~TrackingCertificationInfo() override
Destructor.
void resetTrackingCertificationMEs(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginJob() override
BeginJob.
std::map< std::string, TrackingMEs > TrackingMEsMap
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
void fillTrackingCertificationMEs(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
TrackingCertificationInfo(const edm::ParameterSet &ps)
Constructor.
std::vector< std::string > SubDetFolder
void bookTrackingCertificationMEs(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
edm::ESHandle< SiStripDetCabling > detCabling_
void Fill(long long x)
MonitorElement * TrackingCertificationSummaryMap
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
void fillDummyTrackingCertificationAtLumi(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
std::vector< int > m_fed_in
Definition: RunInfo.h:26
void fillTrackingCertificationMEsAtLumi(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
void Reset()
reset ME (ie. contents, errors, etc)
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:192
TH2F * getTH2F() const
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
void resetTrackingCertificationMEsAtLumi(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
int getNbinsY() const
get # of bins in Y-axis
T get() const
Definition: EventSetup.h:68
int getNbinsX() const
get # of bins in X-axis
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:105
bool isValid() const
Definition: ESHandle.h:45
static void getTopFolderPath(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, std::string top_dir, std::string &path)
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
Kind kind() const
Get the type of the monitor element.
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_, edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &iSetup) override
End Of Luminosity.
Definition: Run.h:44
void bookTrackingCertificationMEsAtLumi(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)