CMS 3D CMS Logo

MagBinFinders.h
Go to the documentation of this file.
1 
2 // A set of binfiders adapted from CommonReco/DetLayers.
3 // FIXME: This file should eventually disappear and binfinders in
4 // CommonReco/DetLayers modified to be general enough!!!
5 
6 namespace MagBinFinders {
7  template <class T>
9  template <class T>
11 } // namespace MagBinFinders
12 
13 //----------------------------------------------------------------------
14 #ifndef GeneralBinFinderInR_H
15 #define GeneralBinFinderInR_H
16 
23 //#include "CommonReco/DetLayers/interface/RBorderFinder.h"
24 #include <cmath>
25 #include <vector>
26 
27 template <class T>
29 public:
31 
32  GeneralBinFinderInR(std::vector<T>& borders) : theNbins(borders.size()), theBorders(borders) {
33  // FIXME: compute bin positions.
34  // for (vector<T>::const_iterator i=theBorders.begin();
35  // i<theBorders.end(); ++i) {
36  // theBorders.push_back(((*i) + (*(i+1))) / 2.);
37 
38  // cout << "GeneralBinFinderInR_ " << theNbins << " " << theBorders.size() << " " << (int) this << endl;
39  }
40 
41  // /// Construct from an already initialized RBorderFinder
42  // GeneralBinFinderInR(const RBorderFinder& bf) {
43  // theBorders=bf.RBorders();
44  // theBins=bf.RBins();
45  // theNbins=theBins.size();
46  // }
47 
48  // /// Construct from the list of Det*
49  // GeneralBinFinderInR(vector<Det*>::const_iterator first,
50  // vector<Det*>::const_iterator last)
51  // : theNbins( last-first)
52  // {
53  // vector<Det*> dets(first,last);
54  // RBorderFinder bf(dets);
55  // theBorders=bf.phiBorders();
56  // theBins=bf.phiBins();
57  // theNbins=theBins.size();
58  // }
59 
62  int binIndex(T R) const override {
63  int i;
64  for (i = 0; i < theNbins; ++i) {
65  if (R < theBorders[i]) { // FIXME: one can be skipped?
66  break;
67  }
68  }
69  return binIndex(i - 1);
70  }
71 
73  int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
74 
76  T binPosition(int ind) const override { return theBins[binIndex(ind)]; }
77 
78 private:
79  int theNbins;
80  std::vector<T> theBorders;
81  std::vector<T> theBins;
82 };
83 #endif
84 //----------------------------------------------------------------------
85 
86 //----------------------------------------------------------------------
87 #ifndef GeneralBinFinderInZ_H
88 #define GeneralBinFinderInZ_H
89 
98 #include <cmath>
99 
100 template <class T>
102 public:
104 
105  GeneralBinFinderInZ(std::vector<T>& borders)
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  }
119 
120  // FIXME: ??? theNbins e theBorders hanno size theNbins -1.
121  // theBorders[1] e' l'inizio del secondo bin !!!
122 
123  // GeneralBinFinderInZ(vector<Det*>::const_iterator first,
124  // vector<Det*>::const_iterator last) :
125  // theNbins( last-first)
126  // {
127  // theBins.reserve(theNbins);
128  // for (vector<Det*>::const_iterator i=first; i<last-1; ++i) {
129  // theBins.push_back((**i).position().z());
130  // theBorders.push_back(((**i).position().z() +
131  // (**(i+1)).position().z()) / 2.);
132  // }
133 
134  // theZOffset = theBorders.front();
135  // theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
136  // }
137 
139  int binIndex(T z) const override {
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  }
173 
175  int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
176 
178  T binPosition(int ind) const override { return theBins[binIndex(ind)]; }
179 
180  static double pi() { return 3.141592653589793238; }
181  static double twoPi() { return 2. * pi(); }
182 
183 private:
184  int theNbins;
187  std::vector<T> theBorders;
188  std::vector<T> theBins;
189 };
190 #endif
191 //----------------------------------------------------------------------
MagBinFinders::GeneralBinFinderInZ::GeneralBinFinderInZ
GeneralBinFinderInZ()
Definition: MagBinFinders.h:103
MagBinFinders::GeneralBinFinderInR::theBorders
std::vector< T > theBorders
Definition: MagBinFinders.h:80
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
end
#define end
Definition: vmac.h:39
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
MagBinFinders::GeneralBinFinderInR::binIndex
int binIndex(T R) const override
Definition: MagBinFinders.h:62
MagBinFinders::GeneralBinFinderInZ::binIndex
int binIndex(int i) const override
returns an index in the valid range
Definition: MagBinFinders.h:175
MagBinFinders
Definition: MagBinFinders.h:6
MagBinFinders::GeneralBinFinderInZ::theNbins
int theNbins
Definition: MagBinFinders.h:184
MagBinFinders::GeneralBinFinderInZ::binPosition
T binPosition(int ind) const override
the middle of the bin.
Definition: MagBinFinders.h:178
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
MagBinFinders::GeneralBinFinderInR::binPosition
T binPosition(int ind) const override
The middle of the bin.
Definition: MagBinFinders.h:76
BaseBinFinder.h
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
MagBinFinders::GeneralBinFinderInZ::twoPi
static double twoPi()
Definition: MagBinFinders.h:181
MagBinFinders::GeneralBinFinderInR::GeneralBinFinderInR
GeneralBinFinderInR()
Definition: MagBinFinders.h:30
MagBinFinders::GeneralBinFinderInR
Definition: MagBinFinders.h:8
MagBinFinders::GeneralBinFinderInR::binIndex
int binIndex(int i) const override
Returns an index in the valid range.
Definition: MagBinFinders.h:73
MagBinFinders::GeneralBinFinderInZ::theZOffset
T theZOffset
Definition: MagBinFinders.h:186
T
long double T
Definition: Basic3DVectorLD.h:48
MagBinFinders::GeneralBinFinderInZ::theBins
std::vector< T > theBins
Definition: MagBinFinders.h:188
MagBinFinders::GeneralBinFinderInR::theBins
std::vector< T > theBins
Definition: MagBinFinders.h:81
BaseBinFinder
Definition: BaseBinFinder.h:11
MagBinFinders::GeneralBinFinderInR::GeneralBinFinderInR
GeneralBinFinderInR(std::vector< T > &borders)
Definition: MagBinFinders.h:32
MagBinFinders::GeneralBinFinderInR::theNbins
int theNbins
Definition: MagBinFinders.h:79
dttmaxenums::R
Definition: DTTMax.h:29
begin
#define begin
Definition: vmac.h:32
MagBinFinders::GeneralBinFinderInZ::GeneralBinFinderInZ
GeneralBinFinderInZ(std::vector< T > &borders)
Definition: MagBinFinders.h:105
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MagBinFinders::GeneralBinFinderInZ
Definition: MagBinFinders.h:10