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 "TrkGeometry/MaterialLayer.h"
15 #include "TrkExInterfaces/IPropagationEngine.h"
16 #include "TrkExInterfaces/INavigationEngine.h"
17 #include <iostream>
18 #include <iomanip>
19 
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
24 {
25 
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 );
41  }
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);
45  // return the code
46  return eCode;
47 }
48 
49 
50 template <class T> Trk::ExtrapolationCode Trk::ExtrapolationEngine::initNavigation(Trk::ExtrapolationCell<T>& eCell,
51  const Trk::Surface* sf,
52  Trk::PropDirection dir) const
53 {
54  // initialize the Navigation stream ----------------------------------------------------------------------------------------
55  //
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 );
68 
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;
73  } else {
74  eCell.leadVolume = eCell.startVolume;
75  }
76  // bail out of the start volume can not be resolved
77  if (!eCell.startVolume) return Trk::ExtrapolationCode::FailureNavigation;
78  // screen output
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());
82  if (eCell.startLayer)
83  EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "start layer termined with index : " << eCell.startLayer->layerIndex());
84  eCell.setRadialDirection();
85  // ---------- END initialization -----------------------------------------------------------------------------------------
86  if (sf){
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);
103  // screen output
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);
107  // screen output
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());
112  // memory cleanup
113  delete navCell.endParameters;
114  }
115  // check the final end volume configuraiton - screen output
116  if (eCell.endVolume)
117  EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "end volume termined as : " << eCell.endVolume->volumeName());
118  if (eCell.endLayer)
119  EX_MSG_VERBOSE( eCell.navigationStep, "navigation", "", "end layer termined with index : " << eCell.endLayer->layerIndex());
120  } else
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;
124 
125 }
126 
127