ATLAS Offline Software
CalibSegmentChi2Minimizer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
8 #include "GaudiKernel/PhysicalConstants.h"
9 namespace {
10  constexpr double c_inv{1./ Gaudi::Units::c_light};
11 }
12 
13 
14 namespace MuonR4{
17  using namespace SegmentFit;
18 
20  const EventContext& ctx,
21  const Amg::Transform3D& locToGlobTrf,
22  HitVec&& hits,
23  const ISpacePointCalibrator* calibrator,
24  bool doT0Fit):
26  m_name{name},
27  m_ctx{ctx},
28  m_locToGlob{locToGlobTrf},
29  m_hits{std::move(hits)},
30  m_calibrator{calibrator},
31  m_doT0Fit{doT0Fit} {
32 
33 
34  for (const HitType& hit : m_hits) {
35  if (hit->fitState() != CalibratedSpacePoint::State::Valid){
36  continue;
37  }
39  if (hit->type() == xAOD::UncalibMeasType::Other) {
40  m_nMeas +=2;
41  m_hasPhi = true;
42  continue;
43  }
44  m_nMeas += hit->spacePoint()->measuresEta();
45  m_nMeas += hit->spacePoint()->measuresPhi();
46  m_hasPhi |= hit->spacePoint()->measuresPhi();
47  if (m_doT0Fit && hit->measuresTime() && hit->type() != xAOD::UncalibMeasType::MdtDriftCircleType) {
48  ++m_nMeas;
49  }
50  }
51  if (m_nMeas - 2 - (m_hasPhi ? 2 : 0) <= 1) {
52  m_doT0Fit = false;
53  }
54  std::ranges::sort(m_hits,
55  [](const HitType& a, const HitType& b) {
56  return a->positionInChamber().z() < b->positionInChamber().z();
57  });
58  }
59 
61  HitVec copyHits{};
62  for (const HitType& copyMe : m_hits) {
63  copyHits.emplace_back(std::make_unique<CalibratedSpacePoint>(*copyMe));
64  }
65  return new CalibSegmentChi2Minimizer(m_name, m_ctx, m_locToGlob, std::move(copyHits), m_calibrator, m_doT0Fit);
66  }
68  return m_locToGlob;
69  }
70  unsigned int CalibSegmentChi2Minimizer::NDim() const {
71  return toInt(ParamDefs::nPars);
72  }
74  return m_doT0Fit;
75  }
77  return m_nMeas - 2 - (m_hasPhi ? 2 : 0) - m_doT0Fit;
78  }
80  return m_hasPhi;
81  }
83  return m_hits;
84  }
86 
87  Parameters parVec{Parameters::Zero()};
88  for (int p = 0 ; p < toInt(ParamDefs::nPars); ++p) {
89  parVec[p] = pars[p];
90  }
91  const auto[segPos, segDir] = makeLine(parVec);
92  const double timeDelay = pars[toInt(ParamDefs::time)];
93  HitVec released = m_calibrator->calibrate(m_ctx, std::move(m_hits), segPos, segDir, timeDelay);
94  m_hits.clear();
95  return released;
96  }
97  double CalibSegmentChi2Minimizer::DoEval(const double* pars) const {
98 
99  Parameters parVec{Parameters::Zero()};
100  for (int p = 0 ; p < toInt(ParamDefs::nPars); ++p) {
101  parVec[p] = pars[p];
102  }
103  const auto[segPos, segDir] = makeLine(parVec);
104 
105  const double timeDelay = pars[toInt(ParamDefs::time)];
106  ATH_MSG_VERBOSE("Starting parameters position: "<<Amg::toString(segPos)<<", direction: "<<Amg::toString(segDir)
107  <<", timeDelay: "<<timeDelay<<". Do time fit "<<m_doT0Fit);
108 
109  m_hits = m_calibrator->calibrate(m_ctx, std::move(m_hits), segPos, segDir, timeDelay);
110 
111  double chi2{0.};
112  std::optional<double> arrivalTime = std::nullopt;
113  if (m_doT0Fit) {
114  arrivalTime = std::make_optional<double>( (m_locToGlob *segPos).mag() * c_inv + timeDelay);
115  }
116  for (const HitType& hit : m_hits) {
117  chi2 += SegmentFitHelpers::chiSqTerm(segPos,segDir, timeDelay, arrivalTime, *hit, msg());
118  }
119  ATH_MSG_VERBOSE("Final chi2: "<<chi2);
120  return chi2;
121  }
122 }
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MuonR4::CalibSegmentChi2Minimizer::localToGlobTrans
const Amg::Transform3D & localToGlobTrans() const
Returns the local to global transformation.
Definition: CalibSegmentChi2Minimizer.cxx:67
MuonR4::HitType
CalibSegmentChi2Minimizer::HitType HitType
Definition: CalibSegmentChi2Minimizer.cxx:15
MuonR4::SegmentFit::Parameters
AmgVector(toInt(ParamDefs::nPars)) Parameters
Definition: MuonHoughDefs.h:48
MuonR4::CalibSegmentChi2Minimizer::CalibSegmentChi2Minimizer
CalibSegmentChi2Minimizer(const std::string &name, const EventContext &ctx, const Amg::Transform3D &locToGlobTrf, HitVec &&hits, const ISpacePointCalibrator *calibrator, bool doT0Fit)
Constructor taking the input hits to fit.
Definition: CalibSegmentChi2Minimizer.cxx:19
MuonR4::HitVec
SpacePointPerLayerSorter::HitVec HitVec
Definition: SpacePointPerLayerSorter.cxx:9
ISpacePointCalibrator.h
MuonR4::ISpacePointCalibrator::calibrate
virtual CalibSpacePointPtr calibrate(const EventContext &ctx, const SpacePoint *spacePoint, const Amg::Vector3D &seedPosInChamb, const Amg::Vector3D &seedDirInChamb, const double timeDelay) const =0
Calibrates a single space point.
MuonR4::CalibSegmentChi2Minimizer::HitVec
std::vector< HitType > HitVec
Definition: CalibSegmentChi2Minimizer.h:25
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
MuonR4::SegmentFitHelpers::chiSqTerm
double chiSqTerm(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const SpacePoint &measurement, MsgStream &msg)
Calculates the chi2 contribuation to a linear segment line from an uncalibrated measurement.
Definition: SegmentFitHelperFunctions.cxx:27
MuonR4::SegmentFit::makeLine
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
Definition: SegmentFitterEventData.cxx:30
MuonR4::CalibSegmentChi2Minimizer::Clone
CalibSegmentChi2Minimizer * Clone() const override final
Clone of the object.
Definition: CalibSegmentChi2Minimizer.cxx:60
MuonR4::CalibSegmentChi2Minimizer::HitType
std::unique_ptr< CalibratedSpacePoint > HitType
Definition: CalibSegmentChi2Minimizer.h:24
MuonR4::CalibSegmentChi2Minimizer::m_hasPhi
bool m_hasPhi
Definition: CalibSegmentChi2Minimizer.h:75
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
z
#define z
SegmentFitHelperFunctions.h
MuonR4::CalibSegmentChi2Minimizer::DoEval
double DoEval(const double *pars) const override final
Evaluate the chi2 for the given set of parameters.
Definition: CalibSegmentChi2Minimizer.cxx:97
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonR4::CalibSegmentChi2Minimizer::doTimeFit
bool doTimeFit() const
Does the fit include the time.
Definition: CalibSegmentChi2Minimizer.cxx:73
MuonR4::CalibSegmentChi2Minimizer::hasPhiMeas
bool hasPhiMeas() const
Are phi measurements in the collection.
Definition: CalibSegmentChi2Minimizer.cxx:79
chi2
double chi2(TH1 *h0, TH1 *h1)
Definition: comparitor.cxx:522
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
xAOD::Other
@ Other
MuonR4::CalibSegmentChi2Minimizer::m_nMeas
unsigned int m_nMeas
Definition: CalibSegmentChi2Minimizer.h:76
MuonR4::CalibSegmentChi2Minimizer::release
HitVec release(const double *pars)
Releases all measurements.
Definition: CalibSegmentChi2Minimizer.cxx:85
HitType
HitType
Definition: FPGATrackSimHit.h:38
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
MuonR4::SegmentFit::ParamDefs::time
@ time
MuonR4::CalibratedSpacePoint::State::Valid
@ Valid
MuonR4::CalibSegmentChi2Minimizer::NDim
unsigned int NDim() const override final
Degrees of freedom.
Definition: CalibSegmentChi2Minimizer.cxx:70
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MuonR4::SegmentFit::toInt
constexpr int toInt(const ParamDefs p)
Definition: MuonHoughDefs.h:42
MuonR4::CalibSegmentChi2Minimizer::measurements
const HitVec & measurements() const
Returns the used measurements.
Definition: CalibSegmentChi2Minimizer.cxx:82
MuonR4::CalibSegmentChi2Minimizer::m_name
std::string m_name
Definition: CalibSegmentChi2Minimizer.h:58
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
MuonR4::ISpacePointCalibrator
Interface class to refine the space point calibration with an external seed.
Definition: ISpacePointCalibrator.h:19
MuonR4::CalibSegmentChi2Minimizer::m_doT0Fit
bool m_doT0Fit
Definition: CalibSegmentChi2Minimizer.h:63
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
a
TList * a
Definition: liststreamerinfos.cxx:10
SegmentFitterEventData.h
MuonR4::CalibSegmentChi2Minimizer::nDoF
int nDoF() const
Returns the degrees of freedom from the measurements & beamspot constraint.
Definition: CalibSegmentChi2Minimizer.cxx:76
MuonR4::CalibSegmentChi2Minimizer::m_locToGlob
Amg::Transform3D m_locToGlob
Definition: CalibSegmentChi2Minimizer.h:60
MuonR4::CalibSegmentChi2Minimizer
Definition: CalibSegmentChi2Minimizer.h:21
MuonR4::CalibSegmentChi2Minimizer::m_ctx
const EventContext & m_ctx
Definition: CalibSegmentChi2Minimizer.h:59
MuonR4::CalibSegmentChi2Minimizer::m_calibrator
const ISpacePointCalibrator * m_calibrator
Definition: CalibSegmentChi2Minimizer.h:62
xAOD::UncalibMeasType::MdtDriftCircleType
@ MdtDriftCircleType
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:26
CalibSegmentChi2Minimizer.h
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32