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