CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoTracker/TkNavigation/src/SimpleBarrelNavigableLayer.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkNavigation/interface/SimpleBarrelNavigableLayer.h"
00002 
00003 #include "DataFormats/GeometrySurface/interface/BoundCylinder.h"
00004 #include "DataFormats/GeometrySurface/interface/BoundDisk.h"
00005 
00006 #include "TrackingTools/DetLayers/src/DetBelowZ.h"
00007 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
00008 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00009 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00010 
00011 #include "RecoTracker/TkNavigation/interface/TkLayerLess.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 #include <functional>
00015 #include <algorithm>
00016 #include <map>
00017 #include <cmath>
00018 
00019 using namespace std;
00020 
00021 
00022 SimpleBarrelNavigableLayer::
00023 SimpleBarrelNavigableLayer( BarrelDetLayer* detLayer,
00024                             const BDLC& outerBLC, 
00025                             const FDLC& outerLeftFL, 
00026                             const FDLC& outerRightFL,
00027                             const MagneticField* field,
00028                             float epsilon,
00029                             bool checkCrossingSide) :
00030   SimpleNavigableLayer(field,epsilon,checkCrossingSide),
00031   areAllReachableLayersSet(false),
00032   theDetLayer( detLayer), 
00033   theOuterBarrelLayers( outerBLC),
00034   theOuterLeftForwardLayers( outerLeftFL),
00035   theOuterRightForwardLayers( outerRightFL)
00036 
00037 {
00038   // put barrel and forward layers together
00039   theNegOuterLayers.reserve( outerBLC.size() + outerLeftFL.size());
00040   thePosOuterLayers.reserve( outerBLC.size() + outerRightFL.size());
00041 
00042   for (ConstBDLI bl=outerBLC.begin(); bl!=outerBLC.end(); bl++) 
00043     theNegOuterLayers.push_back( *bl);
00044   thePosOuterLayers = theNegOuterLayers; // barrel part the same
00045 
00046   for (ConstFDLI fl=outerLeftFL.begin(); fl!=outerLeftFL.end(); fl++) 
00047     theNegOuterLayers.push_back( *fl);
00048   for (ConstFDLI fl=outerRightFL.begin(); fl!=outerRightFL.end(); fl++) 
00049     thePosOuterLayers.push_back( *fl);
00050 
00051   // sort the outer layers 
00052   sort( theNegOuterLayers.begin(), theNegOuterLayers.end(), TkLayerLess());
00053   sort( thePosOuterLayers.begin(), thePosOuterLayers.end(), TkLayerLess());
00054   sort(theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), TkLayerLess());
00055   sort(theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), TkLayerLess());
00056   sort(theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), TkLayerLess());
00057 }
00058   
00059 
00060 SimpleBarrelNavigableLayer::
00061 SimpleBarrelNavigableLayer( BarrelDetLayer* detLayer,
00062                             const BDLC& outerBLC, 
00063                             const BDLC& innerBLC,
00064                             const BDLC& allOuterBLC,
00065                             const BDLC& allInnerBLC,
00066                             const FDLC& outerLeftFL, 
00067                             const FDLC& outerRightFL,
00068                             const FDLC& allOuterLeftFL,
00069                             const FDLC& allOuterRightFL,
00070                             const FDLC& innerLeftFL,
00071                             const FDLC& innerRightFL,
00072                             const FDLC& allInnerLeftFL,
00073                             const FDLC& allInnerRightFL,
00074                             const MagneticField* field,
00075                             float epsilon,
00076                             bool checkCrossingSide) :
00077   SimpleNavigableLayer(field,epsilon,checkCrossingSide),
00078   areAllReachableLayersSet(true),
00079   theDetLayer( detLayer), 
00080   theOuterBarrelLayers( outerBLC),
00081   theInnerBarrelLayers( innerBLC),
00082   theAllOuterBarrelLayers( allOuterBLC),
00083   theAllInnerBarrelLayers( allInnerBLC),
00084   theOuterLeftForwardLayers( outerLeftFL),
00085   theOuterRightForwardLayers( outerRightFL),
00086   theAllOuterLeftForwardLayers( allOuterLeftFL),
00087   theAllOuterRightForwardLayers( allOuterRightFL),
00088   theInnerLeftForwardLayers( innerLeftFL),
00089   theInnerRightForwardLayers( innerRightFL),
00090   theAllInnerLeftForwardLayers( allInnerLeftFL),
00091   theAllInnerRightForwardLayers( allInnerRightFL)
00092 {
00093   // put barrel and forward layers together
00094   theNegOuterLayers.reserve( outerBLC.size() + outerLeftFL.size());
00095   thePosOuterLayers.reserve( outerBLC.size() + outerRightFL.size());
00096   theNegInnerLayers.reserve( innerBLC.size() + innerLeftFL.size());
00097   thePosInnerLayers.reserve( innerBLC.size() + innerRightFL.size());
00098 
00099 
00100   for (ConstBDLI bl=outerBLC.begin(); bl!=outerBLC.end(); bl++) 
00101     theNegOuterLayers.push_back( *bl);
00102   thePosOuterLayers = theNegOuterLayers; // barrel part the same
00103 
00104   for (ConstFDLI fl=outerLeftFL.begin(); fl!=outerLeftFL.end(); fl++) 
00105     theNegOuterLayers.push_back( *fl);
00106   for (ConstFDLI fl=outerRightFL.begin(); fl!=outerRightFL.end(); fl++) 
00107     thePosOuterLayers.push_back( *fl);
00108 
00109   for (ConstBDLI bl=innerBLC.begin(); bl!=innerBLC.end(); bl++)
00110     theNegInnerLayers.push_back( *bl);
00111   thePosInnerLayers = theNegInnerLayers; // barrel part the same
00112 
00113   for (ConstFDLI fl=innerLeftFL.begin(); fl!=innerLeftFL.end(); fl++)
00114     theNegInnerLayers.push_back( *fl);
00115   for (ConstFDLI fl=innerRightFL.begin(); fl!=innerRightFL.end(); fl++)
00116     thePosInnerLayers.push_back( *fl);
00117 
00118   // sort the outer layers 
00119   sort( theNegOuterLayers.begin(), theNegOuterLayers.end(), TkLayerLess());
00120   sort( thePosOuterLayers.begin(), thePosOuterLayers.end(), TkLayerLess());
00121   sort( theNegInnerLayers.begin(), theNegInnerLayers.end(), TkLayerLess(outsideIn));
00122   sort( thePosInnerLayers.begin(), thePosInnerLayers.end(), TkLayerLess(outsideIn));
00123   sort(theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), TkLayerLess());
00124   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(),TkLayerLess(outsideIn));
00125   sort(theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), TkLayerLess());
00126   sort(theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), TkLayerLess());
00127   sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(),TkLayerLess(outsideIn));
00128   sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(),TkLayerLess(outsideIn));
00129 
00130 }
00131 
00132 
00133 vector<const DetLayer*> 
00134 SimpleBarrelNavigableLayer::nextLayers( NavigationDirection dir) const
00135 {
00136   vector<const DetLayer*> result;
00137   
00138   // the order is the one in which layers
00139   // should be checked for a reasonable trajectory
00140 
00141   if ( dir == insideOut) {
00142     result = theNegOuterLayers;
00143     for ( DLC::const_iterator i=thePosOuterLayers.begin();
00144           i!=thePosOuterLayers.end(); i++) {
00145       // avoid duplication of barrel layers
00146       if ((**i).location() == GeomDetEnumerators::endcap) result.push_back(*i);
00147     }
00148   }
00149   else {
00150     result = theNegInnerLayers;
00151     for ( DLC::const_iterator i=thePosInnerLayers.begin();
00152           i!=thePosInnerLayers.end(); i++) {
00153       // avoid duplication of barrel layers
00154       if ((**i).location() == GeomDetEnumerators::endcap) result.push_back(*i);
00155     }
00156   }
00157   return result;
00158 }
00159 
00160 vector<const DetLayer*>
00161 SimpleBarrelNavigableLayer::nextLayers( const FreeTrajectoryState& fts, 
00162                                         PropagationDirection dir) const
00163 {
00164   // This method contains the sequence in which the layers are tested.
00165   // The iteration stops as soon as a layer contains the propagated state
00166   // within epsilon.
00167 
00168   vector<const DetLayer*> result;
00169 
00170   FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
00171     FreeTrajectoryState( fts.parameters()) :
00172     fts;
00173 
00174   //establish whether the tracks is crossing the tracker from outer layers to inner ones 
00175   //or from inner to outer.
00176   GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
00177   //GlobalVector transverseMomentum(fts.momentum().x(), fts.momentum().y(), 0);
00178   //bool isInOutTrack  = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
00179   bool isInOutTrackBarrel  = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;
00180   //cout << "dot: " << transversePosition.dot(fts.momentum()) << endl;
00181 
00182   float zpos = fts.position().z();
00183   bool isInOutTrackFWD = fts.momentum().z()*zpos>0;
00184   
00185 
00186   //establish whether inner or outer layers are crossed after propagation, according
00187   //to BOTH propagationDirection AND track momentum
00188   bool dirOppositeXORisInOutTrackBarrel = ( !(dir == oppositeToMomentum) && isInOutTrackBarrel) || ((dir == oppositeToMomentum) && !isInOutTrackBarrel);
00189   bool dirOppositeXORisInOutTrackFWD = ( !(dir == oppositeToMomentum) && isInOutTrackFWD) || ((dir == oppositeToMomentum) && !isInOutTrackFWD);
00190 
00191   LogDebug("SimpleBarrelNavigableLayer") << "is alongMomentum? " << (dir == alongMomentum) << endl
00192                                          << "isInOutTrackBarrel: " << isInOutTrackBarrel << endl
00193                                          << "isInOutTrackFWD: " << isInOutTrackFWD << endl
00194                                          << "dirOppositeXORisInOutTrackFWD: " << dirOppositeXORisInOutTrackFWD << endl
00195                                          << "dirOppositeXORisInOutTrackBarrel: "<< dirOppositeXORisInOutTrackBarrel << endl;
00196 
00197   bool signZmomentumXORdir = (( (fts.momentum().z() > 0) && !(dir == alongMomentum) ) ||
00198                               (!(fts.momentum().z() > 0) &&  (dir == alongMomentum) )   );
00199 
00200 
00201   if ( dirOppositeXORisInOutTrackBarrel &&  dirOppositeXORisInOutTrackFWD) {
00202 
00203     if ( signZmomentumXORdir   ) {
00204       wellInside( ftsWithoutErrors, dir, theNegOuterLayers, result);
00205     }
00206     else {
00207       wellInside( ftsWithoutErrors, dir, thePosOuterLayers, result);
00208     }
00209   } else if (!dirOppositeXORisInOutTrackBarrel &&  !dirOppositeXORisInOutTrackFWD){
00210     if ( signZmomentumXORdir ) {
00211       wellInside( ftsWithoutErrors, dir, thePosInnerLayers, result);
00212     }
00213     else {
00214       wellInside( ftsWithoutErrors, dir, theNegInnerLayers, result);
00215     }
00216   } else if (!dirOppositeXORisInOutTrackBarrel && dirOppositeXORisInOutTrackFWD){
00217     wellInside(ftsWithoutErrors, dir, theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(), result);        
00218 
00219     if (signZmomentumXORdir){   
00220       wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
00221       wellInside(ftsWithoutErrors, dir, theOuterLeftForwardLayers.begin(), theOuterLeftForwardLayers.end(), result);    
00222     }   else {
00223       wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
00224       wellInside(ftsWithoutErrors, dir, theOuterRightForwardLayers.begin(), theOuterRightForwardLayers.end(), result);
00225     }
00226   } else {
00227      if (signZmomentumXORdir){
00228         wellInside(ftsWithoutErrors, dir, theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(), result);
00229      } else {
00230         wellInside(ftsWithoutErrors, dir, theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(), result);
00231      }  
00232      wellInside(ftsWithoutErrors, dir, theOuterBarrelLayers.begin(), theOuterBarrelLayers.end(), result);       
00233   }
00234 
00235   bool goingIntoTheBarrel = (!isInOutTrackBarrel && dir==alongMomentum) || (isInOutTrackBarrel && dir==oppositeToMomentum) ;
00236 
00237   LogDebug("SimpleBarrelNavigableLayer") << "goingIntoTheBarrel: " << goingIntoTheBarrel;
00238 
00239 
00240   if (theSelfSearch && result.size()==0){
00241     if (!goingIntoTheBarrel){     LogDebug("SimpleBarrelNavigableLayer")<<" state is not going toward the center of the barrel. not adding self search.";}
00242     else{
00243       const BarrelDetLayer * bl = dynamic_cast<const BarrelDetLayer *>(detLayer());      unsigned int before=result.size();
00244       LogDebug("SimpleBarrelNavigableLayer")<<" I am trying to added myself as a next layer.";
00245       wellInside(ftsWithoutErrors, dir, bl, result);
00246       unsigned int after=result.size();
00247       if (before!=after)
00248         LogDebug("SimpleBarrelNavigableLayer")<<" I have added myself as a next layer.";
00249     }
00250   }
00251   
00252   return result;
00253 }
00254 
00255 
00256 vector<const DetLayer*> 
00257 SimpleBarrelNavigableLayer::compatibleLayers( NavigationDirection dir) const
00258 {
00259   if( !areAllReachableLayersSet ){
00260     edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
00261     throw DetLayerException("compatibleLayers() method used without all reachableLayers are set"); 
00262   }
00263 
00264   vector<const DetLayer*> result;
00265   if ( dir == insideOut) {
00266     for ( BDLC::const_iterator i=theAllOuterBarrelLayers.begin();
00267           i!=theAllOuterBarrelLayers.end(); i++) {
00268           result.push_back(*i);
00269     }
00270 //    result = theAllOuterBarrelLayers;
00271     for ( FDLC::const_iterator i=theAllOuterLeftForwardLayers.begin();
00272           i!=theAllOuterLeftForwardLayers.end(); i++) {
00273           // avoid duplication of barrel layers
00274           result.push_back(*i);
00275     }
00276     for ( FDLC::const_iterator i=theAllOuterRightForwardLayers.begin();
00277           i!=theAllOuterRightForwardLayers.end(); i++) {
00278           // avoid duplication of barrel layers
00279           result.push_back(*i);
00280     }
00281   }
00282   else {
00283     for ( BDLC::const_iterator i=theAllInnerBarrelLayers.begin();
00284           i!=theAllInnerBarrelLayers.end(); i++) {
00285           result.push_back(*i);
00286     }
00287     for ( FDLC::const_iterator i=theAllInnerLeftForwardLayers.begin();
00288           i!=theAllInnerLeftForwardLayers.end(); i++) {
00289           // avoid duplication of barrel layers
00290           result.push_back(*i);
00291     }
00292     for ( FDLC::const_iterator i=theAllInnerRightForwardLayers.begin();
00293           i!=theAllInnerRightForwardLayers.end(); i++) {
00294           // avoid duplication of barrel layers
00295           result.push_back(*i);
00296     }
00297 
00298    }
00299 
00300   return result;
00301 }
00302 
00303 vector<const DetLayer*> 
00304 SimpleBarrelNavigableLayer::compatibleLayers( const FreeTrajectoryState& fts, 
00305                                               PropagationDirection dir) const
00306 {
00307   if( !areAllReachableLayersSet ){
00308     int counter = 0;
00309     return SimpleNavigableLayer::compatibleLayers(fts,dir,counter);
00310     //    edm::LogError("TkNavigation") << "ERROR: compatibleLayers() method used without all reachableLayers are set" ;
00311     //    throw DetLayerException("compatibleLayers() method used without all reachableLayers are set"); 
00312   }
00313 
00314   vector<const DetLayer*> result;
00315   FreeTrajectoryState ftsWithoutErrors = (fts.hasError()) ?
00316   FreeTrajectoryState( fts.parameters()) : fts;
00317 
00318   //establish whether the tracks is crossing the tracker from outer layers to inner ones 
00319   //or from inner to outer.
00320   GlobalVector transversePosition(fts.position().x(), fts.position().y(), 0);
00321   //GlobalVector transverseMomentum(fts.momentum().x(), fts.momentum().y(), 0);
00322   //bool isInOutTrack  = (fts.position().basicVector().dot(fts.momentum().basicVector())>0) ? 1 : 0;
00323   bool isInOutTrack  = (transversePosition.dot(fts.momentum())>0) ? 1 : 0;
00324   //establish whether inner or outer layers are crossed after propagation, according
00325   //to BOTH propagationDirection AND track momentum
00326   bool dirOppositeXORisInOutTrack = ( !(dir == oppositeToMomentum) && isInOutTrack) || ((dir == oppositeToMomentum) && !isInOutTrack);
00327 
00328   vector<const DetLayer*> temp = dirOppositeXORisInOutTrack ? compatibleLayers(insideOut) : compatibleLayers(outsideIn);
00329   wellInside( ftsWithoutErrors, dir, temp, result);
00330 
00331   return result;
00332 
00333 }
00334 
00335 
00336 DetLayer* SimpleBarrelNavigableLayer::detLayer() const { return theDetLayer;}
00337 
00338 void   SimpleBarrelNavigableLayer::setDetLayer( DetLayer* dl) {
00339   cerr << "Warniong: SimpleBarrelNavigableLayer::setDetLayer called."
00340        << endl << "This should never happen!" << endl;
00341 }
00342 
00343 void SimpleBarrelNavigableLayer::setInwardLinks(const BDLC& theBarrelv, 
00344                                                 const FDLC& theForwardv,
00345                                                 TkLayerLess sorter)
00346 {
00347   theInnerBarrelLayers=theBarrelv;
00348   // sort the inner layers
00349   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(),sorter);
00350 
00351 
00352   ConstFDLI middle = find_if( theForwardv.begin(),theForwardv.end(),
00353                               not1(DetBelowZ(0)));
00354   theInnerLeftForwardLayers=FDLC(theForwardv.begin(),middle);
00355   theInnerRightForwardLayers=FDLC(middle,theForwardv.end());
00356 
00357   // sort the inner layers
00358   sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(),sorter);
00359   sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(),sorter);
00360 
00361 
00362 
00363   // put barrel and forward layers together
00364   theNegInnerLayers.reserve( theInnerBarrelLayers.size() + theInnerLeftForwardLayers.size());
00365   thePosInnerLayers.reserve( theInnerBarrelLayers.size() + theInnerRightForwardLayers.size());
00366 
00367   for (ConstBDLI bl=theInnerBarrelLayers.begin(); bl!=theInnerBarrelLayers.end(); bl++) 
00368     theNegInnerLayers.push_back( *bl);
00369   thePosInnerLayers = theNegInnerLayers; // barrel part the same
00370 
00371   for (ConstFDLI fl=theInnerLeftForwardLayers.begin(); fl!=theInnerLeftForwardLayers.end(); fl++) 
00372     theNegInnerLayers.push_back( *fl);
00373   for (ConstFDLI fl=theInnerRightForwardLayers.begin(); fl!=theInnerRightForwardLayers.end(); fl++) 
00374     thePosInnerLayers.push_back( *fl);
00375 
00376   // sort the inner layers 
00377   sort( theNegInnerLayers.begin(), theNegInnerLayers.end(), sorter);
00378   sort( thePosInnerLayers.begin(), thePosInnerLayers.end(), sorter);
00379   sort(theInnerBarrelLayers.begin(), theInnerBarrelLayers.end(),sorter);
00380   sort(theInnerLeftForwardLayers.begin(), theInnerLeftForwardLayers.end(),sorter);
00381   sort(theInnerRightForwardLayers.begin(), theInnerRightForwardLayers.end(),sorter);
00382 
00383 }
00384 
00385 void SimpleBarrelNavigableLayer::setAdditionalLink(DetLayer* additional, NavigationDirection direction){
00386   ForwardDetLayer* fadditional = dynamic_cast<ForwardDetLayer*>(additional);
00387   BarrelDetLayer*  badditional = dynamic_cast<BarrelDetLayer*>(additional);
00388   if (badditional){     
00389         if (direction==insideOut){
00390                 theAllOuterBarrelLayers.push_back(badditional);
00391                 theOuterBarrelLayers.push_back(badditional);
00392                 theNegOuterLayers.push_back(badditional);
00393                 thePosOuterLayers.push_back(badditional);
00394                 return; 
00395         }
00396         theAllInnerBarrelLayers.push_back(badditional);  
00397         theInnerBarrelLayers.push_back(badditional);
00398         theNegInnerLayers.push_back(badditional);
00399         thePosInnerLayers.push_back(badditional);       
00400         return;
00401   } else if (fadditional){
00402         double zpos = fadditional->position().z(); 
00403         if (direction==insideOut){
00404                 if (zpos>0){
00405                         theOuterRightForwardLayers.push_back(fadditional);
00406                         theAllOuterRightForwardLayers.push_back(fadditional);
00407                         thePosOuterLayers.push_back(fadditional);
00408                         return; 
00409                 }
00410                 theOuterLeftForwardLayers.push_back(fadditional);
00411                 theAllOuterLeftForwardLayers.push_back(fadditional);
00412                 theNegOuterLayers.push_back(fadditional);
00413                 return;
00414         }
00415         if (zpos>0){
00416                 theInnerRightForwardLayers.push_back(fadditional);
00417                 theAllInnerRightForwardLayers.push_back(fadditional);
00418                 thePosInnerLayers.push_back(fadditional);
00419                 return;
00420         }
00421         theInnerLeftForwardLayers.push_back(fadditional);
00422         theAllInnerLeftForwardLayers.push_back(fadditional);
00423         theNegInnerLayers.push_back(fadditional);
00424         return;
00425   }
00426   edm::LogError("TkNavigation") << "trying to add neither a ForwardDetLayer nor a BarrelDetLayer";      
00427   return;       
00428 }