CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
MagBinFinders::GeneralBinFinderInZ< T > Class Template Reference

#include <MagBinFinders.h>

Inheritance diagram for MagBinFinders::GeneralBinFinderInZ< T >:
BaseBinFinder< T >

Public Member Functions

virtual int binIndex (T z) const
 returns an index in the valid range for the bin closest to Z More...
 
virtual int binIndex (int i) const
 returns an index in the valid range More...
 
virtual T binPosition (int ind) const
 the middle of the bin. More...
 
 GeneralBinFinderInZ ()
 
 GeneralBinFinderInZ (std::vector< T > &borders)
 
- Public Member Functions inherited from BaseBinFinder< T >
 BaseBinFinder ()
 
virtual ~BaseBinFinder ()
 

Static Public Member Functions

static double pi ()
 
static double twoPi ()
 

Private Attributes

std::vector< TtheBins
 
std::vector< TtheBorders
 
int theNbins
 
T theZOffset
 
T theZStep
 

Detailed Description

template<class T>
class MagBinFinders::GeneralBinFinderInZ< T >

Definition at line 8 of file MagBinFinders.h.

Constructor & Destructor Documentation

template<class T>
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ ( )
inline
template<class T>
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ ( std::vector< T > &  borders)
inline

Definition at line 120 of file MagBinFinders.h.

120  :
121  theNbins(borders.size()),
122  theBorders(++(borders.begin()),borders.end()) { // Skip border of 1. bin
123  // FIXME: crashes for borders.size()==1 (trivial case)
124  // FIXME set theBins!!!
125  theZOffset = theBorders.front();
126  if (theNbins>2) {
127  theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
128  } else {
129  theZStep = 1.; // Not relevant in this case...
130  }
131 
132 // cout << "GeneralBinFinderInZ " << theBorders.size()
133 // << " " << theZStep << endl;
134  }

Member Function Documentation

template<class T>
virtual int MagBinFinders::GeneralBinFinderInZ< T >::binIndex ( T  z) const
inlinevirtual

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().

155  {
156  int bin = binIndex(int((z-theZOffset)/theZStep)+1);
157 
158  // check left border
159  if (bin > 0) {
160  if (z < theBorders[bin-1]) {
161  // z is to the left of the left border, the correct bin is left
162  for (int i=bin-1; ; --i) {
163  if (i <= 0) return 0;
164  if ( z > theBorders[i-1]) return i;
165  }
166  }
167  }
168  else return 0;
169 
170  // check right border
171  if (bin < theNbins-1) {
172  if ( z > theBorders[bin]) {
173  // z is to the right of the right border, the correct bin is right
174  for (int i=bin+1; ; ++i) {
175  if (i >= theNbins-1) return theNbins-1;
176  if ( z < theBorders[i]) return i;
177  }
178  }
179  }
180  else return theNbins-1;
181 
182  // if we arrive here it means that the bin is ok
183  return bin;
184  }
int i
Definition: DBlmapReader.cc:9
virtual int binIndex(T z) const
returns an index in the valid range for the bin closest to Z
double double double z
template<class T>
virtual int MagBinFinders::GeneralBinFinderInZ< T >::binIndex ( int  i) const
inlinevirtual

returns an index in the valid range

Implements BaseBinFinder< T >.

Definition at line 187 of file MagBinFinders.h.

187  {
188  return std::min( std::max( i, 0), theNbins-1);
189  }
int i
Definition: DBlmapReader.cc:9
#define min(a, b)
Definition: mlp_lapack.h:161
const T & max(const T &a, const T &b)
template<class T>
virtual T MagBinFinders::GeneralBinFinderInZ< T >::binPosition ( int  ind) const
inlinevirtual

the middle of the bin.

Implements BaseBinFinder< T >.

Definition at line 192 of file MagBinFinders.h.

192  {
193  return theBins[binIndex(ind)];
194  }
virtual int binIndex(T z) const
returns an index in the valid range for the bin closest to Z
template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::pi ( )
inlinestatic

Definition at line 196 of file MagBinFinders.h.

Referenced by MagBinFinders::GeneralBinFinderInZ< double >::twoPi().

196 { return 3.141592653589793238;}
template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi ( )
inlinestatic

Definition at line 197 of file MagBinFinders.h.

197 { return 2.*pi();}

Member Data Documentation

template<class T>
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBins
private
template<class T>
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBorders
private
template<class T>
int MagBinFinders::GeneralBinFinderInZ< T >::theNbins
private
template<class T>
T MagBinFinders::GeneralBinFinderInZ< T >::theZOffset
private
template<class T>
T MagBinFinders::GeneralBinFinderInZ< T >::theZStep
private