CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

XHistogram Class Reference

#include <XHistogram.h>

List of all members.

Classes

struct  position

Public Types

typedef TH2I ColorMap
typedef TH2F Histogram
typedef std::pair< double, double > Range

Public Member Functions

ColorMapcolormap (void) const
 access the colormap
void fill (double x, double y, const std::vector< double > &weight, double norm)
 fill one point
void fill (double x, double y, const std::vector< double > &weight, double norm, unsigned int colour)
 fill one point and set its color
void fill (const Range &x, const Range &y, const std::vector< double > &weight, double norm)
 fill one segment, normalizing each bin's weight to the fraction of the segment it contains
void fill (const Range &x, const Range &y, const std::vector< double > &weight, double norm, unsigned int colour)
 fill one segment and set its color, normalizing each bin's weight to the fraction of the segment it contains
Histogramget (size_t h=0) const
 access one of the histograms
Histogramnormalization (void) const
 access the normalization
void normalize (void)
 normalize the histograms
void setMinDl (double dl)
 XHistogram (void)
 default CTOR
 XHistogram (size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, std::vector< double > max)

Protected Member Functions

void check_weight (const std::vector< double > &weight) throw (std::invalid_argument)
 check the weights passed as an std::vector have the correct size
std::vector< positionsplitSegment (Range x, Range y) const
 split a segment into a vector of points

Protected Attributes

boost::shared_ptr< ColorMapm_colormap
boost::shared_ptr< Histogramm_dummy
std::vector< boost::shared_ptr
< Histogram > > 
m_histograms
double m_minDl
boost::shared_ptr< Histogramm_normalization
size_t m_size
size_t m_xBins
Range m_xRange
size_t m_yBins
Range m_yRange

Detailed Description

Definition at line 13 of file XHistogram.h.


Member Typedef Documentation

typedef TH2I XHistogram::ColorMap

Definition at line 16 of file XHistogram.h.

typedef TH2F XHistogram::Histogram

Definition at line 17 of file XHistogram.h.

typedef std::pair<double, double> XHistogram::Range

Definition at line 18 of file XHistogram.h.


Constructor & Destructor Documentation

XHistogram::XHistogram ( void  ) [inline]

default CTOR

Definition at line 35 of file XHistogram.h.

XHistogram::XHistogram ( size_t  size,
size_t  bins_x,
size_t  bins_y,
Range  x,
Range  y,
size_t  zones,
std::vector< double >  max 
) [inline]

Definition at line 49 of file XHistogram.h.

References i, m_colormap, m_histograms, m_normalization, and m_size.

                                                                                                                 :
    m_minDl( 0.000001 ),
    m_xRange( x ),
    m_yRange( y ),
    m_xBins( bins_x ),
    m_yBins( bins_y ),
    m_size( size ),
    m_histograms( m_size ),
    m_normalization(),
    m_colormap()
  {
    // setup unnamed ROOT histograms
    for (size_t i = 0; i < m_size; ++i) {
      m_histograms[i].reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
      m_histograms[i]->SetMinimum( 0. );
      m_histograms[i]->SetMaximum( max[i] );
    }
    m_normalization.reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
    m_colormap.reset(new ColorMap( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second ));
    m_colormap->SetMinimum( 0 );
    m_colormap->SetMaximum( zones );
    Histogram( 0, 0, 0, 0., 0., 0, 0., 0. );        // make ROOT "forget" about unnamed histograms
  }

Member Function Documentation

void XHistogram::check_weight ( const std::vector< double > &  weight) throw (std::invalid_argument) [inline, protected]

check the weights passed as an std::vector have the correct size

Definition at line 135 of file XHistogram.h.

References m_size, and CommonMethods::weight().

Referenced by fill().

  {
    // run time check for vector size
    if (weight.size() != m_size)
       throw std::invalid_argument("weight: wrong number of elements");
  }
ColorMap* XHistogram::colormap ( void  ) const [inline]

access the colormap

Definition at line 104 of file XHistogram.h.

References m_colormap.

