CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/RecoPixelVertexing/PixelTriplets/interface/ThirdHitRZPrediction.h

Go to the documentation of this file.
00001 #ifndef ThirdHitRZPrediction_H
00002 #define ThirdHitRZPrediction_H
00003 
00009 #include <algorithm>
00010 
00011 #include "RecoPixelVertexing/PixelTriplets/interface/ThirdHitRZPredictionBase.h"
00012 
00013 namespace helper {
00014   // Helper template to define how the ThirdHitRZPrediction interfaces
00015   // the prediction implementation
00016   template<class Propagator>
00017   class ThirdHitRZPredictionTraits {
00018   public:
00019     static inline float transform(const Propagator &propagator, bool barrel, float rOrZ);
00020   };
00021 
00022   // generic: defaults to calling zAtR or rAtZ
00023   // template can be specialized for individual classes if different
00024   // are required
00025   template<class Propagator>
00026   inline float ThirdHitRZPredictionTraits<Propagator>::transform(
00027         const Propagator &propagator, bool barrel, float rOrZ)
00028   { return barrel ? propagator.zAtR(rOrZ) : propagator.rAtZ(rOrZ); }
00029 }
00030 
00031 template<class Propagator>
00032 class ThirdHitRZPrediction : public ThirdHitRZPredictionBase {
00033 public:
00034   typedef helper::ThirdHitRZPredictionTraits<Propagator> traits;
00035 
00036   ThirdHitRZPrediction() : ThirdHitRZPredictionBase(), thePropagator(0) {}
00037   ThirdHitRZPrediction(const Propagator *propagator, float tolerance, const DetLayer* layer = 0) :
00038       ThirdHitRZPredictionBase(tolerance, layer), thePropagator(propagator) {}
00039 
00040   Range operator()(const DetLayer *layer = 0);
00041   inline Range operator()(float rORz) const { return (*this)(rORz, *thePropagator); }
00042   Range operator()(float rORz, const Propagator &propagator) const;
00043 
00044   void initPropagator(const Propagator *propagator) { thePropagator = propagator; }
00045 
00046 private:
00047   const Propagator *thePropagator;
00048 };
00049 
00050 template<class Propagator>
00051 typename ThirdHitRZPrediction<Propagator>::Range
00052 ThirdHitRZPrediction<Propagator>::operator()(const DetLayer *layer)
00053 {
00054   if (layer) initLayer(layer);
00055   if (!theBarrel && !theForward) return Range(0., 0.);
00056   float v1 = traits::transform(*thePropagator, theBarrel, theDetRange.min());
00057   float v2 = traits::transform(*thePropagator, theBarrel, theDetRange.max());
00058   if (v1 > v2) std::swap(v1, v2);
00059   return Range(v1 - theTolerance.left(), v2 + theTolerance.right());
00060 }
00061 
00062 template<class Propagator>
00063 typename ThirdHitRZPrediction<Propagator>::Range
00064 ThirdHitRZPrediction<Propagator>::operator()(float rOrZ, const Propagator &propagator) const
00065 {
00066   float v = traits::transform(propagator, theBarrel, rOrZ);
00067   return Range(v - theTolerance.left(), v + theTolerance.right());
00068 }
00069 
00070 #endif