ATLAS Offline Software
Loading...
Searching...
No Matches
runActsGeoComparison.cxx
Go to the documentation of this file.
1
2/*
3 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
4*/
14
15
17
18#include <Identifier/Identifier.h>
19
20#include "Acts/Surfaces/SurfaceBounds.hpp"
21#include "Acts/Definitions/Units.hpp"
22#include "Acts/Definitions/Tolerance.hpp"
23
25#include <TFile.h>
26#include <TTreeReader.h>
27
28#include <set>
29
30namespace {
31 template <typename T> std::ostream& operator<<(std::ostream& ostr, const std::vector<T>& v) {
32 if (v.empty()) {
33 return ostr;
34 }
35 ostr<<"[";
36 for (std::size_t i =0 ; i < v.size() ; ++i) {
37 ostr<<v[i];
38 if (i +1 != v.size()){
39 ostr<<", ";
40 }
41 }
42 ostr<<"]";
43 return ostr;
44 }
45}
46
47using namespace ActsTrk;
48using namespace Acts::UnitLiterals;
55 Amg::Transform3D transform{Amg::Transform3D::Identity()};
57 double thickness{0.};
59 using BoundsType = Acts::SurfaceBounds::BoundsType;
60
61 BoundsType boundType{BoundsType::eOther};
63 std::vector<double> boundaryValues{};
65 bool operator<(const ActiveSensor& other) const {
66 return other.id < id;
67 }
68 friend std::ostream& operator<<(std::ostream& ostr, const ActiveSensor& sensor) {
69 ostr<<"Id: "<<sensor.id.get_compact()<<", type: "<<to_string(sensor.detType)
70 <<", bounds ("<<sensor.boundType<<") "<<sensor.boundaryValues;
71 return ostr;
72 }
73};
74
75std::set<ActiveSensor> readTreeDump(const std::string& inputFile) {
76 std::set<ActiveSensor> to_ret{};
77 std::cout<<"Read the Acts geometry dump from "<<inputFile<<std::endl;
78 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
79 if (!inFile || !inFile->IsOpen()) {
80 std::cerr<<__FILE__<<":"<<__LINE__<<" Failed to open "<<inputFile<<std::endl;
81 return to_ret;
82 }
83 TTreeReader treeReader("ReadoutGeometryTest", inFile.get());
84 if (treeReader.IsInvalid()){
85 std::cerr<<__FILE__<<":"<<__LINE__<<" The file "<<inputFile<<" does not contain the 'ReadoutGeometryTest'"<<std::endl;
86 return to_ret;
87 }
88
89 TTreeReaderValue<Identifier::value_type> identifier{treeReader, "identifier"};
90 TTreeReaderValue<std::uint8_t> detectorType{treeReader, "detectorType"};
91 TTreeReaderValue<std::uint8_t> boundType{treeReader, "boundType"};
92
93 TTreeReaderValue<std::vector<float>> geoModelTransformX{treeReader, "GeoModelTransformX"};
94 TTreeReaderValue<std::vector<float>> geoModelTransformY{treeReader, "GeoModelTransformY"};
95 TTreeReaderValue<std::vector<float>> geoModelTransformZ{treeReader, "GeoModelTransformZ"};
96
97 TTreeReaderValue<std::vector<double>> boundValues{treeReader, "boundValues"};
98 TTreeReaderValue<double> thickness{treeReader, "thickness"};
99
100 while (treeReader.Next()) {
101 ActiveSensor newElement{};
102
103 newElement.id = (*identifier);
104 newElement.detType = static_cast<DetectorType>(*detectorType);
105 newElement.boundType = static_cast<ActiveSensor::BoundsType>(*detectorType);
106 newElement.boundaryValues = (*boundValues);
107 newElement.thickness = (*thickness);
108
109 Amg::RotationMatrix3D geoRot{Amg::RotationMatrix3D::Identity()};
110 geoRot.col(0) = Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
111 geoRot.col(1) = Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
112 geoRot.col(2) = Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
113 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
114 newElement.transform = Amg::getTransformFromRotTransl(std::move(geoRot), std::move(geoTrans));
115
116 to_ret.insert(newElement);
117 }
118 std::cout<<"File parsing is finished. Found in total "<<to_ret.size()<<" readout element dumps "<<std::endl;
119 return to_ret;
120}
121
122int main1( int argc, char** argv ) {
123 std::string refFile{}, testFile{};
124
125 for (int arg = 1; arg < argc; ++arg) {
126 std::string the_arg{argv[arg]};
127 if (the_arg == "--refFile" && arg +1 < argc) {
128 refFile = std::string{argv[arg+1]};
129 ++arg;
130 } else if (the_arg == "--testFile" && arg + 1 < argc) {
131 testFile = std::string{argv[arg+1]};
132 ++arg;
133 }
134 }
135 if (refFile.empty()) {
136 std::cerr<<"Please parse the path of the reference file via --refFile "<<std::endl;
137 return EXIT_FAILURE;
138 }
139 if (testFile.empty()) {
140 std::cerr<<"Please parse the path of the test file via --testFile "<<std::endl;
141 return EXIT_FAILURE;
142 }
144 if (!refFile.starts_with( "root://")) refFile = PathResolver::FindCalibFile(refFile);
145 if (!testFile.starts_with( "root://")) testFile = PathResolver::FindCalibFile(testFile);
147 std::set<ActiveSensor> refSensors = readTreeDump(refFile);
148 if (refSensors.empty()) {
149 std::cerr<<"The file "<<refFile<<" should contain at least one chamber "<<std::endl;
150 return EXIT_FAILURE;
151 }
152 std::set<ActiveSensor> testSensors = readTreeDump(testFile);
153 if (testSensors.empty()) {
154 std::cerr<<"The file "<<testFile<<" should contain at least one chamber "<<std::endl;
155 return EXIT_FAILURE;
156 }
157 int return_code = EXIT_SUCCESS;
158 unsigned int goodSensors{0};
160 for (const ActiveSensor& reference : refSensors) {
161 std::set<ActiveSensor>::const_iterator test_itr = testSensors.find(reference);
162 if (test_itr == testSensors.end()) {
163 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": The chamber "<<reference
164 <<" is not part of the testing "<<std::endl;
165 return_code = EXIT_FAILURE;
166 continue;
167 }
168 bool sensorOkay = true;
169 const ActiveSensor& test = {*test_itr};
170
171
172 if (test.detType != reference.detType) {
173 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": The detector element types are different for "<<reference<<" test: "<<to_string(test.detType)<<std::endl;
174 sensorOkay = false;
175 }
176
177 if (test.boundType != reference.boundType) {
178 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": The bound types are different for "<<reference<<" test: "<<test.boundType<<std::endl;
179 sensorOkay = false;
180 } else {
181 for (std::size_t b = 0; b < test.boundaryValues.size(); ++b) {
182 if (std::abs(reference.boundaryValues[b] - test.boundaryValues[b]) > Acts::s_epsilon) {
183 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": The bounds are different for "
184 <<reference<<" & test: "<<test.boundaryValues<<std::endl;
185 sensorOkay = false;
186 }
187 }
188 }
189 if (std::abs(test.thickness - reference.thickness) > Acts::s_epsilon) {
190 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": "<<reference
191 <<" has different thickness w.r.t the test "
192 <<reference.thickness<<" vs. "<< test.thickness<<std::endl;
193 sensorOkay = false;
194 }
195 const Amg::Transform3D distortion = test.transform.inverse() * reference.transform;
198 if (!Amg::doesNotDeform(distortion)) {
199 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": The chamber coordinate systems rotate differently for "
200 <<reference<<". Difference in the coordinate transformation: "<<Amg::toString(distortion)
201 <<" --- refTrf: "<<Amg::toString(reference.transform)
202 <<" --- testTrf: "<<Amg::toString(test.transform)<<std::endl;
203 sensorOkay = false;
204 }
207 if (distortion.translation().mag() > Acts::s_onSurfaceTolerance ) {
208 std::cout<<"runActsGeoComparison() "<<__LINE__
209 <<": The origins of the chamber coordinate systems are not exactly at the same point for "
210 <<reference<<". Translation shift: "<<Amg::toString(distortion.translation(), 2)<<std::endl;
211 sensorOkay = false;
212 }
213 if (sensorOkay){
214 ++goodSensors;
215 }
216 }
217 for (const ActiveSensor& test : testSensors) {
218 if (!refSensors.count(test)) {
219 std::cerr<<"runActsGeoComparison() "<<__LINE__<<": "<<test<<" is only in the test set."<<std::endl;
220 return_code = EXIT_FAILURE;
221 }
222 }
223 std::cout<<"runActsGeoComparison() "<<__LINE__<<": "<<goodSensors<<"/"<<refSensors.size()
224 <<" sensors are in perfect agreement. "<<std::endl;
225 return return_code;
226
227}
228
229
230int main (int argc, char** argv )
231{
232 int ret = 1;
233 try {
234 ret = main1 (argc, argv);
235 }
236 catch (const std::exception& e) {
237 std::cerr << e.what() << "\n";
238 }
239 return ret;
240}
241
value_type get_compact() const
Get the compact id.
static std::string FindCalibFile(const std::string &logical_file_name)
int main()
Definition hello.cxx:18
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::string to_string(const DetectorType &type)
MsgStream & operator<<(MsgStream &out, const ActsUtils::Stat &stat)
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
@ UnDefined
Small Thing Gap chambers (NSW)
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
bool doesNotDeform(const Amg::Transform3D &trans)
Checks whether the linear part of the transformation rotates or stetches any of the basis vectors.
Amg::Transform3D getTransformFromRotTransl(Amg::RotationMatrix3D rot, Amg::Vector3D transl_vec)
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
std::set< ActiveSensor > readTreeDump(const std::string &inputFile)
Identifier id
Identifier of the sensor.
std::vector< double > boundaryValues
Defining properties of the boundary.
DetectorType detType
Technology type of the sensor.
bool operator<(const ActiveSensor &other) const
Ordering operator.
double thickness
sensor thickness
Amg::Transform3D transform
Transform of the sensor.
Acts::SurfaceBounds::BoundsType BoundsType
Boundary type.
friend std::ostream & operator<<(std::ostream &ostr, const ActiveSensor &sensor)
int main1()
Definition testRead.cxx:68