FairShip
Loading...
Searching...
No Matches
test_acts_straw_geometry.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
5// Tests of the ACTS straw geometry: the straw material comes from the wall,
6// gas and wire volumes of the TGeo geometry.
7
8#include <cmath>
9#include <iostream>
10
11#include "Acts/Material/ISurfaceMaterial.hpp"
12#include "Acts/Material/MaterialSlab.hpp"
13#include "ActsStrawGeometry.hpp"
14#include "TGeoManager.h"
15#include "TGeoMaterial.h"
16#include "TGeoMatrix.h"
17#include "TGeoMedium.h"
18#include "TGeoTube.h"
19#include "TGeoVolume.h"
20
21namespace {
22
23// Straw dimensions of geometry/strawtubes_config.yaml (cm)
24constexpr double kOuterRadius = 1.;
25constexpr double kWall = 0.0036;
26constexpr double kWireRadius = 0.0015;
27constexpr double kEps = 0.0001;
28
29int failures = 0;
30
31void check(bool condition, const char* what) {
32 if (!condition) {
33 std::cout << "FAIL: " << what << std::endl;
34 ++failures;
35 }
36}
37
40double meanX0(double rmin, double rmax, const TGeoMaterial& material) {
41 return M_PI * (rmax * rmax - rmin * rmin) / (2. * kOuterRadius) /
42 material.GetRadLen();
43}
44
45void testStrawMaterial() {
46 auto* manager = new TGeoManager("strawGeometry", "straws");
47 // Mylar, Ar/CO2 80/20 and tungsten as in geometry/media.geo
48 auto* mylar = new TGeoMixture("mylar", 3, 1.39);
49 mylar->AddElement(1.008, 1., 0.042);
50 mylar->AddElement(12.01, 6., 0.625);
51 mylar->AddElement(16., 8., 0.333);
52 auto* gasMix = new TGeoMixture("STTmix8020_1bar", 3, 0.001698);
53 gasMix->AddElement(39.948, 18., 0.78);
54 gasMix->AddElement(12.01, 6., 0.06);
55 gasMix->AddElement(15.9994, 8., 0.16);
56 auto* tungsten = new TGeoMaterial("tungsten", 183.84, 74., 19.3);
57 auto* vacuum = new TGeoMaterial("vacuum", 0., 0., 0.);
58
59 auto* top = manager->MakeBox("cave", new TGeoMedium("vacuum", 1, vacuum),
60 500., 500., 500.);
61 manager->SetTopVolume(top);
62 auto* layer = manager->MakeBox("layer", new TGeoMedium("air", 2, vacuum),
63 300., 10., kOuterRadius + kEps);
64 auto* straw = new TGeoVolume(
65 "straw", new TGeoTube(kOuterRadius - kWall, kOuterRadius, 250.),
66 new TGeoMedium("mylar", 3, mylar));
67 auto* gas = new TGeoVolume(
68 "gas",
69 new TGeoTube(kWireRadius + kEps, kOuterRadius - kWall - kEps, 250.),
70 new TGeoMedium("STTmix8020_1bar", 4, gasMix));
71 auto* wire = new TGeoVolume("wire", new TGeoTube(0., kWireRadius, 250.),
72 new TGeoMedium("tungsten", 5, tungsten));
73 // Two horizontal straws of station 1, view 0, layer 0
74 for (int number = 1; number <= 2; ++number) {
75 auto* placement =
76 new TGeoCombiTrans(0., 2. * kOuterRadius * (number - 1.5), 0.,
77 new TGeoRotation("r", 90., 90., 0.));
78 layer->AddNode(straw, 1001000 + number, placement);
79 layer->AddNode(gas, 1002000 + number, placement);
80 layer->AddNode(wire, 1003000 + number, placement);
81 }
82 top->AddNode(layer, 1, new TGeoTranslation(0., 0., 8400.));
83 manager->CloseGeometry();
84
85 const SHiP::ActsStrawGeometry geometry(*manager);
86 check(geometry.size() == 2, "two straws");
87 const Acts::Surface* surface = geometry.surface(1002001);
88 check(surface != nullptr, "straw surface found by detector ID");
89 if (surface == nullptr || surface->surfaceMaterial() == nullptr) {
90 check(false, "straw surface has material");
91 delete manager;
92 return;
93 }
94 const double x0 = surface->surfaceMaterial()
95 ->materialSlab(Acts::Vector2::Zero())
96 .thicknessInX0();
97 const double expected =
98 meanX0(kOuterRadius - kWall, kOuterRadius, *mylar) +
99 meanX0(kWireRadius + kEps, kOuterRadius - kWall - kEps, *gasMix) +
100 meanX0(0., kWireRadius, *tungsten);
101 if (std::abs(x0 - expected) > 1e-3 * expected) {
102 std::cout << "straw material " << x0 << " X0, expected " << expected
103 << std::endl;
104 }
105 check(std::abs(x0 - expected) < 1e-3 * expected,
106 "straw material is the mean path through wall, gas and wire");
107 // About 0.039% X0 of wall, 0.012% of gas and 0.001% of wire
108 check(x0 > 5.0e-4 && x0 < 5.5e-4, "straw material is about 5.3e-4 X0");
109 delete manager;
110}
111
112} // namespace
113
114int main() {
115 testStrawMaterial();
116 if (failures == 0) {
117 std::cout << "All ACTS straw geometry tests passed" << std::endl;
118 }
119 return failures == 0 ? 0 : 1;
120}