CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoTracker/TkDetLayers/src/TECLayer.cc

Go to the documentation of this file.
00001 #include "TECLayer.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "CompatibleDetToGroupAdder.h"
00006 #include "DetGroupMerger.h"
00007 #include "LayerCrossingSide.h"
00008 
00009 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00010 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
00011 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
00012 #include "TrackingTools/DetLayers/interface/PhiLess.h"
00013 #include "DataFormats/GeometrySurface/interface/SimpleDiskBounds.h"
00014 #include "TkDetUtil.h"
00015 
00016 
00017 using namespace std;
00018 
00019 typedef GeometricSearchDet::DetWithState DetWithState;
00020 
00021 TECLayer::TECLayer(vector<const TECPetal*>& innerPetals,
00022                    vector<const TECPetal*>& outerPetals) : 
00023   theFrontComps(innerPetals.begin(),innerPetals.end()), 
00024   theBackComps(outerPetals.begin(),outerPetals.end())
00025 {
00026   theComps.assign(theFrontComps.begin(),theFrontComps.end());
00027   theComps.insert(theComps.end(),theBackComps.begin(),theBackComps.end());
00028 
00029   for(vector<const GeometricSearchDet*>::const_iterator it=theComps.begin();
00030       it!=theComps.end();it++){  
00031     theBasicComps.insert(theBasicComps.end(),   
00032                          (**it).basicComponents().begin(),
00033                          (**it).basicComponents().end());
00034   }
00035 
00036 
00037   //This should be no necessary. TO BE CHECKED
00038   //sort(theFrontPetals.begin(), theFrontPetals.end(), PetalLessPhi());
00039   //sort(theBackPetals.begin(), theBackPetals.end(), PetalLessPhi());
00040 
00041   // building disk for front and back petals
00042   setSurface( computeDisk( theComps ) );
00043   theFrontDisk = computeDisk( theFrontComps);
00044   theBackDisk  = computeDisk( theBackComps);
00045 
00046   // set up the bin finders
00047   theFrontBinFinder = BinFinderPhi(theFrontComps.front()->position().phi(),
00048                                    theFrontComps.size());
00049   theBackBinFinder  = BinFinderPhi(theBackComps.front()->position().phi(),
00050                                    theBackComps.size());  
00051 
00052   //--------- DEBUG INFO --------------
00053   LogDebug("TkDetLayers") << "DEBUG INFO for TECLayer" << "\n"
00054                           << "TECLayer z,perp, innerRadius, outerR: " 
00055                           << this->position().z()    << " , "
00056                           << this->position().perp() << " , "
00057                           << this->specificSurface().innerRadius() << " , "
00058                           << this->specificSurface().outerRadius() ;
00059   
00060 
00061   for(vector<const GeometricSearchDet*>::const_iterator it=theFrontComps.begin(); 
00062       it!=theFrontComps.end(); it++){
00063     LogDebug("TkDetLayers") << "frontPetal phi,z,r: " 
00064          << (*it)->surface().position().phi() << " , "
00065          << (*it)->surface().position().z() <<   " , "
00066          << (*it)->surface().position().perp() ;
00067   }
00068 
00069   for(vector<const GeometricSearchDet*>::const_iterator it=theBackComps.begin(); 
00070       it!=theBackComps.end(); it++){
00071     LogDebug("TkDetLayers") << "backPetal phi,z,r: " 
00072          << (*it)->surface().position().phi() << " , "
00073          << (*it)->surface().position().z() <<   " , "
00074          << (*it)->surface().position().perp() ;
00075   }
00076   //----------------------------------- 
00077 
00078 
00079 }
00080 
00081 
00082 
00083 TECLayer::~TECLayer(){
00084   vector<const GeometricSearchDet*>::const_iterator i;
00085   for (i=theComps.begin(); i!=theComps.end(); i++) {
00086     delete *i;
00087   }
00088 } 
00089   
00090 
00091 void
00092 TECLayer::groupedCompatibleDetsV( const TrajectoryStateOnSurface& tsos,
00093                                           const Propagator& prop,
00094                                            const MeasurementEstimator& est,
00095                                            std::vector<DetGroup> & result) const {  
00096   SubLayerCrossings  crossings; 
00097   crossings = computeCrossings( tsos, prop.propagationDirection());
00098   if(! crossings.isValid()) return;
00099 
00100   vector<DetGroup> closestResult;
00101   addClosest( tsos, prop, est, crossings.closest(), closestResult); 
00102   LogDebug("TkDetLayers") << "in TECLayer, closestResult.size(): " << closestResult.size();
00103 
00104   // this differs from other groupedCompatibleDets logic, which DON'T check next in such cases!!!
00105   if(closestResult.empty()){
00106     vector<DetGroup> nextResult;
00107     addClosest( tsos, prop, est, crossings.other(), nextResult);   
00108     LogDebug("TkDetLayers") << "in TECLayer, nextResult.size(): " << nextResult.size();
00109     if(nextResult.empty())       return;
00110     
00111 
00112     DetGroupElement nextGel( nextResult.front().front());  
00113     int crossingSide = LayerCrossingSide().endcapSide( nextGel.trajectoryState(), prop);
00114     DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result, 
00115                                             crossings.closestIndex(), crossingSide);   
00116   }  
00117   else {
00118     DetGroupElement closestGel( closestResult.front().front());  
00119     float phiWindow = tkDetUtil::computeWindowSize( closestGel.det(), closestGel.trajectoryState(), est); 
00120     searchNeighbors( tsos, prop, est, crossings.closest(), phiWindow,
00121                      closestResult, false); 
00122     vector<DetGroup> nextResult;  
00123     searchNeighbors( tsos, prop, est, crossings.other(), phiWindow,
00124                      nextResult, true); 
00125     
00126     int crossingSide = LayerCrossingSide().endcapSide( closestGel.trajectoryState(), prop);
00127     DetGroupMerger::orderAndMergeTwoLevels( closestResult, nextResult, result,
00128                                             crossings.closestIndex(), crossingSide);
00129   }
00130 }
00131 
00132 SubLayerCrossings TECLayer::computeCrossings(const TrajectoryStateOnSurface& startingState,
00133                                              PropagationDirection propDir) const
00134 {
00135   double rho( startingState.transverseCurvature());
00136   
00137   HelixPlaneCrossing::PositionType startPos( startingState.globalPosition() );
00138   HelixPlaneCrossing::DirectionType startDir( startingState.globalMomentum() );
00139   HelixForwardPlaneCrossing crossing(startPos,startDir,rho,propDir);
00140 
00141   pair<bool,double> frontPath = crossing.pathLength( *theFrontDisk);
00142   if (!frontPath.first) SubLayerCrossings();
00143 
00144 
00145   GlobalPoint gFrontPoint(crossing.position(frontPath.second));
00146   LogDebug("TkDetLayers") 
00147     << "in TECLayer,front crossing point: r,z,phi: (" 
00148     << gFrontPoint.perp() << ","
00149     << gFrontPoint.z() << "," 
00150     << gFrontPoint.phi() << ")" << endl;
00151   
00152 
00153   int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.barePhi()); 
00154   SubLayerCrossing frontSLC( 0, frontIndex, gFrontPoint);
00155 
00156 
00157 
00158   pair<bool,double> backPath = crossing.pathLength( *theBackDisk);
00159   if (!backPath.first) SubLayerCrossings();
00160 
00161 
00162   GlobalPoint gBackPoint( crossing.position(backPath.second));
00163   LogDebug("TkDetLayers") 
00164     << "in TECLayer,back crossing point: r,z,phi: (" 
00165     << gBackPoint.perp() << "," 
00166     << gFrontPoint.z() << "," 
00167     << gBackPoint.phi() << ")" << endl;
00168 
00169 
00170   int backIndex = theBackBinFinder.binIndex(gBackPoint.barePhi());
00171   SubLayerCrossing backSLC( 1, backIndex, gBackPoint);
00172 
00173   
00174   // 0ss: frontDisk has index=0, backDisk has index=1
00175   float frontDist = std::abs(Geom::deltaPhi( double(gFrontPoint.barePhi()), 
00176                                              double(theFrontComps[frontIndex]->surface().phi())));
00177   float backDist = std::abs(Geom::deltaPhi( double(gBackPoint.barePhi()), 
00178                                             double(theBackComps[backIndex]->surface().phi())));
00179   
00180 
00181   if (frontDist < backDist) {
00182     return SubLayerCrossings( frontSLC, backSLC, 0);
00183   }
00184   else {
00185     return SubLayerCrossings( backSLC, frontSLC, 1);
00186   } 
00187 }
00188 
00189 bool TECLayer::addClosest( const TrajectoryStateOnSurface& tsos,
00190                            const Propagator& prop,
00191                            const MeasurementEstimator& est,
00192                            const SubLayerCrossing& crossing,
00193                            vector<DetGroup>& result) const
00194 {
00195   const vector<const GeometricSearchDet*>& sub( subLayer( crossing.subLayerIndex()));
00196   const GeometricSearchDet* det(sub[crossing.closestDetIndex()]);
00197 
00198   LogDebug("TkDetLayers")  
00199     << "in TECLayer, adding petal at r,z,phi: (" 
00200     << det->position().perp() << "," 
00201     << det->position().z() << "," 
00202     << det->position().phi() << ")" << endl;
00203 
00204   return CompatibleDetToGroupAdder().add( *det, tsos, prop, est, result); 
00205 }
00206 
00207 void TECLayer::searchNeighbors( const TrajectoryStateOnSurface& tsos,
00208                                 const Propagator& prop,
00209                                 const MeasurementEstimator& est,
00210                                 const SubLayerCrossing& crossing,
00211                                 float window, 
00212                                 vector<DetGroup>& result,
00213                                 bool checkClosest) const
00214 {
00215   GlobalPoint gCrossingPos = crossing.position();
00216   
00217   const vector<const GeometricSearchDet*>& sLayer( subLayer( crossing.subLayerIndex()));
00218  
00219   int closestIndex = crossing.closestDetIndex();
00220   int negStartIndex = closestIndex-1;
00221   int posStartIndex = closestIndex+1;
00222 
00223   if (checkClosest) { // must decide if the closest is on the neg or pos side
00224     if ( PhiLess()( gCrossingPos.phi(), sLayer[closestIndex]->position().phi())) {
00225       posStartIndex = closestIndex;
00226     }
00227     else {
00228       negStartIndex = closestIndex;
00229     }
00230   }
00231 
00232   const BinFinderPhi& binFinder = (crossing.subLayerIndex()==0 ? theFrontBinFinder : theBackBinFinder);
00233 
00234   typedef CompatibleDetToGroupAdder Adder;
00235   int half = sLayer.size()/2;  // to check if dets are called twice....
00236   for (int idet=negStartIndex; idet >= negStartIndex - half; idet--) {
00237     const GeometricSearchDet & neighborPetal = *sLayer[binFinder.binIndex(idet)];
00238     if (!overlap( gCrossingPos, neighborPetal, window)) break;
00239     if (!Adder::add( neighborPetal, tsos, prop, est, result)) break;
00240     // maybe also add shallow crossing angle test here???
00241   }
00242   for (int idet=posStartIndex; idet < posStartIndex + half; idet++) {
00243     const GeometricSearchDet & neighborPetal = *sLayer[binFinder.binIndex(idet)];
00244     if (!overlap( gCrossingPos, neighborPetal, window)) break;
00245     if (!Adder::add( neighborPetal, tsos, prop, est, result)) break;
00246     // maybe also add shallow crossing angle test here???
00247   }
00248 }
00249 
00250 bool TECLayer::overlap( const GlobalPoint& gpos, const GeometricSearchDet& gsdet, float phiWin) const
00251 {
00252   float phi = gpos.barePhi();
00253   const BoundDiskSector&  diskSector = static_cast<const BoundDiskSector&>(gsdet.surface());
00254   pair<float,float> phiRange(phi-phiWin,phi+phiWin);
00255   pair<float,float> petalPhiRange(diskSector.phi() - 0.5*diskSector.phiExtension(),
00256                                   diskSector.phi() + 0.5*diskSector.phiExtension());
00257 
00258 
00259   return rangesIntersect(phiRange, petalPhiRange, PhiLess());
00260 }
00261 
00262 
00263 
00264 BoundDisk*
00265 TECLayer::computeDisk( vector<const GeometricSearchDet*>& petals) const
00266 {
00267   // Attention: it is assumed that the petals do belong to one layer, and are all
00268   // of the same rmin/rmax extension !!  
00269   
00270   const BoundDiskSector&  diskSector = static_cast<const BoundDiskSector&>(petals.front()->surface());
00271 
00272   float rmin = diskSector.innerRadius();
00273   float rmax = diskSector.outerRadius();
00274   
00275   float theZmax(petals.front()->position().z());
00276   float theZmin(theZmax);
00277   for ( vector<const GeometricSearchDet*>::const_iterator i = petals.begin(); i != petals.end(); i++ ) {
00278     float zmin = (**i).position().z() - (**i).surface().bounds().thickness()/2.;
00279     float zmax = (**i).position().z() + (**i).surface().bounds().thickness()/2.;
00280     theZmax = max( theZmax, zmax);
00281     theZmin = min( theZmin, zmin);
00282   }
00283 
00284   float zPos = (theZmax+theZmin)/2.;
00285   PositionType pos(0.,0.,zPos);
00286   RotationType rot;
00287 
00288   return new BoundDisk( pos, rot,SimpleDiskBounds(rmin, rmax,    
00289                                                   theZmin-zPos, theZmax-zPos));
00290 }
00291