CMS 3D CMS Logo

SiPixelInformationExtractor.cc
Go to the documentation of this file.
1 
12 
15 
18 
26 
29 
35 
36 #include "TClass.h"
37 #include "TText.h"
38 #include "TROOT.h"
39 #include "TPad.h"
40 #include "TStyle.h"
41 #include "TSystem.h"
42 #include "TString.h"
43 #include "TImage.h"
44 #include "TPaveText.h"
45 #include "TImageDump.h"
46 #include "TRandom.h"
47 #include "TStopwatch.h"
48 #include "TAxis.h"
49 #include "TPaveLabel.h"
50 #include "Rtypes.h"
51 #include "TH1F.h"
52 #include "TH2F.h"
53 #include "TProfile.h"
54 
55 #include <iostream>
56 #include <cmath>
57 #include <map>
58 
59 #include <cstdlib> // for free() - Root can allocate with malloc() - sigh...
60 
61 using namespace std;
62 using namespace edm;
63 
64 //------------------------------------------------------------------------------
68 SiPixelInformationExtractor::SiPixelInformationExtractor(bool offlineXMLfile) : offlineXMLfile_(offlineXMLfile) {
69  edm::LogInfo("SiPixelInformationExtractor") <<
70  " Creating SiPixelInformationExtractor " << "\n" ;
71 
72  readReference_ = false;
73 }
74 
75 //------------------------------------------------------------------------------
80  edm::LogInfo("SiPixelInformationExtractor") <<
81  " Deleting SiPixelInformationExtractor " << "\n" ;
82 
83 }
84 
85 //------------------------------------------------------------------------------
90 
91 
92 //============================================================================================================
93 // -- Return type of ME
94 //
96 {
97  string qtype = theMe->getRootObject()->IsA()->GetName() ;
98  if( qtype.find("TH1") != string::npos )
99  {
100  return "TH1" ;
101  } else if ( qtype.find("TH2") != string::npos ) {
102  return "TH2" ;
103  } else if ( qtype.find("TH3") != string::npos ) {
104  return "TH3" ;
105  }
106  return "TH1" ;
107 }
108 
109 //------------------------------------------------------------------------------
114 void SiPixelInformationExtractor::getItemList(const multimap<string, string>& req_map,
115  string item_name,
116  vector<string>& items) {
117  items.clear();
118  for (multimap<string, string>::const_iterator it = req_map.begin();
119  it != req_map.end(); it++) {
120  if (it->first == item_name) {
121  items.push_back(it->second);
122  }
123  }
124 }
125 
126 //------------------------------------------------------------------------------
131 bool SiPixelInformationExtractor::hasItem(multimap<string,string>& req_map,
132  string item_name){
133  multimap<string,string>::iterator pos = req_map.find(item_name);
134  if (pos != req_map.end()) return true;
135  return false;
136 }
137 
138 //------------------------------------------------------------------------------
143 std::string SiPixelInformationExtractor::getItemValue(const std::multimap<std::string,std::string>& req_map,
144  std::string item_name){
145  std::multimap<std::string,std::string>::const_iterator pos = req_map.find(item_name);
146  std::string value = " ";
147  if (pos != req_map.end()) {
148  value = pos->second;
149  }
150  return value;
151 }
152 std::string SiPixelInformationExtractor::getItemValue(std::multimap<std::string,std::string>& req_map,
153  std::string item_name){
154  std::multimap<std::string,std::string>::iterator pos = req_map.find(item_name);
155  std::string value = " ";
156  if (pos != req_map.end()) {
157  value = pos->second;
158  }
159  return value;
160 }
161 
162 //
163 // -- Get color name from status
164 //
166  if (status == dqm::qstatus::STATUS_OK) col = "#00ff00";
167  else if (status == dqm::qstatus::WARNING) col = "#ffff00";
168  else if (status == dqm::qstatus::ERROR) col = "#ff0000";
169  else if (status == dqm::qstatus::OTHER) col = "#ffa500";
170  else col = "#0000ff";
171 }
172 //
173 // -- Get Image name from ME
174 //
175 void SiPixelInformationExtractor::selectColor(string& col, vector<QReport*>& reports){
176  int istat = 999;
177  int status = 0;
178  for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
179  it++) {
180  status = (*it)->getStatus();
181  if (status > istat) istat = status;
182  }
183  selectColor(col, status);
184 }
185 //
186 // -- Get Image name from status
187 //
189  if (status == dqm::qstatus::STATUS_OK) name="images/LI_green.gif";
190  else if (status == dqm::qstatus::WARNING) name="images/LI_yellow.gif";
191  else if (status == dqm::qstatus::ERROR) name="images/LI_red.gif";
192  else if (status == dqm::qstatus::OTHER) name="images/LI_orange.gif";
193  else name="images/LI_blue.gif";
194 }
195 //
196 // -- Get Image name from ME
197 //
198 void SiPixelInformationExtractor::selectImage(string& name, vector<QReport*>& reports){
199  int istat = 999;
200  int status = 0;
201  for (vector<QReport*>::const_iterator it = reports.begin(); it != reports.end();
202  it++) {
203  status = (*it)->getStatus();
204  if (status > istat) istat = status;
205  }
206  selectImage(name, status);
207 }
208 
209 //------------------------------------------------------------------------------
214  double & colorValue,
215  pair<double,double> & norm)
216 {
217  double normalizationX = 1 ;
218  double normalizationY = 1 ;
219  double meanX = 0 ;
220  double meanY = 0 ;
221 
222  colorValue = 0 ;
223 
224  pair<double,double> normX ;
225  pair<double,double> normY ;
226 
227  string theMEType = getMEType(theME) ;
228 
229  if( theMEType.find("TH1") != string::npos)
230  {
231  meanX = (double)theME->getMean();
232  getNormalization(theME, normX, "TH1") ;
233  normalizationX = fabs( normX.second - normX.first) ;
234  if( normalizationX == 0 ) {normalizationX=1.E-20;}
235  colorValue = meanX / normalizationX ;
236  norm.first = normX.first ;
237  norm.second = normX.second ;
238  }
239 
240  if( theMEType.find("TH2") != string::npos)
241  {
242  meanX = (double)theME->getMean(1);
243  meanY = (double)theME->getMean(2);
244  getNormalization2D(theME, normX, normY, "TH2") ;
245  normalizationX = fabs( normX.second - normX.first) ;
246  normalizationY = fabs( normY.second - normY.first) ;
247  if( normalizationX == 0 ) {normalizationX=1.E-20;}
248  if( normalizationY == 0 ) {normalizationY=1.E-20;}
249  double cVX = meanX / normalizationX ;
250  double cVY = meanY / normalizationY ;
251  colorValue = sqrt(cVX*cVX + cVY*cVY) ;
252  if( normalizationX >= normalizationY )
253  {
254  norm.first = normX.first;
255  norm.second = normX.second ;
256  } else {
257  norm.first = normY.first;
258  norm.second = normY.second ;
259  }
260  }
261 
262  return ;
263 }
264 
265 //------------------------------------------------------------------------------
270  pair<double,double>& norm,
271  std::string theMEType)
272 {
273  double normLow = 0 ;
274  double normHigh = 0 ;
275 
276  if( theMEType.find("TH1") != string::npos)
277  {
278  normHigh = (double)theME->getNbinsX() ;
279  norm.first = normLow ;
280  norm.second = normHigh ;
281  }
282 }
283 
284 //------------------------------------------------------------------------------
289  pair<double,double>& normX,
290  pair<double,double>& normY,
291  std::string theMEType)
292 {
293  double normLow = 0 ;
294  double normHigh = 0 ;
295 
296  if( theMEType.find("TH2") != string::npos )
297  {
298  normHigh = (double)theME->getNbinsX() ;
299  normX.first = normLow ;
300  normX.second = normHigh ;
301  normHigh = (double)theME->getNbinsY() ;
302  normY.first = normLow ;
303  normY.second = normHigh ;
304  }
305 }
306 
307 //------------------------------------------------------------------------------
313 {
314  const string& mEName = mE->getName();
315 
316  int detId = 0;
317 
318  if( mEName.find("_3") != string::npos )
319  {
320  string detIdString = mEName.substr((mEName.find_last_of("_"))+1,9);
321  std::istringstream isst;
322  isst.str(detIdString);
323  isst>>detId;
324  }
325  return detId ;
326 
327 }
328 
330 
331 void SiPixelInformationExtractor::bookNoisyPixels(DQMStore::IBooker & iBooker, float noiseRate_,bool Tier0Flag) {
332 //std::cout<<"BOOK NOISY PIXEL MEs!"<<std::endl;
333  iBooker.cd();
334  if(noiseRate_>=0.){
335  iBooker.setCurrentFolder("Pixel/Barrel");
336  EventRateBarrelPixels = iBooker.book1D("barrelEventRate","Digi event rate for all Barrel pixels",1000,0.,0.01);
337  EventRateBarrelPixels->setAxisTitle("Event Rate",1);
338  EventRateBarrelPixels->setAxisTitle("Number of Pixels",2);
339  iBooker.cd();
340  iBooker.setCurrentFolder("Pixel/Endcap");
341  EventRateEndcapPixels = iBooker.book1D("endcapEventRate","Digi event rate for all Endcap pixels",1000,0.,0.01);
342  EventRateEndcapPixels->setAxisTitle("Event Rate",1);
343  EventRateEndcapPixels->setAxisTitle("Number of Pixels",2);
344  }
345 }
346 
347 
349 
350 void SiPixelInformationExtractor::findNoisyPixels(DQMStore::IBooker & iBooker, DQMStore::IGetter & iGetter, bool init, float noiseRate_, int noiseRateDenominator_, edm::ESHandle<SiPixelFedCablingMap> theCablingMap)
351 {
352 
353 
354  if(init){
355  endOfModules_=false;
356  nevents_=noiseRateDenominator_;
357  if(nevents_ == -1){
358  iBooker.cd();
359  iGetter.cd();
360  iBooker.setCurrentFolder("Pixel/EventInfo");
361  iGetter.setCurrentFolder("Pixel/EventInfo");
362  nevents_ = (iGetter.get("Pixel/EventInfo/processedEvents"))->getIntValue();
363  }
364  iBooker.cd();
365  iGetter.cd();
366  myfile_.open ("NoisyPixelList.txt", ios::app);
367  myfile_ << "Noise summary, ran over " << nevents_ << " events, threshold was set to " << noiseRate_ << std::endl;
368  }
369  string currDir = iBooker.pwd();
370  string dname = currDir.substr(currDir.find_last_of("/")+1);
371 
372 
373  if(dname.find("Module_")!=string::npos){
374  vector<string> meVec = iGetter.getMEs();
375  for (vector<string>::const_iterator it = meVec.begin(); it != meVec.end(); it++) {
376  string full_path = currDir + "/" + (*it);
377  if(full_path.find("hitmap_siPixelDigis")!=string::npos){
378  MonitorElement * me = iGetter.get(full_path);
379  if (!me) continue;
380  int detid=getDetId(me); int pixcol=-1; int pixrow=-1;
381  std::vector<std::pair<std::pair<int, int>, float> > noisyPixelsInModule;
382  TH2F * hothisto = me->getTH2F();
383  if(hothisto){
384  for(int i=1; i!=hothisto->GetNbinsX()+1; i++){
385  for(int j=1; j!=hothisto->GetNbinsY()+1; j++){
386  float value = (hothisto->GetBinContent(i,j))/float(nevents_);
387  if(me->getPathname().find("Barrel")!=string::npos){
388  EventRateBarrelPixels = iGetter.get("Pixel/Barrel/barrelEventRate");
390  }else if(me->getPathname().find("Endcap")!=string::npos){
391  EventRateEndcapPixels = iGetter.get("Pixel/Endcap/endcapEventRate");
393  }
394  if(value > noiseRate_){
395  pixcol = i-1;
396  pixrow = j-1;
397 
398  std::pair<int, int> address(pixcol, pixrow);
399  std::pair<std::pair<int, int>, float> PixelStats(address, value);
400  noisyPixelsInModule.push_back(PixelStats);
401  }
402  }
403  }
404  }
405  noisyDetIds_[detid] = noisyPixelsInModule;
406  }
407  }
408  }
409  vector<string> subDirVec = iGetter.getSubdirs();
410  for (vector<string>::const_iterator ic = subDirVec.begin();
411  ic != subDirVec.end(); ic++) {
412  if((*ic).find("AdditionalPixelErrors")!=string::npos) continue;
413  iGetter.cd(*ic);
414  iBooker.cd(*ic);
415  init=false;
416  findNoisyPixels(iBooker,iGetter,init,noiseRate_,noiseRateDenominator_,theCablingMap);
417  iBooker.goUp();
418  iGetter.setCurrentFolder(iBooker.pwd());
419  }
420 
421  if(iBooker.pwd().find("EventInfo")!=string::npos) endOfModules_ = true;
422 
423  if(!endOfModules_) return;
424  if(currDir == "Pixel/EventInfo/reportSummaryContents"){
425  std::vector<std::pair<sipixelobjects::DetectorIndex,double> > pixelvec;
426  std::map<uint32_t,int> myfedmap;
427  std::map<uint32_t,std::string> mynamemap;
428  int realfedID = -1;
429  int counter = 0;
430  int n_noisyrocs_all = 0;
431  int n_noisyrocs_barrel = 0;
432  int n_noisyrocs_endcap = 0;
433  int n_verynoisyrocs_all = 0;
434  int n_verynoisyrocs_barrel = 0;
435  int n_verynoisyrocs_endcap = 0;
436 
437  for(int fid = 0; fid < 40; fid++){
438  for(std::map<uint32_t, std::vector< std::pair<std::pair<int, int>, float> > >::const_iterator it = noisyDetIds_.begin();
439  it != noisyDetIds_.end(); it++){
440  uint32_t detid = (*it).first;
441  std::vector< std::pair<std::pair<int, int>, float> > noisyPixels = (*it).second;
442  // now convert into online conventions:
443  for(int fedid=0; fedid<=40; ++fedid){
444  SiPixelFrameConverter converter(theCablingMap.product(),fedid);
445  uint32_t newDetId = detid;
446  if(converter.hasDetUnit(newDetId)){
447  realfedID=fedid;
448  break;
449  }
450  }
451  if(fid == realfedID){
452  if(realfedID==-1) continue;
453  DetId detId(detid);
454  uint32_t detSubId = detId.subdetId();
456  bool HalfModule = false;
457  if (detSubId == 2){ //FPIX
458  PixelEndcapName nameworker(detid);
459  outputname = nameworker.name();
460  } else if(detSubId == 1){ //BPIX
461  PixelBarrelName nameworker(detid);
462  outputname = nameworker.name();
463  HalfModule = nameworker.isHalfModule();
464 
465  } else{
466  continue;
467  }
468  std::map<int,int> myrocmap;
469  myfedmap[detid]=realfedID;
470  mynamemap[detid]=outputname;
471 
472  for(std::vector< std::pair< std::pair<int,int>, float> >::const_iterator pxl = noisyPixels.begin();
473  pxl != noisyPixels.end(); pxl++){
474  std::pair<int,int> offlineaddress = (*pxl).first;
475  float Noise_frac = (*pxl).second;
476  int offlineColumn = offlineaddress.first;
477  int offlineRow = offlineaddress.second;
478  counter++;
479 
481  SiPixelFrameConverter formatter(theCablingMap.product(),realfedID);
482  sipixelobjects::DetectorIndex detector = {detid, offlineRow, offlineColumn};
483  formatter.toCabling(cabling,detector);
484  // cabling should now contain cabling.roc and cabling.dcol and cabling.pxid
485  // however, the coordinates now need to be converted from dcl,pxid to the row,col coordinates used in the calibration info
487  loc.dcol = cabling.dcol;
488  loc.pxid = cabling.pxid;
489 
490  sipixelobjects::LocalPixel locpixel(loc);
491  assert(realfedID >= 0);
492  assert(cabling.link >= 0);
493  assert(cabling.roc >= 0);
494  sipixelobjects::CablingPathToDetUnit path = {static_cast<unsigned int>(realfedID),
495  static_cast<unsigned int>(cabling.link),
496  static_cast<unsigned int>(cabling.roc)};
497  const sipixelobjects::PixelROC *theRoc = theCablingMap->findItem(path);
498  // END of FIX
499 
500  int onlineColumn = locpixel.rocCol();
501  int onlineRow= locpixel.rocRow();
502  myrocmap[(theRoc->idInDetUnit())]++;
503 
504  // ROC numbers in the barrel go from 8 to 15 instead of 0 to 7 in half modules. This is a
505  // fix to get the roc number, and add 8 to it if:
506  // it's a Barrel module AND on the minus side AND a Half module
507 
508  int rocnumber = -1;
509 
510  if((detSubId == 1) && (outputname.find("mO")!=string::npos || outputname.find("mI")!=string::npos) && (HalfModule)){
511  rocnumber = theRoc->idInDetUnit() + 8;
512  }
513  else{
514  rocnumber = theRoc->idInDetUnit();
515  }
516 
517  myfile_ <<"NAME: "<<outputname<<" , DETID: "<<detid<<" , OFFLINE: col,row: "<<offlineColumn<<","<<offlineRow<<" \t , ONLINE: roc,col,row: "<<rocnumber<<","<<onlineColumn<<","<<onlineRow<< " \t , fed,dcol,pixid,link: "<<realfedID<<","<<loc.dcol<<","<<loc.pxid<<","<<cabling.link << ", Noise fraction: " << Noise_frac << std::endl;
518  }
519  for(std::map<int, int>::const_iterator nrc = myrocmap.begin(); nrc != myrocmap.end(); nrc++){
520  if((*nrc).second > 0){
521  n_noisyrocs_all++;
522  if(detSubId == 2){
523  n_noisyrocs_endcap++;
524  } else if(detSubId == 1){
525  n_noisyrocs_barrel++;}
526  }
527  if((*nrc).second > 40){
528  n_verynoisyrocs_all++;
529  if(detSubId == 2){
530  n_verynoisyrocs_endcap++;
531  } else if(detSubId == 1){
532  n_verynoisyrocs_barrel++;}
533  }
534  }
535  }
536 
537  }
538  }
539  myfile_ << "There are " << n_noisyrocs_all << " noisy ROCs (ROCs with at least 1 noisy pixel) in the entire detector. " << n_noisyrocs_endcap << " are in the FPIX and " << n_noisyrocs_barrel << " are in the BPIX. " << endl;
540  myfile_ << "There are " << n_verynoisyrocs_all << " highly noisy ROCs (ROCs with at least 10% of all pixels passing the noise threshold) in the entire detector. " << n_verynoisyrocs_endcap << " are in the FPIX and " << n_verynoisyrocs_barrel << " are in the BPIX. " << endl;
541 
542  }
543  myfile_.close();
544  return;
545 }
SiPixelInformationExtractor(bool offlineXMLfile)
Constructor of the SiPixelInformationExtractor class.
void getNormalization(MonitorElement *mE, std::pair< double, double > &norm, std::string theMEType)
(Documentation under construction).
static const int OTHER
const std::string & getPathname() const
get pathname of parent folder
TObject * getRootObject() const
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:307
int init
Definition: HydjetWrapper.h:67
void computeStatus(MonitorElement *mE, double &colorValue, std::pair< double, double > &norm)
(Documentation under construction).
static const int WARNING
const std::string & getName() const
get name of ME
std::map< uint32_t, std::vector< std::pair< std::pair< int, int >, float > > > noisyDetIds_
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
bool hasItem(std::multimap< std::string, std::string > &req_map, std::string item_name)
(Documentation under construction).
identify pixel inside single ROC
Definition: LocalPixel.h:7
void readConfiguration()
Read Configuration File.
std::string name() const override
from base class
void Fill(long long x)
bool isHalfModule() const
full or half module
T sqrt(T t)
Definition: SSEVec.h:18
void bookNoisyPixels(DQMStore::IBooker &iBooker, float noiseRate, bool Tier0Flag)
void findNoisyPixels(DQMStore::IBooker &iBooker, DQMStore::IGetter &iGetter, bool init, float noiseRate, int noiseRateDenominator, edm::ESHandle< SiPixelFedCablingMap > theCablingMap)
unsigned int idInDetUnit() const
id of this ROC in DetUnit etermined by token path
Definition: PixelROC.h:40
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
std::string name() const override
from base class
void selectImage(std::string &name, int status)
Definition: value.py:1
void getNormalization2D(MonitorElement *mE, std::pair< double, double > &normX, std::pair< double, double > &normY, std::string theMEType)
(Documentation under construction).
std::string getMEType(MonitorElement *mE)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
TH2F * getTH2F() const
double collumn and pixel ID in double collumn representation
Definition: LocalPixel.h:22
Definition: DetId.h:18
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
const std::string & pwd()
Definition: DQMStore.cc:287
std::string getItemValue(const std::multimap< std::string, std::string > &req_map, std::string item_name)
(Documentation under construction).
int getNbinsY() const
get # of bins in Y-axis
void selectColor(std::string &col, int status)
return(e1-e2)*(e1-e2)+dp *dp
void getItemList(const std::multimap< std::string, std::string > &req_map, std::string item_name, std::vector< std::string > &items)
(Documentation under construction).
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:349
int getDetId(MonitorElement *mE)
(Documentation under construction).
HLT enums.
std::vector< std::string > getSubdirs()
Definition: DQMStore.cc:325
col
Definition: cuy.py:1008
static const int STATUS_OK
~SiPixelInformationExtractor()
Destructor of the SiPixelInformationExtractor class.
int getNbinsX() const
get # of bins in X-axis
const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &path) const override
std::vector< std::string > getMEs()
Definition: DQMStore.cc:329
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
T const * product() const
Definition: ESHandle.h:86
static const int ERROR