FairShip
Loading...
Searching...
No Matches
test_timedet_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#include <cmath>
6#include <iostream>
7
8#include "FairGeoInterface.h"
9#include "FairGeoLoader.h"
10#include "TGeoManager.h"
11#include "TGeoMaterial.h"
12#include "TGeoMedium.h"
13#include "TGeoNode.h"
14#include "TGeoVolume.h"
15#include "TimeDet.h"
16#include "TimeDetPoint.h"
17
18namespace {
19
20bool close(double lhs, double rhs, double tolerance = 1e-9) {
21 return std::abs(lhs - rhs) < tolerance;
22}
23
24bool check_close(const char* name, double actual, double expected) {
25 if (close(actual, expected)) return true;
26 std::cerr << name << ": expected " << expected << ", got " << actual
27 << std::endl;
28 return false;
29}
30
31} // namespace
32
33int main() {
34 TimeDet time_det("TimeDet", true);
35
36 bool ok = true;
37 ok &= time_det.GetNColumns() == 3;
38 ok &= time_det.GetNRows() == 110;
39 ok &= time_det.GetNBars() == 330;
40
41 ok &= check_close("bar size X", time_det.GetBarSizeX(), 140.0);
42 ok &= check_close("bar size Y", time_det.GetBarSizeY(), 6.0);
43 ok &= check_close("bar size Z", time_det.GetBarSizeZ(), 1.0);
44 ok &= check_close("bar overlap X", time_det.GetBarOverlapX(), 10.0);
45 ok &= check_close("bar overlap Y", time_det.GetBarOverlapY(), 0.55);
46
47 ok &= check_close("column 0 X", time_det.GetXCol(0), -130.0);
48 ok &= check_close("column 1 X", time_det.GetXCol(1), 0.0);
49 ok &= check_close("column 2 X", time_det.GetXCol(2), 130.0);
50 ok &= check_close(
51 "column overlap X",
52 time_det.GetBarSizeX() - (time_det.GetXCol(1) - time_det.GetXCol(0)),
53 10.0);
54
55 ok &= check_close("row 0 Y", time_det.GetYRow(0), -297.025);
56 ok &= check_close("row 109 Y", time_det.GetYRow(109), 297.025);
57 ok &= check_close("row pitch Y", time_det.GetYRow(1) - time_det.GetYRow(0),
58 5.45);
59 ok &= check_close(
60 "row overlap Y",
61 time_det.GetBarSizeY() - (time_det.GetYRow(1) - time_det.GetYRow(0)),
62 0.55);
63 ok &= check_close("covered height Y",
64 (time_det.GetYRow(109) + time_det.GetBarSizeY() / 2.0) -
65 (time_det.GetYRow(0) - time_det.GetBarSizeY() / 2.0),
66 600.05);
67
68 ok &= check_close("Z col0 row0", time_det.GetZBar(0, 0), 0.0);
69 ok &= check_close("Z col0 row1", time_det.GetZBar(1, 0), 1.2);
70 ok &= check_close("Z col1 row0", time_det.GetZBar(0, 1), 9.0);
71 ok &= check_close("Z col1 row1", time_det.GetZBar(1, 1), 10.2);
72
73 int row = -1;
74 int col = -1;
75 time_det.GetBarRowCol(329, row, col);
76 ok &= row == 109;
77 ok &= col == 2;
78
79 FairGeoLoader geo_loader("TGeo", "FairGeoLoader");
80 auto* geo_interface = geo_loader.getGeoInterface();
81 geo_interface->setMediaFile("geometry/media.geo");
82 if (!geo_interface->readMedia()) {
83 std::cerr << "Could not load geometry/media.geo" << std::endl;
84 return 1;
85 }
86
87 TGeoManager* geometry = gGeoManager;
88 auto* material = new TGeoMaterial("WorldMaterial", 14.7, 7.3, 0.0012);
89 auto* medium = new TGeoMedium("WorldMedium", 1, material);
90 auto* top = geometry->MakeBox("World", medium, 1000.0, 1000.0, 1000.0);
91 geometry->SetTopVolume(top);
92
93 time_det.ConstructGeometry();
94
95 TGeoNode* detector_node = top->GetNode(0);
96 if (detector_node == nullptr) {
97 std::cerr << "Timing Detector assembly was not placed in the world"
98 << std::endl;
99 return 1;
100 }
101
102 TGeoVolume* detector_volume = detector_node->GetVolume();
103 if (detector_volume == nullptr || detector_volume->GetNodes() == nullptr) {
104 std::cerr << "Timing Detector assembly has no bar placements" << std::endl;
105 return 1;
106 }
107
108 const int number_of_placements =
109 detector_volume->GetNodes()->GetEntriesFast();
110 if (number_of_placements != time_det.GetNBars()) {
111 std::cerr << "Expected " << time_det.GetNBars() << " bars, got "
112 << number_of_placements << std::endl;
113 return 1;
114 }
115
116 if (!ok) return 1;
117
118 std::cout << "Timing detector geometry matches ShipSoft/Geometry: "
119 << "3 columns x 110 rows, 1400 x 60 x 10 mm bars, "
120 << "5.5 mm vertical overlap, and " << number_of_placements
121 << " placements" << std::endl;
122 return 0;
123}
Int_t GetNColumns() const
Definition TimeDet.h:45
Double_t GetBarSizeY() const
Definition TimeDet.h:49
void GetBarRowCol(int ib, int &irow, int &icol) const
Definition TimeDet.cxx:181
double GetXCol(int ic) const
Definition TimeDet.cxx:187
Int_t GetNRows() const
Definition TimeDet.h:46
Double_t GetBarOverlapY() const
Definition TimeDet.h:52
Double_t GetBarOverlapX() const
Definition TimeDet.h:51
Double_t GetBarSizeZ() const
Definition TimeDet.h:50
Double_t GetBarSizeX() const
Definition TimeDet.h:48
void ConstructGeometry() override
Definition TimeDet.cxx:144
double GetZBar(int ir, int ic) const
Definition TimeDet.cxx:195
Int_t GetNBars() const
Definition TimeDet.h:47
double GetYRow(int ir) const
Definition TimeDet.cxx:191