TimedExtrapolator.cxx 112 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/

///////////////////////////////////////////////////////////////////
// TimedExtrapolator.cxx, (c) ATLAS Detector software
///////////////////////////////////////////////////////////////////

#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/PhysicalConstants.h"
// Trk include
#include "TrkExTools/TimedExtrapolator.h"
#include "TrkExInterfaces/IPropagator.h"
#include "TrkExInterfaces/IMultipleScatteringUpdator.h"
#include "TrkExInterfaces/IEnergyLossUpdator.h"
#include "TrkExUtils/IntersectionSolution.h"
#include "TrkSurfaces/SurfaceBounds.h"
#include "TrkSurfaces/DiscBounds.h"
#include "TrkSurfaces/PerigeeSurface.h"
#include "TrkSurfaces/StraightLineSurface.h"
#include "TrkSurfaces/CylinderSurface.h"
#include "TrkTrack/Track.h"
#include "TrkGeometry/DetachedTrackingVolume.h"
24
#include "TrkGeometry/AlignableTrackingVolume.h"
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "TrkGeometry/Layer.h"
#include "TrkGeometry/CompoundLayer.h"
#include "TrkGeometry/CylinderLayer.h"
#include "TrkGeometry/SubtractedCylinderLayer.h"
#include "TrkGeometry/TrackingGeometry.h"
#include "TrkGeometry/MaterialProperties.h"
#include "TrkVolumes/BoundarySurface.h"
#include "TrkVolumes/BoundarySurfaceFace.h"
#include "TrkVolumes/CylinderVolumeBounds.h"
#include "TrkVolumes/Volume.h"
#include "TrkParticleBase/TrackParticleBase.h"
#include "TrkEventUtils/TrkParametersComparisonFunction.h"
#include "TrkDetDescrInterfaces/IDynamicLayerCreator.h"
#include "TrkDetDescrUtils/SharedObject.h"
#include "TrkDetDescrUtils/GeometrySignature.h"
#include "TrkMaterialOnTrack/EnergyLoss.h"
#include "TrkMaterialOnTrack/ScatteringAngles.h"
#include "TrkParameters/TrackParameters.h"
#include "TrkGeometry/MagneticFieldProperties.h"
// for the comparison with a pointer
#include <stdint.h>

// Amg
#include "EventPrimitives/EventPrimitives.h"
#include "GeoPrimitives/GeoPrimitives.h"

// Trk
#include "TrkSurfaces/PlaneSurface.h"

Trk::ParticleMasses Trk::TimedExtrapolator::s_particleMasses;

// constructor
Trk::TimedExtrapolator::TimedExtrapolator(const std::string& t, const std::string& n, const IInterface* p) :
  AthAlgTool(t,n,p),
  m_propagators(),
  m_stepPropagator("Trk::STEP_Propagator/AtlasSTEP_Propagator"), 
  m_navigator("Trk::Navigator/AtlasNavigator"), 
  m_updators(),
  m_msupdators(),
  m_elossupdators(),
  //m_dynamicLayerCreator(),
  m_subPropagators(Trk::NumberOfSignatures),
  m_subUpdators(Trk::NumberOfSignatures),
  m_propNames(),
  m_updatNames(),
  m_meotpIndex(0),
  m_configurationLevel(10),
  m_searchLevel(10),
  m_includeMaterialEffects(true),
  m_requireMaterialDestinationHit(false),
  m_stopWithNavigationBreak(false),
  m_stopWithUpdateZero(false),
  m_subSurfaceLevel(true),
  m_skipInitialLayerUpdate(false),
  m_referenceMaterial(false),
  m_extendedLayerSearch(true), 
  m_initialLayerAttempts(3),
  m_successiveLayerAttempts(1),
  m_tolerance(0.002),  
84
  m_caloMsSecondary(false),  
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
  m_activeOverlap(false),
  m_useDenseVolumeDescription(true),
  m_useMuonMatApprox(false),
  m_checkForCompundLayers(false),
  m_destinationSurface(0),
  m_boundaryVolume(0),
  m_recall(false),
  m_recallSurface(0),
  m_recallLayer(0),
  m_recallTrackingVolume(0),
  m_hitVector(0),
  m_lastValidParameters(0),
  m_currentStatic(0),
  m_currentDense(0),
  m_highestVolume(0),
  m_resolveActive(false),
  m_resolveMultilayers(true),
  m_muonEntrance(0),
  m_returnPassiveLayers(false),
  m_robustSampling(true),
  m_path(PathLimit(0.,0)),
  m_methodSequence(0),
  m_maxMethodSequence(2000),
  m_printHelpOutputAtInitialize(false),
  m_printRzOutput(true),
  m_extrapolateCalls(0),
  m_extrapolateBlindlyCalls(0),
  m_extrapolateDirectlyCalls(0),
  m_extrapolateStepwiseCalls(0),
  m_startThroughAssociation(0),        
  m_startThroughRecall(0),         
  m_startThroughGlobalSearch(0),       
  m_destinationThroughAssociation(0),  
  m_destinationThroughRecall(0),       
  m_destinationThroughGlobalSearch(0), 
  m_layerSwitched(0),
  m_navigationStatistics(false),
  m_navigationBreakDetails(false),
  m_navigationBreakLoop(0),
  m_navigationBreakOscillation(0),
  m_navigationBreakNoVolume(0),
  m_navigationBreakDistIncrease(0),
  m_navigationBreakVolumeSignature(0),
  m_overlapSurfaceHit(0),
  m_materialEffectsOnTrackValidation(false),
  m_meotSearchCallsFw(0),
  m_meotSearchCallsBw(0),
  m_meotSearchSuccessfulFw(0),  
  m_meotSearchSuccessfulBw(0),
  m_lastMaterialLayer(0),
  m_cacheLastMatLayer(false),
  m_particleMass(0.),
  m_fastField(false)
{
      declareInterface<ITimedExtrapolator>(this);
      
      // extrapolation steering
      declareProperty("StopWithNavigationBreak",        m_stopWithNavigationBreak);
      declareProperty("StopWithUpdateKill",             m_stopWithUpdateZero);      
      declareProperty("SkipInitialPostUpdate",          m_skipInitialLayerUpdate);
      declareProperty("MaximalMethodSequence",          m_maxMethodSequence);       
      // propagation steering
      declareProperty("Propagators",                    m_propagators);
      declareProperty("SubPropagators",                 m_propNames);
      declareProperty("STEP_Propagator",                m_stepPropagator);
      // material effects handling
      declareProperty("ApplyMaterialEffects",           m_includeMaterialEffects);      
      declareProperty("RequireMaterialDestinationHit",  m_requireMaterialDestinationHit);
      declareProperty("MaterialEffectsUpdators",        m_updators);  
      declareProperty("MultipleScatteringUpdators",     m_msupdators);  
      declareProperty("EnergyLossUpdators",             m_elossupdators);  
      declareProperty("SubMEUpdators",                  m_updatNames);  
      declareProperty("CacheLastMaterialLayer",         m_cacheLastMatLayer);
      // general behavior navigation      
      declareProperty("SearchLevelClosestParameters",   m_searchLevel);
      declareProperty("Navigator",                      m_navigator);
      declareProperty("UseDenseVolumeDescription",      m_useDenseVolumeDescription);
      // muon system specifics            
      declareProperty("UseMuonMatApproximation",        m_useMuonMatApprox);
      declareProperty("CheckForCompoundLayers",         m_checkForCompundLayers);
      declareProperty("ResolveMuonStation",             m_resolveActive);
      declareProperty("ResolveMultilayers",             m_resolveMultilayers);
      declareProperty("ConsiderMuonStationOverlaps",    m_activeOverlap);  
      //declareProperty("DynamicLayerCreator",          m_dynamicLayerCreator);  
      declareProperty("RobustSampling",                 m_robustSampling);  
      // material & navigation related steering
      declareProperty("MaterialEffectsOnTrackProviderIndex" , m_meotpIndex);  
      declareProperty("MaterialEffectsOnTrackValidation"    , m_materialEffectsOnTrackValidation);
      declareProperty("ReferenceMaterial"                   , m_referenceMaterial);
      declareProperty("ExtendedLayerSearch"                 , m_extendedLayerSearch);
      declareProperty("InitialLayerAttempts"                , m_initialLayerAttempts);
      declareProperty("SuccessiveLayerAttempts"             , m_successiveLayerAttempts);
      // debug and validation
      declareProperty("HelpOutput",                     m_printHelpOutputAtInitialize);
      declareProperty("positionOutput",                 m_printRzOutput);
      declareProperty("NavigationStatisticsOutput",     m_navigationStatistics);
      declareProperty("DetailedNavigationOutput",       m_navigationBreakDetails);
      declareProperty("Tolerance",                      m_tolerance);
      declareProperty("CaloMsSecondary",                m_caloMsSecondary);
      //Magnetic field properties
      declareProperty("MagneticFieldProperties",	m_fastField);  
}

// destructor
Trk::TimedExtrapolator::~TimedExtrapolator()
{}

// Athena standard methods
// initialize
StatusCode Trk::TimedExtrapolator::initialize()
{   
    m_fieldProperties = m_fastField ? Trk::MagneticFieldProperties(Trk::FastField) : Trk::MagneticFieldProperties(Trk::FullField);
    if(m_propagators.size() == 0) m_propagators.push_back("Trk::RungeKuttaPropagator/DefaultPropagator");
    if(m_updators.size() == 0) m_updators.push_back("Trk::MaterialEffectsUpdator/DefaultMaterialEffectsUpdator");
    if(m_msupdators.size() == 0) m_msupdators.push_back("Trk::MultipleScatteringUpdator/AtlasMultipleScatteringUpdator");
    if(m_elossupdators.size() == 0) m_elossupdators.push_back("Trk::EnergyLossUpdator/AtlasEnergyLossUpdator");
    
    if (m_propagators.size()) {
      if ( m_propagators.retrieve().isFailure() ) {
        ATH_MSG_FATAL( "Failed to retrieve tool " << m_propagators );
        return StatusCode::FAILURE;
      } else 
        ATH_MSG_INFO( "Retrieved tools " << m_propagators );      
    }

     
     // from the number of retrieved propagators set the configurationLevel
     unsigned int validprop = m_propagators.size();
     
     if (!validprop){
        ATH_MSG_WARNING( "None of the defined propagators could be retrieved!" );
        ATH_MSG_WARNING( "  Extrapolators jumps back in unconfigured mode, only strategy pattern methods can be used." ); 
      } else {
        m_configurationLevel = validprop - 1;
        ATH_MSG_VERBOSE( "Configuration level automatically set to " << m_configurationLevel );        
      }
    
    // Get the Navigation AlgTools
    if ( m_navigator.retrieve().isFailure() ) {
      ATH_MSG_FATAL( "Failed to retrieve tool " << m_navigator );
      return StatusCode::FAILURE;
    } else {
      ATH_MSG_INFO( "Retrieved tool " << m_navigator );
    }
    // Get the Material Updator
    if (m_includeMaterialEffects && m_updators.size()){
      if ( m_updators.retrieve().isFailure() ) {
        ATH_MSG_FATAL( "None of the defined material updatros could be retrieved!" );
        ATH_MSG_FATAL( "No multiple scattering and energy loss material update will be done."        );
        return StatusCode::FAILURE;
      } else 
        ATH_MSG_INFO( "Retrieved tools: " << m_updators );
    }

    // from the number of retrieved propagators set the configurationLevel
    unsigned int validmeuts = m_updators.size();
   
    // -----------------------------------------------------------
    // Sanity check 1
    
    if (!m_propNames.size() && m_propagators.size()){
       ATH_MSG_DEBUG( "Inconsistent setup of Extrapolator, no sub-propagators configured, doing it for you. " );
       m_propNames.push_back(m_propagators[0]->name().substr( 8, m_propagators[0]->name().size()-8 ));
    }
    
    if (!m_updatNames.size() && m_updators.size()){
       ATH_MSG_DEBUG( "Inconsistent setup of Extrapolator, no sub-materialupdators configured, doing it for you. " );
       m_updatNames.push_back(m_updators[0]->name().substr( 8, m_updators[0]->name().size()-8 ));
    }

    // -----------------------------------------------------------
    // Sanity check 2
    // fill the number of propagator names and updator names up with first one
    while ( int(m_propNames.size()) < int(Trk::NumberOfSignatures)) 
         m_propNames.push_back(m_propNames[0]); 
    while  (int(m_updatNames.size()) < int(Trk::NumberOfSignatures)) 
         m_updatNames.push_back(m_updatNames[0]); 
    if (validprop && validmeuts){
      // Per definition: if configured not found, take the lowest one
      for (unsigned int isign=0; int(isign) < int(Trk::NumberOfSignatures); ++isign){
                unsigned int index = 0;
           
          for (unsigned int iProp = 0; iProp < m_propagators.size(); iProp++) {
                 std::string pname = m_propagators[iProp]->name().substr( 8, m_propagators[iProp]->name().size()-8 );
            if ( m_propNames[isign] == pname ) index = iProp; 
              }
             ATH_MSG_DEBUG( " subPropagator:" << isign << " pointing to propagator: "<< m_propagators[index]->name() );
             m_subPropagators[isign] =  ( index < validprop ) ? &(*m_propagators[index]) : &(*m_propagators[Trk::Global]);     

          index = 0; 
          for (unsigned int iUp = 0; iUp < m_updators.size(); iUp++) {
          std::string uname = m_updators[iUp]->name().substr( 8, m_updators[iUp]->name().size()-8 );
          if ( m_updatNames[isign] == uname ) index = iUp; 
             }
            ATH_MSG_DEBUG( " subMEUpdator:" << isign << " pointing to updator: "<< m_updators[index]->name() );
            m_subUpdators[isign] =  ( index < validmeuts ) ? &(*m_updators[index]) : &(*m_updators[Trk::Global]);     
     }
   } else {
      ATH_MSG_FATAL( "Configuration Problem of Extrapolator: "                        
          << "  -- At least one IPropagator and IMaterialUpdator instance have to be given.! " );
   
   }
            
    /*
    // Get the DynamicLayerCreator
    if(m_doMuonDynamic && m_dynamicLayerCreator){
      if ( m_dynamicLayerCreator.retrieve().isFailure() ) {
        ATH_MSG_ERROR( "Failed to retrieve tool " << m_dynamicLayerCreator 
            << "No multiple scattering and energy loss material update will be done." );
        return StatusCode::SUCCESS;
      } else 
        ATH_MSG_DEBUG( "Retrieved tool " << m_dynamicLayerCreator );      
    }
    */

    m_maxNavigSurf = 1000;
    m_navigSurfs.reserve(m_maxNavigSurf); 
    m_maxNavigVol = 50;
    m_navigVols.reserve(m_maxNavigVol); 
    m_navigVolsInt.reserve(m_maxNavigVol); 

       
    ATH_MSG_INFO("initialize() successful" );    
    return StatusCode::SUCCESS;
}

