ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MuonR4::CalibSegmentChi2Minimizer Class Reference

#include <CalibSegmentChi2Minimizer.h>

Inheritance diagram for MuonR4::CalibSegmentChi2Minimizer:
Collaboration diagram for MuonR4::CalibSegmentChi2Minimizer:

Public Types

using HitType = std::unique_ptr< CalibratedSpacePoint >
 
using HitVec = std::vector< HitType >
 

Public Member Functions

 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. More...
 
double DoEval (const double *pars) const override final
 Evaluate the chi2 for the given set of parameters. More...
 
CalibSegmentChi2MinimizerClone () const override final
 Clone of the object. More...
 
unsigned int NDim () const override final
 Degrees of freedom. More...
 
bool hasPhiMeas () const
 Are phi measurements in the collection. More...
 
bool doTimeFit () const
 Does the fit include the time. More...
 
int nDoF () const
 Returns the degrees of freedom from the measurements & beamspot constraint. More...
 
const HitVecmeasurements () const
 Returns the used measurements. More...
 
std::vector< double > chi2Terms (const double *pars) const
 Returns the contribution of each measurement to the chi2. More...
 
HitVec release (const double *pars)
 Releases all measurements. More...
 
const Amg::Transform3DlocalToGlobTrans () const
 Returns the local to global transformation. More...
 

Private Member Functions

double segmentChi2TermStrip (const CalibratedSpacePoint &hit, const Amg::Vector3D &chamberIsect, const Amg::Vector3D &segmentDir) const
 
double segmentChi2TermMdt (const CalibratedSpacePoint &hit, const Amg::Vector3D &chamberIsect, const Amg::Vector3D &segmentDir) const
 
bool msgLvl (const MSG::Level lvl) const
 Test the output level. More...
 
MsgStream & msg () const
 The standard message stream. More...
 
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream. More...
 
void setLevel (MSG::Level lvl)
 Change the current logging level. More...
 
void initMessaging () const
 Initialize our message level and MessageSvc. More...
 

Private Attributes

std::string m_name {}
 
const EventContext & m_ctx
 
Amg::Transform3D m_locToGlob {Amg::Transform3D::Identity()}
 
HitVec m_hits ATLAS_THREAD_SAFE {}
 
const ISpacePointCalibratorm_calibrator {}
 
bool m_doT0Fit {false}
 
bool m_hasPhi {false}
 
unsigned int m_nMeas {0}
 
std::string m_nm
 Message source name. More...
 
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels) More...
 
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer. More...
 
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level. More...
 

Detailed Description

Definition at line 21 of file CalibSegmentChi2Minimizer.h.

Member Typedef Documentation

◆ HitType

Definition at line 24 of file CalibSegmentChi2Minimizer.h.

◆ HitVec

Definition at line 25 of file CalibSegmentChi2Minimizer.h.

Constructor & Destructor Documentation

◆ CalibSegmentChi2Minimizer()

MuonR4::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.

Beam spot constraint

Definition at line 19 of file CalibSegmentChi2Minimizer.cxx.

24  :
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  }

Member Function Documentation

◆ chi2Terms()

std::vector<double> MuonR4::CalibSegmentChi2Minimizer::chi2Terms ( const double *  pars) const

Returns the contribution of each measurement to the chi2.

◆ Clone()

CalibSegmentChi2Minimizer * MuonR4::CalibSegmentChi2Minimizer::Clone ( ) const
finaloverride

Clone of the object.

Definition at line 60 of file CalibSegmentChi2Minimizer.cxx.

60  {
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  }

◆ DoEval()

double MuonR4::CalibSegmentChi2Minimizer::DoEval ( const double *  pars) const
finaloverride

Evaluate the chi2 for the given set of parameters.

Definition at line 97 of file CalibSegmentChi2Minimizer.cxx.

97  {
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  }

◆ doTimeFit()

bool MuonR4::CalibSegmentChi2Minimizer::doTimeFit ( ) const

Does the fit include the time.

Definition at line 73 of file CalibSegmentChi2Minimizer.cxx.

73  {
74  return m_doT0Fit;
75  }

◆ hasPhiMeas()

bool MuonR4::CalibSegmentChi2Minimizer::hasPhiMeas ( ) const

Are phi measurements in the collection.

Definition at line 79 of file CalibSegmentChi2Minimizer.cxx.

79  {
80  return m_hasPhi;
81  }

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40 {
42  m_lvl = m_imsg ?
43  static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
44  MSG::INFO;
45 }

◆ localToGlobTrans()

const Amg::Transform3D & MuonR4::CalibSegmentChi2Minimizer::localToGlobTrans ( ) const

Returns the local to global transformation.

Definition at line 67 of file CalibSegmentChi2Minimizer.cxx.

67  {
68  return m_locToGlob;
69  }

◆ measurements()

const HitVec & MuonR4::CalibSegmentChi2Minimizer::measurements ( ) const

Returns the used measurements.

Definition at line 82 of file CalibSegmentChi2Minimizer.cxx.

82  {
83  return m_hits;
84  }

◆ msg() [1/2]

MsgStream & AthMessaging::msg ( ) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 164 of file AthMessaging.h.

165 {
166  MsgStream* ms = m_msg_tls.get();
167  if (!ms) {
168  if (!m_initialized.test_and_set()) initMessaging();
169  ms = new MsgStream(m_imsg,m_nm);
170  m_msg_tls.reset( ms );
171  }
172 
173  ms->setLevel (m_lvl);
174  return *ms;
175 }

