![]() |
![]() |
#include <SimTracker/TrackerMaterialAnalysis/plugins/XHistogram.h>
Public Types | |
typedef TH2I | ColorMap |
typedef TH2F | Histogram |
typedef std::pair< double, double > | Range |
Public Member Functions | |
ColorMap * | colormap (void) const |
access the colormap | |
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 | |
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 (double x, double y, const std::vector< double > &weight, double norm, unsigned int colour) |
fill one point and set its color | |
void | fill (double x, double y, const std::vector< double > &weight, double norm) |
fill one point | |
Histogram * | get (size_t h=0) const |
access one of the histograms | |
Histogram * | normalization (void) const |
access the normalization | |
void | normalize (void) |
normalize the histograms | |
void | setMinDl (double dl) |
set the minimum length of sub-segment a segment should be split into: when splitting across bin boundaries with splitSegment(. | |
XHistogram (size_t size, size_t bins_x, size_t bins_y, Range x, Range y, size_t zones, std::vector< double > max) | |
XHistogram (void) | |
default CTOR | |
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< position > | splitSegment (Range x, Range y) const |
split a segment into a vector of points | |
Protected Attributes | |
boost::shared_ptr< ColorMap > | m_colormap |
boost::shared_ptr< Histogram > | m_dummy |
std::vector< boost::shared_ptr < Histogram > > | m_histograms |
double | m_minDl |
boost::shared_ptr< Histogram > | m_normalization |
size_t | m_size |
size_t | m_xBins |
Range | m_xRange |
size_t | m_yBins |
Range | m_yRange |
Classes | |
struct | position |
Definition at line 13 of file XHistogram.h.
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.
XHistogram::XHistogram | ( | void | ) | [inline] |
default CTOR
Definition at line 35 of file XHistogram.h.
00035 : 00036 m_minDl( 0.000001 ), 00037 m_xRange(), 00038 m_yRange(), 00039 m_xBins(), 00040 m_yBins(), 00041 m_size(), 00042 m_histograms(), 00043 m_normalization(), 00044 m_colormap(), 00045 m_dummy() 00046 { }
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.
00049 : 00050 m_minDl( 0.000001 ), 00051 m_xRange( x ), 00052 m_yRange( y ), 00053 m_xBins( bins_x ), 00054 m_yBins( bins_y ), 00055 m_size( size ), 00056 m_histograms( m_size ), 00057 m_normalization(), 00058 m_colormap() 00059 { 00060 // setup unnamed ROOT histograms 00061 for (size_t i = 0; i < m_size; ++i) { 00062 m_histograms[i].reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second )); 00063 m_histograms[i]->SetMinimum( 0. ); 00064 m_histograms[i]->SetMaximum( max[i] ); 00065 } 00066 m_normalization.reset(new Histogram( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second )); 00067 m_colormap.reset(new ColorMap( 0, 0, bins_x, x.first, x.second, bins_y, y.first, y.second )); 00068 m_colormap->SetMinimum( 0 ); 00069 m_colormap->SetMaximum( zones ); 00070 Histogram( 0, 0, 0, 0., 0., 0, 0., 0. ); // make ROOT "forget" about unnamed histograms 00071 }
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 weight.
Referenced by fill().
00136 { 00137 // run time check for vector size 00138 if (weight.size() != m_size) 00139 throw std::invalid_argument("weight: wrong number of elements"); 00140 }
access the colormap
Definition at line 104 of file XHistogram.h.
References m_colormap.
Referenced by TrackingMaterialPlotter::draw().
00105 { 00106 return (ColorMap *) m_colormap->Clone(0); 00107 }
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, h, i, m_colormap, m_histograms, m_normalization, m_size, s, splitSegment(), and v.
00106 { 00107 check_weight( weight ); 00108 00109 std::vector<position> v = splitSegment( x, y ); 00110 for (size_t i = 0, s = v.size(); i < s; ++i) { 00111 for (size_t h = 0; h < m_size; ++h) 00112 m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] ); 00113 m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm ); 00114 m_colormap->SetBinContent( m_colormap->FindBin(v[i].x, v[i].y), (float) colour ); 00115 } 00116 }
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, h, i, m_histograms, m_normalization, m_size, s, splitSegment(), and v.
00093 { 00094 check_weight( weight ); 00095 00096 std::vector<position> v = splitSegment( x, y ); 00097 for (size_t i = 0, s = v.size(); i < s; ++i) { 00098 for (size_t h = 0; h < m_size; ++h) 00099 m_histograms[h]->Fill( v[i].x, v[i].y, v[i].f * weight[h] ); 00100 m_normalization->Fill( v[i].x, v[i].y, v[i].f * norm ); 00101 } 00102 }
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(), h, m_colormap, m_histograms, m_normalization, and m_size.
00082 { 00083 check_weight( weight ); 00084 00085 for (size_t h = 0; h < m_size; ++h) 00086 m_histograms[h]->Fill( x, y, weight[h] ); 00087 m_normalization->Fill( x, y, norm ); 00088 m_colormap->SetBinContent( m_colormap->FindBin(x, y), (float) colour ); 00089 }
void XHistogram::fill | ( | double | x, | |
double | y, | |||
const std::vector< double > & | weight, | |||
double | norm | |||
) |
fill one point
Definition at line 71 of file XHistogram.cc.
References check_weight(), h, m_histograms, m_normalization, and m_size.
Referenced by TrackingMaterialPlotter::plotSegmentInLayer(), and TrackingMaterialPlotter::plotSegmentUnassigned().
00072 { 00073 check_weight( weight ); 00074 00075 for (size_t h = 0; h < m_size; ++h) 00076 m_histograms[h]->Fill( x, y, weight[h] ); 00077 m_normalization->Fill( x, y, norm ); 00078 }
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().
00090 { 00091 if (h < m_size) 00092 return (Histogram *) m_histograms[h]->Clone(0); 00093 else 00094 return 0; 00095 }
access the normalization
Definition at line 98 of file XHistogram.h.
References m_normalization.
00099 { 00100 return (Histogram *) m_normalization->Clone(0); 00101 }
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().
00120 { 00121 for (int i = 0; i < m_normalization->GetSize(); ++i) { 00122 if ((*m_normalization)[i] > 0.) { 00123 for (size_t h = 0; h < m_size; ++h) 00124 (*m_histograms[h])[i] /= (*m_normalization)[i]; 00125 (*m_normalization)[i] = 1.; 00126 } 00127 } 00128 }
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.
00112 { 00113 m_minDl = dl; 00114 }
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, int, m_minDl, m_xBins, m_xRange, m_yBins, m_yRange, HLT_VtxMuL3::result, s, python::multivaluedict::sort(), steps, v, x, and y.
Referenced by fill().
00008 { 00009 double deltaX = rangeX.second - rangeX.first; 00010 double deltaY = rangeY.second - rangeY.first; 00011 double length = hypot(deltaX, deltaY); 00012 double stepX = (m_xRange.second - m_xRange.first) / m_xBins; 00013 double stepY = (m_yRange.second - m_yRange.first) / m_yBins; 00014 00015 int min_i, max_i, min_j, max_j; 00016 if (rangeX.first < rangeX.second) { 00017 min_i = (int) ceil(rangeX.first / stepX); // included 00018 max_i = (int) floor(rangeX.second / stepX) + 1; // excluded 00019 } else { 00020 min_i = (int) ceil(rangeX.second / stepX); 00021 max_i = (int) floor(rangeX.first / stepX) + 1; 00022 } 00023 if (rangeY.first < rangeY.second) { 00024 min_j = (int) ceil(rangeY.first / stepY); 00025 max_j = (int) floor(rangeY.second / stepY) + 1; 00026 } else { 00027 min_j = (int) ceil(rangeY.second / stepY); 00028 max_j = (int) floor(rangeY.first / stepY) + 1; 00029 } 00030 00031 int steps = max_i-min_i + max_j-min_j + 2; 00032 std::vector<position> v; 00033 v.clear(); 00034 v.reserve(steps); 00035 00036 v.push_back( position(0., rangeX.first, rangeY.first) ); 00037 double x, y, f; 00038 for (int i = min_i; i < max_i; ++i) { 00039 x = i * stepX; 00040 y = rangeY.first + (x - rangeX.first) * deltaY / deltaX; 00041 f = std::fabs( (x - rangeX.first) / deltaX ); 00042 v.push_back( position(f, x, y) ); 00043 } 00044 for (int i = min_j; i < max_j; ++i) { 00045 y = i * stepY; 00046 x = rangeX.first + (y - rangeY.first) * deltaX / deltaY; 00047 f = std::fabs( (y - rangeY.first) / deltaY ); 00048 v.push_back( position(f, x, y) ); 00049 } 00050 v.push_back( position(1., rangeX.second, rangeY.second) ); 00051 00052 // sort by distance from the start of the segment 00053 std::sort(v.begin(), v.end()); 00054 00055 // filter away the fragments shorter than m_minDl, and save the center of each fragment along with its fractionary length 00056 std::vector<position> result; 00057 result.push_back( v.front() ); 00058 for (int i = 1, s = v.size(); i < s; ++i) { 00059 double mx = (v[i].x + v[i-1].x) / 2.; 00060 double my = (v[i].y + v[i-1].y) / 2.; 00061 double df = (v[i].f - v[i-1].f); 00062 if (df * length < m_minDl) 00063 continue; 00064 result.push_back( position( df, mx, my ) ); 00065 } 00066 00067 return result; 00068 }
boost::shared_ptr<ColorMap> XHistogram::m_colormap [protected] |
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] |
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] |
Range XHistogram::m_xRange [protected] |
size_t XHistogram::m_yBins [protected] |
Range XHistogram::m_yRange [protected] |