CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
SiPixelHistoPlotter Class Reference

#include <SiPixelHistoPlotter.h>

Classes

struct  PlotParameter
 

Public Member Functions

void createPlots (DQMStore *bei)
 
void createStaticPlot (MonitorElement *me, const std::string &file_name)
 
void getNamedImageBuffer (const std::string &path, std::string &image)
 
void setNewPlot (std::string &path, std::string &option, int width, int height)
 
 SiPixelHistoPlotter ()
 
 ~SiPixelHistoPlotter ()
 

Private Member Functions

void createDummyImage (const std::string &name)
 
void fillNamedImageBuffer (TCanvas *c1, const std::string &name)
 (Documentation under construction). More...
 
bool hasNamedImage (const std::string &name)
 
void makePlot (DQMStore *bei, const PlotParameter &par)
 
void setDrawingOption (TH1 *hist)
 
void setLines (MonitorElement *me, std::string &meName, double &ymin, double &ymax, double &warning, double &error, double &channelFraction)
 
void setSubDetAxisDrawing (std::string detector, TH1F *histo)
 

Private Attributes

std::map< std::string,
std::string > 
namedPictureBuffer_
 
std::vector< PlotParameterplotList_
 

Detailed Description

Definition at line 17 of file SiPixelHistoPlotter.h.

Constructor & Destructor Documentation

SiPixelHistoPlotter::SiPixelHistoPlotter ( )

Definition at line 29 of file SiPixelHistoPlotter.cc.

29  {
30  edm::LogInfo("SiPixelHistoPlotter") <<
31  " Creating SiPixelHistoPlotter " << "\n" ;
32 }
SiPixelHistoPlotter::~SiPixelHistoPlotter ( )

Definition at line 36 of file SiPixelHistoPlotter.cc.

36  {
37  edm::LogInfo("SiPixelHistoPlotter") <<
38  " Deleting SiPixelHistoPlotter " << "\n" ;
39  plotList_.clear();
40 
41 }
std::vector< PlotParameter > plotList_

Member Function Documentation

void SiPixelHistoPlotter::createDummyImage ( const std::string &  name)
private

Definition at line 316 of file SiPixelHistoPlotter.cc.

References recoMuon::in, and geometryCSVtoXML::line.

316  {
317  string line;
318  ostringstream local_str;
319  // Read back the file line by line and temporarily store it in a stringstream
320  std::ifstream * imagefile = new std::ifstream("images/EmptyPlot.png",ios::in);
321  if(imagefile->is_open()) {
322  while (getline( *imagefile, line )) {
323  local_str << line << endl ;
324  }
325  }
326  namedPictureBuffer_.insert(pair<string, string>(name, local_str.str()));
327 
328  imagefile->close() ;
329 }
std::map< std::string, std::string > namedPictureBuffer_
void SiPixelHistoPlotter::createPlots ( DQMStore bei)

Definition at line 63 of file SiPixelHistoPlotter.cc.

References mergeVDriftHistosByStation::name.

Referenced by SiPixelInformationExtractor::createImages().

63  {
64  string name = "Dummy";
65  if (!hasNamedImage(name)) createDummyImage(name);
66  //cout<<"HP::createPlots:PlotList size="<<plotList_.size()<<endl;
67  for (vector<PlotParameter>::iterator it = plotList_.begin();
68  it != plotList_.end(); it++) {
69  makePlot(bei, (*it));
70  }
71  plotList_.clear();
72 }
bool hasNamedImage(const std::string &name)
void makePlot(DQMStore *bei, const PlotParameter &par)
void createDummyImage(const std::string &name)
std::vector< PlotParameter > plotList_
void SiPixelHistoPlotter::createStaticPlot ( MonitorElement me,
const std::string &  file_name 
)

Definition at line 352 of file SiPixelHistoPlotter.cc.

References svgfig::canvas(), edmPickEvents::command, cmsHarvester::file_name, MonitorElement::getRefRootObject(), MonitorElement::getRefTH1(), MonitorElement::getTH1(), and mergeVDriftHistosByStation::name.

