2   Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
 
    5 ///////////////////////////////////////////////////////////////////
 
    6 // ExtrapolationEngine.icc, (c) ATLAS Detector software
 
    7 ///////////////////////////////////////////////////////////////////
 
    9 #include "TrkSurfaces/Surface.h"
 
   10 #include "TrkVolumes/BoundarySurface.h"
 
   11 #include "TrkGeometry/TrackingGeometry.h"
 
   12 #include "TrkGeometry/TrackingVolume.h"
 
   13 #include "TrkGeometry/Layer.h"
 
   14 #include "TrkGeometry/MaterialLayer.h"
 
   15 #include "TrkExInterfaces/IPropagationEngine.h"
 
   16 #include "TrkExInterfaces/INavigationEngine.h"
 
   20 template <class T> Trk::ExtrapolationCode Trk::ExtrapolationEngine::extrapolateT(Trk::ExtrapolationCell<T>& eCell,
 
   21                                                                                  const Trk::Surface* sf,
 
   22                                                                                  Trk::PropDirection dir,
 
   23                                                                                  const Trk::BoundaryCheck& bcheck) const
 
   26     EX_MSG_DEBUG(eCell.navigationStep, "extrapolate", "", "starting extrapolation sequence."); 
 
   27     // initialize the navigation
 
   28     Trk::ExtrapolationCode eCode = initNavigation<T>(eCell,sf,dir);
 
   29     EX_MSG_VERBOSE(eCell.navigationStep, "extrapolate", "", "initialize navigation with return code : " << eCode.toString() );
 
   30     // main loop over volumes 
 
   31     while (eCell.leadVolume && eCode == Trk::ExtrapolationCode::InProgress ){
 
   32         // give output that you are in the master volume loop
 
   33         EX_MSG_VERBOSE(eCell.navigationStep, "extrapolate", "loop", "processing volume (signature) : " << eCell.leadVolume->volumeName() << " (" << eCell.leadVolume->geometrySignature() << ")");
 
   34         // get the appropriate IExtrapolationEngine
 
   35         Trk::GeometryType geoType = (eCell.leadVolume->geometrySignature()>2 and eCell.leadVolume->geometrySignature()!=Trk::HGTD) ? Trk::Dense : Trk::Static;
 
   36         const Trk::IExtrapolationEngine* iee = m_eeAccessor[geoType];
 
   37         eCode = iee ? iee->extrapolate(eCell, sf, bcheck) : Trk::ExtrapolationCode::FailureConfiguration;
 
   38         // give a message about what you have
 
   39         EX_MSG_VERBOSE(eCell.navigationStep, "extrapolate", "", "returned from volume with return code : " << eCode.toString() <<
 
   40       " and geoType:"<< geoType );
 
   42     EX_MSG_DEBUG(eCell.navigationStep, "extrapolate", "", "extrapolation finished with return code : " << eCode.toString() );
 
   43     // before you return, finalize: sets the leadParameters to endParameters and empties the garbage bin
 
   44     eCell.finalize(eCode);
 
   50 template <class T> Trk::ExtrapolationCode Trk::ExtrapolationEngine::initNavigation(Trk::ExtrapolationCell<T>& eCell,
 
   51                                                                                    const Trk::Surface* sf,
 
   52                                                                                    Trk::PropDirection dir) const
 
   54     // initialize the Navigation stream ----------------------------------------------------------------------------------------
 
   56     // this is the global initialization, it only associated direct objects
 
   57     // detailed navigation search needs to be done by the sub engines (since they know best)
 
   58     EX_MSG_DEBUG(++eCell.navigationStep, "navigation", "", "initialize the navigation stream."); 
 
   59     // initialization of the navigation requires that leadParameters to be the startParameters
 
   60     eCell.leadParameters = eCell.startParameters;
 
   61     // now check the tracking geometry and retrieve it if not existing
 
   62     const TrackingGeometry &tracking_geometry = trackingGeometry();
 
   63     // ---------- START initialization -----------------------------------------------------------------------------------------
 
   64     // initialize the start parameters - try association first
 
   65     eCell.startLayer  = eCell.startLayer ? eCell.startLayer : eCell.leadParameters->associatedSurface().associatedLayer();
 
   66     eCell.startVolume = eCell.startVolume ? eCell.startVolume :
 
   67         ( eCell.startLayer ? eCell.startLayer->enclosingTrackingVolume() : 0  );
 
   69     if (!eCell.startVolume ||  tracking_geometry.atVolumeBoundary(eCell.startParameters->position(),eCell.startVolume,0.001)  ) {
 
   70       Trk::ExtrapolationCode eVol = m_navigationEngine->resolvePosition(eCell,dir,true);  
 
   71       if (!eVol.isSuccessOrRecovered() && !eVol.inProgress()) return eVol; 
 
   72       eCell.startVolume = eCell.leadVolume;
 
   74       eCell.leadVolume = eCell.startVolume;
 
   76     // bail out of the start volume can not be resolved
 
   77     if (!eCell.startVolume) return Trk::ExtrapolationCode::FailureNavigation;
 
   79     EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "start volume termined as : " << eCell.startVolume->volumeName() );
 
   80     // check layer association
 
   81     eCell.startLayer     = eCell.startLayer ? eCell.startLayer : eCell.startVolume->associatedLayer(eCell.leadParameters->position());
 
   83        EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "start layer termined with index : " << eCell.startLayer->layerIndex());
 
   84     eCell.setRadialDirection();      
 
   85     // ---------- END initialization -----------------------------------------------------------------------------------------
 
   87       // keep track of the end surface    
 
   88       eCell.endSurface = sf;
 
   89       // re-evaluate the radial direction if the end surface is given
 
   90       // should not happen in FATRAS extrapolation mode
 
   91       if ( !eCell.checkConfigurationMode(Trk::ExtrapolationMode::FATRAS) )
 
   92           eCell.setRadialDirection();
 
   93       // trying association via the layer : associated layer of material layer 
 
   94       eCell.endLayer  =  sf->associatedLayer() ? sf->associatedLayer() : sf->materialLayer() ;
 
   95       eCell.endVolume = eCell.endLayer ? eCell.endLayer->enclosingTrackingVolume() : 0;
 
   96       // check if you found layer and volume
 
   97       if (!eCell.endVolume){
 
   98           EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "end volume needs to be determinded by surface intersection." );
 
   99           // use a propagation to find the endVolume and endLayer
 
  100           // - @TODO can be opmisied (straiht line for high momentum - use directly )
 
  101           Trk::ExtrapolationCell<T> navCell(*eCell.leadParameters, dir);
 
  102           navCell.addConfigurationMode(Trk::ExtrapolationMode::Direct);
 
  104           Trk::ExtrapolationCode eCode = m_propagationEngine->propagate(navCell,*eCell.endSurface,Trk::anyDirection,false,eCell.navigationCurvilinear);
 
  105           // check for sucess to the destination
 
  106           CHECK_ECODE_SUCCESS_NODEST(navCell, eCode);
 
  108           EX_MSG_VERBOSE (eCell.navigationStep, "navigation", "", "found endVolume and andLayer through propagation - return code : " << eCode.toString() );
 
  109           // take the lead parameters to find end volume and end layer
 
  110       eCell.endVolume = tracking_geometry.lowestTrackingVolume(navCell.endParameters->position());
 
  111       eCell.endLayer  = tracking_geometry.associatedLayer(navCell.endParameters->position());
 
  113           delete navCell.endParameters;
 
  115       // check the final end volume configuraiton - screen output
 
  117           EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "end volume termined as : " << eCell.endVolume->volumeName());
 
  119           EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "end layer termined with index : " << eCell.endLayer->layerIndex());
 
  121         EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "no destination surface nor end volume provided, extrapolaiton has to stop on other means." );
 
  122     // return the progress call
 
  123     return Trk::ExtrapolationCode::InProgress;