ATLAS Offline Software
Loading...
Searching...
No Matches
runActsGeoComparison.cxx File Reference
#include <GeoPrimitives/GeoPrimitivesHelpers.h>
#include <GeoPrimitives/GeoPrimitivesToStringConverter.h>
#include <ActsGeometryInterfaces/IDetectorElement.h>
#include <Identifier/Identifier.h>
#include "Acts/Surfaces/SurfaceBounds.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/Definitions/Tolerance.hpp"
#include <PathResolver/PathResolver.h>
#include <TFile.h>
#include <TTreeReader.h>
#include <set>

Go to the source code of this file.

Classes

struct  ActiveSensor

Functions

std::set< ActiveSensorreadTreeDump (const std::string &inputFile)
int main1 (int argc, char **argv)
int main (int argc, char **argv)

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 230 of file runActsGeoComparison.cxx.

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}
int main1()
Definition testRead.cxx:68

◆ main1()

int main1 ( int argc,
char ** argv )

check whether the files are xroot d -> otherwise call path resovler

Parse the tree dump

Start to loop over the chambers

We do not care whether the orientation of the coordinate system along the wire flips for negative chambers or not

The ultimate goal is to have the tube positioned at the same place. We maybe need the origin position later when we are adding the alignable transforms...

Definition at line 122 of file runActsGeoComparison.cxx.

122 {
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}
static std::string FindCalibFile(const std::string &logical_file_name)
std::string to_string(const DetectorType &type)
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
bool doesNotDeform(const Amg::Transform3D &trans)
Checks whether the linear part of the transformation rotates or stetches any of the basis vectors.
Eigen::Affine3d Transform3D
std::set< ActiveSensor > readTreeDump(const std::string &inputFile)

◆ readTreeDump()

std::set< ActiveSensor > readTreeDump ( const std::string & inputFile)

Definition at line 75 of file runActsGeoComparison.cxx.

75 {
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}
DetectorType
Simple enum to Identify the Type of the ACTS sub detector.
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Amg::Transform3D getTransformFromRotTransl(Amg::RotationMatrix3D rot, Amg::Vector3D transl_vec)
Eigen::Matrix< double, 3, 1 > Vector3D
str inFile
Definition makeTOC.py:5
Identifier id
Identifier of the sensor.
std::vector< double > boundaryValues
Defining properties of the boundary.
DetectorType detType
Technology type of the sensor.
double thickness
sensor thickness
Amg::Transform3D transform
Transform of the sensor.
Acts::SurfaceBounds::BoundsType BoundsType
Boundary type.