ATLAS Offline Software
SpacePointCalibrator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "SpacePointCalibrator.h"
5 
15 #include "GaudiKernel/PhysicalConstants.h"
17 
20 
22 
25 
26 #include "Acts/Utilities/MathHelpers.hpp"
27 
29 
30 #include <float.h>
31 
32 namespace {
33  constexpr double c_inv = 1./ Gaudi::Units::c_light;
34 }
35 
36 namespace MuonR4{
37  using namespace Acts::UnitLiterals;
41  using namespace SegmentFit;
42 
44  ATH_CHECK(m_geoCtxKey.initialize());
45  ATH_CHECK(m_idHelperSvc.retrieve());
46  ATH_CHECK(m_mdtCalibrationTool.retrieve(EnableTool{m_idHelperSvc->hasMDT()}));
47  ATH_CHECK(m_nswCalibTool.retrieve(EnableTool{m_idHelperSvc->hasMM() || m_idHelperSvc->hasSTGC()}));
48  ATH_CHECK(detStore()->retrieve(m_detMgr));
49  return StatusCode::SUCCESS;
50  }
51 
53  const CalibratedSpacePoint& spacePoint,
54  const Amg::Vector3D& segPos,
55  const Amg::Vector3D& segDir,
56  const double timeDelay) const {
57  CalibSpacePointPtr calibSP{};
58  if (spacePoint.type() != xAOD::UncalibMeasType::Other){
59  calibSP = calibrate(ctx, spacePoint.spacePoint(), segPos, segDir, timeDelay);
60  } else {
61  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint);
62  }
63  if (spacePoint.fitState() == State::Outlier) {
64  calibSP->setFitState(State::Outlier);
65  }
66  return calibSP;
67  }
68 
71  const Amg::Vector3D& segPos,
72  const Amg::Vector3D& segDir,
73  const double timeDelay) const {
74  for (CalibSpacePointPtr& sp : spacePoints){
75  sp = calibrate(ctx, *sp, segPos, segDir, timeDelay);
76  }
77  return spacePoints;
78  }
79 
81  const SpacePoint* spacePoint,
82  const Amg::Vector3D& posInChamb,
83  const Amg::Vector3D& dirInChamb,
84  const double timeOffset) const {
85 
86  const ActsGeometryContext* gctx{nullptr};
87  if (!SG::get(gctx, m_geoCtxKey, ctx).isSuccess()) {
88  return nullptr;
89  }
90  const Amg::Vector3D& spPos{spacePoint->localPosition()};
91  const Amg::Transform3D& locToGlob{spacePoint->msSector()->localToGlobalTrans(*gctx)};
92  const Amg::Vector3D& chDir{spacePoint->sensorDirection()};
93 
94  // Adjust the space point position according to the external seed. But only if the space point
95  // is a 1D strip
96  Amg::Vector3D calibSpPos = spacePoint->dimension() == 2 ? spPos
97  : spPos + Amg::intersect<3>(posInChamb, dirInChamb, spPos, chDir).value_or(0) * chDir;
98 
99  SpacePoint::Cov_t cov = spacePoint->covariance();
100  CalibSpacePointPtr calibSP{};
101  switch (spacePoint->type()) {
103  const Amg::Vector3D locClosestApproach = posInChamb
104  + Amg::intersect<3>(spPos, chDir,
105  posInChamb, dirInChamb).value_or(0) * dirInChamb;
106 
107  Amg::Vector3D closestApproach{locToGlob* locClosestApproach};
108  const double timeOfArrival = closestApproach.mag() * c_inv + timeOffset;
109 
110  if (ATH_LIKELY(spacePoint->dimension() == 1)) {
111  auto* dc = static_cast<const xAOD::MdtDriftCircle*>(spacePoint->primaryMeasurement());
112  MdtCalibInput calibInput{*dc, *gctx};
113  calibInput.setTrackDirection(locToGlob.linear() * dirInChamb,
114  Acts::abs(dirInChamb.phi() - 90._degree) > 1.e-7 );
115  calibInput.setTimeOfFlight(timeOfArrival);
116  calibInput.setClosestApproach(std::move(closestApproach));
117  ATH_MSG_VERBOSE("Parse hit calibration "<<m_idHelperSvc->toString(dc->identify())<<", "<<calibInput);
118  MdtCalibOutput calibOutput = m_mdtCalibrationTool->calibrate(ctx, calibInput);
119  ATH_MSG_VERBOSE("Returned calibration object "<<calibOutput);
120  State fitState{State::Valid};
123  ATH_MSG_DEBUG("Failed to create a valid hit from "<<m_idHelperSvc->toString(dc->identify())
124  <<std::endl<<calibInput<<std::endl<<calibOutput);
125  fitState = State::FailedCalib;
126  cov[Acts::toUnderlying(AxisDefs::etaCov)] = dc->readoutElement()->innerTubeRadius();
127  } else {
128  cov[Acts::toUnderlying(AxisDefs::etaCov)] = Acts::square(calibOutput.driftRadiusUncert());
129  }
130  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos), fitState);
131  calibSP->setCovariance(cov);
132  calibSP->setDriftRadius(calibOutput.driftRadius());
133  } else {
134  auto* dc = static_cast<const xAOD::MdtTwinDriftCircle*>(spacePoint->primaryMeasurement());
135  MdtCalibInput calibInput{*dc, *gctx};
136  calibInput.setClosestApproach(closestApproach);
137  calibInput.setTimeOfFlight(timeOfArrival);
138 
139  MdtCalibInput twinInput{dc->twinIdentify(), dc->twinAdc(), dc->twinTdc(), dc->readoutElement(), *gctx};
140  twinInput.setClosestApproach(closestApproach);
141  twinInput.setTimeOfFlight(timeOfArrival);
142 
143  MdtCalibTwinOutput calibOutput = m_mdtCalibrationTool->calibrateTwinTubes(ctx,
144  std::move(calibInput),
145  std::move(twinInput));
146 
147  State fitState{State::Valid};
149  ATH_MSG_DEBUG("Failed to create a valid hit from "<<m_idHelperSvc->toString(dc->identify())
150  <<std::endl<<calibOutput);
151  cov[Acts::toUnderlying(AxisDefs::etaCov)] = Acts::square(dc->readoutElement()->innerTubeRadius());
152  cov[Acts::toUnderlying(AxisDefs::phiCov)] = Acts::square(0.5* dc->readoutElement()->activeTubeLength(dc->measurementHash()));
153  fitState = State::FailedCalib;
154  } else {
155  cov[Acts::toUnderlying(AxisDefs::etaCov)] = Acts::square(calibOutput.uncertPrimaryR());
156  cov[Acts::toUnderlying(AxisDefs::phiCov)] = Acts::square(calibOutput.sigmaZ());
157  }
158  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos), fitState);
159  calibSP->setCovariance(cov);
160  calibSP->setDriftRadius(calibOutput.primaryDriftR());
161  }
162  break;
163  }
165  auto* strip = static_cast<const xAOD::RpcMeasurement*>(spacePoint->primaryMeasurement());
166 
168  const Amg::Transform3D toGasGap{strip->readoutElement()->globalToLocalTrans(*gctx, strip->layerHash()) * locToGlob};
169  const Amg::Vector3D lPos = toGasGap * calibSpPos;
170  using EdgeSide = MuonGMR4::RpcReadoutElement::EdgeSide;
171  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos));
172 
173  cov[Acts::toUnderlying(AxisDefs::timeCov)] = Acts::square(m_rpcTimeResolution);
174 
175  const double time1 = strip->time()
176  - strip->readoutElement()->distanceToEdge(strip->layerHash(),
177  lPos.block<2,1>(0,0),
178  EdgeSide::readOut) /m_rpcSignalVelocity;
179 
180  if (spacePoint->dimension() == 2) {
181  auto* strip2 = static_cast<const xAOD::RpcMeasurement*>(spacePoint->secondaryMeasurement());
182 
183  const double time2 = strip2->time() -
184  strip2->readoutElement()->distanceToEdge(strip2->layerHash(),
185  Eigen::Rotation2D{90._degree}*lPos.block<2,1>(0,0),
186  EdgeSide::readOut)/m_rpcSignalVelocity;
188  calibSP->setTimeMeasurement(0.5*(time1 + time2));
190  cov[Acts::toUnderlying(AxisDefs::timeCov)] += Acts::square(0.5*(time1 - time2));
191  }
192  calibSP->setCovariance(cov);
193  ATH_MSG_VERBOSE("Create rpc space point "<<m_idHelperSvc->toString(strip->identify())<<", dimension "<<spacePoint->dimension()
194  << ", at "<<Amg::toString(calibSP->localPosition())<<", uncalib time: "
195  <<strip->time()<<", calib time: "<<calibSP->time()<<" cov " <<calibSP->covariance());
196  break;
197  }
199  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos));
200  calibSP->setCovariance(cov);
201  break;
202  }
204  const xAOD::MMCluster* cluster = static_cast<const xAOD::MMCluster*>(spacePoint->primaryMeasurement());
205  Amg::Vector3D globalPos{locToGlob * posInChamb};
206  Amg::Vector3D globalDir{locToGlob.linear() * dirInChamb};
207 
208  std::pair<double, double> calibPosCov {calibrateMM(ctx, *gctx, *cluster, globalPos, globalDir)};
209 
210  ATH_MSG_DEBUG("Calibrated pos and cov" << calibPosCov.first << " " << calibPosCov.second);
211  cov[Acts::toUnderlying(AxisDefs::etaCov)] = calibPosCov.second;
212  Amg::Transform3D toChamberTrans{ locToGlob.inverse() * cluster->readoutElement()->localToGlobalTrans(*gctx, cluster->layerHash())};
213 
214  // since we want to take the second coordiante from the external estimate we need to transform the sp posiiton to the layer frame, replace the precission coordinate and transform back
215  Amg::Vector3D calibSpPosInLayer = toChamberTrans.inverse() * calibSpPos;
216  ATH_MSG_DEBUG("in layer before calibration" << Amg::toString(calibSpPosInLayer));
217  calibSpPosInLayer.x() = calibPosCov.first;
218  ATH_MSG_DEBUG("in layer after calibration" << Amg::toString(calibSpPosInLayer));
219  calibSpPos = toChamberTrans * calibSpPosInLayer;
220 
221  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos));
222  calibSP->setCovariance(cov);
223  ATH_MSG_DEBUG("calibrated MM cluster "<<m_idHelperSvc->toString(cluster->identify()) << " loc x old " << cluster->localPosition<1>()[0] << " new loc x " << calibSP->localPosition()[1] << "cov " << calibSP->covariance());
224 
225  break;
226  }
228  const auto* cluster = static_cast<const xAOD::sTgcMeasurement*>(spacePoint->primaryMeasurement());
229 
230  // We do not apply any correction for pads or wire only space points
231  if (cluster->channelType() != sTgcIdHelper::sTgcChannelTypes::Strip) {
232  ATH_MSG_DEBUG("Calibrating an sTGC Pad or wire " << m_idHelperSvc->toString(cluster->identify()));
233  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos));
234  calibSP->setCovariance(cov);
235  break;
236  }
237 
238  double posAlongTheStrip{0.};
239 
240  // check if the space point is a strip/wire combination and take the position along the strip from the wire measurement
241  if(spacePoint->secondaryMeasurement()) {
242  const auto* secMeas = static_cast<const xAOD::sTgcMeasurement*>(spacePoint->secondaryMeasurement());
243  ATH_MSG_VERBOSE("Using secondary measurement "<< m_idHelperSvc->toString(secMeas->identify())<<" for sTGC strip cluster " << m_idHelperSvc->toString(cluster->identify()));
244  posAlongTheStrip = spacePoint->secondaryMeasurement()->localPosition<1>()[0];
245  } else {
246  ATH_MSG_VERBOSE("No secondary measurement for sTGC strip cluster " << m_idHelperSvc->toString(cluster->identify()));
247  }
248 
249  Amg::Vector3D globalPos{locToGlob * posInChamb};
250  Amg::Vector3D globalDir{locToGlob.linear() * dirInChamb};
251 
252  const auto* stripClus = static_cast<const xAOD::sTgcStripCluster*>(cluster);
253  const auto [calibPos, calibCov] = calibratesTGC(ctx, *gctx, *stripClus, posAlongTheStrip, globalPos, globalDir);
254 
255  ATH_MSG_DEBUG("Calibrated pos and cov" << calibPos << " " << calibCov);
256  cov[Acts::toUnderlying(AxisDefs::etaCov)] = calibCov;
257  Amg::Transform3D toChamberTrans{ locToGlob.inverse() * cluster->readoutElement()->localToGlobalTrans(*gctx, cluster->layerHash())};
258 
259  // since we want to take the second coordiante from the external estimate we need to transform the sp posiiton to the layer frame, replace the precission coordinate and transform back
260  Amg::Vector3D calibSpPosInLayer = toChamberTrans.inverse() * calibSpPos;
261  ATH_MSG_DEBUG("in layer before calibration" << Amg::toString(calibSpPosInLayer));
262  calibSpPosInLayer.x() = calibPos;
263  ATH_MSG_DEBUG("in layer after calibration" << Amg::toString(calibSpPosInLayer));
264  calibSpPos = toChamberTrans * calibSpPosInLayer;
265 
266  calibSP = std::make_unique<CalibratedSpacePoint>(spacePoint, std::move(calibSpPos));
267  calibSP->setCovariance(cov);
268  ATH_MSG_DEBUG("calibrated sTGC cluster "<<m_idHelperSvc->toString(cluster->identify()) << " loc x old " << cluster->localPosition<1>()[0] << " new loc x " << calibSP->localPosition()[1] << "cov " << calibSP->covariance());
269 
270  break;
271  }
272 
273  default:
274  ATH_MSG_WARNING("Do not know how to calibrate "<<m_idHelperSvc->toString(spacePoint->identify()));
275  }
276  return calibSP;
277  }
278 
280  const std::vector<const SpacePoint*>& spacePoints,
281  const Amg::Vector3D& posInChamb,
282  const Amg::Vector3D& dirInChamb,
283  const double timeOffset) const {
284  CalibSpacePointVec calibSpacePoints{};
285  calibSpacePoints.reserve(spacePoints.size());
286  for(const SpacePoint* spacePoint : spacePoints) {
287  CalibSpacePointPtr hit = calibrate(ctx, spacePoint, posInChamb, dirInChamb, timeOffset);
288  if (hit) {
289  calibSpacePoints.push_back(std::move(hit));
290  }
291  }
292  return calibSpacePoints;
293  }
294  double SpacePointCalibrator::driftVelocity(const EventContext& ctx,
295  const CalibratedSpacePoint& spacePoint) const {
296  if(spacePoint.type() == xAOD::UncalibMeasType::MdtDriftCircleType) {
297  const MuonCalib::MdtFullCalibData* calibConsts = m_mdtCalibrationTool->getCalibConstants(ctx, spacePoint.spacePoint()->identify());
298  const std::optional<double> driftTime = calibConsts->rtRelation->tr()->driftTime(spacePoint.driftRadius());
299  return calibConsts->rtRelation->rt()->driftVelocity(driftTime.value_or(0.));
300  }
301  return 0.;
302  }
303  double SpacePointCalibrator::driftAcceleration(const EventContext& ctx,
304  const CalibratedSpacePoint& spacePoint) const {
305  if(spacePoint.type() == xAOD::UncalibMeasType::MdtDriftCircleType) {
306  const MuonCalib::MdtFullCalibData* calibConsts = m_mdtCalibrationTool->getCalibConstants(ctx, spacePoint.spacePoint()->identify());
307  const std::optional<double> driftTime = calibConsts->rtRelation->tr()->driftTime(spacePoint.driftRadius());
308  return calibConsts->rtRelation->rt()->driftAcceleration(driftTime.value_or(0.));
309  }
310  return 0.;
311  }
312 
313 
314  std::pair<double, double> SpacePointCalibrator::calibrateMM(const EventContext& ctx, const ActsGeometryContext& gctx, const xAOD::MMCluster& cluster, const Amg::Vector3D& globalPos, const Amg::Vector3D& globalDir) const{
315  std::vector<NSWCalib::CalibratedStrip> calibClus;
316  StatusCode sc = m_nswCalibTool->calibrateClus(ctx, gctx, cluster, globalPos, calibClus);
317  if(sc.isFailure()) {
318  ATH_MSG_WARNING("Failed to calibrate MM cluster "<<m_idHelperSvc->toString(cluster.identify()));
319  return std::make_pair(0., 0.);
320  }
321 
322  Amg::Vector2D locPos{cluster.localPosition<1>()[0] * Amg::Vector2D::UnitX()};
324 
325  Amg::MatrixX calibCov{};
326  calibCov.resize(1,1);
327  calibCov(0,0) = cluster.localCovariance<1>()(0, 0);
328  ATH_MSG_DEBUG("old loc pos " << locPos[0] << " old cov" << calibCov(0,0) );
329 
330  Muon::IMMClusterBuilderTool::RIO_Author rotAuthor = m_clusterBuilderToolMM->getCalibratedClusterPosition(ctx, calibClus, locDir ,locPos, calibCov);
331  if(rotAuthor == Muon::IMMClusterBuilderTool::RIO_Author::unKnownAuthor){
332  THROW_EXCEPTION("Failed to calibrate MM cluster "<<m_idHelperSvc->toString(cluster.identify()));
333  }
334  ATH_MSG_DEBUG("new loc pos " << locPos[0] << " new cov" << calibCov(0,0) );
335  return std::make_pair(locPos[0], calibCov(0,0));
336  }
337 
338  std::pair<double, double> SpacePointCalibrator::calibratesTGC(const EventContext& ctx, const ActsGeometryContext& gctx, const xAOD::sTgcStripCluster& cluster,
339  double posAlongTheStrip, const Amg::Vector3D& globalPos, const Amg::Vector3D& globalDir) const{
340 
341  // avoid unused variable warning while this code is under development
342  (void) ctx;
343  (void) globalDir;
344 
345  // if the second coordiante was not provided by the wire, take it from the seed track position
346  if(posAlongTheStrip == -FLT_MAX){
347  Amg::Vector3D extPosLocal = cluster.readoutElement()->globalToLocalTrans(gctx, cluster.layerHash()) * globalPos;
348  posAlongTheStrip = extPosLocal[1];
349  }
350 
351  // For now just copying over the local position and covariance. Eventually this should apply corrections from B-Lines and as build geometry
352 
353  return std::make_pair(cluster.localPosition<1>()[0], cluster.localCovariance<1>()(0,0));
354  }
355 
356  void SpacePointCalibrator::calibrateSourceLink(const Acts::GeometryContext& geoctx,
357  const Acts::CalibrationContext& cctx,
358  const Acts::SourceLink& link,
359  ActsTrk::MutableTrackContainer::TrackStateProxy trackState) const {
360 
362  const Acts::BoundTrackParameters trackPars{trackState.referenceSurface().getSharedPtr(),
363  trackState.parameters(), trackState.covariance(),
365 
366  const Amg::Vector3D trackPos{trackPars.position(geoctx)};
367  const Amg::Vector3D trackDir{trackPars.direction()};
368  const ActsGeometryContext* gctx = geoctx.get<const ActsGeometryContext*>();
369  const EventContext* ctx = cctx.get<const EventContext*>();
370  const auto* muonMeas = ActsTrk::detail::xAODUncalibMeasCalibrator::unpack(link);
371  ATH_MSG_VERBOSE("Calibrate measurement "<<m_idHelperSvc->toString(xAOD::identify(muonMeas))
372  <<" @ surface "<<trackState.referenceSurface().geometryId());
373  switch (muonMeas->type()){
374  using enum xAOD::UncalibMeasType;
375  case MdtDriftCircleType: {
376  const auto* dc = static_cast<const xAOD::MdtDriftCircle*>(muonMeas);
377  MdtCalibInput calibInput{*dc, *gctx};
378  calibInput.setClosestApproach(trackPos);
379  //calibInput.setTimeOfFlight(trackPars.parameters()[Acts::eBoundTime]);
380  calibInput.setTrackDirection(trackDir, true);
381  const double driftSign = sign(trackPars.parameters()[Acts::eBoundLoc0]);
382 
384  if (ATH_LIKELY(muonMeas->numDimensions() == 1)) {
385  MdtCalibOutput calibOutput = m_mdtCalibrationTool->calibrate(*ctx, calibInput);
386  ATH_MSG_VERBOSE("Returned calibration object "<<calibOutput);
387  AmgVector(1) pos{AmgVector(1)::Zero()};
388  AmgSymMatrix(1) cov{AmgSymMatrix(1)::Identity()};
391  ATH_MSG_DEBUG("Failed to create a valid hit from "<<m_idHelperSvc->toString(dc->identify())
392  <<std::endl<<calibInput<<std::endl<<calibOutput);
393  cov(Acts::eBoundLoc0,Acts::eBoundLoc0) = std::pow(dc->readoutElement()->innerTubeRadius(), 2);
394  } else {
395  pos[Acts::eBoundLoc0] = driftSign*calibOutput.driftRadius();
396  cov(Acts::eBoundLoc0, Acts::eBoundLoc0) = std::pow(calibOutput.driftRadiusUncert(), 2);
397  }
398  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime, pos, cov, link, trackState);
399  }
401  else {
402  const auto* twinDC = static_cast<const xAOD::MdtTwinDriftCircle*>(muonMeas);
403  MdtCalibInput twinInput{twinDC->twinIdentify(), twinDC->twinAdc(), twinDC->twinTdc(), twinDC->readoutElement(), *gctx};
404  twinInput.setClosestApproach(trackPos);
405  twinInput.setTimeOfFlight(trackPars.parameters()[Acts::eBoundTime]);
406 
407  MdtCalibTwinOutput calibOutput = m_mdtCalibrationTool->calibrateTwinTubes(*ctx,
408  std::move(calibInput),
409  std::move(twinInput));
411  AmgSymMatrix(2) locCov{AmgSymMatrix(2)::Identity()};
413  ATH_MSG_DEBUG("Failed to create a valid hit from "<<m_idHelperSvc->toString(dc->identify())
414  <<std::endl<<calibOutput);
415  locCov(Acts::eBoundLoc0, Acts::eBoundLoc0) = std::pow(dc->readoutElement()->innerTubeRadius(), 2);
416  locCov(Acts::eBoundLoc1, Acts::eBoundLoc1) = std::pow(0.5* dc->readoutElement()->activeTubeLength(dc->measurementHash()), 2);
417  } else {
418  locCov(Acts::eBoundLoc0, Acts::eBoundLoc0) = std::pow(calibOutput.uncertPrimaryR(), 2);
419  locCov(Acts::eBoundLoc1, Acts::eBoundLoc1) = std::pow(calibOutput.sigmaZ(), 2);
420  locPos[Acts::eBoundLoc0] = driftSign*calibOutput.primaryDriftR();
421  locPos[Acts::eBoundLoc1] = calibOutput.locZ();
422  }
423  setState<2, ActsTrk::MutableTrackStateBackend>(ProjectorType::e2DimNoTime, locPos, locCov, link, trackState);
424  }
425  break;
426  } case RpcStripType: {
427  const auto* rpcClust = static_cast<const xAOD::RpcMeasurement*>(muonMeas);
429  if (ATH_LIKELY(rpcClust->numDimensions() == 1)) {
430  if (!m_useRpcTime) {
431  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime,
432  rpcClust->localPosition<1>(),
433  rpcClust->localCovariance<1>(), link, trackState);
434  } else {
435  AmgVector(2) measPars{AmgVector(2)::Zero()};
436  AmgSymMatrix(2) measCov{AmgSymMatrix(2)::Identity()};
437  measPars[0] = rpcClust->localPosition<1>()[0];
438  measCov(0,0) = rpcClust->localCovariance<1>()(0, 0);
439  measCov(1,1) = std::pow(m_rpcTimeResolution, 2);
440  setState<2, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimWithTime,
441  measPars, measCov, link, trackState);
442  }
443  }
445  else {
446  if (!m_useRpcTime) {
447  setState<2, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime,
448  rpcClust->localPosition<2>(),
449  rpcClust->localCovariance<2>(), link, trackState);
450  } else {
451  AmgVector(3) measPars{AmgVector(3)::Zero()};
452  AmgSymMatrix(3) measCov{AmgSymMatrix(3)::Identity()};
453  measPars.block<2,1>(0,0) = xAOD::toEigen(rpcClust->localPosition<2>());
454  measCov.block<2,2>(0,0) = xAOD::toEigen(rpcClust->localCovariance<2>());
455  measCov(2,2) = std::pow(m_rpcTimeResolution, 2);
456  setState<3, ActsTrk::MutableTrackStateBackend>(ProjectorType::e2DimWithTime,
457  measPars, measCov, link, trackState);
458  }
459  }
460  break;
461  } case TgcStripType: {
462  if (!m_useTgcTime) {
463  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimRotNoTime,
464  muonMeas->localPosition<1>(),
465  muonMeas->localCovariance<1>(), link, trackState);
466  } else {
467  ATH_MSG_WARNING("Tgc time calibration to be implemented...");
468  }
469  break;
470  }
471  case MMClusterType: {
472  const auto* mmClust = static_cast<const xAOD::MMCluster*>(muonMeas);
473  std::pair<double, double> calibPosCov{calibrateMM(*ctx,* gctx, *mmClust, trackPos, trackDir)};
474  AmgVector(1) pos{AmgVector(1)(calibPosCov.first)};
475  AmgSymMatrix(1) cov{AmgSymMatrix(1)(calibPosCov.second)};
476 
477  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime,
478  pos,
479  cov, link, trackState);
480  break;
481  } case sTgcStripType: {
482  const auto* stgcClust = static_cast<const xAOD::sTgcMeasurement*>(muonMeas);
483 
484  if(stgcClust->channelType() == sTgcIdHelper::sTgcChannelTypes::Wire) {
485  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime,
486  muonMeas->localPosition<1>(),
487  muonMeas->localCovariance<1>(), link, trackState);
488 
489  } else if(stgcClust->channelType() == sTgcIdHelper::sTgcChannelTypes::Pad) {
490  setState<2, ActsTrk::MutableTrackStateBackend>(ProjectorType::e2DimNoTime,
491  stgcClust->localPosition<2>(),
492  stgcClust->localCovariance<2>(), link, trackState);
493 
494 
495  } else { // strips
496  const auto stgCluster = static_cast<const xAOD::sTgcStripCluster*>(muonMeas);
497  std::pair<double, double> calibPosCov{calibratesTGC(*ctx, *gctx, *stgCluster, -FLT_MAX, trackPos, trackDir)};
498  if(!m_usesTgcTime){
499  AmgVector(1) pos{AmgVector(1)(calibPosCov.first)};
500  AmgSymMatrix(1) cov{AmgSymMatrix(1)(calibPosCov.second)};
501  setState<1, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimNoTime,
502  pos,
503  cov, link, trackState);
504  } else {
505  ATH_MSG_WARNING("sTGC time calibration to be implemented...");
506  AmgVector(2) pos{AmgVector(2)::Zero()};
507  AmgSymMatrix(2) cov{AmgSymMatrix(2)::Zero()};
508  pos[0] = calibPosCov.first;
509  pos[1] = stgCluster->time();
510  cov(0,0) = calibPosCov.second;
511  cov(1,1) = std::pow(25 /*ns*/, 2);
512 
513  setState<2, ActsTrk::MutableTrackStateBackend>(ProjectorType::e1DimWithTime,
514  pos,
515  cov, link, trackState);
516  }
517  break;
518 
519  }
520  THROW_EXCEPTION("sTGC measurements are not yet implemented");
521  break;
522  } default: {
523  THROW_EXCEPTION("The parsed measurement is not a muon measurement. Please check.");
524  }
525  }
526  }
527 }
MuonR4::ISpacePointCalibrator::CalibSpacePointVec
std::vector< CalibSpacePointPtr > CalibSpacePointVec
Definition: ISpacePointCalibrator.h:31
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
MdtCalibInput::setTrackDirection
void setTrackDirection(const Amg::Vector3D &trackDir, bool hasPhi)
Sets the direction of the externally determined track.
Definition: MdtCalibInput.cxx:110
MuonR4::SpacePoint::msSector
const MuonGMR4::SpectrometerSector * msSector() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:84
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
xAOD::RpcMeasurement_v1
RpcMeasurement_v1: Class storing the geneic.
Definition: RpcMeasurement_v1.h:21
xAOD::identify
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:82
xAOD::sTgcMeasurement_v1::layerHash
IdentifierHash layerHash() const
Returns the hash of the associated gasGap layer.
Definition: sTgcMeasurement_v1.cxx:38
UtilFunctions.h
MuonR4::SpacePoint::type
xAOD::UncalibMeasType type() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:88
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
MdtCalibInput.h
xAOD::sTgcStripCluster_v1
Definition: sTgcStripCluster_v1.h:13
sTgcIdHelper.h
xAOD::MMCluster_v1
Definition: MMCluster_v1.h:20
MdtCalibInput
Definition: MdtCalibInput.h:34
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
NswClusteringUtils.h
MuonR4::SpacePoint::CovIdx::timeCov
@ timeCov
MuonR4::SpacePoint::Cov_t
std::array< double, 3 > Cov_t
Abrivation of the covariance type.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:27
MuonCalib::MdtFullCalibData::rtRelation
RtRelationPtr rtRelation
Definition: MdtFullCalibData.h:21
xAOD::UncalibMeasType::MMClusterType
@ MMClusterType
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:200
xAOD::MMCluster_v1::readoutElement
const MuonGMR4::MmReadoutElement * readoutElement() const
Retrieve the associated MmReadoutElement.
MdtCalibTwinOutput::sigmaZ
double sigmaZ() const
Definition: MdtCalibTwinOutput.cxx:49
MuonR4::CalibratedSpacePoint::State::Outlier
@ Outlier
MuonR4::SpacePoint::secondaryMeasurement
const xAOD::UncalibratedMeasurement * secondaryMeasurement() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:78
MdtTwinDriftCircle.h
MuonGMR4::MuonReadoutElement::globalToLocalTrans
Amg::Transform3D globalToLocalTrans(const ActsGeometryContext &ctx) const
Transformations to translate between local <-> global coordinates.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:78
xAODUncalibMeasCalibrator.h
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::UncalibMeasType::sTgcStripType
@ sTgcStripType
MuonR4::SpacePoint::CovIdx::etaCov
@ etaCov
MuonCalib::MdtFullCalibData
class which holds the full set of calibration constants for a given tube
Definition: MdtFullCalibData.h:15
MuonGMR4::RpcReadoutElement::EdgeSide
EdgeSide
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:109
MdtCalibTwinOutput::uncertPrimaryR
double uncertPrimaryR() const
Definition: MdtCalibTwinOutput.cxx:52
MatrixUtils.h
AmgSymMatrix
#define AmgSymMatrix(dim)
Definition: EventPrimitives.h:50
Muon::MdtStatusDriftTime
@ MdtStatusDriftTime
The tube produced a vaild measurement.
Definition: MdtDriftCircleStatus.h:34
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
ActsTrk::detail::xAODUncalibMeasCalibrator::unpack
static const xAOD::UncalibratedMeasurement * unpack(const Acts::SourceLink &sl)
Helper method to unpack an Acts source link to an uncalibrated measurement.
Definition: xAODUncalibMeasCalibrator.cxx:12
xAOD::UncalibMeasType::TgcStripType
@ TgcStripType
MuonR4::CalibSpacePointVec
ISpacePointCalibrator::CalibSpacePointVec CalibSpacePointVec
Definition: SpacePointCalibrator.cxx:38
MuonR4::SpacePoint::primaryMeasurement
const xAOD::UncalibratedMeasurement * primaryMeasurement() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:75
xAOD::MMCluster_v1::layerHash
IdentifierHash layerHash() const
Returns the hash of the associated layer (Needed for surface retrieval)
Definition: MMCluster_v1.cxx:23
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
TRT::Hit::driftTime
@ driftTime
Definition: HitInfo.h:43
Muon::NswClustering::toLocal
Amg::Vector3D toLocal(const Amg::Transform3D &toLocalTrans, const Amg::Vector3D &dir)
Rotates a direction vector into a local frame: x-axis : Parallell to the radial direction of the dete...
Definition: NswClusteringUtils.h:21
MuonR4::SpacePointCalibrator::calibratesTGC
std::pair< double, double > calibratesTGC(const EventContext &ctx, const ActsGeometryContext &gctx, const xAOD::sTgcStripCluster &cluster, double posAlongTheStrip, const Amg::Vector3D &globalPos, const Amg::Vector3D &globalDir) const
Calibrates the position and covariance of an sTGC (small-strip Thin Gap Chamber) cluster.
Definition: SpacePointCalibrator.cxx:338
SG::get
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
Definition: ReadCondHandle.h:287
xAOD::MMCluster_v1::identify
const Identifier & identify() const
: Returns the Athena identifier of the micro mega cluster It's constructed from the measurementHash &...
Definition: MMCluster_v1.cxx:26
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MdtCalibOutput.h
AmgVector
AmgVector(4) T2BSTrackFilterTool
Definition: T2BSTrackFilterTool.cxx:114
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonR4::CalibratedSpacePoint::State::FailedCalib
@ FailedCalib
xAOD::MdtTwinDriftCircle_v1
Definition: MdtTwinDriftCircle_v1.h:12
MuonR4::CalibratedSpacePoint::State
State
State flag to distinguish different space point states.
Definition: CalibratedSpacePoint.h:24
MuonR4::SpacePointCalibrator::calibrateSourceLink
void calibrateSourceLink(const Acts::GeometryContext &geoctx, const Acts::CalibrationContext &cctx, const Acts::SourceLink &link, ActsTrk::MutableTrackContainer::TrackStateProxy state) const override final
Definition: SpacePointCalibrator.cxx:356
xAOD::Other
@ Other
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCalibTwinOutput::locZ
double locZ() const
Definition: MdtCalibTwinOutput.cxx:48
MuonR4::CalibratedSpacePoint::type
xAOD::UncalibMeasType type() const
Returns the space point type.
Definition: CalibratedSpacePoint.cxx:41
MdtCalibInput::setClosestApproach
void setClosestApproach(const Amg::Vector3D &approach)
Sets the closest approach.
Definition: MdtCalibInput.cxx:106
MuonR4::SpacePoint::covariance
const Cov_t & covariance() const
Returns the covariance array.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:61
xAOD::UncalibratedMeasurement_v1::localCovariance
ConstMatrixMap< N > localCovariance() const
Returns the local covariance of the measurement.
MuonR4::SpacePointCalibrator::driftVelocity
double driftVelocity(const EventContext &ctx, const CalibratedSpacePoint &spacePoint) const override final
Definition: SpacePointCalibrator.cxx:294
SpacePointCalibrator.h
F600IntegrationConfig.spacePoints
spacePoints
Definition: F600IntegrationConfig.py:122
MdtCalibOutput::status
MdtDriftCircleStatus status() const
Status of the calibration.
Definition: MdtCalibOutput.cxx:40
MdtCalibOutput
Definition: MdtCalibOutput.h:10
xAOD::UncalibratedMeasurement_v1::localPosition
ConstVectorMap< N > localPosition() const
Returns the local position of the measurement.
MuonR4::SpacePointCalibrator::driftAcceleration
double driftAcceleration(const EventContext &ctx, const CalibratedSpacePoint &spacePoint) const override final
Definition: SpacePointCalibrator.cxx:303
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MdtDriftCircle.h
MuonR4::CalibratedSpacePoint::State::Valid
@ Valid
MuonR4::SpacePoint
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:24
MuonR4::ISpacePointCalibrator::CalibSpacePointPtr
std::unique_ptr< CalibratedSpacePoint > CalibSpacePointPtr
Definition: ISpacePointCalibrator.h:30
TgcStrip.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonR4::sign
constexpr double sign(const double x)
Returns the sign of a number.
Definition: MatrixUtils.h:11
MuonR4::SpacePoint::CovIdx::phiCov
@ phiCov
MuonR4::CalibratedSpacePoint::fitState
State fitState() const
Returns the state of the calibrated space point.
Definition: CalibratedSpacePoint.cxx:51
xAOD::sTgcMeasurement_v1::readoutElement
const MuonGMR4::sTgcReadoutElement * readoutElement() const
Retrieve the associated sTgcReadoutElement.
RpcMeasurement.h
MdtCalibTwinOutput::primaryStatus
MdtDriftCircleStatus primaryStatus() const
Definition: MdtCalibTwinOutput.cxx:54
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:73
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition: throwExcept.h:10
python.copyTCTOutput.locDir
locDir
Definition: copyTCTOutput.py:110
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
MdtCalibOutput::driftRadiusUncert
double driftRadiusUncert() const
Returns the uncertainty on the drift radius.
Definition: MdtCalibOutput.cxx:20
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MultiTrajectory.h
ATH_LIKELY
#define ATH_LIKELY(x)
Definition: AthUnlikelyMacros.h:16
MuonR4::SpacePointCalibrator::calibrate
CalibSpacePointPtr calibrate(const EventContext &ctx, const SpacePoint *spacePoint, const Amg::Vector3D &seedPosInChamb, const Amg::Vector3D &seedDirInChamb, const double timeDelay) const override final
Definition: SpacePointCalibrator.cxx:80
MuonR4::SpacePoint::localPosition
const Amg::Vector3D & localPosition() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:50
MdtCalibTwinOutput
Definition: MdtCalibTwinOutput.h:11
MuonR4::CalibSpacePointPtr
ISpacePointCalibrator::CalibSpacePointPtr CalibSpacePointPtr
Definition: SpacePointCalibrator.cxx:39
SegmentFitterEventData.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MdtReadoutElement.h
MuonGMR4::SpectrometerSector::localToGlobalTrans
const Amg::Transform3D & localToGlobalTrans(const ActsGeometryContext &gctx) const
Returns the local -> global tarnsformation from the sector.
Definition: SpectrometerSector.cxx:75
MuonR4::CalibratedSpacePoint
The calibrated Space point is created during the calibration process.
Definition: CalibratedSpacePoint.h:14
MdtFullCalibData.h
MuonR4::SpacePoint::dimension
unsigned dimension() const
Is the space point a 1D or combined 2D measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:107
xAOD::UncalibMeasType
UncalibMeasType
Define the type of the uncalibrated measurement.
Definition: MeasurementDefs.h:25
MuonGMR4::MuonReadoutElement::localToGlobalTrans
const Amg::Transform3D & localToGlobalTrans(const ActsGeometryContext &ctx) const
Returns the local to global transformation into the ATLAS coordinate system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonReadoutElement.cxx:81
MMCluster.h
MdtCalibTwinOutput::primaryDriftR
double primaryDriftR() const
Definition: MdtCalibTwinOutput.cxx:50
xAOD::MdtDriftCircle_v1
https://gitlab.cern.ch/atlas/athena/-/blob/master/MuonSpectrometer/MuonReconstruction/MuonRecEvent/Mu...
Definition: MdtDriftCircle_v1.h:21
Muon::MMClusterOnTrack::Author
Author
Definition: MMClusterOnTrack.h:89
MuonR4::CalibratedSpacePoint::spacePoint
const SpacePoint * spacePoint() const
The pointer to the space point out of which this space point has been built.
Definition: CalibratedSpacePoint.cxx:15
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
xAOD::UncalibMeasType::RpcStripType
@ RpcStripType
xAOD::RpcMeasurement_v1::time
float time() const
Returns the time.
MuonR4::CalibratedSpacePoint::driftRadius
double driftRadius() const
: Returns the size of the drift radius
Definition: CalibratedSpacePoint.cxx:37
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
MdtCalibOutput::driftRadius
double driftRadius() const
Returns the drift radius of the calibrated object.
Definition: MdtCalibOutput.cxx:19
MuonR4::SpacePoint::identify
const Identifier & identify() const
: Identifier of the primary measurement
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:97
xAOD::sTgcMeasurement_v1
Definition: sTgcMeasurement_v1.h:21
MuonR4::SpacePointCalibrator::calibrateMM
std::pair< double, double > calibrateMM(const EventContext &ctx, const ActsGeometryContext &gctx, const xAOD::MMCluster &cluster, const Amg::Vector3D &globalPos, const Amg::Vector3D &globalDir) const
Calibrates the position and covariance of a MicroMegas (MM) cluster.
Definition: SpacePointCalibrator.cxx:314
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
MuonR4::SpacePoint::sensorDirection
const Amg::Vector3D & sensorDirection() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:51
MuonR4::SpacePointCalibrator::initialize
StatusCode initialize() override final
Definition: SpacePointCalibrator.cxx:43