CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
PhiBorderFinder Class Reference

#include <PhiBorderFinder.h>

Public Types

typedef DetRod Det
 
typedef geomsort::ExtractPhi< Det, float > DetPhi
 

Public Member Functions

bool isPhiOverlapping () const
 Returns true if any 2 of the Det overlap in phi. More...
 
bool isPhiPeriodic () const
 Returns true if the Dets are periodic in phi. More...
 
unsigned int nBins ()
 
const std::vector< double > & phiBins () const
 The centers of the Dets. More...
 
 PhiBorderFinder (const std::vector< const Det *> &utheDets)
 
const std::vector< double > & phiBorders () const
 
virtual ~PhiBorderFinder ()
 

Private Member Functions

int binIndex (int i) const
 
double positiveRange (double phi) const
 

Private Attributes

bool isPhiOverlapping_
 
bool isPhiPeriodic_
 
unsigned int theNbins
 
std::vector< double > thePhiBins
 
std::vector< double > thePhiBorders
 

Detailed Description

Find the phi binning of a list of detector according to several definitions.

Author
N. Amapane - INFN Torino

Definition at line 27 of file PhiBorderFinder.h.

Member Typedef Documentation

◆ Det

Definition at line 29 of file PhiBorderFinder.h.

◆ DetPhi

Definition at line 30 of file PhiBorderFinder.h.

Constructor & Destructor Documentation

◆ PhiBorderFinder()

PhiBorderFinder::PhiBorderFinder ( const std::vector< const Det *> &  utheDets)

Definition at line 3 of file PhiBorderFinder.cc.

References binIndex(), BoundingBox::corners(), Exception, dqmdumpme::first, mps_fire::i, isPhiOverlapping_, isPhiPeriodic_, LogTrace, SiStripPI::mean, metname, phi, phimax, phimin, Geom::pi(), position, positiveRange(), precomputed_value_sort(), DiDispStaMuonMonitor_cfi::pt, SiStripPI::rms, edm::second(), stat_RMS(), AlCaHLTBitMon_QueryRunRegistry::string, edm::swap(), theNbins, thePhiBins, thePhiBorders, and Geom::Phi< T1, Range >::value().

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 }
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
Definition: Phi.h:52
unsigned int theNbins

◆ ~PhiBorderFinder()

virtual PhiBorderFinder::~PhiBorderFinder ( )
inlinevirtual

Definition at line 34 of file PhiBorderFinder.h.

34 {}

Member Function Documentation

◆ binIndex()

int PhiBorderFinder::binIndex ( int  i) const
inlineprivate

Definition at line 63 of file PhiBorderFinder.h.

References mps_fire::i, createfilelist::int, and theNbins.

Referenced by PhiBorderFinder().

63  {
64  int ind = i % (int)theNbins;
65  return (ind < 0) ? ind + theNbins : ind;
66  }
unsigned int theNbins

◆ isPhiOverlapping()

bool PhiBorderFinder::isPhiOverlapping ( ) const
inline

Returns true if any 2 of the Det overlap in phi.

Definition at line 42 of file PhiBorderFinder.h.

References isPhiOverlapping_.

Referenced by MTDTrayBarrelLayer::MTDTrayBarrelLayer(), and MuRodBarrelLayer::MuRodBarrelLayer().

42 { return isPhiOverlapping_; }

◆ isPhiPeriodic()

bool PhiBorderFinder::isPhiPeriodic ( ) const
inline

Returns true if the Dets are periodic in phi.

Definition at line 39 of file PhiBorderFinder.h.

References isPhiPeriodic_.

Referenced by MTDTrayBarrelLayer::MTDTrayBarrelLayer(), and MuRodBarrelLayer::MuRodBarrelLayer().

39 { return isPhiPeriodic_; }

◆ nBins()

unsigned int PhiBorderFinder::nBins ( )
inline

Definition at line 36 of file PhiBorderFinder.h.

References theNbins.

36 { return theNbins; }
unsigned int theNbins

◆ phiBins()

const std::vector<double>& PhiBorderFinder::phiBins ( ) const
inline

The centers of the Dets.

Definition at line 49 of file PhiBorderFinder.h.

References thePhiBins.

Referenced by GeneralBinFinderInPhi< T >::GeneralBinFinderInPhi().

49 { return thePhiBins; }
std::vector< double > thePhiBins

◆ phiBorders()

const std::vector<double>& PhiBorderFinder::phiBorders ( ) const
inline

The borders, defined for each det as the middle between its lower edge and the previous Det's upper edge.

Definition at line 46 of file PhiBorderFinder.h.

References thePhiBorders.

Referenced by GeneralBinFinderInPhi< T >::GeneralBinFinderInPhi().

46 { return thePhiBorders; }
std::vector< double > thePhiBorders

◆ positiveRange()

double PhiBorderFinder::positiveRange ( double  phi) const
inlineprivate

Definition at line 61 of file PhiBorderFinder.h.

References phi, and Geom::twoPi().

Referenced by PhiBorderFinder().

61 { return (phi > 0) ? phi : phi + Geom::twoPi(); }
constexpr double twoPi()
Definition: Pi.h:32

Member Data Documentation

◆ isPhiOverlapping_

bool PhiBorderFinder::isPhiOverlapping_
private

Definition at line 57 of file PhiBorderFinder.h.

Referenced by isPhiOverlapping(), and PhiBorderFinder().

◆ isPhiPeriodic_

bool PhiBorderFinder::isPhiPeriodic_
private

Definition at line 56 of file PhiBorderFinder.h.

Referenced by isPhiPeriodic(), and PhiBorderFinder().

◆ theNbins

unsigned int PhiBorderFinder::theNbins
private

Definition at line 55 of file PhiBorderFinder.h.

Referenced by binIndex(), nBins(), and PhiBorderFinder().

◆ thePhiBins

std::vector<double> PhiBorderFinder::thePhiBins
private

Definition at line 59 of file PhiBorderFinder.h.

Referenced by phiBins(), and PhiBorderFinder().

◆ thePhiBorders

std::vector<double> PhiBorderFinder::thePhiBorders
private

Definition at line 58 of file PhiBorderFinder.h.

Referenced by PhiBorderFinder(), and phiBorders().