1#include "Tracking/geo/TrackersTrackingGeometry.h"
3#include "Tracking/geo/GeoUtils.h"
7const std::string TrackersTrackingGeometry::NAME =
"TrackersTrackingGeometry";
9TrackersTrackingGeometry::TrackersTrackingGeometry(
10 const Acts::GeometryContext& gctx,
const std::string& gdml,
bool debug)
11 : TrackingGeometry(NAME, gctx, gdml, debug) {
12 if (debug_) std::cout <<
"Looking for Tagger and Recoil volumes" << std::endl;
14 Tagger_ = findDaughterByName(fWorldPhysVol_,
"tagger_PV");
18 BuildTaggerLayoutMap(Tagger_,
"tagger");
19 Acts::CuboidVolumeBuilder::VolumeConfig tagger_volume_cfg =
22 Recoil_ = findDaughterByName(fWorldPhysVol_,
"recoil_PV");
23 BuildRecoilLayoutMap(Recoil_,
"recoil");
24 Acts::CuboidVolumeBuilder::VolumeConfig recoil_volume_cfg =
27 std::vector<Acts::CuboidVolumeBuilder::VolumeConfig> volBuilderConfigs{
28 tagger_volume_cfg, recoil_volume_cfg};
31 Acts::CuboidVolumeBuilder cvb;
33 Acts::CuboidVolumeBuilder::Config config;
34 config.position = {-200, 0., 0.};
35 config.length = {900, 480, 240};
36 config.volumeCfg = volBuilderConfigs;
38 cvb.setConfig(config);
40 Acts::TrackingGeometryBuilder::Config tgbCfg;
41 tgbCfg.trackingVolumeBuilders.push_back(
42 [=](
const auto& cxt,
const auto& inner,
const auto&) {
43 return cvb.trackingVolume(cxt, inner,
nullptr);
46 Acts::TrackingGeometryBuilder tgb(tgbCfg);
47 tGeometry_ = tgb.trackingGeometry(gctx_);
50 makeLayerSurfacesMap();
54Acts::CuboidVolumeBuilder::VolumeConfig
55TrackersTrackingGeometry::buildRecoilVolume() {
56 Acts::CuboidVolumeBuilder::VolumeConfig subDetVolumeConfig;
57 Acts::Transform3 subDet_transform = GetTransform(*Recoil_,
true);
59 std::cout << subDet_transform.translation() << std::endl;
60 std::cout << subDet_transform.rotation() << std::endl;
65 Acts::Vector3 sub_det_position = {
66 subDet_transform.translation()(0) - 1,
67 subDet_transform.translation()(1),
68 subDet_transform.translation()(2),
72 G4Box* subDetBox = (G4Box*)(Recoil_->GetLogicalVolume()->GetSolid());
77 2 * (subDetBox->GetZHalfLength() + 1) * Acts::UnitConstants::mm;
84 double y_length = TrackerYLength_;
85 double z_length = TrackerZLength_;
88 std::cout << Recoil_->GetName() << std::endl;
89 std::cout <<
"position" << std::endl;
90 std::cout << sub_det_position << std::endl;
91 std::cout <<
"x_length " << x_length <<
" y_length " << y_length
92 <<
" z_length " << z_length << std::endl;
95 subDetVolumeConfig.position = sub_det_position;
96 subDetVolumeConfig.length = {x_length, y_length, z_length};
97 subDetVolumeConfig.name =
"Recoil";
100 Acts::Material subdet_mat = Acts::Material();
101 subDetVolumeConfig.volumeMaterial =
102 std::make_shared<Acts::HomogeneousVolumeMaterial>(subdet_mat);
104 std::vector<Acts::CuboidVolumeBuilder::LayerConfig> layerConfig;
107 for (
auto& layer : recoil_layout) {
109 std::cout << layer.first <<
" : surfaces==>" << layer.second.size()
113 Acts::CuboidVolumeBuilder::LayerConfig lcfg;
114 lcfg.surfaces = layer.second;
116 double clearance = 0.01;
117 double thickness = layer.second.front()
119 ->materialSlab(Acts::Vector2{0., 0.})
124 lcfg.envelopeX = std::array<double, 2>{thickness / 2. + clearance,
125 thickness / 2. + clearance};
127 layerConfig.push_back(lcfg);
130 subDetVolumeConfig.layerCfg = layerConfig;
132 return subDetVolumeConfig;
135Acts::CuboidVolumeBuilder::VolumeConfig
136TrackersTrackingGeometry::buildTrackerVolume() {
137 Acts::CuboidVolumeBuilder::VolumeConfig subDetVolumeConfig;
140 Acts::Transform3 subDet_transform = GetTransform(*Tagger_,
true);
144 Acts::Vector3 sub_det_position = {
145 subDet_transform.translation()(0) - 1,
146 subDet_transform.translation()(1),
147 subDet_transform.translation()(2),
151 G4Box* subDetBox = (G4Box*)(Tagger_->GetLogicalVolume()->GetSolid());
156 2 * (subDetBox->GetZHalfLength() + 1) * Acts::UnitConstants::mm;
163 double y_length = TrackerYLength_;
164 double z_length = TrackerZLength_;
167 std::cout << Tagger_->GetName() << std::endl;
168 std::cout <<
"position" << std::endl;
169 std::cout << sub_det_position << std::endl;
170 std::cout <<
"x_length " << x_length <<
" y_length " << y_length
171 <<
" z_length " << z_length << std::endl;
173 std::cout << subDet_transform.translation() << std::endl;
174 std::cout << subDet_transform.rotation() << std::endl;
177 subDetVolumeConfig.position = sub_det_position;
178 subDetVolumeConfig.length = {x_length, y_length, z_length};
179 subDetVolumeConfig.name =
"Tagger";
182 Acts::Material subdet_mat = Acts::Material();
183 subDetVolumeConfig.volumeMaterial =
184 std::make_shared<Acts::HomogeneousVolumeMaterial>(subdet_mat);
186 std::vector<Acts::CuboidVolumeBuilder::LayerConfig> layerConfig;
189 for (
auto& layer : tagger_layout) {
191 std::cout << layer.first <<
" : surfaces==>" << layer.second.size()
195 for (
auto& surface : layer.second) surface->toStream(gctx_);
198 Acts::CuboidVolumeBuilder::LayerConfig lcfg;
199 lcfg.surfaces = layer.second;
201 double clearance = 0.01;
202 double thickness = layer.second.front()
204 ->materialSlab(Acts::Vector2{0., 0.})
209 lcfg.envelopeX = std::array<double, 2>{thickness / 2. + clearance,
210 thickness / 2. + clearance};
212 layerConfig.push_back(lcfg);
215 subDetVolumeConfig.layerCfg = layerConfig;
217 return subDetVolumeConfig;
220void TrackersTrackingGeometry::BuildRecoilLayoutMap(G4VPhysicalVolume* pvol,
221 std::string surfacename) {
223 std::cout <<
"Building layout for the " << pvol->GetName() <<
" tracker"
225 getAllDaughters(pvol);
229 Acts::Transform3 tracker_transform = GetTransform(*pvol);
231 G4LogicalVolume* l_vol = pvol->GetLogicalVolume();
232 for (G4int i = 0; i < l_vol->GetNoDaughters(); i++) {
233 std::string sln = l_vol->GetDaughter(i)->GetName();
234 if (sln.find(surfacename) != std::string::npos) {
235 G4VPhysicalVolume* _Component0Volume{
nullptr};
236 G4VPhysicalVolume* _ActiveSensor{
nullptr};
237 Acts::Transform3 ref1_transform = GetTransform(*(l_vol->GetDaughter(i)));
238 int SensorCopyNr = -999;
242 if (sln.find(
"axial") != std::string::npos ||
243 sln.find(
"stereo") != std::string::npos) {
245 findDaughterByName(l_vol->GetDaughter(i),
246 "LDMXRecoilL14ModuleVolume_component0_physvol");
247 if (!_Component0Volume)
248 throw std::runtime_error(
249 "Could not find component0 volume for L14 Recoil");
250 _ActiveSensor = findDaughterByName(
252 "LDMXRecoilL14ModuleVolume_component0Sensor0_physvol");
258 else if (sln.find(
"l5_sensor") != std::string::npos ||
259 sln.find(
"l6_sensor") != std::string::npos) {
261 findDaughterByName(l_vol->GetDaughter(i),
262 "LDMXRecoilL56ModuleVolume_component0_physvol");
263 if (!_Component0Volume)
264 throw std::runtime_error(
265 "Could not find component0 volume for L56 Recoil");
266 _ActiveSensor = findDaughterByName(
268 "LDMXRecoilL56ModuleVolume_component0Sensor0_physvol");
273 else if (sln.find(
"sensor_vol")) {
275 findDaughterByName(l_vol->GetDaughter(i),
"active_sensor");
276 SensorCopyNr = l_vol->GetDaughter(i)->GetCopyNo();
280 throw std::runtime_error(
"Could not build recoil layout");
283 throw std::runtime_error(
284 "Could not find ActiveSensor for recoil volume");
286 Acts::Transform3 ref2_transform = Acts::Transform3::Identity();
288 if (_Component0Volume)
289 ref2_transform = GetTransform(*(_Component0Volume));
291 std::shared_ptr<Acts::PlaneSurface> sensorSurface = GetSurface(
292 _ActiveSensor, tracker_transform * ref1_transform * ref2_transform);
295 if (sln ==
"recoil_l1_axial" || sln ==
"recoil_l1_stereo" ||
296 SensorCopyNr == 10 || SensorCopyNr == 20)
297 recoil_layout[
"recoil_tracker_L1"].push_back(sensorSurface);
299 if (sln ==
"recoil_l2_axial" || sln ==
"recoil_l2_stereo" ||
300 SensorCopyNr == 30 || SensorCopyNr == 40)
301 recoil_layout[
"recoil_tracker_L2"].push_back(sensorSurface);
303 if (sln ==
"recoil_l3_axial" || sln ==
"recoil_l3_stereo" ||
304 SensorCopyNr == 50 || SensorCopyNr == 60)
305 recoil_layout[
"recoil_tracker_L3"].push_back(sensorSurface);
307 if (sln ==
"recoil_l4_axial" || sln ==
"recoil_l4_stereo" ||
308 SensorCopyNr == 70 || SensorCopyNr == 80)
309 recoil_layout[
"recoil_tracker_L4"].push_back(sensorSurface);
311 if (sln ==
"recoil_l5_sensor1" || sln ==
"recoil_l5_sensor2" ||
312 sln ==
"recoil_l5_sensor3" || sln ==
"recoil_l5_sensor4" ||
313 sln ==
"recoil_l5_sensor5" || sln ==
"recoil_l5_sensor6" ||
314 sln ==
"recoil_l5_sensor7" || sln ==
"recoil_l5_sensor8" ||
315 sln ==
"recoil_l5_sensor9" || sln ==
"recoil_l5_sensor10" ||
316 (SensorCopyNr >= 90 && SensorCopyNr <= 99))
318 recoil_layout[
"recoil_tracker_L5"].push_back(sensorSurface);
320 if (sln ==
"recoil_l6_sensor1" || sln ==
"recoil_l6_sensor2" ||
321 sln ==
"recoil_l6_sensor3" || sln ==
"recoil_l6_sensor4" ||
322 sln ==
"recoil_l6_sensor5" || sln ==
"recoil_l6_sensor6" ||
323 sln ==
"recoil_l6_sensor7" || sln ==
"recoil_l6_sensor8" ||
324 sln ==
"recoil_l6_sensor9" || sln ==
"recoil_l6_sensor10" ||
325 (SensorCopyNr >= 100 && SensorCopyNr <= 109))
326 recoil_layout[
"recoil_tracker_L6"].push_back(sensorSurface);
335void TrackersTrackingGeometry::BuildTaggerLayoutMap(G4VPhysicalVolume* pvol,
336 std::string surfacename) {
338 std::cout <<
"Building layout for the " << pvol->GetName() <<
" tracker"
340 getAllDaughters(pvol);
344 Acts::Transform3 tracker_transform = GetTransform(*pvol);
346 G4LogicalVolume* l_vol = pvol->GetLogicalVolume();
347 for (G4int i = 0; i < l_vol->GetNoDaughters(); i++) {
348 std::string sln = l_vol->GetDaughter(i)->GetName();
351 if (sln.find(surfacename) != std::string::npos) {
376 Acts::Transform3 ref1_transform = GetTransform(*(l_vol->GetDaughter(i)));
378 G4VPhysicalVolume* _Component0Volume = findDaughterByName(
379 l_vol->GetDaughter(i),
"LDMXTaggerModuleVolume_component0_physvol");
381 Acts::Transform3 ref2_transform = Acts::Transform3::Identity();
382 G4VPhysicalVolume* _ActiveSensor =
nullptr;
383 int SensorCopyNr = -999;
386 if (_Component0Volume) {
387 ref2_transform = GetTransform(*(_Component0Volume));
388 _ActiveSensor = findDaughterByName(
390 "LDMXTaggerModuleVolume_component0Sensor0_physvol");
395 findDaughterByName(l_vol->GetDaughter(i),
"active_sensor");
396 SensorCopyNr = (l_vol->GetDaughter(i))->GetCopyNo();
399 if (!_ActiveSensor) {
400 throw std::runtime_error(
401 "Could not find the ActiveSensor from Component0Volume");
405 std::shared_ptr<Acts::PlaneSurface> sensorSurface = GetSurface(
406 _ActiveSensor, tracker_transform * ref1_transform * ref2_transform);
408 if (sln ==
"LDMXTaggerModuleVolume_physvol1" ||
409 sln ==
"LDMXTaggerModuleVolume_physvol2" || SensorCopyNr == 130 ||
411 tagger_layout[
"tagger_tracker_L1"].push_back(sensorSurface);
413 if (sln ==
"LDMXTaggerModuleVolume_physvol3" ||
414 sln ==
"LDMXTaggerModuleVolume_physvol4" || SensorCopyNr == 110 ||
416 tagger_layout[
"tagger_tracker_L2"].push_back(sensorSurface);
418 if (sln ==
"LDMXTaggerModuleVolume_physvol5" ||
419 sln ==
"LDMXTaggerModuleVolume_physvol6" || SensorCopyNr == 90 ||
421 tagger_layout[
"tagger_tracker_L3"].push_back(sensorSurface);
423 if (sln ==
"LDMXTaggerModuleVolume_physvol7" ||
424 sln ==
"LDMXTaggerModuleVolume_physvol8" || SensorCopyNr == 70 ||
426 tagger_layout[
"tagger_tracker_L4"].push_back(sensorSurface);
428 if (sln ==
"LDMXTaggerModuleVolume_physvol9" ||
429 sln ==
"LDMXTaggerModuleVolume_physvol10" || SensorCopyNr == 50 ||
431 tagger_layout[
"tagger_tracker_L5"].push_back(sensorSurface);
433 if (sln ==
"LDMXTaggerModuleVolume_physvol11" ||
434 sln ==
"LDMXTaggerModuleVolume_physvol12" || SensorCopyNr == 30 ||
436 tagger_layout[
"tagger_tracker_L6"].push_back(sensorSurface);
438 if (sln ==
"LDMXTaggerModuleVolume_physvol13" ||
439 sln ==
"LDMXTaggerModuleVolume_physvol14" || SensorCopyNr == 10 ||
441 tagger_layout[
"tagger_tracker_L7"].push_back(sensorSurface);
447std::shared_ptr<Acts::PlaneSurface> TrackersTrackingGeometry::GetSurface(
448 G4VPhysicalVolume* pvol, Acts::Transform3 ref_trans) {
450 throw std::runtime_error(
451 "TrackersTrackingGeometry::GetSurface:: pvol is nullptr");
454 Acts::Transform3 surface_transform = GetTransform(*pvol);
456 surface_transform = ref_trans * surface_transform;
459 Acts::Transform3 surface_transform_tracker = toTracker(surface_transform);
462 std::cout <<
"THE SENSOR TRANSFORM - TRANSLATION" << std::endl;
463 std::cout << surface_transform.translation()(0) << std::endl;
464 std::cout << surface_transform.translation()(1) << std::endl;
465 std::cout << surface_transform.translation()(2) << std::endl;
466 std::cout <<
"THE SENSOR TRANSFORM - ROTATION" << std::endl;
467 std::cout << surface_transform.rotation() << std::endl;
469 std::cout <<
"TO THE TRACKER FRAME" << std::endl;
470 std::cout << surface_transform_tracker.translation()(0) << std::endl;
471 std::cout << surface_transform_tracker.translation()(1) << std::endl;
472 std::cout << surface_transform_tracker.translation()(2) << std::endl;
473 std::cout <<
"THE SENSOR TRANSFORM - ROTATION" << std::endl;
474 std::cout << surface_transform_tracker.rotation() << std::endl;
502 Acts::Material silicon = Acts::Material::fromMassDensity(
503 95.7 * Acts::UnitConstants::mm, 465.2 * Acts::UnitConstants::mm, 28.03,
504 14., 2.32 * Acts::UnitConstants::g / Acts::UnitConstants::cm3);
507 G4Box* surfaceSolid = (G4Box*)(pvol->GetLogicalVolume()->GetSolid());
510 std::cout <<
"Sensor Dimensions" << std::endl;
511 std::cout << surfaceSolid->GetXHalfLength() <<
" "
512 << surfaceSolid->GetYHalfLength() <<
" "
513 << surfaceSolid->GetZHalfLength() <<
" " << std::endl;
518 2 * surfaceSolid->GetZHalfLength() * Acts::UnitConstants::mm;
519 Acts::MaterialSlab silicon_slab(silicon, thickness);
522 std::shared_ptr<const Acts::RectangleBounds> rect_bounds =
523 std::make_shared<const Acts::RectangleBounds>(Acts::RectangleBounds(
524 surfaceSolid->GetXHalfLength() * Acts::UnitConstants::mm,
525 surfaceSolid->GetYHalfLength() * Acts::UnitConstants::mm));
528 std::shared_ptr<Acts::PlaneSurface> surface =
529 Acts::Surface::makeShared<Acts::PlaneSurface>(surface_transform_tracker,
531 surface->assignSurfaceMaterial(
532 std::make_shared<Acts::HomogeneousSurfaceMaterial>(silicon_slab));
537 auto detElement = std::make_shared<DetectorElement>(
538 surface, surface_transform_tracker, thickness);
544 surface->assignDetectorElement(std::move(*detElement));
545 detElements.push_back(detElement);