CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RBorderFinder.h
Go to the documentation of this file.
1 #ifndef RBorderFinder_H
2 #define RBorderFinder_H
3 
15 
20 
21 #include <vector>
22 //#include <iostream>
23 
25 public:
26 
27  typedef ForwardDetRing Det; //FIXME!!!
29 
30  RBorderFinder(std::vector<const Det*> theDets)
32  {
33  precomputed_value_sort(theDets.begin(), theDets.end(), DetR());
34 
35  std::vector<ConstReferenceCountingPointer<BoundDisk> > disks(theNbins);
36  for ( int i = 0; i < theNbins; i++ ) {
37  disks[i] =
38  dynamic_cast<const BoundDisk*> (&(theDets[i]->surface()));
39  if (disks[i]==0) {
40  throw cms::Exception("UnexpectedState") << "RBorderFinder: implemented for BoundDisks only";
41  }
42  }
43 
44 
45  if (theNbins==1) { // Trivial case
46  isRPeriodic_ = true; // meaningless in this case
47  theRBorders.push_back(disks.front()->innerRadius());
48  theRBins.push_back((disks.front()->outerRadius()+disks.front()->innerRadius()));
49 // std::cout << "RBorderFinder: theNbins " << theNbins << std::endl
50 // << " C: " << theRBins[0]
51 // << " Border: " << theRBorders[0] << std::endl;
52  } else { // More than 1 bin
53  double step = (disks.back()->innerRadius() -
54  disks.front()->innerRadius())/(theNbins-1);
55  std::vector<double> spread;
56  std::vector<std::pair<double,double> > REdge;
57  REdge.reserve(theNbins);
58  theRBorders.reserve(theNbins);
59  theRBins.reserve(theNbins);
60  spread.reserve(theNbins);
61 
62  for ( int i = 0; i < theNbins; i++ ) {
63  theRBins.push_back((disks[i]->outerRadius()+disks[i]->innerRadius())/2.);
64  spread.push_back(theRBins.back() - (theRBins[0] + i*step));
65  REdge.push_back(std::pair<double,double>(disks[i]->innerRadius(),
66  disks[i]->outerRadius()));
67  }
68 
69  theRBorders.push_back(REdge[0].first);
70  for (int i = 1; i < theNbins; i++) {
71  // Average borders of previous and next bins
72  double br = (REdge[(i-1)].second + REdge[i].first)/2.;
73  theRBorders.push_back(br);
74  }
75 
76  for (int i = 1; i < theNbins; i++) {
77  if (REdge[i].first - REdge[i-1].second < 0) {
78  isROverlapping_ = true;
79  break;
80  }
81  }
82 
83  double rms = stat_RMS(spread);
84  if ( rms < 0.01*step) {
85  isRPeriodic_ = true;
86  }
87 
88 // std::cout << "RBorderFinder: theNbins " << theNbins
89 // << " step: " << step << " RMS " << rms << std::endl;
90 // for (int idbg = 0; idbg < theNbins; idbg++) {
91 // std::cout << "L: " << REdge[idbg].first
92 // << " C: " << theRBins[idbg]
93 // << " R: " << REdge[idbg].second
94 // << " Border: " << theRBorders[idbg]
95 // << " SP: " << spread[idbg] << std::endl;
96 // }
97  }
98 
99  //Check that everything is proper
100  if ((int)theRBorders.size() != theNbins || (int)theRBins.size() != theNbins)
101  throw cms::Exception("UnexpectedState") << "RBorderFinder consistency error";
102 }
103 
104  // Construct from a std::vector of Det*.
105  // Not tested, and do not work if the Dets are rings since
106  // position().perp() gives 0...
107 // RBorderFinder(std::vector<Det*> theDets)
108 // : theNbins(theDets.size()), isRPeriodic_(false), isROverlapping_(false)
109 // {
110 // sort(theDets.begin(), theDets.end(), DetLessR());
111 
112 // double step = (theDets.back()->position().perp() -
113 // theDets.front()->position().perp())/(theNbins-1);
114 // std::vector<double> spread(theNbins);
115 // std::vector<std::pair<double,double> > REdge;
116 // REdge.reserve(theNbins);
117 // theRBorders.reserve(theNbins);
118 // theRBins.reserve(theNbins);
119 // for ( int i = 0; i < theNbins; i++ ) {
120 // theRBins.push_back(theDets[i]->position().perp());
121 // spread.push_back(theDets[i]->position().perp()
122 // - (theDets[0]->position().perp() + i*step));
123 
124 // const BoundPlane * plane =
125 // dynamic_cast<const BoundPlane*>(&theDets[i]->surface());
126 // if (plane==0) {
127 // throw DetLogicError("RBorderFinder: det surface is not a BoundPlane");
128 // }
129 
130 // std::vector<GlobalPoint> dc =
131 // BoundingBox().corners(*plane);
132 
133 // float rmin(dc.front().perp());
134 // float rmax(rmin);
135 // for (std::vector<GlobalPoint>::const_iterator pt=dc.begin();
136 // pt!=dc.end(); pt++) {
137 // float r = (*pt).perp();
138 // // float z = pt->z();
139 // rmin = min( rmin, r);
140 // rmax = max( rmax, r);
141 // }
142 
143 // // in addition to the corners we have to check the middle of the
144 // // det +/- length/2 since the min (max) radius for typical fw dets
145 // // is reached there
146 // float rdet = theDets[i]->position().perp();
147 // float len = theDets[i]->surface().bounds().length();
148 // rmin = min( rmin, rdet-len/2.F);
149 // // theRmax = max( theRmax, rdet+len/2.F);
150 
151 // REdge.push_back(make_std::pair(rmin,rmax));
152 // }
153 // // ...
154 // }
155 
156 
157  virtual ~RBorderFinder(){};
158 
160  inline bool isRPeriodic() const { return isRPeriodic_; }
161 
163  inline bool isROverlapping() const { return isROverlapping_; }
164 
167  inline std::vector<double> RBorders() const { return theRBorders; }
168 
170  inline std::vector<double> RBins() const { return theRBins; }
171 
172  // inline std::vector<double> etaBorders() {}
173  // inline std::vector<double> zBorders() {}
174 
175 
176 private:
177  int theNbins;
180  std::vector<double> theRBorders;
181  std::vector<double> theRBins;
182 
183  inline int binIndex( int i) const {
184  return std::min( std::max( i, 0), theNbins-1);
185  }
186 };
187 #endif
188 
int i
Definition: DBlmapReader.cc:9
list step
Definition: launcher.py:15
tuple disks
Definition: alignBH_cfg.py:13
geomsort::ExtractR< Det, float > DetR
Definition: RBorderFinder.h:28
#define min(a, b)
Definition: mlp_lapack.h:161
U second(std::pair< T, U > const &p)
int binIndex(int i) const
const T & max(const T &a, const T &b)
std::vector< double > RBins() const
The centers of the Dets.
tuple br
Definition: scaleCards.py:54
double stat_RMS(const CONT &cont)
Definition: simple_stat.h:20
bool first
Definition: L1TdeRCT.cc:94
virtual ~RBorderFinder()
std::vector< double > RBorders() const
ForwardDetRing Det
Definition: RBorderFinder.h:27
std::vector< double > theRBorders
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
bool isRPeriodic() const
Returns true if the Dets are periodic in R.
tuple size
Write out results.
bool isROverlapping() const
Returns true if any 2 of the Det overlap in R.
RBorderFinder(std::vector< const Det * > theDets)
Definition: RBorderFinder.h:30
std::vector< double > theRBins