CMS 3D CMS Logo

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

int binIndex (T z) const override
 returns an index in the valid range for the bin closest to Z More...
 
int binIndex (int i) const override
 returns an index in the valid range More...
 
T binPosition (int ind) const override
 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>
int MagBinFinders::GeneralBinFinderInZ< T >::binIndex ( T  z) const
inlineoverridevirtual

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 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 binIndex(T z) const override
returns an index in the valid range for the bin closest to Z
bin
set the eta bin as selection string.
template<class T>
int MagBinFinders::GeneralBinFinderInZ< T >::binIndex ( int  i) const
inlineoverridevirtual

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  }
T min(T a, T b)
Definition: MathUtil.h:58
template<class T>
T MagBinFinders::GeneralBinFinderInZ< T >::binPosition ( int  ind) const
inlineoverridevirtual

the middle of the bin.

Implements BaseBinFinder< T >.

Definition at line 190 of file MagBinFinders.h.

190  {
191  return theBins[binIndex(ind)];
192  }
int binIndex(T z) const override
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.

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

Definition at line 203 of file MagBinFinders.h.

template<class T>
std::vector<T> MagBinFinders::GeneralBinFinderInZ< T >::theBorders
private

Definition at line 202 of file MagBinFinders.h.

template<class T>
int MagBinFinders::GeneralBinFinderInZ< T >::theNbins
private

Definition at line 199 of file MagBinFinders.h.

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

Definition at line 201 of file MagBinFinders.h.

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

Definition at line 200 of file MagBinFinders.h.