ATLAS Offline Software
MuonPRDSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MuonPRDSelectionTool.h"
6 
8 
9 namespace Muon {
10 
11  MuonPRDSelectionTool::MuonPRDSelectionTool(const std::string& type, const std::string& name, const IInterface* parent):
13  m_distanceToTubeCut(1000.),
14  m_secondCoordinateCut(1500.)
15  {
16  declareInterface<IMuonPRDSelectionTool>(this);
17  }
18 
20 
21  ATH_CHECK(m_idHelperSvc.retrieve());
22  ATH_CHECK(m_mdtCreator.retrieve());
23  ATH_CHECK(m_clusterCreator.retrieve());
24  return StatusCode::SUCCESS;
25  }
26 
28 
29  if( msgLvl(MSG::DEBUG) ){
30  msg(MSG::DEBUG) << " intersection: in sector " << intersection.layerSurface.sector
31  << " region " << MuonStationIndex::regionName(intersection.layerSurface.regionIndex)
32  << " layer " << MuonStationIndex::layerName(intersection.layerSurface.layerIndex)
33  << " r " << intersection.trackParameters->position().perp() << " z " << intersection.trackParameters->position().z()
34  << " phi " << intersection.trackParameters->position().phi()
35  << " local (" << intersection.trackParameters->parameters()[Trk::loc1] << "," << intersection.trackParameters->parameters()[Trk::loc2] << ")";
36  if( intersection.trackParameters->covariance() ) {
37  msg(MSG::DEBUG) << " err (" << Amg::error(*intersection.trackParameters->covariance(),Trk::loc1) << "," << Amg::error(*intersection.trackParameters->covariance(),Trk::loc2) << ")";
38  }
39 
40  if( !layerPrepRawData.mdts.empty() ) msg(MSG::DEBUG) << " MDTs " << layerPrepRawData.mdts.size();
41  if( !layerPrepRawData.rpcs.empty() ) msg(MSG::DEBUG) << " RPCs " << layerPrepRawData.rpcs.size();
42  if( !layerPrepRawData.tgcs.empty() ) msg(MSG::DEBUG) << " TGCs " << layerPrepRawData.tgcs.size();
43  if( !layerPrepRawData.cscs.empty() ) msg(MSG::DEBUG) << " CSCs " << layerPrepRawData.cscs.size();
44  if( !layerPrepRawData.stgcs.empty() ) msg(MSG::DEBUG) << " STGCs " << layerPrepRawData.stgcs.size();
45  if( !layerPrepRawData.mms.empty() ) msg(MSG::DEBUG) << " MMs " << layerPrepRawData.mms.size();
46  msg(MSG::DEBUG) << endmsg;
47  }
48 
49  // loop over MDT collections
50  for( const auto *col : layerPrepRawData.mdts ){
52  }
53 
54  // loop over RPC collections
55  for( const auto *col : layerPrepRawData.rpcs ){
57  }
58 
59  // loop over TGC collections
60  for( const auto *col : layerPrepRawData.tgcs ){
62  }
63 
64  // loop over STGC collections
65  for( const auto *col : layerPrepRawData.stgcs ){
67  }
68 
69  // loop over MM collections
70  for( const auto *col : layerPrepRawData.mms ){
72  }
73 
74  return true;
75  }
76 
77 
79 
80  // calculate intersection with tube
81  const Amg::Vector3D& direction = intersection.trackParameters->momentum();
82  Amg::Vector3D intersect = intersectMDT(mdt,intersection.trackParameters->position(),direction,true);
83 
84 
85  // calculate local position of the intersection in tube frame
86  const Identifier& id = mdt.identify();
87  const MuonGM::MdtReadoutElement* detEl = mdt.detectorElement();
88  const Trk::Surface& surface = mdt.detectorElement()->surface(id);
89  Amg::Vector2D localPosition{Amg::Vector2D::Zero()};
90  if( !surface.globalToLocal(intersect,direction,localPosition) ){
91  ATH_MSG_VERBOSE(" globalToLocal failed for " << m_idHelperSvc->toString(id) );
92  return nullptr;
93  }
94 
95  // bound checks
96  double tubeHalfLen = 0.5*detEl->getActiveTubeLength( m_idHelperSvc->mdtIdHelper().tubeLayer(id),m_idHelperSvc->mdtIdHelper().tube(id) );
97  double distanceAlongTube = localPosition[Trk::locZ];
98 
99  if( msgLvl(MSG::VERBOSE) ) {
100  msg(MSG::VERBOSE) << " Intersected " << m_idHelperSvc->toString(id) << " distance to wire " << localPosition[Trk::locR]
101  << " error " << Amg::error(*intersection.trackParameters->covariance(),Trk::locX) << " along tube (%) " << distanceAlongTube/tubeHalfLen;
102 
103  }
104  if( std::abs(distanceAlongTube) > tubeHalfLen + m_secondCoordinateCut ) {
105  if( msgLvl(MSG::VERBOSE) ) msg(MSG::VERBOSE) << " outside tube second coordinate range, dropping " << endmsg;
106  return nullptr;
107  }
108 
109  if( std::abs(localPosition[Trk::locR]) > m_distanceToTubeCut ) {
110  if( msgLvl(MSG::VERBOSE) ) msg(MSG::VERBOSE) << " too far from wire, dropping " << endmsg;
111  return nullptr;
112  }
113 
114  // shift intersection within tube
115  if( distanceAlongTube > tubeHalfLen ){
116  localPosition[Trk::locZ] = distanceAlongTube < 0 ? -tubeHalfLen : tubeHalfLen;
117  surface.localToGlobal(localPosition,direction,intersect);
118  if( msgLvl(MSG::VERBOSE) ) msg(MSG::VERBOSE) << " outside tube, shifting";
119  }
121 
122  // calibrate hit
123  const MdtDriftCircleOnTrack* mdtROT = m_mdtCreator->createRIO_OnTrack( mdt, intersect, &direction );
124  if( !mdtROT ) ATH_MSG_VERBOSE(" Failed to calibrate " << m_idHelperSvc->toString(id));
125  return mdtROT;
126  }
127 
129 
130  // basic info
131  const Identifier& id = clus.identify();
132  const Trk::Surface& surf = clus.detectorElement()->surface(id);
133 
134  // calculate intersection
135  const Amg::Vector3D& position = pars.position();
136  const Amg::Vector3D& direction = pars.momentum();
137  Trk::Intersection slIntersection = clus.detectorElement()->surface(id).straightLineIntersection(position,direction,false,false);
138  Amg::Vector3D intersect = slIntersection.position;
139 
140 
141  // get local position
142  Amg::Vector2D localPosition;
143  if( !surf.globalToLocal(intersect,direction,localPosition) ){
144  ATH_MSG_VERBOSE(" globalToLocal failed for " << m_idHelperSvc->toString(id) );
145  return nullptr;
146  }
147 
148  if( msgLvl(MSG::VERBOSE) ) msg(MSG::VERBOSE) << " Intersected " << m_idHelperSvc->toString(id) << " local position " << localPosition[Trk::loc1] << " " << localPosition[Trk::loc2];
149 
150  if( !surf.insideBounds(localPosition, m_distanceToTubeCut, m_secondCoordinateCut) ) {
151  if( msgLvl(MSG::VERBOSE) ) msg(MSG::VERBOSE) << " outside bounds, dropping " << endmsg;
152  return nullptr;
153  }
155 
156  const MuonClusterOnTrack *cluster = m_clusterCreator->createRIO_OnTrack(clus, intersect);
157 
158  if( !cluster ){
159  ATH_MSG_VERBOSE(" --- cluster creation failed ");
160  return nullptr;
161  }
162 
163  return cluster;
164  }
165 
167  return calibrateAndSelect(*intersection.trackParameters,clus);
168  }
169 
170  Amg::Vector3D MuonPRDSelectionTool::intersectMDT( const MdtPrepData& mdt, const Amg::Vector3D& position, const Amg::Vector3D& direction, bool usePlane ) const {
171 
172  if( usePlane ){
173  const Identifier& id = mdt.identify();
174  const MuonGM::MdtReadoutElement* detEl = mdt.detectorElement();
175  const Amg::Vector3D& tubePos = mdt.globalPosition();
176  // if there is a phi measurement in the pattern use the global direction to calculate the intersect with the tube
177  // use the intersect to calculate the second coordinate
178  const Amg::Transform3D amdbToGlobal = detEl->AmdbLRSToGlobalTransform();
179 
180  // calculate intersect pattern measurement plane
181  const Amg::Vector3D& planeposition = tubePos;
182 
183  // always project on plane with normal in radial direction
184  Amg::Vector3D planenormal = !m_idHelperSvc->isEndcap(id) ? amdbToGlobal.linear()*Amg::Vector3D(0.,0.,1.) : amdbToGlobal.linear()*Amg::Vector3D(0.,1.,0.);
185 
186  double denom = direction.dot(planenormal);
187  double u = (planenormal.dot(planeposition - position))/denom;
188  Amg::Vector3D piOnPlane = ( position + u * direction);
189  return piOnPlane;
190  }
191  Trk::Intersection intersection = mdt.detectorElement()->surface(mdt.identify()).straightLineIntersection(position,direction,false,false);
192  return intersection.position;
193  }
194 
195 
196 
197 }
198 
Muon::MuonPRDSelectionTool::calibrateAndSelectMdt
bool calibrateAndSelectMdt(const MuonSystemExtension::Intersection &intersection, const MdtPrepDataCollection &prds, std::vector< const MdtDriftCircleOnTrack * > &rots) const
calibrate and select MDTs in a collection
Definition: MuonPRDSelectionTool.h:39
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
Muon::MuonPRDSelectionTool::calibrateAndSelect
bool calibrateAndSelect(const MuonSystemExtension::Intersection &intersection, const MuonLayerPrepRawData &layerPrepRawData, MuonLayerROTs &layerROTs) const
IMuonPRDSelectionTool interface: calibrateAndSelect.
Definition: MuonPRDSelectionTool.cxx:27
MuonGM::MuonReadoutElement::AmdbLRSToGlobalTransform
virtual Amg::Transform3D AmdbLRSToGlobalTransform() const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonReadoutElement.cxx:145
Trk::Intersection
Definition: Intersection.h:24
Trk::locX
@ locX
Definition: ParamDefs.h:43
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
MuonPRDSelectionTool.h
EventPrimitivesHelpers.h
Muon::MuonPRDSelectionTool::m_secondCoordinateCut
double m_secondCoordinateCut
Definition: MuonPRDSelectionTool.h:93
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:41
Muon::MuonLayerPrepRawData::tgcs
std::vector< const TgcPrepDataCollection * > tgcs
Definition: MuonLayerPrepRawData.h:25
Muon::MuonLayerPrepRawData
Struct to hold all PrepRawData collections in a given layer.
Definition: MuonLayerPrepRawData.h:22
Trk::locR
@ locR
Definition: ParamDefs.h:50
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
MuonGM::MuonClusterReadoutElement::surface
virtual const Trk::PlaneSurface & surface() const override
access to chamber surface (phi orientation), uses the first gas gap
Definition: MuonClusterReadoutElement.h:123
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:83
Muon::MuonLayerPrepRawData::stgcs
std::vector< const sTgcPrepDataCollection * > stgcs
Definition: MuonLayerPrepRawData.h:27
Muon::MuonStationIndex::regionName
static const std::string & regionName(DetectorRegionIndex index)
convert DetectorRegionIndex into a string
Definition: MuonStationIndex.cxx:176
Trk::locZ
@ locZ
local cylindrical
Definition: ParamDefs.h:48
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
Muon::MuonLayerPrepRawData::mdts
std::vector< const MdtPrepDataCollection * > mdts
Definition: MuonLayerPrepRawData.h:23
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Muon::MuonPRDSelectionTool::initialize
StatusCode initialize()
Definition: MuonPRDSelectionTool.cxx:19
MuonGM::MdtReadoutElement::getActiveTubeLength
double getActiveTubeLength(const int tubeLayer, const int tube) const
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Muon::MuonPRDSelectionTool::m_distanceToTubeCut
double m_distanceToTubeCut
cuts
Definition: MuonPRDSelectionTool.h:92
Muon::MdtPrepData::globalPosition
virtual const Amg::Vector3D & globalPosition() const
Returns the global position of the CENTER of the drift tube (i.e.
Definition: MdtPrepData.h:149
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::MuonStationIndex::layerName
static const std::string & layerName(LayerIndex index)
convert LayerIndex into a string
Definition: MuonStationIndex.cxx:192
Muon::MuonPRDSelectionTool::calibrateAndSelectCluster
bool calibrateAndSelectCluster(const MuonSystemExtension::Intersection &intersection, const COL &prds, std::vector< const MuonClusterOnTrack * > &rots) const
calibrate and select clusters in a collection
Definition: MuonPRDSelectionTool.h:49
Trk::ParametersBase
Definition: ParametersBase.h:55
Trk::Intersection::position
Amg::Vector3D position
Definition: Intersection.h:25
compute_lumi.denom
denom
Definition: compute_lumi.py:76
Muon::MuonLayerROTs
struct holding RIO_OnTracks for a given layer
Definition: MuonLayerROTs.h:18
Trk::PrepRawData::identify
Identifier identify() const
return the identifier
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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::MdtDriftCircleOnTrack
This class represents the corrected MDT measurements, where the corrections include the effects of wi...
Definition: MdtDriftCircleOnTrack.h:37
Muon::MdtPrepData
Class to represent measurements from the Monitored Drift Tubes.
Definition: MdtPrepData.h:37
Trk::Surface::insideBounds
virtual bool insideBounds(const Amg::Vector2D &locpos, double tol1=0., double tol2=0.) const =0
virtual methods to be overwritten by the inherited surfaces
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Muon::MuonPRDSelectionTool::m_mdtCreator
ToolHandle< IMdtDriftCircleOnTrackCreator > m_mdtCreator
Definition: MuonPRDSelectionTool.h:88
Trk::PlaneSurface::straightLineIntersection
virtual Intersection straightLineIntersection(const Amg::Vector3D &pos, const Amg::Vector3D &dir, bool forceDir, Trk::BoundaryCheck bchk) const override final
fast straight line intersection schema - standard: provides closest intersection and (signed) path le...
Definition: PlaneSurface.cxx:223
query_example.col
col
Definition: query_example.py:7
Muon::MuonLayerPrepRawData::cscs
std::vector< const CscPrepDataCollection * > cscs
Definition: MuonLayerPrepRawData.h:26
Muon::MuonPRDSelectionTool::MuonPRDSelectionTool
MuonPRDSelectionTool(const std::string &type, const std::string &name, const IInterface *parent)
Default AlgTool functions.
Definition: MuonPRDSelectionTool.cxx:11
Muon::MuonPRDSelectionTool::intersectMDT
Amg::Vector3D intersectMDT(const MdtPrepData &mdt, const Amg::Vector3D &position, const Amg::Vector3D &direction, bool usePlane) const
intersect MDT surface or tube plane
Definition: MuonPRDSelectionTool.cxx:170
Trk::Surface::globalToLocal
virtual bool globalToLocal(const Amg::Vector3D &glob, const Amg::Vector3D &mom, Amg::Vector2D &loc) const =0
Specified by each surface type: GlobalToLocal method without dynamic memory allocation - boolean chec...
Amg::intersect
std::optional< double > intersect(const AmgVector(N)&posA, const AmgVector(N)&dirA, const AmgVector(N)&posB, const AmgVector(N)&dirB)
Calculates the closest approach of two lines.
Definition: GeoPrimitivesHelpers.h:302
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Muon::MuonLayerPrepRawData::rpcs
std::vector< const RpcPrepDataCollection * > rpcs
Definition: MuonLayerPrepRawData.h:24
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
MuonGM::MdtReadoutElement::surface
virtual const Trk::Surface & surface() const override final
Return surface associated with this detector element.
Definition: MuonDetDescr/MuonReadoutGeometry/src/MdtReadoutElement.cxx:875
Muon::MuonLayerPrepRawData::mms
std::vector< const MMPrepDataCollection * > mms
Definition: MuonLayerPrepRawData.h:28
Muon::MuonCluster
Class representing clusters in the muon system.
Definition: MuonSpectrometer/MuonReconstruction/MuonRecEvent/MuonPrepRawData/MuonPrepRawData/MuonCluster.h:37
Muon::MuonSystemExtension::Intersection
data per intersection
Definition: MuonSystemExtension.h:21
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
AthAlgTool
Definition: AthAlgTool.h:26
Muon::MuonCluster::detectorElement
virtual const MuonGM::MuonClusterReadoutElement * detectorElement() const override=0
Returns the detector element corresponding to this PRD.
Trk::loc1
@ loc1
Definition: ParamDefs.h:40
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Muon::MuonPRDSelectionTool::m_clusterCreator
ToolHandle< IMuonClusterOnTrackCreator > m_clusterCreator
Definition: MuonPRDSelectionTool.h:89
Muon::MdtPrepData::detectorElement
virtual const MuonGM::MdtReadoutElement * detectorElement() const override
Returns the detector element corresponding to this PRD.
Definition: MdtPrepData.h:156
Muon::MuonPRDSelectionTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonPRDSelectionTool.h:87
Trk::Surface::localToGlobal
virtual void localToGlobal(const Amg::Vector2D &locp, const Amg::Vector3D &mom, Amg::Vector3D &glob) const =0
Specified by each surface type: LocalToGlobal method without dynamic memory allocation.
Muon::MuonClusterOnTrack
Base class for Muon cluster RIO_OnTracks.
Definition: MuonClusterOnTrack.h:34
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32