CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Attributes

GenericBinFinderInZ< T, G > Class Template Reference

#include <GenericBinFinderInZ.h>

Inheritance diagram for GenericBinFinderInZ< T, G >:
BaseBinFinder< T >

List of all members.

Public Types

typedef std::vector< const G * >
::const_iterator 
ConstItr

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.
 GenericBinFinderInZ ()
 GenericBinFinderInZ (ConstItr first, ConstItr last)

Static Public Member Functions

static double pi ()
static double twoPi ()

Private Attributes

std::vector< TtheBins
std::vector< float > theBorders
int theNbins
T theZOffset
T theZStep

Detailed Description

template<class T, class G>
class GenericBinFinderInZ< T, G >

A Z bin finder for a non-periodic group of detectors. The template argument G should be something with a surface() method, such as a GeomDet or a GeometricSearchDet

Definition at line 16 of file GenericBinFinderInZ.h.


Member Typedef Documentation

template<class T, class G>
typedef std::vector<const G*>::const_iterator GenericBinFinderInZ< T, G >::ConstItr

Definition at line 18 of file GenericBinFinderInZ.h.


Constructor & Destructor Documentation

template<class T, class G>
GenericBinFinderInZ< T, G >::GenericBinFinderInZ ( ) [inline]

Definition at line 19 of file GenericBinFinderInZ.h.

: theNbins(0), theZStep(0), theZOffset(0) {}
template<class T, class G>
GenericBinFinderInZ< T, G >::GenericBinFinderInZ ( ConstItr  first,
ConstItr  last 
) [inline]

Definition at line 21 of file GenericBinFinderInZ.h.

                                                     :
    theNbins( last-first)
  {
    theBins.reserve(theNbins);
    for (ConstItr i=first; i<last-1; i++) {
      theBins.push_back((**i).position().z());
      theBorders.push_back(((**i).position().z() + 
                            (**(i+1)).position().z()) / 2.);
    }

    theZOffset = theBorders.front(); 
    theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
  }

Member Function Documentation

template<class T, class G>
virtual int GenericBinFinderInZ< T, G >::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 36 of file GenericBinFinderInZ.h.

Referenced by GenericBinFinderInZ< float, GeomDet >::binIndex(), GenericBinFinderInZ< float, GeomDet >::binPosition(), and MuDetRod::compatibleDets().

                                   {
    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, class G>
virtual int GenericBinFinderInZ< T, G >::binIndex ( int  i) const [inline, virtual]

returns an index in the valid range

Implements BaseBinFinder< T >.

Definition at line 68 of file GenericBinFinderInZ.h.

                                     {
    return std::min( std::max( i, 0), theNbins-1);
  }
template<class T, class G>
virtual T GenericBinFinderInZ< T, G >::binPosition ( int  ind) const [inline, virtual]

the middle of the bin.

Implements BaseBinFinder< T >.

Definition at line 73 of file GenericBinFinderInZ.h.

                                        {
    return theBins[binIndex(ind)];
  }
template<class T, class G>
static double GenericBinFinderInZ< T, G >::pi ( ) [inline, static]

Definition at line 77 of file GenericBinFinderInZ.h.

Referenced by GenericBinFinderInZ< float, GeomDet >::twoPi().

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

Definition at line 78 of file GenericBinFinderInZ.h.

{ return 2.*pi();}

Member Data Documentation

template<class T, class G>
std::vector<T> GenericBinFinderInZ< T, G >::theBins [private]
template<class T, class G>
std::vector<float> GenericBinFinderInZ< T, G >::theBorders [private]
template<class T, class G>
int GenericBinFinderInZ< T, G >::theNbins [private]
template<class T, class G>
T GenericBinFinderInZ< T, G >::theZOffset [private]
template<class T, class G>
T GenericBinFinderInZ< T, G >::theZStep [private]