CMS 3D CMS Logo

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
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 }
size
Write out results.
const std::string metname
double positiveRange(double phi) const
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
#define LogTrace(id)
U second(std::pair< T, U > const &p)
std::vector< double > thePhiBorders
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
int binIndex(int i) const
static std::vector< GlobalPoint > corners(const Plane &)
Definition: BoundingBox.cc:20
static int position[264][3]
Definition: ReadPGInfo.cc:289
std::vector< double > thePhiBins
step
Definition: StallMonitor.cc:83
constexpr double pi()
Definition: Pi.h:31
T1 value() const
Explicit access to value in case implicit conversion not OK.
Definition: Phi.h:75
Definition: Phi.h:52
PhiBorderFinder(const std::vector< const Det *> &utheDets)
unsigned int theNbins