CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

PhiBorderFinder Class Reference

#include <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
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(), Exception, first, i, isPhiOverlapping_, isPhiPeriodic_, LogTrace, timingPdfMaker::mean, metname, phi, phimax, phimin, Geom::pi(), pi, position, positiveRange(), precomputed_value_sort(), plotscripts::rms(), edm::second(), stat_RMS(), launcher::step, swap(), theNbins, thePhiBins, thePhiBorders, and Geom::Phi< T >::value().

    : theNbins(theDets.size()), isPhiPeriodic_(false), isPhiOverlapping_(false) {
    precomputed_value_sort(theDets.begin(), theDets.end(), DetPhi());

    const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|PhiBorderFinder";

    double step = 2.*Geom::pi()/theNbins;

    LogTrace(metname) << "RecoMuonDetLayers::PhiBorderFinder "
                      << "step w: " << step << " # of bins: " << theNbins;
    
    std::vector<double> spread(theNbins);
    std::vector<std::pair<double,double> > phiEdge;
    phiEdge.reserve(theNbins);
    thePhiBorders.reserve(theNbins);
    thePhiBins.reserve(theNbins);
    for ( unsigned int i = 0; i < theNbins; i++ ) {
      thePhiBins.push_back(theDets[i]->position().phi());
      spread.push_back(theDets[i]->position().phi()
        - (theDets[0]->position().phi() + i*step));
      
      LogTrace(metname) << "bin: " << i << " phi bin: " << thePhiBins[i]
                        << " spread: " <<  spread[i];
      

      ConstReferenceCountingPointer<BoundPlane> plane = 
        dynamic_cast<const BoundPlane*>(&theDets[i]->surface());
      if (plane==0) {
        //FIXME
        throw cms::Exception("UnexpectedState") << ("PhiBorderFinder: det surface is not a BoundPlane");
      }
      
      std::vector<GlobalPoint> dc = 
        BoundingBox().corners(*plane);

      float phimin(999.), phimax(-999.);
      for (std::vector<GlobalPoint>::const_iterator pt=dc.begin();
           pt!=dc.end(); pt++) {
        float phi = (*pt).phi();
//      float z = pt->z();
        if (phi < phimin) phimin = phi;
        if (phi > phimax) phimax = phi;
      }
      if (phimin*phimax < 0. &&           //Handle pi border:
          phimax - phimin > Geom::pi()) { //Assume that the Det is on
                                          //the shortest side 
        std::swap(phimin,phimax);
      }
      phiEdge.push_back(std::pair<double,double>(phimin,phimax));
    }
    
    for (unsigned int i = 0; i < theNbins; i++) {
      
      // Put the two phi values in the [0,2pi] range
      double firstPhi  = positiveRange(phiEdge[i].first);
      double secondPhi = positiveRange(phiEdge[binIndex(i-1)].second);

      // Reformat them in the [-pi,pi] range
      Geom::Phi<double> firstEdge(firstPhi);
      Geom::Phi<double> secondEdge(secondPhi);

      // Calculate the mean and format the result in the [-pi,pi] range
      // Get their value in order to perform the mean in the correct way
      Geom::Phi<double> mean((firstEdge.value() + secondEdge.value())/2.);
      
      // Special case: at +-pi there is a discontinuity
      if ( phiEdge[i].first * phiEdge[binIndex(i-1)].second < 0 &&
           fabs(firstPhi-secondPhi) < Geom::pi() ) 
        mean = Geom::pi() - mean;
     
      thePhiBorders.push_back(mean);
    }
  
    for (unsigned int i = 0; i < theNbins; i++) {
      if (Geom::Phi<double>(phiEdge[i].first)
          - Geom::Phi<double>(phiEdge[binIndex(i-1)].second) < 0) {
        isPhiOverlapping_ = true;
        break;
      }
    }

    double rms = stat_RMS(spread); 
    if ( rms < 0.01*step) { 
      isPhiPeriodic_ = true;
    }

    //Check that everything is proper
    if (thePhiBorders.size() != theNbins || thePhiBins.size() != theNbins) 
      //FIXME
      throw cms::Exception("UnexpectedState") << "PhiBorderFinder: consistency error";
  }
virtual PhiBorderFinder::~PhiBorderFinder ( ) [inline, virtual]

Definition at line 129 of file PhiBorderFinder.h.

{};

Member Function Documentation

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

Definition at line 161 of file PhiBorderFinder.h.

References theNbins.

Referenced by PhiBorderFinder().

                             {
    int ind = i % (int)theNbins;
    return (ind < 0) ? ind+theNbins : ind;
  }
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().

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

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

Definition at line 131 of file PhiBorderFinder.h.

References theNbins.

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

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

{ return thePhiBorders; }
double PhiBorderFinder::positiveRange ( double  phi) const [inline, private]

Definition at line 156 of file PhiBorderFinder.h.

References Geom::twoPi().

Referenced by PhiBorderFinder().

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

Member Data Documentation

Definition at line 152 of file PhiBorderFinder.h.

Referenced by isPhiOverlapping(), and PhiBorderFinder().

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