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

Constructor & Destructor Documentation

◆ GeneralBinFinderInZ() [1/2]

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

◆ GeneralBinFinderInZ() [2/2]

template<class T>
MagBinFinders::GeneralBinFinderInZ< T >::GeneralBinFinderInZ ( std::vector< T > &  borders)
inline

Definition at line 105 of file MagBinFinders.h.

106  : theNbins(borders.size()), theBorders(++(borders.begin()), borders.end()) { // Skip border of 1. bin
107  // FIXME: crashes for borders.size()==1 (trivial case)
108  // FIXME set theBins!!!
109  theZOffset = theBorders.front();
110  if (theNbins > 2) {
111  theZStep = (theBorders.back() - theBorders.front()) / (theNbins - 2);
112  } else {
113  theZStep = 1.; // Not relevant in this case...
114  }
115 
116  // cout << "GeneralBinFinderInZ " << theBorders.size()
117  // << " " << theZStep << endl;
118  }

Member Function Documentation

◆ binIndex() [1/2]

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

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

139  {
140  int bin = binIndex(int((z - theZOffset) / theZStep) + 1);
141 
142  // check left border
143  if (bin > 0) {
144  if (z < theBorders[bin - 1]) {
145  // z is to the left of the left border, the correct bin is left
146  for (int i = bin - 1;; --i) {
147  if (i <= 0)
148  return 0;
149  if (z > theBorders[i - 1])
150  return i;
151  }
152  }
153  } else
154  return 0;
155 
156  // check right border
157  if (bin < theNbins - 1) {
158  if (z > theBorders[bin]) {
159  // z is to the right of the right border, the correct bin is right
160  for (int i = bin + 1;; ++i) {
161  if (i >= theNbins - 1)
162  return theNbins - 1;
163  if (z < theBorders[i])
164  return i;
165  }
166  }
167  } else
168  return theNbins - 1;
169 
170  // if we arrive here it means that the bin is ok
171  return bin;
172  }
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z

◆ binIndex() [2/2]

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

◆ binPosition()

template<class T>
T MagBinFinders::GeneralBinFinderInZ< T >::binPosition ( int  ind) const
inlineoverridevirtual

the middle of the bin.

Implements BaseBinFinder< T >.

Definition at line 178 of file MagBinFinders.h.

178 { return theBins[binIndex(ind)]; }
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z

◆ pi()

template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::pi ( )
inlinestatic

Definition at line 180 of file MagBinFinders.h.

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

180 { return 3.141592653589793238; }

◆ twoPi()

template<class T>
static double MagBinFinders::GeneralBinFinderInZ< T >::twoPi ( )
inlinestatic

Definition at line 181 of file MagBinFinders.h.

181 { return 2. * pi(); }

Member Data Documentation

◆ theBins

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

◆ theBorders

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

◆ theNbins

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

◆ theZOffset

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

◆ theZStep

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