CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/TrackingTools/DetLayers/interface/GeneralBinFinderInZforGeometricSearchDet.h

Go to the documentation of this file.
00001 #ifndef GeneralBinFinderInZ_H
00002 #define GeneralBinFinderInZ_H
00003 
00008 #include "Utilities/BinningTools/interface/BaseBinFinder.h"
00009 #include "TrackingTools/DetLayers/interface/GeometricSearchDet.h"
00010 #include <cmath>
00011 
00012 template <class T>
00013 class GeneralBinFinderInZforGeometricSearchDet : public BaseBinFinder<T> {
00014 public:
00015 
00016   GeneralBinFinderInZforGeometricSearchDet() : theNbins(0), theZStep(0), theZOffset(0) {}
00017 
00018   GeneralBinFinderInZforGeometricSearchDet(
00019                       std::vector<const GeometricSearchDet*>::const_iterator first,
00020                       std::vector<const GeometricSearchDet*>::const_iterator last) :
00021     theNbins( last-first)
00022   {
00023     theBins.reserve(theNbins);
00024     for (std::vector<const GeometricSearchDet*>::const_iterator i=first; i<last-1; i++) {
00025       theBins.push_back((**i).position().z());
00026       theBorders.push_back(((**i).position().z() + 
00027                             (**(i+1)).position().z()) / 2.);
00028     }
00029 
00030     theZOffset = theBorders.front(); 
00031     theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
00032   }
00033 
00035   virtual int binIndex( T z) const {
00036     int bin = binIndex( int((z-theZOffset)/theZStep)+1);
00037     
00038     // check left border
00039     if (bin > 0) {
00040       if ( z < theBorders[bin-1]) {
00041         // z is to the left of the left border, the correct bin is left
00042         for (int i=bin-1; ; i--) {
00043           if (i <= 0) return 0;  
00044           if ( z > theBorders[i-1]) return i;
00045         }
00046       }
00047     } 
00048     else return 0;
00049     
00050     // check right border
00051     if (bin < theNbins-1) {
00052       if ( z > theBorders[bin]) {
00053         // z is to the right of the right border, the correct bin is right
00054         for (int i=bin+1; ; i++) {
00055           if (i >= theNbins-1) return theNbins-1;  
00056           if ( z < theBorders[i]) return i;
00057         }
00058       }
00059     }
00060     else return theNbins-1;
00061     
00062     // if we arrive here it means that the bin is ok 
00063     return bin;
00064   }
00065 
00067   virtual int binIndex( int i) const {
00068     return std::min( std::max( i, 0), theNbins-1);
00069   }
00070    
00072   virtual T binPosition( int ind) const {
00073     return theBins[binIndex(ind)];
00074   }
00075 
00076   static double pi() { return 3.141592653589793238;}
00077   static double twoPi() { return 2.*pi();}
00078 
00079 private:
00080 
00081   int theNbins;
00082   T theZStep;
00083   T theZOffset;
00084   std::vector<float> theBorders;
00085   std::vector<T> theBins;
00086 };
00087 #endif