ATLAS Offline Software
MuonSegmentFittingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <Math/Functor.h>
9 
10 using namespace MuonR4;
11 
13  ISvcLocator* pSvcLocator)
14  : AthReentrantAlgorithm(name, pSvcLocator) {}
15 
20 
21  return StatusCode::SUCCESS;
22 }
23 
24 StatusCode MuonSegmentFittingAlg::execute(const EventContext& ctx) const {
25 
28  const StationHoughSegmentSeedContainer* segmentSeeds=nullptr;
31  m_outSegments, ctx);
32  ATH_CHECK(writeSegments.record(
33  std::make_unique<MuonSegmentContainer>()));
34  for (const StationHoughSegmentSeeds & stationWithMax : *segmentSeeds){
35  for (auto & seed : stationWithMax.getMaxima()){
38  if (data.foundMin){
39  writeSegments->push_back(buildSegment(data));
40  }
41  }
42  }
43 
44  return StatusCode::SUCCESS;
45 }
46 
47 template <class ContainerType>
49  const EventContext& ctx, const SG::ReadHandleKey<ContainerType>& key,
50  const ContainerType*& contToPush) const {
51  contToPush = nullptr;
52  if (key.empty()) {
53  ATH_MSG_VERBOSE("No key has been parsed for object "
54  << typeid(ContainerType).name());
55  return StatusCode::SUCCESS;
56  }
57  SG::ReadHandle<ContainerType> readHandle{key, ctx};
58  ATH_CHECK(readHandle.isPresent());
59  contToPush = readHandle.cptr();
60  return StatusCode::SUCCESS;
61 }
62 
64  data.chi2 = -1;
65  data.measurementsToFit = seed.getHitsInMax();
66  data.foundMin = false;
67  data.x0 = seed.interceptX();
68  data.y0 = seed.interceptY();
69  data.tanTheta = seed.tanTheta();
70  data.tanPhi = seed.tanPhi();
71  data.minimizer->SetVariable((int)MuonSegmentFitterEventData::parameterIndices::y0,"y0",data.y0,1.e-5);
72  data.minimizer->SetVariable((int)MuonSegmentFitterEventData::parameterIndices::x0,"x0",data.x0,1.e-5);
73  data.minimizer->SetVariable((int)MuonSegmentFitterEventData::parameterIndices::tanTheta,"tanTheta",data.tanTheta,1.e-5);
74  data.minimizer->SetVariable((int)MuonSegmentFitterEventData::parameterIndices::tanPhi,"tanPhi",data.tanPhi,1.e-5);
75  data.minimizer->SetVariableLimits((int)MuonSegmentFitterEventData::parameterIndices::y0,data.y0 - 600, data.y0 + 600);
76  data.minimizer->SetVariableLimits((int)MuonSegmentFitterEventData::parameterIndices::x0,data.x0 - 600, data.x0 + 600);
77  data.minimizer->SetVariableLimits((int)MuonSegmentFitterEventData::parameterIndices::tanTheta,data.tanTheta - 0.6, data.tanTheta + 0.6);
78  data.minimizer->SetVariableLimits((int)MuonSegmentFitterEventData::parameterIndices::tanPhi,data.tanPhi - 0.6, data.tanPhi + 0.6);
79  data.minimizer->SetMaxFunctionCalls(1e8); // for Minuit/Minuit2
80  data.minimizer->SetMaxIterations(1e8); // for GSL
81  data.minimizer->SetTolerance(0.0001);
82  data.minimizer->SetStrategy(1);
83  data.minimizer->SetPrintLevel(0);
84  data.chi2_per_measurement.clear();
85  data.chi2_per_measurement.resize(2 * data.measurementsToFit.size());
86  return StatusCode::SUCCESS;
87 }
89  const ActsGeometryContext* gctx{nullptr};
91  data.gctx = gctx;
92  return StatusCode::SUCCESS;
93 }
94 
96  ROOT::Math::Functor c2f(std::bind(SegmentFitHelpers::segmentChiSquare, std::placeholders::_1, data.measurementsToFit, data.chi2_per_measurement),4);
97  data.minimizer->SetFunction(c2f);
98  // do the minimization
99  if (!data.minimizer->Minimize()){
100  data.minimizer->SetStrategy(2);
101  data.minimizer->Minimize();
102  }
103  data.minimizer->Hesse();
104  const double* xs = data.minimizer->X();
105  const double* errs = data.minimizer->Errors();
106  SegmentFitHelpers::segmentChiSquare(xs, data.measurementsToFit, data.chi2_per_measurement); // updates the event data's chi2 per layer
115  data.chi2 = c2f(xs);
116  data.foundMin = true;
117 
118  return StatusCode::SUCCESS;
119 }
120 
122  // dummy
123  std::vector<const xAOD::UncalibratedMeasurement*> measurements;
124  for (auto hit : data.measurementsToFit){
125  if (hit->primaryMeasurement()) measurements.push_back(hit->primaryMeasurement());
126  if (hit->secondaryMeasurement()) measurements.push_back(hit->secondaryMeasurement());
127  }
128  MuonSegment segment(data.y0, data.x0, data.tanTheta, data.tanPhi, measurements);
129  segment.setChi2(data.chi2);
130  segment.setChi2PerMeasurement(data.chi2_per_measurement);
131  return segment;
132 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonR4::MuonSegmentFittingAlg::buildSegment
MuonR4::MuonSegment buildSegment(MuonSegmentFitterEventData &data) const
Definition: MuonSegmentFittingAlg.cxx:121
MuonR4::MuonSegmentFitterEventData_impl::parameterIndices::tanTheta
@ tanTheta
MuonR4::SegmentFitHelpers::segmentChiSquare
double segmentChiSquare(const double *par, const std::vector< MuonR4::HoughHitType > &hits, std::vector< double > &chi2PerMeas)
Definition: SegmentFitHelperFunctions.cxx:24
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MuonR4::StationHoughSegmentSeedContainer
std::set< StationHoughSegmentSeeds > StationHoughSegmentSeedContainer
Definition: StationHoughMaxContainer.h:13
MuonR4::MuonSegment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/MuonPatternRecognition/MuonPatternEvent/MuonPatternEvent/MuonSegment.h:18
HoughHelperFunctions.h
MuonR4::MuonSegmentFittingAlg::MuonSegmentFittingAlg
MuonSegmentFittingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonSegmentFittingAlg.cxx:12
MuonR4::MuonSegmentFittingAlg::m_inHoughSegmentSeedKey
SG::ReadHandleKey< MuonR4::StationHoughSegmentSeedContainer > m_inHoughSegmentSeedKey
Definition: MuonSegmentFittingAlg.h:47
MuonR4::MuonSegmentFitterEventData_impl::parameterIndices::y0
@ y0
MuonR4::MuonSegmentFittingAlg::initialize
virtual StatusCode initialize() override
Definition: MuonSegmentFittingAlg.cxx:16
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::ReadHandleKey< ContainerType >
MuonR4::MuonSegmentFitterEventData_impl
Definition: MuonSegmentFitterEventData.h:14
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
MuonR4::MuonSegmentFitterEventData_impl::parameterIndices::tanPhi
@ tanPhi
MuonR4::MuonSegmentFittingAlg::retrieveContainer
StatusCode retrieveContainer(const EventContext &ctx, const SG::ReadHandleKey< ContainerType > &key, const ContainerType *&contToPush) const
Helper method to fetch data from StoreGate.
Definition: MuonSegmentFittingAlg.cxx:48
MuonR4::StationHoughResults
Small data class to collect the hough maxima for one given station.
Definition: StationHoughMaxima.h:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SegmentFitHelperFunctions.h
MuonR4::MuonSegmentFittingAlg::m_geoCtxKey
SG::ReadHandleKey< ActsGeometryContext > m_geoCtxKey
Definition: MuonSegmentFittingAlg.h:52
MuonR4::MuonSegmentFittingAlg::m_outSegments
SG::WriteHandleKey< MuonSegmentContainer > m_outSegments
Definition: MuonSegmentFittingAlg.h:49
MuonR4::MuonSegmentFittingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonSegmentFittingAlg.cxx:24
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
MuonR4::MuonSegmentFitterEventData_impl::parameterIndices::x0
@ x0
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MuonR4::MuonSegmentFittingAlg::prepareSegmentFit
StatusCode prepareSegmentFit(const HoughSegmentSeed &seed, MuonSegmentFitterEventData &data) const
Definition: MuonSegmentFittingAlg.cxx:63
MuonR4
The CsvMuonSimHitDumper reads a Simulation Hit container for muons and dumps information to csv files...
Definition: MuonSpacePoint.h:11
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
MuonR4::MuonSegmentFittingAlg::fitSegment
StatusCode fitSegment(MuonSegmentFitterEventData &data) const
Definition: MuonSegmentFittingAlg.cxx:95
MuonSegmentFittingAlg.h
MuonR4::HoughSegmentSeed_impl
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition: HoughSegmentSeed.h:13
NSWL1::PadTriggerAdapter::segment
Muon::NSW_PadTriggerSegment segment(const NSWL1::PadTrigger &data)
Definition: PadTriggerAdapter.cxx:5
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
MuonR4::MuonSegmentFittingAlg::prepareEventData
StatusCode prepareEventData(const EventContext &ctx, MuonSegmentFitterEventData &data) const
Definition: MuonSegmentFittingAlg.cxx:88