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 33 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 33 of file TrackingGeometry.cxx.

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

50 {
51 return (pvol_a.GetTranslation().z() < pvol_b.GetTranslation().z());
52 };

◆ convertG4Pos()

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

Definition at line 281 of file TrackingGeometry.cxx.

281 {
282 Acts::Vector3 trans{g4pos.x(), g4pos.y(), g4pos.z()};
283
284 {
285 ldmx_log(trace) << "g4pos::" << g4pos;
286 ldmx_log(trace) << "trans" << trans;
287 }
288
289 return trans;
290}

◆ convertG4Rot()

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

Definition at line 257 of file TrackingGeometry.cxx.

258 {
259 // If the rotation is the identity then g4rot will be a null ptr.
260 // So then check it and fill rot accordingly
261
262 rot = Acts::RotationMatrix3::Identity();
263
264 if (g4rot) {
265 rot(0, 0) = g4rot->xx();
266 rot(0, 1) = g4rot->xy();
267 rot(0, 2) = g4rot->xz();
268
269 rot(1, 0) = g4rot->yx();
270 rot(1, 1) = g4rot->yy();
271 rot(1, 2) = g4rot->yz();
272
273 rot(2, 0) = g4rot->zx();
274 rot(2, 1) = g4rot->zy();
275 rot(2, 2) = g4rot->zz();
276 }
277}

◆ dumpGeometry()

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

Definition at line 180 of file TrackingGeometry.cxx.

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

◆ 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 85 of file TrackingGeometry.h.

85{ return field_map_file_; }

◆ findDaughterByName()

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

Definition at line 133 of file TrackingGeometry.cxx.

134 {
135 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
136 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
137 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
138 std::string d_name = f_daughter_phys_vol->GetName();
139 if (d_name.find(name) != std::string::npos) return f_daughter_phys_vol;
140 // if (fDaughterPhysVol->GetName() == name) return fDaughterPhysVol;
141 }
142
143 return nullptr;
144}

◆ getAllDaughters()

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

Definition at line 146 of file TrackingGeometry.cxx.

146 {
147 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
148
149 ldmx_log(trace) << "Checking daughters of ::" << pvol->GetName();
150
151 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
152 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
153
154 ldmx_log(trace) << "name::" << f_daughter_phys_vol->GetName();
155 ldmx_log(trace) << "pos_::" << f_daughter_phys_vol->GetTranslation();
156 ldmx_log(trace)
157 << "n_dau::"
158 << f_daughter_phys_vol->GetLogicalVolume()->GetNoDaughters();
159 ldmx_log(trace) << "replica::" << f_daughter_phys_vol->IsReplicated();
160 ldmx_log(trace) << "copyNR::" << f_daughter_phys_vol->GetCopyNo();
161
162 getAllDaughters(f_daughter_phys_vol);
163 }
164}

◆ getSurface()

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

Definition at line 77 of file TrackingGeometry.h.

77 {
78 return layer_surface_map_.at(layerid);
79 }

◆ getSurfaces()

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

Definition at line 292 of file TrackingGeometry.cxx.

293 {
294 if (!t_geometry_)
295 EXCEPTION_RAISE("BadGeometry",
296 "TrackingGeometry::getSurfaces tGeometry is null");
297
298 const Acts::TrackingVolume* t_volume = t_geometry_->highestTrackingVolume();
299 if (t_volume->confinedVolumes()) {
300 for (auto volume : t_volume->confinedVolumes()->arrayObjects()) {
301 if (volume->confinedLayers()) {
302 for (const auto& layer : volume->confinedLayers()->arrayObjects()) {
303 if (layer->layerType() == Acts::navigation) continue;
304 for (auto surface : layer->surfaceArray()->surfaces()) {
305 if (surface) {
306 surfaces.push_back(surface);
307
308 } // surface exists
309 } // surfaces
310 } // layers objects
311 } // confined layers
312 } // volumes objects
313 } // confined volumes
314}

◆ getTG()

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

Definition at line 61 of file TrackingGeometry.h.

61 {
62 return t_geometry_;
63 };

◆ getTransform()

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

Definition at line 217 of file TrackingGeometry.cxx.

218 {
219 Acts::Vector3 pos(phex.GetTranslation().x(), phex.GetTranslation().y(),
220 phex.GetTranslation().z());
221
222 Acts::RotationMatrix3 rotation;
223 convertG4Rot(phex.GetRotation(), rotation);
224
225 // rotate to the tracking frame
226 if (toTrackingFrame) {
227 pos(0) = phex.GetTranslation().z();
228 pos(1) = phex.GetTranslation().x();
229 pos(2) = phex.GetTranslation().y();
230 rotation = x_rot_ * y_rot_ * rotation;
231 }
232
233 Acts::Translation3 translation(pos);
234
235 Acts::Transform3 transform(translation * rotation);
236
237 return transform;
238}

◆ makeLayerSurfacesMap()

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

Definition at line 316 of file TrackingGeometry.cxx.

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

◆ toTracker()

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

Definition at line 242 of file TrackingGeometry.cxx.

243 {
244 Acts::Vector3 pos{trans.translation()(2), trans.translation()(0),
245 trans.translation()(1)};
246
247 Acts::RotationMatrix3 rotation = trans.rotation();
248 rotation = x_rot_ * y_rot_ * rotation;
249
250 Acts::Translation3 translation(pos);
251 Acts::Transform3 transform(translation * rotation);
252
253 return transform;
254}

Member Data Documentation

◆ det_elements_

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

Definition at line 90 of file TrackingGeometry.h.

◆ f_world_phys_vol_

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

Definition at line 98 of file TrackingGeometry.h.

98{nullptr};

◆ field_map_file_

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

Definition at line 101 of file TrackingGeometry.h.

101{""};

◆ gctx_

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

Definition at line 93 of file TrackingGeometry.h.

◆ gdml_

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

Definition at line 94 of file TrackingGeometry.h.

94{""};

◆ layer_surface_map_

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

Definition at line 81 of file TrackingGeometry.h.

◆ t_geometry_

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

Definition at line 97 of file TrackingGeometry.h.

97{nullptr};

◆ x_rot_

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

Definition at line 96 of file TrackingGeometry.h.

◆ y_rot_

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

Definition at line 96 of file TrackingGeometry.h.


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