// finalize
StatusCode Trk::TimedExtrapolator::finalize()
{
  ATH_MSG_INFO( "finalize() successful" );
  return StatusCode::SUCCESS;
}



const Trk::TrackParameters*  Trk::TimedExtrapolator::extrapolateWithPathLimit(
									 const Trk::TrackParameters& parm,
									 Trk::PathLimit& pathLim, Trk::TimeLimit& timeLim,
									 Trk::PropDirection dir,
									 Trk::ParticleHypothesis particle,
									 std::vector<Trk::HitInfo>*& hitInfo,
                                                                         Trk::GeometrySignature& nextGeoID,  
									 const Trk::TrackingVolume* boundaryVol) const
{
// extrapolation method intended for simulation of particle decay; collects intersections with active layers
// possible outcomes:1/ returns curvilinear parameters after reaching the maximal path
//                   2/ returns parameters at destination volume boundary 
//                   3/ returns 0 ( particle stopped ) but keeps vector of hits    

  ATH_MSG_DEBUG( "M-[" << ++m_methodSequence << "] extrapolateWithPathLimit(...) " << pathLim.x0Max << ", from " << parm.position());
  ATH_MSG_DEBUG( "M-[" << ++m_methodSequence << "] extrapolateWithPathLimit(...): resolve active layers? " << m_resolveActive);
 
  if (!m_stepPropagator) {
    // Get the STEP_Propagator AlgTool
    if ( m_stepPropagator.retrieve().isFailure() ) {
      ATH_MSG_ERROR( "Failed to retrieve tool " << m_stepPropagator );
      ATH_MSG_ERROR("Configure STEP Propagator for extrapolation with path limit");
      return 0;
    } else {
      ATH_MSG_INFO( "Retrieved tool " << m_stepPropagator );
    }
  }

  // reset the path ( in x0 !!) 
  m_path = PathLimit( pathLim.x0Max - pathLim.x0Collected, pathLim.process);     // collect material locally

  // initialize hit vector
  m_hitVector = hitInfo;
 
  // if no input volume, define as highest volume
  //const Trk::TrackingVolume* destVolume = boundaryVol ? boundaryVol : m_navigator->highestVolume();
  m_currentStatic = 0;
  if (boundaryVol && !boundaryVol->inside(parm.position(),m_tolerance) ) return 0;
   
  // extrapolate to destination volume boundary with path limit
  const Trk::TrackParameters* returnParms = extrapolateToVolumeWithPathLimit( parm, timeLim, dir,particle, nextGeoID, boundaryVol);

  //save actual path on output  
  if (m_path.x0Collected>0.)  pathLim.updateMat(m_path.x0Collected, m_path.weightedZ/m_path.x0Collected, m_path.l0Collected);
   
  return returnParms;
} 
   
const Trk::TrackParameters*  Trk::TimedExtrapolator::extrapolateToVolumeWithPathLimit(
									 const Trk::TrackParameters& parm,
									 Trk::TimeLimit& timeLim,
									 Trk::PropDirection dir,
									 Trk::ParticleHypothesis particle,
                                                                         Trk::GeometrySignature& nextGeoID,
									 const Trk::TrackingVolume* destVol) const
{ 
  // returns:
  //    A)  curvilinear track parameters if path limit reached 
  //    B)  boundary parameters (at destination volume boundary)

  // initialize the return parameters vector
  const Trk::TrackParameters* returnParameters = 0;
  const Trk::TrackParameters* currPar = &parm;
  const Trk::TrackingVolume*  currVol = 0;
  const Trk::TrackingVolume*  nextVol = 0;
  std::vector<unsigned int> solutions;
  const Trk::TrackingVolume* assocVol = 0;  
  unsigned int               iDest = 0;
  
  // destination volume boundary ? 
  if ( destVol && m_navigator->atVolumeBoundary(currPar,destVol,dir,nextVol,m_tolerance) && nextVol != destVol ) { return &parm; }
  
  bool resolveActive = true;
  if ( m_lastMaterialLayer && !m_lastMaterialLayer->isOnLayer(parm.position()) ) m_lastMaterialLayer = 0;  
  if (!m_highestVolume ) m_highestVolume = m_navigator->highestVolume();

  emptyGarbageBin(&parm);
  // navigation surfaces
  if( m_navigSurfs.capacity() > m_maxNavigSurf ) m_navigSurfs.reserve(m_maxNavigSurf); 
  m_navigSurfs.clear();

  // target volume may not be part of tracking geometry 
  if (destVol) { 
    const Trk::TrackingVolume* tgVol =  m_navigator->trackingGeometry()->trackingVolume(destVol->volumeName());
    if (!tgVol || tgVol!=destVol) {
      const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds = destVol->boundarySurfaces();
      for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	m_navigSurfs.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
      }
      iDest = bounds.size();
    }		   
  }
    
  // resolve current position
  bool updateStatic = false;
  Amg::Vector3D gp = parm.position();
  if ( !m_currentStatic || !m_currentStatic->inside(gp,m_tolerance) ) {
    m_currentStatic =  m_navigator->trackingGeometry()->lowestStaticTrackingVolume(gp);   
    updateStatic = true; 
  }
  if ( m_navigator->atVolumeBoundary(currPar,m_currentStatic,dir,nextVol,m_tolerance) && nextVol != m_currentStatic ) {
    // no next volume found --- end of the world
    if ( !nextVol ) {
      ATH_MSG_DEBUG( "  [+] Word boundary reached        - at " << positionOutput(currPar->position()) );
      nextGeoID = Trk::GeometrySignature(Trk::Unsigned);
      return currPar;
    }
    m_currentStatic = nextVol;
    updateStatic = true;
  }

  // current frame volume known-retrieve geoID
  nextGeoID = m_currentStatic->geometrySignature(); 

435
436
437
438
439
440
441
442
  // resolve active Calo volumes if hit info required 
  if ( m_hitVector && nextGeoID==Trk::Calo ) {
    const Trk::AlignableTrackingVolume* alignTV = dynamic_cast<const Trk::AlignableTrackingVolume*> (m_currentStatic);
    if (alignTV) {
      return extrapolateInAlignableTV(*currPar,timeLim,dir,particle,nextGeoID,alignTV).trPar;
    }
  }

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
  // update if new static volume
  if ( updateStatic ) {    // retrieve boundaries
    m_staticBoundaries.clear();
    const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds = m_currentStatic->boundarySurfaces();
    for (unsigned int ib=0; ib< bounds.size(); ib++ ){
      const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
      m_staticBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
    }

    m_detachedVols.clear();
    m_detachedBoundaries.clear();
    m_denseVols.clear();
    m_denseBoundaries.clear();
    m_layers.clear();
    m_navigLays.clear();

    // new: ID volumes may have special material layers ( entry layers ) - add them here
460
461
462
463
464
465
466
467
468
469
470
    //if (m_currentStatic->entryLayerProvider()) {
    //  const std::vector<const Trk::Layer*>& entryLays = m_currentStatic->entryLayerProvider()->layers();
    //  for (unsigned int i=0; i < entryLays.size(); i++) { 
    //	if (entryLays[i]->layerType()>0 || entryLays[i]->layerMaterialProperties()) {
    //	  m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(entryLays[i]->surfaceRepresentation()),true));
    //	  m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,entryLays[i]) );
    //	  Trk::DistanceSolution distSol = m_layers.back().first->straightLineDistanceEstimate(currPar->position(),
    //                                                                                        currPar->momentum().normalized());
    //	}
    // } 
    //}
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

    // detached volume boundaries
    const std::vector<const Trk::DetachedTrackingVolume*>* detVols = m_currentStatic->confinedDetachedVolumes();
    if (detVols) {
      std::vector<const Trk::DetachedTrackingVolume*>::const_iterator iTer = detVols->begin();
      for (; iTer != detVols->end(); iTer++) { 
        // active station ?
        const Trk::Layer* layR = (*iTer)->layerRepresentation();
        bool active = ( layR && layR->layerType() ) ? true : false;
	const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > >  detBounds=(*iTer)->trackingVolume()->boundarySurfaces();
        if (active) {
	  m_detachedVols.push_back(std::pair<const Trk::DetachedTrackingVolume*,unsigned int> (*iTer,detBounds.size()) );
	  for (unsigned int ibb=0; ibb< detBounds.size(); ibb++ ){
	    const Trk::Surface& surf = (detBounds[ibb].getPtr())->surfaceRepresentation();
	    m_detachedBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	  }	  
	} else if (m_currentStatic->geometrySignature()!=Trk::MS ||
		   !m_useMuonMatApprox || (*iTer)->name().substr((*iTer)->name().size()-4,4)=="PERM" ) {  // retrieve inert detached objects only if needed
          if ((*iTer)->trackingVolume()->zOverAtimesRho()!=0. && 
	      (!(*iTer)->trackingVolume()->confinedDenseVolumes() || !(*iTer)->trackingVolume()->confinedDenseVolumes()->size() )
	      && ( !(*iTer)->trackingVolume()->confinedArbitraryLayers() ||
                   !(*iTer)->trackingVolume()->confinedArbitraryLayers()->size() ) ) {
            m_denseVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> 
				  ((*iTer)->trackingVolume(),detBounds.size() ) );
	    for (unsigned int ibb=0; ibb< detBounds.size(); ibb++ ){
	      const Trk::Surface& surf = (detBounds[ibb].getPtr())->surfaceRepresentation();
	      m_denseBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	    }
	  } 
          const std::vector<const Trk::Layer*>* confLays = (*iTer)->trackingVolume()->confinedArbitraryLayers(); 
	  if ( (*iTer)->trackingVolume()->confinedDenseVolumes() || (confLays && confLays->size()> detBounds.size()) ) {
            m_detachedVols.push_back(std::pair<const Trk::DetachedTrackingVolume*,unsigned int>(*iTer,detBounds.size()));
	    for (unsigned int ibb=0; ibb< detBounds.size(); ibb++ ){
	      const Trk::Surface& surf = (detBounds[ibb].getPtr())->surfaceRepresentation();
	      m_detachedBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	    }
          } else if ( confLays ) {
	    std::vector<const Trk::Layer*>::const_iterator lIt = confLays->begin();
	    for ( ; lIt!= confLays->end(); lIt++ ){
	      m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&((*lIt)->surfaceRepresentation()),true) );
	      m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> ((*iTer)->trackingVolume(),*lIt) );
	    }            
	  }         
	}
      }
    }
    m_denseResolved    = std::pair<unsigned int,unsigned int> (m_denseVols.size(), m_denseBoundaries.size());
    m_layerResolved    = m_layers.size();
  } 

  m_navigSurfs.insert(m_navigSurfs.end(),m_staticBoundaries.begin(),m_staticBoundaries.end());

  // resolve the use of dense volumes
  m_dense = (m_currentStatic->geometrySignature()==Trk::MS && m_useMuonMatApprox ) || (m_currentStatic->geometrySignature()!=Trk::MS && m_useDenseVolumeDescription );

  // reset remaining counters
  m_currentDense = m_dense ?  m_currentStatic : m_highestVolume;
  m_navigBoundaries.clear(); 
