ATLAS Offline Software
Loading...
Searching...
No Matches
ZDC_DetTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ZDC_DetTool.h"
6#include "ZDC_DetFactory.h"
7#include "ZDC_ZDCModule.h"
8#include "ZDC_RPDModule.h"
9#include "ZDC_BRANModule.h"
10#include "ZDC_DetManager.h"
13#include "GaudiKernel/IService.h"
14#include "GaudiKernel/ISvcLocator.h"
15#include "GaudiKernel/SystemOfUnits.h"
18#include <GeoModelKernel/GeoDefinitions.h>
19#include <memory>
20
21ZDC_DetTool::ZDC_DetTool(const std::string& type, const std::string& name, const IInterface* parent)
22 : GeoModelTool(type, name, parent)
23{
24
25 if (msgLevel(MSG::DEBUG))
26 msg(MSG::DEBUG) << "INSIDE CONSTRUCTOR OF DETTOOL" << endmsg
27 << "INSIDE CONSTRUCTOR OF DETTOOL string& type " << type << endmsg
28 << "INSIDE CONSTRUCTOR OF DETTOOL std::string& name " << name << endmsg;
29}
30
32{
33 // This will need to be modified once we register the Toy DetectorNode in the Transient Detector Store
34
35 if (nullptr != m_detector) {
36
37 delete m_detector;
38 m_detector = nullptr;
39 }
40}
41
43{
44 if (msgLevel(MSG::DEBUG)) msg(MSG::DEBUG) << " Building ZDC geometry " << endmsg;
45
46 // Locate the top level experiment node
47 GeoModelExperiment* theExpt = nullptr;
48 if (StatusCode::SUCCESS != detStore()->retrieve(theExpt, "ATLAS")) {
49 ATH_MSG_ERROR(" Could not find GeoModelExperiment ATLAS ");
50 return StatusCode::FAILURE;
51 }
52
53 // Create the ZDC Detector Factory
54 ZDC_DetFactory theZDCFactory(detStore().operator->());
55
56 //Retrieve the ZDC geometry from the database
57
58 const IZdcGeometryDB *theZdcGeoDB = ZdcGeoDBGeometryDB::getInstance();
59 const nlohmann::json& zdcGeo = theZdcGeoDB->getDB();
60 if (zdcGeo.is_null()) {
61 ATH_MSG_ERROR("The ZDC geometry DB is null!");
62 return StatusCode::FAILURE;
63}
64
65
66 /*************************************************
67 * Get the TAN/TAXN slots and hold onto the transform
68 **************************************************/
69 std::array<GeoTrf::Transform3D, 2> tanTrf;
70 for (auto slot : zdcGeo["TAN/TAXN"].items()) {
71 // Retrieve all of the values from the json file
72 int side = slot.value()["side"].get<int>();
73 int iside = side == -1 ? 0 : 1;
74 double x = slot.value()["x"].get<double>();
75 double y = slot.value()["y"].get<double>();
76 double z = slot.value()["z"].get<double>();
77 double height = slot.value()["height"].get<double>();
78 double width = slot.value()["width"].get<double>();
79 double depth = slot.value()["depth"].get<double>();
80 std::string name = slot.value()["name"].get<std::string>();
81 tanTrf.at(iside) = GeoTrf::Translate3D(x * Gaudi::Units::mm, y * Gaudi::Units::mm, z * Gaudi::Units::mm);
82
83 // Add the TAN/TAXN slot to the factory
84 theZDCFactory.setTANSlot(iside, width, height, depth, tanTrf.at(iside), name);
85 }
86
87 /*************************************************
88 * Add the ZDC/RPD/BRAN modules to the factory
89 **************************************************/
90 for (auto det : zdcGeo["Detector"].items()) {
91 std::unique_ptr<ZDC_ModuleBase> pDet;
92
93 std::string name = det.value()["name"].get<std::string>();
94 int side = det.value()["side"].get<int>();
95 int iside = side == -1 ? 0 : 1;
96 int module = det.value()["module"].get<int>();
97 double x = det.value()["x"].get<double>();
98 double y = det.value()["y"].get<double>();
99 double z = det.value()["z"].get<double>();
100 double q = det.value()["q"].get<double>();
101 double i = det.value()["i"].get<double>();
102 double j = det.value()["j"].get<double>();
103 double k = det.value()["k"].get<double>();
104
105 if (std::string(det.key()).find("ZDC") != std::string::npos) {
106 pDet = std::make_unique<ZDC_ZDCModule>( name, side, module, det.value()["type"].get<int>() );
107
108 }else if (std::string(det.key()).find("RPD") != std::string::npos) {
109 pDet = std::make_unique<ZDC_RPDModule>( name, side, module );
110
111 }else if (std::string(det.key()).find("BRAN") != std::string::npos) {
112 pDet = std::make_unique<ZDC_BRANModule>( name, side, module );
113
114 }else {
115 ATH_MSG_ERROR("Unknown detector type " << det.key());
116 return StatusCode::FAILURE;
117 }
118
119 // Set the transform and subtract the TAN translation for this side since that's the mother volume of the detector
120 pDet->setTransform(GeoTrf::Translate3D(x - tanTrf.at(iside).translation().x(), y - tanTrf.at(iside).translation().y(), z - tanTrf.at(iside).translation().z()) * GeoTrf::Rotation3D(q, i, j, k) );
121
122 // Add the module to the factory
123 theZDCFactory.addModule(std::move(pDet));
124 }
125
126 if (nullptr == m_detector) { // Create the ZDCDetectorNode instance
127
128 try {
129 // This strange way of casting is to avoid an utterly brain damaged compiler warning.
130 GeoPhysVol* world = &*theExpt->getPhysVol();
131 theZDCFactory.create(world);
132 }
133 catch (const std::bad_alloc&) {
134
135 if (msgLevel(MSG::FATAL)) msg(MSG::FATAL) << "Could not create new ZDC DetectorNode!" << endmsg;
136 return StatusCode::FAILURE;
137 }
138
139 // Register the ZDC DetectorNode instance with the Transient Detector Store
140 theExpt->addManager(theZDCFactory.getDetectorManager());
141 if(detStore()->record(theZDCFactory.getDetectorManager(),theZDCFactory.getDetectorManager()->getName())==StatusCode::SUCCESS){
142 return StatusCode::SUCCESS;}
143 else{
144 msg(MSG::FATAL) << "Could not register ZDC detector manager" << endmsg;}
145
146 }
147
148 return StatusCode::FAILURE;
149}
#define endmsg
#define ATH_MSG_ERROR(x)
const double width
#define y
#define x
#define z
GeoPhysVol * getPhysVol()
Destructor.
void addManager(const GeoVDetectorManager *)
GeoVDetectorManager * m_detector
const nlohmann::json & getDB() const
virtual void create(GeoPhysVol *world) override
void setTANSlot(uint iside, double width, double height, double depth, const GeoTrf::Transform3D trf, const std::string &name)
void addModule(std::unique_ptr< ZDC_ModuleBase > module)
virtual const ZDC_DetManager * getDetectorManager() const override
virtual ~ZDC_DetTool() override final
virtual StatusCode create() override final
ZDC_DetTool(const std::string &type, const std::string &name, const IInterface *parent)
static const IZdcGeometryDB * getInstance()
std::string depth
tag string for intendation
Definition fastadd.cxx:46
singleton-like access to IMessageSvc via open function and helper
MsgStream & msg
Definition testRead.cxx:32