CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TkDetLayers/src/TOBRod.cc

Go to the documentation of this file.
00001 #include "TOBRod.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "TrackingTools/DetLayers/interface/RodPlaneBuilderFromDet.h"
00006 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00007 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00008 #include "TrackingTools/GeomPropagators/interface/HelixBarrelPlaneCrossingByCircle.h"
00009 
00010 #include "LayerCrossingSide.h"
00011 #include "DetGroupMerger.h"
00012 #include "CompatibleDetToGroupAdder.h"
00013 
00014 
00015 using namespace std;
00016 
00017 typedef GeometricSearchDet::DetWithState DetWithState;
00018 
00019 class DetZLess {
00020 public:
00021   bool operator()(const GeomDet* a,const GeomDet* b) 
00022   {
00023     return (a->position().z() < b->position().z());
00024   } 
00025 };
00026 
00027 
00028 TOBRod::TOBRod(vector<const GeomDet*>& innerDets,
00029                vector<const GeomDet*>& outerDets):
00030   theInnerDets(innerDets),theOuterDets(outerDets)
00031 {
00032   theDets.assign(theInnerDets.begin(),theInnerDets.end());
00033   theDets.insert(theDets.end(),theOuterDets.begin(),theOuterDets.end());
00034 
00035 
00036   RodPlaneBuilderFromDet planeBuilder;
00037   setPlane( planeBuilder( theDets));
00038   theInnerPlane = planeBuilder( theInnerDets);
00039   theOuterPlane = planeBuilder( theOuterDets);
00040 
00041 
00042   sort(theDets.begin(),theDets.end(),DetZLess());
00043   sort(theInnerDets.begin(),theInnerDets.end(),DetZLess());
00044   sort(theOuterDets.begin(),theOuterDets.end(),DetZLess());
00045   theInnerBinFinder = BinFinderType(theInnerDets.begin(), theInnerDets.end());
00046   theOuterBinFinder = BinFinderType(theOuterDets.begin(), theOuterDets.end());
00047 
00048 
00049  
00050   LogDebug("TkDetLayers") << "==== DEBUG TOBRod =====" ; 
00051   for (vector<const GeomDet*>::const_iterator i=theInnerDets.begin();
00052        i != theInnerDets.end(); i++){
00053     LogDebug("TkDetLayers") << "inner TOBRod's Det pos z,perp,eta,phi: " 
00054                             << (**i).position().z() << " , " 
00055                             << (**i).position().perp() << " , " 
00056                             << (**i).position().eta() << " , " 
00057                             << (**i).position().phi() ;
00058   }
00059   
00060   for (vector<const GeomDet*>::const_iterator i=theOuterDets.begin();
00061        i != theOuterDets.end(); i++){
00062     LogDebug("TkDetLayers") << "outer TOBRod's Det pos z,perp,eta,phi: " 
00063                             << (**i).position().z() << " , " 
00064                             << (**i).position().perp() << " , " 
00065                             << (**i).position().eta() << " , " 
00066                             << (**i).position().phi() ;
00067   }
00068   LogDebug("TkDetLayers") << "==== end DEBUG TOBRod =====" ; 
00069   
00070 
00071 
00072 }
00073 
00074 TOBRod::~TOBRod(){
00075   
00076 } 
00077 
00078 
00079 const vector<const GeometricSearchDet*>& 
00080 TOBRod::components() const{
00081   throw DetLayerException("TOBRod doesn't have GeometricSearchDet components");
00082 }
00083   
00084 pair<bool, TrajectoryStateOnSurface>
00085 TOBRod::compatible( const TrajectoryStateOnSurface& ts, const Propagator&, 
00086                     const MeasurementEstimator&) const{
00087   edm::LogError("TkDetLayers") << "temporary dummy implementation of TOBRod::compatible()!!" ;
00088   return pair<bool,TrajectoryStateOnSurface>();
00089 }
00090 
00091 
00092 
00093 
00094 
00095 void
00096 TOBRod::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00097                                const Propagator& prop,
00098                                const MeasurementEstimator& est,
00099                                std::vector<DetGroup> & result) const{
00100   
00101   SubLayerCrossings  crossings; 
00102   crossings = computeCrossings( tsos, prop.propagationDirection());
00103   if(! crossings.isValid()) return;
00104 
00105   vector<DetGroup> closestResult;
00106   addClosest( tsos, prop, est, crossings.closest(), closestResult);
00107   if (closestResult.empty()){
00108     vector<DetGroup> nextResult;
00109     addClosest( tsos, prop, est, crossings.other(), nextResult);
00110     if(nextResult.empty())    return;
00111 
00112     DetGroupElement nextGel( nextResult.front().front());  
00113     int crossingSide = LayerCrossingSide().barrelSide( nextGel.trajectoryState(), prop);
00114     DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00115                                            crossings.closestIndex(), crossingSide);   
00116   } else {
00117   
00118     DetGroupElement closestGel( closestResult.front().front());
00119     float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est);
00120 
00121     searchNeighbors( tsos, prop, est, crossings.closest(), window,
00122                      closestResult, false);
00123 
00124     vector<DetGroup> nextResult;
00125     searchNeighbors( tsos, prop, est, crossings.other(), window,
00126                      nextResult, true);
00127 
00128     int crossingSide = LayerCrossingSide().barrelSide( closestGel.trajectoryState(), prop);
00129     DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00130                                             crossings.closestIndex(), crossingSide);
00131   }
00132 }
00133 
00134 
00135 SubLayerCrossings 
00136 TOBRod::computeCrossings( const TrajectoryStateOnSurface& startingState,
00137                           PropagationDirection propDir) const
00138 {
00139   GlobalPoint startPos( startingState.globalPosition());
00140   GlobalVector startDir( startingState.globalMomentum());
00141   double rho( startingState.transverseCurvature());
00142 
00143   HelixBarrelPlaneCrossingByCircle crossing( startPos, startDir, rho, propDir);
00144 
00145   pair<bool,double> innerPath = crossing.pathLength( *theInnerPlane);
00146   if (!innerPath.first) return SubLayerCrossings();
00147 
00148   GlobalPoint gInnerPoint( crossing.position(innerPath.second));
00149   int innerIndex = theInnerBinFinder.binIndex(gInnerPoint.z());
00150   float innerDist = fabs( theInnerBinFinder.binPosition(innerIndex) - gInnerPoint.z());
00151   SubLayerCrossing innerSLC( 0, innerIndex, gInnerPoint);
00152 
00153   pair<bool,double> outerPath = crossing.pathLength( *theOuterPlane);
00154   if (!outerPath.first) return SubLayerCrossings();
00155 
00156   GlobalPoint gOuterPoint( crossing.position(outerPath.second));
00157   int outerIndex = theOuterBinFinder.binIndex(gOuterPoint.z());
00158   float outerDist = fabs( theOuterBinFinder.binPosition(outerIndex) - gOuterPoint.z());
00159   SubLayerCrossing outerSLC( 1, outerIndex, gOuterPoint);
00160 
00161   if (innerDist < outerDist) {
00162     return SubLayerCrossings( innerSLC, outerSLC, 0);
00163   }
00164   else {
00165     return SubLayerCrossings( outerSLC, innerSLC, 1);
00166   } 
00167 }
00168 
00169 
00170 
00171 
00172 bool 
00173 TOBRod::addClosest( const TrajectoryStateOnSurface& tsos,
00174                     const Propagator& prop,
00175                     const MeasurementEstimator& est,
00176                     const SubLayerCrossing& crossing,
00177                     vector<DetGroup>& result) const
00178 {
00179 
00180   const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
00181   return CompatibleDetToGroupAdder::add( *sRod[crossing.closestDetIndex()], 
00182                                          tsos, prop, est, result);
00183 }
00184 
00185 
00186 float TOBRod::computeWindowSize( const GeomDet* det, 
00187                                  const TrajectoryStateOnSurface& tsos, 
00188                                  const MeasurementEstimator& est) const
00189 {
00190   return
00191     est.maximalLocalDisplacement(tsos, det->surface()).y();
00192 }
00193 
00194 
00195 
00196 
00197 void TOBRod::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00198                               const Propagator& prop,
00199                               const MeasurementEstimator& est,
00200                               const SubLayerCrossing& crossing,
00201                               float window, 
00202                               vector<DetGroup>& result,
00203                               bool checkClosest) const
00204 {
00205   GlobalPoint gCrossingPos = crossing.position();
00206 
00207   const vector<const GeomDet*>& sRod( subRod( crossing.subLayerIndex()));
00208  
00209   int closestIndex = crossing.closestDetIndex();
00210   int negStartIndex = closestIndex-1;
00211   int posStartIndex = closestIndex+1;
00212 
00213   if (checkClosest) { // must decide if the closest is on the neg or pos side
00214     if (gCrossingPos.z() < sRod[closestIndex]->surface().position().z()) {
00215       posStartIndex = closestIndex;
00216     }
00217     else {
00218       negStartIndex = closestIndex;
00219     }
00220   }
00221 
00222   typedef CompatibleDetToGroupAdder Adder;
00223   for (int idet=negStartIndex; idet >= 0; idet--) {
00224     if (!overlap( gCrossingPos, *sRod[idet], window)) break;
00225     if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
00226   }
00227   for (int idet=posStartIndex; idet < static_cast<int>(sRod.size()); idet++) {
00228     if (!overlap( gCrossingPos, *sRod[idet], window)) break;
00229     if (!Adder::add( *sRod[idet], tsos, prop, est, result)) break;
00230   }
00231 }
00232 
00233 
00234 
00235 bool TOBRod::overlap( const GlobalPoint& crossPoint, const GeomDet& det, float window) const
00236 {
00237   // check if the z window around TSOS overlaps with the detector theDet (with a 1% margin added)
00238   
00239   //   const float tolerance = 0.1;
00240   const float relativeMargin = 1.01;
00241 
00242   LocalPoint localCrossPoint( det.surface().toLocal(crossPoint));
00243   //   if (fabs(localCrossPoint.z()) > tolerance) {
00244   //     edm::LogInfo(TkDetLayers) << "TOBRod::overlap calculation assumes point on surface, but it is off by "
00245   //     << localCrossPoint.z() ;
00246   //   }
00247 
00248   float localY = localCrossPoint.y();
00249   float detHalfLength = det.surface().bounds().length()/2.;
00250 
00251   //   edm::LogInfo(TkDetLayers) << "TOBRod::overlap: Det at " << det.position() << " hit at " << localY 
00252   //        << " Window " << window << " halflength "  << detHalfLength ;
00253   
00254   if ( ( fabs(localY)-window) < relativeMargin*detHalfLength ) { // FIXME: margin hard-wired!
00255     return true;
00256   } else {
00257     return false;
00258   }
00259 }
00260