LDMX Software
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
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, bool debug)
 
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 > > detElements
 

Protected Attributes

const Acts::GeometryContext & gctx_
 
std::string gdml_ {""}
 
bool debug_ {false}
 
Acts::RotationMatrix3 x_rot_
 
Acts::RotationMatrix3 y_rot_
 
std::shared_ptr< const Acts::TrackingGeometry > tGeometry_ {nullptr}
 
G4VPhysicalVolume * fWorldPhysVol_ {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 49 of file TrackingGeometry.h.

Constructor & Destructor Documentation

◆ TrackingGeometry()

tracking::geo::TrackingGeometry::TrackingGeometry ( const std::string &  name,
const Acts::GeometryContext &  gctx,
const std::string &  gdml,
bool  debug 
)
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
[in]debugwhether to print extra information or nah

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

29 gctx_{gctx},
30 gdml_{gdml},
31 debug_{debug} {
32 // Build The rotation matrix to the tracking frame
33 // Rotate the sensors to be orthogonal to X
34 double rotationAngle = M_PI * 0.5;
35
36 // 0 0 -1
37 // 0 1 0
38 // 1 0 0
39
40 // This rotation is needed to have the plane orthogonal to the X direction.
41 // Rotation of the surfaces
42 Acts::Vector3 xPos1(cos(rotationAngle), 0., sin(rotationAngle));
43 Acts::Vector3 yPos1(0., 1., 0.);
44 Acts::Vector3 zPos1(-sin(rotationAngle), 0., cos(rotationAngle));
45
46 y_rot_.col(0) = xPos1;
47 y_rot_.col(1) = yPos1;
48 y_rot_.col(2) = zPos1;
49
50 // Rotate the sensors to put them in the proper orientation in Z
51 Acts::Vector3 xPos2(1., 0., 0.);
52 Acts::Vector3 yPos2(0., cos(rotationAngle), sin(rotationAngle));
53 Acts::Vector3 zPos2(0., -sin(rotationAngle), cos(rotationAngle));
54
55 x_rot_.col(0) = xPos2;
56 x_rot_.col(1) = yPos2;
57 x_rot_.col(2) = zPos2;
58
70 std::unique_ptr<SilentG4> silence;
71 if (G4RunManager::GetRunManager() == nullptr) {
72 // no run manager ==> no simulation
73 silence = std::make_unique<SilentG4>();
74 // these lines compied from G4UImanager::SetCoutDestination
75 // to avoid creating G4UImanager unnecessarily
76 G4coutbuf.SetDestination(silence.get());
77 G4cerrbuf.SetDestination(silence.get());
78 }
79
80 // Get the world volume
81 G4GDMLParser parser;
82
83 // Validation requires internet
84 parser.Read(gdml_, false);
85
86 fWorldPhysVol_ = parser.GetWorldVolume();
87
88 if (silence) {
89 // we created the session and silenced G4
90 // undo that now incase others have use for G4
91 // nullptr => standard (std::cout and std::cerr)
92 G4coutbuf.SetDestination(nullptr);
93 G4cerrbuf.SetDestination(nullptr);
94 }
95}
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 66 of file TrackingGeometry.h.

67 {
68 return (pvol_a.GetTranslation().z() < pvol_b.GetTranslation().z());
69 };

◆ ConvertG4Pos()

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

Definition at line 249 of file TrackingGeometry.cxx.

249 {
250 Acts::Vector3 trans{g4pos.x(), g4pos.y(), g4pos.z()};
251
252 if (debug_) {
253 std::cout << std::endl;
254 std::cout << "g4pos::" << g4pos << std::endl;
255 std::cout << trans << std::endl;
256 }
257
258 return trans;
259}

◆ ConvertG4Rot()

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

Definition at line 225 of file TrackingGeometry.cxx.

226 {
227 // If the rotation is the identity then g4rot will be a null ptr.
228 // So then check it and fill rot accordingly
229
230 rot = Acts::RotationMatrix3::Identity();
231
232 if (g4rot) {
233 rot(0, 0) = g4rot->xx();
234 rot(0, 1) = g4rot->xy();
235 rot(0, 2) = g4rot->xz();
236
237 rot(1, 0) = g4rot->yx();
238 rot(1, 1) = g4rot->yy();
239 rot(1, 2) = g4rot->yz();
240
241 rot(2, 0) = g4rot->zx();
242 rot(2, 1) = g4rot->zy();
243 rot(2, 2) = g4rot->zz();
244 }
245}

◆ dumpGeometry()

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

Definition at line 147 of file TrackingGeometry.cxx.

148 {
149 if (!tGeometry_) return;
150
151 if (debug_) {
152 std::cout << __PRETTY_FUNCTION__ << std::endl;
153
154 for (auto const& surfaceId : layer_surface_map_) {
155 std::cout << " " << surfaceId.first << std::endl;
156 std::cout << " Check the surface" << std::endl;
157 // surfaceId.second->toStream(gctx, std::cout);
158 surfaceId.second->toStream(gctx);
159 std::cout << " GeometryID::" << surfaceId.second->geometryId()
160 << std::endl;
161 std::cout << " GeometryID::" << surfaceId.second->geometryId().value()
162 << std::endl;
163 }
164 }
165
166 // Should fail if already exists
167 boost::filesystem::create_directory(outputDir);
168
169 double outputScalor = 1.0;
170 size_t outputPrecision = 6;
171
172 Acts::ObjVisualization3D objVis(outputPrecision, outputScalor);
173 Acts::ViewConfig containerView = Acts::ViewConfig({220, 220, 220});
174 Acts::ViewConfig volumeView = Acts::ViewConfig({220, 220, 0});
175 Acts::ViewConfig sensitiveView = Acts::ViewConfig({0, 180, 240});
176 Acts::ViewConfig passiveView = Acts::ViewConfig({240, 280, 0});
177 Acts::ViewConfig gridView = Acts::ViewConfig({220, 0, 0});
178
179 Acts::GeometryView3D::drawTrackingVolume(
180 objVis, *(tGeometry_->highestTrackingVolume()), gctx, containerView,
181 volumeView, passiveView, sensitiveView, gridView, true, "", ".");
182}

◆ findDaughterByName()

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

Definition at line 97 of file TrackingGeometry.cxx.

98 {
99 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
100 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
101 G4VPhysicalVolume* fDaughterPhysVol = lvol->GetDaughter(i);
102 std::string dName = fDaughterPhysVol->GetName();
103 if (dName.find(name) != std::string::npos) return fDaughterPhysVol;
104 // if (fDaughterPhysVol->GetName() == name) return fDaughterPhysVol;
105 }
106
107 return nullptr;
108}

