LDMX Software
tracking::geo::TrackingGeometry Class Reference

This class is a abstract base class (ABC) doing common tasks that tracking geometries need done. More...

#include <TrackingGeometry.h>

Public Member Functions

 TrackingGeometry (const std::string &name, const Acts::GeometryContext &gctx, const std::string &gdml)
 
virtual ~TrackingGeometry ()=default
 Destructor.
 
G4VPhysicalVolume * findDaughterByName (G4VPhysicalVolume *pvol, G4String name)
 
void getAllDaughters (G4VPhysicalVolume *pvol)
 
void convertG4Rot (const G4RotationMatrix *g4rot, Acts::RotationMatrix3 &rot) const
 
Acts::Vector3 convertG4Pos (const G4ThreeVector &g4pos) const
 
void dumpGeometry (const std::string &outputDir, const Acts::GeometryContext &gctx) const
 
std::shared_ptr< const Acts::TrackingGeometry > getTG () const
 
Acts::Transform3 getTransform (const G4VPhysicalVolume &phex, bool toTrackingFrame=false) const
 
Acts::Transform3 toTracker (const Acts::Transform3 &trans) const
 
void makeLayerSurfacesMap ()
 
void getSurfaces (std::vector< const Acts::Surface * > &surfaces) const
 
const Acts::Surface * getSurface (int layerid) const
 
const std::string & fieldMapFile () const
 Full path to the field map file extracted from the GDML auxiliary data.
 
- Public Member Functions inherited from framework::ConditionsObject
 ConditionsObject (const std::string &name)
 Class constructor.
 
virtual ~ConditionsObject ()
 Destructor.
 
std::string getName () const
 Get the name of this object.
 

Static Public Member Functions

static bool compareZlocation (const G4VPhysicalVolume &pvol_a, const G4VPhysicalVolume &pvol_b)
 

Public Attributes

std::unordered_map< unsigned int, const Acts::Surface * > layer_surface_map_
 
std::vector< std::shared_ptr< tracking::geo::DetectorElement > > det_elements_
 

Protected Attributes

const Acts::GeometryContext & gctx_
 
std::string gdml_ {""}
 
Acts::RotationMatrix3 x_rot_
 
Acts::RotationMatrix3 y_rot_
 
std::shared_ptr< const Acts::TrackingGeometry > t_geometry_ {nullptr}
 
G4VPhysicalVolume * f_world_phys_vol_ {nullptr}
 

Private Attributes

std::string field_map_file_ {""}
 

Detailed Description

This class is a abstract base class (ABC) doing common tasks that tracking geometries need done.

Right now, in LDMX, there are two (or three) distinct tracking geometries: The tagger tracker, the recoil tracker, and the ECal. Sometimes the tagger and recoil are combined into a single tracker geometry but the ECal is always distinct.

While this class inherits from ConditionsObject, it should never have a provider. Only the concrete derived classes should have providers.

Definition at line 53 of file TrackingGeometry.h.

Constructor & Destructor Documentation

◆ TrackingGeometry()

tracking::geo::TrackingGeometry::TrackingGeometry ( const std::string & name,
const Acts::GeometryContext & gctx,
const std::string & gdml )
Parameters
[in]namethe name of this geometry condition object
[in]gctxthe geometry context for this geometry
[in]gdmlthe path to the detector GDML to load

We are about to use the G4GDMLParser and would like to silence the output from parsing the geometry. This can only be done by redirecting G4cout and G4cerr via the G4UImanager.

The Simulator (if it is running) will already do this redirection for us and we don't want to override it, so we check if there is a simulation running by seeing if the run manager is created. If it isn't, then we redirect G4cout and G4cerr to a G4Session that just throws away all those messages.

Definition at line 22 of file TrackingGeometry.cxx.