352  {
353  TH1* hist1 = me->getTH1();
354  TCanvas* canvas = new TCanvas("TKCanvas", "TKCanvas", 600, 400);
355  if (hist1) {
356  TText tTitle;
357  tTitle.SetTextFont(64);
358  tTitle.SetTextSizePixels(20);
359 
360  setDrawingOption(hist1);
361  hist1->Draw();
362  string name = hist1->GetName();
363  if (me->getRefRootObject()) {
364  TH1* hist1_ref = me->getRefTH1();
365  if (hist1_ref) {
366  hist1_ref->SetLineColor(4);
367  hist1_ref->SetMarkerColor(4);
368  if (name.find("SUM") != string::npos) hist1_ref->Draw("same");
369  else hist1_ref->DrawNormalized("same", hist1->GetEntries());
370  }
371  }
372  }
373  canvas->Update();
374  string command = "rm -f " + file_name;
375  gSystem->Exec(command.c_str());
376  canvas->Print(file_name.c_str(),"png");
377  canvas->Clear();
378  delete canvas;
379 }
TH1 * getRefTH1(void) const
void setDrawingOption(TH1 *hist)
def canvas
Definition: svgfig.py:481
TH1 * getTH1(void) const
TObject * getRefRootObject(void) const
void SiPixelHistoPlotter::fillNamedImageBuffer ( TCanvas *  c1,
const std::string &  name 
)
private

(Documentation under construction).

This method

Definition at line 255 of file SiPixelHistoPlotter.cc.

References i, mergeVDriftHistosByStation::name, NULL, and reco::return().

256 {
257 //cout<<"Entering SiPixelHistoPlotter::fillNamedImageBuffer: "<<endl;
258  // DQMScope enter;
259  // Now extract the image
260  // 114 - stands for "no write on Close"
261 // cout << ACYellow << ACBold
262 // << "[SiPixelInformationExtractor::fillNamedImageBuffer()] "
263 // << ACPlain
264 // << "A canvas: "
265 // << c1->GetName()
266 // << endl ;
267  c1->Update();
268  c1->Modified();
269  TImageDump imgdump("tmp.png", 114);
270  c1->Paint();
271 
272 // get an internal image which will be automatically deleted
273 // in the imgdump destructor
274  TImage *image = imgdump.GetImage();
275 
276  if( image == NULL )
277  {
278  //cout << "No TImage found for "
279 // << name
280  // << endl ;
281  return ;
282  }
283  //cout<<"found an image!"<<endl;
284  char *buf;
285  int sz = 0;
286  image->GetImageBuffer(&buf, &sz);
287 
288  ostringstream local_str;
289  for (int i = 0; i < sz; i++) local_str << buf[i];
290 
291 // delete [] buf;
292  ::free(buf); // buf is allocated via realloc() by a C language AfterStep library invoked by the
293  // default (and so far only) TImage implementation in root, TASImage.
294 
295  // clear the first element map if # of entries > 30
297  //cout<<"filling namedPictureBuffer_["<<name<<"] now"<<endl;
298  namedPictureBuffer_[name] = local_str.str();
299  //if (namedPictureBuffer_[name].size() > 0) cout << "image created " << name << endl;
300 //cout<<"... leaving SiPixelHistoPlotter::fillNamedImageBuffer!"<<endl;
301 }
bool hasNamedImage(const std::string &name)
int i
Definition: DBlmapReader.cc:9
std::map< std::string, std::string > namedPictureBuffer_
#define NULL
Definition: scimark2.h:8
return(e1-e2)*(e1-e2)+dp *dp
void SiPixelHistoPlotter::getNamedImageBuffer ( const std::string &  path,
std::string &  image 
)

Definition at line 239 of file SiPixelHistoPlotter.cc.

239  {
240  map<string, string>::iterator cPos = namedPictureBuffer_.find(path);
241  if (cPos != namedPictureBuffer_.end()) {
242  image = cPos->second;
243  if (namedPictureBuffer_.size() > 99 ) namedPictureBuffer_.erase(cPos);
244  } else {
245  cPos = namedPictureBuffer_.find("Dummy");
246  image = cPos->second;
247  }
248 }
std::map< std::string, std::string > namedPictureBuffer_
tuple path
else: Piece not in the list, fine.
bool SiPixelHistoPlotter::hasNamedImage ( const std::string &  name)
private

