Skip to content

Commit abbf814

Browse files
authored
Merge branch 'main' into refactor-seeding2-edm-make-xyz-optional
2 parents 7ddb151 + 2c1d51b commit abbf814

File tree

23 files changed

+589
-291
lines changed

23 files changed

+589
-291
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#pragma once
10+
11+
#include "Acts/Definitions/Algebra.hpp"
12+
#include "Acts/Definitions/Units.hpp"
13+
14+
namespace Acts::detail {
15+
/// @brief Auxiliary class to coherently sort Transforms and Vectors such that
16+
/// a strict ordering between two objects may be defined and hence
17+
/// a sorted map or set of these objects becomes possible. In the case of
18+
/// Vectors, the sorter compares the differences of each component. As
19+
/// soon as a difference exceeds the predefined translational tolerance
20+
/// threshold the < operator is assigned based on this difference. In the
21+
/// case of rotations, the three Euler angles of the rotation matrix are
22+
/// evaluated and compared in an analogous way
23+
class TransformComparator {
24+
public:
25+
/// @brief Default constructor setting the predefined tolerance values
26+
/// for translation & rotation
27+
TransformComparator() = default;
28+
/// @brief Constructor with an adaption of the translation & rotTolerance
29+
/// @param transTolerance: Tolerance value within the difference of the
30+
/// i-th component between two vectors is considered to be 0
31+
/// @param rotTolerance: Tolerance value within the difference of the
32+
/// i-th Euler angle between two Rotations is considered to be 0
33+
TransformComparator(const double transTolerance, const double rotTolerance);
34+
/// @brief Generic comparison function between two kSize-dimensional vectors
35+
/// Returns 0 if all components agree within the translational
36+
/// tolerance. As soon as one component differs, 1 is returned if the
37+
/// component from vector a is larger and otherwise -1
38+
/// @param a: Reference to the first vector to compare
39+
/// @param b: Reference to the second vector to compare
40+
template <unsigned int kSize>
41+
int compare(const Acts::ActsVector<kSize>& a,
42+
const Acts::ActsVector<kSize>& b) const {
43+
for (unsigned int i = 0; i < kSize; ++i) {
44+
const double diff = a[i] - b[i];
45+
if (std::abs(diff) > m_tolTrans) {
46+
return diff > 0 ? 1 : -1;
47+
}
48+
}
49+
return 0;
50+
}
51+
/// @brief Brief compares the three Euler angles of the two rotation matrices
52+
/// If all angles agree within the rotational tolerance, 0 is returned.
53+
/// Otherwise, -1 or 1 is returned depending on whether the first
54+
/// differing i-th angle from a or b is larger.
55+
/// @param a: Reference to the first rotation matrix to compare
56+
/// @param b: Reference to the second rotation matrix to compare
57+
int compare(const Acts::RotationMatrix3& a,
58+
const Acts::RotationMatrix3& b) const;
59+
/// @brief Compares two transforms. First, it's checked whether the translational
60+
/// components between the two differ and if not the comparison between
61+
/// the two rotation matrices is returned
62+
/// @param a: Reference to the first transform to compare
63+
/// @param b: Reference to the second transform to compare
64+
int compare(const Acts::Transform3& a, const Acts::Transform3& b) const;
65+
66+
/// @brief Implementation of the < operator for Transforms
67+
bool operator()(const Acts::Transform3& a, const Acts::Transform3& b) const;
68+
/// @brief Implementation of the < operator for RotationMatrices
69+
bool operator()(const Acts::RotationMatrix3& a,
70+
const Acts::RotationMatrix3& b) const;
71+
/// @brief Implementation of the < operator for 3-vectors
72+
bool operator()(const Acts::Vector3& a, const Acts::Vector3& b) const;
73+
/// @brief Implementation of the < operator for 2-vectors
74+
bool operator()(const Acts::Vector2& a, const Acts::Vector2& b) const;
75+
76+
private:
77+
/** @brief Maximum tolerance per translational vector component */
78+
double m_tolTrans{0.1 * Acts::UnitConstants::um};
79+
/** @brief Maximum tolerance per euler angle */
80+
double m_tolRot{0.01 * Acts::UnitConstants::mrad};
81+
};
82+
} // namespace Acts::detail