529
530
531
532
  if (m_denseVols.size()>m_denseResolved.first) m_denseVols.resize(m_denseResolved.first);
  while (m_denseBoundaries.size()>m_denseResolved.second) m_denseBoundaries.pop_back();
  if (m_layers.size()>m_layerResolved) m_navigLays.resize(m_layerResolved);
  while (m_layers.size()>m_layerResolved)  m_layers.pop_back();
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669

  // current detached volumes
  // collect : subvolume boundaries, ordered/unordered layers, confined dense volumes
  ////////////////////////////////////////////////////// 
  // const Trk::DetachedTrackingVolume* currentActive = 0;
  std::vector<std::pair<const Trk::TrackingVolume*,unsigned int> > navigVols;
   
  gp = currPar->position();    
  std::vector<const Trk::DetachedTrackingVolume*>* detVols =  m_navigator->trackingGeometry()->lowestDetachedTrackingVolumes(gp);    
  std::vector<const Trk::DetachedTrackingVolume*>::iterator dIter = detVols->begin();
  for (; dIter != detVols->end(); dIter++) {
    const Trk::Layer* layR = (*dIter)->layerRepresentation();
    bool active = ( layR && layR->layerType() ) ? true : false;
    if (active && !resolveActive) continue; 
    if (!active && m_currentStatic->geometrySignature()==Trk::MS && 
	m_useMuonMatApprox && (*dIter)->name().substr((*dIter)->name().size()-4,4)!="PERM") continue;
    const Trk::TrackingVolume* dVol = (*dIter)->trackingVolume();
    // detached volume exit ?
    bool dExit =  m_navigator->atVolumeBoundary(currPar,dVol,dir,nextVol,m_tolerance) && !nextVol;
    if (dExit) continue;
    // inert material 
    const std::vector<const Trk::TrackingVolume*>* confinedDense = dVol->confinedDenseVolumes();
    const std::vector<const Trk::Layer*>*          confinedLays  = dVol->confinedArbitraryLayers();
    
    if (!active && !confinedDense && !confinedLays) continue; 
    const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds=dVol->boundarySurfaces();
    if (!active && !confinedDense && confinedLays->size()<= bounds.size()) continue;
    if (confinedDense || confinedLays ) {
      navigVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> (dVol,bounds.size()) );
      for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	m_navigBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
      }
      // collect dense volume boundary
      if (confinedDense) {
	std::vector<const Trk::TrackingVolume*>::const_iterator vIter = confinedDense->begin();
	for (; vIter != confinedDense->end(); vIter++) {
	  const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds=
	    (*vIter)->boundarySurfaces();
	  m_denseVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> (*vIter,bounds.size()) );
	  for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	    const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	    m_denseBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	  }
	}
      }
      // collect unordered layers
      if (confinedLays) {
	for (unsigned int il = 0; il < confinedLays->size(); il++) {
	  m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&((*confinedLays)[il]->surfaceRepresentation()),true));   
	  m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (dVol,(*confinedLays)[il]) );
	}    
      }
    } else {   // active material
      const Trk::TrackingVolume* detVol= dVol->associatedSubVolume(gp);
      if ( !detVol && dVol->confinedVolumes()) {
	std::vector<const Trk::TrackingVolume*> subvols = dVol->confinedVolumes()->arrayObjects();
	for (unsigned int iv=0;iv<subvols.size();iv++) {
	  if ( subvols[iv]->inside(gp,m_tolerance) ) {
	    detVol = subvols[iv]; 
	    break;
	  }
	}
      }
      
      if (!detVol) detVol = dVol;
      bool vExit =  m_navigator->atVolumeBoundary(currPar,detVol,dir,nextVol,m_tolerance) && nextVol!=detVol;
      if ( vExit && nextVol && nextVol->inside(gp,m_tolerance)) { detVol = nextVol; vExit = false; } 
      if ( !vExit ) {
	const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds= detVol->boundarySurfaces();
	navigVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> (detVol,bounds.size()) );
	for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	  const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	  m_navigBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	}
	if ( detVol->zOverAtimesRho() != 0.) {
	  m_denseVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> (detVol,bounds.size()) );
	  for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	    const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	    m_denseBoundaries.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&surf,true));
	  }
	} 
	// layers ?
	if ( detVol->confinedLayers() ) {         
          if (m_robustSampling || m_currentStatic->geometrySignature()==Trk::MS) {
	    std::vector<const Trk::Layer*> cLays = detVol->confinedLayers()->arrayObjects();
	    for (unsigned int i=0; i < cLays.size(); i++) { 
	      if (cLays[i]->layerType()>0 || cLays[i]->layerMaterialProperties()) {
		m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(cLays[i]->surfaceRepresentation()),true));
		m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,cLays[i]) );
	      }
	    }            
	  } else { 
	    const Trk::Layer* lay = detVol->associatedLayer(gp);
	    //if (lay && ( (*dIter)->layerRepresentation()
	    //		 &&(*dIter)->layerRepresentation()->layerType()>0 ) ) currentActive=(*dIter);  
	    if (lay) {
	      m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(lay->surfaceRepresentation()),true));
	      m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (detVol,lay) );
	    }
	    const Trk::Layer* nextLayer = detVol->nextLayer(currPar->position(),dir*currPar->momentum().normalized(),true);      
	    if (nextLayer && nextLayer != lay ) {
	      m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(nextLayer->surfaceRepresentation()),true));
	      m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (detVol,nextLayer) );
	    }
	  }
	} else if ( detVol->confinedArbitraryLayers() ) {
	  const std::vector<const Trk::Layer*>* layers = detVol->confinedArbitraryLayers();
	  for (unsigned int il = 0; il < layers->size(); il++) {
	    m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&((*layers)[il]->surfaceRepresentation()),true));   
	    m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (detVol,(*layers)[il]) );
	  }    
	}
      }
    }
  }
  delete detVols;    

  // confined layers
  if ( m_currentStatic->confinedLayers() && updateStatic ) {
    //if ( m_currentStatic->confinedLayers() ) {
    if (m_robustSampling || m_currentStatic->geometrySignature()==Trk::MS) {
      std::vector<const Trk::Layer*> cLays = m_currentStatic->confinedLayers()->arrayObjects();
      for (unsigned int i=0; i < cLays.size(); i++) { 
	if (cLays[i]->layerType()>0 || cLays[i]->layerMaterialProperties()) {
	  m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(cLays[i]->surfaceRepresentation()),true));
	  m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,cLays[i]) );
	}
      }
    } else { 
      //* this does not work - debug !
      const Trk::Layer* lay = m_currentStatic->associatedLayer(gp);       
      //if (!lay) {
      //  lay = m_currentStatic->associatedLayer(gp+m_tolerance*parm.momentum().normalized());
      //	std::cout<<" find input associated layer, second attempt:"<< lay<< std::endl;
      //} 
      if (lay) {
670
	m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(lay->surfaceRepresentation()),Trk::BoundaryCheck(false)));
671
672
673
	m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,lay) );
	const Trk::Layer* nextLayer = lay->nextLayer(currPar->position(),dir*currPar->momentum().normalized());      
	if (nextLayer && nextLayer != lay ) {
674
	  m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(nextLayer->surfaceRepresentation()),Trk::BoundaryCheck(false)));