25 : framework::ConditionsObject(name), gctx_{gctx}, gdml_{gdml} {
26 // Build The rotation matrix to the tracking frame
27 // Rotate the sensors to be orthogonal to X
28 double rotation_angle = M_PI * 0.5;
29
30 // 0 0 -1
31 // 0 1 0
32 // 1 0 0
33
34 // This rotation is needed to have the plane orthogonal to the X direction.
35 // Rotation of the surfaces
36 Acts::Vector3 x_pos1(cos(rotation_angle), 0., sin(rotation_angle));
37 Acts::Vector3 y_pos1(0., 1., 0.);
38 Acts::Vector3 z_pos1(-sin(rotation_angle), 0., cos(rotation_angle));
39
40 y_rot_.col(0) = x_pos1;
41 y_rot_.col(1) = y_pos1;
42 y_rot_.col(2) = z_pos1;
43
44 // Rotate the sensors to put them in the proper orientation in Z
45 Acts::Vector3 x_pos2(1., 0., 0.);
46 Acts::Vector3 y_pos2(0., cos(rotation_angle), sin(rotation_angle));
47 Acts::Vector3 z_pos2(0., -sin(rotation_angle), cos(rotation_angle));
48
49 x_rot_.col(0) = x_pos2;
50 x_rot_.col(1) = y_pos2;
51 x_rot_.col(2) = z_pos2;
52
64 std::unique_ptr<SilentG4> silence;
65 if (G4RunManager::GetRunManager() == nullptr) {
66 // no run manager ==> no simulation
67 silence = std::make_unique<SilentG4>();
68 // these lines compied from G4UImanager::SetCoutDestination
69 // to avoid creating G4UImanager unnecessarily
70 G4coutbuf.SetDestination(silence.get());
71 G4cerrbuf.SetDestination(silence.get());
72 }
73
74 // Get the world volume
75 G4GDMLParser parser;
76
77 // Validation requires internet
78 parser.Read(gdml_, false);
79
80 // Extract field map filename from GDML auxiliary data and resolve full path.
81 // GDML path: .../data/detectors/<det>/detector.gdml
82 // Field map: .../data/fieldmap/<filename>
83 const G4GDMLAuxListType* aux_list = parser.GetAuxList();
84 for (const auto& aux : *aux_list) {
85 if (aux.type == "MagneticField") {
86 for (const auto& sub : *aux.auxList) {
87 if (sub.type == "File") {
88 boost::filesystem::path fmap(std::string(sub.value));
89 if (fmap.is_absolute()) {
90 field_map_file_ = fmap.string();
91 } else {
92 boost::filesystem::path prefix = boost::filesystem::path(gdml_)
93 .parent_path()
94 .parent_path()
95 .parent_path();
96 field_map_file_ = (prefix / "fieldmap" / fmap).string();
97 }
98 break;
99 }
100 }
101 break;
102 }
103 }
104
105 if (field_map_file_.empty()) {
106 ldmx_log(warn) << "TrackingGeometry: no MagneticField/File auxiliary "
107 "entry found in '"
108 << gdml_ << "' — tracking will use a zero B-field";
109 }
110
111 f_world_phys_vol_ = parser.GetWorldVolume();
112
113 if (silence) {
114 // we created the session and silenced G4
115 // undo that now incase others have use for G4
116 // nullptr => standard (ldmx_log(trace) and std::cerr)
117 G4coutbuf.SetDestination(nullptr);
118 G4cerrbuf.SetDestination(nullptr);
119 }
120}
Base class for all conditions objects, very simple.

Member Function Documentation

◆ compareZlocation()

static bool tracking::geo::TrackingGeometry::compareZlocation ( const G4VPhysicalVolume & pvol_a,
const G4VPhysicalVolume & pvol_b )
inlinestatic

Definition at line 69 of file TrackingGeometry.h.

70 {
71 return (pvol_a.GetTranslation().z() < pvol_b.GetTranslation().z());
72 };

◆ convertG4Pos()

Acts::Vector3 tracking::geo::TrackingGeometry::convertG4Pos ( const G4ThreeVector & g4pos) const

Definition at line 270 of file TrackingGeometry.cxx.

270 {
271 Acts::Vector3 trans{g4pos.x(), g4pos.y(), g4pos.z()};
272
273 {
274 ldmx_log(trace) << "g4pos::" << g4pos;
275 ldmx_log(trace) << "trans" << trans;
276 }
277
278 return trans;
279}

◆ convertG4Rot()

void tracking::geo::TrackingGeometry::convertG4Rot ( const G4RotationMatrix * g4rot,
Acts::RotationMatrix3 & rot ) const

Definition at line 246 of file TrackingGeometry.cxx.

247 {
248 // If the rotation is the identity then g4rot will be a null ptr.
249 // So then check it and fill rot accordingly
250
251 rot = Acts::RotationMatrix3::Identity();
252
253 if (g4rot) {
254 rot(0, 0) = g4rot->xx();
255 rot(0, 1) = g4rot->xy();
256 rot(0, 2) = g4rot->xz();
257
258 rot(1, 0) = g4rot->yx();
259 rot(1, 1) = g4rot->yy();
260 rot(1, 2) = g4rot->yz();
261
262 rot(2, 0) = g4rot->zx();
263 rot(2, 1) = g4rot->zy();
264 rot(2, 2) = g4rot->zz();
265 }
266}

◆ dumpGeometry()

void tracking::geo::TrackingGeometry::dumpGeometry ( const std::string & outputDir,
const Acts::GeometryContext & gctx ) const

Definition at line 169 of file TrackingGeometry.cxx.

