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 >

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 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 118 of file MagBinFinders.h.

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

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 153 of file MagBinFinders.h.

Referenced by MagBinFinders::GeneralBinFinderInZ< double >::binIndex(), MagBinFinders::GeneralBinFinderInZ< double >::binPosition(), and MagBRod::findVolume().

153  {
154  int bin = binIndex(int((z-theZOffset)/theZStep)+1);
155 
156  // check left border
157  if (bin > 0) {
158  if (z < theBorders[bin-1]) {
159  // z is to the left of the left border, the correct bin is left
160  for (int i=bin-1; ; --i) {
161  if (i <= 0) return 0;
162  if ( z > theBorders[i-1]) return i;
163  }
164  }
165  }
166  else return 0;
167 
168  // check right border
169  if (bin < theNbins-1) {
170  if ( z > theBorders[bin]) {
171  // z is to the right of the right border, the correct bin is right
172  for (int i=bin+1; ; ++i) {
173  if (i >= theNbins-1) return theNbins-1;
174  if ( z < theBorders[i]) return i;
175  }
176  }
177  }
178  else return theNbins-1;
179 
180  // if we arrive here it means that the bin is ok
181  return bin;
182  }
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
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 185 of file MagBinFinders.h.

185  {
186  return std::min( std::max( i, 0), theNbins-1);
187  }
int i
Definition: DBlmapReader.cc:9
T min(T a, T b)
Definition: MathUtil.h:58
template<class T>
virtual T MagBinFinders::GeneralBinFinderInZ< T >::binPosition ( int  ind) const
inlinevirtual

the middle of the bin.

Implements BaseBinFinder< T >.

Definition at line 190 of file MagBinFinders.h.

190  {
191  return theBins[binIndex(ind)];
192  }
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 194 of file MagBinFinders.h.

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

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

Definition at line 195 of file MagBinFinders.h.

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