CMS 3D CMS Logo

PhiBorderFinder.h
Go to the documentation of this file.
1 #ifndef PhiBorderFinder_H
2 #define PhiBorderFinder_H
3 
13 
16 
22 
23 // FIXME: remove this include
25 
26 #include <vector>
27 
29 public:
30 
31  typedef DetRod Det; //FIXME!!!
33 
34 
35  PhiBorderFinder(const std::vector<const Det*>& utheDets)
37  std::vector<const Det*> theDets = utheDets;
38  precomputed_value_sort(theDets.begin(), theDets.end(), DetPhi());
39 
40  const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|PhiBorderFinder";
41 
42  double step = 2.*Geom::pi()/theNbins;
43 
44  LogTrace(metname) << "RecoMuonDetLayers::PhiBorderFinder "
45  << "step w: " << step << " # of bins: " << theNbins;
46 
47  std::vector<double> spread(theNbins);
48  std::vector<std::pair<double,double> > phiEdge;
49  phiEdge.reserve(theNbins);
50  thePhiBorders.reserve(theNbins);
51  thePhiBins.reserve(theNbins);
52  for ( unsigned int i = 0; i < theNbins; i++ ) {
53  thePhiBins.push_back(theDets[i]->position().phi());
54  spread.push_back(theDets[i]->position().phi()
55  - (theDets[0]->position().phi() + i*step));
56 
57  LogTrace(metname) << "bin: " << i << " phi bin: " << thePhiBins[i]
58  << " spread: " << spread[i];
59 
60 
62  dynamic_cast<const BoundPlane*>(&theDets[i]->surface());
63  if (plane==nullptr) {
64  //FIXME
65  throw cms::Exception("UnexpectedState") << ("PhiBorderFinder: det surface is not a BoundPlane");
66  }
67 
68  std::vector<GlobalPoint> dc =
69  BoundingBox().corners(*plane);
70 
71  float phimin(999.), phimax(-999.);
72  for (std::vector<GlobalPoint>::const_iterator pt=dc.begin();
73  pt!=dc.end(); pt++) {
74  float phi = (*pt).phi();
75 // float z = pt->z();
76  if (phi < phimin) phimin = phi;
77  if (phi > phimax) phimax = phi;
78  }
79  if (phimin*phimax < 0. && //Handle pi border:
80  phimax - phimin > Geom::pi()) { //Assume that the Det is on
81  //the shortest side
82  std::swap(phimin,phimax);
83  }
84  phiEdge.push_back(std::pair<double,double>(phimin,phimax));
85  }
86 
87  for (unsigned int i = 0; i < theNbins; i++) {
88 
89  // Put the two phi values in the [0,2pi] range
90  double firstPhi = positiveRange(phiEdge[i].first);
91  double secondPhi = positiveRange(phiEdge[binIndex(i-1)].second);
92 
93  // Reformat them in the [-pi,pi] range
94  Geom::Phi<double> firstEdge(firstPhi);
95  Geom::Phi<double> secondEdge(secondPhi);
96 
97  // Calculate the mean and format the result in the [-pi,pi] range
98  // Get their value in order to perform the mean in the correct way
99  Geom::Phi<double> mean((firstEdge.value() + secondEdge.value())/2.);
100 
101  // Special case: at +-pi there is a discontinuity
102  if ( phiEdge[i].first * phiEdge[binIndex(i-1)].second < 0 &&
103  fabs(firstPhi-secondPhi) < Geom::pi() )
104  mean = Geom::pi() - mean;
105 
106  thePhiBorders.push_back(mean);
107  }
108 
109  for (unsigned int i = 0; i < theNbins; i++) {
110  if (Geom::Phi<double>(phiEdge[i].first)
111  - Geom::Phi<double>(phiEdge[binIndex(i-1)].second) < 0) {
112  isPhiOverlapping_ = true;
113  break;
114  }
115  }
116 
117  double rms = stat_RMS(spread);
118  if ( rms < 0.01*step) {
119  isPhiPeriodic_ = true;
120  }
121 
122  //Check that everything is proper
123  if (thePhiBorders.size() != theNbins || thePhiBins.size() != theNbins)
124  //FIXME
125  throw cms::Exception("UnexpectedState") << "PhiBorderFinder: consistency error";
126  }
127 
128 
129  virtual ~PhiBorderFinder(){};
130 
131  inline unsigned int nBins() {return theNbins;}
132 
134  inline bool isPhiPeriodic() const { return isPhiPeriodic_; }
135 
137  inline bool isPhiOverlapping() const { return isPhiOverlapping_; }
138 
141  inline const std::vector<double>& phiBorders() const { return thePhiBorders; }
142 
144  inline const std::vector<double>& phiBins() const { return thePhiBins; }
145 
146  // inline std::vector<double> etaBorders() {}
147  // inline std::vector<double> zBorders() {}
148 
149 private:
150  unsigned int theNbins;
153  std::vector<double> thePhiBorders;
154  std::vector<double> thePhiBins;
155 
156  inline double positiveRange (double phi) const
157  {
158  return (phi > 0) ? phi : phi + Geom::twoPi();
159  }
160 
161  int binIndex( int i) const {
162  int ind = i % (int)theNbins;
163  return (ind < 0) ? ind+theNbins : ind;
164  }
165 
166 
167 };
168 #endif
169 
size
Write out results.
const std::string metname
geomsort::ExtractPhi< Det, float > DetPhi
virtual ~PhiBorderFinder()
U second(std::pair< T, U > const &p)
const std::vector< double > & phiBorders() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::vector< double > thePhiBorders
PhiBorderFinder(const std::vector< const Det * > &utheDets)
double stat_RMS(const CONT &cont)
Definition: simple_stat.h:24
#define LogTrace(id)
T value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:38
bool isPhiPeriodic() const
Returns true if the Dets are periodic in phi.
Definition: DetRod.h:13
unsigned int nBins()
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:24
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
static int position[264][3]
Definition: ReadPGInfo.cc:509
double positiveRange(double phi) const
std::vector< double > thePhiBins
step
bool isPhiOverlapping() const
Returns true if any 2 of the Det overlap in phi.
constexpr double pi()
Definition: Pi.h:31
constexpr double twoPi()
Definition: Pi.h:32
int binIndex(int i) const
const std::vector< double > & phiBins() const
The centers of the Dets.
unsigned int theNbins