675
676
677
678
	  m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,nextLayer) );
	}
	const Trk::Layer* backLayer = lay->nextLayer(currPar->position(),-dir*currPar->momentum().normalized());      
	if (backLayer && backLayer != lay ) {
679
	  m_layers.push_back(std::pair<const Trk::Surface*,Trk::BoundaryCheck>(&(backLayer->surfaceRepresentation()),Trk::BoundaryCheck(false)));
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
	  m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,backLayer) );
	}
      }
    }
  }
   
  // m_navigSurfs contains destination surface (if it exists), static volume boundaries  
  // complete with TG m_layers/dynamic layers, m_denseBoundaries, m_navigBoundaries, m_detachedBoundaries

  if (m_layers.size()) m_navigSurfs.insert(m_navigSurfs.end(),m_layers.begin(),m_layers.end());
  if (m_denseBoundaries.size()) m_navigSurfs.insert(m_navigSurfs.end(),m_denseBoundaries.begin(),m_denseBoundaries.end());
  if (m_navigBoundaries.size()) m_navigSurfs.insert(m_navigSurfs.end(),m_navigBoundaries.begin(),m_navigBoundaries.end());
  if (m_detachedBoundaries.size()) m_navigSurfs.insert(m_navigSurfs.end(),m_detachedBoundaries.begin(),m_detachedBoundaries.end());


  // current dense
  m_currentDense =  m_highestVolume;
  if (m_dense && !m_denseVols.size()) m_currentDense = m_currentStatic;
  else {
    for (unsigned int i=0;i<m_denseVols.size(); i++) {
      const Trk::TrackingVolume* dVol = m_denseVols[i].first;
      if ( dVol->inside(currPar->position(),m_tolerance)  && dVol->zOverAtimesRho()!=0. ) {
	if ( !m_navigator->atVolumeBoundary(currPar,dVol,dir,nextVol,m_tolerance) || nextVol == dVol ) m_currentDense = dVol;
      } 
    }
  }

  // before propagation, loop over layers and collect hits 
  if (m_hitVector) {

    for (unsigned int i=0; i<m_navigLays.size(); i++) {

      if (m_navigLays[i].second->layerType()>0 && m_navigLays[i].second->isOnLayer(currPar->position()) ) {
	if (m_navigLays[i].second->surfaceArray()) {
	  // perform the overlap Search on this layer
	  ATH_MSG_VERBOSE( "  [o] Calling overlapSearch() on input layer.");	
	  overlapSearch(*m_subPropagators[0],*currPar,*currPar,*m_navigLays[i].second,timeLim.time,dir,true,particle);       	   
	} else {
	  ATH_MSG_VERBOSE( "  [o] Collecting intersection with active input layer.");	
          m_hitVector->push_back(Trk::HitInfo(currPar->clone(),timeLim.time,m_navigLays[i].second->layerType(),0.));
	}
      } // ------------------------------------------------- Fatras mode off -----------------------------------

    }

  }
  
  // ready to propagate      
  // till: A/ static volume boundary(bcheck=true) , B/ material layer(bcheck=true), C/ destination surface(bcheck=false)
  // update of m_navigSurfs required if I/ entry into new navig volume, II/ exit from currentActive without overlaps
   
   nextVol = 0;
   while (currPar) {      
     std::vector<unsigned int> solutions;
     //double time_backup = timeLim.time;
     //double path_backup = m_path.x0Collected;
     ATH_MSG_DEBUG( "  [+] Starting propagation at position  " << positionOutput(currPar->position())  
		    << " (current momentum: " << currPar->momentum().mag() << ")" ); 
     ATH_MSG_DEBUG( "  [+] " << m_navigSurfs.size() << " target surfaces in '" << m_currentDense->volumeName() <<"'.");      // verify that material input makes sense
     if (!(m_currentDense->inside(currPar->position(),m_tolerance) 
	   || m_navigator->atVolumeBoundary(currPar,m_currentDense,dir,assocVol,m_tolerance) ) ) m_currentDense = m_highestVolume ;
     //const Trk::TrackParameters* nextPar = m_stepPropagator->propagateT(*currPar,m_navigSurfs,dir,*m_currentDense,particle,solutions,m_path,timeLim,true);
742
     const Trk::TrackParameters* nextPar = m_stepPropagator->propagateT(*currPar,m_navigSurfs,dir,m_fieldProperties,particle,solutions,m_path,timeLim,true,m_currentDense,m_hitVector);
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
     ATH_MSG_VERBOSE( "  [+] Propagation done. " );
     if (nextPar)  
       ATH_MSG_DEBUG( "  [+] Position after propagation -   at " << positionOutput(nextPar->position())<<", timed at " << timeLim.time); 

     if (!nextPar) {
       ATH_MSG_DEBUG( "  [!] Propagation failed, return 0" );
       m_parametersAtBoundary.boundaryInformation(m_currentStatic,nextPar,nextPar);     
       return returnParameters;
     }

     throwIntoGarbageBin(nextPar);         

     // material update has been done already by the propagator
     if ( m_path.x0Max>0. && ( (m_path.process<100 && m_path.x0Collected >= m_path.x0Max) || (m_path.process>100 && m_path.l0Collected >= m_path.x0Max)) ) {

       // trigger presampled interaction, provide material properties if needed 
       // process interaction only if creation of secondaries allowed
       if ( m_currentStatic->geometrySignature()==Trk::ID || m_caloMsSecondary ) {
	 const Trk::Material* extMprop = m_path.process>100 ? m_currentDense : 0;
       
	 const Trk::TrackParameters* iPar = m_updators[0]->interact(timeLim.time,nextPar->position(),nextPar->momentum(),particle,m_path.process,extMprop);
   
	 if (!iPar) return returnParameters;
  
	 throwIntoGarbageBin(iPar);         
	 return extrapolateToVolumeWithPathLimit(*iPar,timeLim,dir,particle,nextGeoID,destVol);

       } else {    // kill the particle without trace ( some validation info can be included here eventually )
	 return returnParameters;
       }

     }
     // decay ?
     if ( timeLim.tMax > 0. &&  timeLim.time >= timeLim.tMax ) {
       // process interaction only if creation of secondaries allowed
       if ( m_currentStatic->geometrySignature()==Trk::ID || m_caloMsSecondary ) {
	 // trigger presampled interaction 
	 const Trk::TrackParameters* iPar = m_updators[0]->interact(timeLim.time,nextPar->position(),nextPar->momentum(),particle,timeLim.process);
	 if (!iPar) return returnParameters;
	 throwIntoGarbageBin(iPar);         
	 return extrapolateToVolumeWithPathLimit(*iPar,timeLim,dir,particle,nextGeoID,destVol);
       } else {    // kill the particle without trace ( some validation info can be included here eventually )
	 return returnParameters;
       }
     }

     // check missing volume boundary
     if (nextPar && !(m_currentDense->inside(nextPar->position(),m_tolerance) 
		      || m_navigator->atVolumeBoundary(nextPar,m_currentDense,dir,assocVol,m_tolerance) ) ) {
       ATH_MSG_DEBUG( "  [!] ERROR: missing volume boundary for volume"<< m_currentDense->volumeName() );
     }
     //  if ( m_currentDense->zOverAtimesRho() != 0.) {     
     //    ATH_MSG_DEBUG( "  [!] ERROR: trying to recover: repeat the propagation step in"<< m_highestVolume->volumeName() );
     //    m_currentDense = m_highestVolume;
     //    timeLim.time = time_backup; 
     //    continue;
     //  }
     //}

     ATH_MSG_DEBUG( "  [+] Number of intersection solutions: " << solutions.size() );

     unsigned int iSol  = 0;
     while ( iSol < solutions.size() ) {
       if ( solutions[iSol] < iDest ) {
         return nextPar->clone();          
       } else if ( solutions[iSol] < iDest + m_staticBoundaries.size() ) {
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828

	 // material attached ?
	 const Trk::Layer*  mb =  m_navigSurfs[solutions[iSol]].first->materialLayer();  
	 if (mb) {
	   if (mb->layerMaterialProperties() && mb->layerMaterialProperties()->fullMaterial(nextPar->position()) ) {

	     const ITimedMatEffUpdator* currentUpdator = subMaterialEffectsUpdator(*m_currentStatic);
	     nextPar =  currentUpdator ?
	       currentUpdator->update(nextPar, *mb, timeLim, m_path, m_currentStatic->geometrySignature(), dir, particle) : nextPar;
	   
	     if (!nextPar) {
	       ATH_MSG_VERBOSE( "  [+] Update may have killed neutral track - return." );
	       m_parametersAtBoundary.resetBoundaryInformation();
	       return returnParameters;
	     }
	   } else {    // material layer without material ?
	     ATH_MSG_VERBOSE( " boundary layer without material:"<<mb->layerIndex() );
	   }
	 }

829
830
	 // static volume boundary; return to the main loop 
	 unsigned int index = solutions[iSol]-iDest;
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
	 // use global coordinates to retrieve attached volume (just for static!)
	 nextVol = (m_currentStatic->boundarySurfaces())[index].getPtr()->attachedVolume(nextPar->position(),nextPar->momentum(),dir);
	 // double check the next volume
	 if ( nextVol && !(nextVol->inside(nextPar->position()+0.01*nextPar->momentum().normalized(),m_tolerance) ) ) {
	   ATH_MSG_DEBUG( "  [!] WARNING: wrongly assigned static volume ?"<< m_currentStatic->volumeName()<<"->" << nextVol->volumeName() );
	   nextVol = m_navigator->trackingGeometry()->lowestStaticTrackingVolume(nextPar->position()+0.01*nextPar->momentum().normalized());
	   if (nextVol) ATH_MSG_DEBUG( "  new search yields: "<< nextVol->volumeName() );          
	 }
	 // end double check - to be removed after validation of the geometry gluing 
	 if (nextVol != m_currentStatic ) {
	   m_parametersAtBoundary.boundaryInformation(nextVol,nextPar,nextPar);         
	   ATH_MSG_DEBUG("  [+] StaticVol boundary reached of '" <<m_currentStatic->volumeName() << "'.");
	   if ( m_navigator->atVolumeBoundary(nextPar,m_currentStatic,dir,assocVol,m_tolerance) && assocVol != nextVol )
	     m_currentDense = m_dense ? nextVol : m_highestVolume;
	   // no next volume found --- end of the world
	   if ( !nextVol ) {
	     ATH_MSG_DEBUG( "  [+] World boundary reached        - at " << positionOutput(nextPar->position())<<", timed at " << timeLim.time);
             nextGeoID = Trk::GeometrySignature(Trk::Unsigned);
	     if (!destVol) { return nextPar;}
	   }
           // next volume found and parameters are at boundary
	   if ( nextVol && nextPar ){ 
	     ATH_MSG_DEBUG( "  [+] Crossing to next volume '" << nextVol->volumeName() << "'");
	     ATH_MSG_DEBUG( "  [+] Crossing position is         - at " <<  positionOutput(nextPar->position()) );
             if (!destVol && m_currentStatic->geometrySignature()!=nextVol->geometrySignature())
	       { nextGeoID=nextVol->geometrySignature(); return nextPar; }   
	   }     
	   return extrapolateToVolumeWithPathLimit(*nextPar,timeLim,dir,particle,nextGeoID,destVol);
	 }
       } else if ( solutions[iSol] < iDest + m_staticBoundaries.size() + m_layers.size() ) {
	 // next layer; don't return passive material layers unless required 
	 unsigned int index = solutions[iSol]-iDest-m_staticBoundaries.size();
	 const Trk::Layer* nextLayer = m_navigLays[index].second;
         // material update ?
         //bool matUp = nextLayer->layerMaterialProperties() && m_includeMaterialEffects && nextLayer->isOnLayer(nextPar->position());
         bool matUp = nextLayer->fullUpdateMaterialProperties(*nextPar) && m_includeMaterialEffects && nextLayer->isOnLayer(nextPar->position());
         // identical to last material layer ?
869
870
         if (matUp && nextLayer==m_lastMaterialLayer &&  nextLayer->surfaceRepresentation().type()!=Trk::Surface::Cylinder ) matUp = false;

871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
	 // material update 
	 const ITimedMatEffUpdator* currentUpdator = subMaterialEffectsUpdator(*m_currentStatic);
         if ( matUp ) {
           double pIn = nextPar->momentum().mag(); 
	   nextPar = currentUpdator ? currentUpdator->update(nextPar, *nextLayer, timeLim, m_path, m_currentStatic->geometrySignature(), dir, particle) : nextPar;
	   if (!nextPar) {
	     ATH_MSG_VERBOSE( "  [+] Update may have killed track - return." );
	     m_parametersAtBoundary.resetBoundaryInformation();
	     return returnParameters;
	   } else {  
             ATH_MSG_VERBOSE(" Layer energy loss:"<< nextPar->momentum().mag()- pIn << "at position:"<< nextPar->position()<<", current momentum:"<<nextPar->momentum());
           }
	 }   
         // active surface intersections ( Fatras hits ...)
	 if (m_hitVector &&  particle!=Trk::neutron) {
	   if (nextLayer->surfaceArray()) {
	     // perform the overlap Search on this layer
	     ATH_MSG_VERBOSE( "  [o] Calling overlapSearch() on  layer.");	
	     overlapSearch(*m_subPropagators[0],*currPar,*nextPar,*nextLayer,timeLim.time,dir,true,particle);       	   
	   } else if (nextLayer->layerType()>0 && nextLayer->isOnLayer(nextPar->position())) {
	     ATH_MSG_VERBOSE( "  [o] Collecting intersection with active layer.");	
	     m_hitVector->push_back(Trk::HitInfo(nextPar->clone(),timeLim.time,nextLayer->layerType(),0.));
	   }
	 } // ------------------------------------------------- Fatras mode off -----------------------------------

         // TODO : debug the retrieval of next layer
	 if ( !m_robustSampling && !m_currentStatic->geometrySignature()==Trk::MS ) { 
	   if (m_navigLays[index].first && m_navigLays[index].first->confinedLayers()) {
	     const Trk::Layer* newLayer = nextLayer->nextLayer(nextPar->position(),dir*nextPar->momentum().normalized());
	     if (newLayer && newLayer!=nextLayer) {
               bool found = false;
               int replace = -1;
903
               for (unsigned int i=0;i<m_navigLays.size();i++) { 
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
		 if (m_navigLays[i].second==newLayer) {found=true; break;}
                 if (m_navigLays[i].second !=nextLayer) replace = i;
	       }
               if (!found) { 
                 if (replace>-1) {
		   m_navigLays[replace].second = newLayer;
		   m_navigSurfs[solutions[iSol]+replace-index].first = &(newLayer->surfaceRepresentation());
                 } else {
                   // can't insert a surface in middle
		   return extrapolateToVolumeWithPathLimit(*nextPar,timeLim,dir,particle,nextGeoID,destVol);                   
		 }
	       }
	     }            
	   }
	 }
         currPar = nextPar;
       } else if ( solutions[iSol] < iDest + m_staticBoundaries.size() + m_layers.size() + m_denseBoundaries.size() ) {
	 // dense volume boundary
	 unsigned int index = solutions[iSol] - iDest -m_staticBoundaries.size()- m_layers.size();
	 std::vector< std::pair<const Trk::TrackingVolume*,unsigned int> >::iterator dIter = m_denseVols.begin();
	 while ( index >= (*dIter).second && dIter!= m_denseVols.end() ) {
	   index -= (*dIter).second ; 
	   dIter++;
	 }
	 if ( dIter != m_denseVols.end() ) {
	   currVol = (*dIter).first;
	   nextVol = ( (*dIter).first->boundarySurfaces())[index].getPtr()->attachedVolume(*nextPar,dir);
           // the boundary orientation is not reliable
	   Amg::Vector3D tp = nextPar->position()+2*m_tolerance*dir*nextPar->momentum().normalized();
           if (!nextVol || !nextVol->inside(tp,m_tolerance) ) {   // search for dense volumes
	     m_currentDense =  m_highestVolume;
	     if (m_dense && !m_denseVols.size()) m_currentDense = m_currentStatic;
	     else {
	       for (unsigned int i=0;i<m_denseVols.size(); i++) {
		 const Trk::TrackingVolume* dVol = m_denseVols[i].first;
		 if ( dVol->inside(tp,m_tolerance)  && dVol->zOverAtimesRho()!=0. ){
		   m_currentDense = dVol;
		   ATH_MSG_DEBUG( "  [+] Next dense volume found: '" << m_currentDense->volumeName() << "'."); 
		   break;
		 } 
	       } // loop over dense volumes
	     }
	   } else {
             m_currentDense = nextVol;
	     ATH_MSG_DEBUG( "  [+] Next dense volume: '" << m_currentDense->volumeName() << "'."); 
	   }
	 }

       } else if ( solutions[iSol] < iDest + m_staticBoundaries.size() + m_layers.size() + m_denseBoundaries.size() 
		   + m_navigBoundaries.size() ) {
	 // navig volume boundary
	 unsigned int index = solutions[iSol]-iDest-m_staticBoundaries.size()- m_layers.size()-m_denseBoundaries.size();
	 std::vector< std::pair<const Trk::TrackingVolume*,unsigned int> >::iterator nIter = navigVols.begin();
	 while ( index >= (*nIter).second && nIter!= navigVols.end() ) {
	   index -= (*nIter).second ; 
	   nIter++;
	 }
	 if ( nIter != navigVols.end() ) {
	   currVol = (*nIter).first;
	   nextVol = ( (*nIter).first->boundarySurfaces())[index].getPtr()->attachedVolume(*nextPar,dir);
	   if (!nextVol) ATH_MSG_DEBUG("  [+] Navigation volume boundary, leaving volume '"
				       << currVol->volumeName() << "'.");
	   else ATH_MSG_DEBUG("  [+] Navigation volume boundary, entering volume '" << nextVol->volumeName() << "'.");
	   currPar = nextPar;
	   // return only if detached volume boundaries not collected
	   //if ( nextVol || !detachedBoundariesIncluded )
	   if ( nextVol )
	     return extrapolateToVolumeWithPathLimit(*currPar,timeLim,dir,particle,nextGeoID,destVol);                 
	 } 
       } else if ( solutions[iSol] < iDest + m_staticBoundaries.size() + m_layers.size() + m_denseBoundaries.size() 
		   + m_navigBoundaries.size() + m_detachedBoundaries.size() ) {
	 // detached volume boundary
	 unsigned int index = solutions[iSol]-iDest-m_staticBoundaries.size()- m_layers.size()
	   - m_denseBoundaries.size() - m_navigBoundaries.size();
	 std::vector< std::pair<const Trk::DetachedTrackingVolume*,unsigned int> >::iterator dIter = m_detachedVols.begin();
	 while ( index >= (*dIter).second && dIter!= m_detachedVols.end() ) {
	   index -= (*dIter).second ; 
	   dIter++;
	 }
	 if ( dIter != m_detachedVols.end() ) {
	   currVol = (*dIter).first->trackingVolume();
	   nextVol = ( (*dIter).first->trackingVolume()->boundarySurfaces())[index].getPtr()->attachedVolume(*nextPar,dir);
	   if (!nextVol) 
	     ATH_MSG_DEBUG("  [+] Detached volume boundary, leaving volume '" << currVol->volumeName() << "'.");
	   else ATH_MSG_DEBUG("  [+] Detached volume boundary, entering volume '" << nextVol->volumeName() << "'.");
	   currPar = nextPar;
	   //if ( nextVol || !detachedBoundariesIncluded)
	   if ( nextVol )
	     return extrapolateToVolumeWithPathLimit(*currPar,timeLim,dir,particle,nextGeoID,destVol);   
	 } 
       }   
       iSol++;
     }
     currPar = nextPar;
   }

   return returnParameters;
}        


