CMS 3D CMS Logo

VisCSCPlotWidget Class Reference

A Qt widget holding a bar plot. More...

#include <VisReco/VisMuonCSC/interface/VisCSCPlotWidget.h>

List of all members.

Public Member Functions

float getScale (void)
 let the widget calculate the scale: largest element is like MaxVal
QSize minimumSizeHint () const
 sets the data for the graph and updates
void setAutoScale (bool b)
 set the scale: val will be at 85% of height of plot
void setData (const std::vector< VisCSCStackPlots::dataPt > &data)
void setMaxVal (float val)
 ditto
QSize sizeHint () const
 standard qwidget: this is synched with x/y axis info
 VisCSCPlotWidget (const int nbins, QWidget *parent=0, const char *name=0, WFlags f=0)
 ~VisCSCPlotWidget (void)

Protected Member Functions

void mousePressEvent (QMouseEvent *)
 returns bin from position
void paintEvent (QPaintEvent *)
 return the scale factor: volatile
QPoint xform (const int i, const int val)
 where the work is done
int xinvform (const QPoint)
 transform data from bin/value space to pixels on widget

Private Attributes

bool m_autoScale
 number of bins
const int m_bins
 coords of corners of outline
std::vector< QBrush > m_brushes
 maximum of supplied data
QPointArray m_corners
 local copy of the data
std::vector
< VisCSCStackPlots::dataPt
m_data
float m_maxDataVal
float m_maxVal
 volatile: y scale
float m_scale


Detailed Description

A Qt widget holding a bar plot.

Author:
George Alverson, Northeastern University/CMS
Date:
10-MAY-2008
Designed specifically to display a (possibly sparse) set of integer data. x and y axis scales are provided by the helper classes VisCSCPlotWidgetAxisX and VisCSCPlotWidgetAxisY.

The number of bins must be declared at creation, but the data may be dynamically altered. The scale for the y-axis may either be set or calculated automatically.

Definition at line 27 of file VisCSCPlotWidget.h.


Constructor & Destructor Documentation

VisCSCPlotWidget::VisCSCPlotWidget ( const int  nbins,
QWidget *  parent = 0,
const char *  name = 0,
WFlags  f = 0 
)

Definition at line 31 of file VisCSCPlotWidget.cc.

References m_bins, and m_brushes.

00031                                                                                                 :
00032   QWidget(parent, name, f), m_bins(nbins), m_autoScale(true), m_maxVal(-1.F)
00033 {
00034         assert(m_bins>0);
00035 
00036         // set up multiple colors. Use hsv so can just pick hue.
00037 
00038         m_brushes.push_back(QBrush(QColor(120, 255, 255, QColor::Hsv))); //green
00039         m_brushes.push_back(QBrush(QColor(220, 255, 255, QColor::Hsv))); // about 
00040         m_brushes.push_back(QBrush(QColor(320, 255, 255, QColor::Hsv))); // about 
00041         m_brushes.push_back(QBrush(QColor(170, 255, 255, QColor::Hsv))); // about cyan
00042         m_brushes.push_back(QBrush(QColor(270, 255, 255, QColor::Hsv))); // about 
00043         m_brushes.push_back(QBrush(QColor( 10, 255, 255, QColor::Hsv))); // about 
00044 
00045 }

VisCSCPlotWidget::~VisCSCPlotWidget ( void   ) 

Definition at line 47 of file VisCSCPlotWidget.cc.

00048 {
00049 }


Member Function Documentation

float VisCSCPlotWidget::getScale ( void   ) 

let the widget calculate the scale: largest element is like MaxVal

Definition at line 132 of file VisCSCPlotWidget.cc.

References m_autoScale, m_maxDataVal, m_maxVal, and scale.

Referenced by VisCSCPlotWidgetAxisY::paintEvent(), paintEvent(), and setMaxVal().

00132                                      {
00133 
00134         float scale = -1.F;
00135         if (!m_autoScale && m_maxVal > 0)  // rolls over to auto if no maxVal
00136         {
00137                 scale = 0.85F * height()/m_maxVal;
00138         }
00139         else if ( m_maxDataVal != 0)
00140         {
00141                 scale = 0.85F * height()/m_maxDataVal;
00142         }
00143         
00144         
00145         return scale;
00146 }

