ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceIntersectionTest.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// IntersectionTest.cxx, (c) ATLAS Detector software
8
9// Amg includes
11// Trk includes
15#include "TrkSurfaces/Surface.h"
16//Root includes
17#include "TTree.h"
18#include "TString.h"
19// Gaudi
20#include "GaudiKernel/ITHistSvc.h"
21
22
24
25 ATH_MSG_INFO("Test statistics output ---------------------- (start) -------------");
26 for (size_t it = 0; it < m_surfaces.size(); ++it){
27 if (m_surfaceNamesSet[it]){
28 ATH_MSG_INFO("Tested " << m_surfaces[it] << " created "<< m_surfaceNames[it] << " objects.");
29 ATH_MSG_INFO(" -> Result [ attempts / successful (percentage)] : "
30 << m_surfaceAttempts[it] << " / " << m_surfaceSuccessful[it]
31 << " ( " << double(m_surfaceSuccessful[it])/m_surfaceAttempts[it] << " )" );
32 }
33 }
34 ATH_MSG_INFO("Test statistics output ----------------------- (end) --------------");
35
37}
38
40{
41 if ( m_surfaceBuilder.retrieve().isFailure() ){
42 ATH_MSG_FATAL("Could not retrieve surface builder. Aborting.");
43 return StatusCode::FAILURE;
44 }
45 // success return
46 return StatusCode::SUCCESS;
47}
48
49
50
51
53{
54 ATH_MSG_VERBOSE("Running the SurfaceIntersectionTest Test");
55
56 // ----------------- creation of the surfaces & track parameters -------------
57 for (size_t it = 0; it < TrkDetDescrUnitTestBase::m_numTests; ++it ){
58
59 // get a surface from the surface builder
60 const Trk::Surface* sf = m_surfaceBuilder->surface();
61 if (!sf) continue;
62
63 // get the type
64 Trk::SurfaceType sType = sf->type();
65 ++m_surfaces[static_cast<int>(sType)];
66
67 ATH_MSG_VERBOSE("Surface of type " << sf->name() << " at postion " << Amg::toString(sf->center()));
68 if (!m_surfaceNamesSet[static_cast<int>(sType)]) {
69 m_surfaceNames[static_cast<int>(sType)] = sf->name();
70 m_surfaceNamesSet[static_cast<int>(sType)] = true;
71 }
72 // create the Tree for this TrackingVolume
73 TString treeName = "IntersectionTest_Event";
74 treeName += m_eventCounter;
75 TTree* currentTree = new TTree(treeName.Data(),"Intersection");
76 treeName += "_Info";
77 TTree* currentInfoTree = new TTree(treeName.Data(),"Surface Information");
78
79 SmartIF<ITHistSvc> tHistSvc;
80 if (m_writeTTree && (tHistSvc = service("THistSvc")).isValid()) {
81 ATH_MSG_FATAL( "initialize() Could not find Hist Service! Aborting." );
82 return StatusCode::FAILURE;
83 }
84 // create the name under which the tree is registered
85 TString fullTreeName = m_treeFolder+"Intersection_Event";
86 fullTreeName += m_eventCounter;
87 fullTreeName += "_Number";
88 fullTreeName += it;
89 fullTreeName += "_"+sf->name();
90
91 if (m_writeTTree && tHistSvc->regTree(fullTreeName.Data(), currentTree).isFailure()) {
92 ATH_MSG_ERROR( "initialize() Could not register the validation Tree! Aborting." );
93 delete currentTree;
94 return StatusCode::FAILURE;
95 }
96
97 TString fullInfoTreeName = m_treeFolder+"SurfaceInfo_Event";
98 fullInfoTreeName += m_eventCounter;
99 fullInfoTreeName += "_Number";
100 fullInfoTreeName += it;
101 fullInfoTreeName += "_"+sf->name();
102 if (m_writeTTree && tHistSvc->regTree(fullInfoTreeName.Data(), currentInfoTree).isFailure()) {
103 ATH_MSG_ERROR( "initialize() Could not register the validation Tree! Aborting." );
104 delete currentInfoTree;
105 return StatusCode::FAILURE;
106 }
107
108 // the ntuple branches
109 Trk::SurfaceNtupleBranch surfaceBranch;
110 surfaceBranch.initForWrite(*currentInfoTree);
111 surfaceBranch.fill(*sf);
112
113 Trk::VectorNtupleBranch intersectionBranch;
114 intersectionBranch.initForWrite(*currentTree,"Intersection_",3);
115
116 {
117 for (size_t ist = 0; ist < m_testsPerSurface; ++ist){
118 // starting around the perigee
119 Amg::Vector3D startPosition;
120 startPosition.x() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 50.;
121 startPosition.y() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 50.;
122 startPosition.z() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 150.;
123 // aiming towards the surface center
124 const Amg::Vector3D& sfCenter = sf->center();
125 Amg::Vector3D direction = sf->center();
126 direction.x() = sfCenter.x()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
127 direction.y() = sfCenter.y()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
128 direction.z() = sfCenter.z()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
129 direction = direction.normalized();
130 ATH_MSG_VERBOSE(" -> Line: " << Amg::toString(startPosition) << " + t * " << Amg::toString(direction));
131
132 // now doing the distance estimation
133 Trk::Intersection intersection = sf->straightLineIntersection(startPosition,direction,false);
134 ++m_surfaceAttempts[static_cast<int>(sType)];
135 // now check if the intesection is valid or not
136 if (intersection.valid){
137 ++m_surfaceSuccessful[static_cast<int>(sType)];
138 Amg::Vector3D consistency = (intersection.position-intersection.pathLength*direction) - startPosition;
139 if (m_writeTTree){
140 intersectionBranch.fill(intersection.position);
141 currentTree->Fill();
142 }
143 ATH_MSG_VERBOSE( " -o Intersection at " << Amg::toString(intersection.position) );
144 ATH_MSG_VERBOSE( " -x Cross-checked at " << Amg::toString(consistency) );
145 }
146 }
147 // write the tree
148 if (m_writeTTree) currentInfoTree->Fill();
149 delete sf;
150 }
151 }
153 return StatusCode::SUCCESS;
154}
155
156
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
Gaudi::Property< bool > m_writeTTree
StatusCode initializeTest()
initialize the test, i.e.
ToolHandle< ISurfaceBuilder > m_surfaceBuilder
std::vector< size_t > m_surfaceAttempts
std::vector< size_t > m_surfaceSuccessful
Gaudi::Property< size_t > m_testsPerSurface
std::vector< std::string > m_surfaceNames
Abstract Base Class for tracking surfaces.
Definition Surface.h:79
StatusCode finalize()
standard Athena-Algorithm method
Rndm::Numbers * m_gaussDist
Random Number setup.
Gaudi::Property< size_t > m_numTests
number of tests
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 1 > Vector3D
SurfaceType
This enumerator simplifies the persistency & calculations,.
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
This class provides a simple interface to write Surfaces to a root tree.
void initForWrite(TTree &tree, std::string_view prefix="")
initialize class for writing
void fill(const Trk::Surface &surface)
fill a vector
This class provides a simple interface to write Vectors to a root tree The size of the vectors cannot...
bool initForWrite(TTree &tree, std::string_view varname, int nrow, std::string_view prefix="")
initialize class for writing
bool fill(const Amg::VectorX &matrix)
fill a vector