void Trk::TimedExtrapolator::overlapSearch(const IPropagator& prop,
					   const TrackParameters& parm,
					   const TrackParameters& parsOnLayer,
					   const Layer& lay,
					   //const TrackingVolume& tvol,
					   float time,
					   PropDirection dir,
1011
					   BoundaryCheck bcheck, //bcheck
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
					   ParticleHypothesis particle,
					   bool startingLayer) const 
{
 
       // indicate destination layer 
       bool isDestinationLayer = (&parsOnLayer.associatedSurface() == m_destinationSurface);       
       // start and end surface for on-layer navigation
       //  -> take the start surface if ther parameter surface is owned by detector element
       const Trk::Surface* startSurface = ((parm.associatedSurface()).associatedDetectorElement() && startingLayer) ?
           &parm.associatedSurface() : 0;
       const Trk::Surface* endSurface =  isDestinationLayer ? m_destinationSurface : 0;                     
       // - the best detSurface to start from is the one associated to the detector element        
       const Trk::Surface* detSurface = (parsOnLayer.associatedSurface()).associatedDetectorElement() ?
                                        &parsOnLayer.associatedSurface() : 0;

       ATH_MSG_VERBOSE("  [o] OverlapSearch called " << ( startSurface ? "with " : "w/o " ) << "start, " 
                                                       << ( endSurface ? "with " : "w/o " ) << "end surface." );       

       if (!detSurface){ 
          // of parsOnLayer are different from parm, then local position is safe, because the extrapolation
          //   to the detector surface has been done !     
          detSurface = isDestinationLayer ? lay.subSurface(parsOnLayer.localPosition()) : lay.subSurface(parsOnLayer.position()); 
          if (detSurface) ATH_MSG_VERBOSE("  [o] Detector surface found through subSurface() call" );
          else ATH_MSG_VERBOSE("  [o] No Detector surface found on this layer.");
       } else 
          ATH_MSG_VERBOSE("  [o] Detector surface found through parameter on layer association" );       
       
       // indicate the start layer
       bool isStartLayer = (detSurface && detSurface == startSurface);
       
       const Trk::TrackParameters* detParameters     = 0;
       // the temporary vector (might have to be ordered)
       std::vector<const Trk::TrackParameters*> detParametersOnLayer;
       bool reorderDetParametersOnLayer = false;             
       // the first test for the detector surface to be hit (false test) 
       // - only do this if the parameters aren't on the surface 
       // (i.e. search on the start layer or end layer)
       if (isDestinationLayer) 
          detParameters = (&parsOnLayer);
       else if (isStartLayer)
		  detParameters = (&parm);
       else        
          //detParameters = prop.propagate(parm, *detSurface, dir, false, tvol, particle);
          detParameters = prop.propagate(parm, *detSurface, dir, false, m_fieldProperties, particle);

      // set the surface hit to true, it is anyway overruled 
      bool surfaceHit = true;
      if (detParameters && 
          !isStartLayer &&
          !isDestinationLayer) {
          ATH_MSG_VERBOSE( "  [o] First intersection with Detector surface: " <<  *detParameters );
          // for the later use in the overlapSearch
          surfaceHit = detParameters && detSurface ? detSurface->isOnSurface(detParameters->position()) : 0; //,bcheck) - creates problems on start layer; 
          // check also for start/endSurface on this level
           
          surfaceHit = ( surfaceHit && startSurface ) ? 
             ((detParameters->position()-parm.position()).dot(dir*parm.momentum().normalized()) > 0) : surfaceHit;
          surfaceHit = ( surfaceHit && endSurface ) ?
             ((detParameters->position()-parsOnLayer.position()).dot(dir*parsOnLayer.momentum().normalized()) < 0) : surfaceHit;

          // surface is hit within bounds (or at least with given boundary check directive) -> it counts 
          // surface hit also survived start/endsurface search
          //
          // Convention for Fatras: always apply the full update on the last parameters 
          //                        of the gathered vector (no pre/post schema) 
          // don't record a hit on the destination surface
          if (surfaceHit && 
              detSurface != startSurface && 
              detSurface != m_destinationSurface) {
             ATH_MSG_VERBOSE( "  [H] Hit with detector surface recorded ! " );
             // push into the temporary vector
             detParametersOnLayer.push_back(detParameters);          
         } else if (detParameters){
             // no hit -> fill into the garbage bin 
             ATH_MSG_VERBOSE("  [-] Detector surface hit cancelled through bounds check or start/end surface check." );       
             throwIntoGarbageBin(detParameters);
           }
       }

       // search for the overlap ------------------------------------------------------------------------
       if (detParameters){     
1093
1094
1095
         // retrive compatible subsurfaces
	 std::vector<Trk::SurfaceIntersection> cSurfaces;
	 size_t ncSurfaces = lay.compatibleSurfaces(cSurfaces,*detParameters,Trk::anyDirection,bcheck);
1096
            
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
	 // import from StaticEngine.icc
	 if (ncSurfaces){
	   ATH_MSG_VERBOSE( "found " <<  ncSurfaces << " candidate sensitive surfaces to test."); 
	   // now loop over the surfaces:
	   // the surfaces will be sorted @TODO integrate pathLength propagation into this
	   for (auto& csf : cSurfaces ) {
	     // propagate to the compatible surface, return types are (pathLimit failure is excluded by Trk::anyDirection for the moment):
	     const Trk::TrackParameters* overlapParameters = prop.propagate(parm,
									   *(csf.object),
                                                                           Trk::anyDirection,
									   true,
									   m_fieldProperties,
									   particle);           

	     if (overlapParameters) {
	       ATH_MSG_VERBOSE( "  [+] Overlap surface was hit, checking start/end surface condition." );
	       // check on start / end surface for on-layer navigaiton action
	       surfaceHit = ( startSurface ) ? 
		 ((overlapParameters->position()-parm.position()).dot(dir*parm.momentum().normalized()) > 0) : true;
	       surfaceHit = ( surfaceHit && endSurface ) ?
		 ((overlapParameters->position()-parsOnLayer.position()).dot(dir*parsOnLayer.momentum().normalized()) < 0) : surfaceHit;                  
	       if (surfaceHit){
		 ATH_MSG_VERBOSE( "  [H] Hit with detector surface recorded !" );
		 // count the overlap Surfaces hit 
		 ++m_overlapSurfaceHit;
		 // distinguish whether sorting is needed or not
		 reorderDetParametersOnLayer=true;
		 // push back into the temporary vector
		 detParametersOnLayer.push_back(overlapParameters);        
	       } else { // the parameters have been cancelled by start/end surface
		 // no hit -> fill into the garbage bin 
		 ATH_MSG_VERBOSE("  [-] Detector surface hit cancelled through start/end surface check." );       
		 throwIntoGarbageBin(overlapParameters);
	       }
	     }
	   } // loop over test surfaces done
	 } // there are compatible surfaces  

1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
       }  //---------------------------------------------------------------------------------------------

       // push them into the parameters vector
       std::vector<const Trk::TrackParameters*>::const_iterator parsOnLayerIter    = detParametersOnLayer.begin();
       std::vector<const Trk::TrackParameters*>::const_iterator parsOnLayerIterEnd = detParametersOnLayer.end();

       // reorder the track parameters if neccessary, the overlap descriptor did not provide the ordered surfaces
       if (reorderDetParametersOnLayer){
           // sort to reference of incoming parameters
          Trk::TrkParametersComparisonFunction parameterSorter(parm.position());
          sort(detParametersOnLayer.begin(), detParametersOnLayer.end(), parameterSorter);
       }   

       // after sorting : reset the iterators
       parsOnLayerIter    = detParametersOnLayer.begin();
       parsOnLayerIterEnd = detParametersOnLayer.end();
       // now fill them into the parameter vector -------> hit creation done <----------------------
       for ( ; parsOnLayerIter != parsOnLayerIterEnd; ++parsOnLayerIter) {
	 if (m_hitVector) m_hitVector->push_back(Trk::HitInfo(*parsOnLayerIter,time,0,0.));
       }
}

std::string Trk::TimedExtrapolator::positionOutput(const Amg::Vector3D& pos) const
{
   std::stringstream outStream;
   if (m_printRzOutput) 
        outStream <<  "[r,phi,z] = [ " << pos.perp() << ", " << pos.phi() << ", " << pos.z() << " ]";
   else 
        outStream <<  "[xyz] = [ " << pos.x() << ", " << pos.y() << ", " << pos.z() << " ]";
   return outStream.str();
}

std::string Trk::TimedExtrapolator::momentumOutput(const Amg::Vector3D& mom) const
{
   std::stringstream outStream;
   outStream <<  "[eta,phi] = [ " << mom.eta() << ", " << mom.phi() << " ]";
   return outStream.str();
}

void Trk::TimedExtrapolator::emptyGarbageBin(const Trk::TrackParameters* trPar) const
{   
   // empty the garbage  
   std::map<const Trk::TrackParameters*, bool>::iterator garbageIter  = m_garbageBin.begin();
   std::map<const Trk::TrackParameters*, bool>::iterator garbageEnd   = m_garbageBin.end();

   bool throwCurrent = false;  
   bool throwLast    = false;
   for ( ; garbageIter != garbageEnd; ++garbageIter ){
     if (garbageIter->first && garbageIter->first!=trPar && garbageIter->first != m_lastValidParameters) delete (garbageIter->first);
     if (garbageIter->first && garbageIter->first==trPar) throwCurrent = true; 
     if (garbageIter->first && garbageIter->first==m_lastValidParameters) throwLast = true; 
   }

   m_garbageBin.clear();
   if (throwCurrent) throwIntoGarbageBin(trPar);
   if (throwLast) throwIntoGarbageBin(m_lastValidParameters);
}

// the validation action -> propagated to the SubTools
void Trk::TimedExtrapolator::validationAction() const
{
  // record the updator validation information
  for (unsigned int imueot = 0; imueot < m_subUpdators.size(); ++imueot) 
      m_subUpdators[imueot]->validationAction();      
  // record the navigator validation information
  m_navigator->validationAction();
}

const Trk::TrackParameters*  Trk::TimedExtrapolator::transportNeutralsWithPathLimit( const Trk::TrackParameters& parm,
										     Trk::PathLimit& pathLim, Trk::TimeLimit& timeLim,
										     Trk::PropDirection dir,                                    
										     Trk::ParticleHypothesis particle,
										     std::vector<Trk::HitInfo>*& hitInfo,
										     Trk::GeometrySignature& nextGeoID,
										     const Trk::TrackingVolume* boundaryVol) const 
{

// extrapolation method intended for simulation of particle decay; collects the material up to pre-defined limit and triggers
// material interaction
// possible outcomes:1/ returns curvilinear parameters after reaching the maximal path (if to be destroyed)
//                   2/ returns parameters at destination volume boundary 
//                   3/ returns 0 ( particle stopped ) but keeps material and timing info

  ATH_MSG_DEBUG( "M-[" << ++m_methodSequence << "] transportNeutralsWithPathLimit(...) " << pathLim.x0Max << ", from " << parm.position());

  // reset the path ( in x0 !!) 
  m_path = PathLimit( pathLim.x0Max - pathLim.x0Collected, pathLim.process);     // collect material locally

  // initialize time info
  m_time = timeLim.time;

  // initialize hit vector
  m_hitVector = hitInfo;
 
  // if no input volume, define as highest volume
  //const Trk::TrackingVolume* destVolume = boundaryVol ? boundaryVol : m_navigator->highestVolume();
  m_currentStatic = 0;
  if (boundaryVol && !boundaryVol->inside(parm.position(),m_tolerance) ) return 0;

  m_particleMass = s_particleMasses.mass[particle];
   
  // extrapolate to destination volume boundary with path limit
  const Trk::TrackParameters* returnParms = transportToVolumeWithPathLimit( parm, timeLim, dir,particle, nextGeoID, boundaryVol);

  //save actual path on output 
  if (m_path.x0Collected>0.)  pathLim.updateMat(m_path.x0Collected, m_path.weightedZ/m_path.x0Collected, m_path.l0Collected);

  // return timing
  timeLim.time = m_time; 
   
  return returnParms;

}

