CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TkDetLayers/src/PixelBarrelLayer.cc

Go to the documentation of this file.
00001 #include "PixelBarrelLayer.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "LayerCrossingSide.h"
00006 #include "DetGroupMerger.h"
00007 #include "CompatibleDetToGroupAdder.h"
00008 
00009 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00010 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00011 #include "TrackingTools/GeomPropagators/interface/HelixBarrelCylinderCrossing.h"
00012 #include "TrackingTools/DetLayers/interface/CylinderBuilderFromDet.h"
00013 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00014 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
00015 
00016 using namespace std;
00017 
00018 typedef GeometricSearchDet::DetWithState DetWithState;
00019 
00020 PixelBarrelLayer::PixelBarrelLayer(vector<const PixelRod*>& innerRods,
00021                                    vector<const PixelRod*>& outerRods) : 
00022   theInnerComps(innerRods.begin(),innerRods.end()), 
00023   theOuterComps(outerRods.begin(),outerRods.end())
00024 {
00025   theComps.assign(theInnerComps.begin(),theInnerComps.end());
00026   theComps.insert(theComps.end(),theOuterComps.begin(),theOuterComps.end());
00027 
00028   for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00029       it!=theComps.end();it++){  
00030     theBasicComps.insert(theBasicComps.end(),   
00031                          (**it).basicComponents().begin(),
00032                          (**it).basicComponents().end());
00033   }
00034 
00035   theInnerCylinder = cylinder( theInnerComps);
00036   theOuterCylinder = cylinder( theOuterComps);
00037 
00038   theInnerBinFinder = BinFinderType(theInnerComps.front()->position().phi(),
00039                                     theInnerComps.size());
00040   theOuterBinFinder = BinFinderType(theOuterComps.front()->position().phi(),
00041                                     theOuterComps.size());
00042 
00043   
00044   BarrelDetLayer::initialize();
00045 
00046 
00047   //--------- DEBUG INFO --------------
00048   LogDebug("TkDetLayers") << "==== DEBUG PixelBarrelLayer =====" ; 
00049   LogDebug("TkDetLayers") << "PixelBarrelLayer innerCyl r,lenght: "
00050                           << theInnerCylinder->radius() << " , "
00051                           << theInnerCylinder->bounds().length();
00052 
00053   LogDebug("TkDetLayers") << "PixelBarrelLayer outerCyl r,lenght: " 
00054                           << theOuterCylinder->radius() << " , "
00055                           << theOuterCylinder->bounds().length();
00056 
00057 
00058     for (vector<const GeometricSearchDet*>::const_iterator i=theInnerComps.begin();
00059        i != theInnerComps.end(); i++){
00060     LogDebug("TkDetLayers") << "inner PixelRod pos z,perp,eta,phi: " 
00061                             << (**i).position().z()    << " , " 
00062                             << (**i).position().perp() << " , " 
00063                             << (**i).position().eta()  << " , " 
00064                             << (**i).position().phi()  ;
00065   }
00066   
00067   for (vector<const GeometricSearchDet*>::const_iterator i=theOuterComps.begin();
00068        i != theOuterComps.end(); i++){
00069     LogDebug("TkDetLayers") << "outer PixelRod pos z,perp,eta,phi: " 
00070                             << (**i).position().z()    << " , " 
00071                             << (**i).position().perp() << " , " 
00072                             << (**i).position().eta()  << " , " 
00073                             << (**i).position().phi()  ;
00074   }
00075   LogDebug("TkDetLayers") << "==== end DEBUG PixelBarrelLayer =====" ; 
00076   //----------------------------------- 
00077 }
00078 
00079 PixelBarrelLayer::~PixelBarrelLayer(){
00080   vector<const GeometricSearchDet*>::const_iterator i;
00081   for (i=theComps.begin(); i!=theComps.end(); i++) {
00082     delete *i;
00083   }
00084 } 
00085   
00086 
00087 void 
00088 PixelBarrelLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00089                                           const Propagator& prop,
00090                                            const MeasurementEstimator& est,
00091                                            std::vector<DetGroup> & result) const {
00092   vector<DetGroup> closestResult;
00093   SubLayerCrossings  crossings;
00094   crossings = computeCrossings( tsos, prop.propagationDirection());
00095   if(! crossings.isValid()) return;  
00096   
00097   addClosest( tsos, prop, est, crossings.closest(), closestResult);
00098   if (closestResult.empty()) {
00099     addClosest( tsos, prop, est, crossings.other(), result);
00100     return;
00101   }
00102 
00103   DetGroupElement closestGel( closestResult.front().front());
00104   float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00105   
00106   searchNeighbors( tsos, prop, est, crossings.closest(), window,
00107                    closestResult, false);
00108   
00109   vector<DetGroup> nextResult;
00110   searchNeighbors( tsos, prop, est, crossings.other(), window,
00111                    nextResult, true);
00112   
00113   int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
00114   DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00115                                           crossings.closestIndex(), crossingSide);
00116 }
00117 
00118 
00119 // private methods for the implementation of groupedCompatibleDets()
00120 
00121 SubLayerCrossings PixelBarrelLayer::computeCrossings( const TrajectoryStateOnSurface& startingState,
00122                                                       PropagationDirection propDir) const
00123 {
00124   GlobalPoint startPos( startingState.globalPosition());
00125   GlobalVector startDir( startingState.globalMomentum());
00126   double rho( startingState.transverseCurvature());
00127   
00128   HelixBarrelCylinderCrossing innerCrossing( startPos, startDir, rho,
00129                                              propDir,*theInnerCylinder);
00130 
00131   if (!innerCrossing.hasSolution()) return SubLayerCrossings();
00132   //{
00133   //edm::LogInfo(TkDetLayers) << "ERROR in PixelBarrelLayer: inner cylinder not crossed by track" ;
00134   //throw DetLayerException("TkRodBarrelLayer: inner subRod not crossed by track");
00135   //}
00136 
00137   GlobalPoint gInnerPoint( innerCrossing.position());
00138   int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.phi());
00139   float innerDist = theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.phi();
00140   SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
00141 
00142   HelixBarrelCylinderCrossing outerCrossing( startPos, startDir, rho,
00143                                              propDir,*theOuterCylinder);
00144 
00145   if (!outerCrossing.hasSolution()) return SubLayerCrossings();
00146   //if (!outerCrossing.hasSolution()) {
00147   //  throw DetLayerException("PixelBarrelLayer: inner cylinder not crossed by track");
00148   //}
00149 
00150   GlobalPoint gOuterPoint( outerCrossing.position());
00151   int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.phi());
00152   float outerDist = theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.phi() ;
00153   SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
00154   
00155   innerDist *= PhiLess()( theInnerBinFinder.binPosition(innerIndex),gInnerPoint.phi()) ? -1. : 1.; 
00156   outerDist *= PhiLess()( theOuterBinFinder.binPosition(outerIndex),gOuterPoint.phi()) ? -1. : 1.; 
00157   if (innerDist < 0.) { innerDist += 2.*Geom::pi();}
00158   if (outerDist < 0.) { outerDist += 2.*Geom::pi();}
00159   
00160 
00161   if (innerDist < outerDist) {
00162     return SubLayerCrossings( innerSLC, outerSLC, 0);
00163   }
00164   else {
00165     return SubLayerCrossings( outerSLC, innerSLC, 1);
00166   } 
00167 }
00168 
00169 bool PixelBarrelLayer::addClosest( const TrajectoryStateOnSurface& tsos,
00170                                    const Propagator& prop,
00171                                    const MeasurementEstimator& est,
00172                                    const SubLayerCrossing& crossing,
00173                                    vector<DetGroup>& result) const
00174 {
00175   const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
00176   const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
00177   return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
00178 }
00179 
00180 float PixelBarrelLayer::computeWindowSize( const GeomDet* det, 
00181                                            const TrajectoryStateOnSurface& tsos, 
00182                                            const MeasurementEstimator& est) const
00183 {
00184   double xmax = 
00185     est.maximalLocalDisplacement(tsos, det->surface()).x();
00186   return calculatePhiWindow( xmax, *det, tsos);
00187 }
00188 
00189 
00190 double PixelBarrelLayer::calculatePhiWindow( double Xmax, const GeomDet& det,
00191                                              const TrajectoryStateOnSurface& state) const
00192 {
00193 
00194   LocalPoint startPoint = state.localPosition();
00195   LocalVector shift( Xmax , 0. , 0.);
00196   LocalPoint shift1 = startPoint + shift;
00197   LocalPoint shift2 = startPoint + (-shift); 
00198   //LocalPoint shift2( startPoint); //original code;
00199   //shift2 -= shift;
00200 
00201   double phi1 = det.surface().toGlobal(shift1).phi();
00202   double phi2 = det.surface().toGlobal(shift2).phi();
00203   double phiStart = state.globalPosition().phi();
00204   double phiWin = min(fabs(phiStart-phi1),fabs(phiStart-phi2));
00205 
00206   return phiWin;
00207 }
00208 
00209 
00210 void PixelBarrelLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00211                                         const Propagator& prop,
00212                                         const MeasurementEstimator& est,
00213                                         const SubLayerCrossing& crossing,
00214                                         float window, 
00215                                         vector<DetGroup>& result,
00216                                         bool checkClosest) const
00217 {
00218   GlobalPoint gCrossingPos = crossing.position();
00219 
00220   const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00221  
00222   int closestIndex = crossing.closestDetIndex();
00223   int negStartIndex = closestIndex-1;
00224   int posStartIndex = closestIndex+1;
00225 
00226   if (checkClosest) { // must decide if the closest is on the neg or pos side
00227     if ( PhiLess()( gCrossingPos.phi(), sLayer[closestIndex]->position().phi())) {
00228       posStartIndex = closestIndex;
00229     }
00230     else {
00231       negStartIndex = closestIndex;
00232     }
00233   }
00234 
00235   const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theInnerBinFinder : theOuterBinFinder);
00236 
00237   CompatibleDetToGroupAdder adder;
00238   int quarter = sLayer.size()/4;
00239   for (int idet=negStartIndex; idet >= negStartIndex - quarter; idet--) {
00240     const GeometricSearchDet* neighborRod = sLayer[binFinder.binIndex(idet)];
00241     if (!overlap( gCrossingPos, *neighborRod, window)) break;
00242     if (!adder.add( *neighborRod, tsos, prop, est, result)) break;
00243     // maybe also add shallow crossing angle test here???
00244   }
00245   for (int idet=posStartIndex; idet < posStartIndex + quarter; idet++) {
00246     const GeometricSearchDet* neighborRod = sLayer[binFinder.binIndex(idet)];
00247     if (!overlap( gCrossingPos, *neighborRod, window)) break;
00248     if (!adder.add( *neighborRod, tsos, prop, est, result)) break;
00249     // maybe also add shallow crossing angle test here???
00250   }
00251 }
00252 
00253 bool PixelBarrelLayer::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float phiWin) const
00254 {
00255   GlobalPoint crossPoint(gpos);
00256 
00257   // introduce offset (extrapolated point and true propagated point differ by 0.0003 - 0.00033, 
00258   // due to thickness of Rod of 1 cm) 
00259   const float phiOffset = 0.00034;  //...TOBE CHECKED LATER...
00260   phiWin += phiOffset;
00261 
00262   // detector phi range
00263   
00264   pair<float,float> phiRange(crossPoint.phi()-phiWin, crossPoint.phi()+phiWin);
00265 
00266   return rangesIntersect(phiRange, gsdet.surface().phiSpan(), PhiLess());
00267 
00268 } 
00269 
00270 
00271 BoundCylinder* PixelBarrelLayer::cylinder( const vector<const GeometricSearchDet*>& rods) const 
00272 {
00273   vector<const GeomDet*> tmp;
00274   for (vector<const GeometricSearchDet*>::const_iterator it=rods.begin(); it!=rods.end(); it++) {    
00275     tmp.insert(tmp.end(),(*it)->basicComponents().begin(),(*it)->basicComponents().end());
00276   }
00277   return CylinderBuilderFromDet()( tmp.begin(), tmp.end());
00278 }
00279