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
 
- 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< 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}
 

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

23 : framework::ConditionsObject(name), gctx_{gctx}, gdml_{gdml} {
24 // Build The rotation matrix to the tracking frame
25 // Rotate the sensors to be orthogonal to X
26 double rotation_angle = M_PI * 0.5;
27
28 // 0 0 -1
29 // 0 1 0
30 // 1 0 0
31
32 // This rotation is needed to have the plane orthogonal to the X direction.
33 // Rotation of the surfaces
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));
37
38 y_rot_.col(0) = x_pos1;
39 y_rot_.col(1) = y_pos1;
40 y_rot_.col(2) = z_pos1;
41
42 // Rotate the sensors to put them in the proper orientation in Z
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));
46
47 x_rot_.col(0) = x_pos2;
48 x_rot_.col(1) = y_pos2;
49 x_rot_.col(2) = z_pos2;
50
62 std::unique_ptr<SilentG4> silence;
63 if (G4RunManager::GetRunManager() == nullptr) {
64 // no run manager ==> no simulation
65 silence = std::make_unique<SilentG4>();
66 // these lines compied from G4UImanager::SetCoutDestination
67 // to avoid creating G4UImanager unnecessarily
68 G4coutbuf.SetDestination(silence.get());
69 G4cerrbuf.SetDestination(silence.get());
70 }
71
72 // Get the world volume
73 G4GDMLParser parser;
74
75 // Validation requires internet
76 parser.Read(gdml_, false);
77
78 f_world_phys_vol_ = parser.GetWorldVolume();
79
80 if (silence) {
81 // we created the session and silenced G4
82 // undo that now incase others have use for G4
83 // nullptr => standard (ldmx_log(trace) and std::cerr)
84 G4coutbuf.SetDestination(nullptr);
85 G4cerrbuf.SetDestination(nullptr);
86 }
87}
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 70 of file TrackingGeometry.h.

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

◆ convertG4Pos()

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

Definition at line 237 of file TrackingGeometry.cxx.

237 {
238 Acts::Vector3 trans{g4pos.x(), g4pos.y(), g4pos.z()};
239
240 {
241 ldmx_log(trace) << "g4pos::" << g4pos;
242 ldmx_log(trace) << "trans" << trans;
243 }
244
245 return trans;
246}

◆ convertG4Rot()

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

Definition at line 213 of file TrackingGeometry.cxx.

214 {
215 // If the rotation is the identity then g4rot will be a null ptr.
216 // So then check it and fill rot accordingly
217
218 rot = Acts::RotationMatrix3::Identity();
219
220 if (g4rot) {
221 rot(0, 0) = g4rot->xx();
222 rot(0, 1) = g4rot->xy();
223 rot(0, 2) = g4rot->xz();
224
225 rot(1, 0) = g4rot->yx();
226 rot(1, 1) = g4rot->yy();
227 rot(1, 2) = g4rot->yz();
228
229 rot(2, 0) = g4rot->zx();
230 rot(2, 1) = g4rot->zy();
231 rot(2, 2) = g4rot->zz();
232 }
233}

◆ dumpGeometry()

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

Definition at line 136 of file TrackingGeometry.cxx.

137 {
138 if (!t_geometry_) return;
139
140 {
141 ldmx_log(trace) << __PRETTY_FUNCTION__;
142
143 for (auto const& surface_id : layer_surface_map_) {
144 ldmx_log(trace) << " " << surface_id.first;
145 ldmx_log(trace) << " Check the surface";
146 // surfaceId.second->toStream(gctx, ldmx_log(trace));
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();
151 }
152 }
153
154 // Should fail if already exists
155 boost::filesystem::create_directory(outputDir);
156
157 double output_scalor = 1.0;
158 size_t output_precision = 6;
159
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});
166
167 Acts::GeometryView3D::drawTrackingVolume(
168 obj_vis, *(t_geometry_->highestTrackingVolume()), gctx, container_view,
169 volume_view, passive_view, sensitive_view, grid_view, true, "", ".");
170}

◆ findDaughterByName()

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

Definition at line 89 of file TrackingGeometry.cxx.

90 {
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;
96 // if (fDaughterPhysVol->GetName() == name) return fDaughterPhysVol;
97 }
98
99 return nullptr;
100}

◆ getAllDaughters()

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

Definition at line 102 of file TrackingGeometry.cxx.

