ATLAS Offline Software
SurfaceIntersectionTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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 Trk::SurfaceIntersectionTest::SurfaceIntersectionTest(const std::string& name, ISvcLocator* pSvcLocator) :
23  Trk::TrkDetDescrUnitTestBase(name, pSvcLocator),
24  m_surfaceBuilder(),
25  m_testsPerSurface(100),
26  m_eventCounter(0),
27  m_surfaces(6,0),
28  m_surfaceAttempts(6,0),
29  m_surfaceSuccessful(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  ITHistSvc* tHistSvc = nullptr;
98  if (m_writeTTree && service("THistSvc",tHistSvc).isFailure()) {
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  }
170  ++m_eventCounter;
171  return StatusCode::SUCCESS;
172 }
173 
174 
VectorNtupleBranch.h
Trk::TrkDetDescrUnitTestBase::m_numTests
size_t m_numTests
number of tests
Definition: TrkDetDescrUnitTestBase.h:61
Trk::SurfaceNtupleBranch::fill
void fill(const Trk::Surface &surface)
fill a vector
Definition: SurfaceNtupleBranch.cxx:30
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::Intersection
Definition: Intersection.h:24
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Surface.h
Trk::TrkDetDescrUnitTestBase::m_gaussDist
Rndm::Numbers * m_gaussDist
Random Number setup.
Definition: TrkDetDescrUnitTestBase.h:57
Trk::VectorNtupleBranch
This class provides a simple interface to write Vectors to a root tree The size of the vectors cannot...
Definition: VectorNtupleBranch.h:34
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::TrkDetDescrUnitTestBase
Definition: TrkDetDescrUnitTestBase.h:27
SurfaceNtupleBranch.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
Trk::SurfaceType
SurfaceType
Definition: SurfaceTypes.h:17
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
intersection
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
Definition: compareFlatTrees.cxx:25
SurfaceIntersectionTest.h
Trk::VectorNtupleBranch::initForWrite
bool initForWrite(TTree &tree, const std::string &varname, int nrow, const std::string &prefix="")
initialize class for writing
Definition: VectorNtupleBranch.cxx:10
Trk::VectorNtupleBranch::fill
bool fill(const Amg::VectorX &matrix)
fill a vector
Definition: VectorNtupleBranch.cxx:34
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition: GeoPrimitivesToStringConverter.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::TrkDetDescrUnitTestBase::finalize
StatusCode finalize()
standard Athena-Algorithm method
Definition: TrkDetDescrUnitTestBase.cxx:53
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
dumpFileToPlots.treeName
string treeName
Definition: dumpFileToPlots.py:20
Trk::SurfaceIntersectionTest::SurfaceIntersectionTest
SurfaceIntersectionTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: SurfaceIntersectionTest.cxx:22
Trk::SurfaceIntersectionTest::m_testsPerSurface
size_t m_testsPerSurface
Definition: SurfaceIntersectionTest.h:48
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SurfaceIntersectionTest::initializeTest
StatusCode initializeTest()
initialize the test, i.e.
Definition: SurfaceIntersectionTest.cxx:57
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Trk::SurfaceNtupleBranch::initForWrite
void initForWrite(TTree &tree, const std::string &prefix="")
initialize class for writing
Definition: SurfaceNtupleBranch.cxx:11
Trk::SurfaceNtupleBranch
This class provides a simple interface to write Surfaces to a root tree.
Definition: SurfaceNtupleBranch.h:36
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::SurfaceIntersectionTest::m_writeTTree
bool m_writeTTree
Definition: SurfaceIntersectionTest.h:57
Trk::SurfaceIntersectionTest::finalize
StatusCode finalize()
Definition: SurfaceIntersectionTest.cxx:41
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
GeoPrimitivesToStringConverter.h
Trk::SurfaceIntersectionTest::m_surfaceBuilder
ToolHandle< ISurfaceBuilder > m_surfaceBuilder
Definition: SurfaceIntersectionTest.h:46
Trk::SurfaceIntersectionTest::runTest
StatusCode runTest()
Definition: SurfaceIntersectionTest.cxx:70
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75