#include <MagneticField/Layers/src/MagBinFinders.h>
Public Member Functions | |
virtual int | binIndex (int i) const |
returns an index in the valid range | |
virtual int | binIndex (T z) const |
returns an index in the valid range for the bin closest to Z | |
virtual T | binPosition (int ind) const |
the middle of the bin. | |
GeneralBinFinderInZ (std::vector< T > &borders) | |
GeneralBinFinderInZ () | |
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 |
Definition at line 115 of file MagBinFinders.h.
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ | ( | ) | [inline] |
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ | ( | std::vector< T > & | borders | ) | [inline] |
Definition at line 120 of file MagBinFinders.h.
00120 : 00121 theNbins(borders.size()), 00122 theBorders(++(borders.begin()),borders.end()) { // Skip border of 1. bin 00123 // FIXME: crashes for borders.size()==1 (trivial case) 00124 // FIXME set theBins!!! 00125 theZOffset = theBorders.front(); 00126 if (theNbins>2) { 00127 theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2); 00128 } else { 00129 theZStep = 1.; // Not relevant in this case... 00130 } 00131 00132 // cout << "GeneralBinFinderInZ " << theBorders.size() 00133 // << " " << theZStep << endl; 00134 }
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 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().
00155 { 00156 int bin = binIndex(int((z-theZOffset)/theZStep)+1); 00157 00158 // check left border 00159 if (bin > 0) { 00160 if (z < theBorders[bin-1]) { 00161 // z is to the left of the left border, the correct bin is left 00162 for (int i=bin-1; ; --i) { 00163 if (i <= 0) return 0; 00164 if ( z > theBorders[i-1]) return i; 00165 } 00166 } 00167 } 00168 else return 0; 00169 00170 // check right border 00171 if (bin < theNbins-1) { 00172 if ( z > theBorders[bin]) { 00173 // z is to the right of the right border, the correct bin is right 00174 for (int i=bin+1; ; ++i) { 00175 if (i >= theNbins-1) return theNbins-1; 00176 if ( z < theBorders[i]) return i; 00177 } 00178 } 00179 } 00180 else return theNbins-1; 00181 00182 // if we arrive here it means that the bin is ok 00183 return bin; 00184 }
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().
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi | ( | ) | [inline, static] |
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().