CMS 3D CMS Logo

PhiBorderFinder Class Reference

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

#include <RecoMuon/DetLayers/src/PhiBorderFinder.h>

List of all members.

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.
bool isPhiPeriodic () const
 Returns true if the Dets are periodic in phi.
unsigned int nBins ()
const std::vector< double > & phiBins () const
 The centers of the Dets.
 PhiBorderFinder (std::vector< const Det * > theDets)
const std::vector< double > & phiBorders () const
 The borders, defined for each det as the middle between its lower edge and the previous Det's upper edge.
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

typedef DetRod PhiBorderFinder::Det

Definition at line 32 of file PhiBorderFinder.h.

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

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(), dc, Exception, first, i, isPhiOverlapping_, isPhiPeriodic_, LogTrace, mean(), phi, Geom::pi(), positiveRange(), precomputed_value_sort(), edm::second(), stat_RMS(), cmsRelvalreportInput::step, std::swap(), theNbins, thePhiBins, thePhiBorders, and Geom::Phi< T >::value().

00037     : theNbins(theDets.size()), isPhiPeriodic_(false), isPhiOverlapping_(false) {
00038     precomputed_value_sort(theDets.begin(), theDets.end(), DetPhi());
00039 
00040     const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|PhiBorderFinder";
00041 
00042     double step = 2.*Geom::pi()/theNbins;
00043 
00044     LogTrace(metname) << "RecoMuonDetLayers::PhiBorderFinder "
00045                       << "step w: " << step << " # of bins: " << theNbins;
00046     
00047     std::vector<double> spread(theNbins);
00048     std::vector<std::pair<double,double> > phiEdge;
00049     phiEdge.reserve(theNbins);
00050     thePhiBorders.reserve(theNbins);
00051     thePhiBins.reserve(theNbins);
00052     for ( unsigned int i = 0; i < theNbins; i++ ) {
00053       thePhiBins.push_back(theDets[i]->position().phi());
00054       spread.push_back(theDets[i]->position().phi()
00055         - (theDets[0]->position().phi() + i*step));
00056       
00057       LogTrace(metname) << "bin: " << i << " phi bin: " << thePhiBins[i]
00058                         << " spread: " <<  spread[i];
00059       
00060 
00061       ConstReferenceCountingPointer<BoundPlane> plane = 
00062         dynamic_cast<const BoundPlane*>(&theDets[i]->surface());
00063       if (plane==0) {
00064         //FIXME
00065         throw cms::Exception("UnexpectedState") << ("PhiBorderFinder: det surface is not a BoundPlane");
00066       }
00067       
00068       std::vector<GlobalPoint> dc = 
00069         BoundingBox().corners(*plane);
00070 
00071       float phimin(999.), phimax(-999.);
00072       for (std::vector<GlobalPoint>::const_iterator pt=dc.begin();
00073            pt!=dc.end(); pt++) {
00074         float phi = (*pt).phi();
00075 //      float z = pt->z();
00076         if (phi < phimin) phimin = phi;
00077         if (phi > phimax) phimax = phi;
00078       }
00079       if (phimin*phimax < 0. &&           //Handle pi border:
00080           phimax - phimin > Geom::pi()) { //Assume that the Det is on
00081                                           //the shortest side 
00082         std::swap(phimin,phimax);
00083       }
00084       phiEdge.push_back(std::pair<double,double>(phimin,phimax));
00085     }
00086     
00087     for (unsigned int i = 0; i < theNbins; i++) {
00088       
00089       // Put the two phi values in the [0,2pi] range
00090       double firstPhi  = positiveRange(phiEdge[i].first);
00091       double secondPhi = positiveRange(phiEdge[binIndex(i-1)].second);
00092 
00093       // Reformat them in the [-pi,pi] range
00094       Geom::Phi<double> firstEdge(firstPhi);
00095       Geom::Phi<double> secondEdge(secondPhi);
00096 
00097       // Calculate the mean and format the result in the [-pi,pi] range
00098       // Get their value in order to perform the mean in the correct way
00099       Geom::Phi<double> mean((firstEdge.value() + secondEdge.value())/2.);
00100       
00101       // Special case: at +-pi there is a discontinuity
00102       if ( phiEdge[i].first * phiEdge[binIndex(i-1)].second < 0 &&
00103            fabs(firstPhi-secondPhi) < Geom::pi() ) 
00104         mean = Geom::pi() - mean;
00105      
00106       thePhiBorders.push_back(mean);
00107     }
00108   
00109     for (unsigned int i = 0; i < theNbins; i++) {
00110       if (Geom::Phi<double>(phiEdge[i].first)
00111           - Geom::Phi<double>(phiEdge[binIndex(i-1)].second) < 0) {
00112         isPhiOverlapping_ = true;
00113         break;
00114       }
00115     }
00116 
00117     double rms = stat_RMS(spread); 
00118     if ( rms < 0.01*step) { 
00119       isPhiPeriodic_ = true;
00120     }
00121 
00122     //Check that everything is proper
00123     if (thePhiBorders.size() != theNbins || thePhiBins.size() != theNbins) 
00124       //FIXME
00125       throw cms::Exception("UnexpectedState") << "PhiBorderFinder: consistency error";
00126   }

virtual PhiBorderFinder::~PhiBorderFinder (  )  [inline, virtual]

Definition at line 129 of file PhiBorderFinder.h.

00129 {};


Member Function Documentation

int PhiBorderFinder::binIndex ( int  i  )  const [inline, private]

Definition at line 161 of file PhiBorderFinder.h.

References int, and theNbins.

Referenced by PhiBorderFinder().

00161                              {
00162     int ind = i % (int)theNbins;
00163     return (ind < 0) ? ind+theNbins : ind;
00164   }

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_.

00137 { 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_.

00134 { return isPhiPeriodic_; }

unsigned int PhiBorderFinder::nBins (  )  [inline]

Definition at line 131 of file PhiBorderFinder.h.

References theNbins.

00131 {return 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().

00144 { return 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().

00141 { return thePhiBorders; }

double PhiBorderFinder::positiveRange ( double  phi  )  const [inline, private]

Definition at line 156 of file PhiBorderFinder.h.

References Geom::twoPi().

Referenced by PhiBorderFinder().

00157   {
00158     return (phi > 0) ? phi : phi + Geom::twoPi();
00159   }


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().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:29:53 2009 for CMSSW by  doxygen 1.5.4