ATLAS Offline Software
Loading...
Searching...
No Matches
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
24Trk::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),
46 m_unmappedTree(nullptr),
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
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
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
172 m_assignedPositionR = lIntersect.intersection.position.perp();
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
#define M_PI
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
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:75
float m_mappingPositionY
Definition MappingTest.h:63
ServiceHandle< Trk::ITrackingGeometrySvc > m_trackingGeometrySvc
Service handle for retrieving the TrackingGeometry.
Definition MappingTest.h:51
StatusCode initializeTest()
StatusCode bookTree()
float m_assignedPositionZ
Definition MappingTest.h:69
float m_unmappedPositionZ
Definition MappingTest.h:78
float m_unmappedPositionX
Definition MappingTest.h:76
float m_assignmentDistance
Definition MappingTest.h:73
bool m_executed
Make sure it only runs once.
Definition MappingTest.h:49
float m_mappingPositionX
Definition MappingTest.h:62
double m_etaCutOff
do not map beyond this point
Definition MappingTest.h:55
std::string m_mappingTreeDescription
Definition MappingTest.h:59
float m_assignedCorrection
Definition MappingTest.h:71
float m_mappingPositionR
Definition MappingTest.h:65
float m_assignedPositionY
Definition MappingTest.h:68
TTree * m_mappingTree
Definition MappingTest.h:60
float m_assignedPositionR
Definition MappingTest.h:70
float m_mappingPositionZ
Definition MappingTest.h:64
MappingTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
float m_unmappedPositionY
Definition MappingTest.h:77
const TrackingGeometry * m_trackingGeometry
The TrackingGeometry to be retrieved.
Definition MappingTest.h:52
std::string m_mappingVolumeName
only map within this volume
Definition MappingTest.h:56
std::string m_trackingGeometryName
The Name of the TrackingGeometry.
Definition MappingTest.h:53
float m_unmappedPositionR
Definition MappingTest.h:79
std::string m_mappingTreeName
Definition MappingTest.h:58
float m_assignedPositionX
Definition MappingTest.h:67
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.
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
const VolumeBounds & volumeBounds() const
returns the volumeBounds()
Definition Volume.h:96
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
@ mappingMode
CurvilinearParametersT< NeutralParametersDim, Neutral, PlaneSurface > NeutralCurvilinearParameters
FullIntersection< Layer, Surface, T > LayerIntersection
Amg::Vector3D position