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