const Trk::TrackParameters*  Trk::TimedExtrapolator::transportToVolumeWithPathLimit( const Trk::TrackParameters& parm,
										     Trk::TimeLimit& timeLim,
										     Trk::PropDirection dir,                                    
										     Trk::ParticleHypothesis particle,
										     Trk::GeometrySignature& nextGeoID,
										     const Trk::TrackingVolume* destVol) const 
{

  // returns:
  //    A)  curvilinear track parameters if path or time limit reached 
  //    B)  boundary parameters (at destination volume boundary)

  // initialize the return parameters vector
  const Trk::TrackParameters* returnParameters = 0;
  const Trk::TrackParameters* currPar = &parm;
  const Trk::TrackingVolume*  currVol = 0;
  const Trk::TrackingVolume*  nextVol = 0;
  const Trk::TrackingVolume* assocVol = 0;  
  //int                        nEntryLays = 0;
  unsigned int               iDest = 0;

  // std::cout << "transportNeutralsWithPathLimit(...) " << m_pathLim << ", from " << parm.position()<<" current time, path:"<< m_time<<","<<m_path<<std::endl;
  
  // destination volume boundary ? 
  if ( destVol && m_navigator->atVolumeBoundary(currPar,destVol,dir,nextVol,m_tolerance) && nextVol != destVol ) { return &parm; }
  
  // bool resolveActive = m_resolveActive;
  if (!m_highestVolume ) m_highestVolume = m_navigator->highestVolume();

  emptyGarbageBin(&parm);
  // transport surfaces:  collect only those with valid intersection (easy to calculate for neutrals)
  if( m_trSurfs.capacity() > m_maxNavigSurf ) m_trSurfs.reserve(m_maxNavigSurf); 
  m_trSurfs.clear();

  // target volume may not be part of tracking geometry 
  if (destVol) { 
    const Trk::TrackingVolume* tgVol =  m_navigator->trackingGeometry()->trackingVolume(destVol->volumeName());
    if (!tgVol || tgVol!=destVol) {
      const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds = destVol->boundarySurfaces();
      for (unsigned int ib=0; ib< bounds.size(); ib++ ){
	const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
	Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									  dir*currPar->momentum().normalized());
        if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
          // boundary check
	  Amg::Vector3D gp = currPar->position()+ distSol.first()*dir*currPar->momentum().normalized();
          if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
	    iDest++;
	    m_trSurfs.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
	  }   // valid intersection
	}  // along path
        if (distSol.numberOfSolutions()>1 && distSol.second()>0.) {
          // boundary check
	  Amg::Vector3D gp = currPar->position()+ distSol.second()*dir*currPar->momentum().normalized();
          if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
	    iDest++;
	    m_trSurfs.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.second()));
	  }   // valid intersection
	}
      } // end loop over boundaries
    } // end process external volume 		   
  }
    
  // resolve current position
  Amg::Vector3D gp = parm.position();
  if ( !m_currentStatic || !m_currentStatic->inside(gp,m_tolerance) ) {
    m_currentStatic =  m_navigator->trackingGeometry()->lowestStaticTrackingVolume(gp);    
    ATH_MSG_DEBUG( "  [+] current static volume resolved by navigator (inside): "<< 
		   positionOutput(currPar->position())<<":"<<m_currentStatic->volumeName() );
  }

  if ( m_navigator->atVolumeBoundary(currPar,m_currentStatic,dir,nextVol,m_tolerance) && nextVol != m_currentStatic ) {
    // no next volume found --- end of the world
    if ( !nextVol ) {
      ATH_MSG_DEBUG( "  [+] Word boundary reached        - at " << positionOutput(currPar->position()) );
      nextGeoID = Trk::GeometrySignature(Trk::Unsigned);
      return currPar;
    }
    ATH_MSG_DEBUG( "  [+] current static volume resolved by navigator at boundary: "<< positionOutput(currPar->position())
		   <<m_currentStatic->volumeName()<<"->"<< nextVol->volumeName()<<" with tolerance " << m_tolerance );
    m_currentStatic = nextVol;
  }

  // current frame volume known-retrieve geoID
  nextGeoID = m_currentStatic->geometrySignature(); 

1335
1336
1337
1338
1339
1340
1341
1342
  // resolve active Calo volumes if hit info required 
  if ( m_hitVector && nextGeoID==Trk::Calo ) {
    const Trk::AlignableTrackingVolume* alignTV = dynamic_cast<const Trk::AlignableTrackingVolume*> (m_currentStatic);
    if (alignTV) {
      return transportInAlignableTV(parm,timeLim,dir,particle,nextGeoID,alignTV).trPar;
    }
  }