◆ msg() [2/2]

MsgStream & AthMessaging::msg ( const MSG::Level  lvl) const
inlineinherited

The standard message stream.

Returns a reference to the default message stream May not be invoked before sysInitialize() has been invoked.

Definition at line 179 of file AthMessaging.h.

180 { return msg() << lvl; }

◆ msgLvl()

bool AthMessaging::msgLvl ( const MSG::Level  lvl) const
inlineinherited

Test the output level.

Parameters
lvlThe message level to test against
Returns
boolean Indicating if messages at given level will be printed
Return values
trueMessages at level "lvl" will be printed

Definition at line 151 of file AthMessaging.h.

152 {
153  if (!m_initialized.test_and_set()) initMessaging();
154  if (m_lvl <= lvl) {
155  msg() << lvl;
156  return true;
157  } else {
158  return false;
159  }
160 }

◆ NDim()

unsigned int MuonR4::CalibSegmentChi2Minimizer::NDim ( ) const
finaloverride

Degrees of freedom.

Definition at line 70 of file CalibSegmentChi2Minimizer.cxx.

70  {
71  return toInt(ParamDefs::nPars);
72  }

◆ nDoF()

int MuonR4::CalibSegmentChi2Minimizer::nDoF ( ) const

Returns the degrees of freedom from the measurements & beamspot constraint.

Definition at line 76 of file CalibSegmentChi2Minimizer.cxx.

76  {
77  return m_nMeas - 2 - (m_hasPhi ? 2 : 0) - m_doT0Fit;
78  }

◆ release()

HitVec MuonR4::CalibSegmentChi2Minimizer::release ( const double *  pars)

Releases all measurements.

Definition at line 85 of file CalibSegmentChi2Minimizer.cxx.

85  {
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  }

◆ segmentChi2TermMdt()

double MuonR4::CalibSegmentChi2Minimizer::segmentChi2TermMdt ( const CalibratedSpacePoint hit,
const Amg::Vector3D chamberIsect,
const Amg::Vector3D segmentDir 
) const
private

◆ segmentChi2TermStrip()

double MuonR4::CalibSegmentChi2Minimizer::segmentChi2TermStrip ( const CalibratedSpacePoint hit,
const Amg::Vector3D chamberIsect,
const Amg::Vector3D segmentDir 
) const
private

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level  lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29 {
30  m_lvl = lvl;
31 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

HitVec m_hits MuonR4::CalibSegmentChi2Minimizer::ATLAS_THREAD_SAFE {}
mutableprivate

Definition at line 61 of file CalibSegmentChi2Minimizer.h.

◆ m_calibrator

const ISpacePointCalibrator* MuonR4::CalibSegmentChi2Minimizer::m_calibrator {}
private

Definition at line 62 of file CalibSegmentChi2Minimizer.h.

◆ m_ctx

const EventContext& MuonR4::CalibSegmentChi2Minimizer::m_ctx
private

Definition at line 59 of file CalibSegmentChi2Minimizer.h.

◆ m_doT0Fit

bool MuonR4::CalibSegmentChi2Minimizer::m_doT0Fit {false}
private

Definition at line 63 of file CalibSegmentChi2Minimizer.h.

◆ m_hasPhi

bool MuonR4::CalibSegmentChi2Minimizer::m_hasPhi {false}
private

Definition at line 75 of file CalibSegmentChi2Minimizer.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

◆ m_locToGlob

Amg::Transform3D MuonR4::CalibSegmentChi2Minimizer::m_locToGlob {Amg::Transform3D::Identity()}
private

Definition at line 60 of file CalibSegmentChi2Minimizer.h.

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels)

Definition at line 132 of file AthMessaging.h.

◆ m_name

std::string MuonR4::CalibSegmentChi2Minimizer::m_name {}
private

Definition at line 58 of file CalibSegmentChi2Minimizer.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_nMeas

unsigned int MuonR4::CalibSegmentChi2Minimizer::m_nMeas {0}
private

Definition at line 76 of file CalibSegmentChi2Minimizer.h.


The documentation for this class was generated from the following files:
AthMessaging::m_lvl
std::atomic< MSG::Level > m_lvl
Current logging level.
Definition: AthMessaging.h:138
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
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::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
AthMessaging::m_imsg
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
Definition: AthMessaging.h:135
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
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
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
z
#define z
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
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
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::m_name
std::string m_name
Definition: CalibSegmentChi2Minimizer.h:58
MuonR4::CalibSegmentChi2Minimizer::m_doT0Fit
bool m_doT0Fit
Definition: CalibSegmentChi2Minimizer.h:63
a
TList * a
Definition: liststreamerinfos.cxx:10
AthMessaging::m_nm
std::string m_nm
Message source name.
Definition: AthMessaging.h:129
MuonR4::CalibSegmentChi2Minimizer::m_locToGlob
Amg::Transform3D m_locToGlob
Definition: CalibSegmentChi2Minimizer.h:60
AthMessaging::initMessaging
void initMessaging() const
Initialize our message level and MessageSvc.
Definition: AthMessaging.cxx:39
MuonR4::CalibSegmentChi2Minimizer::m_ctx
const EventContext & m_ctx
Definition: CalibSegmentChi2Minimizer.h:59
AthMessaging::m_msg_tls
boost::thread_specific_ptr< MsgStream > m_msg_tls
MsgStream instance (a std::cout like with print-out levels)
Definition: AthMessaging.h:132
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
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32