CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoHI/HiMuonAlgos/src/HICTkOuterStartingLayerFinder.cc

Go to the documentation of this file.
00001 #include "RecoHI/HiMuonAlgos/interface/HICTkOuterStartingLayerFinder.h"
00002 
00003 #include "DataFormats/GeometrySurface/interface/BoundSurface.h"
00004 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
00005 
00006 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00007 #include "DataFormats/GeometrySurface/interface/Plane.h"
00008 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00009 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00010 #include "Geometry/TrackerGeometryBuilder/interface/TrackerLayerIdAccessor.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00012 
00013 //#define PROPAGATOR_DB
00014 using namespace std;
00015 using namespace edm;
00016 
00017 //#define DEBUG
00018 
00019 namespace cms{
00020 HICTkOuterStartingLayerFinder::HICTkOuterStartingLayerFinder(int& numberOfSigmas, const MagneticField * mf, 
00021                                  const GeometricSearchTracker* th, const HICConst* hh):
00022                                  NumberOfSigm(numberOfSigmas),
00023                                  magfield(mf),
00024                                  theTracker(th),
00025                                  theHICConst(hh)      
00026 {
00027 
00028 // Get tracking geometry         
00029     
00030     theBarrelLayers = theTracker->barrelLayers();
00031     forwardPosLayers = theTracker->posForwardLayers();
00032     forwardNegLayers = theTracker->negForwardLayers();
00033     //cout<<" HICTkOuterStartingLayerFinder::zvert "<<theHICConst->zvert<<endl;
00034 }
00035 
00036 HICTkOuterStartingLayerFinder::LayerContainer HICTkOuterStartingLayerFinder::startingLayers(FreeTrajectoryState& fts)
00037 {
00038   vector<DetLayer*> seedlayers;
00039   
00040   
00041   BoundSurface* surc = (BoundSurface*)&((theBarrelLayers.back())->specificSurface());
00042   
00043   length=surc->bounds().length()/2.;
00044   
00045   double maxcoor=fabs(fts.parameters().position().z())+NumberOfSigm*fts.curvilinearError().matrix()(4,4);
00046   
00047   //
00048   //  barrel part (muon and tracker)
00049   //
00050   
00051 #ifdef DEBUG
00052   std::cout<<"HICTkOuterStartingLayerFinder::startingLayers::maxcoor "<<fabs(fts.parameters().position().z())<<" "<<
00053   NumberOfSigm<<" "<<fts.curvilinearError().matrix()(4,4)<<" maxcoor "<<maxcoor<<" length "<<length<<std::endl;
00054 #endif
00055   
00056   if(maxcoor<length) {
00057     seedlayers.push_back( theBarrelLayers.back());
00058     seedlayers.push_back( *(theBarrelLayers.end()-2));
00059     return seedlayers;
00060   }
00061 
00062   bool checkBarrel;
00063   
00064   if(fts.parameters().position().z() < 0.){
00065     checkBarrel = findForwardLayers( fts, forwardNegLayers, seedlayers);
00066   } else {
00067     checkBarrel = findForwardLayers( fts, forwardPosLayers, seedlayers);
00068   }
00069   
00070   if (!checkBarrel) return seedlayers;
00071 //
00072 // One should attach barrel layers
00073 //  
00074   if(fts.parameters().position().z() < 0.){
00075     return findBarrelLayers( fts, forwardNegLayers, seedlayers);
00076   }else{
00077     return findBarrelLayers( fts, forwardPosLayers, seedlayers);
00078   }
00079 
00080   //  return seedlayers;
00081   
00082 }
00083 
00084 bool HICTkOuterStartingLayerFinder::findForwardLayers( const FreeTrajectoryState& fts,
00085                                                     std::vector<ForwardDetLayer*>& fls, 
00086                                                     HICTkOuterStartingLayerFinder::LayerContainer& seedlayers){
00087               
00088   bool barrel = false;
00089 
00090 #ifdef DEBUG
00091   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::start "<<NumberOfSigm<<std::endl;
00092 #endif  
00093 
00094   double outrad, zseed, rseed, theta, atrack, btrack;
00095   double dz, dr, a1, zdet, newzmin, newzmax;  
00096   std::vector<ForwardDetLayer*>::const_iterator flayer; 
00097   double mincoor=fabs(fts.parameters().position().z())-
00098                                                       NumberOfSigm*fts.curvilinearError().matrix()(4,4);
00099                                                       
00100 //  double zdetlast=(fls.front())->surface().position().z();
00101   double zdetlast=length;
00102   outrad=(fls.back())->specificSurface().outerRadius();
00103   
00104   zseed=fts.parameters().position().z();  
00105   rseed=fts.parameters().position().perp();
00106   dz = 3.*NumberOfSigm*fts.curvilinearError().matrix()(4,4); // ok
00107   dr = NumberOfSigm*fts.curvilinearError().matrix()(4,4);
00108   
00109   theta=fts.parameters().momentum().theta();
00110   atrack=tan(theta);
00111   btrack=rseed-atrack*zseed;
00112 //  zvert=-btrack/atrack;
00113 
00114 #ifdef DEBUG
00115   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers "<<rseed<<" dr "<<dr<<" outrad "<<outrad<<std::endl;
00116 #endif   
00117 
00118   if(rseed+dr<outrad){
00119 #ifdef DEBUG
00120   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::add last forward layer "<<rseed<<" dr "<<dr<<" outrad "<<outrad<<std::endl;
00121 #endif
00122     seedlayers.push_back(fls.back());
00123     zdetlast = fabs((fls.back())->surface().position().z());
00124 
00125   }else{
00126     if(rseed>outrad) {
00127 #ifdef DEBUG
00128   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::1 zseed "<<zseed<<" dz "<<dz<<std::endl;
00129 #endif
00130 
00131     newzmin=abs(zseed)-3.*dz; // ok 8*dz now 3*dz
00132 //    newzmin = fabs(zseed)-30.; // ok 16.06.08
00133     newzmax=fabs(zseed)+dz/(2.*NumberOfSigm); // ok dz
00134     } else {
00135     a1=(rseed+dr)/(fabs(zseed)-fabs(theHICConst->zvert));
00136     if(zseed<0.) a1=-1.*a1;
00137 
00138 #ifdef DEBUG
00139   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::2 zseed "<<zseed<<" dz "<<dz<<" "<<(fls.back())->surface().position().z()<<std::endl;
00140 #endif
00141 
00142     newzmin=abs(outrad/a1)-3.*dz; //ok 6*dz now 3*dz 
00143 //    newzmin = fabs(zseed)-30.; // ok 16.06.08
00144     newzmax=fabs((fls.back())->surface().position().z())+dz;
00145     }
00146 #ifdef DEBUG
00147   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::newzmin,newzmax "<<newzmin<<" "<<newzmax<<std::endl;
00148 #endif
00149     
00150     for(flayer=fls.end()-1;flayer!=fls.begin()-1;flayer--){
00151      
00152       zdet=(**flayer).surface().position().z();
00153 #ifdef DEBUG
00154   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::zdet "<<zdet<<" thickness "<<(**flayer).surface().bounds().thickness()<<std::endl;
00155 #endif
00156            
00157 //      if(abs(newzmin)<=abs(zdet+(**flayer).surface().bounds().thickness())
00158 //                 && abs(zdet-(**flayer).surface().bounds().thickness())<=abs(newzmax)){ 
00159 
00160       if(fabs(zdet)<length) break;
00161 
00162       if(fabs(newzmin)<=fabs(zdet)+(**flayer).surface().bounds().thickness()
00163                  && fabs(zdet)-(**flayer).surface().bounds().thickness()<=fabs(newzmax)){
00164 
00165 #ifdef DEBUG
00166   std::cout<<"HICTkOuterStartingLayerFinder::findForwardLayers::add layer "<<zdet<<std::endl;
00167 #endif
00168          
00169         seedlayers.push_back(&(**flayer));
00170         zdetlast=zdet;
00171 
00172       } //zmin
00173 
00174     } //flayer
00175   }
00176 //  if(mincoor<abs(zdetlast) ){
00177 #ifdef DEBUG
00178 
00179    std::cout<<"HICTkOuterStartingLayerFinder::zdetlast,mincoor "<<zdetlast<<" "<<mincoor<<std::endl;
00180 
00181 #endif
00182   if(fabs(mincoor)<fabs(zdetlast)||fabs(zdetlast)<140.){
00183 #ifdef DEBUG
00184    std::cout<<"HICTkOuterStartingLayerFinder::add barrel layers to forward "<<std::endl;
00185 #endif
00186     barrel=true;
00187   }
00188   return barrel;
00189 }
00190 HICTkOuterStartingLayerFinder::LayerContainer HICTkOuterStartingLayerFinder::findBarrelLayers( const FreeTrajectoryState& fts,
00191                                                                          std::vector<ForwardDetLayer*>& fls, LayerContainer& seedlayers)
00192 {             
00193 #ifdef DEBUG
00194   std::cout<<"HICTkOuterStartingLayerFinder::findBarrelLayers::start::zdetlast "<<length<<std::endl;
00195 #endif
00196   std::vector<BarrelDetLayer*>::const_iterator blayer; 
00197  //  
00198  // double zdetlast=(fls.front())->surface().position().z();
00199 
00200   double zdetlast = length+10.;
00201   //double zseed=fts.parameters().position().z();  
00202   //double rseed=fts.parameters().position().perp();
00203   //double dz = NumberOfSigm*fts.curvilinearError().matrix()(5,5);
00204   //double atrack=tan(fts.parameters().momentum().theta());
00205   //double btrack=rseed-atrack*zseed;
00206 //  double zvert=-btrack/atrack;
00207   double r,rmin,rmax;   
00208   
00209   BoundSurface* surc = (BoundSurface*)&((theBarrelLayers.back())->surface());
00210   double zbarrel=surc->bounds().length()/2.;
00211   BoundCylinder* bc = dynamic_cast<BoundCylinder*>(surc);
00212   double barrelradius=bc->radius();
00213 
00214   double a1=barrelradius/(fabs(zdetlast)-fabs(theHICConst->zvert));
00215 
00216 
00217   rmin=a1*zbarrel-(theBarrelLayers.back())->surface().bounds().thickness();
00218   rmax=barrelradius+(theBarrelLayers.back())->surface().bounds().thickness();
00219      
00220 //  if(fabs(zseed)-dz<zbarrel){
00221 //    rmax=barrelradius+(theBarrelLayers.back())->surface().bounds().thickness();
00222 //  } else{
00223 //    a2=barrelradius/(fabs(zseed-theHICConst->zvert)-dz);
00224 //    if(zseed<0.) a2=-1.*a2;
00225 //    rmax=a2*zbarrel+(theBarrelLayers.back())->surface().bounds().thickness();
00226 //  cout<<" Check a2,rmax "<<a2<<" "<<rmax<<endl;
00227 //  }
00228      
00229 #ifdef DEBUG
00230   std::cout<<"HICTkOuterStartingLayerFinder::findBarrelLayers::rmin,rmax "<<rmin<<" "<<rmax<<std::endl;
00231 #endif 
00232 
00233   for(blayer=theBarrelLayers.end()-1;blayer!=theBarrelLayers.begin()-1;blayer--){
00234   
00235   BoundSurface* sc = (BoundSurface*)&((*blayer)->surface());
00236   r=(dynamic_cast<BoundCylinder*>(sc))->radius();
00237 
00238             
00239     if(r>rmin&&r<=rmax){
00240       seedlayers.push_back(&(**blayer));
00241 #ifdef DEBUG
00242   std::cout<<"HICTkOuterStartingLayerFinder::findBarrelLayers::add "<<r<<std::endl;
00243 #endif
00244     }
00245   }//blayer barrel  
00246   return seedlayers;
00247 }
00248 }