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 
118  if( eSetup.find( recordKey ) != nullptr) {
119 
120  edm::ESHandle<RunInfo> sumFED;
121  eSetup.get<RunInfoRcd>().get(sumFED);
122 
123  if ( sumFED.isValid() ) {
124 
125  std::vector<int> FedsInIds= sumFED->m_fed_in;
126  for ( auto fedID : FedsInIds ) {
127  if ( fedID >= siPixelFedIdMin && fedID <= siPixelFedIdMax ) {
128  ++nFEDConnected_;
129  ++nPixelFEDConnected_;
130  }
131  else if ( fedID >= siStripFedIdMin && fedID <= siStripFedIdMax )
132  ++nFEDConnected_;
133  }
134  LogDebug ("TrackingDcsInfo") << " TrackingDcsInfo :: Connected FEDs " << nFEDConnected_;
135  }
136  }
137 
138  allPixelFEDConnected_ = ( nPixelFEDConnected_ == siPixelFeds );
139 
140 }
141 
142 //
143 // -- Book MEs for Tracking Certification fractions
144 //
146 
147  if (verbose_) std::cout << "[TrackingCertificationInfo::bookTrackingCertificationMEs] starting .. trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
148 
150 
151  ibooker_.cd();
152  std::string tracking_dir = "";
153  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
154 
155  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(tracking_dir+"/EventInfo");
156  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo");
157 
158  TrackingCertification = ibooker_.bookFloat("CertificationSummary");
159 
160  std::string hname, htitle;
161  hname = "CertificationReportMap";
162  htitle = "Tracking Certification Summary Map";
163  size_t nQT = TrackingMEsMap.size();
164  TrackingCertificationSummaryMap = ibooker_.book2D(hname, htitle, nQT,0.5,float(nQT)+0.5,1,0.5,1.5);
165  TrackingCertificationSummaryMap->setAxisTitle("Track Quality Type", 1);
167  size_t ibin =0;
168  for ( auto meQTset : TrackingMEsMap ) {
169  TrackingCertificationSummaryMap->setBinLabel(ibin+1,meQTset.first);
170  ibin++;
171  }
172 
173 
174  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
175  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
176 
177  for (std::map<std::string, TrackingMEs>::iterator it = TrackingMEsMap.begin();
178  it != TrackingMEsMap.end(); it++) {
179  std::string meQTname = it->first;
180  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] meQTname: " << meQTname << std::endl;
181  it->second.TrackingFlag = ibooker_.bookFloat("Track"+meQTname);
182  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
183  }
184 
186  ibooker_.cd();
187  }
188 
189  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
190 }
191 
192 //
193 // -- Book MEs for Tracking Certification per LS
194 //
196 
197  if (verbose_) std::cout << "[TrackingCertificationInfo::bookTrackingCertificationMEs] starting .. trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
198 
200 
201  ibooker_.cd();
202  std::string tracking_dir = "";
203  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
204 
205  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(tracking_dir+"/EventInfo");
206  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo");
207 
208  TrackingLSCertification = ibooker_.bookFloat("CertificationSummary");
209 
210  if (!tracking_dir.empty() ) ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
211  else ibooker_.setCurrentFolder(TopFolderName_+"/EventInfo/CertificationContents");
212 
213  for (std::map<std::string, TrackingLSMEs>::iterator it = TrackingLSMEsMap.begin();
214  it != TrackingLSMEsMap.end(); it++) {
215  std::string meQTname = it->first;
216  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] meQTname: " << meQTname << std::endl;
217  it->second.TrackingFlag = ibooker_.bookFloat("Track"+meQTname);
218  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] " << it->first << " exists ? " << it->second.TrackingFlag << std::endl;
219  }
220 
222  ibooker_.cd();
223  }
224 
225  if (verbose_) std::cout << "[TrackingCertificationInfo::bookStatus] trackingCertificationBooked_: " << trackingCertificationBooked_ << std::endl;
226 }
227 //
228 
229 //
230 // -- End Luminosity Block
231 //
233 
234  edm::LogInfo( "TrackingDaqInfo") << "TrackingDaqInfo::endLuminosityBlock";
235  bookTrackingCertificationMEsAtLumi(ibooker_,igetter_);
236  fillDummyTrackingCertificationAtLumi(ibooker_,igetter_);
237 
238  if ( nFEDConnected_ > 0 ) fillTrackingCertificationMEsAtLumi(ibooker_,igetter_);
239  else fillDummyTrackingCertificationAtLumi(ibooker_,igetter_);
240 }
241 
242 //
243 // -- End of Run
244 //
246 
247  if (verbose_) std::cout << "[TrackingCertificationInfo::dqmEndJob]" << std::endl;
248 
249  edm::LogInfo ("TrackingCertificationInfo") <<"TrackingCertificationInfo:: End Run";
250  bookTrackingCertificationMEs(ibooker_,igetter_);
251  fillDummyTrackingCertification(ibooker_,igetter_);
252 
253  if ( nFEDConnected_ > 0 ) fillTrackingCertificationMEs(ibooker_,igetter_);
254  else fillDummyTrackingCertification(ibooker_,igetter_);
255 
256  if (verbose_) std::cout << "[TrackingCertificationInfo::endRun] DONE" << std::endl;
257 
258 }
259 //
260 // --Fill Tracking Certification
261 //
264  // edm::LogError("TrackingCertificationInfo") << " TrackingCertificationInfo::fillTrackingCertificationMEs : MEs missing ";
265  return;
266  }
267 
268  ibooker_.cd();
269  std::string tracking_dir = "";
270  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
271  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] tracking_dir: " << tracking_dir << std::endl;
272  std::vector<MonitorElement*> all_mes = igetter_.getContents(tracking_dir+"/EventInfo/reportSummaryContents");
273  float fval = 1.0;
274 
275  if (verbose_) std::cout << "all_mes: " << all_mes.size() << std::endl;
276 
277  if ( checkPixelFEDs_ ) {
278  float val = 1.;
279  if ( allPixelFEDConnected_ ) val = 0.;
280  int xbin = 0;
281  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
282  it != TrackingMEsMap.end(); it++) {
283  std::string type = it->first;
284  if ( type == "pixel" ) {
285  it->second.TrackingFlag->Fill(val);
287  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] xbin: " << xbin << " val: " << val << std::endl;
288  th2d->SetBinContent(xbin+1,1,val);
289  }
290  xbin++;
291  }
292  fval = fminf(fval,val);
293  }
294 
295  int xbin = ( checkPixelFEDs_ ? 1 : 0);
296  for (std::vector<MonitorElement *>::const_iterator ime = all_mes.begin();
297  ime!= all_mes.end(); ime++) {
298  MonitorElement * me = (*ime);
299  if (!me) continue;
300  if (verbose_) std::cout<< "[TrackingCertificationInfo::fillTrackingCertificationMEs] me: " << me->getName() << std::endl;
301  if (me->kind() == MonitorElement::DQM_KIND_REAL) {
302  const std::string& name = me->getName();
303  float val = me->getFloatValue();
304 
305  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
306  it != TrackingMEsMap.end(); it++) {
307 
308  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
309 
310  std::string type = it->first;
311  if (name.find(type) != std::string::npos) {
312  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] type: " << type << " <---> name: " << name << std::endl;
313  it->second.TrackingFlag->Fill(val);
314  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] xbin: " << xbin << " val: " << val << std::endl;
316  th2d->SetBinContent(xbin+1,1,val);
317  xbin++;
318  break;
319  }
320  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
321 
322  }
323  fval = fminf(fval,val);
324  }
325  }
326  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEs] TrackingCertification: " << fval << std::endl;
327  TrackingCertification->Fill(fval);
328 }
329 
330 //
331 // --Reset Tracking Certification
332 //
336  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
337  it != TrackingMEsMap.end(); it++) {
338  it->second.TrackingFlag->Reset();
339  }
340 }
341 
342 //
343 // --Reset Tracking Certification per LS
344 //
348  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
349  it != TrackingLSMEsMap.end(); it++) {
350  it->second.TrackingFlag->Reset();
351  }
352 }
353 
354 //
355 // -- Fill Dummy Tracking Certification
356 //
358  resetTrackingCertificationMEs(ibooker_,igetter_);
361  for (std::map<std::string, TrackingMEs>::const_iterator it = TrackingMEsMap.begin();
362  it != TrackingMEsMap.end(); it++) {
363  it->second.TrackingFlag->Fill(-1.0);
364  }
365 
366  for (int xbin = 1; xbin < TrackingCertificationSummaryMap->getNbinsX()+1; xbin++ )
367  for (int ybin = 1; ybin < TrackingCertificationSummaryMap->getNbinsY()+1; ybin++ )
368  TrackingCertificationSummaryMap->Fill(xbin,ybin,-1);
369 
370 
371  }
372 }
373 
374 //
375 // -- Fill Dummy Tracking Certification per LS
376 //
378  resetTrackingCertificationMEsAtLumi(ibooker_,igetter_);
381  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
382  it != TrackingLSMEsMap.end(); it++) {
383  it->second.TrackingFlag->Fill(-1.0);
384  }
385 
386  }
387 }
388 
389 //
390 // --Fill Tracking Certification per LS
391 //
393  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] starting .." << std::endl;
395  return;
396  }
397  resetTrackingCertificationMEsAtLumi(ibooker_,igetter_);
398 
399  ibooker_.cd();
400  std::string tracking_dir = "";
401  TrackingUtility::getTopFolderPath(ibooker_,igetter_, TopFolderName_, tracking_dir);
402  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] tracking_dir: " << tracking_dir << std::endl;
403 
404 
405  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] tracking_dir: " << tracking_dir << std::endl;
406  std::vector<MonitorElement*> all_mes = igetter_.getContents(tracking_dir+"/EventInfo/reportSummaryContents");
407 
408  if (verbose_) std::cout << "all_mes: " << all_mes.size() << std::endl;
409 
410  for (std::vector<MonitorElement *>::const_iterator ime = all_mes.begin();
411  ime!= all_mes.end(); ime++) {
412  MonitorElement * me = (*ime);
413  if (!me) continue;
414  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] me: " << me->getName() << std::endl;
415  if (me->kind() == MonitorElement::DQM_KIND_REAL) {
416  const std::string& name = me->getName();
417  float val = me->getFloatValue();
418  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] val: " << val << std::endl;
419 
420  for (std::map<std::string, TrackingLSMEs>::const_iterator it = TrackingLSMEsMap.begin();
421  it != TrackingLSMEsMap.end(); it++) {
422 
423  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
424 
425  std::string type = it->first;
426  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] type: " << type << std::endl;
427  if (name.find(type) != std::string::npos) {
428  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] type: " << type << " <---> name: " << name << std::endl;
429  it->second.TrackingFlag->Fill(val);
430  break;
431  }
432  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] ME: " << it->first << " [" << it->second.TrackingFlag->getFullname() << "] flag: " << it->second.TrackingFlag->getFloatValue() << std::endl;
433  }
434  }
435  }
436 
437  float global_dqm_flag = 1.0;
438  std::string full_path = tracking_dir + "/EventInfo/reportSummary";
439  MonitorElement* me_dqm = igetter_.get(full_path);
440  if (me_dqm && me_dqm->kind() == MonitorElement::DQM_KIND_REAL) global_dqm_flag = me_dqm->getFloatValue();
441  if (verbose_) std::cout << "[TrackingCertificationInfo::fillTrackingCertificationMEsAtLumi] global_dqm_flag: " << global_dqm_flag << std::endl;
442 
444  TrackingLSCertification->Fill(global_dqm_flag);
445 }
#define LogDebug(id)
std::map< std::string, TrackingLSMEs > TrackingLSMEsMap
type
Definition: HCALResponse.h:21
std::vector< MonitorElement * > getContents(Args &&...args)
Definition: DQMStore.h:305
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
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_)
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
#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
static HCTypeTag findType(char const *iTypeName)
find a type based on the types name, if not found will return default HCTypeTag
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 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)
TH2F * getTH2F() const
void resetTrackingCertificationMEsAtLumi(DQMStore::IBooker &ibooker_, DQMStore::IGetter &igetter_)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
int getNbinsY() const
get # of bins in Y-axis
T get() const
Definition: EventSetup.h:63
boost::optional< eventsetup::EventSetupRecordGeneric > find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:88
int getNbinsX() const
get # of bins in X-axis
MonitorElement * bookFloat(Args &&...args)
Definition: DQMStore.h:112
bool isValid() const
Definition: ESHandle.h:47
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_)