Definition at line 306 of file SiPixelHistoPlotter.cc.

306  {
307  map<string, string>::const_iterator cPos = namedPictureBuffer_.find(name);
308  if (cPos == namedPictureBuffer_.end()) {
309  return false;
310  } else return true;
311 }
std::map< std::string, std::string > namedPictureBuffer_
void SiPixelHistoPlotter::makePlot ( DQMStore bei,
const PlotParameter par 
)
private

Definition at line 77 of file SiPixelHistoPlotter.cc.

References svgfig::canvas(), SiPixelHistoPlotter::PlotParameter::CHeight, SiPixelHistoPlotter::PlotParameter::CWidth, MonitorElement::DQM_KIND_TH2F, relativeConstraints::error, DQMStore::get(), MonitorElement::getName(), MonitorElement::getRefRootObject(), MonitorElement::getRefTH1(), MonitorElement::getRootObject(), SiPixelUtility::getStatus(), SiPixelUtility::getStatusColor(), timingPdfMaker::histo, MonitorElement::kind(), mergeVDriftHistosByStation::name, SiPixelHistoPlotter::PlotParameter::Option, SiPixelHistoPlotter::PlotParameter::Path, SiPixelUtility::setDrawingOption(), dqm::qstatus::STATUS_OK, GlobalPosition_Frontier_DevDB_cff::tag, runonSM::text, SiStripMonitorClusterAlca_cfi::xmax, SiStripMonitorClusterAlca_cfi::xmin, SiStripMonitorClusterAlca_cfi::ymax, and SiStripMonitorClusterAlca_cfi::ymin.