QSize VisCSCPlotWidget::minimumSizeHint (  )  const

sets the data for the graph and updates

Definition at line 50 of file VisCSCPlotWidget.cc.

00051 {
00052         // minimumSizeHint/sizeHint must be coordinated with x/y axis 
00053         return QSize( 80, 40 );
00054 }

void VisCSCPlotWidget::mousePressEvent ( QMouseEvent *  e  )  [protected]

returns bin from position

Definition at line 147 of file VisCSCPlotWidget.cc.

References arg, GeomDetEnumerators::endcap, i, id, it, m_data, edm::second(), strip(), warning, and xinvform().

00148 {
00149         uint i = uint( xinvform( e->pos() ) );
00150         if (i < m_data.size() )
00151         {
00152             QString text = QString("Bin No: %1\n").arg(i);
00153             uint32_t strip = m_data[i].first & 0xFFFFFFFF;
00154             uint32_t chamber = (m_data[i].first >> 32) & 0xFFFFFFFF;
00155             CSCDetId id(chamber);
00156             text.append(QString("Strip: %1/").arg(strip));
00157             text.append(QString("Chamber: %1/").arg(id.chamber()));
00158             text.append(QString("Ring: %1/").arg(id.ring()));
00159             text.append(QString("Station: %1/").arg(id.station()));
00160             text.append(QString("Endcap: %1\nValues: \n").arg(id.endcap()));
00161             for (std::vector<int>::const_iterator it = m_data[i].second.begin(); it != m_data[i].second.end(); ++it)
00162             {
00163                 text.append(QString("%1\n").arg(*it,8,'f',0));
00164             }
00165             QMessageBox::information(0, "CSC Channel info", text); 
00166         }
00167         else
00168         {
00169             QMessageBox::warning(0, "CSC channel info", "channel not found");
00170         }
00171 }

void VisCSCPlotWidget::paintEvent ( QPaintEvent *   )  [protected]

return the scale factor: volatile

Definition at line 59 of file VisCSCPlotWidget.cc.

References end, getScale(), i, it, m_brushes, m_data, m_scale, and xform().

00060 {
00061         int lastBin = 0;
00062         std::vector<QPoint> vtx(1,xform(0,0)); //first corner
00063         m_scale = getScale();
00064 
00065         for (std::vector<VisCSCStackPlots::dataPt>::const_iterator it = m_data.begin(); it != m_data.end(); it++ )
00066         {
00067                 int height = std::accumulate((it->second).begin(), (it->second).end(), 0);
00068                 vtx.push_back( xform(lastBin++, height ) );
00069                 vtx.push_back( xform(lastBin,   height ) ); 
00070         }
00071         vtx.push_back( xform(lastBin, 0) ); //last corner
00072         
00073 
00074         QPainter painter(this);
00075         painter.setPen(Qt::blue);
00076 //      painter.setBrush(Qt::green);
00077 
00078         // bars
00079         for (std::vector<VisCSCStackPlots::dataPt>::iterator it = m_data.begin(); it != m_data.end(); it++ )
00080         {
00081                 std::vector<int>::const_iterator hit0 = it->second.begin();     
00082                 int height = 0;
00083                 for (std::vector<int>::const_iterator hit=hit0; hit != it->second.end(); ++hit)
00084                 {
00085                         int dx = std::distance(m_data.begin(), it);
00086                         painter.setBrush( m_brushes.at( std::distance( hit0, hit ) ) );
00087                         painter.drawRect(QRect(xform(dx, *hit+height), xform(dx+1, height) ));
00088                         height += *hit;
00089                 }
00090         }
00091         // outline
00092         // convert std::vector to QPointArray
00093         QPointArray corners(int(vtx.size()));
00094         for (uint i=0;  i < vtx.size() ; i++)
00095         {
00096                 corners.setPoint(i, vtx[i]);
00097         }
00098         painter.drawPolyline(corners);
00099 }

void VisCSCPlotWidget::setAutoScale ( bool  b  ) 

