CMS 3D CMS Logo

MagBinFinders::GeneralBinFinderInZ< T > Class Template Reference

#include <MagneticField/Layers/src/MagBinFinders.h>

Inheritance diagram for MagBinFinders::GeneralBinFinderInZ< T >:

BaseBinFinder< T >

List of all members.

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
theZOffset
theZStep


Detailed Description

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

Definition at line 115 of file MagBinFinders.h.


Constructor & Destructor Documentation

template<class T>
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ (  )  [inline]

Definition at line 118 of file MagBinFinders.h.

00118 : theNbins(0), theZStep(0), theZOffset(0) {}

template<class T>
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   }
  


Member Function Documentation

template<class T>
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.

00187                                      {
00188     return std::min( std::max( i, 0), theNbins-1);
00189   }

template<class T>
virtual int MagBinFinders::GeneralBinFinderInZ< T >::binIndex ( 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   }

template<class T>
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.

00192                                         {
00193     return theBins[binIndex(ind)];
00194   }

template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::pi (  )  [inline, static]

Definition at line 196 of file MagBinFinders.h.

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

00196 { return 3.141592653589793238;}

template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi (  )  [inline, static]

Definition at line 197 of file MagBinFinders.h.

00197 { return 2.*pi();}


Member Data Documentation

template<class T>
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBins [private]

Definition at line 205 of file MagBinFinders.h.

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

template<class T>
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().

template<class T>
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().

template<class T>
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().

template<class T>
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().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:48:53 2009 for CMSSW by  doxygen 1.5.4