CMS 3D CMS Logo

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