◆ getAllDaughters()

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

Definition at line 110 of file TrackingGeometry.cxx.

110 {
111 G4LogicalVolume* lvol = pvol->GetLogicalVolume();
112
113 if (debug_)
114 std::cout << "Checking daughters of ::" << pvol->GetName() << std::endl;
115
116 for (G4int i = 0; i < lvol->GetNoDaughters(); i++) {
117 G4VPhysicalVolume* fDaughterPhysVol = lvol->GetDaughter(i);
118
119 if (debug_) {
120 std::cout << "name::" << fDaughterPhysVol->GetName() << std::endl;
121 std::cout << "pos::" << fDaughterPhysVol->GetTranslation() << std::endl;
122 std::cout << "n_dau::"
123 << fDaughterPhysVol->GetLogicalVolume()->GetNoDaughters()
124 << std::endl;
125 std::cout << "replica::" << fDaughterPhysVol->IsReplicated() << std::endl;
126 std::cout << "copyNR::" << fDaughterPhysVol->GetCopyNo() << std::endl;
127
128 getAllDaughters(fDaughterPhysVol);
129 }
130 }
131}

◆ getSurface()

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

Definition at line 94 of file TrackingGeometry.h.

94 {
95 return layer_surface_map_.at(layerid);
96 }

◆ getSurfaces()

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

Definition at line 261 of file TrackingGeometry.cxx.

