13#include "Acts/Geometry/GeometryContext.hpp"
14#include "Acts/Surfaces/LineBounds.hpp"
15#include "Acts/Surfaces/StrawSurface.hpp"
21constexpr double kStereoAngle = 4.57 * M_PI / 180.;
22constexpr double kPitch = 2.;
23constexpr double kRadius = 1.;
27void check(
bool condition,
const char* what) {
29 std::cout <<
"FAIL: " << what << std::endl;
35 double offset,
double z) {
37 const double dx = std::cos(angle);
38 const double dy = std::sin(angle);
40 z, dx,
dy, 0., kRadius, 250.};
43double viewAngle(
int view) {
44 return view == 1 ? kStereoAngle : view == 2 ? -kStereoAngle : 0.;
49 const auto gctx = Acts::GeometryContext::dangerouslyDefaultConstruct();
50 Acts::Transform3 ship = Acts::Transform3::Identity();
51 const Acts::Vector3 axis(wire.
dx, wire.
dy, wire.
dz);
52 const Acts::Vector3 other = axis.cross(Acts::Vector3::UnitZ()).normalized();
53 ship.linear().col(0) = other;
54 ship.linear().col(1) = axis.cross(other);
55 ship.linear().col(2) = axis;
56 ship.translation() = Acts::Vector3(wire.
x, wire.
y, wire.
z);
57 const auto surface = Acts::Surface::makeShared<Acts::StrawSurface>(
59 std::make_shared<const Acts::LineBounds>(kRadius * 10., 2500.));
60 const Acts::Vector3 position =
62 const Acts::Vector3 direction =
65 const auto pca = surface->intersect(gctx, position, direction).closest();
66 const auto local = surface->globalToLocal(gctx, pca.position(), direction);
70void testSignConvention() {
71 for (
const int view : {0, 1, 2}) {
72 for (
const double offset : {-0.4, 0.7}) {
73 const auto wire = makeWire(1, view, 0, viewAngle(view), 0., 100.);
78 -std::sin(viewAngle(view)) * offset + 0.3 * std::cos(viewAngle(view));
80 std::cos(viewAngle(view)) * offset + 0.3 * std::sin(viewAngle(view));
84 const double acts = actsLoc0(line, wire);
85 check(std::abs(ours - acts) < 1e-6,
86 "signed wire distance matches ACTS straw loc0");
87 check(std::abs(std::abs(ours) - std::abs(offset)) < 0.01,
88 "signed wire distance has the expected size");
95 std::vector<SHiP::StrawWire>& wires) {
96 for (
int view = 0; view < 4; ++view) {
97 for (
int layer = 0; layer < 2; ++layer) {
98 const double z = z0 + 10. * view + 2. * layer;
99 const double angle = viewAngle(view);
102 -std::sin(angle) * line.
x(z) + std::cos(angle) * line.
y(z);
103 const double stagger = layer * kPitch / 2.;
104 const double offset =
105 std::round((u - stagger) / kPitch) * kPitch + stagger;
106 wires.push_back(makeWire(station, view, layer, angle, offset, z));
111void testFindsSyntheticTrack() {
114 constexpr double bendingZ = 500.;
115 constexpr double fieldIntegral = 0.65;
124 down.
ty = up.
ty + 0.299792458 * fieldIntegral /
momentum;
126 std::vector<SHiP::StrawWire> wires;
127 addStation(1, 0., up, wires);
128 addStation(2, 200., up, wires);
129 addStation(3, 800., down, wires);
130 addStation(4, 1000., down, wires);
131 std::vector<SHiP::PatRecHit> hits;
132 for (std::size_t i = 0;
i < wires.size(); ++
i) {
133 const auto& line = wires[
i].station <= 2 ? up : down;
134 hits.push_back({
static_cast<int>(
i), &wires[i],
140 const auto tracks =
patRec.findTracks(hits);
141 check(tracks.size() == 1,
"one track found");
142 if (tracks.size() != 1) {
145 const auto& track = tracks.front();
146 check(track.charge == 1,
"charge from the kink");
147 check(std::abs(track.momentum - momentum) / momentum < 0.01,
148 "momentum from the kink");
149 check(track.upstream.hits.size() == 16 && track.downstream.hits.size() == 16,
150 "all hits on the segments");
151 for (
const auto* segment : {&track.upstream, &track.downstream}) {
152 const auto& truth = segment == &track.upstream ? up : down;
153 check(std::abs(segment->x(bendingZ) - truth.x(bendingZ)) < 0.01 &&
154 std::abs(segment->y(bendingZ) - truth.y(bendingZ)) < 0.01,
156 for (std::size_t k = 0;
k < segment->hits.size(); ++
k) {
157 const auto& wire = wires[segment->hits[
k]];
159 check(std::abs(distance) < 0.05 ||
160 segment->signs[k] == (distance >= 0. ? 1 : -1),
169 testSignConvention();
170 testFindsSyntheticTrack();
172 std::cout <<
"All straw pattern recognition tests passed" << std::endl;
174 return failures == 0 ? 0 : 1;
Acts::Transform3 transformToActs(const Acts::Transform3 &shipTransform)
Transform of a TGeo placement (SHiP frame, cm) in the ACTS frame.
Acts::RotationMatrix3 toActsRotation()
Rotation taking SHiP-frame vectors to the ACTS frame.
Acts::Vector3 positionToActs(double x, double y, double z)
constexpr double kShipLength
Length unit of the SHiP frame, in ACTS units.
double signedWireDistance(const LineSegment &line, const StrawWire &wire)
A straw wire in the SHiP frame (cm), for pattern recognition.
double dx
Unit vector along the wire.