ATLAS Offline Software
Loading...
Searching...
No Matches
SurfaceIntersectionTest.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// 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
22Trk::SurfaceIntersectionTest::SurfaceIntersectionTest(const std::string& name, ISvcLocator* pSvcLocator) :
23 Trk::TrkDetDescrUnitTestBase(name, pSvcLocator),
27 m_surfaces(6,0),
30 m_surfaceNames(6,""),
31 m_surfaceNamesSet(6,false),
32 m_writeTTree(true),
33 m_treeFolder("/val/")
34{
35 declareProperty("SurfaceBuilder", m_surfaceBuilder);
36 declareProperty("NumberOfTestsPerSurface", m_testsPerSurface);
37 declareProperty("WriteTTree", m_writeTTree);
38
39}
40
42
43 ATH_MSG_INFO("Test statistics output ---------------------- (start) -------------");
44 for (size_t it = 0; it < m_surfaces.size(); ++it){
45 if (m_surfaceNamesSet[it]){
46 ATH_MSG_INFO("Tested " << m_surfaces[it] << " created "<< m_surfaceNames[it] << " objects.");
47 ATH_MSG_INFO(" -> Result [ attempts / successful (percentage)] : "
48 << m_surfaceAttempts[it] << " / " << m_surfaceSuccessful[it]
49 << " ( " << double(m_surfaceSuccessful[it])/m_surfaceAttempts[it] << " )" );
50 }
51 }
52 ATH_MSG_INFO("Test statistics output ----------------------- (end) --------------");
53
55}
56
58{
59 if ( m_surfaceBuilder.retrieve().isFailure() ){
60 ATH_MSG_FATAL("Could not retrieve surface builder. Aborting.");
61 return StatusCode::FAILURE;
62 }
63 // success return
64 return StatusCode::SUCCESS;
65}
66
67
68
69
71{
72 ATH_MSG_VERBOSE("Running the SurfaceIntersectionTest Test");
73
74 // ----------------- creation of the surfaces & track parameters -------------
75 for (size_t it = 0; it < TrkDetDescrUnitTestBase::m_numTests; ++it ){
76
77 // get a surface from the surface builder
78 const Trk::Surface* sf = m_surfaceBuilder->surface();
79 if (!sf) continue;
80
81 // get the type
82 Trk::SurfaceType sType = sf->type();
83 ++m_surfaces[static_cast<int>(sType)];
84
85 ATH_MSG_VERBOSE("Surface of type " << sf->name() << " at postion " << Amg::toString(sf->center()));
86 if (!m_surfaceNamesSet[static_cast<int>(sType)]) {
87 m_surfaceNames[static_cast<int>(sType)] = sf->name();
88 m_surfaceNamesSet[static_cast<int>(sType)] = true;
89 }
90 // create the Tree for this TrackingVolume
91 TString treeName = "IntersectionTest_Event";
92 treeName += m_eventCounter;
93 TTree* currentTree = new TTree(treeName.Data(),"Intersection");
94 treeName += "_Info";
95 TTree* currentInfoTree = new TTree(treeName.Data(),"Surface Information");
96
97 SmartIF<ITHistSvc> tHistSvc;
98 if (m_writeTTree && (tHistSvc = service("THistSvc")).isValid()) {
99 ATH_MSG_FATAL( "initialize() Could not find Hist Service! Aborting." );
100 return StatusCode::FAILURE;
101 }
102 // create the name under which the tree is registered
103 TString fullTreeName = m_treeFolder+"Intersection_Event";
104 fullTreeName += m_eventCounter;
105 fullTreeName += "_Number";
106 fullTreeName += it;
107 fullTreeName += "_"+sf->name();
108
109 if (m_writeTTree && tHistSvc->regTree(fullTreeName.Data(), currentTree).isFailure()) {
110 ATH_MSG_ERROR( "initialize() Could not register the validation Tree! Aborting." );
111 delete currentTree;
112 return StatusCode::FAILURE;
113 }
114
115 TString fullInfoTreeName = m_treeFolder+"SurfaceInfo_Event";
116 fullInfoTreeName += m_eventCounter;
117 fullInfoTreeName += "_Number";
118 fullInfoTreeName += it;
119 fullInfoTreeName += "_"+sf->name();
120 if (m_writeTTree && tHistSvc->regTree(fullInfoTreeName.Data(), currentInfoTree).isFailure()) {
121 ATH_MSG_ERROR( "initialize() Could not register the validation Tree! Aborting." );
122 delete currentInfoTree;
123 return StatusCode::FAILURE;
124 }
125
126 // the ntuple branches
127 Trk::SurfaceNtupleBranch surfaceBranch;
128 surfaceBranch.initForWrite(*currentInfoTree);
129 surfaceBranch.fill(*sf);
130
131 Trk::VectorNtupleBranch intersectionBranch;
132 intersectionBranch.initForWrite(*currentTree,"Intersection_",3);
133
134 {
135 for (size_t ist = 0; ist < m_testsPerSurface; ++ist){
136 // starting around the perigee
137 Amg::Vector3D startPosition;
138 startPosition.x() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 50.;
139 startPosition.y() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 50.;
140 startPosition.z() = TrkDetDescrUnitTestBase::m_gaussDist->shoot()* 150.;
141 // aiming towards the surface center
142 const Amg::Vector3D& sfCenter = sf->center();
143 Amg::Vector3D direction = sf->center();
144 direction.x() = sfCenter.x()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
145 direction.y() = sfCenter.y()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
146 direction.z() = sfCenter.z()*(1.+0.25*TrkDetDescrUnitTestBase::m_gaussDist->shoot());
147 direction = direction.normalized();
148 ATH_MSG_VERBOSE(" -> Line: " << Amg::toString(startPosition) << " + t * " << Amg::toString(direction));
149
150 // now doing the distance estimation
151 Trk::Intersection intersection = sf->straightLineIntersection(startPosition,direction,false);
152 ++m_surfaceAttempts[static_cast<int>(sType)];
153 // now check if the intesection is valid or not
154 if (intersection.valid){
155 ++m_surfaceSuccessful[static_cast<int>(sType)];
156 Amg::Vector3D consistency = (intersection.position-intersection.pathLength*direction) - startPosition;
157 if (m_writeTTree){
158 intersectionBranch.fill(intersection.position);
159 currentTree->Fill();
160 }
161 ATH_MSG_VERBOSE( " -o Intersection at " << Amg::toString(intersection.position) );
162 ATH_MSG_VERBOSE( " -x Cross-checked at " << Amg::toString(consistency) );
163 }
164 }
165 // write the tree
166 if (m_writeTTree) currentInfoTree->Fill();
167 delete sf;
168 }
169 }
171 return StatusCode::SUCCESS;
172}
173
174
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
StatusCode initializeTest()
initialize the test, i.e.
ToolHandle< ISurfaceBuilder > m_surfaceBuilder
std::vector< size_t > m_surfaceAttempts
std::vector< size_t > m_surfaceSuccessful
SurfaceIntersectionTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
std::vector< std::string > m_surfaceNames
Abstract Base Class for tracking surfaces.
StatusCode finalize()
standard Athena-Algorithm method
Rndm::Numbers * m_gaussDist
Random Number setup.
TrkDetDescrUnitTestBase(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
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
Ensure that the ATLAS eigen extensions are properly loaded.
SurfaceType
This enumerator simplifies the persistency & calculations,.
This class provides a simple interface to write Surfaces to a root tree.
void initForWrite(TTree &tree, const std::string &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, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for writing
bool fill(const Amg::VectorX &matrix)
fill a vector