CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoTracker/TkNavigation/src/SimpleForwardNavigableLayer.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkNavigation/interface/SimpleForwardNavigableLayer.h"
00002 
00003 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00004 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00005 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00006 
00007 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
00008 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
00009 
00010 #include "RecoTracker/TkNavigation/interface/TkLayerLess.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 
00014 using namespace std;
00015 
00016 SimpleForwardNavigableLayer::
00017 SimpleForwardNavigableLayer( ForwardDetLayer* detLayer,
00018                              const BDLC& outerBL, 
00019                              const FDLC& outerFL, 
00020                              const MagneticField* field,
00021                              float epsilon,
00022                              bool checkCrossingSide) :
00023   SimpleNavigableLayer(field,epsilon,checkCrossingSide),
00024   areAllReachableLayersSet(false),
00025   theDetLayer(detLayer), 
00026   theOuterBarrelLayers(outerBL),
00027   theInnerBarrelLayers(0),
00028   theOuterForwardLayers(outerFL),
00029   theInnerForwardLayers(0),
00030   theOuterLayers(0), 
00031   theInnerLayers(0)
00032 {
00033   
00034   // put barrel and forward layers together
00035   theOuterLayers.reserve(outerBL.size() + outerFL.size());
00036   for ( ConstBDLI bl = outerBL.begin(); bl != outerBL.end(); bl++ ) 
00037     theOuterLayers.push_back(*bl);
00038   for ( ConstFDLI fl = outerFL.begin(); fl != outerFL.end(); fl++ ) 
00039     theOuterLayers.push_back(*fl);
00040 
00041   // sort the outer layers 
00042   sort(theOuterLayers.begin(), theOuterLayers.end(), TkLayerLess());
00043   sort(theOuterForwardLayers.begin(), theOuterForwardLayers.end(), TkLayerLess());
00044   sort(theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), TkLayerLess());
00045 
00046 }
00047 
00048 SimpleForwardNavigableLayer::
00049 SimpleForwardNavigableLayer( ForwardDetLayer* detLayer,
00050                              const BDLC& outerBL, 
00051                              const BDLC& allOuterBL,
00052                              const BDLC& innerBL,
00053                              const BDLC& allInnerBL,
00054                              const FDLC& outerFL, 
00055                              const FDLC& allOuterFL,
00056                              const FDLC& innerFL,
00057                              const FDLC& allInnerFL,
00058                              const MagneticField* field,
00059                              float epsilon,
00060                              bool checkCrossingSide) :
00061   SimpleNavigableLayer(field,epsilon,checkCrossingSide),
00062   areAllReachableLayersSet(true),
00063   theDetLayer(detLayer), 
00064   theOuterBarrelLayers(outerBL),
00065   theAllOuterBarrelLayers(allOuterBL),
00066   theInnerBarrelLayers(innerBL),
00067   theAllInnerBarrelLayers(allInnerBL),
00068   theOuterForwardLayers(outerFL),
00069   theAllOuterForwardLayers(allOuterFL),
00070   theInnerForwardLayers(innerFL),
00071   theAllInnerForwardLayers(allInnerFL),
00072   theOuterLayers(0), 
00073   theInnerLayers(0),
00074   theAllOuterLayers(0),
00075   theAllInnerLayers(0)
00076 {
00077   
00078   // put barrel and forward layers together
00079   theOuterLayers.reserve(outerBL.size() + outerFL.size());
00080   for ( ConstBDLI bl = outerBL.begin(); bl != outerBL.end(); bl++ ) 
00081     theOuterLayers.push_back(*bl);
00082   for ( ConstFDLI fl = outerFL.begin(); fl != outerFL.end(); fl++ ) 
00083     theOuterLayers.push_back(*fl);
00084 
00085   theAllOuterLayers.reserve(allOuterBL.size() + allOuterFL.size());
00086   for ( ConstBDLI bl = allOuterBL.begin(); bl != allOuterBL.end(); bl++ )
00087     theAllOuterLayers.push_back(*bl);
00088   for ( ConstFDLI fl = allOuterFL.begin(); fl != allOuterFL.end(); fl++ )
00089     theAllOuterLayers.push_back(*fl);
00090 
00091   theInnerLayers.reserve(innerBL.size() + innerFL.size());
00092   for ( ConstBDLI bl = innerBL.begin(); bl != innerBL.end(); bl++ )
00093     theInnerLayers.push_back(*bl);
00094   for ( ConstFDLI fl = innerFL.begin(); fl != innerFL.end(); fl++ )
00095     theInnerLayers.push_back(*fl);
00096 
00097   theAllInnerLayers.reserve(allInnerBL.size() + allInnerFL.size());
00098   for ( ConstBDLI bl = allInnerBL.begin(); bl != allInnerBL.end(); bl++ )
00099     theAllInnerLayers.push_back(*bl);
00100   for ( ConstFDLI fl = allInnerFL.begin(); fl != allInnerFL.end(); fl++ )
00101     theAllInnerLayers.push_back(*fl);
00102 
00103 
00104   // sort the outer layers 
00105   sort(theOuterLayers.begin(), theOuterLayers.end(), TkLayerLess());
00106   sort(theInnerLayers.begin(), theInnerLayers.end(),TkLayerLess(outsideIn));
00107   sort(theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), TkLayerLess());
00108   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(),TkLayerLess(outsideIn));
00109   sort(theOuterForwardLayers.begin(), theOuterForwardLayers.end(), TkLayerLess());
00110   sort(theInnerForwardLayers.begin(), theInnerForwardLayers.end(),TkLayerLess(outsideIn));
00111 
00112   sort(theAllOuterLayers.begin(), theAllOuterLayers.end(), TkLayerLess());
00113   sort(theAllInnerLayers.begin(), theAllInnerLayers.end(),TkLayerLess(outsideIn));
00114 
00115 }
00116 
00117 
00118 
00119 vector<const DetLayer*> 
00120 SimpleForwardNavigableLayer::nextLayers( NavigationDirection dir) const
00121 {
00122   vector<const DetLayer*> result;
00123   
00124   // the order is the one in which layers
00125   // should be checked for a reasonable trajectory
00126 
00127   if ( dir == insideOut ) {
00128     return theOuterLayers;
00129   }
00130   else {
00131     return theInnerLayers;
00132   }
00133 
00134   return result;
00135 }
00136 
00137 vector<const DetLayer*> 
00138 SimpleForwardNavigableLayer::nextLayers( const FreeTrajectoryState& fts, 
00139                                          PropagationDirection dir) const 
00140 {
00141   // This method contains the sequence in which the layers are tested.
00142   // The iteration stops as soon as a layer contains the propagated state
00143   // within epsilon
00144 
00145   vector<const DetLayer*> result;
00146 
00147   FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
00148     FreeTrajectoryState(fts.parameters()) : fts;
00149 
00150   //establish whether the tracks is crossing the tracker from outer layers to inner ones 
00151   //or from inner to outer
00152   //bool isInOutTrack  = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
00153   float zpos = fts.position().z();
00154   bool isInOutTrackFWD = fts.momentum().z()*zpos>0;
00155   GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
00156   bool isInOutTrackBarrel  = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;        
00157 
00158   //establish whether inner or outer layers are crossed after propagation, according
00159   //to BOTH propagationDirection AND track momentum
00160   bool dirOppositeXORisInOutTrackBarrel = ( !(dir == oppositeToMomentum) && isInOutTrackBarrel) || ( (dir == oppositeToMomentum) && !isInOutTrackBarrel);
00161   bool dirOppositeXORisInOutTrackFWD = ( !(dir == oppositeToMomentum) && isInOutTrackFWD) || ( (dir == oppositeToMomentum) && !isInOutTrackFWD);
00162   //bool dirOppositeXORisInOutTrack = ( !(dir == oppositeToMomentum) && isInOutTrack) || ( (dir == oppositeToMomentum) && !isInOutTrack);
00163 
00164   if ( dirOppositeXORisInOutTrackFWD && dirOppositeXORisInOutTrackBarrel ) { //standard tracks
00165 
00166     //wellInside(ftsWithoutErrors, dir, theOuterForwardLayers.begin(), theOuterForwardLayers.end(), result);
00167     wellInside(ftsWithoutErrors, dir, theOuterLayers, result);
00168 
00169   }
00170   else if (!dirOppositeXORisInOutTrackFWD && !dirOppositeXORisInOutTrackBarrel){ // !dirOppositeXORisInOutTrack
00171 
00172     //wellInside(ftsWithoutErrors, dir, theInnerForwardLayers.begin(), theInnerForwardLayers.end(), result);
00173     wellInside(ftsWithoutErrors, dir, theInnerLayers, result);
00174 
00175   } else if (!dirOppositeXORisInOutTrackFWD && dirOppositeXORisInOutTrackBarrel ) {
00176     wellInside(ftsWithoutErrors, dir, theInnerForwardLayers.begin(), theInnerForwardLayers.end(), result);
00177     wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);                
00178 
00179   } else {
00180     wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), result);        
00181     wellInside(ftsWithoutErrors, dir, theOuterForwardLayers.begin(), theOuterForwardLayers.end(), result);
00182 
00183   }
00184 /*
00185   if ( dirOppositeXORisInOutTrackBarrel ) {
00186 
00187     wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);
00188 
00189   }
00190   else { // !dirOppositeXORisInOutTrack
00191 
00192     wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(),theInnerBarrelLayers.end(), result);
00193 
00194   }
00195 */
00196 
00197   return result;
00198 }
00199 
00200 
00201 vector<const DetLayer*> 
00202 SimpleForwardNavigableLayer::compatibleLayers( NavigationDirection dir) const
00203 {
00204   if( !areAllReachableLayersSet ){
00205     edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
00206     throw DetLayerException("compatibleLayers() method used without all reachableLayers are set"); 
00207   }
00208 
00209   vector<const DetLayer*> result;
00210 
00211   if ( dir == insideOut ) {
00212     return theAllOuterLayers;
00213   }
00214   else {
00215     return theAllInnerLayers;
00216   }
00217   return result;
00218 
00219 }
00220 
00221 vector<const DetLayer*> 
00222 SimpleForwardNavigableLayer::compatibleLayers( const FreeTrajectoryState& fts, 
00223                                                PropagationDirection dir) const
00224 {
00225   if( !areAllReachableLayersSet ){
00226     int counter = 0;
00227     return SimpleNavigableLayer::compatibleLayers(fts,dir,counter);
00228     //    edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
00229     //    throw DetLayerException("compatibleLayers() method used without all reachableLayers are set"); 
00230   }
00231 
00232   vector<const DetLayer*> result;
00233   FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
00234     FreeTrajectoryState(fts.parameters()) : fts;
00235 
00236   //establish whether the tracks is crossing the tracker from outer layers to inner ones 
00237   //or from inner to outer.
00238   //bool isInOutTrack  = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
00239 /*  float zpos = fts.position().z();
00240   bool isInOutTrack = fts.momentum().z()*zpos>0;
00241   
00242   //establish whether inner or outer layers are crossed after propagation, according
00243   //to BOTH propagationDirection AND track momentum
00244   bool dirOppositeXORisInOutTrack = ( !(dir == oppositeToMomentum) && isInOutTrack) || ((dir == oppositeToMomentum) && !isInOutTrack);
00245 
00246   if ( dirOppositeXORisInOutTrack ) {
00247     wellInside(ftsWithoutErrors, dir, theAllOuterLayers, result);
00248   }
00249   else { // !dirOppositeXORisInOutTrack
00250     wellInside(ftsWithoutErrors, dir, theAllInnerLayers, result);
00251   }
00252 */
00253 
00254   float zpos = fts.position().z();
00255   bool isInOutTrackFWD = fts.momentum().z()*zpos>0;
00256   GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
00257   bool isInOutTrackBarrel  = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;
00258 
00259   //establish whether inner or outer layers are crossed after propagation, according
00260   //to BOTH propagationDirection AND track momentum
00261   bool dirOppositeXORisInOutTrackBarrel = ( !(dir == oppositeToMomentum) && isInOutTrackBarrel) || ( (dir == oppositeToMomentum) && !isInOutTrackBarrel);
00262   bool dirOppositeXORisInOutTrackFWD = ( !(dir == oppositeToMomentum) && isInOutTrackFWD) || ( (dir == oppositeToMomentum) && !isInOutTrackFWD);
00263   //bool dirOppositeXORisInOutTrack = ( !(dir == oppositeToMomentum) && isInOutTrack) || ( (dir == oppositeToMomentum) && !isInOutTrack);
00264 
00265   if ( dirOppositeXORisInOutTrackFWD && dirOppositeXORisInOutTrackBarrel ) { //standard tracks
00266 
00267     //wellInside(ftsWithoutErrors, dir, theOuterForwardLayers.begin(), theOuterForwardLayers.end(), result);
00268     wellInside(ftsWithoutErrors, dir, theAllOuterLayers, result);
00269 
00270   }
00271   else if (!dirOppositeXORisInOutTrackFWD && !dirOppositeXORisInOutTrackBarrel){ // !dirOppositeXORisInOutTrack
00272   
00273     //wellInside(ftsWithoutErrors, dir, theInnerForwardLayers.begin(), theInnerForwardLayers.end(), result);
00274     wellInside(ftsWithoutErrors, dir, theAllInnerLayers, result);
00275   
00276   } else if (!dirOppositeXORisInOutTrackFWD && dirOppositeXORisInOutTrackBarrel ) {
00277         
00278     wellInside(ftsWithoutErrors, dir, theAllInnerForwardLayers.begin(), theAllInnerForwardLayers.end(), result);
00279     wellInside(ftsWithoutErrors, dir, theAllOuterBarrelLayers.begin(), theAllOuterBarrelLayers.end(), result);
00280   
00281   } else { 
00282   
00283     wellInside(ftsWithoutErrors, dir, theAllInnerBarrelLayers.begin(), theAllInnerBarrelLayers.end(), result);
00284     wellInside(ftsWithoutErrors, dir, theAllOuterForwardLayers.begin(), theAllOuterForwardLayers.end(), result);
00285 
00286   }
00287   return result;
00288 }
00289 
00290 
00291 DetLayer* SimpleForwardNavigableLayer::detLayer() const { return theDetLayer; }
00292 
00293 void SimpleForwardNavigableLayer::setDetLayer( DetLayer* dl) {
00294   cerr << "Warning: SimpleForwardNavigableLayer::setDetLayer called."
00295        << endl << "This should never happen!" << endl;
00296 }
00297 
00298 void SimpleForwardNavigableLayer::setInwardLinks(const BDLC& innerBL, 
00299                                                  const FDLC& innerFL,
00300                                                  TkLayerLess sorter) {
00301 
00302   theInnerBarrelLayers  = innerBL;
00303   theInnerForwardLayers = innerFL;
00304 
00305   theInnerLayers.clear();
00306   theInnerLayers.reserve(innerBL.size() + innerFL.size());
00307   for ( ConstBDLI bl = innerBL.begin(); bl != innerBL.end(); bl++ )
00308     theInnerLayers.push_back(*bl);
00309   for ( ConstFDLI fl = innerFL.begin(); fl != innerFL.end(); fl++ )
00310     theInnerLayers.push_back(*fl);
00311 
00312   // sort the inner layers
00313   sort(theInnerLayers.begin(), theInnerLayers.end(),sorter);
00314   sort(theInnerForwardLayers.begin(), theInnerForwardLayers.end(),sorter);
00315   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), sorter);
00316 
00317 }
00318 
00319 void SimpleForwardNavigableLayer::setAdditionalLink(DetLayer* additional, NavigationDirection direction){
00320   ForwardDetLayer* fadditional = dynamic_cast<ForwardDetLayer*>(additional);
00321   BarrelDetLayer*  badditional = dynamic_cast<BarrelDetLayer*>(additional);
00322   if (badditional){
00323         if (direction==insideOut){
00324                 theOuterBarrelLayers.push_back(badditional);
00325                 theAllOuterBarrelLayers.push_back(badditional);
00326                 theOuterLayers.push_back(badditional);
00327                 theAllOuterLayers.push_back(badditional);
00328                 return;
00329         }
00330         theInnerBarrelLayers.push_back(badditional);
00331         theAllInnerBarrelLayers.push_back(badditional);
00332         theInnerLayers.push_back(badditional);
00333         theAllInnerLayers.push_back(badditional);
00334         return;
00335   } else if (fadditional){
00336         if (direction==insideOut){
00337                 theOuterForwardLayers.push_back(fadditional);
00338                 theAllOuterForwardLayers.push_back(fadditional);        
00339                 theOuterLayers.push_back(badditional);
00340                 theAllOuterLayers.push_back(badditional);
00341                 return;
00342         }
00343         theInnerForwardLayers.push_back(fadditional);
00344         theAllInnerForwardLayers.push_back(fadditional);
00345         theInnerLayers.push_back(badditional);
00346         theAllInnerLayers.push_back(badditional);
00347         return;
00348   }
00349   edm::LogError("TkNavigation") << "trying to add neither a ForwardDetLayer nor a BarrelDetLayer";
00350   return;
00351 }