#include <MagBinFinders.h>
Public Member Functions | |
virtual int | binIndex (T z) const |
returns an index in the valid range for the bin closest to Z | |
virtual int | binIndex (int i) const |
returns an index in the valid range | |
virtual T | binPosition (int ind) const |
the middle of the bin. | |
GeneralBinFinderInZ () | |
GeneralBinFinderInZ (std::vector< T > &borders) | |
Static Public Member Functions | |
static double | pi () |
static double | twoPi () |
Private Attributes | |
std::vector< T > | theBins |
std::vector< T > | theBorders |
int | theNbins |
T | theZOffset |
T | theZStep |
A Z bin finder for a non-periodic group of detectors. Search is done starting from an initial equal-size-bin guess. Therefore it becomes less efficient for binnings with very different bin size. It is not particularily suited for very few bins...
Definition at line 115 of file MagBinFinders.h.
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ | ( | ) | [inline] |
Definition at line 118 of file MagBinFinders.h.
: theNbins(0), theZStep(0), theZOffset(0) {}
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ | ( | std::vector< T > & | borders | ) | [inline] |
Definition at line 120 of file MagBinFinders.h.
: theNbins(borders.size()), theBorders(++(borders.begin()),borders.end()) { // Skip border of 1. bin // FIXME: crashes for borders.size()==1 (trivial case) // FIXME set theBins!!! theZOffset = theBorders.front(); if (theNbins>2) { theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2); } else { theZStep = 1.; // Not relevant in this case... } // cout << "GeneralBinFinderInZ " << theBorders.size() // << " " << theZStep << endl; }
virtual int MagBinFinders::GeneralBinFinderInZ< T >::binIndex | ( | T | z | ) | const [inline, virtual] |
returns an index in the valid range for the bin closest to Z
Implements BaseBinFinder< T >.
Definition at line 155 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), MagBinFinders::GeneralBinFinderInZ< double >::binPosition(), and MagBRod::findVolume().
{ int bin = binIndex(int((z-theZOffset)/theZStep)+1); // check left border if (bin > 0) { if (z < theBorders[bin-1]) { // z is to the left of the left border, the correct bin is left for (int i=bin-1; ; --i) { if (i <= 0) return 0; if ( z > theBorders[i-1]) return i; } } } else return 0; // check right border if (bin < theNbins-1) { if ( z > theBorders[bin]) { // z is to the right of the right border, the correct bin is right for (int i=bin+1; ; ++i) { if (i >= theNbins-1) return theNbins-1; if ( z < theBorders[i]) return i; } } } else return theNbins-1; // if we arrive here it means that the bin is ok return bin; }
virtual int MagBinFinders::GeneralBinFinderInZ< T >::binIndex | ( | int | i | ) | const [inline, virtual] |
returns an index in the valid range
Implements BaseBinFinder< T >.
Definition at line 187 of file MagBinFinders.h.
virtual T MagBinFinders::GeneralBinFinderInZ< T >::binPosition | ( | int | ind | ) | const [inline, virtual] |
the middle of the bin.
Implements BaseBinFinder< T >.
Definition at line 192 of file MagBinFinders.h.
static double MagBinFinders::GeneralBinFinderInZ< T >::pi | ( | ) | [inline, static] |
Definition at line 196 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::twoPi().
{ return 3.141592653589793238;}
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi | ( | ) | [inline, static] |
Definition at line 197 of file MagBinFinders.h.
{ return 2.*pi();}
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBins [private] |
Definition at line 205 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binPosition().
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBorders [private] |
Definition at line 204 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), and MagBinFinders::GeneralBinFinderInZ< double >::GeneralBinFinderInZ().
int MagBinFinders::GeneralBinFinderInZ< T >::theNbins [private] |
Definition at line 201 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), and MagBinFinders::GeneralBinFinderInZ< double >::GeneralBinFinderInZ().
T MagBinFinders::GeneralBinFinderInZ< T >::theZOffset [private] |
Definition at line 203 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), and MagBinFinders::GeneralBinFinderInZ< double >::GeneralBinFinderInZ().
T MagBinFinders::GeneralBinFinderInZ< T >::theZStep [private] |
Definition at line 202 of file MagBinFinders.h.
Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), and MagBinFinders::GeneralBinFinderInZ< double >::GeneralBinFinderInZ().