Referenced by TrackingMaterialPlotter::draw().

  {
    return (ColorMap *) m_colormap->Clone(0);
  }
void XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm,
unsigned int  colour 
)

fill one point and set its color

Definition at line 81 of file XHistogram.cc.

References check_weight(), HcalObjRepresent::Fill(), h, m_colormap, m_histograms, m_normalization, and m_size.

{
  check_weight( weight );

  for (size_t h = 0; h < m_size; ++h)
    m_histograms[h]->Fill( x, y, weight[h] );
  m_normalization->Fill( x, y, norm );
  m_colormap->SetBinContent( m_colormap->FindBin(x, y), (float) colour );
}
void XHistogram::fill ( const Range x,
const Range y,
const std::vector< double > &  weight,
double  norm,
unsigned int  colour 
)

fill one segment and set its color, normalizing each bin's weight to the fraction of the segment it contains

Definition at line 105 of file XHistogram.cc.

References check_weight(), f, HcalObjRepresent::Fill(), h, i, m_colormap, m_histograms, m_normalization, m_size, alignCSCRings::s, splitSegment(), and v.

{
  check_weight( weight );

  std::vector<position> v = splitSegment( x, y );
  for (size_t i = 0, s = v.size(); i < s; ++i) {
    for (size_t h = 0; h < m_size; ++h)
      m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] );
    m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm );
    m_colormap->SetBinContent( m_colormap->FindBin(v[i].x, v[i].y), (float) colour );
  }
}
void XHistogram::fill ( double  x,
double  y,
const std::vector< double > &  weight,
double  norm 
)
void XHistogram::fill ( const Range x,
const Range y,
const std::vector< double > &  weight,
double  norm 
)

fill one segment, normalizing each bin's weight to the fraction of the segment it contains

Definition at line 92 of file XHistogram.cc.

References check_weight(), f, HcalObjRepresent::Fill(), h, i, m_histograms, m_normalization, m_size, alignCSCRings::s, splitSegment(), and v.

{
  check_weight( weight );

  std::vector<position> v = splitSegment( x, y );
  for (size_t i = 0, s = v.size(); i < s; ++i) {
    for (size_t h = 0; h < m_size; ++h)
      m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] );
    m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm );
  }
}
Histogram* XHistogram::get ( size_t  h = 0) const [inline]

access one of the histograms

Definition at line 89 of file XHistogram.h.

References h, m_histograms, and m_size.

Referenced by TrackingMaterialPlotter::draw().

  {
    if (h < m_size)
      return (Histogram *) m_histograms[h]->Clone(0);
    else
      return 0;
  }
Histogram* XHistogram::normalization ( void  ) const [inline]

access the normalization

Definition at line 98 of file XHistogram.h.

References m_normalization.

  {
    return (Histogram *) m_normalization->Clone(0);
  }
void XHistogram::normalize ( void  )

normalize the histograms

Definition at line 119 of file XHistogram.cc.

References h, i, m_histograms, m_normalization, and m_size.

Referenced by TrackingMaterialPlotter::normalize().

{
  for (int i = 0; i < m_normalization->GetSize(); ++i) {
    if ((*m_normalization)[i] > 0.) {
      for (size_t h = 0; h < m_size; ++h)
        (*m_histograms[h])[i] /= (*m_normalization)[i];
      (*m_normalization)[i] = 1.;
    } 
  }
}
void XHistogram::setMinDl ( double  dl) [inline]

set the minimum length of sub-segment a segment should be split into: when splitting across bin boundaries with splitSegment(...), sub-segments shorter than this are skipped

Definition at line 111 of file XHistogram.h.

References m_minDl.

  {
    m_minDl = dl;
  }
std::vector< XHistogram::position > XHistogram::splitSegment ( Range  x,
Range  y 
) const [protected]

split a segment into a vector of points

Definition at line 7 of file XHistogram.cc.

References f, i, m_minDl, m_xBins, m_xRange, m_yBins, m_yRange, position, query::result, alignCSCRings::s, python::multivaluedict::sort(), relval_steps::steps, v, x, and detailsBasic3DVector::y.