170 {
171 if (!t_geometry_) return;
172
173 {
174 ldmx_log(trace) << __PRETTY_FUNCTION__;
175
176 for (auto const& surface_id : layer_surface_map_) {
177 ldmx_log(trace) << " " << surface_id.first;
178 ldmx_log(trace) << " Check the surface";
179 // surfaceId.second->toStream(gctx, ldmx_log(trace));
180 surface_id.second->toStream(gctx);
181 ldmx_log(trace) << " GeometryID: " << surface_id.second->geometryId();
182 ldmx_log(trace) << " GeometryID value: "
183 << surface_id.second->geometryId().value();
184 }
185 }
186
187 // Should fail if already exists
188 boost::filesystem::create_directory(outputDir);
189
190 double output_scalor = 1.0;
191 size_t output_precision = 6;
192
193 Acts::ObjVisualization3D obj_vis(output_precision, output_scalor);
194 Acts::ViewConfig container_view = Acts::ViewConfig({220, 220, 220});
195 Acts::ViewConfig volume_view = Acts::ViewConfig({220, 220, 0});
196 Acts::ViewConfig sensitive_view = Acts::ViewConfig({0, 180, 240});
197 Acts::ViewConfig passive_view = Acts::ViewConfig({240, 280, 0});
198 Acts::ViewConfig grid_view = Acts::ViewConfig({220, 0, 0});
199
200 Acts::GeometryView3D::drawTrackingVolume(
201 obj_vis, *(t_geometry_->highestTrackingVolume()), gctx, container_view,
202 volume_view, passive_view, sensitive_view, grid_view, true, "", ".");
203}

◆ fieldMapFile()

const std::string & tracking::geo::TrackingGeometry::fieldMapFile ( ) const
inline

Full path to the field map file extracted from the GDML auxiliary data.

Empty if no MagneticField auxiliary block was found.

Definition at line 105 of file TrackingGeometry.h.

105{ return field_map_file_; }

◆ findDaughterByName()

G4VPhysicalVolume * tracking::geo::TrackingGeometry::findDaughterByName ( G4VPhysicalVolume * pvol,
G4String name )

Definition at line 122 of file TrackingGeometry.cxx.

123 {
124 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
125 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
126 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
127 std::string d_name = f_daughter_phys_vol->GetName();
128 if (d_name.find(name) != std::string::npos) return f_daughter_phys_vol;
129 // if (fDaughterPhysVol->GetName() == name) return fDaughterPhysVol;
130 }
131
132 return nullptr;
133}

◆ getAllDaughters()

void tracking::geo::TrackingGeometry::getAllDaughters ( G4VPhysicalVolume * pvol)

Definition at line 135 of file TrackingGeometry.cxx.

135 {
136 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
137
138 ldmx_log(trace) << "Checking daughters of ::" << pvol->GetName();
139
140 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
141 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
142
143 ldmx_log(trace) << "name::" << f_daughter_phys_vol->GetName();
144 ldmx_log(trace) << "pos_::" << f_daughter_phys_vol->GetTranslation();
145 ldmx_log(trace)
146 << "n_dau::"
147 << f_daughter_phys_vol->GetLogicalVolume()->GetNoDaughters();
148 ldmx_log(trace) << "replica::" << f_daughter_phys_vol->IsReplicated();
149 ldmx_log(trace) << "copyNR::" << f_daughter_phys_vol->GetCopyNo();
150
151 getAllDaughters(f_daughter_phys_vol);
152 }
153}

◆ getSurface()

const Acts::Surface * tracking::geo::TrackingGeometry::getSurface ( int layerid) const
inline

Definition at line 97 of file TrackingGeometry.h.

97 {
98 return layer_surface_map_.at(layerid);
99 }

◆ getSurfaces()

void tracking::geo::TrackingGeometry::getSurfaces ( std::vector< const Acts::Surface * > & surfaces) const

Definition at line 281 of file TrackingGeometry.cxx.

282 {
283 if (!t_geometry_)
284 EXCEPTION_RAISE("BadGeometry",
285 "TrackingGeometry::getSurfaces tGeometry is null");
286
287 const Acts::TrackingVolume* t_volume = t_geometry_->highestTrackingVolume();
288 if (t_volume->confinedVolumes()) {
289 for (auto volume : t_volume->confinedVolumes()->arrayObjects()) {
290 if (volume->confinedLayers()) {
291 for (const auto& layer : volume->confinedLayers()->arrayObjects()) {
292 if (layer->layerType() == Acts::navigation) continue;
293 for (auto surface : layer->surfaceArray()->surfaces()) {
294 if (surface) {
295 surfaces.push_back(surface);
296
297 } // surface exists
298 } // surfaces
299 } // layers objects
300 } // confined layers
301 } // volumes objects
302 } // confined volumes
303}

◆ getTG()

std::shared_ptr< const Acts::TrackingGeometry > tracking::geo::TrackingGeometry::getTG ( ) const
inline

Definition at line 81 of file TrackingGeometry.h.