262 {
263 if (!tGeometry_)
264 throw std::runtime_error("TrackingGeometry::getSurfaces tGeometry is null");
265
266 const Acts::TrackingVolume* tVolume = tGeometry_->highestTrackingVolume();
267 if (tVolume->confinedVolumes()) {
268 for (auto volume : tVolume->confinedVolumes()->arrayObjects()) {
269 if (volume->confinedLayers()) {
270 for (const auto& layer : volume->confinedLayers()->arrayObjects()) {
271 if (layer->layerType() == Acts::navigation) continue;
272 for (auto surface : layer->surfaceArray()->surfaces()) {
273 if (surface) {
274 surfaces.push_back(surface);
275
276 } // surface exists
277 } // surfaces
278 } // layers objects
279 } // confined layers
280 } // volumes objects
281 } // confined volumes
282}

◆ getTG()

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

Definition at line 78 of file TrackingGeometry.h.

78 {
79 return tGeometry_;
80 };

◆ GetTransform()

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

Definition at line 185 of file TrackingGeometry.cxx.

186 {
187 Acts::Vector3 pos(phex.GetTranslation().x(), phex.GetTranslation().y(),
188 phex.GetTranslation().z());
189
190 Acts::RotationMatrix3 rotation;
191 ConvertG4Rot(phex.GetRotation(), rotation);
192
193 // rotate to the tracking frame
194 if (toTrackingFrame) {
195 pos(0) = phex.GetTranslation().z();
196 pos(1) = phex.GetTranslation().x();
197 pos(2) = phex.GetTranslation().y();
198 rotation = x_rot_ * y_rot_ * rotation;
199 }
200
201 Acts::Translation3 translation(pos);
202
203 Acts::Transform3 transform(translation * rotation);
204
205 return transform;
206}

◆ makeLayerSurfacesMap()

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

Definition at line 284 of file TrackingGeometry.cxx.

284 {
285 std::vector<const Acts::Surface*> surfaces;
286 getSurfaces(surfaces);
287
288 for (auto& surface : surfaces) {
289 // Layers from 1 to 14 - for the tagger
290 // unsigned int layerId = (surface->geometryId().layer() / 2) ; // Old 1
291 // sensor per layer
292
293 unsigned int volumeId = surface->geometryId().volume();
294 unsigned int layerId = (surface->geometryId().layer() /
295 2); // set layer ID from 1 to 7 for the tagger and
296 // from 1 to 6 for the recoil
297 unsigned int sensorId =
298 surface->geometryId().sensitive() -
299 1; // set sensor ID from 0 to 1 for the tagger and from 0 to 9 for the
300 // axial sensors in the back layers of the recoil
301
302 if (debug_)
303 std::cout << "VolumeID " << volumeId << " LayerId " << layerId
304 << " sensorId " << sensorId << std::endl;
305
306 // surface ID = vol * 1000 + ly * 100 + sensor
307 unsigned int surfaceId = volumeId * 1000 + layerId * 100 + sensorId;
308
309 layer_surface_map_[surfaceId] = surface;
310
311 } // surfaces loop
312}

◆ toTracker()

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

Definition at line 210 of file TrackingGeometry.cxx.

211 {
212 Acts::Vector3 pos{trans.translation()(2), trans.translation()(0),
213 trans.translation()(1)};
214
215 Acts::RotationMatrix3 rotation = trans.rotation();
216 rotation = x_rot_ * y_rot_ * rotation;
217
218 Acts::Translation3 translation(pos);
219 Acts::Transform3 transform(translation * rotation);
220
221 return transform;
222}

Member Data Documentation

◆ debug_

bool tracking::geo::TrackingGeometry::debug_ {false}
protected

Definition at line 110 of file TrackingGeometry.h.

110{false};

◆ detElements

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

Definition at line 102 of file TrackingGeometry.h.

◆ fWorldPhysVol_

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

Definition at line 114 of file TrackingGeometry.h.

114{nullptr};

◆ gctx_

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

Definition at line 107 of file TrackingGeometry.h.

◆ gdml_

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

Definition at line 109 of file TrackingGeometry.h.

109{""};

◆ layer_surface_map_

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

Definition at line 98 of file TrackingGeometry.h.

◆ tGeometry_

std::shared_ptr<const Acts::TrackingGeometry> tracking::geo::TrackingGeometry::tGeometry_ {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: