CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 (std::vector< const Det * > theDets)
 
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.

Date:
2007/03/07 13:20:54
Revision:
1.10
Author
N. Amapane - INFN Torino

Definition at line 29 of file PhiBorderFinder.h.

Member Typedef Documentation

Definition at line 32 of file PhiBorderFinder.h.

Definition at line 33 of file PhiBorderFinder.h.

Constructor & Destructor Documentation

PhiBorderFinder::PhiBorderFinder ( std::vector< const Det * >  theDets)
inline

Definition at line 36 of file PhiBorderFinder.h.

References binIndex(), BoundingBox::corners(), edm::hlt::Exception, first, i, isPhiOverlapping_, isPhiPeriodic_, LogTrace, timingPdfMaker::mean, metname, phi, phimax, phimin, Geom::pi(), position, positiveRange(), precomputed_value_sort(), plotscripts::rms(), edm::second(), stat_RMS(), launcher::step, std::swap(), theNbins, thePhiBins, thePhiBorders, and Geom::Phi< T >::value().

37  : theNbins(theDets.size()), isPhiPeriodic_(false), isPhiOverlapping_(false) {
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==0) {
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
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  }
int i
Definition: DBlmapReader.cc:9
list step
Definition: launcher.py:15
const std::string metname
geomsort::ExtractPhi< Det, float > DetPhi
static std::vector< GlobalPoint > corners(const BoundPlane &)
Definition: BoundingBox.cc:24
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:20
bool first
Definition: L1TdeRCT.cc:94
#define LogTrace(id)
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
double pi()
Definition: Pi.h:31
static int position[264][3]
Definition: ReadPGInfo.cc:509
double positiveRange(double phi) const
std::vector< double > thePhiBins
Definition: Phi.h:20
int binIndex(int i) const
unsigned int theNbins
Definition: DDAxes.h:10
virtual PhiBorderFinder::~PhiBorderFinder ( )
inlinevirtual

Definition at line 129 of file PhiBorderFinder.h.

129 {};

Member Function Documentation

int PhiBorderFinder::binIndex ( int  i) const
inlineprivate

Definition at line 161 of file PhiBorderFinder.h.

References theNbins.

Referenced by PhiBorderFinder().

161  {
162  int ind = i % (int)theNbins;
163  return (ind < 0) ? ind+theNbins : ind;
164  }
int i
Definition: DBlmapReader.cc:9
unsigned int theNbins
bool PhiBorderFinder::isPhiOverlapping ( ) const
inline

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

Definition at line 137 of file PhiBorderFinder.h.

References isPhiOverlapping_.

Referenced by MuRodBarrelLayer::MuRodBarrelLayer().

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

Returns true if the Dets are periodic in phi.

Definition at line 134 of file PhiBorderFinder.h.

References isPhiPeriodic_.

Referenced by MuRodBarrelLayer::MuRodBarrelLayer().

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

Definition at line 131 of file PhiBorderFinder.h.

References theNbins.

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

The centers of the Dets.

Definition at line 144 of file PhiBorderFinder.h.

References thePhiBins.

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

144 { 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 141 of file PhiBorderFinder.h.

References thePhiBorders.

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

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

Definition at line 156 of file PhiBorderFinder.h.

References Geom::twoPi().

Referenced by PhiBorderFinder().

157  {
158  return (phi > 0) ? phi : phi + Geom::twoPi();
159  }
double twoPi()
Definition: Pi.h:32
Definition: DDAxes.h:10

Member Data Documentation

bool PhiBorderFinder::isPhiOverlapping_
private

Definition at line 152 of file PhiBorderFinder.h.

Referenced by isPhiOverlapping(), and PhiBorderFinder().

bool PhiBorderFinder::isPhiPeriodic_
private

Definition at line 151 of file PhiBorderFinder.h.

Referenced by isPhiPeriodic(), and PhiBorderFinder().

unsigned int PhiBorderFinder::theNbins
private

Definition at line 150 of file PhiBorderFinder.h.

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

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

Definition at line 154 of file PhiBorderFinder.h.

Referenced by phiBins(), and PhiBorderFinder().

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

Definition at line 153 of file PhiBorderFinder.h.

Referenced by PhiBorderFinder(), and phiBorders().