CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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> class GeneralBinFinderInR;
8  template <class T> class GeneralBinFinderInZ;
9 }
10 
11 
12 //----------------------------------------------------------------------
13 #ifndef GeneralBinFinderInR_H
14 #define GeneralBinFinderInR_H
15 
24 //#include "CommonReco/DetLayers/interface/RBorderFinder.h"
25 #include <cmath>
26 #include <vector>
27 
28 template <class T>
30 public:
31 
33 
34  GeneralBinFinderInR(std::vector<T>& borders) :
35  theNbins(borders.size()),
36  theBorders(borders) {
37  // FIXME: compute bin positions.
38 // for (vector<T>::const_iterator i=theBorders.begin();
39 // i<theBorders.end(); ++i) {
40 // theBorders.push_back(((*i) + (*(i+1))) / 2.);
41 
42 // cout << "GeneralBinFinderInR_ " << theNbins << " " << theBorders.size() << " " << (int) this << endl;
43 }
44 
45 
46 // /// Construct from an already initialized RBorderFinder
47 // GeneralBinFinderInR(const RBorderFinder& bf) {
48 // theBorders=bf.RBorders();
49 // theBins=bf.RBins();
50 // theNbins=theBins.size();
51 // }
52 
53 // /// Construct from the list of Det*
54 // GeneralBinFinderInR(vector<Det*>::const_iterator first,
55 // vector<Det*>::const_iterator last)
56 // : theNbins( last-first)
57 // {
58 // vector<Det*> dets(first,last);
59 // RBorderFinder bf(dets);
60 // theBorders=bf.phiBorders();
61 // theBins=bf.phiBins();
62 // theNbins=theBins.size();
63 // }
64 
65 
68  virtual int binIndex( T R) const {
69  int i;
70  for (i = 0; i<theNbins; ++i) {
71  if (R < theBorders[i]){ // FIXME: one can be skipped?
72  break;
73  }
74  }
75  return binIndex(i-1);
76  }
77 
79  virtual int binIndex( int i) const {
80  return std::min( std::max( i, 0), theNbins-1);
81  }
82 
84  virtual T binPosition( int ind) const {
85  return theBins[binIndex(ind)];
86  }
87 
88 
89 private:
90  int theNbins;
91  std::vector<T> theBorders;
92  std::vector<T> theBins;
93 
94 };
95 #endif
96 //----------------------------------------------------------------------
97 
98 
99 
100 //----------------------------------------------------------------------
101 #ifndef GeneralBinFinderInZ_H
102 #define GeneralBinFinderInZ_H
103 
112 #include <cmath>
113 
114 template <class T>
116 public:
117 
119 
120  GeneralBinFinderInZ(std::vector<T>& borders) :
121  theNbins(borders.size()),
122  theBorders(++(borders.begin()),borders.end()) { // Skip border of 1. bin
123  // FIXME: crashes for borders.size()==1 (trivial case)
124  // FIXME set theBins!!!
125  theZOffset = theBorders.front();
126  if (theNbins>2) {
127  theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
128  } else {
129  theZStep = 1.; // Not relevant in this case...
130  }
131 
132 // cout << "GeneralBinFinderInZ " << theBorders.size()
133 // << " " << theZStep << endl;
134  }
135 
136  // FIXME: ??? theNbins e theBorders hanno size theNbins -1.
137  // theBorders[1] e' l'inizio del secondo bin !!!
138 
139 // GeneralBinFinderInZ(vector<Det*>::const_iterator first,
140 // vector<Det*>::const_iterator last) :
141 // theNbins( last-first)
142 // {
143 // theBins.reserve(theNbins);
144 // for (vector<Det*>::const_iterator i=first; i<last-1; ++i) {
145 // theBins.push_back((**i).position().z());
146 // theBorders.push_back(((**i).position().z() +
147 // (**(i+1)).position().z()) / 2.);
148 // }
149 
150 // theZOffset = theBorders.front();
151 // theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
152 // }
153 
155  virtual int binIndex(T z) const {
156  int bin = binIndex(int((z-theZOffset)/theZStep)+1);
157 
158  // check left border
159  if (bin > 0) {
160  if (z < theBorders[bin-1]) {
161  // z is to the left of the left border, the correct bin is left
162  for (int i=bin-1; ; --i) {
163  if (i <= 0) return 0;
164  if ( z > theBorders[i-1]) return i;
165  }
166  }
167  }
168  else return 0;
169 
170  // check right border
171  if (bin < theNbins-1) {
172  if ( z > theBorders[bin]) {
173  // z is to the right of the right border, the correct bin is right
174  for (int i=bin+1; ; ++i) {
175  if (i >= theNbins-1) return theNbins-1;
176  if ( z < theBorders[i]) return i;
177  }
178  }
179  }
180  else return theNbins-1;
181 
182  // if we arrive here it means that the bin is ok
183  return bin;
184  }
185 
187  virtual int binIndex( int i) const {
188  return std::min( std::max( i, 0), theNbins-1);
189  }
190 
192  virtual T binPosition( int ind) const {
193  return theBins[binIndex(ind)];
194  }
195 
196  static double pi() { return 3.141592653589793238;}
197  static double twoPi() { return 2.*pi();}
198 
199 private:
200 
201  int theNbins;
204  std::vector<T> theBorders;
205  std::vector<T> theBins;
206 };
207 #endif
208 //----------------------------------------------------------------------
int i
Definition: DBlmapReader.cc:9
virtual int binIndex(T R) const
Definition: MagBinFinders.h:68
virtual int binIndex(T z) const
returns an index in the valid range for the bin closest to Z
#define min(a, b)
Definition: mlp_lapack.h:161
virtual int binIndex(int i) const
Returns an index in the valid range.
Definition: MagBinFinders.h:79
double double double z
GeneralBinFinderInR(std::vector< T > &borders)
Definition: MagBinFinders.h:34
const T & max(const T &a, const T &b)
#define end
Definition: vmac.h:38
#define begin
Definition: vmac.h:31
virtual int binIndex(int i) const
returns an index in the valid range
GeneralBinFinderInZ(std::vector< T > &borders)
long double T
virtual T binPosition(int ind) const
The middle of the bin.
Definition: MagBinFinders.h:84
tuple size
Write out results.
virtual T binPosition(int ind) const
the middle of the bin.