CMS 3D CMS Logo

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 >

List of all members.

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< TtheBins
std::vector< TtheBorders
int theNbins
T theZOffset
T theZStep

Detailed Description

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

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.


Constructor & Destructor Documentation

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

Definition at line 118 of file MagBinFinders.h.

: 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.

                                             :
    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;
  }

Member Function Documentation

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

                                     {
    return std::min( std::max( i, 0), theNbins-1);
  }
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.

                                        {
    return theBins[binIndex(ind)];
  }
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().

{ return 3.141592653589793238;}
template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi ( ) [inline, static]

Definition at line 197 of file MagBinFinders.h.

{ 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]