1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
  // distance to static volume boundaries recalculated
  // retrieve boundaries along path
  m_trStaticBounds.clear();
  const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds = m_currentStatic->boundarySurfaces();
  for (unsigned int ib=0; ib< bounds.size(); ib++ ){
    const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
    Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
								      dir*currPar->momentum().normalized());
    if (distSol.numberOfSolutions()>0 && (distSol.currentDistance(false)>m_tolerance || distSol.numberOfSolutions()>1 ) && distSol.first()>m_tolerance ) {
      double dist = distSol.first();
      // resolve multiple intersection solutions
      if (distSol.numberOfSolutions()>1 && dist<m_tolerance && distSol.second()>dist ) dist = distSol.second();
      // boundary check
      Amg::Vector3D gp = currPar->position()+dist*dir*currPar->momentum().normalized();
      if ( surf.isOnSurface(gp,true,m_tolerance,m_tolerance) ) {
	m_trStaticBounds.insert(m_trStaticBounds.begin(),Trk::DestBound(&surf,dist,ib));
      }   
    }  // along path
    if (distSol.numberOfSolutions()>1 && distSol.second()>m_tolerance ) {
      double dist = distSol.second();
      // boundary check
      Amg::Vector3D gp = currPar->position()+dist*dir*currPar->momentum().unit();
      if ( surf.isOnSurface(gp,true,m_tolerance,m_tolerance) ) {
	if ( dist > m_tolerance ) {  // valid intersection
	  m_trStaticBounds.insert(m_trStaticBounds.begin(),Trk::DestBound(&surf,dist,ib));
	}
      }   
    }  // along path
  } // end loop over boundaries
  
  if ( !m_trStaticBounds.size() ) {
    ATH_MSG_WARNING( "  transportToVolumeWithPathLimit() - at " << currPar->position() <<", missing static volume boundary "
		     << m_currentStatic->volumeName() <<": transport interrupted" );

    ATH_MSG_WARNING("---> particle R,phi,z, momentum:"<< currPar->position().perp()<<","<<currPar->position().phi()<<","<<currPar->position().z() <<","<<currPar->momentum());
    ATH_MSG_WARNING("---> static volume position:"<< m_currentStatic->center());
    const Trk::CylinderVolumeBounds* cyl = dynamic_cast<const Trk::CylinderVolumeBounds*> (&(m_currentStatic->volumeBounds()));
    if (cyl) ATH_MSG_WARNING("---> cylinder volume dimensions:"<<cyl->innerRadius()<<","<<cyl->outerRadius()<<","<<cyl->halflengthZ());
  

    for (unsigned int ib=0; ib< bounds.size(); ib++ ){
      const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
      Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
								      dir*currPar->momentum().unit());
      ATH_MSG_WARNING("---> decomposed boundary surface position, normal, estimated distance:"<<ib<<","<<surf.center()<<","<<surf.normal());
      ATH_MSG_WARNING("---> estimated distance to (first solution):boundary check:"<<distSol.numberOfSolutions()<<","<<distSol.first()<<":"<<
		      surf.isOnSurface(currPar->position()+distSol.first()*dir*currPar->momentum().unit(),true,m_tolerance,m_tolerance));
      if (distSol.numberOfSolutions()>1)
       ATH_MSG_WARNING("---> estimated distance to (second solution):boundary check:" << distSol.second()<< ","<<
		       surf.isOnSurface(currPar->position()+distSol.second()*dir*currPar->momentum().unit(),true,m_tolerance,m_tolerance));  
    }

    return returnParameters;

  } else if (m_trStaticBounds[0].distance < m_tolerance ) {

    // TODO find out why this case (=exit from volume) haven't been handled by Navigator 
    //ATH_MSG_WARNING( " recovering from glitch at the static volume boundary:"<<m_trStaticBounds[0].distance );

    Amg::Vector3D gp = currPar->position()+ m_tolerance*dir*currPar->momentum().unit();
    m_currentStatic =  m_navigator->trackingGeometry()->lowestStaticTrackingVolume(gp);    

    if (m_currentStatic) return transportToVolumeWithPathLimit(parm, timeLim, dir, particle, nextGeoID, destVol);	  
    else {
	    ATH_MSG_DEBUG( "  [+] World boundary reached        - at " << positionOutput(currPar->position())<<", timed at " << m_time );
	    nextGeoID = Trk::GeometrySignature(Trk::Unsigned);
	    if (!destVol) { return currPar;}
    }
  }
  
  m_detachedVols.clear();
  m_trDetachBounds.clear();
  m_denseVols.clear();
  m_trDenseBounds.clear();
  m_trLays.clear();
  m_navigLays.clear();

  // new: ID volumes may have special material layers ( entry layers ) - add them here
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
  //if (m_currentStatic->entryLayerProvider()) {
  //  const std::vector<const Trk::Layer*>& entryLays = m_currentStatic->entryLayerProvider()->layers();
  //  for (unsigned int i=0; i < entryLays.size(); i++) {
  //    if (entryLays[i]->layerType()>0 || entryLays[i]->layerMaterialProperties()) {
  //	  const Trk::Surface& surf=entryLays[i]->surfaceRepresentation(); 
  //	  Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
  //									    dir*currPar->momentum().normalized());
  //	  if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
  //	    // boundary check
  //	    Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
  // 	    if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
  //	      m_trLays.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
  //	      m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,entryLays[i]) );
  //	    }   // valid intersection
  //	  }  // along path
  //     }
  //  } 
  //}
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622

  // detached volume boundaries
  const std::vector<const Trk::DetachedTrackingVolume*>* detVols = m_currentStatic->confinedDetachedVolumes();
  if (detVols) {
    std::vector<const Trk::DetachedTrackingVolume*>::const_iterator iTer = detVols->begin();
    for (; iTer != detVols->end(); iTer++) { 
      // active station ?
      const Trk::Layer* layR = (*iTer)->layerRepresentation();
      bool active = ( layR && layR->layerType() ) ? true : false;
      
      if (active) {
	// probably does not full resolution ?
	/*
          if ( resolveActive ) {
	  const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > >  detBounds=
	      (*iTer)->trackingVolume()->boundarySurfaces();
	      // loop over boundaries, save only if valid intersection
	      int newB=0;
	      for (unsigned int ib=0; ib< detBounds.size(); ib++ ){
	      const Trk::Surface& surf = (detBounds[ib].getPtr())->surfaceRepresentation();
	      Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
	      dir*currPar->momentum().normalized());
	      if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
		// boundary check
		Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
		if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
		m_trDetachBounds.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
		newB++;
		}   // valid intersection
	      }  // along path
	      } // end loop over boundaries
	      if (newB>0) m_detachedVols.push_back(std::pair<const Trk::DetachedTrackingVolume*,unsigned int> (*iTer,newB) );
	      } else {
	*/
	if (!m_resolveMultilayers || !(*iTer)->multilayerRepresentation() ) {
	  const Trk::Surface& surf = layR->surfaceRepresentation();
	  Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									    dir*currPar->momentum().normalized());
	  if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
	    // boundary check
	    Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
	    if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
	      m_trLays.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
	      m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> ((*iTer)->trackingVolume(),layR));
	    }
	  }
	} else {
	  const std::vector<const Trk::Layer*>* multi = (*iTer)->multilayerRepresentation();
	  for (unsigned int i=0;i<multi->size();i++) {
	    const Trk::Surface& surf = (*multi)[i]->surfaceRepresentation();
	    Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									      dir*currPar->momentum().normalized());
	    if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
	      // boundary check
	      Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
	      if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
		m_trLays.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
		m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> ((*iTer)->trackingVolume(),(*multi)[i]));
	      }
	    }
	  }   // end loop over multilayers
	} // end unresolved active 
      } // active done  
      else if (m_currentStatic->geometrySignature()!=Trk::MS || !m_useMuonMatApprox ||
	       (*iTer)->name().substr((*iTer)->name().size()-4,4)=="PERM" ) {  // retrieve inert detached objects only if needed
	// dense volume boundaries
	if ((*iTer)->trackingVolume()->zOverAtimesRho()!=0. && 
	    (!(*iTer)->trackingVolume()->confinedDenseVolumes() || !(*iTer)->trackingVolume()->confinedDenseVolumes()->size() )
	    && ( !(*iTer)->trackingVolume()->confinedArbitraryLayers() ||
		 !(*iTer)->trackingVolume()->confinedArbitraryLayers()->size() ) ) {
	  const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > >  detBounds=
	    (*iTer)->trackingVolume()->boundarySurfaces();
	  int newB=0;
	  for (unsigned int ibb=0; ibb< detBounds.size(); ibb++ ){
	    const Trk::Surface& surf = (detBounds[ibb].getPtr())->surfaceRepresentation();
	    Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									dir*currPar->momentum().normalized());
	    if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
	      // boundary check
	      Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
	      if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
		m_trDenseBounds.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
		newB++;
	      }   // valid intersection
	    }  // along path
	  } // end loop over boundaries
	  if (newB>0) m_denseVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> 
					    ((*iTer)->trackingVolume(),newB) );
	} 
	// subvolumes ?
	//if ((*iTer)->trackingVolume()->confinedDenseVolumes() &&  (*iTer)->trackingVolume()->confinedDenseVolumes()->size()) 
	//  ATH_MSG_WARNING( "  transportToVolumeWithPathLimit() - at " << currPar->position() <<", unresolved subvolumes for  "
	//		   << (*iTer)->trackingVolume()->volumeName() );
	
	const std::vector<const Trk::TrackingVolume*>* confinedDense = (*iTer)->trackingVolume()->confinedDenseVolumes();
        if (confinedDense && confinedDense->size()) {
	  std::vector<const Trk::TrackingVolume*>::const_iterator vIter = confinedDense->begin();
          for (; vIter!= confinedDense->end(); vIter++) {
	    const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > >  bounds=(*vIter)->boundarySurfaces();
	    int newB=0;
	    for (unsigned int ibb=0; ibb< bounds.size(); ibb++ ){
	      const Trk::Surface& surf = (bounds[ibb].getPtr())->surfaceRepresentation();
	      Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
										dir*currPar->momentum().normalized());
	      if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
		// boundary check
		Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
		if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
		  m_trDenseBounds.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
		  newB++;
		}   // valid intersection
	      }  // along path
	    } // end loop over boundaries
	    if (newB>0) m_denseVols.push_back(std::pair<const Trk::TrackingVolume*,unsigned int> 
					      ((*vIter),newB) );
            if ((*vIter)->confinedDenseVolumes() || (*vIter)->confinedArbitraryLayers())
	      ATH_MSG_WARNING( "  transportToVolumeWithPathLimit() - at " << currPar->position() <<", unresolved sublayers/subvolumes for  "
			       << (*vIter)->volumeName() );
	  }
	}

	// confined layers
	const std::vector<const Trk::Layer*>* confLays = (*iTer)->trackingVolume()->confinedArbitraryLayers(); 
	if ( confLays ) {
	  std::vector<const Trk::Layer*>::const_iterator lIt = confLays->begin();
	  for ( ; lIt!= confLays->end(); lIt++ ){
	    const Trk::Surface& surf = (*lIt)->surfaceRepresentation();
	    Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									dir*currPar->momentum().normalized());
	    if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
	      // boundary check
	      Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
	      if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
		m_trLays.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
		m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> ((*iTer)->trackingVolume(),*lIt) );         
	      }   // valid intersection
	    }  // along path
	  } 
	}  // end confined layers       
      } // end inert material
    }
  } // end detached volumes
  m_denseResolved    = std::pair<unsigned int,unsigned int> (m_denseVols.size(), m_trDenseBounds.size());
  m_layerResolved    = m_trLays.size();

  std::vector< Trk::DestBound >::iterator bIter=m_trStaticBounds.begin();
  while (bIter != m_trStaticBounds.end()) {
    m_trSurfs.push_back(std::pair<const Trk::Surface*,double> ((*bIter).surface,(*bIter).distance));
    bIter++;
  }

  //std::cout <<"navigation in current static:"<< m_trSurfs.size()<<","<<m_trStaticBounds.size()<< std::endl;
  //for (unsigned int ib=0; ib<m_trSurfs.size(); ib++) std::cout <<"distance to static:"<< ib<<","<<m_trSurfs[ib].second<<std::endl;

  // resolve the use of dense volumes
  m_dense = (m_currentStatic->geometrySignature()==Trk::MS && m_useMuonMatApprox ) || (m_currentStatic->geometrySignature()!=Trk::MS && m_useDenseVolumeDescription );

  // reset remaining counters
  m_currentDense = m_dense ?  m_currentStatic : m_highestVolume;
  m_navigBoundaries.clear(); 
  if (m_denseVols.size()>m_denseResolved.first) {
    m_denseVols.resize(m_denseResolved.first);
    m_trDenseBounds.resize(m_denseResolved.second);
  }
  if (m_layers.size()>m_layerResolved) {
    m_trLays.resize(m_layerResolved);
    m_navigLays.resize(m_layerResolved);
  }  

  //if (m_currentStatic->entryLayerProvider()) nEntryLays = m_currentStatic->entryLayerProvider()->layers().size();

  // confined layers
  if ( m_currentStatic->confinedLayers()) {
    std::vector<const Trk::Layer*> cLays = m_currentStatic->confinedLayers()->arrayObjects();
    for (unsigned int i=0; i < cLays.size(); i++) { 
      if (cLays[i]->layerMaterialProperties()) {
	const Trk::Surface& surf = cLays[i]->surfaceRepresentation();
	Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
									  dir*currPar->momentum().normalized());
	if (distSol.numberOfSolutions()>0 && distSol.first()>0.) {
	  // boundary check
	  Amg::Vector3D gp = currPar->position()+distSol.first()*dir*currPar->momentum().normalized();
	  if ( surf.isOnSurface(gp,true,0.001,0.001) ) {
	    m_trLays.push_back(std::pair<const Trk::Surface*,double>(&surf,distSol.first()));
1623
	    m_navigLays.push_back(std::pair<const Trk::TrackingVolume*,const Trk::Layer*> (m_currentStatic,cLays[i]) ); 
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
	  }   // valid intersection
	}  // along path
      }
    }
  }
  
  // m_trSurfs contains destination surface (if it exists), static volume boundaries  
  // complete with TG m_layers/dynamic layers, m_denseBoundaries, m_navigBoundaries, m_detachedBoundaries

  if (m_trLays.size()) m_trSurfs.insert(m_trSurfs.end(),m_trLays.begin(),m_trLays.end());
  if (m_trDenseBounds.size()) m_trSurfs.insert(m_trSurfs.end(),m_trDenseBounds.begin(),m_trDenseBounds.end());
  if (m_trDetachBounds.size()) m_trSurfs.insert(m_trSurfs.end(),m_trDetachBounds.begin(),m_trDetachBounds.end()); 

  // current dense
  m_currentDense =  m_highestVolume;

  for (unsigned int i=0;i<m_denseVols.size(); i++) {
    const Trk::TrackingVolume* dVol = m_denseVols[i].first;
    if ( dVol->inside(currPar->position(),m_tolerance)  && dVol->zOverAtimesRho()!=0. ) {
      if ( !m_navigator->atVolumeBoundary(currPar,dVol,dir,nextVol,m_tolerance) ||
	   dVol->inside(currPar->position()+2*m_tolerance*currPar->momentum().unit(),m_tolerance) ) m_currentDense = dVol;
    } 
  }

  if (m_dense && m_currentDense==m_highestVolume) m_currentDense = m_currentStatic;
  
  // ready to process
  // 1/ order valid intersections ( already in trSurfs )
   
  std::vector<unsigned int> sols;
  for (unsigned int i=0;i<m_trSurfs.size(); i++) { sols.push_back(i); }

  if (sols.size()>1) {
    unsigned int itest=1;
    while ( itest<sols.size() ) {
      if ( m_trSurfs[sols[itest]].second < m_trSurfs[sols[itest-1]].second ) {
        unsigned int iex = sols[itest-1];
        sols[itest-1]=sols[itest];
        sols[itest]=iex;
        itest=1;
      } else itest++; 
    }
    // check ordering
    for (unsigned int is=1; is<sols.size(); is++) if (m_trSurfs[sols[is]].second<m_trSurfs[sols[is-1]].second) std::cout<<"wrong intersection ordering"<< std::endl;
  }


  // 2/ check time/material/boundary limit
      
  // update of m_navigSurfs required if I/ entry into new navig volume, II/ exit from currentActive without overlaps

   nextVol = 0;
   const Trk::TrackParameters* nextPar=0;

   double dist = 0.;  
   double mom=currPar->momentum().mag(); 
   double beta = mom/sqrt(mom*mom+m_particleMass*m_particleMass)*Gaudi::Units::c_light;

   ATH_MSG_DEBUG( "  [0] starting transport of neutral particle in (dense) volume "<< m_currentDense->volumeName() );

   for (unsigned int is=0; is<sols.size(); is++) {

     if ( m_trSurfs[sols[is]].second==0. ) continue;

     double step = m_trSurfs[sols[is]].second-dist;
 
     Amg::Vector3D nextPos = currPar->position()+dir*currPar->momentum().normalized()*m_trSurfs[sols[is]].second;
     //Amg::Vector3D halfStep = nextPos - 0.5*step*dir*currPar->momentum().normalized();

     // check missing volume boundary 
     if ( !(m_currentDense->inside(nextPos,m_tolerance) ) ) {
       ATH_MSG_DEBUG( "  [!] ERROR: missing volume boundary for volume"<< m_currentDense->volumeName() );
       // new search
       m_currentDense =  m_highestVolume;
       for (unsigned int i=0;i<m_denseVols.size(); i++) {
	 const Trk::TrackingVolume* dVol = m_denseVols[i].first;
	 if ( dVol->inside(nextPos,m_tolerance)  && dVol->zOverAtimesRho()!=0. ) m_currentDense = dVol; 
       }
       if (m_dense && m_currentDense==m_highestVolume) m_currentDense = m_currentStatic;

       ATH_MSG_DEBUG( "  [!] new search for dense volume : "<< m_currentDense->volumeName() );
     }
     
     double tDelta = step/beta;
     
     double mDelta = (m_currentDense->zOverAtimesRho() != 0.) ? step/m_currentDense->x0() : 0.;

     // in case of hadronic interaction retrieve nuclear interaction properties, too
     
     double frT = 1.;
     if (step>0 && timeLim.tMax>m_time && m_time+tDelta >= timeLim.tMax) frT = (timeLim.tMax-m_time)*beta/step;
     
     // TODO : compare x0 or l0 according to the process type     
     double frM = 1.;
     if (mDelta>0 && m_path.x0Max > 0.) {
       if (m_path.process < 100 && m_path.x0Collected+mDelta > m_path.x0Max ) frM = (m_path.x0Max-m_path.x0Collected)/mDelta;
       else {     // waiting for hadronic interaction,  retrieve nuclear interaction properties
         double mDeltaL = m_currentDense->L0 > 0. ? step/m_currentDense->L0 : mDelta/0.37/m_currentDense->averageZ();
	 if (m_path.l0Collected+mDeltaL > m_path.x0Max)   frM = (m_path.x0Max-m_path.l0Collected)/mDeltaL;
       }
     }

     double fr = fmin(frT,frM);

     //std::cout << "looping over intersections:"<<is<<","<< m_trSurfs[sols[is]].second<<","<<step << ","<< tDelta<<","<<mDelta << std::endl;

     if (fr<1.) { // decay or material interaction during the step

       int process = frT < frM ? timeLim.process : m_path.process;
       m_time += fr*step/beta; 
1734
       if (mDelta>0 && m_currentDense->averageZ()>0) m_path.updateMat( fr*mDelta, m_currentDense->averageZ(), 0.); 
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761

       nextPos = currPar->position()+dir*currPar->momentum().normalized()*(dist+fr*step);

       // process interaction only if creation of secondaries allowed
       if (m_currentStatic->geometrySignature()==Trk::ID || m_caloMsSecondary ) {

	 const Trk::TrackParameters* nextPar = m_updators[0]->interact(m_time,nextPos,currPar->momentum(),particle,process,m_currentDense);
	 
	 if (nextPar) ATH_MSG_DEBUG( " [!] WARNING: particle survives the interaction "<< process ); 
	 
	 if (nextPar && process==121) {
	   ATH_MSG_DEBUG( " [!] WARNING: failed hadronic interaction, killing the input particle anyway" );
	   return returnParameters;
	 }
   
         if (!nextPar) return returnParameters;
  
         throwIntoGarbageBin(nextPar);
         //return transportToVolumeWithPathLimit(*nextPar, timeLim, dir, particle, nextGeoID, destVol);
       } else {  // kill particle without trace
	   return returnParameters;
       }    

     }  // end decay or material interaction durign the step
 
     // update
     dist = m_trSurfs[sols[is]].second; 
1762
     if (mDelta>0 && m_currentDense->averageZ()>0) m_path.updateMat( mDelta, m_currentDense->averageZ(), 0.); 
1763
1764
1765
1766
1767
1768
1769
1770
     m_time += tDelta;

     nextPar = new Trk::CurvilinearParameters(nextPos,currPar->momentum(),1.);  // fake charge
     throwIntoGarbageBin(nextPar);

     if (sols[is]<iDest) {      // destination volume (most often, subdetector boundary)
       return nextPar;          
     } else if ( sols[is] < iDest + m_trStaticBounds.size() ) {     // tracking geometry frame
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790

       // material attached ?
       const Trk::Layer*  mb =  m_trStaticBounds[sols[is]-iDest].surface->materialLayer();  
       if (mb) {
         if (mb->layerMaterialProperties() && mb->layerMaterialProperties()->fullMaterial(nextPos) ) {

	   const ITimedMatEffUpdator* currentUpdator = subMaterialEffectsUpdator(*m_currentStatic);
	   nextPar =  currentUpdator ?
	     currentUpdator->update(nextPar, *mb, timeLim, m_path, m_currentStatic->geometrySignature(), dir, particle) : nextPar;
	   
	   if (!nextPar) {
	     ATH_MSG_VERBOSE( "  [+] Update may have killed neutral track - return." );
	     m_parametersAtBoundary.resetBoundaryInformation();
	     return returnParameters;
	   }
	 } else {    // material layer without material ?
	   ATH_MSG_VERBOSE( " boundary layer without material:"<<mb->layerIndex() );
         }
       }

1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
       // static volume boundary; return to the main loop 
       unsigned int index = m_trStaticBounds[sols[is]-iDest].bIndex;
       // use global coordinates to retrieve attached volume (just for static!)
       nextVol = (m_currentStatic->boundarySurfaces())[index].getPtr()->attachedVolume(nextPar->position(),nextPar->momentum(),dir);
       // double check the next volume
       if ( nextVol && !(nextVol->inside(nextPar->position()+0.01*nextPar->momentum().normalized(),m_tolerance) ) ) {
	 ATH_MSG_DEBUG( "  [!] WARNING: wrongly assigned static volume ?"<< m_currentStatic->volumeName()<<"->" << nextVol->volumeName() );
	 nextVol = m_navigator->trackingGeometry()->lowestStaticTrackingVolume(nextPar->position()+0.01*nextPar->momentum().normalized());
	 if (nextVol) ATH_MSG_DEBUG( "  new search yields: "<< nextVol->volumeName() );          
       }
       // end double check - to be removed after validation of the geometry gluing 
       if (nextVol != m_currentStatic ) {
	 ATH_MSG_DEBUG("  [+] StaticVol boundary reached of '" <<m_currentStatic->volumeName() << "'.");
	 if ( m_navigator->atVolumeBoundary(nextPar,m_currentStatic,dir,assocVol,m_tolerance) && assocVol != m_currentStatic )
	   m_currentDense = m_dense ? nextVol : m_highestVolume;
	 // no next volume found --- end of the world
	 if ( !nextVol ) {
	   ATH_MSG_DEBUG( "  [+] World boundary reached        - at " << positionOutput(nextPar->position())<<", timed at " << m_time );
	   nextGeoID = Trk::GeometrySignature(Trk::Unsigned);
	   if (!destVol) { return nextPar;}
	 }
	 // next volume found and parameters are at boundary
	 if ( nextVol && nextPar ){ 
	   ATH_MSG_DEBUG( "  [+] Crossing to next volume '" << nextVol->volumeName() << "'");
	   ATH_MSG_DEBUG( "  [+] Crossing position is         - at " <<  positionOutput(nextPar->position()) );
	   if (!destVol && m_currentStatic->geometrySignature()!=nextVol->geometrySignature())
	     { nextGeoID=nextVol->geometrySignature(); return nextPar; }   
	 }     
	 return transportToVolumeWithPathLimit(*nextPar, timeLim, dir, particle, nextGeoID, destVol);
       }
       //if (dist>0.) return transportToVolumeWithPathLimit(*nextPar, timeLim, dir, particle, nextGeoID, destVol);
	 
     } else if ( sols[is] < iDest + m_trStaticBounds.size() + m_trLays.size() ) {     // layer

       // material thickness - simple approach
       unsigned int index = sols[is]-iDest-m_trStaticBounds.size();
       const Trk::Layer* nextLayer = m_navigLays[index].second;

1829
1830
1831
1832
1833
1834
1835
       bool matUp = nextLayer->layerMaterialProperties()->fullMaterial(nextPos) && m_includeMaterialEffects;

       if (!matUp && !nextLayer->layerMaterialProperties()->fullMaterial(nextPos) )
         ATH_MSG_WARNING("layer without material:"<< nextLayer->layerIndex());    

       // identical to the last material layer ?
       if (matUp && nextLayer==m_lastMaterialLayer && nextLayer->surfaceRepresentation().type()!=Trk::Surface::Cylinder ) matUp = false;
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894

       // material update        
       if (matUp) {

	 const ITimedMatEffUpdator* currentUpdator = subMaterialEffectsUpdator(*m_currentStatic);

	 nextPar =  currentUpdator ?
	   currentUpdator->update(nextPar, *nextLayer, timeLim, m_path, m_currentStatic->geometrySignature(), dir, particle) : nextPar;

         if (!nextPar) {
	     ATH_MSG_VERBOSE( "  [+] Update may have killed neutral track - return." );
	     m_parametersAtBoundary.resetBoundaryInformation();
	     return returnParameters;
         }
      
       } 

     } else if ( sols[is] < iDest + m_trStaticBounds.size() + m_trLays.size() + m_trDenseBounds.size() ) {

       // dense volume boundary : no material update here, navigation only ( set m_currentDense for next step )

       unsigned int index = sols[is] - iDest -m_trStaticBounds.size()- m_trLays.size();
       std::vector< std::pair<const Trk::TrackingVolume*,unsigned int> >::iterator dIter = m_denseVols.begin();
       while ( index >= (*dIter).second && dIter!= m_denseVols.end() ) {
	 index -= (*dIter).second ; 
	 dIter++;
       }
       if ( dIter != m_denseVols.end() ) {
	 currVol = (*dIter).first;

         if ( m_navigator->trackingGeometry()->atVolumeBoundary(nextPos,nextPar->momentum(), currVol,assocVol, dir,m_tolerance) ) {
            if ( assocVol && assocVol->zOverAtimesRho()!= 0. ) m_currentDense = assocVol;
            else if ( currVol->inside(nextPos+0.002*dir*nextPar->momentum().normalized()) ) m_currentDense = currVol;
            else {
	      // new search
	      m_currentDense =  m_highestVolume;
	      if (m_useMuonMatApprox && !m_denseVols.size()) m_currentDense = m_currentStatic;
	      else {
		for (unsigned int i=0;i<m_denseVols.size(); i++) {
		  const Trk::TrackingVolume* dVol = m_denseVols[i].first;
		  if ( dVol->inside(nextPos+0.002*dir*nextPar->momentum().normalized(),m_tolerance)  && dVol->zOverAtimesRho()!=0. ) m_currentDense = dVol; 
		}
	      }
	    }
	 }
       }
     } else {   // detached volume bounds - not relevant ?
       
     }

     throwIntoGarbageBin(nextPar);

   }

   ATH_MSG_WARNING( "  transportToVolumeWithPathLimit() - return with navigation break from volume "<<  m_currentStatic->volumeName()   );

   return nextPar;

}
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314


