ATLAS Offline Software
ActsWriteTrackingGeometryTransforms.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // PACKAGE
10 
11 
12 // ATHENA
15 #include "GaudiKernel/ISvcLocator.h"
16 #include "ActsInterop/Logger.h"
17 
18 // ACTS
19 #include "Acts/Utilities/Logger.hpp"
20 #include "Acts/Geometry/TrackingGeometry.hpp"
21 #include "Acts/Surfaces/Surface.hpp"
22 #include "Acts/Geometry/GeometryIdentifier.hpp"
23 
24 // STL
25 #include <string>
26 
27 using gid = Acts::GeometryIdentifier;
28 
30  ISvcLocator* pSvcLocator)
31  : AthAlgorithm(name, pSvcLocator),m_pixelID(nullptr),m_SCT_ID(nullptr),
32  m_writeFullTransform(false)
33 {
34 }
35 
37 
38  // Grab PixelID helper
39  ATH_CHECK (detStore()->retrieve(m_pixelID, "PixelID") );
40  ATH_CHECK (detStore()->retrieve(m_SCT_ID,"SCT_ID") );
41 
43 
44  std::ofstream os(m_outputName); // truncate
45 
46  return StatusCode::SUCCESS;
47 }
48 
50 
51  ATH_MSG_DEBUG("In ActsWriteTrackingGeometryTransforms::execute");
52 
53 
54  const EventContext& ctx = Gaudi::Hive::currentContext();
55 
56  auto trackingGeometry = m_trackingGeometryTool->trackingGeometry();
57  ATH_MSG_DEBUG("Retrieved tracking Geometry");
58  const ActsGeometryContext& gctx = m_trackingGeometryTool->getGeometryContext(ctx);
59  ATH_MSG_DEBUG("Retrieved geometry context");
60 
61  std::stringstream ss;
62 
63 
64  std::ofstream os(m_outputName, std::ios_base::app);
65 
66  trackingGeometry->visitSurfaces([&] (const Acts::Surface* srf) {
67  const Acts::DetectorElementBase *detElem = srf->associatedDetectorElement();
68  const auto *gmde = static_cast<const ActsDetectorElement *>(detElem);
69 
70  Identifier ath_geoid = gmde->identify();
71 
72  if(dynamic_cast<const InDetDD::TRT_BaseElement*>(gmde->upstreamDetectorElement()) != nullptr) {
73  return;
74  }
75 
76  if(dynamic_cast<const InDetDD::HGTD_DetectorElement*>(gmde->upstreamDetectorElement()) != nullptr) {
77  return;
78  }
79 
80  const auto sil_de = dynamic_cast<const InDetDD::SiDetectorElement*>(gmde->upstreamDetectorElement());
81  if(sil_de == nullptr) {
82  throw std::runtime_error{"Not TRT, Not HGTD and not Si either"}; // this shouldn't happen
83  }
84 
85  gid geoID = srf->geometryId();
86 
87  os << geoID.volume() << ";";
88  os << geoID.boundary() << ";";
89  os << geoID.layer() << ";";
90  os << geoID.sensitive() << ";";
91 
92  os << ctx.eventID().event_number() << ";";
93 
94  int bec,ld,etam,phim, side;
95 
96  if(sil_de->isPixel()) {
97  bec = m_pixelID->barrel_ec(ath_geoid);
98  ld = m_pixelID->layer_disk(ath_geoid);
99  etam = m_pixelID->eta_module(ath_geoid);
100  phim = m_pixelID->phi_module(ath_geoid);
101  side = 0;
102  os << 0;
103  }
104  else if(sil_de->isSCT()) {
105 
106  bec = m_SCT_ID->barrel_ec(ath_geoid);
107  ld = m_SCT_ID->layer_disk(ath_geoid);
108  etam = m_SCT_ID->eta_module(ath_geoid);
109  phim = m_SCT_ID->phi_module(ath_geoid);
110  side = m_SCT_ID->side(ath_geoid);
111  os << 1;
112  }
113  else {
114  throw std::runtime_error{"The Detector Element is neither Pixel nor SCT"}; // this shouldn't happen
115  }
116  // Write the type of silicon first (0=PIX, 1=SCT)
117  os << ";";
118 
119  // Then write the athena geoid and the unpacked version
120  os<<ath_geoid<<","<<bec<<","<<ld<<","<<etam<<","<<phim<<","<<side<<";";
121 
122  ATH_MSG_DEBUG(geoID<<" "<<ath_geoid<<" "<<bec<<" "<<ld<<" "<<etam<<" "<<phim<<" "<<side);
123 
124  const ActsGeometryContext void_gctx;
125  if (m_writeFullTransform) {
126  // iterate over components of transform
127  const auto* p = srf->transform(gctx.context()).data();
128  for(size_t i=0;i<16;i++) {
129  if(i>0) {
130  os << ",";
131  }
132  os << *(p+i);
133  }
134  } else { // only write center of the detector element
135  double cx = srf->center(void_gctx.context()).x();
136  double cy = srf->center(void_gctx.context()).y();
137  double cz = srf->center(void_gctx.context()).z();
138  os<<cx<<","<<cy<<","<<cz;
139  }
140 
141  os << "\n";
142  });
143 
144 
145  return StatusCode::SUCCESS;
146 }
147 
149  return StatusCode::SUCCESS;
150 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ActsGeometryContext.h
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
PixelID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: PixelID.h:619
ActsWriteTrackingGeometryTransforms::ActsWriteTrackingGeometryTransforms
ActsWriteTrackingGeometryTransforms(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsWriteTrackingGeometryTransforms.cxx:29
InDetDD::HGTD_DetectorElement
Definition: HGTD_DetectorElement.h:40
ActsWriteTrackingGeometryTransforms::m_trackingGeometryTool
ToolHandle< IActsTrackingGeometryTool > m_trackingGeometryTool
Definition: ActsWriteTrackingGeometryTransforms.h:47
SCT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: SCT_ID.h:728
ActsWriteTrackingGeometryTransforms::m_outputName
Gaudi::Property< std::string > m_outputName
Definition: ActsWriteTrackingGeometryTransforms.h:49
SCT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: SCT_ID.h:740
x
#define x
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT::Hit::side
@ side
Definition: HitInfo.h:83
AthAlgorithm.h
ActsGeometryContext::context
Acts::GeometryContext context() const
Definition: ActsGeometryContext.h:46
PlotCalibFromCool.cx
cx
Definition: PlotCalibFromCool.py:666
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
ActsWriteTrackingGeometryTransforms::initialize
virtual StatusCode initialize() override
Definition: ActsWriteTrackingGeometryTransforms.cxx:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
IActsTrackingGeometrySvc.h
ActsWriteTrackingGeometryTransforms::execute
virtual StatusCode execute() override
Definition: ActsWriteTrackingGeometryTransforms.cxx:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsDetectorElement
Definition: ActsDetectorElement.h:42
ActsWriteTrackingGeometryTransforms::m_writeFullTransform
Gaudi::Property< bool > m_writeFullTransform
Definition: ActsWriteTrackingGeometryTransforms.h:50
ActsDetectorElement.h
gid
Acts::GeometryIdentifier gid
Definition: ActsWriteTrackingGeometryTransforms.cxx:27
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:28
AthAlgorithm
Definition: AthAlgorithm.h:47
ActsWriteTrackingGeometryTransforms::m_pixelID
const PixelID * m_pixelID
Definition: ActsWriteTrackingGeometryTransforms.h:44
PixelID::layer_disk
int layer_disk(const Identifier &id) const
Definition: PixelID.h:626
PixelID::eta_module
int eta_module(const Identifier &id) const
Definition: PixelID.h:651
ActsWriteTrackingGeometryTransforms::m_SCT_ID
const SCT_ID * m_SCT_ID
Definition: ActsWriteTrackingGeometryTransforms.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SCT_ID::layer_disk
int layer_disk(const Identifier &id) const
Definition: SCT_ID.h:734
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
RNGWrapper.h
y
#define y
PlotCalibFromCool.cy
cy
Definition: PlotCalibFromCool.py:667
SCT_ID::eta_module
int eta_module(const Identifier &id) const
Definition: SCT_ID.h:746
ActsWriteTrackingGeometryTransforms::finalize
virtual StatusCode finalize() override
Definition: ActsWriteTrackingGeometryTransforms.cxx:148
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
Logger.h
PixelID::phi_module
int phi_module(const Identifier &id) const
Definition: PixelID.h:644
geometry_dat_to_json.ld
ld
Definition: geometry_dat_to_json.py:14
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
ActsWriteTrackingGeometryTransforms.h