set the scale: val will be at 85% of height of plot

Definition at line 131 of file VisCSCPlotWidget.cc.

References m_autoScale.

Referenced by VisCSCStackPlots::VisCSCStackPlots().

00131 {m_autoScale = b;}

void VisCSCPlotWidget::setData ( const std::vector< VisCSCStackPlots::dataPt > &  data  ) 

Definition at line 110 of file VisCSCPlotWidget.cc.

References end, it, m_data, m_maxDataVal, and python::multivaluedict::sort().

00111 {
00112         m_data = d;
00113         dataPtCompare dpc;
00114         std::sort( m_data.begin(), m_data.end(), dpc );
00115         dataPtDataCompare dpdc;
00116         if (d.begin() == d.end())
00117         {
00118                 m_maxDataVal = -1.F; 
00119         }
00120         else
00121         {
00122                 std::vector<VisCSCStackPlots::dataPt>::const_iterator it(std::max_element(m_data.begin(), m_data.end(), dpdc ));
00123                 m_maxDataVal = std::accumulate((it->second).begin(), (it->second).end(), 0.F);
00124         }
00125 }

void VisCSCPlotWidget::setMaxVal ( float  val  ) 

ditto

Definition at line 126 of file VisCSCPlotWidget.cc.

References getScale(), and m_maxVal.

00127 {
00128         m_maxVal = val;
00129         getScale(); // resets the scale to use the max value
00130 }

QSize VisCSCPlotWidget::sizeHint ( void   )  const

standard qwidget: this is synched with x/y axis info

Definition at line 55 of file VisCSCPlotWidget.cc.

00056 {
00057         return QSize( 400, 100 );
00058 }

QPoint VisCSCPlotWidget::xform ( const int  i,
const int  val 
) [protected]

where the work is done

Definition at line 100 of file VisCSCPlotWidget.cc.

References m_bins, m_scale, and width.

Referenced by paintEvent().

00101 {
00102 
00103         return QPoint(int(float(i*(width()-1))/m_bins + 0.5F), int(floor( height() - (val * m_scale + 0.5F ))));
00104 }

int VisCSCPlotWidget::xinvform ( const   QPoint  )  [protected]

transform data from bin/value space to pixels on widget

Definition at line 105 of file VisCSCPlotWidget.cc.

References int, m_bins, and width.

Referenced by mousePressEvent().

00106 {
00107         return   int( (float(p.x()))*(m_bins)/(width()-1) ); 
00108 
00109 }       


Member Data Documentation

bool VisCSCPlotWidget::m_autoScale [private]

number of bins

Definition at line 50 of file VisCSCPlotWidget.h.

Referenced by getScale(), and setAutoScale().

const int VisCSCPlotWidget::m_bins [private]

coords of corners of outline

Definition at line 49 of file VisCSCPlotWidget.h.

Referenced by VisCSCPlotWidget(), xform(), and xinvform().

std::vector<QBrush> VisCSCPlotWidget::m_brushes [private]

maximum of supplied data

Definition at line 54 of file VisCSCPlotWidget.h.

Referenced by paintEvent(), and VisCSCPlotWidget().

QPointArray VisCSCPlotWidget::m_corners [private]

local copy of the data

Definition at line 48 of file VisCSCPlotWidget.h.

std::vector<VisCSCStackPlots::dataPt> VisCSCPlotWidget::m_data [private]

Definition at line 47 of file VisCSCPlotWidget.h.

Referenced by mousePressEvent(), paintEvent(), and setData().

float VisCSCPlotWidget::m_maxDataVal [private]

Definition at line 53 of file VisCSCPlotWidget.h.

Referenced by getScale(), and setData().

float VisCSCPlotWidget::m_maxVal [private]

volatile: y scale

Definition at line 52 of file VisCSCPlotWidget.h.

Referenced by getScale(), and setMaxVal().

float VisCSCPlotWidget::m_scale [private]

Definition at line 51 of file VisCSCPlotWidget.h.

Referenced by paintEvent(), and xform().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:35:11 2009 for CMSSW by  doxygen 1.5.4