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 28 of file PhiBorderFinder.h.

Member Typedef Documentation

Definition at line 31 of file PhiBorderFinder.h.

Definition at line 32 of file PhiBorderFinder.h.

Constructor & Destructor Documentation

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

Definition at line 3 of file PhiBorderFinder.cc.

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

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

Definition at line 37 of file PhiBorderFinder.h.

37 {};

Member Function Documentation

int PhiBorderFinder::binIndex ( int  i) const
inlineprivate

Definition at line 69 of file PhiBorderFinder.h.

References createfilelist::int.

Referenced by PhiBorderFinder().

69  {
70  int ind = i % (int)theNbins;
71  return (ind < 0) ? ind+theNbins : ind;
72  }
unsigned int theNbins
bool PhiBorderFinder::isPhiOverlapping ( ) const
inline

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

Definition at line 45 of file PhiBorderFinder.h.

References isPhiOverlapping_.

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

45 { return isPhiOverlapping_; }
bool PhiBorderFinder::isPhiPeriodic ( ) const
inline

Returns true if the Dets are periodic in phi.

Definition at line 42 of file PhiBorderFinder.h.

References isPhiPeriodic_.

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

42 { return isPhiPeriodic_; }
unsigned int PhiBorderFinder::nBins ( )
inline

Definition at line 39 of file PhiBorderFinder.h.

References theNbins.

39 {return theNbins;}
unsigned int theNbins
const std::vector<double>& PhiBorderFinder::phiBins ( ) const
inline

The centers of the Dets.

Definition at line 52 of file PhiBorderFinder.h.

References thePhiBins.

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

52 { return thePhiBins; }
std::vector< double > thePhiBins
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 49 of file PhiBorderFinder.h.

References thePhiBorders.

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

49 { return thePhiBorders; }
std::vector< double > thePhiBorders
double PhiBorderFinder::positiveRange ( double  phi) const
inlineprivate

Definition at line 64 of file PhiBorderFinder.h.

References Geom::twoPi().

Referenced by PhiBorderFinder().

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

Member Data Documentation

bool PhiBorderFinder::isPhiOverlapping_
private

Definition at line 60 of file PhiBorderFinder.h.

Referenced by isPhiOverlapping(), and PhiBorderFinder().

bool PhiBorderFinder::isPhiPeriodic_
private

Definition at line 59 of file PhiBorderFinder.h.

Referenced by isPhiPeriodic(), and PhiBorderFinder().

unsigned int PhiBorderFinder::theNbins
private

Definition at line 58 of file PhiBorderFinder.h.

Referenced by nBins(), and PhiBorderFinder().

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

Definition at line 62 of file PhiBorderFinder.h.

Referenced by phiBins(), and PhiBorderFinder().

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

Definition at line 61 of file PhiBorderFinder.h.

Referenced by PhiBorderFinder(), and phiBorders().