CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PhiBorderFinder.cc
Go to the documentation of this file.
2 
3 PhiBorderFinder::PhiBorderFinder(const std::vector<const Det*>& utheDets)
4  : theNbins(utheDets.size()), isPhiPeriodic_(false), isPhiOverlapping_(false) {
5  std::vector<const Det*> theDets = utheDets;
6  precomputed_value_sort(theDets.begin(), theDets.end(), DetPhi());
7 
8  const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|PhiBorderFinder";
9 
10  double step = 2. * Geom::pi() / theNbins;
11 
12  LogTrace(metname) << "RecoMuonDetLayers::PhiBorderFinder "
13  << "step w: " << step << " # of bins: " << theNbins;
14 
15  std::vector<double> spread(theNbins);
16  std::vector<std::pair<double, double> > phiEdge;
17  phiEdge.reserve(theNbins);
18  thePhiBorders.reserve(theNbins);
19  thePhiBins.reserve(theNbins);
20  for (unsigned int i = 0; i < theNbins; i++) {
21  thePhiBins.push_back(theDets[i]->position().phi());
22  spread.push_back(theDets[i]->position().phi() - (theDets[0]->position().phi() + i * step));
23 
24  LogTrace(metname) << "bin: " << i << " phi bin: " << thePhiBins[i] << " spread: " << spread[i];
25 
26  ConstReferenceCountingPointer<BoundPlane> plane = dynamic_cast<const BoundPlane*>(&theDets[i]->surface());
27  if (plane == nullptr) {
28  //FIXME
29  throw cms::Exception("UnexpectedState") << ("PhiBorderFinder: det surface is not a BoundPlane");
30  }
31 
32  std::vector<GlobalPoint> dc = BoundingBox().corners(*plane);
33 
34  float phimin(999.), phimax(-999.);
35  for (std::vector<GlobalPoint>::const_iterator pt = dc.begin(); pt != dc.end(); pt++) {
36  float phi = (*pt).phi();
37  // float z = pt->z();
38  if (phi < phimin)
39  phimin = phi;
40  if (phi > phimax)
41  phimax = phi;
42  }
43  if (phimin * phimax < 0. && //Handle pi border:
44  phimax - phimin > Geom::pi()) { //Assume that the Det is on
45  //the shortest side
46  std::swap(phimin, phimax);
47  }
48  phiEdge.push_back(std::pair<double, double>(phimin, phimax));
49  }
50 
51  for (unsigned int i = 0; i < theNbins; i++) {
52  // Put the two phi values in the [0,2pi] range
53  double firstPhi = positiveRange(phiEdge[i].first);
54  double secondPhi = positiveRange(phiEdge[binIndex(i - 1)].second);
55 
56  // Reformat them in the [-pi,pi] range
57  Geom::Phi<double> firstEdge(firstPhi);
58  Geom::Phi<double> secondEdge(secondPhi);
59 
60  // Calculate the mean and format the result in the [-pi,pi] range
61  // Get their value in order to perform the mean in the correct way
62  Geom::Phi<double> mean((firstEdge.value() + secondEdge.value()) / 2.);
63 
64  // Special case: at +-pi there is a discontinuity
65  if (phiEdge[i].first * phiEdge[binIndex(i - 1)].second < 0 && fabs(firstPhi - secondPhi) < Geom::pi())
66  mean = Geom::pi() - mean;
67 
68  thePhiBorders.push_back(mean);
69  }
70 
71  for (unsigned int i = 0; i < theNbins; i++) {
72  if (Geom::Phi<double>(phiEdge[i].first) - Geom::Phi<double>(phiEdge[binIndex(i - 1)].second) < 0) {
73  isPhiOverlapping_ = true;
74  break;
75  }
76  }
77 
78  double rms = stat_RMS(spread);
79  if (rms < 0.01 * step) {
80  isPhiPeriodic_ = true;
81  }
82 
83  //Check that everything is proper
84  if (thePhiBorders.size() != theNbins || thePhiBins.size() != theNbins)
85  //FIXME
86  throw cms::Exception("UnexpectedState") << "PhiBorderFinder: consistency error";
87 }
const std::string metname
T1 value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:75
#define LogTrace(id)
U second(std::pair< T, U > const &p)
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:23
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
geomsort::ExtractPhi< Det, float > DetPhi
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
static int position[264][3]
Definition: ReadPGInfo.cc:289
double positiveRange(double phi) const
std::vector< double > thePhiBins
step
Definition: StallMonitor.cc:98
constexpr double pi()
Definition: Pi.h:31
Definition: Phi.h:52
int binIndex(int i) const
tuple size
Write out results.
unsigned int theNbins