102 {
103 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
104
105 ldmx_log(trace) << "Checking daughters of ::" << pvol->GetName();
106
107 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
108 G4VPhysicalVolume* f_daughter_phys_vol = lvol->GetDaughter(i);
109
110 ldmx_log(trace) << "name::" << f_daughter_phys_vol->GetName();
111 ldmx_log(trace) << "pos_::" << f_daughter_phys_vol->GetTranslation();
112 ldmx_log(trace)
113 << "n_dau::"
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();
117
118 getAllDaughters(f_daughter_phys_vol);
119 }
120}

◆ getSurface()

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

Definition at line 98 of file TrackingGeometry.h.

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

◆ getSurfaces()

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

Definition at line 248 of file TrackingGeometry.cxx.

249 {
250 if (!t_geometry_)
251 throw std::runtime_error("TrackingGeometry::getSurfaces tGeometry is null");
252
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()) {
260 if (surface) {
261 surfaces.push_back(surface);
262
263 } // surface exists
264 } // surfaces
265 } // layers objects
266 } // confined layers
267 } // volumes objects
268 } // confined volumes
269}

◆ getTG()

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

Definition at line 82 of file TrackingGeometry.h.

82 {
83 return t_geometry_;
84 };

◆ getTransform()

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

Definition at line 173 of file TrackingGeometry.cxx.

174 {
175 Acts::Vector3 pos(phex.GetTranslation().x(), phex.GetTranslation().y(),
176 phex.GetTranslation().z());
177
178 Acts::RotationMatrix3 rotation;
179 convertG4Rot(phex.GetRotation(), rotation);
180
181 // rotate to the tracking frame
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;
187 }
188
189 Acts::Translation3 translation(pos);
190
191 Acts::Transform3 transform(translation * rotation);
192
193 return transform;
194}

◆ makeLayerSurfacesMap()

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

Definition at line 271 of file TrackingGeometry.cxx.

271 {
272 std::vector<const Acts::Surface*> surfaces;
273 getSurfaces(surfaces);
274
275 for (auto& surface : surfaces) {
276 // Layers from 1 to 14 - for the tagger
277 // unsigned int layerId = (surface->geometryId().layer() / 2) ; // Old 1
278 // sensor per layer_
279
280 unsigned int volume_id = surface->geometryId().volume();
281 unsigned int layer_id = (surface->geometryId().layer() /
282 2); // set layer_ ID from 1 to 7 for the tagger
283 // and from 1 to 6 for the recoil
284 unsigned int sensor_id =
285 surface->geometryId().sensitive() -
286 1; // set sensor ID from 0 to 1 for the tagger and from 0 to 9 for the
287 // axial sensors in the back layers of the recoil
288
289 ldmx_log(trace) << "VolumeID " << volume_id << " LayerId " << layer_id
290 << " sensorId " << sensor_id;
291
292 // surface ID = vol * 1000 + ly * 100 + sensor
293 unsigned int surface_id = volume_id * 1000 + layer_id * 100 + sensor_id;
294
295 layer_surface_map_[surface_id] = surface;
296
297 } // surfaces loop
298}

◆ toTracker()

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

Definition at line 198 of file TrackingGeometry.cxx.

199 {
200 Acts::Vector3 pos{trans.translation()(2), trans.translation()(0),
201 trans.translation()(1)};
202
203 Acts::RotationMatrix3 rotation = trans.rotation();
204 rotation = x_rot_ * y_rot_ * rotation;
205
206 Acts::Translation3 translation(pos);
207 Acts::Transform3 transform(translation * rotation);
208
209 return transform;
210}

Member Data Documentation

◆ det_elements_

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

Definition at line 106 of file TrackingGeometry.h.

◆ f_world_phys_vol_

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

Definition at line 114 of file TrackingGeometry.h.

114{nullptr};

◆ gctx_

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

Definition at line 109 of file TrackingGeometry.h.

◆ gdml_

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

Definition at line 110 of file TrackingGeometry.h.

110{""};

◆ layer_surface_map_

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

Definition at line 102 of file TrackingGeometry.h.

◆ t_geometry_

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

Definition at line 113 of file TrackingGeometry.h.

113{nullptr};

◆ x_rot_

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

Definition at line 112 of file TrackingGeometry.h.

◆ y_rot_

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

Definition at line 112 of file TrackingGeometry.h.


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