CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoTracker/TkDetLayers/src/CompositeTECPetal.cc

Go to the documentation of this file.
00001 #include "CompositeTECPetal.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "ForwardDiskSectorBuilderFromWedges.h"
00006 #include "LayerCrossingSide.h"
00007 #include "DetGroupMerger.h"
00008 #include "CompatibleDetToGroupAdder.h"
00009 
00010 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00011 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00012 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
00013 
00014 #include "TkDetUtil.h"
00015 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
00016 
00017 #include <boost/function.hpp>
00018 #include <boost/bind.hpp>
00019 #include<algorithm>
00020 #include<numeric>
00021 #include<iterator>
00022 
00023 using namespace std;
00024 
00025 typedef GeometricSearchDet::DetWithState DetWithState;
00026 
00027 
00028 namespace {
00029 namespace details {
00030 
00031   struct Mean {
00032     float operator()(const GeometricSearchDet*  a, const GeometricSearchDet* b) const {
00033       return 0.5*(b->position().perp()+a->position().perp());
00034     }
00035     float operator()(float  a, float b) const {
00036       return 0.5*(b+a);
00037     }
00038   };
00039 
00040   void fillBoundaries(std::vector<const GeometricSearchDet*> const & dets,
00041                       std::vector<float> & boundaries) {
00042     boundaries.resize(dets.size());
00043     std::transform(dets.begin(), dets.end(),  boundaries.begin(),
00044                    boost::bind(&GlobalPoint::perp,boost::bind(&GeometricSearchDet::position,_1))
00045                    );
00046     std::adjacent_difference(boundaries.begin(),boundaries.end(),  boundaries.begin(), Mean());
00047   }
00048 
00049   int findBin(std::vector<float> const & boundaries, float r) {
00050     return  
00051       std::lower_bound(boundaries.begin()+1,boundaries.end(),r)
00052       -boundaries.begin()-1;
00053   }
00054 
00055 }
00056 }
00057 
00058 CompositeTECPetal::CompositeTECPetal(vector<const TECWedge*>& innerWedges,
00059                                      vector<const TECWedge*>& outerWedges) : 
00060   theFrontComps(innerWedges.begin(),innerWedges.end()), 
00061   theBackComps(outerWedges.begin(),outerWedges.end())
00062 {
00063   theComps.assign(theFrontComps.begin(),theFrontComps.end());
00064   theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
00065 
00066   details::fillBoundaries( theFrontComps, theFrontBoundaries);
00067   details::fillBoundaries( theBackComps, theBackBoundaries);
00068 
00069 
00070   for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00071       it!=theComps.end();it++){  
00072     theBasicComps.insert(theBasicComps.end(),   
00073                          (**it).basicComponents().begin(),
00074                          (**it).basicComponents().end());
00075   }
00076 
00077 
00078   //the Wedge are already R ordered
00079   //sort( theWedges.begin(), theWedges.end(), DetLessR());
00080   //sort( theFrontWedges.begin(), theFrontWedges.end(), DetLessR() );
00081   //sort( theBackWedges.begin(), theBackWedges.end(), DetLessR() );
00082   vector<const TECWedge*> allWedges;
00083   allWedges.assign(innerWedges.begin(),innerWedges.end());
00084   allWedges.insert(allWedges.end(),outerWedges.begin(),outerWedges.end());
00085 
00086   theDiskSector  = ForwardDiskSectorBuilderFromWedges()( allWedges );
00087   theFrontSector = ForwardDiskSectorBuilderFromWedges()( innerWedges);
00088   theBackSector  = ForwardDiskSectorBuilderFromWedges()( outerWedges);
00089 
00090   //--------- DEBUG INFO --------------
00091   LogDebug("TkDetLayers") << "DEBUG INFO for CompositeTECPetal" ;
00092 
00093   for(vector<const GeometricSearchDet*>::const_iterator it=theFrontComps.begin(); 
00094       it!=theFrontComps.end(); it++){
00095     LogDebug("TkDetLayers") << "frontWedge phi,z,r: " 
00096                             << (*it)->surface().position().phi() << " , "
00097                             << (*it)->surface().position().z() <<   " , "
00098                             << (*it)->surface().position().perp() ;
00099   }
00100 
00101   for(vector<const GeometricSearchDet*>::const_iterator it=theBackComps.begin(); 
00102       it!=theBackComps.end(); it++){
00103     LogDebug("TkDetLayers") << "backWedge phi,z,r: " 
00104                             << (*it)->surface().position().phi() << " , "
00105                             << (*it)->surface().position().z() <<   " , "
00106                             << (*it)->surface().position().perp() ;
00107   }
00108   //----------------------------------- 
00109 
00110 
00111 }
00112 
00113 
00114 CompositeTECPetal::~CompositeTECPetal(){
00115   vector<const GeometricSearchDet*>::const_iterator i;
00116   for (i=theComps.begin(); i!=theComps.end(); i++) {
00117     delete *i;
00118   }
00119 } 
00120 
00121   
00122 pair<bool, TrajectoryStateOnSurface>
00123 CompositeTECPetal::compatible( const TrajectoryStateOnSurface& ts, const Propagator&, 
00124                   const MeasurementEstimator&) const{
00125   edm::LogError("TkDetLayers") << "temporary dummy implementation of CompositeTECPetal::compatible()!!" ;
00126   return pair<bool,TrajectoryStateOnSurface>();
00127 }
00128 
00129 
00130 void
00131 CompositeTECPetal::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00132                                            const Propagator& prop,
00133                                            const MeasurementEstimator& est,
00134                          std::vector<DetGroup> & result) const {
00135 
00136   vector<DetGroup> closestResult;
00137   SubLayerCrossings  crossings; 
00138   crossings = computeCrossings( tsos, prop.propagationDirection());
00139   if(! crossings.isValid()) return;
00140 
00141   addClosest( tsos, prop, est, crossings.closest(), closestResult); 
00142   LogDebug("TkDetLayers") << "in TECPetal, closestResult.size(): "<< closestResult.size();
00143 
00144   if (closestResult.empty()){
00145     vector<DetGroup> nextResult;
00146     addClosest( tsos, prop, est, crossings.other(), nextResult); 
00147     LogDebug("TkDetLayers") << "in TECPetal, nextResult.size(): "<< nextResult.size() ;
00148     if(nextResult.empty())    return;
00149     
00150     DetGroupElement nextGel( nextResult.front().front());  
00151     int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
00152     DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00153                                             crossings.closestIndex(), crossingSide);
00154   } else {
00155     
00156   DetGroupElement closestGel( closestResult.front().front());  
00157   float window = computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est); 
00158 
00159   searchNeighbors( tsos, prop, est, crossings.closest(), window,
00160                    closestResult, false); 
00161 
00162   vector<DetGroup> nextResult;
00163   searchNeighbors( tsos, prop, est, crossings.other(), window,
00164                    nextResult, true); 
00165 
00166   int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
00167   DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00168                                           crossings.closestIndex(), crossingSide);
00169   }
00170 }
00171 
00172 SubLayerCrossings 
00173 CompositeTECPetal::computeCrossings(const TrajectoryStateOnSurface& startingState,
00174                                    PropagationDirection propDir) const
00175 {
00176   double rho( startingState.transverseCurvature());
00177   
00178   HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
00179   HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
00180   HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
00181   pair<bool,double> frontPath = crossing.pathLength( *theFrontSector);
00182 
00183   if (!frontPath.first) return SubLayerCrossings();
00184 
00185   GlobalPoint gFrontPoint(crossing.position(frontPath.second));
00186   LogDebug("TkDetLayers") 
00187     << "in TECPetal,front crossing : r,z,phi: (" 
00188     << gFrontPoint.perp() << ","
00189     << gFrontPoint.z() << "," 
00190     << gFrontPoint.phi() << ")";
00191   
00192 
00193   int frontIndex = findBin(gFrontPoint.perp(),0);
00194   float frontDist = fabs( findPosition(frontIndex,0).perp() - gFrontPoint.perp());
00195   SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
00196 
00197 
00198 
00199   pair<bool,double> backPath = crossing.pathLength( *theBackSector);
00200 
00201   if (!backPath.first) return SubLayerCrossings();
00202   
00203 
00204   GlobalPoint gBackPoint( crossing.position(backPath.second));
00205   LogDebug("TkDetLayers") 
00206     << "in TECPetal,back crossing r,z,phi: (" 
00207     << gBackPoint.perp() << ","
00208     << gBackPoint.z() << "," 
00209     << gBackPoint.phi() << ")" ;
00210 
00211   int backIndex = findBin(gBackPoint.perp(),1);
00212   float backDist = fabs( findPosition(backIndex,1).perp() - gBackPoint.perp());
00213   
00214   SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
00215   
00216   
00217   // 0ss: frontDisk has index=0, backDisk has index=1
00218   if (frontDist < backDist) {
00219     return SubLayerCrossings( frontSLC, backSLC, 0);
00220   }
00221   else {
00222     return SubLayerCrossings( backSLC, frontSLC, 1);
00223   } 
00224 }
00225 
00226 bool CompositeTECPetal::addClosest( const TrajectoryStateOnSurface& tsos,
00227                                     const Propagator& prop,
00228                                     const MeasurementEstimator& est,
00229                                     const SubLayerCrossing& crossing,
00230                                     vector<DetGroup>& result) const
00231 {
00232   const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
00233   const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
00234 
00235   LogDebug("TkDetLayers") 
00236     << "in TECPetal, adding Wedge at r,z,phi: (" 
00237     << det->position().perp() << "," 
00238     << det->position().z() << "," 
00239     << det->position().phi() << ")" ;
00240   LogDebug("TkDetLayers") 
00241     << "wedge comps size: " 
00242     << det->basicComponents().size();
00243 
00244   return CompatibleDetToGroupAdder::add( *det, tsos, prop, est, result);
00245 }
00246 
00247 
00248 
00249 void 
00250 CompositeTECPetal::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00251                                     const Propagator& prop,
00252                                     const MeasurementEstimator& est,
00253                                     const SubLayerCrossing& crossing,
00254                                     float window, 
00255                                     vector<DetGroup>& result,
00256                                     bool checkClosest) const
00257 {
00258   GlobalPoint gCrossingPos = crossing.position();
00259 
00260   const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00261  
00262   int closestIndex = crossing.closestDetIndex(); 
00263   int negStartIndex = closestIndex-1;
00264   int posStartIndex = closestIndex+1;
00265 
00266   if (checkClosest) { // must decide if the closest is on the neg or pos side
00267     if ( gCrossingPos.perp() < sLayer[closestIndex]->position().perp() ) {
00268       posStartIndex = closestIndex;
00269     }
00270     else {
00271       negStartIndex = closestIndex;
00272     }
00273   }
00274 
00275 
00276   //const BinFinderType& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
00277   int theSize = crossing.subLayerIndex()==0 ? theFrontComps.size() : theBackComps.size();
00278   
00279   typedef CompatibleDetToGroupAdder Adder;
00280   for (int idet=negStartIndex; idet >= 0; idet--) {
00281     //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
00282     const GeometricSearchDet & neighborWedge = *sLayer[idet];
00283     if (!overlap( gCrossingPos, neighborWedge, window)) break;  // --- to check
00284     if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
00285     // maybe also add shallow crossing angle test here???
00286   }
00287   for (int idet=posStartIndex; idet <theSize; idet++) {
00288     //if(idet<0 || idet>= theSize) {edm::LogInfo(TkDetLayers) << "===== error! gone out vector bounds.idet: " << idet ;exit;}
00289     const GeometricSearchDet & neighborWedge = *sLayer[idet];
00290     if (!overlap( gCrossingPos, neighborWedge, window)) break;  // ---- to check
00291     if (!Adder::add( neighborWedge, tsos, prop, est, result)) break;
00292     // maybe also add shallow crossing angle test here???
00293   }
00294 }
00295 
00296 bool 
00297 CompositeTECPetal::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float ymax)
00298 {
00299   // this method is just a duplication of overlapInR 
00300   // adapeted for groupedCompatibleDets() needs
00301 
00302   // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
00303   float tsRadius = gpos.perp();
00304   float thetamin = ( max((float)0.,tsRadius-ymax))/(fabs(gpos.z())+10.); // add 10 cm contingency 
00305   float thetamax = ( tsRadius + ymax)/(fabs(gpos.z())-10.);
00306 
00307   const BoundDiskSector& wedgeSector = static_cast<const BoundDiskSector&>( gsdet.surface());                   
00308   float wedgeMinZ = fabs( wedgeSector.position().z()) - 0.5*wedgeSector.bounds().thickness();
00309   float wedgeMaxZ = fabs( wedgeSector.position().z()) + 0.5*wedgeSector.bounds().thickness(); 
00310   float thetaWedgeMin =  wedgeSector.innerRadius()/ wedgeMaxZ;
00311   float thetaWedgeMax =  wedgeSector.outerRadius()/ wedgeMinZ;
00312   
00313   // do the theta regions overlap ?
00314 
00315   return  !( thetamin > thetaWedgeMax || thetaWedgeMin > thetamax);
00316   
00317 } 
00318 
00319 
00320 
00321 
00322 
00323 float CompositeTECPetal::computeWindowSize( const GeomDet* det, 
00324                                             const TrajectoryStateOnSurface& tsos, 
00325                                             const MeasurementEstimator& est)
00326 {
00327   return est.maximalLocalDisplacement(tsos, det->surface()).y();
00328 }
00329 
00330 
00331 int CompositeTECPetal::findBin( float R, int diskSectorType) const 
00332 {
00333   return details::findBin(diskSectorType==0 ? theFrontBoundaries : theBackBoundaries,R);
00334 }
00335 
00336 
00337 
00338 
00339 GlobalPoint CompositeTECPetal::findPosition(int index,int diskSectorType) const 
00340 {
00341   vector<const GeometricSearchDet*> const & diskSector = diskSectorType == 0 ? theFrontComps : theBackComps; 
00342   return (diskSector[index])->position();
00343 }
00344