77  {
78 //cout<<"Entering SiPixelHistoPlotter::makePlot: "<<endl;
79  TCanvas * canvas = new TCanvas("PXCanvas", "PXCanvas", par.CWidth, par.CHeight);
80  gROOT->Reset();
81  gStyle->SetPalette(1,0);
82  gStyle->SetOptStat(111110);
83  canvas->SetBorderMode(0);
84  canvas->SetFillColor(0);
85 
86  TPaveText * paveOnCanvas = new TPaveText(0.57,0.79,0.77,0.99,"NDCtr");
87  paveOnCanvas->SetFillColor(0);
88 
89  //std::cout<<"::makePlot:Trying to plot "<<par.Path<<std::endl;
90  MonitorElement * me = bei->get(par.Path);
91  if (me) {
92 
93  string opt = "";
94  if (me->kind() == MonitorElement::DQM_KIND_TH2F)
95  { opt = "COLZ"; gStyle->SetOptStat(10); }
96  me->getRootObject()->Draw(opt.c_str());
97  int istat = SiPixelUtility::getStatus(me);
98 
99  string dopt = par.Option;
100  string tag;
101  int icol;
102  SiPixelUtility::getStatusColor(istat, icol, tag);
103 
104  TH1F* histo = dynamic_cast<TH1F*>(me->getRootObject());
105  string var = (me->getName()).substr((me->getName()).find_last_of("/")+1);
106  if (histo) {
107  //setDrawingOption(histo);
108  //histo->Draw(opt.c_str());
109  string name = histo->GetName();
110  if (me->getRefRootObject()) {
111  TH1* histo_ref = me->getRefTH1();
112  if (histo_ref) {
113  histo_ref->SetLineColor(4);
114  histo_ref->SetMarkerColor(4);
115  if (name.find("SUM") != string::npos) histo_ref->Draw("same");
116  else histo_ref->DrawNormalized("same", histo->GetEntries());
117  }
118  }
119  }
120  canvas->Update();
121 
122  //TH1* histo = me->getTH1();
123  //TH1F* tproject = 0;
124  //if (dopt == "projection") {
125  //getProjection(me, tproject);
126  //if (tproject) tproject->Draw();
127  //else histo->Draw();
128  //} else {
129  // histo->Draw();
130  //}
131  //TText tTitle;
132  //tTitle.SetTextFont(64);
133  //tTitle.SetTextSizePixels(20);
134  //tTitle.DrawTextNDC(0.1, 0.92, histo->GetName());
135 
136  //if (icol != 1) {
137  // TText tt;
138  // tt.SetTextSize(0.12);
139  // tt.SetTextColor(icol);
140  // tt.DrawTextNDC(0.5, 0.5, tag.c_str());
141  //}
142 
143  TLine* l_min = new TLine();
144  TLine* l_max = new TLine();
145  l_min->SetLineWidth(4);
146  l_max->SetLineWidth(4);
147 
148 
149  if(istat!=0){
150  TText* statusOnCanvas = paveOnCanvas->AddText(tag.c_str());
151  statusOnCanvas->SetTextSize(0.08);
152  statusOnCanvas->SetTextFont(112);
153  statusOnCanvas->SetNDC(kTRUE);
154  statusOnCanvas->SetTextColor(icol);
155 
156  double ymax = -1.;
157  double ymin = -1.;
158  double xmax = -1.;
159  double xmin = -1.;
160  double warning = -1.;
161  double error = -1.;
162  double channelFraction = -1.;
163  //if(var.find("SUM") != string::npos){
164  //cout << "ME name: " << var << endl;
165  setLines(me,var,ymin,ymax,warning,error,channelFraction);
166  //cout << "ymin: " << ymin << " ymax: " << ymax << " warning: " << warning << " error: " << error << " channelFraction: " << channelFraction << endl;
167 
168  if(istat!=dqm::qstatus::STATUS_OK){
169  string textMessage = "fraction of channels failing:";
170  TText* messageOnCanvas = paveOnCanvas->AddText(textMessage.c_str());
171  messageOnCanvas->SetTextSize(0.03);
172  messageOnCanvas->SetNDC(kTRUE);
173  char text[10];
174  sprintf(text,"%.2f %%",channelFraction);
175  messageOnCanvas = paveOnCanvas->AddText(text);
176  messageOnCanvas->SetTextSize(0.035);
177  messageOnCanvas->SetNDC(kTRUE);
178  }
179  if(ymin!= -1. && ymax!=-1.){
181  l_min->SetLineColor(icol);
182  l_max->SetLineColor(icol);
183  if(var.find("SUM") != string::npos){
184  xmin = histo->GetXaxis()->GetXmin();
185  xmax = histo->GetXaxis()->GetXmax();
186  //cout<<"xmin="<<xmin<<" , xmax="<<xmax<<" , ymin="<<ymin<<" , ymax="<<ymax<<endl;
187  l_min->SetX1(xmin);
188  l_min->SetX2(xmax);
189  l_min->SetY1(ymin);
190  l_min->SetY2(ymin);
191  l_min->Draw("same");
192  l_max->SetX1(xmin);
193  l_max->SetX2(xmax);
194  l_max->SetY1(ymax);
195  l_max->SetY2(ymax);
196  l_max->Draw("same");
197  }else{
198  xmin = ymin;
199  xmax = ymax;
200  ymin = histo->GetYaxis()->GetBinLowEdge(1);
201  ymax = histo->GetMaximum();
202  //cout<<"xmin="<<xmin<<" , xmax="<<xmax<<" , ymin="<<ymin<<" , ymax="<<ymax<<endl;
203  l_min->SetX1(xmin);
204  l_min->SetX2(xmin);
205  l_min->SetY1(ymin);
206  l_min->SetY2(ymax);
207  l_min->Draw("same");
208  l_max->SetX1(xmax);
209  l_max->SetX2(xmax);
210  l_max->SetY1(ymin);
211  l_max->SetY2(ymax);
212  l_max->Draw("same");
213  }
214  }
215  //setSubDetAxisDrawing((me->getName()),histo);
216  //}
217  paveOnCanvas->Draw("same");
218  }
219  if(((var.find("Barrel") != string::npos) && (var.find("SUM") != string::npos)) ||
220  ((var.find("Endcap") != string::npos) && (var.find("SUM") != string::npos)))
221  setSubDetAxisDrawing((me->getName()),histo);
222 
223  canvas->Update();
224 
225 
226  //cout<<"Calling fillNamedImageBuffer now!"<<endl;
227  fillNamedImageBuffer(canvas, par.Path);
228  canvas->Clear();
229  } else {
230  createDummyImage(par.Path);
231  }
232  delete canvas;
233  //cout<<"... leaving SiPixelHistoPlotter::makePlot!"<<endl;
234 }
const std::string & getName(void) const
get name of ME
TH1 * getRefTH1(void) const
void setSubDetAxisDrawing(std::string detector, TH1F *histo)
void setLines(MonitorElement *me, std::string &meName, double &ymin, double &ymax, double &warning, double &error, double &channelFraction)
void createDummyImage(const std::string &name)
def canvas
Definition: svgfig.py:481
static void setDrawingOption(TH1 *hist, float xlow=-1., float xhigh=-1.)
static int getStatus(MonitorElement *me)
static void getStatusColor(int status, int &rval, int &gval, int &bval)
tuple text
Definition: runonSM.py:42
Kind kind(void) const
Get the type of the monitor element.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1693
void fillNamedImageBuffer(TCanvas *c1, const std::string &name)
(Documentation under construction).
TObject * getRootObject(void) const
static const int STATUS_OK
TObject * getRefRootObject(void) const
void SiPixelHistoPlotter::setDrawingOption ( TH1 *  hist)
private

