CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoTracker/TkMSParametrization/src/MSLayer.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkMSParametrization/interface/MSLayer.h"
00002 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00003 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00004 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00005 #include "RecoTracker/TkMSParametrization/interface/MSLayersKeeper.h"
00006 
00007 #include<iostream>
00008 
00009 
00010 using namespace GeomDetEnumerators;
00011 using namespace std;
00012 template <class T> T sqr( T t) {return t*t;}
00013 
00014 //----------------------------------------------------------------------
00015 ostream& operator<<( ostream& s, const MSLayer & l) 
00016 {
00017   s <<" face: "<<l.face() 
00018     <<" pos:"<<l.position()<<", "
00019     <<" range:"<<l.range()<<", "
00020     <<l.theX0Data;
00021   return s;
00022 }
00023 //----------------------------------------------------------------------
00024 ostream& operator<<( ostream& s, const MSLayer::DataX0 & d)
00025 {
00026   if (d.hasX0)  s << "x0="<<d.x0 <<" sumX0D="<<d.sumX0D;  
00027   else if (d.allLayers)  s << "x0 by MSLayersKeeper"; 
00028   else  s <<"empty DataX0"; 
00029   return s; 
00030 }
00031 //----------------------------------------------------------------------
00032 //MP
00033 MSLayer::MSLayer(const DetLayer* layer, DataX0 dataX0)
00034  : theFace(layer->location()), theX0Data(dataX0) 
00035 {
00036   const BarrelDetLayer* bl; const ForwardDetLayer * fl;
00037   theHalfThickness = layer->surface().bounds().thickness()/2;  
00038 
00039   switch (theFace) {
00040   case barrel : 
00041     bl = static_cast<const BarrelDetLayer* >(layer);
00042     thePosition = bl->specificSurface().radius();
00043     theRange = Range(-bl->surface().bounds().length()/2,
00044                      bl->surface().bounds().length()/2);
00045     break;
00046   case endcap : 
00047     fl = static_cast<const ForwardDetLayer* >(layer);
00048     thePosition = fl->position().z(); 
00049     theRange = Range(fl->specificSurface().innerRadius(),
00050                      fl->specificSurface().outerRadius());
00051     break;
00052   default:
00053     // should throw or simimal
00054     cout << " ** MSLayer ** unknown part - will not work!" <<endl; 
00055     break;
00056   } 
00057 }
00058 //----------------------------------------------------------------------
00059 MSLayer::MSLayer(Location part, float position, Range range, float halfThickness,
00060     DataX0 dataX0)
00061   : theFace(part), 
00062     thePosition(position), 
00063     theRange(range), 
00064     theHalfThickness(halfThickness), 
00065     theX0Data(dataX0)
00066   { }
00067 
00068 
00069 //----------------------------------------------------------------------
00070 bool MSLayer::operator== (const MSLayer &o) const
00071 {
00072   return  theFace == o.theFace && std::abs(thePosition-o.thePosition) < 1.e-3f;
00073 }
00074 
00075 //----------------------------------------------------------------------
00076 pair<PixelRecoPointRZ,bool> MSLayer::crossing( 
00077     const PixelRecoLineRZ & line) const
00078 { 
00079  const float eps = 1.e-5;
00080   bool  inLayer = true;
00081   if (theFace==barrel) { 
00082     float value = line.zAtR(thePosition);
00083     if (value > theRange.max()) { 
00084       value = theRange.max()-eps;
00085       inLayer = false;
00086     } 
00087     else if (value < theRange.min() ) { 
00088       value = theRange.min()+eps;
00089       inLayer = false;
00090     }
00091     return make_pair( PixelRecoPointRZ(thePosition, value), inLayer) ;
00092   }
00093   else {
00094     float value = line.rAtZ(thePosition);
00095     if (value > theRange.max()) { 
00096       value = theRange.max()-eps;
00097       inLayer = false;
00098     }
00099     else if (value < theRange.min() ) { 
00100       value = theRange.min()+eps;
00101       inLayer = false;
00102     }
00103     return make_pair( PixelRecoPointRZ( value, thePosition), inLayer);
00104   }
00105 }
00106 //----------------------------------------------------------------------
00107 float MSLayer::distance(const PixelRecoPointRZ & point) const
00108 {
00109   float dr = 0;
00110   float dz = 0;
00111   switch(theFace) { 
00112   case barrel: 
00113     dr = std::abs(point.r()-thePosition);
00114     if (theRange.inside(point.z())) {
00115       return (dr < theHalfThickness) ? 0.f : dr;
00116     }
00117     else {
00118       dz = point.z() > theRange.max() ?
00119           point.z()-theRange.max() : theRange.min() - point.z();
00120     }
00121     break;
00122   case endcap:
00123     dz = std::abs(point.z()-thePosition);
00124     if (theRange.inside(point.r())) {
00125       return (dz < theHalfThickness) ? 0. : dz;
00126     }
00127     else {
00128       dr = point.r() > theRange.max() ?
00129           point.r()-theRange.max() : theRange.min()-point.r();
00130     }
00131     break;
00132   case invalidLoc: break; // make gcc happy
00133   }
00134   return std::sqrt(sqr(dr)+sqr(dz));
00135 }
00136 
00137 //----------------------------------------------------------------------
00138 bool MSLayer::operator< (const MSLayer & o) const
00139 {
00140 
00141   if (theFace==barrel && o.theFace==barrel) 
00142     return thePosition < o.thePosition;
00143   else if (theFace==barrel && o.theFace==endcap)
00144     return thePosition < o.range().max(); 
00145   else if (theFace==endcap && o.theFace==endcap ) 
00146     return std::abs(thePosition) < std::abs(o.thePosition);
00147   else 
00148     return range().max() < o.thePosition; 
00149 }
00150 //----------------------------------------------------------------------
00151 float MSLayer::x0(float cotTheta) const
00152 {
00153   if (theX0Data.hasX0) {
00154     float OverSinTheta = std::sqrt(1.f+cotTheta*cotTheta);
00155     switch(theFace) {
00156     case barrel:  return theX0Data.x0*OverSinTheta;
00157     case endcap: return theX0Data.x0*std::abs(OverSinTheta/cotTheta);
00158     case invalidLoc: return 0.;// make gcc happy
00159     }
00160   } else if (theX0Data.allLayers) {
00161     const MSLayer * dataLayer =
00162        theX0Data.allLayers->layers(cotTheta).findLayer(*this);
00163     if (dataLayer) return  dataLayer->x0(cotTheta);
00164   } 
00165   return 0.;
00166 }
00167 
00168 //----------------------------------------------------------------------
00169 float MSLayer::sumX0D(float cotTheta) const
00170 {
00171 if (theX0Data.hasX0) {
00172     switch(theFace) {
00173     case barrel:  
00174       return theX0Data.sumX0D
00175         *std::sqrt( std::sqrt(   (1.f+cotTheta*cotTheta)
00176                                  / (1.f+theX0Data.cotTheta*theX0Data.cotTheta)
00177                                  )
00178                     );
00179     case endcap: 
00180       return (theX0Data.hasFSlope) ?  
00181          theX0Data.sumX0D 
00182              + theX0Data.slopeSumX0D * (1.f/cotTheta-1.f/theX0Data.cotTheta)
00183        : theX0Data.sumX0D;
00184     case invalidLoc: break;// make gcc happy
00185     }
00186   } else if (theX0Data.allLayers) {
00187     const MSLayer* dataLayer =
00188        theX0Data.allLayers->layers(cotTheta).findLayer(*this);
00189     if (dataLayer) return  dataLayer->sumX0D(cotTheta);
00190   }
00191   return 0.;
00192 
00193 }