ATLAS Offline Software
SegmentRefitTest.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 "SegmentRefitTest.h"
5 
9 
15 
16 using namespace MuonR4::SegmentFit;
17 
18 namespace MuonValR4{
20  ATH_CHECK(m_preFitKey.initialize());
21  ATH_CHECK(m_postFitKey.initialize());
22  ATH_CHECK(m_linkKey.initialize());
23  ATH_CHECK(m_idHelperSvc.retrieve());
24 
25  ATH_CHECK(m_tree.init(this));
26  return StatusCode::SUCCESS;
27  }
29  ATH_CHECK(m_tree.write());
30  return StatusCode::SUCCESS;
31  }
32 
34  const EventContext& ctx{Gaudi::Hive::currentContext()};
35  const xAOD::MuonSegmentContainer* postFitSegments{nullptr};
36  ATH_CHECK(SG::get(postFitSegments, m_postFitKey, ctx));
37 
41  std::unordered_set<const xAOD::MuonSegment*> filledPreFits{};
42  auto fillPrefit = [&] (const xAOD::MuonSegment* seg) -> StatusCode {
43  if (!filledPreFits.insert(seg).second) {
44  return StatusCode::SUCCESS;
45  }
46  const MuonR4::Segment* reFitMe = MuonR4::detailedSegment(*seg);
47 
48  auto preFitPars = localSegmentPars(*seg);
49  m_chamberIndex = Acts::toUnderlying(reFitMe->msSector()->chamberIndex());
50  m_stationSide = reFitMe->msSector()->side();
51  m_stationPhi = reFitMe->msSector()->stationPhi();
53  m_preFitLocX = preFitPars[Acts::toUnderlying(ParamDefs::x0)];
54  m_preFitLocY = preFitPars[Acts::toUnderlying(ParamDefs::y0)];
55  m_preFitTheta = preFitPars[Acts::toUnderlying(ParamDefs::theta)];
56  m_preFitPhi = preFitPars[Acts::toUnderlying(ParamDefs::phi)];
58  m_uncertLocX = Amg::error(reFitMe->covariance(), Acts::toUnderlying(ParamDefs::x0));
59  m_uncertLocY = Amg::error(reFitMe->covariance(), Acts::toUnderlying(ParamDefs::y0));
60  m_uncertTheta = Amg::error(reFitMe->covariance(), Acts::toUnderlying(ParamDefs::theta));
61  m_uncertPhi = Amg::error(reFitMe->covariance(), Acts::toUnderlying(ParamDefs::phi));
62 
63  m_preFitChi2 = reFitMe->chi2();
64  m_preFitNdoF = reFitMe->nDoF();
65  m_preFitNPrecHits = reFitMe->summary().nPrecHits;
66  m_preFitNTrigEtaHits = reFitMe->summary().nEtaTrigHits;
67  m_preFitNTrigPhiHits = reFitMe->summary().nPhiHits;
68  return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
69  };
71  for (const xAOD::MuonSegment* seg: *postFitSegments){
72  m_postFitChi2 = seg->chiSquared();
73  m_postFitNdoF = seg->numberDoF();
74  m_postFitNPrecHits = seg->nPrecisionHits();
75  m_postFitNTrigEtaHits = seg->nTrigEtaLayers();
76  m_postFitNTrigPhiHits = seg->nPhiLayers();
77  const auto segPars = localSegmentPars(*seg);
78  m_postFitLocX = segPars[Acts::toUnderlying(ParamDefs::x0)];
79  m_postFitLocY = segPars[Acts::toUnderlying(ParamDefs::y0)];
80  m_postFitTheta = segPars[Acts::toUnderlying(ParamDefs::theta)];
81  m_postFitPhi = segPars[Acts::toUnderlying(ParamDefs::phi)];
82  static const SG::ConstAccessor<xAOD::MeasVector<Acts::toUnderlying(ParamDefs::nPars)>> acc_seed{"seedSegPars"};
83  m_seedFitLocY = acc_seed(*seg)[Acts::toUnderlying(ParamDefs::y0)];
84  m_seedFitTheta = acc_seed(*seg)[Acts::toUnderlying(ParamDefs::theta)];
85  m_seedFitLocX = acc_seed(*seg)[Acts::toUnderlying(ParamDefs::x0)];
86  m_seedFitPhi = acc_seed(*seg)[Acts::toUnderlying(ParamDefs::phi)];
87 
88  m_goodFit = true;
89  ATH_CHECK(fillPrefit((*acc_segLink(*seg))));
90  }
91  const xAOD::MuonSegmentContainer* preFitSegments{nullptr};
92  ATH_CHECK(SG::get(preFitSegments, m_preFitKey, ctx));
93  for (const xAOD::MuonSegment* preFit: *preFitSegments) {
94  ATH_CHECK(fillPrefit(preFit));
95  }
96  ATH_MSG_DEBUG("Processing done");
97  return StatusCode::SUCCESS;
98  }
99 }
MuonR4::Segment::summary
const HitSummary & summary() const
Returns the hit summary.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:74
MuonR4::SegmentFit
Definition: MuonHoughDefs.h:33
MuonGMR4::SpectrometerSector::side
int8_t side() const
Returns the side of the MS-sector 1 -> A side ; -1 -> C side.
Definition: SpectrometerSector.cxx:57
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
MuonGMR4::SpectrometerSector::stationPhi
int stationPhi() const
: Returns the station phi of the sector
Definition: SpectrometerSector.cxx:63
EventPrimitivesHelpers.h
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
SegmentRefitTest.h
MuonR4::Segment::chi2
double chi2() const
Returns the chi2 of the segment fit.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:45
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
xAODUncalibMeasCalibrator.h
SpectrometerSector.h
MuonR4::Segment::nDoF
unsigned int nDoF() const
Returns the number of degrees of freedom.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:47
MuonR4::Segment::HitSummary::nEtaTrigHits
unsigned nEtaTrigHits
Number of good Rpc / Tgc eta hits.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:65
MuonR4::detailedSegment
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
Definition: TrackingHelpers.cxx:7
MuonValR4::SegmentRefitTest::initialize
virtual StatusCode initialize() override final
Definition: SegmentRefitTest.cxx:19
MuonGMR4::SpectrometerSector::chamberIndex
Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index scheme.
Definition: SpectrometerSector.cxx:62
CalibrationContext.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonValR4::SegmentRefitTest::finalize
virtual StatusCode finalize() override final
Definition: SegmentRefitTest.cxx:28
MuonR4::Segment::msSector
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:39
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonValR4
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Definition: IPatternVisualizationTool.h:23
xAOD::MeasVector
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
Definition: MeasurementDefs.h:53
MuonR4::Segment::HitSummary::nPrecHits
unsigned nPrecHits
Number of good Mdt / Mm / sTgc eta hits.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:63
TrackingHelpers.h
Amg::error
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
Definition: EventPrimitivesHelpers.h:40
SegmentFitterEventData.h
GeoPrimitivesToStringConverter.h
MuonR4::SegmentFit::localSegmentPars
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
Definition: SegmentFitterEventData.cxx:33
ReadDecorHandle.h
Handle class for reading a decoration on an object.
MuonValR4::SegmentRefitTest::execute
virtual StatusCode execute() override final
Definition: SegmentRefitTest.cxx:33
MuonR4::Segment::HitSummary::nPhiHits
unsigned nPhiHits
Number of good Rpc / Tgc / sTgc phi hits.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:67
MuonR4::Segment::covariance
const SegmentFit::Covariance & covariance() const
Returns the uncertainties of the defining parameters.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:53