Definition at line 333 of file SiPixelHistoPlotter.cc.

333  {
334  if (!hist) return;
335 
336  TAxis* xa = hist->GetXaxis();
337  TAxis* ya = hist->GetYaxis();
338 
339  xa->SetTitleOffset(0.7);
340  xa->SetTitleSize(0.05);
341  xa->SetLabelSize(0.04);
342 
343  ya->SetTitleOffset(0.7);
344  ya->SetTitleSize(0.05);
345  ya->SetLabelSize(0.04);
346 
347 }
void SiPixelHistoPlotter::setLines ( MonitorElement me,
std::string &  meName,
double &  ymin,
double &  ymax,
double &  warning,
double &  error,
double &  channelFraction 
)
private

Definition at line 382 of file SiPixelHistoPlotter.cc.

References MonitorElement::getQErrors(), MonitorElement::getQOthers(), MonitorElement::getQWarnings(), MonitorElement::hasError(), MonitorElement::hasOtherReport(), MonitorElement::hasWarning(), zeeHLT_cff::report, AlCaHLTBitMon_QueryRunRegistry::string, runonSM::text, SiStripMonitorClusterAlca_cfi::ymax, and SiStripMonitorClusterAlca_cfi::ymin.

388  {
389 //cout<<"Entering SiPixelHistoPlotter::setLines for "<<meName<<endl;
390  std::vector<QReport *> report;
391  std::string colour;
392 
393  if (me->hasError()){
394  colour="red";
395  report= me->getQErrors();
396  } else if( me->hasWarning()){
397  colour="orange";
398  report= me->getQWarnings();
399  } else if(me->hasOtherReport()){
400  colour="black";
401  report= me->getQOthers();
402  } else {
403  colour="green";
404  }
405  for(std::vector<QReport *>::iterator itr=report.begin(); itr!=report.end();++itr ){
406  std::string text= (*itr)->getMessage();
407  //std::cout<<"ME: "<<meName<<" QTmessage:"<<text<<std::endl;
408  int num1 = text.find_first_of(":")+1;
409  int num2 = text.find_first_of("-",num1)+1;
410  int num3 = text.find_first_of(" ",num2);
411  std::stringstream dummy(text.substr(num1,num2-num1-1));
412  dummy >> ymin;
413  std::stringstream dummy1(text.substr(num2,num3-num2));
414  dummy1 >> ymax;
415  //std::cout<<",ymin="<<ymin<<",ymax="<<ymax<<std::endl;
416  int num4 = text.find_last_of("=")+2;
417  std::stringstream dummy2(text.substr(num4));
418  dummy2 >> channelFraction;
419  channelFraction = (1.- channelFraction)*100.;
420  error = 25.;
421  warning = 10.;
422  //std::cout<<",warning="<<warning<<",error="<<error<<std::endl;
423  }
424 
425 }
bool hasError(void) const
true if at least of one of the quality tests returned an error
std::vector< QReport * > getQErrors(void) const
get errors from last set of quality tests
tuple report
Definition: zeeHLT_cff.py:9
bool hasWarning(void) const
true if at least of one of the quality tests returned a warning
tuple text
Definition: runonSM.py:42
std::vector< QReport * > getQOthers(void) const
bool hasOtherReport(void) const
true if at least of one of the tests returned some other (non-ok) status
std::vector< QReport * > getQWarnings(void) const
get warnings from last set of quality tests
void SiPixelHistoPlotter::setNewPlot ( std::string &  path,
std::string &  option,
int  width,
int  height 
)

