CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:45:55 2009 for CMSSW by  doxygen 1.5.4