25 #include "GaudiKernel/SystemOfUnits.h"
44 declareInterface<IMuidCaloTrackStateOnSurface>(
this);
53 ATH_MSG_DEBUG(
"Initializing CombinedMuonTrackStateOnSurface");
71 return StatusCode::SUCCESS;
79 <<
" completely failed to intersect the calorimeter." <<
endmsg <<
" "
82 return StatusCode::SUCCESS;
87 std::vector<std::unique_ptr<const Trk::TrackStateOnSurface>>
caloTSOS;
90 std::unique_ptr<Trk::TrackStateOnSurface> innerTS, middleTS, outerTS;
91 std::unique_ptr<const Trk::TrackParameters> inParams, midParams;
105 fieldCondObj->getInitializedCache(fieldCache);
108 bool trackOutwards =
true;
113 trackOutwards =
false;
123 middleParams = midParams.get();
129 middleTS =
m_caloEnergyParam->trackStateOnSurface(ctx, *midParams, innerParams, outerParams);
130 if (!middleTS) { middleParams =
nullptr; }
136 std::unique_ptr<const Trk::TrackParameters>
params;
138 if (!middleTS)
break;
152 <<
" correctedEnergy "
167 std::make_unique<Trk::AtaCylinder>(middleParams->
position(),
momentum, middleParams->
charge(), *cylinder);
189 if (!middleTS) {
ATH_MSG_VERBOSE(
" fail tracking outwards: no intersect at middle surface"); }
192 ATH_MSG_VERBOSE(
" fail tracking ouwards: no intersect at inner surface");
200 middleParams = midParams.get();
203 innerParams = inParams.get();
207 middleTS =
m_caloEnergyDeposit->trackStateOnSurface(ctx, *middleParams, inParams.get(), outerParams);
209 middleTS =
m_caloEnergyParam->trackStateOnSurface(ctx, *middleParams, inParams.get(), outerParams);
223 <<
" correctedEnergy "
227 std::unique_ptr<const Trk::TrackParameters>
params;
231 middleParams->covariance() ? std::optional<AmgSymMatrix(5)>(*middleParams->covariance()) : std::nullopt;
247 ATH_MSG_VERBOSE(
" fail tracking inwards: no intersect at inner surface");
250 ATH_MSG_VERBOSE(
" fail tracking inwards: no intersect at middle surface");
256 caloTSOS.push_back(std::move(innerTS));
259 if (middleTS)
caloTSOS.push_back(std::move(middleTS));
261 caloTSOS.push_back(std::move(outerTS));
293 std::unique_ptr<const Trk::TrackParameters> extrapolation =
getExtrapolatedParameters(ctx, middleParams, SurfaceLayer::Middle);
299 std::unique_ptr<Trk::TrackStateOnSurface> TSOS;
301 TSOS =
m_caloEnergyDeposit->trackStateOnSurface(ctx, *extrapolation, innerParams, outerParams);
303 TSOS =
m_caloEnergyParam->trackStateOnSurface(ctx, *extrapolation, innerParams, outerParams);
323 const std::string surf_layer_str =
layer == SurfaceLayer::Inner ?
"Inner" : (
layer == SurfaceLayer::Middle ?
"Middle" :
"Outer");
326 double startingPhi = 0.;
339 if (!surface)
return nullptr;
342 unsigned extrapolations = 0;
345 propDirection = momentumDirection;
347 propDirection = oppositeDirection;
351 std::unique_ptr<const Trk::TrackParameters> extrapolation{
353 if (!extrapolation)
return nullptr;
357 if (std::abs(
deltaPhi) > M_PI_2) {
return nullptr; }
361 double signRZ = (extrapolation->position().perp() -
parameters.position().perp()) *
362 (extrapolation->position().z() -
parameters.position().z());
363 if (signRZ * extrapolation->position().z() < 0.) {
370 bool restart =
false;
376 std::unique_ptr<const Trk::Surface> reset_surface;
377 while (++extrapolations < 5 && extrapolatedSurface != oldSurface) {
381 propDirection = momentumDirection;
383 propDirection = oppositeDirection;
388 std::unique_ptr<const Trk::TrackParameters> oldParameters = std::move(extrapolation);
391 if (!extrapolation) {
399 ATH_MSG_DEBUG(surf_layer_str <<
" Parameters: oscillating => arbitrary solution chosen");
401 extrapolation = std::move(oldParameters);
402 reset_surface.reset(extrapolation->associatedSurface().clone());
403 extrapolatedSurface = reset_surface.get();
404 surface = extrapolatedSurface;
407 ATH_MSG_VERBOSE(surf_layer_str <<
" Parameters: restart extrap after " << extrapolations <<
" extrapolations");
411 surface = oldSurface;
415 ATH_MSG_DEBUG(surf_layer_str <<
" Parameters: Extrapolation succeeded go to next iteration");
416 oldSurface = surface;
417 surface = extrapolatedSurface;
424 if (std::abs(
deltaPhi) > M_PI_2) {
return nullptr; }
426 ATH_MSG_VERBOSE(surf_layer_str <<
" Parameters: success after " << extrapolations <<
" extrapolation step(s). "
427 << std::setiosflags(std::ios::fixed) <<
" Intersection at: r,phi,z " << std::setw(7)
428 << std::setprecision(1) << extrapolation->position().perp() << std::setw(7) << std::setprecision(3)
429 << extrapolation->position().phi() << std::setw(8) << std::setprecision(1)
430 << extrapolation->position().z() <<
" Direction: eta,phi " << std::setw(7) << std::setprecision(3)
431 << extrapolation->momentum().eta() << std::setw(7) << std::setprecision(3)
432 << extrapolation->momentum().phi());
434 return extrapolation;
440 double parameterDistance =
parameters.position().mag();
442 parameterDistance =
parameters.associatedSurface().center().perp();