Definition at line 46 of file SiPixelHistoPlotter.cc.

References SiPixelHistoPlotter::PlotParameter::CHeight, SiPixelHistoPlotter::PlotParameter::CWidth, SiPixelHistoPlotter::PlotParameter::Option, SiPixelHistoPlotter::PlotParameter::Path, cmsHarvester::path, and create_public_lumi_plots::width.

49  {
50 //cout<<"Entering SiPixelHistoPlotter::setNewPlot for "<<path<<endl;
51  PlotParameter local_par;
52  local_par.Path = path;
53  local_par.Option = option;
54  local_par.CWidth = width;
55  local_par.CHeight = height;
56  plotList_.push_back(local_par);
57 //cout<<"... leaving SiPixelHistoPlotter::setNewPlot!"<<endl;
58 }
tuple path
else: Piece not in the list, fine.
std::vector< PlotParameter > plotList_
void SiPixelHistoPlotter::setSubDetAxisDrawing ( std::string  detector,
TH1F *  histo 
)
private

Definition at line 430 of file SiPixelHistoPlotter.cc.

References groupFilesInBlocks::tt.

430  {
431 
432  histo->GetXaxis()->SetLabelColor(0);
433 
434  string ownName = "";
435  if(detector.find("Barrel") != string::npos || detector.find("Endcap") != string::npos){
436  if(detector.find("Barrel") != string::npos){
437  ownName = "Shell";
438  }
439  if(detector.find("Endcap") != string::npos){
440  ownName = "HalfCylinder";
441  }
442 
443  TText tt;
444  tt.SetTextSize(0.04);
445  string mI = ownName + "_mI"; tt.DrawTextNDC(0.12, 0.04, mI.c_str());
446  string mO = ownName + "_mO"; tt.DrawTextNDC(0.32, 0.04, mO.c_str());
447  string pI = ownName + "_pI"; tt.DrawTextNDC(0.52, 0.04, pI.c_str());
448  string pO = ownName + "_pO"; tt.DrawTextNDC(0.72, 0.04, pO.c_str());
449  }
450  if(detector.find("Shell") != string::npos){
451  ownName = "Layer";
452  TText tt;
453  tt.SetTextSize(0.04);
454  string l_one = ownName + "_1"; tt.DrawTextNDC(0.12, 0.03, l_one.c_str());
455  string l_two = ownName + "_2"; tt.DrawTextNDC(0.42, 0.03, l_two.c_str());
456  string l_three = ownName + "_3"; tt.DrawTextNDC(0.72, 0.03, l_three.c_str());
457  }
458  if(detector.find("HalfCylinder") != string::npos){
459  ownName = "Disk";
460  TText tt;
461  tt.SetTextSize(0.04);
462  string d_one = ownName + "_1"; tt.DrawTextNDC(0.12, 0.03, d_one.c_str());
463  string d_two = ownName + "_2"; tt.DrawTextNDC(0.62, 0.03, d_two.c_str());
464  }
465 }

Member Data Documentation

std::map<std::string, std::string> SiPixelHistoPlotter::namedPictureBuffer_
private

Definition at line 57 of file SiPixelHistoPlotter.h.

std::vector<PlotParameter> SiPixelHistoPlotter::plotList_
private

Definition at line 58 of file SiPixelHistoPlotter.h.