ATLAS Offline Software
Loading...
Searching...
No Matches
MappingTest.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
25{
26
27 // Get the TrackingGeometry from StoreGate
28 // initialize the TrackingGeometrySvc
29 if (m_trackingGeometrySvc.retrieve().isFailure()) {
30 ATH_MSG_FATAL( "Cannot retrieve TrackingGeometrySvc. Abort job. " );
31 return StatusCode::FAILURE;
32 }
33 m_trackingGeometryName = m_trackingGeometrySvc->trackingGeometryName();
34
35 return StatusCode::SUCCESS;
36}
37
39{
40 ATH_MSG_VERBOSE("Booking the Material Tree.");
41
42 // ------------------------------> OUTPUT NTUPLE (geometry validation)
43
44 m_mappingTree = new TTree(m_mappingTreeName.value().c_str(),
45 m_mappingTreeDescription.value().c_str());
46 // add the Branches
47 m_mappingTree->Branch("ValPosX", &m_mappingPositionX, "valpx/F");
48 m_mappingTree->Branch("ValPosY", &m_mappingPositionY, "valpy/F");
49 m_mappingTree->Branch("ValPosZ", &m_mappingPositionZ, "valpz/F");
50 m_mappingTree->Branch("ValPosR", &m_mappingPositionR, "valpr/F");
51
52 // add the Branches for the association objects
53 m_mappingTree->Branch("AssocPosX", &m_assignedPositionX, "asspx/F");
54 m_mappingTree->Branch("AssocPosY", &m_assignedPositionY, "asspy/F");
55 m_mappingTree->Branch("AssocPosZ", &m_assignedPositionZ, "asspz/F");
56 m_mappingTree->Branch("AssocPosR", &m_assignedPositionR, "asspr/F");
57 m_mappingTree->Branch("AssocCorr", &m_assignedCorrection, "asscor/F");
58 m_mappingTree->Branch("AssocLayer", &m_assignedLayerIndex, "assidx/I");
59 m_mappingTree->Branch("AssocDistance", &m_assignmentDistance, "asignd/F");
60
61 // ------------------------------> OUTPUT NTUPLE (unmapped hits)
62 m_unmappedTree = new TTree("UnmappedHits", "Unmapped Hits of the MappingTest Algorithm");
63 // add the Branches
64 m_unmappedTree->Branch("UnmappedHitX", &m_unmappedPositionX, "unmappedx/F");
65 m_unmappedTree->Branch("UnmappedHitY", &m_unmappedPositionY, "unmappedy/F");
66 m_unmappedTree->Branch("UnmappedHitZ", &m_unmappedPositionZ, "unmappedz/F");
67 m_unmappedTree->Branch("UnmappedHitR", &m_unmappedPositionR, "unmappedr/F");
68
69 // now register the Tree
70 SmartIF<ITHistSvc> tHistSvc{service("THistSvc")};
71 if (!tHistSvc) {
72 ATH_MSG_ERROR( "initialize() Could not find Hist Service -> Switching Tree output off !" );
73 delete m_unmappedTree; m_unmappedTree = nullptr;
74 delete m_mappingTree; m_mappingTree = nullptr;
75 }
76 if (tHistSvc && ((tHistSvc->regTree("/val/UnmappedAssociations", m_unmappedTree)).isFailure()
77 || (tHistSvc->regTree("/val/MappingTest", m_mappingTree)).isFailure()) ) {
78 ATH_MSG_ERROR( "initialize() Could not register the validation Tree -> Switching Tree output off !" );
79 delete m_unmappedTree; m_unmappedTree = nullptr;
80 delete m_mappingTree; m_mappingTree = nullptr;
81 }
82
83 return StatusCode::SUCCESS;
84
85}
86
88{
89 ATH_MSG_VERBOSE("Running the MappingTest Test");
90
91 // ------------------------------- get the trackingGeometry at first place
92 if (!m_trackingGeometry) {
93 if ((detStore()->retrieve(m_trackingGeometry, m_trackingGeometryName)).isFailure())
94 ATH_MSG_FATAL( "Could not retrieve TrackingGeometry '" << m_trackingGeometryName << "' from DetectorStore." );
95 else
96 ATH_MSG_INFO( "TrackingGeometry '" << m_trackingGeometryName << "' successfully retrieved from DetectorStore." );
97 }
98 // only run if it didn't already run before
100 // get the volume and the overal boundaries
101 const TrackingVolume* tVolume = m_trackingGeometry->trackingVolume(m_mappingVolumeName);
102 if (tVolume){
103 ATH_MSG_INFO("Retrieved TrackingVolume '" << tVolume->volumeName() << "'. Start the mapping validation.");
104 const Trk::CylinderVolumeBounds* cvb = dynamic_cast<const Trk::CylinderVolumeBounds*>(&(tVolume->volumeBounds()));
105 if (cvb){
106 double mRad = cvb->innerRadius();
107 double dRad = cvb->deltaRadius();
108 double zHalf = cvb->halflengthZ();
109 // run the mapping
110 for ( size_t it = 0; it < TrkDetDescrUnitTestBase::m_numTests; ++it ){
111 // create the mapping position
112 double mapRad = mRad + TrkDetDescrUnitTestBase::m_flatDist->shoot()*dRad;
113 double mapPhi = M_PI * (2*TrkDetDescrUnitTestBase::m_flatDist->shoot() - 1.);
114 double mapZ = zHalf * (2*TrkDetDescrUnitTestBase::m_flatDist->shoot() - 1.);
115 double mapX = mapRad*cos(mapPhi);
116 double mapY = mapRad*sin(mapPhi);
117 // the mapping position & unit is the same
118 Amg::Vector3D position(mapX, mapY, mapZ);
119 Amg::Vector3D direction = position.normalized();
120 // create curvilinear parameters
122 // get the closest material layer
124 = m_trackingGeometry->closestMaterialLayer<Trk::NeutralCurvilinearParameters>(ncp, Trk::mappingMode, true);
125 if (lIntersect.intersection.valid){
126 // the mapping positions
127 m_mappingPositionX = mapX;
128 m_mappingPositionY = mapY;
129 m_mappingPositionZ = mapZ;
130 m_mappingPositionR = mapRad;
131 // the resulting assigned position
135 m_assignedPositionR = lIntersect.intersection.position.perp();
139 // and now write the tree
140 m_mappingTree->Fill();
141 } else {
142 // the unmapped positions
143 // and now fill the tree
144 m_unmappedPositionX = mapY;
145 m_unmappedPositionY = mapY;
146 m_unmappedPositionZ = mapZ;
147 m_unmappedPositionR = mapRad;
148 // and now fill the tree
149 m_unmappedTree->Fill();
150 }
151 }
152 }
153 } else
154 ATH_MSG_INFO("Could not retrieve the TrackingVolume '" << m_mappingVolumeName << "'." );
155
156 }
157 m_executed = true;
158 return StatusCode::SUCCESS;
159
160}
161
162
#define M_PI
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
const ServiceHandle< StoreGateSvc > & detStore() const
Bounds for a cylindrical Volume, the decomposeToSurfaces method creates a vector of up to 6 surfaces:
double innerRadius() const
This method returns the inner radius.
double halflengthZ() const
This method returns the halflengthZ.
double deltaRadius() const
This method returns the delta radius.
Intersection intersection
int value() const
layerIndex expressed in an integer
Definition LayerIndex.h:71
const LayerIndex & layerIndex() const
get the layerIndex
StatusCode runTest()
TTree * m_unmappedTree
Definition MappingTest.h:82
float m_mappingPositionY
Definition MappingTest.h:70
Gaudi::Property< std::string > m_mappingVolumeName
Definition MappingTest.h:60
ServiceHandle< Trk::ITrackingGeometrySvc > m_trackingGeometrySvc
Definition MappingTest.h:52
StatusCode initializeTest()
StatusCode bookTree()
Gaudi::Property< std::string > m_mappingTreeDescription
Definition MappingTest.h:66
float m_assignedPositionZ
Definition MappingTest.h:76
float m_unmappedPositionZ
Definition MappingTest.h:85
float m_unmappedPositionX
Definition MappingTest.h:83
Gaudi::Property< std::string > m_mappingTreeName
Definition MappingTest.h:64
float m_assignmentDistance
Definition MappingTest.h:80
bool m_executed
Make sure it only runs once.
Definition MappingTest.h:49
float m_mappingPositionX
Definition MappingTest.h:69
float m_assignedCorrection
Definition MappingTest.h:78
float m_mappingPositionR
Definition MappingTest.h:72
float m_assignedPositionY
Definition MappingTest.h:75
TTree * m_mappingTree
Definition MappingTest.h:67
float m_assignedPositionR
Definition MappingTest.h:77
float m_mappingPositionZ
Definition MappingTest.h:71
float m_unmappedPositionY
Definition MappingTest.h:84
const TrackingGeometry * m_trackingGeometry
The TrackingGeometry to be retrieved.
Definition MappingTest.h:54
std::string m_trackingGeometryName
The Name of the TrackingGeometry.
Definition MappingTest.h:55
float m_unmappedPositionR
Definition MappingTest.h:86
float m_assignedPositionX
Definition MappingTest.h:74
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
const std::string & volumeName() const
Returns the VolumeName - for debug reason, might be depreciated later.
Gaudi::Property< size_t > m_numTests
number of tests
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
Definition Volume.h:96
Eigen::Matrix< double, 3, 1 > Vector3D
@ mappingMode
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
CurvilinearParametersT< NeutralParametersDim, Neutral, PlaneSurface > NeutralCurvilinearParameters
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
FullIntersection< Layer, Surface, T > LayerIntersection
Amg::Vector3D position