ATLAS Offline Software
MappingTest.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 // MappingTest.cxx, (c) ATLAS Detector software
8 
9 // Trk includes
12 #include "TrkGeometry/Layer.h"
17 //Root includes
18 #include "TTree.h"
19 #include "TString.h"
20 // Gaudi
21 #include "GaudiKernel/ITHistSvc.h"
22 
23 
24 Trk::MappingTest::MappingTest(const std::string& name, ISvcLocator* pSvcLocator) :
25  Trk::TrkDetDescrUnitTestBase(name, pSvcLocator),
26  m_executed(false),
27  m_trackingGeometrySvc("TrackingGeometrySvc","AtlasTrackingGeometrySvc"),
28  m_trackingGeometry(nullptr),
29  m_trackingGeometryName("AtlasTrackingGeometry"),
30  m_etaCutOff(6.0),
31  m_mappingVolumeName("InDet::Detectors::Pixel::Barrel"),
32  m_mappingTreeName("LayerMappingTest"),
33  m_mappingTreeDescription("Test Algorithm for Layer - 3D point association"),
34  m_mappingTree(nullptr),
35  m_mappingPositionX(0.),
36  m_mappingPositionY(0.),
37  m_mappingPositionZ(0.),
38  m_mappingPositionR(0.),
39  m_assignedPositionX(0.),
40  m_assignedPositionY(0.),
41  m_assignedPositionZ(0.),
42  m_assignedPositionR(0.),
43  m_assignedCorrection(0.),
44  m_assignedLayerIndex(0),
45  m_assignmentDistance(0.),
46  m_unmappedTree(nullptr),
47  m_unmappedPositionX(0.),
48  m_unmappedPositionY(0.),
49  m_unmappedPositionZ(0.),
50  m_unmappedPositionR(0.)
51  {
52  // get the service handle for the TrackingGeometry
53  declareProperty("TrackingGeometrySvc" , m_trackingGeometrySvc);
54  // Eta cut off
55  declareProperty("EtaCutOff" , m_etaCutOff);
56  declareProperty("HighestVolume" , m_mappingVolumeName);
57  //
58  declareProperty("MappingTreeName" , m_mappingTreeName);
59  declareProperty("MappingTreeDescription" , m_mappingTreeDescription);
60  }
61 
63 {
64 
65  // Get the TrackingGeometry from StoreGate
66  // initialize the TrackingGeometrySvc
67  if (m_trackingGeometrySvc.retrieve().isFailure()) {
68  ATH_MSG_FATAL( "Cannot retrieve TrackingGeometrySvc. Abort job. " );
69  return StatusCode::FAILURE;
70  }
71  m_trackingGeometryName = m_trackingGeometrySvc->trackingGeometryName();
72 
73  return StatusCode::SUCCESS;
74 }
75 
77 {
78  ATH_MSG_VERBOSE("Booking the Material Tree.");
79 
80  // ------------------------------> OUTPUT NTUPLE (geometry validation)
81 
82  m_mappingTree = new TTree(m_mappingTreeName.c_str(), m_mappingTreeDescription.c_str());
83  // add the Branches
84  m_mappingTree->Branch("ValPosX", &m_mappingPositionX, "valpx/F");
85  m_mappingTree->Branch("ValPosY", &m_mappingPositionY, "valpy/F");
86  m_mappingTree->Branch("ValPosZ", &m_mappingPositionZ, "valpz/F");
87  m_mappingTree->Branch("ValPosR", &m_mappingPositionR, "valpr/F");
88 
89  // add the Branches for the association objects
90  m_mappingTree->Branch("AssocPosX", &m_assignedPositionX, "asspx/F");
91  m_mappingTree->Branch("AssocPosY", &m_assignedPositionY, "asspy/F");
92  m_mappingTree->Branch("AssocPosZ", &m_assignedPositionZ, "asspz/F");
93  m_mappingTree->Branch("AssocPosR", &m_assignedPositionR, "asspr/F");
94  m_mappingTree->Branch("AssocCorr", &m_assignedCorrection, "asscor/F");
95  m_mappingTree->Branch("AssocLayer", &m_assignedLayerIndex, "assidx/I");
96  m_mappingTree->Branch("AssocDistance", &m_assignmentDistance, "asignd/F");
97 
98  // ------------------------------> OUTPUT NTUPLE (unmapped hits)
99  m_unmappedTree = new TTree("UnmappedHits", "Unmapped Hits of the MappingTest Algorithm");
100  // add the Branches
101  m_unmappedTree->Branch("UnmappedHitX", &m_unmappedPositionX, "unmappedx/F");
102  m_unmappedTree->Branch("UnmappedHitY", &m_unmappedPositionY, "unmappedy/F");
103  m_unmappedTree->Branch("UnmappedHitZ", &m_unmappedPositionZ, "unmappedz/F");
104  m_unmappedTree->Branch("UnmappedHitR", &m_unmappedPositionR, "unmappedr/F");
105 
106  // now register the Tree
107  SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
108  if (!tHistSvc) {
109  ATH_MSG_ERROR( "initialize() Could not find Hist Service -> Switching Tree output off !" );
110  delete m_unmappedTree; m_unmappedTree = nullptr;
111  delete m_mappingTree; m_mappingTree = nullptr;
112  }
113  if (tHistSvc && ((tHistSvc->regTree("/val/UnmappedAssociations", m_unmappedTree)).isFailure()
114  || (tHistSvc->regTree("/val/MappingTest", m_mappingTree)).isFailure()) ) {
115  ATH_MSG_ERROR( "initialize() Could not register the validation Tree -> Switching Tree output off !" );
116  delete m_unmappedTree; m_unmappedTree = nullptr;
117  delete m_mappingTree; m_mappingTree = nullptr;
118  }
119 
120  return StatusCode::SUCCESS;
121 
122 }
123 
125 {
126  ATH_MSG_VERBOSE("Running the MappingTest Test");
127 
128  // ------------------------------- get the trackingGeometry at first place
129  if (!m_trackingGeometry) {
130  if ((detStore()->retrieve(m_trackingGeometry, m_trackingGeometryName)).isFailure())
131  ATH_MSG_FATAL( "Could not retrieve TrackingGeometry '" << m_trackingGeometryName << "' from DetectorStore." );
132  else
133  ATH_MSG_INFO( "TrackingGeometry '" << m_trackingGeometryName << "' successfully retrieved from DetectorStore." );
134  }
135  // only run if it didn't already run before
136  if (!m_executed && m_trackingGeometry){
137  // get the volume and the overal boundaries
138  const TrackingVolume* tVolume = m_trackingGeometry->trackingVolume(m_mappingVolumeName);
139  if (tVolume){
140  ATH_MSG_INFO("Retrieved TrackingVolume '" << tVolume->volumeName() << "'. Start the mapping validation.");
141  const Trk::CylinderVolumeBounds* cvb = dynamic_cast<const Trk::CylinderVolumeBounds*>(&(tVolume->volumeBounds()));
142  if (cvb){
143  double mRad = cvb->innerRadius();
144  double dRad = cvb->deltaRadius();
145  double zHalf = cvb->halflengthZ();
146  // run the mapping
147  for ( size_t it = 0; it < TrkDetDescrUnitTestBase::m_numTests; ++it ){
148  // create the mapping position
149  double mapRad = mRad + TrkDetDescrUnitTestBase::m_flatDist->shoot()*dRad;
150  double mapPhi = M_PI * (2*TrkDetDescrUnitTestBase::m_flatDist->shoot() - 1.);
151  double mapZ = zHalf * (2*TrkDetDescrUnitTestBase::m_flatDist->shoot() - 1.);
152  double mapX = mapRad*cos(mapPhi);
153  double mapY = mapRad*sin(mapPhi);
154  // the mapping position & unit is the same
155  Amg::Vector3D position(mapX, mapY, mapZ);
156  Amg::Vector3D direction = position.normalized();
157  // create curvilinear parameters
158  Trk::NeutralCurvilinearParameters ncp(position,direction,0.);
159  // get the closest material layer
160  const Trk::LayerIntersection<Amg::Vector3D> lIntersect
161  = m_trackingGeometry->closestMaterialLayer<Trk::NeutralCurvilinearParameters>(ncp, Trk::mappingMode, true);
162  if (lIntersect.intersection.valid){
163  // the mapping positions
164  m_mappingPositionX = mapX;
165  m_mappingPositionY = mapY;
166  m_mappingPositionZ = mapZ;
167  m_mappingPositionR = mapRad;
168  // the resulting assigned position
169  m_assignedPositionX = lIntersect.intersection.position.x();
170  m_assignedPositionY = lIntersect.intersection.position.y();
171  m_assignedPositionZ = lIntersect.intersection.position.z();
172  m_assignedPositionR = lIntersect.intersection.position.perp();
173  m_assignedCorrection = 0.;
174  m_assignedLayerIndex = lIntersect.object->layerIndex().value();
175  m_assignmentDistance = lIntersect.intersection.pathLength;
176  // and now write the tree
177  m_mappingTree->Fill();
178  } else {
179  // the unmapped positions
180  // and now fill the tree
181  m_unmappedPositionX = mapY;
182  m_unmappedPositionY = mapY;
183  m_unmappedPositionZ = mapZ;
184  m_unmappedPositionR = mapRad;
185  // and now fill the tree
186  m_unmappedTree->Fill();
187  }
188  }
189  }
190  } else
191  ATH_MSG_INFO("Could not retrieve the TrackingVolume '" << m_mappingVolumeName << "'." );
192 
193  }
194  m_executed = true;
195  return StatusCode::SUCCESS;
196 
197 }
198 
199 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Trk::MappingTest::m_mappingVolumeName
std::string m_mappingVolumeName
only map within this volume
Definition: MappingTest.h:56
Trk::TrkDetDescrUnitTestBase::m_flatDist
Rndm::Numbers * m_flatDist
Definition: TrkDetDescrUnitTestBase.h:58
Trk::TrkDetDescrUnitTestBase::m_numTests
size_t m_numTests
number of tests
Definition: TrkDetDescrUnitTestBase.h:61
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::MappingTest::runTest
StatusCode runTest()
Definition: MappingTest.cxx:124
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkDetDescrUnitTestBase
Definition: TrkDetDescrUnitTestBase.h:27
Trk::MappingTest::m_trackingGeometrySvc
ServiceHandle< Trk::ITrackingGeometrySvc > m_trackingGeometrySvc
Service handle for retrieving the TrackingGeometry.
Definition: MappingTest.h:51
Trk::Intersection::pathLength
double pathLength
Definition: Intersection.h:26
skel.it
it
Definition: skel.GENtoEVGEN.py:396
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Layer.h
NeutralParameters.h
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::MappingTest::m_etaCutOff
double m_etaCutOff
do not map beyond this point
Definition: MappingTest.h:55
CylinderVolumeBounds.h
MappingTest.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::MappingTest::m_mappingTreeName
std::string m_mappingTreeName
Definition: MappingTest.h:58
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::MappingTest::bookTree
StatusCode bookTree()
Definition: MappingTest.cxx:76
Trk::CylinderVolumeBounds::halflengthZ
double halflengthZ() const
This method returns the halflengthZ.
Definition: CylinderVolumeBounds.h:207
Trk::CurvilinearParametersT
Definition: CurvilinearParametersT.h:48
Trk::Intersection::position
Amg::Vector3D position
Definition: Intersection.h:25
Trk::MappingTest::m_mappingTreeDescription
std::string m_mappingTreeDescription
Definition: MappingTest.h:59
Trk::CylinderVolumeBounds
Definition: CylinderVolumeBounds.h:70
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::TrackingVolume::volumeName
const std::string & volumeName() const
Returns the VolumeName - for debug reason, might be depreciated later.
IGeometryProcessor.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::Intersection::valid
bool valid
Definition: Intersection.h:28
TrackingVolume.h
Trk::FullIntersection::intersection
Intersection intersection
Definition: Intersection.h:66
Trk::MappingTest::initializeTest
StatusCode initializeTest()
Definition: MappingTest.cxx:62
Trk::CylinderVolumeBounds::innerRadius
double innerRadius() const
This method returns the inner radius.
Definition: CylinderVolumeBounds.h:187
Trk::FullIntersection::object
const T * object
Definition: Intersection.h:67
Trk::Volume::volumeBounds
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
Definition: Volume.h:97
TrackingGeometry.h
Trk::CylinderVolumeBounds::deltaRadius
double deltaRadius() const
This method returns the delta radius.
Definition: CylinderVolumeBounds.h:199
Trk::FullIntersection
Class extension to return the object, a represenation & the result.
Definition: Intersection.h:64
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::mappingMode
@ mappingMode
Definition: PropDirection.h:23
Trk::MappingTest::MappingTest
MappingTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: MappingTest.cxx:24