Referenced by fill().

{
  double deltaX = rangeX.second - rangeX.first;
  double deltaY = rangeY.second - rangeY.first;
  double length = hypot(deltaX, deltaY);
  double stepX = (m_xRange.second - m_xRange.first) / m_xBins;
  double stepY = (m_yRange.second - m_yRange.first) / m_yBins;

  int min_i, max_i, min_j, max_j;
  if (rangeX.first < rangeX.second) {
    min_i = (int) ceil(rangeX.first / stepX);            // included
    max_i = (int) floor(rangeX.second / stepX) + 1;      // excluded
  } else {
    min_i = (int) ceil(rangeX.second / stepX);
    max_i = (int) floor(rangeX.first / stepX) + 1;
  }
  if (rangeY.first < rangeY.second) {
    min_j = (int) ceil(rangeY.first / stepY);
    max_j = (int) floor(rangeY.second / stepY) + 1;
  } else {
    min_j = (int) ceil(rangeY.second / stepY);
    max_j = (int) floor(rangeY.first / stepY) + 1;
  }

  int steps = max_i-min_i + max_j-min_j + 2;
  std::vector<position> v;
  v.clear();
  v.reserve(steps);

  v.push_back( position(0., rangeX.first, rangeY.first) );
  double x, y, f;
  for (int i = min_i; i < max_i; ++i) {
    x = i * stepX;
    y = rangeY.first + (x - rangeX.first) * deltaY / deltaX;
    f = std::fabs( (x - rangeX.first) / deltaX );
    v.push_back( position(f, x, y) );
  }
  for (int i = min_j; i < max_j; ++i) {
    y = i * stepY;
    x = rangeX.first + (y - rangeY.first) * deltaX / deltaY;
    f = std::fabs( (y - rangeY.first) / deltaY );
    v.push_back( position(f, x, y) );
  }
  v.push_back( position(1., rangeX.second, rangeY.second) );

  // sort by distance from the start of the segment
  std::sort(v.begin(), v.end());

  // filter away the fragments shorter than m_minDl, and save the center of each fragment along with its fractionary length
  std::vector<position> result;
  result.push_back( v.front() );
  for (int i = 1, s = v.size(); i < s; ++i) {
    double mx = (v[i].x + v[i-1].x) / 2.;
    double my = (v[i].y + v[i-1].y) / 2.;
    double df = (v[i].f - v[i-1].f);
    if (df * length < m_minDl)
      continue;
    result.push_back( position( df, mx, my ) );
  }

  return result;
}

Member Data Documentation

boost::shared_ptr<ColorMap> XHistogram::m_colormap [protected]

Definition at line 30 of file XHistogram.h.

Referenced by colormap(), fill(), and XHistogram().

boost::shared_ptr<Histogram> XHistogram::m_dummy [protected]

Definition at line 31 of file XHistogram.h.

std::vector< boost::shared_ptr<Histogram> > XHistogram::m_histograms [protected]

Definition at line 28 of file XHistogram.h.

Referenced by fill(), get(), normalize(), and XHistogram().

double XHistogram::m_minDl [protected]

Definition at line 21 of file XHistogram.h.

Referenced by setMinDl(), and splitSegment().

boost::shared_ptr<Histogram> XHistogram::m_normalization [protected]

Definition at line 29 of file XHistogram.h.

Referenced by fill(), normalization(), normalize(), and XHistogram().

size_t XHistogram::m_size [protected]

Definition at line 26 of file XHistogram.h.

Referenced by check_weight(), fill(), get(), normalize(), and XHistogram().

size_t XHistogram::m_xBins [protected]

Definition at line 24 of file XHistogram.h.

Referenced by splitSegment().

Definition at line 22 of file XHistogram.h.

Referenced by splitSegment().

size_t XHistogram::m_yBins [protected]

Definition at line 25 of file XHistogram.h.

Referenced by splitSegment().

Definition at line 23 of file XHistogram.h.

Referenced by splitSegment().