Trk::BoundaryTrackParameters Trk::TimedExtrapolator::transportInAlignableTV(const Trk::TrackParameters& parm,
								       Trk::TimeLimit& timeLim,
								       Trk::PropDirection dir,                                    
								       Trk::ParticleHypothesis particle,
								       Trk::GeometrySignature& nextGeoID,
								       const Trk::AlignableTrackingVolume* aliTV) const

{
  ATH_MSG_DEBUG( "  [0] starting transport of neutral particle in alignable volume "<< m_currentStatic->volumeName() );
 
  // material loop in sensitive Calo volumes 
  // returns: boundary parameters (static volume boundary)
  // material collection / intersection with active layers  ( binned material used ) 
  
  // initialize the return parameters vector
  const Trk::TrackParameters* currPar = &parm;
  const Trk::TrackingVolume*  nextVol = 0;
  std::vector<Trk::IdentifiedIntersection> iis;

  emptyGarbageBin(&parm);

  if (!aliTV) return Trk::BoundaryTrackParameters(0,0,0);
    
  // TODO if volume entry go to entry of misaligned volume

  // save volume entry if collection present

  const Trk::BinnedMaterial* binMat = aliTV->binnedMaterial();

  const Trk::IdentifiedMaterial* binIDMat = 0;

  const Trk::Material*  currMat = aliTV;     // material to be used

  if (binMat && m_hitVector) {
    binIDMat = binMat->material(currPar->position());
    if (binIDMat->second>0) m_hitVector->push_back(Trk::HitInfo(currPar->clone(),timeLim.time,binIDMat->second,0.));
  }

  // loop through binned material : save identifier, material, distance

  // binned material 
  if (binMat) {

    Amg::Vector3D pos = currPar->position();
    Amg::Vector3D umo = currPar->momentum().normalized();

    const Trk::BinUtility* lbu =  binMat->layerBinUtility(pos);
    if (lbu) {
      //std::cout <<"layerBinUtility retrieved:"<<lbu->bins()<< std::endl;
      m_currentLayerBin = binMat->layerBin(pos);
      currMat           = binMat->material(pos)->first;
      std::pair<size_t,float> dist2next = lbu->distanceToNext(pos,dir*umo);
      //std::cout<<"estimated distance to the next bin:"<<dist2next.first<<","<<dist2next.second<< std::endl; 
      unsigned int lastBin = dist2next.first;
      double distTot = dist2next.second*dir;
      while (dist2next.first < lbu->bins()) {
        pos = pos+ dist2next.second*dir*umo;
	//std::cout <<"step inside volume?"<< aliTV->inside(pos)<<","<<aliTV->inside(pos,0.002)<< std::endl;
        if ( !aliTV->inside(pos) ) break;   // step outside volume
        binIDMat       = binMat->material(pos);   // material at the bin entry
        iis.push_back(Trk::IdentifiedIntersection(distTot,binIDMat->second,binIDMat->first));
        dist2next = lbu->distanceToNext(pos,dir*umo);  // distance to the bin exit
        distTot += dist2next.second*dir;                // combined distance
        if (dist2next.first==lastBin) break;
        lastBin=dist2next.first;
      }
    }
  }

  // resolve exit from the volume

  m_trStaticBounds.clear();
  const std::vector< SharedObject<const BoundarySurface<TrackingVolume> > > bounds = aliTV->boundarySurfaces();
  for (unsigned int ib=0; ib< bounds.size(); ib++ ){
    const Trk::Surface& surf = (bounds[ib].getPtr())->surfaceRepresentation();
    Trk::DistanceSolution distSol = surf.straightLineDistanceEstimate(currPar->position(),
								      dir*currPar->momentum().normalized());
    double dist = distSol.first();
    // resolve multiple intersection solutions
    if (distSol.numberOfSolutions()>1 && dist<m_tolerance && distSol.second()>dist ) dist = distSol.second();
    // boundary check
    Amg::Vector3D gp = currPar->position()+dist*dir*currPar->momentum().normalized();
    if ( surf.isOnSurface(gp,true,m_tolerance,m_tolerance) ) {
      const Trk::TrackingVolume* attachedVol =  (bounds[ib].getPtr())->attachedVolume(gp,currPar->momentum(),dir);
      if ( attachedVol != m_currentStatic )   { //exit  
        nextVol = attachedVol;
	m_trStaticBounds.insert(m_trStaticBounds.begin(),Trk::DestBound(&surf,dist,ib));
      }   
    }
  } // end loop over boundaries

  if (!m_trStaticBounds.size()) {

    ATH_MSG_ERROR("exit from alignable volume "<<aliTV->volumeName()<<" not resolved, aborting");
    return Trk::BoundaryTrackParameters(0,0,0); 

  } else if (m_trStaticBounds.size()>1) {  // hit edge ?
    Amg::Vector3D gp = currPar->position()+(m_trStaticBounds[0].distance+1.)*dir*currPar->momentum().normalized();
    nextVol =  m_navigator->trackingGeometry()->lowestStaticTrackingVolume(gp); 
  }

  // exit from the volume may coincide with the last bin boundary - leave 10 microns marge  
  if (iis.size() &&  m_trStaticBounds[0].distance-iis.back().distance < 0.01) iis.pop_back();

  // add volume exit
  iis.push_back(Trk::<