2#include "Tracking/geo/TrackingGeometry.h"
15 G4UIsession* SessionStart() {
return nullptr; }
16 G4int ReceiveG4cout(
const G4String&) {
return 0; }
17 G4int ReceiveG4cerr(
const G4String&) {
return 0; }
21 const Acts::GeometryContext& gctx,
22 const std::string& gdml)
23 :
framework::ConditionsObject(name), gctx_{gctx}, gdml_{gdml} {
26 double rotation_angle = M_PI * 0.5;
34 Acts::Vector3 x_pos1(cos(rotation_angle), 0., sin(rotation_angle));
35 Acts::Vector3 y_pos1(0., 1., 0.);
36 Acts::Vector3 z_pos1(-sin(rotation_angle), 0., cos(rotation_angle));
38 y_rot_.col(0) = x_pos1;
39 y_rot_.col(1) = y_pos1;
40 y_rot_.col(2) = z_pos1;
43 Acts::Vector3 x_pos2(1., 0., 0.);
44 Acts::Vector3 y_pos2(0., cos(rotation_angle), sin(rotation_angle));
45 Acts::Vector3 z_pos2(0., -sin(rotation_angle), cos(rotation_angle));
47 x_rot_.col(0) = x_pos2;
48 x_rot_.col(1) = y_pos2;
49 x_rot_.col(2) = z_pos2;
62 std::unique_ptr<SilentG4> silence;
63 if (G4RunManager::GetRunManager() ==
nullptr) {
65 silence = std::make_unique<SilentG4>();
68 G4coutbuf.SetDestination(silence.get());
69 G4cerrbuf.SetDestination(silence.get());
76 parser.Read(gdml_,
false);
78 f_world_phys_vol_ = parser.GetWorldVolume();
84 G4coutbuf.SetDestination(
nullptr);
85 G4cerrbuf.SetDestination(
nullptr);
89G4VPhysicalVolume* TrackingGeometry::findDaughterByName(G4VPhysicalVolume* pvol,
91 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
92 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
93 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
94 std::string d_name = f_daughter_phys_vol->GetName();
95 if (d_name.find(name) != std::string::npos)
return f_daughter_phys_vol;
102void TrackingGeometry::getAllDaughters(G4VPhysicalVolume* pvol) {
103 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
105 ldmx_log(trace) <<
"Checking daughters of ::" << pvol->GetName();
107 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
108 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
110 ldmx_log(trace) <<
"name::" << f_daughter_phys_vol->GetName();
111 ldmx_log(trace) <<
"pos_::" << f_daughter_phys_vol->GetTranslation();
114 << f_daughter_phys_vol->GetLogicalVolume()->GetNoDaughters();
115 ldmx_log(trace) <<
"replica::" << f_daughter_phys_vol->IsReplicated();
116 ldmx_log(trace) <<
"copyNR::" << f_daughter_phys_vol->GetCopyNo();
118 getAllDaughters(f_daughter_phys_vol);
136void TrackingGeometry::dumpGeometry(
const std::string& outputDir,
137 const Acts::GeometryContext& gctx)
const {
138 if (!t_geometry_)
return;
141 ldmx_log(trace) << __PRETTY_FUNCTION__;
143 for (
auto const& surface_id : layer_surface_map_) {
144 ldmx_log(trace) <<
" " << surface_id.first;
145 ldmx_log(trace) <<
" Check the surface";
147 surface_id.second->toStream(gctx);
148 ldmx_log(trace) <<
" GeometryID: " << surface_id.second->geometryId();
149 ldmx_log(trace) <<
" GeometryID value: "
150 << surface_id.second->geometryId().value();
155 boost::filesystem::create_directory(outputDir);
157 double output_scalor = 1.0;
158 size_t output_precision = 6;
160 Acts::ObjVisualization3D obj_vis(output_precision, output_scalor);
161 Acts::ViewConfig container_view = Acts::ViewConfig({220, 220, 220});
162 Acts::ViewConfig volume_view = Acts::ViewConfig({220, 220, 0});
163 Acts::ViewConfig sensitive_view = Acts::ViewConfig({0, 180, 240});
164 Acts::ViewConfig passive_view = Acts::ViewConfig({240, 280, 0});
165 Acts::ViewConfig grid_view = Acts::ViewConfig({220, 0, 0});
167 Acts::GeometryView3D::drawTrackingVolume(
168 obj_vis, *(t_geometry_->highestTrackingVolume()), gctx, container_view,
169 volume_view, passive_view, sensitive_view, grid_view,
true,
"",
".");
173Acts::Transform3 TrackingGeometry::getTransform(
const G4VPhysicalVolume& phex,
174 bool toTrackingFrame)
const {
175 Acts::Vector3 pos(phex.GetTranslation().x(), phex.GetTranslation().y(),
176 phex.GetTranslation().z());
178 Acts::RotationMatrix3 rotation;
179 convertG4Rot(phex.GetRotation(), rotation);
182 if (toTrackingFrame) {
183 pos(0) = phex.GetTranslation().z();
184 pos(1) = phex.GetTranslation().x();
185 pos(2) = phex.GetTranslation().y();
186 rotation = x_rot_ * y_rot_ * rotation;
189 Acts::Translation3 translation(pos);
191 Acts::Transform3 transform(translation * rotation);
198Acts::Transform3 TrackingGeometry::toTracker(
199 const Acts::Transform3& trans)
const {
200 Acts::Vector3 pos{trans.translation()(2), trans.translation()(0),
201 trans.translation()(1)};
203 Acts::RotationMatrix3 rotation = trans.rotation();
204 rotation = x_rot_ * y_rot_ * rotation;
206 Acts::Translation3 translation(pos);
207 Acts::Transform3 transform(translation * rotation);
213void TrackingGeometry::convertG4Rot(
const G4RotationMatrix* g4rot,
214 Acts::RotationMatrix3& rot)
const {
218 rot = Acts::RotationMatrix3::Identity();
221 rot(0, 0) = g4rot->xx();
222 rot(0, 1) = g4rot->xy();
223 rot(0, 2) = g4rot->xz();
225 rot(1, 0) = g4rot->yx();
226 rot(1, 1) = g4rot->yy();
227 rot(1, 2) = g4rot->yz();
229 rot(2, 0) = g4rot->zx();
230 rot(2, 1) = g4rot->zy();
231 rot(2, 2) = g4rot->zz();
237Acts::Vector3 TrackingGeometry::convertG4Pos(
const G4ThreeVector& g4pos)
const {
238 Acts::Vector3 trans{g4pos.x(), g4pos.y(), g4pos.z()};
241 ldmx_log(trace) <<
"g4pos::" << g4pos;
242 ldmx_log(trace) <<
"trans" << trans;
248void TrackingGeometry::getSurfaces(
249 std::vector<const Acts::Surface*>& surfaces)
const {
251 throw std::runtime_error(
"TrackingGeometry::getSurfaces tGeometry is null");
253 const Acts::TrackingVolume* t_volume = t_geometry_->highestTrackingVolume();
254 if (t_volume->confinedVolumes()) {
255 for (
auto volume : t_volume->confinedVolumes()->arrayObjects()) {
256 if (volume->confinedLayers()) {
257 for (
const auto& layer : volume->confinedLayers()->arrayObjects()) {
258 if (layer->layerType() == Acts::navigation)
continue;
259 for (
auto surface : layer->surfaceArray()->surfaces()) {
261 surfaces.push_back(surface);
271void TrackingGeometry::makeLayerSurfacesMap() {
272 std::vector<const Acts::Surface*> surfaces;
273 getSurfaces(surfaces);
275 for (
auto& surface : surfaces) {
280 unsigned int volume_id = surface->geometryId().volume();
281 unsigned int layer_id = (surface->geometryId().layer() /
284 unsigned int sensor_id =
285 surface->geometryId().sensitive() -
289 ldmx_log(trace) <<
"VolumeID " << volume_id <<
" LayerId " << layer_id
290 <<
" sensorId " << sensor_id;
293 unsigned int surface_id = volume_id * 1000 + layer_id * 100 + sensor_id;
295 layer_surface_map_[surface_id] = surface;
This class throws away all of the messages from Geant4.
TrackingGeometry(const std::string &name, const Acts::GeometryContext &gctx, const std::string &gdml)
All classes in the ldmx-sw project use this namespace.