ATLAS Offline Software
CscClusterOnTrackCreator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <cmath>
6 
8 
17 #include "TrkSurfaces/Surface.h"
18 
19 using Amg::Transform3D;
20 using Amg::Vector3D;
24 
25 namespace Muon {
26 
27  CscClusterOnTrackCreator::CscClusterOnTrackCreator(const std::string& ty, const std::string& na, const IInterface* pa) :
28  AthAlgTool(ty, na, pa) {
29  // algtool interface - necessary!
30  declareInterface<IMuonClusterOnTrackCreator>(this);
31  declareInterface<IRIO_OnTrackCreator>(this);
32  }
33 
35 
38  ATH_CHECK(m_idHelperSvc.retrieve());
39  if (!m_idHelperSvc->hasCSC()) {
40  ATH_MSG_ERROR("The given detector layout does not contain any CSC chamber, "<<
41  "there must be something wrong in the configuration,"
42  <<" since the CscClusterOnTrackCreator cannot be needed.");
43  return StatusCode::FAILURE;
44  }
45 
46  // get error scaling tool
47  //
49  ATH_CHECK(m_stripFitter.retrieve());
50  ATH_CHECK(m_clusterFitter.retrieve());
51  ATH_CHECK(m_clusterUtilTool.retrieve());
52  return StatusCode::SUCCESS;
53  }
54 
57  MuonClusterOnTrack* MClT = nullptr;
58 
59  // check whether PrepRawData has detector element, if not there print warning
61  if (!EL) {
62  ATH_MSG_WARNING("RIO does not have associated detectorElement!, cannot produce ROT");
63  return nullptr;
64  }
65 
66  // MuClusterOnTrack production
67  //
68  // in RIO_OnTrack the local param and cov should have the same dimension
69  Trk::LocalParameters locpar(RIO.localPosition());
70  if (RIO.localCovariance().cols() > 1) {
71  ATH_MSG_VERBOSE("Making 2-dim local parameters");
72  } else {
73  Trk::DefinedParameter radiusPar(RIO.localPosition().x(), Trk::locX);
74  locpar = Trk::LocalParameters(radiusPar);
75  ATH_MSG_VERBOSE("Making 1-dim local parameters");
76  }
77 
78  Amg::Vector2D lp;
79  double positionAlongStrip = 0;
80 
81  if (!EL->surface(RIO.identify()).globalToLocal(GP, GP, lp)) {
82  Amg::Vector3D lpos = RIO.detectorElement()->surface(RIO.identify()).transform().inverse() * GP;
83  ATH_MSG_WARNING("Extrapolated GlobalPosition not on detector surface! Distance " << lpos.z());
84  lp[Trk::locX] = lpos.x();
85  lp[Trk::locY] = lpos.y();
86  }
87  positionAlongStrip = lp[Trk::locY];
88 
89  // Error matrix production - expect more intelligent code here.
90  //
91  Amg::MatrixX loce = RIO.localCovariance();
92 
93  if (m_idHelperSvc->isCsc(RIO.identify()) && !m_cscErrorScalingKey.key().empty()) {
95  loce = Trk::ErrorScalingCast<MuonEtaPhiRIO_OnTrackErrorScaling>(
96  *error_scaling)
97  ->getScaledCovariance(std::move(loce), Trk::distPhi);
98  ATH_MSG_VERBOSE("CSC: new cov(0,0) is " << loce(0, 0));
99  }
100 
101  if (m_idHelperSvc->isCsc(RIO.identify())) {
102  // cast to CscPrepData
103  const CscPrepData* MClus = dynamic_cast<const CscPrepData*>(&RIO);
104  if (!MClus) {
105  ATH_MSG_WARNING("RIO not of type CscPrepData, cannot create ROT");
106  return nullptr;
107  }
108 
109  // current not changing CscClusterStatus but passing status of RIO
110  MClT = new CscClusterOnTrack(MClus, std::move(locpar), std::move(loce),
111  positionAlongStrip, MClus->status(), MClus->timeStatus(), MClus->time());
112  }
113 
114  return MClT;
115  }
116 
118 
120  const Amg::Vector3D& GP,
121  const Amg::Vector3D& GD) const {
122  if (!m_idHelperSvc->isCsc(RIO.identify())) {
123  ATH_MSG_WARNING("CscClusterOnTrackCreator::createRIO_OnTrack is called by the other muon tech");
124  return nullptr;
125  }
126 
127  MuonClusterOnTrack* MClT = nullptr;
128  // check whether PrepRawData has detector element, if not there print warning
130  if (!EL) {
131  ATH_MSG_WARNING("RIO does not have associated detectorElement!, cannot produce ROT");
132  return MClT;
133  }
134  // cast to CscPrepData : Moved to the front to avoid any memory allocation before return;
135  const CscPrepData* MClus = dynamic_cast<const CscPrepData*>(&RIO);
136  if (!MClus) {
137  ATH_MSG_WARNING("RIO not of type CscPrepData, cannot create ROT");
138  return MClT;
139  }
140 
141  // MuClusterOnTrack production
142  //
143  // in RIO_OnTrack the local param and cov should have the same dimension
145  if (RIO.localCovariance().cols() > 1 ||
146  (m_idHelperSvc->isTgc(RIO.identify()) && m_idHelperSvc->tgcIdHelper().isStrip(RIO.identify()))) {
147  ATH_MSG_VERBOSE("Making 2-dim local parameters");
148  } else {
149  Trk::DefinedParameter radiusPar(RIO.localPosition().x(), Trk::locX);
150  locpar = Trk::LocalParameters(radiusPar);
151  ATH_MSG_VERBOSE("Making 1-dim local parameters");
152  }
153 
155  double positionAlongStrip = 0;
156 
157  if (!EL->surface(RIO.identify()).globalToLocal(GP, GP, lp)) {
158  Amg::Vector3D lpos = RIO.detectorElement()->surface(RIO.identify()).transform().inverse() * GP;
159  ATH_MSG_WARNING("Extrapolated GlobalPosition not on detector surface! Distance " << lpos.z());
160  lp[Trk::locX] = lpos.x();
161  lp[Trk::locY] = lpos.y();
162  }
163  positionAlongStrip = lp[Trk::locY];
164 
165  // Error matrix production - expect more intelligent code here.
166  //
167  Amg::MatrixX loce = RIO.localCovariance();
168 
169  if (m_idHelperSvc->isCsc(RIO.identify()) && !m_cscErrorScalingKey.key().empty()) {
171  loce = Trk::ErrorScalingCast<MuonEtaPhiRIO_OnTrackErrorScaling>(
172  *error_scaling)
173  ->getScaledCovariance(std::move(loce), Trk::distPhi);
174  ATH_MSG_VERBOSE("CSC: new cov(0,0) is " << loce(0, 0));
175  }
176 
177  // postion Error is re-estimate only for precision fit cluster (eta)
178  if (MClus->status() != Muon::CscStatusUnspoiled && MClus->status() != Muon::CscStatusSplitUnspoiled) {
179  // current not changing CscClusterStatus but passing status of RIO
180  MClT = new CscClusterOnTrack(MClus, std::move(locpar), std::move(loce), positionAlongStrip, MClus->status(), MClus->timeStatus(), MClus->time());
181 
182  } else {
183  const MuonGM::CscReadoutElement* ele = MClus->detectorElement();
184  Transform3D globalToLocal = ele->transform(MClus->identify()).inverse();
185  Vector3D d(globalToLocal * GD);
186  double tantheta = d.x() / d.z();
187 
188  std::vector<ICscClusterFitter::Result> results, results0;
189  results = m_clusterUtilTool->getRefitCluster(MClus, tantheta);
190  results0 = m_clusterUtilTool->getRefitCluster(MClus, 0);
191 
192  if (results.empty() || results0.empty()) {
193  ATH_MSG_VERBOSE("No fit result");
194  return new CscClusterOnTrack(MClus, std::move(locpar), std::move(loce),
195  positionAlongStrip, MClus->status(), MClus->timeStatus(), MClus->time());
196  }
198  res = results[0];
199  res0 = results0[0]; // result at normal angle to make error blown correctly in case of cosmic
200  int fitresult = res.fitStatus;
201  if (fitresult) {
202  ATH_MSG_VERBOSE(" Precision fit failed which was succeeded: return="
203  << "cluStatus: " << res.clusterStatus << "fitStatus: " << res.fitStatus);
204  return new CscClusterOnTrack(MClus, std::move(locpar), std::move(loce),
205  positionAlongStrip, MClus->status(), MClus->timeStatus(), MClus->time());
206  } else {
207  ATH_MSG_VERBOSE(" Precision fit succeeded");
208  }
209 
210  ATH_MSG_VERBOSE(" Angle from Segment: "
211  << " :: tanangle : " << tantheta);
212 
213  // in case that we need to scale errors for cosmic/data we want to scale only for normal part
214  // v0 only scaling up intrinsic term...
215  // double errorCorrected = sqrt(res.dposition*res.dposition - res0.dposition*res0.dposition
216  // + m_errorScaler*m_errorScaler*res0.dposition*res0.dposition);
217  // v1 scaling up total uncertainty and add up misalignment term....like sqrt( sigma_nominal^2 * alpha^2 + beta^2)
218  double nominal_error = res.dposition;
219  double errorCorrected =
220  std::sqrt(nominal_error * nominal_error * m_errorScaler * m_errorScaler + m_errorScalerBeta * m_errorScalerBeta);
221  if (errorCorrected < m_minimumError) errorCorrected = m_minimumError;
222 
223  Amg::MatrixX newloce(Amg::MatrixX(1, 1));
224  newloce.setIdentity();
225  newloce *= errorCorrected * errorCorrected;
226  if (!m_cscErrorScalingKey.key().empty()) {
228  newloce =
229  Trk::ErrorScalingCast<MuonEtaPhiRIO_OnTrackErrorScaling>(
230  *error_scaling)
231  ->getScaledCovariance(std::move(newloce), Trk::distPhi);
232  }
233 
234  ATH_MSG_VERBOSE("All: new err matrix is " << newloce);
235  ATH_MSG_VERBOSE(" dpos changed ====> " << Amg::error(newloce, Trk::loc1));
236 
237  MClT = new CscClusterOnTrack(MClus, std::move(locpar), std::move(newloce),
238  positionAlongStrip, MClus->status(), MClus->timeStatus(), MClus->time());
239  ATH_MSG_VERBOSE("global postion of MClT :::: " << MClT->globalPosition());
240  }
241 
242  return MClT;
243  }
244 
246  MuonClusterOnTrack* CscClusterOnTrackCreator::correct(const Trk::PrepRawData& RIO, const Trk::TrackParameters& TP, const EventContext& /*ctx*/) const {
247  return createRIO_OnTrack(RIO, TP.position(), TP.momentum().unit());
248  }
249 
252  return createRIO_OnTrack(RIO, GP, GD);
253  }
254 
256  const ToolHandle<ICscStripFitter>& CscClusterOnTrackCreator::GetICscStripFitter() const { return m_stripFitter; }
257  const ToolHandle<ICscClusterFitter>& CscClusterOnTrackCreator::GetICscClusterFitter() const { return m_clusterFitter; }
258  const ToolHandle<ICscClusterUtilTool>& CscClusterOnTrackCreator::GetICscClusterUtilTool() const { return m_clusterUtilTool; }
259 
260 } // namespace Muon
Trk::LocalParameters
Definition: LocalParameters.h:98
MuonGM::MuonClusterReadoutElement::transform
virtual const Amg::Transform3D & transform() const override
Return local to global transform.
Definition: MuonClusterReadoutElement.h:124
verify_menu_config.results
results
Definition: verify_menu_config.py:67
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
Muon::MuonClusterOnTrack::globalPosition
virtual const Amg::Vector3D & globalPosition() const override
Returns global position.
Definition: MuonClusterOnTrack.cxx:93
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Trk::locX
@ locX
Definition: ParamDefs.h:37
Trk::locY
@ locY
local cartesian
Definition: ParamDefs.h:38
Surface.h
Muon::CscClusterOnTrackCreator::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: CscClusterOnTrackCreator.h:91
Muon::CscStripPrepDataCollection
MuonPrepDataCollection< CscStripPrepData > CscStripPrepDataCollection
Definition: MuonPrepDataCollection.h:111
Muon::CscClusterOnTrackCreator::m_clusterFitter
ToolHandle< ICscClusterFitter > m_clusterFitter
Definition: CscClusterOnTrackCreator.h:94
Trk::ParametersBase::position
const Amg::Vector3D & position() const
Access method for the position.
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
hist_file_dump.d
d
Definition: hist_file_dump.py:137
EventPrimitivesHelpers.h
Trk::PrepRawData::localCovariance
const Amg::MatrixX & localCovariance() const
return const ref to the error matrix
CscStripPrepDataCollection.h
Muon::CscClusterOnTrackCreator::CscClusterOnTrackCreator
CscClusterOnTrackCreator(const std::string &, const std::string &, const IInterface *)
Definition: CscClusterOnTrackCreator.cxx:27
Trk::TrkDetElementBase
Definition: TrkDetElementBase.h:52
MuonGM::CscReadoutElement
Definition: CscReadoutElement.h:56
Muon::CscClusterOnTrackCreator::~CscClusterOnTrackCreator
virtual ~CscClusterOnTrackCreator()
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
Muon::CscClusterOnTrackCreator::correct
virtual MuonClusterOnTrack * correct(const Trk::PrepRawData &RIO, const Trk::TrackParameters &TP, const EventContext &) const override
Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and the predicted Trk::TrackParameter at ...
Definition: CscClusterOnTrackCreator.cxx:246
Muon::CscClusterOnTrackCreator::GetICscClusterUtilTool
virtual const ToolHandle< ICscClusterUtilTool > & GetICscClusterUtilTool() const override
Definition: CscClusterOnTrackCreator.cxx:258
Trk::DefinedParameter
std::pair< double, ParamDefs > DefinedParameter
Definition: DefinedParameter.h:27
Muon::CscClusterOnTrackCreator::m_clusterUtilTool
ToolHandle< ICscClusterUtilTool > m_clusterUtilTool
Definition: CscClusterOnTrackCreator.h:95
Muon::CscPrepData::timeStatus
CscTimeStatus timeStatus() const
Returns the Csc time status flag.
Definition: CscPrepData.h:168
Muon::CscStripPrepData
Class representing the raw data of one CSC strip (for clusters look at Muon::CscPrepData).
Definition: CscStripPrepData.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ICscClusterFitter::Result
Definition: ICscClusterFitter.h:52
CscPrepData.h
Muon::CscClusterOnTrackCreator::m_minimumError
Gaudi::Property< double > m_minimumError
Definition: CscClusterOnTrackCreator.h:104
Muon::CscPrepData
Class representing clusters from the CSC.
Definition: CscPrepData.h:39
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Muon::CscPrepData::status
CscClusterStatus status() const
Returns the Csc status (position measurement) flag.
Definition: CscPrepData.h:163
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
CscClusterOnTrack.h
Trk::TrkDetElementBase::surface
virtual const Surface & surface() const =0
Return surface associated with this detector element.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::CscPrepData::time
double time() const
Returns the time.
Definition: CscPrepData.h:158
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
Muon::CscClusterOnTrackCreator::GetICscStripFitter
virtual const ToolHandle< ICscStripFitter > & GetICscStripFitter() const override
These functions are provided from the interface.
Definition: CscClusterOnTrackCreator.cxx:256
Trk::ParametersBase
Definition: ParametersBase.h:55
Muon::CscClusterOnTrackCreator::m_cscErrorScalingKey
SG::ReadCondHandleKey< RIO_OnTrackErrorScaling > m_cscErrorScalingKey
Definition: CscClusterOnTrackCreator.h:97
Muon::CscStripPrepDataContainer
MuonPrepDataContainerT< CscStripPrepData > CscStripPrepDataContainer
Definition: MuonPrepDataContainer.h:99
Muon::CscClusterOnTrackCreator::GetICscClusterFitter
virtual const ToolHandle< ICscClusterFitter > & GetICscClusterFitter() const override
Definition: CscClusterOnTrackCreator.cxx:257
CscClusterStatus.h
Trk::distPhi
@ distPhi
Definition: ParamDefs.h:50
Muon::CscPrepData::detectorElement
virtual const MuonGM::CscReadoutElement * detectorElement() const override final
Return the detector element corresponding to this PRD.
Definition: CscPrepData.h:148
Trk::PrepRawData
Definition: PrepRawData.h:62
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
fitman.fitresult
fitresult
Definition: fitman.py:590
Muon::CscStatusUnspoiled
@ CscStatusUnspoiled
Clean cluster with precision fit.
Definition: CscClusterStatus.h:26
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
Muon::CscClusterOnTrackCreator::m_errorScalerBeta
Gaudi::Property< double > m_errorScalerBeta
Definition: CscClusterOnTrackCreator.h:103
Trk::PrepRawData::localPosition
const Amg::Vector2D & localPosition() const
return the local position reference
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
LocalParameters.h
ErrorScalingCast.h
Trk::ParametersBase::momentum
const Amg::Vector3D & momentum() const
Access method for the momentum.
Muon::CscClusterOnTrack
Class to represent the calibrated clusters created from CSC strips.
Definition: CscClusterOnTrack.h:47
Muon::CscStatusSplitUnspoiled
@ CscStatusSplitUnspoiled
Clean cluster with precision fit after split cluster.
Definition: CscClusterStatus.h:59
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LocalDirection.h
Muon::CscClusterOnTrackCreator::m_errorScaler
Gaudi::Property< double > m_errorScaler
Definition: CscClusterOnTrackCreator.h:102
AthAlgTool
Definition: AthAlgTool.h:26
Muon::CscClusterOnTrackCreator::m_stripFitter
ToolHandle< ICscStripFitter > m_stripFitter
Definition: CscClusterOnTrackCreator.h:93
Muon::CscClusterOnTrackCreator::initialize
virtual StatusCode initialize() override
Definition: CscClusterOnTrackCreator.cxx:37
Trk::loc1
@ loc1
Definition: ParamDefs.h:34
Muon::CscClusterOnTrackCreator::createRIO_OnTrack
virtual MuonClusterOnTrack * createRIO_OnTrack(const Trk::PrepRawData &RIO, const Amg::Vector3D &GP) const override
Create new Muon::MuonClusterOnTrack from a Trk::PrepRawData and a predicted Trk::TrackParameter.
Definition: CscClusterOnTrackCreator.cxx:56
Trk::Surface::transform
const Amg::Transform3D & transform() const
Returns HepGeom::Transform3D by reference.
NSWL1::globalToLocal
Polygon globalToLocal(const Polygon &pol, float z, const Trk::PlaneSurface &surf)
Definition: GeoUtils.cxx:103
CscClusterOnTrackCreator.h
Muon::MuonClusterOnTrack
Base class for Muon cluster RIO_OnTracks.
Definition: MuonClusterOnTrack.h:34
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
Trk::PrepRawData::detectorElement
virtual const TrkDetElementBase * detectorElement() const =0
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...