81 {
82 return t_geometry_;
83 };

◆ getTransform()

Acts::Transform3 tracking::geo::TrackingGeometry::getTransform ( const G4VPhysicalVolume & phex,
bool toTrackingFrame = false ) const

Definition at line 206 of file TrackingGeometry.cxx.

207 {
208 Acts::Vector3 pos(phex.GetTranslation().x(), phex.GetTranslation().y(),
209 phex.GetTranslation().z());
210
211 Acts::RotationMatrix3 rotation;
212 convertG4Rot(phex.GetRotation(), rotation);
213
214 // rotate to the tracking frame
215 if (toTrackingFrame) {
216 pos(0) = phex.GetTranslation().z();
217 pos(1) = phex.GetTranslation().x();
218 pos(2) = phex.GetTranslation().y();
219 rotation = x_rot_ * y_rot_ * rotation;
220 }
221
222 Acts::Translation3 translation(pos);
223
224 Acts::Transform3 transform(translation * rotation);
225
226 return transform;
227}

◆ makeLayerSurfacesMap()

void tracking::geo::TrackingGeometry::makeLayerSurfacesMap ( )

Definition at line 305 of file TrackingGeometry.cxx.

305 {
306 std::vector<const Acts::Surface*> surfaces;
307 getSurfaces(surfaces);
308
309 for (auto& surface : surfaces) {
310 // Layers from 1 to 14 - for the tagger
311 // unsigned int layerId = (surface->geometryId().layer() / 2) ; // Old 1
312 // sensor per layer_
313
314 unsigned int volume_id = surface->geometryId().volume();
315 unsigned int layer_id = (surface->geometryId().layer() /
316 2); // set layer_ ID from 1 to 7 for the tagger
317 // and from 1 to 6 for the recoil
318 unsigned int sensor_id =
319 surface->geometryId().sensitive() -
320 1; // set sensor ID from 0 to 1 for the tagger and from 0 to 9 for the
321 // axial sensors in the back layers of the recoil
322
323 ldmx_log(trace) << "VolumeID " << volume_id << " LayerId " << layer_id
324 << " sensorId " << sensor_id;
325
326 // surface ID = vol * 1000 + ly * 100 + sensor
327 unsigned int surface_id = volume_id * 1000 + layer_id * 100 + sensor_id;
328
329 layer_surface_map_[surface_id] = surface;
330
331 } // surfaces loop
332}

◆ toTracker()

Acts::Transform3 tracking::geo::TrackingGeometry::toTracker ( const Acts::Transform3 & trans) const

Definition at line 231 of file TrackingGeometry.cxx.

232 {
233 Acts::Vector3 pos{trans.translation()(2), trans.translation()(0),
234 trans.translation()(1)};
235
236 Acts::RotationMatrix3 rotation = trans.rotation();
237 rotation = x_rot_ * y_rot_ * rotation;
238
239 Acts::Translation3 translation(pos);
240 Acts::Transform3 transform(translation * rotation);
241
242 return transform;
243}

Member Data Documentation

◆ det_elements_

std::vector<std::shared_ptr<tracking::geo::DetectorElement> > tracking::geo::TrackingGeometry::det_elements_

Definition at line 110 of file TrackingGeometry.h.

◆ f_world_phys_vol_

G4VPhysicalVolume* tracking::geo::TrackingGeometry::f_world_phys_vol_ {nullptr}
protected

Definition at line 118 of file TrackingGeometry.h.

118{nullptr};

◆ field_map_file_

std::string tracking::geo::TrackingGeometry::field_map_file_ {""}
private

Definition at line 121 of file TrackingGeometry.h.

121{""};

◆ gctx_

const Acts::GeometryContext& tracking::geo::TrackingGeometry::gctx_
protected

Definition at line 113 of file TrackingGeometry.h.

◆ gdml_

std::string tracking::geo::TrackingGeometry::gdml_ {""}
protected

Definition at line 114 of file TrackingGeometry.h.

114{""};

◆ layer_surface_map_

std::unordered_map<unsigned int, const Acts::Surface*> tracking::geo::TrackingGeometry::layer_surface_map_

Definition at line 101 of file TrackingGeometry.h.

◆ t_geometry_

std::shared_ptr<const Acts::TrackingGeometry> tracking::geo::TrackingGeometry::t_geometry_ {nullptr}
protected

Definition at line 117 of file TrackingGeometry.h.

117{nullptr};

◆ x_rot_

Acts::RotationMatrix3 tracking::geo::TrackingGeometry::x_rot_
protected

Definition at line 116 of file TrackingGeometry.h.

◆ y_rot_

Acts::RotationMatrix3 tracking::geo::TrackingGeometry::y_rot_
protected

Definition at line 116 of file TrackingGeometry.h.


The documentation for this class was generated from the following files: