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

Definition at line 103 of file MagBinFinders.h.

103 : theNbins(0), theZStep(0), theZOffset(0) {}

◆ 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 ( int  i) const
inlineoverridevirtual

returns an index in the valid range

Implements BaseBinFinder< T >.

Definition at line 175 of file MagBinFinders.h.

175 { return std::min(std::max(i, 0), theNbins - 1); }

◆ binIndex() [2/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.

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  }

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

◆ 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)]; }

◆ pi()

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

Definition at line 180 of file MagBinFinders.h.

180 { return 3.141592653589793238; }

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

◆ 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
mps_fire.i
i
Definition: mps_fire.py:355
MagBinFinders::GeneralBinFinderInZ::pi
static double pi()
Definition: MagBinFinders.h:180
min
T min(T a, T b)
Definition: MathUtil.h:58
MagBinFinders::GeneralBinFinderInZ::theBorders
std::vector< T > theBorders
Definition: MagBinFinders.h:187
MagBinFinders::GeneralBinFinderInZ::binIndex
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z
Definition: MagBinFinders.h:139
MagBinFinders::GeneralBinFinderInZ::theZStep
T theZStep
Definition: MagBinFinders.h:185
DDAxes::z
MagBinFinders::GeneralBinFinderInZ::theNbins
int theNbins
Definition: MagBinFinders.h:184
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
MagBinFinders::GeneralBinFinderInZ::theZOffset
T theZOffset
Definition: MagBinFinders.h:186
MagBinFinders::GeneralBinFinderInZ::theBins
std::vector< T > theBins
Definition: MagBinFinders.h:188