CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripTrackerMapCreator.cc
Go to the documentation of this file.
9 
12 
15 
20 
21 #include <iostream>
22 
23 //
24 // -- Constructor
25 //
26 /*
27 SiStripTrackerMapCreator::SiStripTrackerMapCreator() {
28  trackerMap_ = 0;
29  if(!edm::Service<TkDetMap>().isAvailable()){
30  edm::LogError("TkHistoMap") <<
31  "\n------------------------------------------"
32  "\nUnAvailable Service TkHistoMap: please insert in the configuration file an instance like"
33  "\n\tprocess.TkDetMap = cms.Service(\"TkDetMap\")"
34  "\n------------------------------------------";
35  }
36  tkDetMap_=edm::Service<TkDetMap>().operator->();
37 }
38 */
39 SiStripTrackerMapCreator::SiStripTrackerMapCreator(const edm::EventSetup& eSetup): meanToMaxFactor_(2.5),eSetup_(eSetup)
40  //, psumap_()
41 {
42  cached_detid=0;
43  cached_layer=0;
44  trackerMap_ = nullptr;
47  edm::ESHandle<TkDetMap> tkDetMapHandle;
48  eSetup_.get<TrackerTopologyRcd>().get(tkDetMapHandle);
49  tkDetMap_ = tkDetMapHandle.product();
50  // psumap_.BuildMap("CalibTracker/SiStripDCS/data/StripPSUDetIDMap_FromJan132010.dat",false);
51 }
52 //
53 // -- Destructor
54 //
56  if (trackerMap_) delete trackerMap_;
57 }
58 //
59 // -- Create Geometric and Fed Tracker Map
60 //
62  DQMStore* dqm_store, std::string& map_type,
63  const edm::EventSetup& eSetup) {
64 
65  const SiStripFedCabling* fedcabling = detcabling_->fedCabling();
66 
67  if(!fedcabling) return;
68 
70  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
71  const TrackerTopology* const tTopo = tTopoHandle.product();
72 
73  if (trackerMap_) delete trackerMap_;
74  trackerMap_ = new TrackerMap(tkmapPset, fedcabling,tTopo);
75  std::string tmap_title = " Tracker Map from " + map_type;
76  trackerMap_->setTitle(tmap_title);
77 
78  nDet = 0;
79  tkMapMax_ = 0.0;
80  tkMapMin_ = 0.0;
81  meanToMaxFactor_ = 2.5;
82  useSSQuality_ = false;
83  ssqLabel_ = "";
84  stripTopLevelDir_="SiStrip";
85 
86  if (map_type == "QTestAlarm") {
87  setTkMapFromAlarm(dqm_store, eSetup);
88  /*
89  trackerMap_->fillc_all_blank();
90  const std::vector<uint16_t>& feds = fedcabling->feds();
91  uint32_t detId_save = 0;
92  for(std::vector<unsigned short>::const_iterator ifed = feds.begin();
93  ifed < feds.end(); ifed++){
94  const std::vector<FedChannelConnection> fedChannels = fedcabling->connections( *ifed );
95  for(std::vector<FedChannelConnection>::const_iterator iconn = fedChannels.begin(); iconn < fedChannels.end(); iconn++){
96 
97  uint32_t detId = iconn->detId();
98  if (detId == 0 || detId == 0xFFFFFFFF) continue;
99  if (detId_save != detId) {
100  detId_save = detId;
101  paintTkMapFromAlarm(detId, dqm_store);
102  }
103  }
104  }
105  */
106  } else {
108  setTkMapFromHistogram(dqm_store, map_type, eSetup);
109  setTkMapRange(map_type);
110  }
112  delete trackerMap_;
113  trackerMap_ = nullptr;
114 }
115 //
116 // -- Create Tracker Map for Offline process
117 //
119  DQMStore* dqm_store, std::string& map_type,
120  const edm::EventSetup& eSetup) {
121 
122  // Determine the strip top level dirctory in the DQM file: it is the path where MechanicalView is minus one directory
123 
124  std::string mdir = "MechanicalView";
125  dqm_store->cd();
126  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
127  edm::LogError("SiStripTopLevelDirNotFound") << "I cannot find the SiStrip top level directory in the DQM file";
128  }
129  else {
130  const std::string& mechanicalview_dir = dqm_store->pwd();
131  stripTopLevelDir_=mechanicalview_dir.substr(0,mechanicalview_dir.find_last_of("/"));
132  edm::LogInfo("SiStripTopLevelDirFound") << "SiStrip top level directory is " << stripTopLevelDir_;
133  }
134  dqm_store->cd();
135 
136  //
137  const SiStripFedCabling* fedcabling = detcabling_->fedCabling();
138 
139  if(!fedcabling) return;
140 
141  edm::ESHandle<TrackerTopology> tTopoHandle;
142  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
143  const TrackerTopology* const tTopo = tTopoHandle.product();
144 
145  if (trackerMap_) delete trackerMap_;
146  trackerMap_ = new TrackerMap(tkmapPset,fedcabling,tTopo);
147 
148  meanToMaxFactor_ = tkmapPset.getUntrackedParameter<double>("meanToMaxFact",2.5);
149  useSSQuality_ = tkmapPset.getUntrackedParameter<bool>("useSSQuality",false);
150  ssqLabel_ = tkmapPset.getUntrackedParameter<std::string>("ssqLabel","");
151  bool tkMapPSU = tkmapPset.getUntrackedParameter<bool>("psuMap",false);
152  bool tkMapFED = tkmapPset.getUntrackedParameter<bool>("fedMap",false);
153  std::string namesuffix = tkmapPset.getUntrackedParameter<std::string>("mapSuffix","");
154 
155  // std::string tmap_title = " Tracker Map from " + map_type;
156  unsigned int runNumber_ = tkmapPset.getUntrackedParameter<unsigned int>("RunNumber",1); //LG
157  std::stringstream ss; //LG
158  ss << runNumber_; //LG
159  sRunNumber = ss.str(); //LG
160  std::cout << sRunNumber << "\n\n\n\n\n\n";
161  std::string tmap_title; //LG
162  if (runNumber_>0) { tmap_title = " Run: " + sRunNumber + ", Tracker Map from " + map_type; } //LG
163  else { tmap_title = " Tracker Map from " + map_type; } //LG
164  trackerMap_->setTitle(tmap_title);
165 
166  if(tkmapPset.exists("TopModules"))
167  topModules=tkmapPset.getUntrackedParameter<bool>("TopModules");
168  else
169  topModules=false;
170 
171  if(tkmapPset.exists("numberTopModules"))
172  numTopModules=tkmapPset.getUntrackedParameter<uint32_t>("numberTopModules");
173  else
174  numTopModules = 20;
175 
176  if (tkmapPset.exists("topModLabel"))
177  topModLabel=tkmapPset.getUntrackedParameter<int32_t>("topModLabel");
178  else
179  topModLabel = " top Modules " + map_type;
180 
181  if (map_type == "QTestAlarm") {
182  setTkMapFromAlarm(dqm_store, eSetup);
183  }
184  else {
185  setTkMapFromHistogram(dqm_store, map_type, eSetup);
186  }
187  // if not overwitten by manual configuration min=0 and max= mean value * meanToMaxFactor_
189 
190  // check manual setting
191 
192  if(tkmapPset.exists("mapMax")) tkMapMax_ = tkmapPset.getUntrackedParameter<double>("mapMax");
193  if(tkmapPset.exists("mapMin")) tkMapMin_ = tkmapPset.getUntrackedParameter<double>("mapMin");
194 
195  if (map_type == "ResidualsMean"){
196  ResidualsRMS_ = false;
197  setTkMapFromHistogram(dqm_store, map_type, eSetup);
198  edm::LogInfo("TkMapToBeSaved") << "Ready to save TkMap " << map_type << namesuffix << " with range set to " << tkMapMin_ << " - " << tkMapMax_;
199  trackerMap_->save(true, 0.0000000001,0.005, map_type+namesuffix+".svg");
200  trackerMap_->save(true, 0.0000000001,0.005, map_type+namesuffix+".png",4500,2400);
201  ResidualsRMS_ = true;
202  map_type = "ResidualsRMS";
203  if (runNumber_>0) { tmap_title = " Run: " + sRunNumber + ", Tracker Map from " + map_type; } //LG
204  else { tmap_title = " Tracker Map from " + map_type; } //LG
205  trackerMap_->setTitle(tmap_title);
206  setTkMapFromHistogram(dqm_store, map_type, eSetup);
207  edm::LogInfo("TkMapToBeSaved") << "Ready to save TkMap " << map_type << namesuffix << " with range set to 0.0 - 0.5";
208  trackerMap_->save(true, 0.000000001, 0.005, map_type+namesuffix+".svg");
209  trackerMap_->save(true, 0.000000001, 0.005, map_type+namesuffix+".png",4500,2400);
210  } else {
211  edm::LogInfo("TkMapToBeSaved") << "Ready to save TkMap " << map_type << namesuffix << " with range set to " << tkMapMin_ << " - " << tkMapMax_;
212  trackerMap_->save(true, tkMapMin_,tkMapMax_, map_type+namesuffix+".svg");
213  trackerMap_->save(true, tkMapMin_,tkMapMax_, map_type+namesuffix+".png",4500,2400);
214  }
215 
216  if(tkMapPSU) {
217 
218  edm::LogInfo("PSUMapToBeSaved") << "Ready to save PSU TkMap " << map_type << namesuffix << " with range set to " << tkMapMin_ << " - " << tkMapMax_;
219  // trackerMap_->save_as_psutrackermap(true, tkMapMin_,tkMapMax_, map_type+namesuffix+"_psu.svg");
220  trackerMap_->save_as_psutrackermap(true, tkMapMin_,tkMapMax_, map_type+namesuffix+"_psu.png");
221 
222  }
223 
224  if(tkMapFED) {
225 
226  edm::LogInfo("FEDMapToBeSaved") << "Ready to save FED TkMap " << map_type << namesuffix << " with range set to " << tkMapMin_ << " - " << tkMapMax_;
227  // trackerMap_->save_as_fedtrackermap(true, tkMapMin_,tkMapMax_, map_type+"_fed.svg");
228  trackerMap_->save_as_fedtrackermap(true, tkMapMin_,tkMapMax_, map_type+namesuffix+"_fed.png");
229 
230  }
231 
232  delete trackerMap_;
233  trackerMap_ = nullptr;
234 }
235 //
236 // -- Fill Tracker Map with QTest Alarms and SiStripQuality bad modules
238 
239  //Retrieve tracker topology from geometry
240  edm::ESHandle<TrackerTopology> tTopoHandle;
241  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
242  const TrackerTopology* const tTopo = tTopoHandle.product();
243 
244  nDet = 0;
245  tkMapMax_ = 0.0;
246  tkMapMin_ = 0.0;
247 
249 
251 
253 
254  std::map<unsigned int,std::string>* badmodmap = new std::map<unsigned int,std::string>;
255 
256  // used to avoid multiple checks on the same detid since the loop is done on the FED channels
257  uint32_t detId_save = 0;
258  // example of loop using SiStripDetCabling
259  for(std::map< uint32_t, std::vector<const FedChannelConnection *> >::const_iterator module = detcabling_->getDetCabling().begin();
260  module!=detcabling_->getDetCabling().end();++module) {
261  uint32_t detId = module->first;
262  if (detId == 0 || detId == 0xFFFFFFFF) continue;
263  if (detId_save != detId) {
264  detId_save = detId;
265  bool isBad = useSSQuality_ && ssq->IsModuleBad(detId);
266  paintTkMapFromAlarm(detId, tTopo, dqm_store,isBad,badmodmap);
267  }
268  else {
269  edm::LogWarning("TwiceTheSameDetId") << "The detid " << detId << " was found already in the loop on SiStripDetCabling";
270  }
271  }
272  //
273  printBadModuleList(badmodmap, eSetup);
274  delete badmodmap;
275 }
276 //
277 void SiStripTrackerMapCreator::printBadModuleList(std::map<unsigned int,std::string>* badmodmap, const edm::EventSetup& eSetup) {
278 
279  //Retrieve tracker topology from geometry
280  edm::ESHandle<TrackerTopology> tTopoHandle;
281  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
282  const TrackerTopology* const tTopo = tTopoHandle.product();
283 
284  bool tibDone=false,tidSide1Done=false,tidSide2Done=false,tobDone=false,tecSide1Done=false,tecSide2Done=false;
285  unsigned int tibFirst=369120277-1,
286  tidSide1First=402664197-1,tidSide2First=402672389-1,
287  tobFirst=436228134-1,
288  tecSide1First=470044965-1,tecSide2First=470307109-1;
289 
290  int ntib=0,ntids1=0,ntids2=0,ntob=0,ntecs1=0,ntecs2=0;
291 
292  for(std::map<unsigned int,std::string>::const_iterator badmod = badmodmap->begin(); badmod!= badmodmap->end(); ++badmod) {
293  SiStripDetId ssdetid(badmod->first);
294  if(ssdetid.subDetector()==SiStripDetId::TIB) ntib++;
295  if(ssdetid.subDetector()==SiStripDetId::TID) {
296 
297  if(tTopo->tidSide(ssdetid)==1) ntids1++;
298  if(tTopo->tidSide(ssdetid)==2) ntids2++;
299  }
300  if(ssdetid.subDetector()==SiStripDetId::TOB) ntob++;
301  if(ssdetid.subDetector()==SiStripDetId::TEC) {
302 
303  if(tTopo->tecSide(ssdetid)==1) ntecs1++;
304  if(tTopo->tecSide(ssdetid)==2) ntecs2++;
305  }
306  }
307 
308  // edm::LogVerbatim("BadModuleList") << "Number of bad modules in total:";
309  edm::LogVerbatim("BadModuleList") << "Run: " << sRunNumber << ", Number of bad modules in total:"; //LG
310  edm::LogVerbatim("BadModuleList") << "--------------------------------------------------------------";
311  edm::LogVerbatim("BadModuleList") << "TIB: " << ntib;
312  edm::LogVerbatim("BadModuleList") << "TID/MINUS: " << ntids1;
313  edm::LogVerbatim("BadModuleList") << "TID/PLUS: " << ntids2;
314  edm::LogVerbatim("BadModuleList") << "TOB: " << ntob;
315  edm::LogVerbatim("BadModuleList") << "TEC/MINUS: " << ntecs1;
316  edm::LogVerbatim("BadModuleList") << "TEC/PLUS: " << ntecs2;
317  edm::LogVerbatim("BadModuleList") << "-------------------------------";
318  edm::LogVerbatim("BadModuleList") ;
319  edm::LogVerbatim("BadModuleList") << "List of bad modules per partition:";
320  edm::LogVerbatim("BadModuleList") << "----------------------------------";
321 
322  for(std::map<unsigned int,std::string>::const_iterator badmod = badmodmap->begin(); badmod!= badmodmap->end(); ++badmod) {
323  if(!tibDone && badmod->first >= tibFirst) {
324  tibDone = true;
325  edm::LogVerbatim("BadModuleList") ;
326  edm::LogVerbatim("BadModuleList") << "SubDetector TIB";
327  edm::LogVerbatim("BadModuleList") ;
328  }
329  if(!tidSide1Done && badmod->first >= tidSide1First) {
330  tidSide1Done = true;
331  edm::LogVerbatim("BadModuleList") ;
332  edm::LogVerbatim("BadModuleList") << "SubDetector TID/MINUS";
333  edm::LogVerbatim("BadModuleList") ;
334  }
335  if(!tidSide2Done && badmod->first >= tidSide2First) {
336  tidSide2Done = true;
337  edm::LogVerbatim("BadModuleList") ;
338  edm::LogVerbatim("BadModuleList") << "SubDetector TID/PLUS";
339  edm::LogVerbatim("BadModuleList") ;
340  }
341  if(!tobDone && badmod->first >= tobFirst) {
342  tobDone = true;
343  edm::LogVerbatim("BadModuleList") ;
344  edm::LogVerbatim("BadModuleList") << "SubDetector TOB";
345  edm::LogVerbatim("BadModuleList") ;
346  }
347  if(!tecSide1Done && badmod->first >= tecSide1First) {
348  tecSide1Done = true;
349  edm::LogVerbatim("BadModuleList") ;
350  edm::LogVerbatim("BadModuleList") << "SubDetector TEC/MINUS";
351  edm::LogVerbatim("BadModuleList") ;
352  }
353  if(!tecSide2Done && badmod->first >= tecSide2First) {
354  tecSide2Done = true;
355  edm::LogVerbatim("BadModuleList") ;
356  edm::LogVerbatim("BadModuleList") << "SubDetector TEC/PLUS";
357  edm::LogVerbatim("BadModuleList") ;
358  }
359  edm::LogVerbatim("BadModuleList") << badmod->second;
360  }
361 }
362 
363 //
364 // -- Paint Tracker Map with QTest Alarms
365 //
367  DQMStore* dqm_store, bool isBad, std::map<unsigned int,std::string>* badmodmap) {
368  std::ostringstream comment;
369  uint16_t flag = 0;
370  flag = getDetectorFlagAndComment(dqm_store, det_id, tTopo, comment);
371 
372  int rval, gval, bval;
373  SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
374  if(isBad) { rval=255; gval=255; bval = 0; comment << " PCLBadModule ";}
375  trackerMap_->setText(det_id, comment.str());
376  trackerMap_->fillc(det_id, rval, gval, bval);
377 
378  if(badmodmap && (flag!=0 || isBad)){
379  uint lay= tTopo->layer(SiStripDetId(det_id));
380  std::string layer =" Layer "+ std::to_string(lay);
381  (*badmodmap)[det_id] = comment.str() + layer;
382  }
383 
384  detflag_[det_id] = flag;
385 }
386 
387 //
388 // -- Paint Tracker Map from TkHistoMap Histograms
390  dqm_store->cd();
391 
392  std::string mdir = "MechanicalView";
393  if (!SiStripUtility::goToDir(dqm_store, mdir)) return;
394  std::string mechanicalview_dir = dqm_store->pwd();
395 
396  std::vector<std::string> subdet_folder;
397  subdet_folder.push_back("TIB");
398  subdet_folder.push_back("TOB");
399  subdet_folder.push_back("TEC/MINUS");
400  subdet_folder.push_back("TEC/PLUS");
401  subdet_folder.push_back("TID/MINUS");
402  subdet_folder.push_back("TID/PLUS");
403 
404  nDet = 0;
405  tkMapMax_ = 0.0;
406  tkMapMin_ = 0.0;
407  std::vector<std::pair<float,uint32_t> >* topNmodVec = new std::vector<std::pair<float,uint32_t> >;
408 
409  for (std::vector<std::string>::const_iterator it = subdet_folder.begin(); it != subdet_folder.end(); it++) {
410  std::string dname = mechanicalview_dir + "/" + (*it);
411  if (!dqm_store->dirExists(dname)) continue;
412  dqm_store->cd(dname);
413  std::vector<std::string> layerVec = dqm_store->getSubdirs();
414  for (std::vector<std::string>::const_iterator iLayer = layerVec.begin(); iLayer != layerVec.end(); iLayer++) {
415  if ((*iLayer).find("BadModuleList") !=std::string::npos) continue;
416  std::vector<MonitorElement*> meVec = dqm_store->getContents((*iLayer));
417  MonitorElement* tkhmap_me = nullptr;
419  for (std::vector<MonitorElement*>::const_iterator itkh = meVec.begin(); itkh != meVec.end(); itkh++) {
420  name = (*itkh)->getName();
421  if (name.find("TkHMap") == std::string::npos) continue;
422  if (htype == "QTestAlarm" ){
423  edm::LogError("ItShouldNotBeHere") << "QTestAlarm map: you should not be here!";
424  tkhmap_me = (*itkh);
425  break;
426  } else if (name.find(htype) != std::string::npos) {
427  tkhmap_me = (*itkh);
428  break;
429  }
430  }
431  if (tkhmap_me != nullptr) {
432  if (topModules){
433  paintTkMapFromHistogram(dqm_store,tkhmap_me, htype, topNmodVec);
434  }
435  else paintTkMapFromHistogram(dqm_store,tkhmap_me, htype, nullptr);
436  }
437  }
438  dqm_store->cd(mechanicalview_dir);
439  }
440  dqm_store->cd();
441  if (topModules) printTopModules(topNmodVec, eSetup);
442  delete topNmodVec;
443 }
444 
445 void SiStripTrackerMapCreator::printTopModules(std::vector<std::pair<float,uint32_t> >* topNmodVec, const edm::EventSetup& eSetup){
446 
448  //edm::ESHandle<TrackerTopology> tTopoHandle;
449  //eSetup.get<TrackerTopologyRecord>().get(tTopoHandle);
450  //const TrackerTopology* const tTopo = tTopoHandle.product();
451  edm::ESHandle<TrackerTopology> tTopoHandle;
452  eSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
453  const TrackerTopology* const tTopo = tTopoHandle.product();
454 
455  if (topNmodVec->empty()) return;
456 
457  std::sort(topNmodVec->rbegin(), topNmodVec->rend());
458  if (topNmodVec->size() > numTopModules) topNmodVec->resize(numTopModules);
459 
460  edm::LogVerbatim("TopModules") << topModLabel;
461  edm::LogVerbatim("TopModules") << "------------------------------------------------------";
462 
463  for (std::vector<std::pair<float, uint32_t> >::const_iterator itNmod = topNmodVec->begin(); itNmod != topNmodVec->end(); itNmod++){
464  std::pair<float, uint32_t> aPair=(*itNmod);
465  uint32_t det_id = aPair.second;
466  std::ostringstream comment;
468  SiStripDetId ssdetid(aPair.second);
469  if(ssdetid.subDetector()==SiStripDetId::TIB) subdetector = "TIB ";
470  if(ssdetid.subDetector()==SiStripDetId::TID){
471  if(tTopo->tidSide(ssdetid)==1) subdetector = "TID/MINUS ";
472  if(tTopo->tidSide(ssdetid)==2) subdetector = "TID/PLUS ";
473  }
474  if(ssdetid.subDetector()==SiStripDetId::TOB) subdetector = "TOB ";
475  if(ssdetid.subDetector()==SiStripDetId::TEC){
476  if(tTopo->tecSide(ssdetid)==1) subdetector = "TEC/MINUS ";
477  if(tTopo->tecSide(ssdetid)==2) subdetector = "TEC/PLUS ";
478  }
479  uint16_t flag = getDetectorFlagAndComment(nullptr, det_id, tTopo, comment);
480  if (flag == 0) edm::LogVerbatim("TopModules") << subdetector << comment.str() << " value: "<< aPair.first;
481  }
482  edm::LogVerbatim("TopModules") << "------------------------------------------------------";
483 }
484 
485 
486 void SiStripTrackerMapCreator::paintTkMapFromHistogram(DQMStore* dqm_store, MonitorElement* me, std::string& htype, std::vector<std::pair<float, uint32_t> >* topNmodVec) {
487 
488  // edm::ESHandle<SiStripQuality> ssq;
489 
490  // if(useSSQuality_) { eSetup_.get<SiStripQualityRcd>().get(ssqLabel_,ssq); }
491 
492  const std::string& name = me->getName();
493  std::string lname = name.substr(name.find("TkHMap_")+7);
494  lname = lname.substr(lname.find("_T")+1);
495  for ( DetId det_id : tkDetMap_->getDetsForLayer(TkDetMap::getLayerNum(lname)) ) {
496  if (det_id.rawId() <= 0) continue;
497  nDet++;
499  float fval = 0.0;
500  if ( (name.find("NumberOfOff") != std::string::npos) || //temporary fix
501  (name.find("NumberOfOnTrackCluster") != std::string::npos) ) {
503  TProfile2D* tp = me->getTProfile2D() ;
504  fval = tp->GetBinEntries(tp->GetBin(xyval.ix, xyval.iy)) * tp->GetBinContent(xyval.ix, xyval.iy);
505  }
506  } else if(name.find("Residuals") != std::string::npos){
507  if(ResidualsRMS_==true){
509  TProfile2D* tp = me->getTProfile2D() ;
510  float fval_prov = tp->GetBinError(xyval.ix, xyval.iy) * sqrt(tp->GetBinEntries(tp->GetBin(xyval.ix, xyval.iy)));
511  fval = fval_prov;
512  }
513  } else {
514  float fval_prov = me->getBinContent(xyval.ix, xyval.iy);
515  fval = std::abs (fval_prov);
516  }
517  } else fval = me->getBinContent(xyval.ix, xyval.iy);
518  if (htype == "QTestAlarm") {
519  edm::LogError("ItShouldNotBeHere") << "QTestAlarm map: you should not be here!";
520  /*
521  int rval, gval, bval;
522  std::ostringstream comment;
523  uint32_t flag = 0;
524  flag = getDetectorFlagAndComment(dqm_store, det_id, comment);
525  SiStripUtility::getDetectorStatusColor(flag, rval, gval, bval);
526  if(useSSQuality_ && ssq->IsModuleBad(det_id)) { rval=255; gval=255; bval = 0;}
527  trackerMap_->fillc(det_id, rval, gval, bval);
528  trackerMap_->setText(det_id, comment.str());
529  */
530  } else {
531  if (fval == 0.0) trackerMap_->fillc(det_id,255, 255, 255);
532  else {
533  trackerMap_->fill_current_val(det_id, fval);
534  if(topNmodVec){
535  auto detPair = std::make_pair(fval,det_id);
536  topNmodVec->push_back(detPair);
537  }
538  }
539  tkMapMax_ += fval;
540  }
541  }
542 }
543 //
544 // -- Get Tracker Map Fill Range
545 //
547  tkMapMin_ = 0.0;
548  if (tkMapMax_ == 0.0) {
549  if (map_type.find("FractionOfBadChannels") != std::string::npos) tkMapMax_ = 1.0;
550  else if (map_type.find("NumberOfCluster") != std::string::npos) tkMapMax_ = 0.01;
551  else if (map_type.find("NumberOfDigi") != std::string::npos) tkMapMax_ = 0.6;
552  else if (map_type.find("NumberOfOffTrackCluster") != std::string::npos) tkMapMax_ = 100.0;
553  else if (map_type.find("NumberOfOnTrackCluster") != std::string::npos) tkMapMax_ = 50.0;
554  else if (map_type.find("StoNCorrOnTrack") != std::string::npos) tkMapMax_ = 200.0;
555  } else {
556  tkMapMax_ = tkMapMax_/nDet*1.0;
558  }
560 }
562  tkMapMin_ = 0.0;
563  if (tkMapMax_ != 0.0) {
564  tkMapMax_ = tkMapMax_/(nDet*1.0);
566  }
567  // the following line seems to be useless and misleading: in the offline map creation the range is set with the save... methods
568  // trackerMap_->setRange(tkMapMin_, tkMapMax_);
569 }
570 //
571 // -- Get Flag and status Comment
572 //
574  const TrackerTopology* tTopo, std::ostringstream& comment) {
575  // comment << " DetId " << det_id << " : ";
576  comment << "Module " << det_id;
577  uint16_t flag = 0;
578 
579  // get FED channels corresponding to the det_id
580 
581  // if(detcabling_) {
582  comment << " FEDCHs ";
583  std::vector<const FedChannelConnection*> conns = detcabling_->getConnections(det_id);
584  for(unsigned int i=0; i< conns.size() ;++i) {
585  if(conns[i]) {
586  comment << std::setw(3) << conns[i]->fedId() << "/" << std::setw(2) << conns[i]->fedCh()<< " ";
587  }
588  else {
589  comment << " ";
590  }
591  }
592  if(conns.empty()) { comment << " "; }
593  if(conns.size()==1) { comment << " "; }
594  if(conns.size()==2) { comment << " "; }
595  // }
596  if(!dqm_store) return flag;
597  // get PSU channel corresponding to the det_id
598  /*
599  comment << " PSU: ";
600  comment << psumap_.getPSUName(det_id);
601  */
602  //
603 
604  SiStripFolderOrganizer folder_organizer;
605  std::string subdet_folder, badmodule_folder;
606 
607  dqm_store->cd();
608 
609  folder_organizer.setSiStripFolderName(stripTopLevelDir_);
610  folder_organizer.getSubDetFolder(det_id, tTopo, subdet_folder);
611 
612  LogDebug("SearchBadModule") << det_id << " " << subdet_folder << " " << stripTopLevelDir_;
613 
614  if (dqm_store->dirExists(subdet_folder)){
615  badmodule_folder = subdet_folder + "/BadModuleList";
616  LogDebug("SearchBadModule") << subdet_folder << " exists: " << badmodule_folder;
617  } else {
618  // badmodule_folder = dqm_store->pwd() + "/BadModuleList";
619  edm::LogError("SubDetFolderNotFound") << subdet_folder << " does not exist for detid " << det_id;
620  return flag;
621  }
622  if (!dqm_store->dirExists(badmodule_folder)) {
623  LogDebug("BadModuleFolderNotFound") << badmodule_folder << " does not exist for detid " << det_id;
624  return flag;
625  }
626  std::ostringstream badmodule_path;
627  badmodule_path << badmodule_folder << "/" << det_id;
628  LogDebug("SearchBadModule") << badmodule_folder << " exists: " << badmodule_path;
629 
630  MonitorElement* bad_module_me = dqm_store->get(badmodule_path.str());
631  if (bad_module_me && bad_module_me->kind() == MonitorElement::DQM_KIND_INT) {
632  LogDebug("SearchBadModule") << "Monitor Element found";
633  flag = bad_module_me->getIntValue();
635  SiStripUtility::getBadModuleStatus(flag, message);
636  comment << message.c_str();
637  }
638  return flag;
639 }
640 //
641 // -- create branches for root file with tracker map values by detId and fill it
642 //
643 void SiStripTrackerMapCreator::createInfoFile(std::vector<std::string> map_names, TTree* tkinfo_tree, DQMStore* dqm_store, std::vector<uint32_t> detidList) {
644 
645  std::map<std::string, float> tkhmap_value;
646  int qtalarm_flag = 0;
647  uint32_t det_id = 0;
648 
649  if(!tkinfo_tree) {
650  edm::LogError("SiStripTrackerMapCreator::createInfoFile") << "Tree not found!";
651  }
652  else {
653  tkinfo_tree->Branch("DetId",&det_id,"DetId/i");
654  for(std::vector<std::string>::const_iterator in = map_names.begin(); in != map_names.end(); ++in) {
655  std::string mapname = (*in);
656  if(mapname == "QTestAlarm") {
657  qtalarm_flag = 0;
658  tkinfo_tree->Branch(mapname.c_str(),&qtalarm_flag,std::string(mapname+"/I").c_str());
659  } else {
660  tkhmap_value[mapname] = -1.0;
661  tkinfo_tree->Branch(mapname.c_str(),&tkhmap_value[mapname],std::string(mapname+"/F").c_str());
662  }
663  }
664 
665  std::string dirname = "";
666 
667  std::string mdir = "MechanicalView";
668  dqm_store->cd();
669  if (!SiStripUtility::goToDir(dqm_store, mdir)) {
670  edm::LogError("SiStripTrackerMapCreator::createInfoFile") << "I cannot find the SiStrip top level directory in the DQM file";
671  }
672  else {
673  const std::string& mechanicalview_dir = dqm_store->pwd();
674  dirname=mechanicalview_dir.substr(0,mechanicalview_dir.find_last_of("/"));
675  edm::LogInfo("SiStripTrackerMapCreator::createInfoFile") << "SiStrip top level directory is " << dirname;
676  }
677  dqm_store->cd();
678 
679  std::vector<TkHistoMap> tkHMaps;
680 
681  uint32_t nHists = map_names.size();
682 
683  for(uint32_t ih = 0; ih < nHists; ++ih) {
684  tkHMaps.emplace_back(tkDetMap_);
685  if(map_names.at(ih) != "QTestAlarm") {
686  std::string tkhmap_name = "TkHMap_" + map_names.at(ih);
687  tkHMaps.at(ih).loadTkHistoMap(dirname, tkhmap_name, true);
688  }
689  }
690 
691  for(std::vector<uint32_t>::const_iterator idet = detidList.begin(); idet != detidList.end(); ++idet) {
692  det_id = (*idet);
693  for(uint32_t ih = 0; ih < nHists; ++ih) {
694  if(map_names.at(ih) == "QTestAlarm") {
695  std::ostringstream comment;
696  qtalarm_flag = getDetectorFlag(det_id);
697  } else {
698  tkhmap_value[map_names.at(ih)] = tkHMaps.at(ih).getValue(det_id);
699  }
700  }
701  if(!tkinfo_tree) {
702  edm::LogError("SiStripTrackerMapCreator::createInfoFile") << "Tree not found!";
703  }
704  else {
705  tkinfo_tree->Fill();
706  }
707  }
708  }
709 
710 }
#define LogDebug(id)
static const char runNumber_[]
T getUntrackedParameter(std::string const &, T const &) const
int64_t getIntValue() const
void fillc_all_blank()
Definition: TrackerMap.cc:2741
const std::string & pwd() const
Definition: DQMStore.cc:719
void setSiStripFolderName(std::string name)
void getSubDetFolder(const uint32_t &detid, const TrackerTopology *tTopo, std::string &folder_name)
TProfile2D * getTProfile2D() const
uint16_t getDetectorFlag(uint32_t det_id)
void save_as_psutrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="psu_svgmap.svg", int width=100+(360+100)*5+300, int height=50+(150+50)*6+300)
Definition: TrackerMap.cc:1853
TString subdetector
edm::ESHandle< SiStripDetCabling > detcabling_
bool exists(std::string const &parameterName) const
checks if a parameter exists
static void getDetectorStatusColor(int status, int &rval, int &gval, int &bval)
const std::string & getName() const
get name of ME
uint16_t getDetectorFlagAndComment(DQMStore *dqm_store, uint32_t det_id, const TrackerTopology *tTopo, std::ostringstream &comment)
void printBadModuleList(std::map< unsigned int, std::string > *badmodmap, const edm::EventSetup &eSetup)
static void getBadModuleStatus(uint16_t flag, std::string &message)
std::vector< DetId > getDetsForLayer(int layer) const
Definition: TkDetMap.h:144
void setTitle(std::string s)
Definition: TrackerMap.h:132
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
static int getLayerNum(const std::string &in)
Definition: TkDetMap.cc:310
void fill_all_blank()
Definition: TrackerMap.cc:2749
void setTkMapFromAlarm(DQMStore *dqm_store, const edm::EventSetup &eSetup)
unsigned int tidSide(const DetId &id) const
std::map< uint32_t, uint16_t > detflag_
const edm::EventSetup & eSetup_
T sqrt(T t)
Definition: SSEVec.h:18
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:699
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool IsModuleBad(const uint32_t &detid) const
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
Definition: DQMStore.cc:1813
void setTkMapFromHistogram(DQMStore *dqm_store, std::string &htype, const edm::EventSetup &eSetup)
std::vector< MonitorElement * > getContents(const std::string &path) const
Definition: DQMStore.cc:1841
std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:1764
void fillc(int idmod, int RGBcode)
Definition: TrackerMap.h:109
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:812
const SiStripFedCabling * fedCabling() const
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
unsigned long long int rval
Definition: vlib.h:22
SubDetector subDetector() const
Definition: SiStripDetId.h:114
Definition: DetId.h:18
const std::map< uint32_t, std::vector< const FedChannelConnection * > > & getDetCabling() const
void save_as_fedtrackermap(bool print_total=true, float minval=0., float maxval=0., std::string s="fed_svgmap.svg", int width=100+(90+100)*31+300, int height=150+(2940+150)*1+300)
Definition: TrackerMap.cc:2135
void cd()
go to top directory (ie. root)
Definition: DQMStore.cc:724
void paintTkMapFromHistogram(DQMStore *dqm_store, MonitorElement *me, std::string &map_type, std::vector< std::pair< float, uint32_t > > *topNmodVec)
const T & get() const
Definition: EventSetup.h:58
def uint(string)
void createInfoFile(std::vector< std::string > map_names, TTree *tkinfo_tree, DQMStore *dqm_store, std::vector< uint32_t > detidList)
void printTopModules(std::vector< std::pair< float, uint32_t > > *topNmodVec, const edm::EventSetup &eSetup)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
void setRange(float min, float max)
Definition: TrackerMap.cc:671
unsigned int layer(const DetId &id) const
double getBinContent(int binx) const
get content of bin (1-D)
void printonline()
Definition: TrackerMap.cc:2887
void createForOffline(const edm::ParameterSet &tkmapPset, DQMStore *dqm_store, std::string &htype, const edm::EventSetup &eSetup)
SiStripTrackerMapCreator(const edm::EventSetup &eSetup)
void fill_current_val(int idmod, float current_val)
Definition: TrackerMap.cc:2759
const TkLayerMap::XYbin & getXY(DetId detid, DetId &cached_detid, int16_t &cached_layer, TkLayerMap::XYbin &cached_XYbin) const
Definition: TkDetMap.cc:549
void setText(int idmod, std::string s)
Definition: TrackerMap.cc:2797
static bool goToDir(DQMStore *dqm_store, std::string name)
T const * product() const
Definition: ESHandle.h:86
Definition: vlib.h:208
void setTkMapRange(std::string &map_type)
Kind kind() const
Get the type of the monitor element.
void create(const edm::ParameterSet &tkmapPset, DQMStore *dqm_store, std::string &htype, const edm::EventSetup &eSetup)
unsigned int tecSide(const DetId &id) const
#define comment(par)
Definition: vmac.h:163
void paintTkMapFromAlarm(uint32_t det_id, const TrackerTopology *tTopo, DQMStore *dqm_store, bool isBad=false, std::map< unsigned int, std::string > *badmodmap=nullptr)