Core/src/Geometry/TrapezoidVolumeBounds.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ bool TrapezoidVolumeBounds::inside(const Vector3& pos, double tol) const {
160160
std::ostream& TrapezoidVolumeBounds::toStream(std::ostream& os) const {
161161
os << std::setiosflags(std::ios::fixed);
162162
os << std::setprecision(5);
163-
os << "TrapezoidVolumeBounds: (minhalfX, halfY, halfZ, alpha, beta) "
163+
os << "TrapezoidVolumeBounds: (halfX @-Y, halfX @+Y, halfY, halfZ, alpha, "
164+
"beta) "
164165
"= ";
165166
os << "(" << get(eHalfLengthXnegY) << ", " << get(eHalfLengthXposY) << ", "
166167
<< get(eHalfLengthY) << ", " << get(eHalfLengthZ);

Core/src/Utilities/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ target_sources(
1111
GraphViz.cpp
1212
ProtoAxis.cpp
1313
ScopedTimer.cpp
14+
TransformComparator.cpp
1415
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#include "Acts/Utilities/detail/TransformComparator.hpp"
10+
11+
namespace Acts::detail {
12+
TransformComparator::TransformComparator(const double transTolerance,
13+
const double rotTolerance)
14+
: m_tolTrans{transTolerance}, m_tolRot{rotTolerance} {}
15+
int TransformComparator::compare(const Acts::RotationMatrix3& a,
16+
const Acts::RotationMatrix3& b) const {
17+
const Acts::Vector3 anglesA = a.eulerAngles(2, 1, 0);
18+
const Acts::Vector3 anglesB = b.eulerAngles(2, 1, 0);
19+
for (int i = 0; i < 3; ++i) {
20+
const double diff = anglesA[i] - anglesB[i];
21+
if (std::abs(diff) > m_tolRot) {
22+
return diff > 0 ? 1 : -1;
23+
}
24+
}
25+
return 0;
26+
}
27+
int TransformComparator::compare(const Acts::Transform3& a,
28+
const Acts::Transform3& b) const {
29+
if (const int tCmp = compare<3>(a.translation(), b.translation());
30+
tCmp != 0) {
31+
return tCmp;
32+
}
33+
return compare(a.rotation(), b.rotation());
34+
}
35+
bool TransformComparator::operator()(const Acts::Transform3& a,
36+
const Acts::Transform3& b) const {
37+
return compare(a, b) < 0;
38+
}
39+
bool TransformComparator::operator()(const Acts::RotationMatrix3& a,
40+
const RotationMatrix3& b) const {
41+
return compare(a, b) < 0;
42+
}
43+
bool TransformComparator::operator()(const Acts::Vector3& a,
44+
const Acts::Vector3& b) const {
45+
return compare<3>(a, b) < 0;
46+
}
47+
bool TransformComparator::operator()(const Acts::Vector2& a,
48+
const Acts::Vector2& b) const {
49+
return compare<2>(a, b) < 0;
50+
}
51+
} // namespace Acts::detail

Examples/Algorithms/Geant4/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
add_library(
22
ActsExamplesGeant4
33
SHARED
4+
src/AlgebraConverters.cpp
45
src/Geant4Simulation.cpp
56
src/MagneticFieldWrapper.cpp
67
src/MaterialPhysicsList.cpp
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#pragma once
10+
11+
#include "Acts/Definitions/Algebra.hpp"
12+
13+
#include "G4ThreeVector.hh"
14+
15+
namespace ActsExamples::Geant4 {
16+
/// @brief Converts a G4 3-vector position into an Acts 3-vector
17+
Acts::Vector3 convertPosition(const G4ThreeVector& g4vec);
18+
/// @brief Converts a G4 4-vector position into an Acts 4-vector
19+
Acts::Vector4 convertPosition(const G4ThreeVector& g4vec, const double time);
20+
/// @brief Converts a G4 momentum vector into an Acts momentum vector
21+
Acts::Vector4 convertMomentum(const G4ThreeVector& g4vec, const double energy);
22+
/// @brief Converts a G4 direction vector into an Acts direction vector
23+
Acts::Vector3 convertDirection(const G4ThreeVector& g4vec);
24+
/// @brief Converts a Acts 3-vector position into a G4 3-vector
25+
G4ThreeVector convertPosition(const Acts::Vector3& actsVec);
26+
/// @brief Converts a Acts 3-direction position into a G4 3-direction
27+
G4ThreeVector convertDirection(const Acts::Vector3& actsVec);
28+
29+
} // namespace ActsExamples::Geant4

Examples/Algorithms/Geant4/include/ActsExamples/Geant4/SensitiveSurfaceMapper.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
#include "Acts/Geometry/GeometryIdentifier.hpp"
1414
#include "Acts/Geometry/TrackingGeometry.hpp"
1515
#include "Acts/Utilities/Logger.hpp"
16+
#include "Acts/Utilities/detail/TransformComparator.hpp"
1617

1718
#include <map>
1819
#include <memory>
1920
#include <string>
21+
#include <unordered_map>
2022
#include <vector>
2123

2224
class G4VPhysicalVolume;
2325

2426
namespace Acts {
2527
class Surface;
26-
}
28+
} // namespace Acts
2729

2830
namespace ActsExamples::Geant4 {
2931

@@ -57,15 +59,22 @@ struct SensitiveCandidatesBase {
5759
virtual ~SensitiveCandidatesBase() = default;
5860
};
5961

60-
/// Implementation of the SensitiveCandidates for Gen1 geometry
62+
/// Implementation of the SensitiveCandidates for Gen1 && Gen3 geometry
6163
struct SensitiveCandidates : public SensitiveCandidatesBase {
62-
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry = nullptr;
64+
SensitiveCandidates(
65+
const std::shared_ptr<const Acts::TrackingGeometry>& trackingGeometry,
66+
std::unique_ptr<const Acts::Logger> _logger);
6367

6468
std::vector<const Acts::Surface*> queryPosition(
6569
const Acts::GeometryContext& gctx,
6670
const Acts::Vector3& position) const override;
6771

6872
std::vector<const Acts::Surface*> queryAll() const override;
73+
74+
private:
75+
std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{};
76+
std::unique_ptr<const Acts::Logger> m_logger{};
77+
const Acts::Logger& logger() const { return *m_logger; }
6978
};
7079

7180
/// @brief The SensitiveSurfaceMapper connects the Geant 4 geometry with the Acts::TrackingGeometry.
@@ -86,8 +95,11 @@ class SensitiveSurfaceMapper {
8695
/// This prefix is used to indicate a sensitive volume that is matched
8796
constexpr static std::string_view mappingPrefix = "ActsSensitive#";
8897
/// @brief Abrivation of the association between G4 volumes and surfaces
98+
99+
using SurfacePosMap_t = std::map<Acts::Vector3, const Acts::Surface*,
100+
Acts::detail::TransformComparator>;
89101
using VolumeToSurfAssocMap_t =
90-
std::multimap<const G4VPhysicalVolume*, const Acts::Surface*>;
102+
std::unordered_map<const G4VPhysicalVolume*, SurfacePosMap_t>;
91103

92104
/// Configuration struct for the surface mapper
93105
struct Config {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file is part of the ACTS project.
2+
//
3+
// Copyright (C) 2016 CERN for the benefit of the ACTS project
4+
//
5+
// This Source Code Form is subject to the terms of the Mozilla Public
6+
// License, v. 2.0. If a copy of the MPL was not distributed with this
7+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8+
9+
#include "ActsExamples/Geant4/AlgebraConverters.hpp"
10+
11+
#include "Acts/Definitions/Units.hpp"
12+
13+
#include "CLHEP/Units/SystemOfUnits.h"
14+
namespace {
15+
constexpr double convertLength = CLHEP::mm / Acts::UnitConstants::mm;
16+
constexpr double convertTime = Acts::UnitConstants::ns / CLHEP::ns;
17+
constexpr double convertEnergy = Acts::UnitConstants::GeV / CLHEP::GeV;
18+
} // namespace
19+
20+
namespace ActsExamples::Geant4 {
21+
Acts::Vector3 convertPosition(const G4ThreeVector& g4vec) {
22+
return Acts::Vector3(g4vec[0] * convertLength, g4vec[1] * convertLength,
23+
g4vec[2] * convertLength);
24+
};
25+
26+
Acts::Vector4 convertPosition(const G4ThreeVector& g4vec, const double time) {
27+
return Acts::Vector4(g4vec[0] * convertLength, g4vec[1] * convertLength,
28+
g4vec[2] * convertLength, time * convertTime);
29+
}
30+
31+
Acts::Vector4 convertMomentum(const G4ThreeVector& g4vec, const double energy) {
32+
return Acts::Vector4{convertEnergy * g4vec[0], convertEnergy * g4vec[1],
33+
convertEnergy * g4vec[2], convertEnergy * energy};
34+
}
35+
36+
G4ThreeVector convertPosition(const Acts::Vector3& actsVec) {
37+
return G4ThreeVector(actsVec[0] / convertLength, actsVec[1] / convertLength,
38+
actsVec[2] / convertLength);
39+
}
40+
Acts::Vector3 convertDirection(const G4ThreeVector& g4vec) {
41+
return Acts::Vector3{g4vec[0], g4vec[1], g4vec[2]};
42+
}
43+
G4ThreeVector convertDirection(const Acts::Vector3& actsVec) {
44+
return G4ThreeVector{actsVec[0], actsVec[1], actsVec[2]};
45+
}
46+
47+
} // namespace ActsExamples::Geant4

Examples/Algorithms/Geant4/src/MagneticFieldWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Acts/Definitions/Units.hpp"
1313
#include "Acts/MagneticField/MagneticFieldContext.hpp"
1414
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
15+
#include "ActsExamples/Geant4/AlgebraConverters.hpp"
1516

1617
#include <utility>
1718

Examples/Algorithms/Geant4/src/MaterialSteppingAction.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Acts/Material/Material.hpp"
1414
#include "Acts/Material/MaterialInteraction.hpp"
1515
#include "Acts/Material/MaterialSlab.hpp"
16+
#include "ActsExamples/Geant4/AlgebraConverters.hpp"
1617
#include "ActsExamples/Geant4/EventStore.hpp"
1718

1819
#include <cstddef>
@@ -84,14 +85,11 @@ void MaterialSteppingAction::UserSteppingAction(const G4Step* step) {
8485
convertLength * step->GetStepLength());
8586

8687
// Create the RecordedMaterialSlab
87-
const auto& rawPos = step->GetPreStepPoint()->GetPosition();
88-
const auto& rawDir = step->GetPreStepPoint()->GetMomentum();
8988
Acts::MaterialInteraction mInteraction;
9089
mInteraction.position =
91-
Acts::Vector3(convertLength * rawPos.x(), convertLength * rawPos.y(),
92-
convertLength * rawPos.z());
93-
mInteraction.direction = Acts::Vector3(rawDir.x(), rawDir.y(), rawDir.z());
94-
mInteraction.direction.normalized();
90+
convertPosition(step->GetPreStepPoint()->GetPosition());
91+
mInteraction.direction =
92+
convertDirection(step->GetPreStepPoint()->GetMomentum()).normalized();
9593
mInteraction.materialSlab = slab;
9694
mInteraction.pathCorrection = (step->GetStepLength() / CLHEP::mm);
9795

@@ -100,10 +98,8 @@ void MaterialSteppingAction::UserSteppingAction(const G4Step* step) {
10098
auto& materialTracks = eventStore().materialTracks;
10199
if (!materialTracks.contains(trackID - 1)) {
102100
Acts::RecordedMaterialTrack rmTrack;
103-
const auto& g4Vertex = g4Track->GetVertexPosition();
104-
Acts::Vector3 vertex(g4Vertex[0], g4Vertex[1], g4Vertex[2]);
105-
const auto& g4Direction = g4Track->GetMomentumDirection();
106-
Acts::Vector3 direction(g4Direction[0], g4Direction[1], g4Direction[2]);
101+
Acts::Vector3 vertex = convertPosition(g4Track->GetVertexPosition());
102+
Acts::Vector3 direction = convertDirection(g4Track->GetMomentumDirection());
107103
rmTrack.first = {vertex, direction};
108104
rmTrack.second.materialInteractions.push_back(mInteraction);
109105
materialTracks[trackID - 1] = rmTrack;

0 commit comments

Comments
 (0)