ATLAS Offline Software
GeometryJsonDumper.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 // GeometryJsonDumper.cxx, (c) ATLAS Detector software
8 
9 // Amg includes
11 // Trk include
14 #include "TrkGeometry/Layer.h"
15 #include "TrkSurfaces/Surface.h"
17 // output stream
18 #include <sstream>
19 
20 // Gaudi
21 #include "GaudiKernel/ITHistSvc.h"
22 
23 
24 // constructor
25 Trk::GeometryJsonDumper::GeometryJsonDumper(const std::string& t, const std::string& n, const IInterface* p) :
27  m_outputFileName("TrackingGeometry.json"),
28  m_outputPrecision(6),
29  m_firstLayerWritten(false)
30 {
31  declareProperty("OutputFileName", m_outputFileName);
32  declareProperty("OutputPrecision", m_outputPrecision);
33 }
34 
35 // destructor
37 = default;
38 
39 
41 {
42  // open the file for writing
43  m_outputFile.open(m_outputFileName.c_str());
44  m_outputFile << "[";
45  m_outputFile << std::setiosflags(std::ios::fixed);
46  m_outputFile << std::setprecision(3);
47  // return the base::initialize() state
49 }
50 
52 {
53  // close the file
54  m_outputFile << "]" << std::endl;
55  m_outputFile.close();
56  // return the base::finalize() state
58 }
59 
60 
61 
63 {
64  return StatusCode::SUCCESS;
65 }
66 
67 
68 StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Layer& lay, size_t /*level*/) const
69 {
70 
71  ATH_MSG_VERBOSE("Dumping information for Layer with index " << lay.layerIndex().value());
72 
73  if (lay.surfaceArray()){
74  size_t nSurfaces = lay.surfaceArray()->arrayObjects().size();
75  // the layer has a surface Array - go for it
76  // get the dimensions
77  const Trk::Surface* referenceSurface = lay.subSurfaceReference();
78  // the reference Surface exists
79  if (referenceSurface){
80  // dynamic_cast to RectangleBounds
81  const Trk::RectangleBounds* rBounds = dynamic_cast<const Trk::RectangleBounds*>(&(referenceSurface->bounds()));
82  // we have rBounds - go on for the moment
83  if (rBounds){
84  if (m_firstLayerWritten) m_outputFile << ",";
85  // the layer is defined
86  m_outputFile << "{\"Name\" : \"Layer " << lay.layerIndex().value() << "\", ";
87  m_outputFile << "\"Dimensions\" : [" << 2*rBounds->halflengthX() << "," << 2.*rBounds->halflengthY() << ", 1.0 ], ";
88  // count the surfaces
89  size_t is = 1;
90  // now loop of the surfaces and dumpt their position
91  m_outputFile << "\"Coords\": [";
92  for (const auto & sf : lay.surfaceArray()->arrayObjects()){
93  // get x,y,z
94  double cx = sf->center().x();
95  double cy = sf->center().y();
96  double cz = sf->center().z();
97  // get the euler angles
98  auto ea = sf->transform().rotation().eulerAngles(0, 1, 2);
99  double e0 = ea[0];
100  double e1 = ea[1];
101  double e2 = ea[2];
102  m_outputFile << "[" << cx << "," << cy << "," << cz << "],[" << e0 << "," << e1 << "," << e2 << "]";
103  if (is < nSurfaces) m_outputFile << ",";
104  ++is;
105  }
106  m_outputFile << "]}";
107  m_firstLayerWritten = true;
108  }
109  }
110  }
111  return StatusCode::SUCCESS;
112 }
113 
114 
115 StatusCode Trk::GeometryJsonDumper::processNode(const Trk::Surface& /*sf*/, size_t /*level*/) const
116 {
117  ATH_MSG_VERBOSE("Dumping information for Surfaces.");
118 
119  return StatusCode::SUCCESS;
120 }
Trk::RectangleBounds
Definition: RectangleBounds.h:38
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
RectangleBounds.h
Surface.h
Trk::RecursiveGeometryProcessor::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: RecursiveGeometryProcessor.cxx:32
egammaEnergyPositionAllSamples::e1
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Layer.h
Trk::GeometryJsonDumper::initialize
StatusCode initialize()
AlgTool initialize method.
Definition: GeometryJsonDumper.cxx:40
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::Layer::subSurfaceReference
const Surface * subSurfaceReference(unsigned int idx=0) const
Return a reference sub surface of the layer, usually the first one in the array.
Definition: Layer.cxx:131
Trk::Layer::surfaceArray
const SurfaceArray * surfaceArray() const
Return the entire SurfaceArray, returns nullptr if no SurfaceArray.
Trk::RecursiveGeometryProcessor::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: RecursiveGeometryProcessor.cxx:39
PlotCalibFromCool.cx
cx
Definition: PlotCalibFromCool.py:666
Trk::RectangleBounds::halflengthX
double halflengthX() const
for consistant naming
Trk::GeometryJsonDumper::m_outputPrecision
int m_outputPrecision
Definition: GeometryJsonDumper.h:66
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::LayerIndex::value
int value() const
layerIndex expressed in an integer
Definition: LayerIndex.h:71
GeometryJsonDumper.h
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::GeometryJsonDumper::finalize
StatusCode finalize()
AlgTool finalize method.
Definition: GeometryJsonDumper.cxx:51
Trk::Surface::bounds
virtual const SurfaceBounds & bounds() const =0
Surface Bounds method.
Trk::BinnedArray::arrayObjects
virtual BinnedArraySpan< T *const > arrayObjects()=0
Return all objects of the Array non-const we can still modify the T.
Trk::RecursiveGeometryProcessor
Definition: RecursiveGeometryProcessor.h:39
Trk::RectangleBounds::halflengthY
double halflengthY() const
for consitant naming
Trk::GeometryJsonDumper::m_outputFileName
std::string m_outputFileName
where the tree is written to
Definition: GeometryJsonDumper.h:65
Trk::GeometryJsonDumper::processNode
StatusCode processNode(const TrackingVolume &tvol, size_t level=0) const
Current implementation: write root visualization to file stream.
Definition: GeometryJsonDumper.cxx:62
mapkey::sf
@ sf
Definition: TElectronEfficiencyCorrectionTool.cxx:38
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
PlotCalibFromCool.cy
cy
Definition: PlotCalibFromCool.py:667
Trk::GeometryJsonDumper::GeometryJsonDumper
GeometryJsonDumper(const std::string &, const std::string &, const IInterface *)
Constructor.
Definition: GeometryJsonDumper.cxx:25
GeoPrimitivesToStringConverter.h
TrackingGeometry.h
Trk::GeometryJsonDumper::~GeometryJsonDumper
virtual ~GeometryJsonDumper()
Destructor.
egammaEnergyPositionAllSamples::e0
double e0(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in pre-sampler
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::Layer
Definition: Layer.h:73
Trk::Layer::layerIndex
const LayerIndex & layerIndex() const
get the layerIndex