CMS 3D CMS Logo

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