14 #include "GeoModelHelpers/TransformToStringConverter.h"
18 #include <GaudiKernel/SystemOfUnits.h>
24 #include <TTreeReader.h>
50 unsigned int numTubes{0};
54 double tubeRadius{0.};
59 unsigned int layerNum{0};
61 unsigned int tubeNum{0};
69 double wireLength{0.};
71 double activeLength{0.};
73 std::vector<TubePositioning> tubeInfo{};
79 return idx < tubeInfo.size() ? tubeInfo[
idx] :
dummy;
82 unsigned int idx = (newTube.layerNum - 1)*numTubes + (newTube.tubeNum -1);
83 if (tubeInfo.size() <=
idx) tubeInfo.resize(
idx+1);
84 tubeInfo[
idx] = std::move(newTube);
92 static const std::map<int, std::string> stationDict{
93 {0,
"BIL"}, {1,
"BIS"}, {7,
"BIR"},
94 {2,
"BML"}, {3,
"BMS"}, {8,
"BMF"}, {53,
"BME"}, {54,
"BMG"}, {52,
"BIM"},
95 {4,
"BOL"}, {5,
"BOS"}, {9,
"BOF"}, {10,
"BOG"},
96 {6,
"BEE"}, {14,
"EEL"}, {15,
"EES"},
97 {13,
"EIL"}, {49,
"EIS"},
98 {17,
"EML"}, {18,
"EMS"},
99 {20,
"EOL"}, {21,
"EOS"}
107 #define TEST_BASICPROP(attribute, propName) \
108 if (std::abs(1.*test.attribute - 1.*reference.attribute) > tolerance) { \
109 std::cerr<<"runMdtGeoComparision() "<<__LINE__<<": "<<test \
110 <<" differs w.r.t "<<propName<<" "<< reference.attribute \
111 <<" (ref) vs. " <<test.attribute << " (test)" << std::endl; \
112 chamberOkay = false; \
115 #define TEST_TUBEPROP(attribute, propName) \
116 if (std::abs(1.*refTube.attribute - 1.*testTube.attribute) > tolerance) { \
117 std::cerr<<"runMdtGeoComparision() "<<__LINE__<<": In "<<test<<" the tubes (" \
118 <<layer<<","<<std::setfill('0')<<std::setw(3)<<tube<<")" \
119 <<" differ w.r.t "<<propName<<". " \
120 << refTube.attribute <<" (ref) vs. " <<testTube.attribute \
121 << " (test)" << std::endl; \
122 chamberOkay = false; \
126 std::set<MdtChamber> to_ret{};
127 std::cout<<
"Read the Mdt geometry tree dump from "<<
inputFile<<std::endl;
130 std::cerr<<__FILE__<<
":"<<__LINE__<<
" Failed to open "<<
inputFile<<std::endl;
135 std::cerr<<__FILE__<<
":"<<__LINE__<<
" The file "<<
inputFile<<
" does not contain the 'MdtGeoModelTree'"<<std::endl;
139 TTreeReaderValue<unsigned short> stationIndex{
treeReader,
"stationIndex"};
140 TTreeReaderValue<short> stationEta{
treeReader,
"stationEta"};
141 TTreeReaderValue<short> stationPhi{
treeReader,
"stationPhi"};
142 TTreeReaderValue<short> stationML{
treeReader,
"stationMultiLayer"};
143 TTreeReaderValue<std::string> chamberDesign{
treeReader,
"chamberDesign"};
145 TTreeReaderValue<double> tubeRadius{
treeReader,
"tubeRadius"};
146 TTreeReaderValue<double> tubePitch{
treeReader,
"tubePitch"};
147 TTreeReaderValue<unsigned short> numTubes{
treeReader,
"numTubes"};
150 TTreeReaderValue<std::vector<float>> geoModelTransformX{
treeReader,
"GeoModelTransformX"};
151 TTreeReaderValue<std::vector<float>> geoModelTransformY{
treeReader,
"GeoModelTransformY"};
152 TTreeReaderValue<std::vector<float>> geoModelTransformZ{
treeReader,
"GeoModelTransformZ"};
154 TTreeReaderValue<std::vector<float>> alignableNodeX{
treeReader,
"AlignableNodeX"};
155 TTreeReaderValue<std::vector<float>> alignableNodeY{
treeReader,
"AlignableNodeY"};
156 TTreeReaderValue<std::vector<float>> alignableNodeZ{
treeReader,
"AlignableNodeZ"};
160 TTreeReaderValue<std::vector<unsigned short>> tubeLayer{
treeReader,
"tubeLayer"};
161 TTreeReaderValue<std::vector<unsigned short>> tubeNumber{
treeReader,
"tubeNumber"};
164 TTreeReaderValue<std::vector<double>> activeTubeLength{
treeReader,
"activeTubeLength"};
165 TTreeReaderValue<std::vector<double>> wireLength{
treeReader,
"wireLength"};
167 TTreeReaderValue<std::vector<float>> tubeTransformTransX{
treeReader,
"tubeTransformTranslationX"};
168 TTreeReaderValue<std::vector<float>> tubeTransformTransY{
treeReader,
"tubeTransformTranslationY"};
169 TTreeReaderValue<std::vector<float>> tubeTransformTransZ{
treeReader,
"tubeTransformTranslationZ"};
171 TTreeReaderValue<std::vector<float>> tubeTransformCol0X{
treeReader,
"tubeTransformLinearCol1X"};
172 TTreeReaderValue<std::vector<float>> tubeTransformCol0Y{
treeReader,
"tubeTransformLinearCol1Y"};
173 TTreeReaderValue<std::vector<float>> tubeTransformCol0Z{
treeReader,
"tubeTransformLinearCol1Z"};
175 TTreeReaderValue<std::vector<float>> tubeTransformCol1X{
treeReader,
"tubeTransformLinearCol2X"};
176 TTreeReaderValue<std::vector<float>> tubeTransformCol1Y{
treeReader,
"tubeTransformLinearCol2Y"};
177 TTreeReaderValue<std::vector<float>> tubeTransformCol1Z{
treeReader,
"tubeTransformLinearCol2Z"};
179 TTreeReaderValue<std::vector<float>> tubeTransformCol2X{
treeReader,
"tubeTransformLinearCol3X"};
180 TTreeReaderValue<std::vector<float>> tubeTransformCol2Y{
treeReader,
"tubeTransformLinearCol3Y"};
181 TTreeReaderValue<std::vector<float>> tubeTransformCol2Z{
treeReader,
"tubeTransformLinearCol3Z"};
183 TTreeReaderValue<std::vector<float>> readOutPosX{
treeReader,
"readOutPosX"};
184 TTreeReaderValue<std::vector<float>> readOutPosY{
treeReader,
"readOutPosY"};
185 TTreeReaderValue<std::vector<float>> readOutPosZ{
treeReader,
"readOutPosZ"};
191 newchamber.id.eta = (*stationEta);
192 newchamber.id.phi = (*stationPhi);
193 newchamber.id.multilayer = (*stationML);
194 newchamber.design = (*chamberDesign);
196 newchamber.tubeRadius = (*tubeRadius);
197 newchamber.tubePitch = (*tubePitch);
199 newchamber.numTubes = (*numTubes);
200 newchamber.numLayers = (*numLayers);
203 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
204 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
205 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
206 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
209 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
210 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
211 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
212 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
217 for (
size_t t = 0;
t < tubeLayer->size(); ++
t){
219 TubePositioning newTube{};
221 newTube.tubeNum = (*tubeNumber)[
t];
222 newTube.tubeLength = (*tubeLength)[
t];
223 newTube.wireLength = (*wireLength)[
t];
225 tubeRot.col(0) =
Amg::Vector3D((*tubeTransformCol0X)[
t],(*tubeTransformCol0Y)[
t], (*tubeTransformCol0Z)[
t]);
226 tubeRot.col(1) =
Amg::Vector3D((*tubeTransformCol1X)[
t],(*tubeTransformCol1Y)[
t], (*tubeTransformCol1Z)[
t]);
227 tubeRot.col(2) =
Amg::Vector3D((*tubeTransformCol2X)[
t],(*tubeTransformCol2Y)[
t], (*tubeTransformCol2Z)[
t]);
228 Amg::Vector3D tubeTrans{(*tubeTransformTransX)[
t],(*tubeTransformTransY)[
t], (*tubeTransformTransZ)[
t]};
230 newTube.readoutPos =
Amg::Vector3D{(*readOutPosX)[
t],(*readOutPosY)[
t],(*readOutPosZ)[
t]};
231 newchamber.insertTube(std::move(newTube));
234 auto insert_itr = to_ret.insert(std::move(newchamber));
235 if (!insert_itr.second) {
236 std::stringstream
err{};
237 err<<__FILE__<<
":"<<__LINE__<<
" The chamber "<<(*insert_itr.first).
id
238 <<
" has already been inserted. "<<std::endl;
239 throw std::runtime_error(
err.str());
242 std::cout<<
"File parsing is finished. Found in total "<<to_ret.size()<<
" readout element dumps "<<std::endl;
250 std::string the_arg{
argv[
arg]};
251 if (the_arg ==
"--refFile" &&
arg +1 <
argc) {
252 refFile = std::string{
argv[
arg+1]};
254 }
else if (the_arg ==
"--testFile" &&
arg + 1 <
argc) {
259 if (refFile.empty()) {
260 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
264 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
271 std::set<MdtChamber> refChambers =
readTreeDump(refFile);
272 if (refChambers.empty()) {
273 std::cerr<<
"The file "<<refFile<<
" should contain at least one chamber "<<std::endl;
277 if (testChambers.empty()) {
278 std::cerr<<
"The file "<<
testFile<<
" should contain at least one chamber "<<std::endl;
281 int return_code = EXIT_SUCCESS;
284 std::set<MdtChamber>::const_iterator test_itr = testChambers.find(
reference);
286 if (test_itr == testChambers.end()) {
287 std::cerr<<
"The chamber "<<
reference<<
" is not part of the testing "<<std::endl;
288 return_code = EXIT_FAILURE;
291 bool chamberOkay =
true;
301 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": The alignable nodes are at differnt places for "
311 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": The chamber coordinate systems rotate differently for "
312 <<
reference<<
". Difference in the coordinate transformation: "
318 if (
false && distortion.translation().mag() >
tolerance) {
319 std::cout<<
"The origins of the chamber coordinate systems are not exactly at the same point for "
323 bool stagFailure{
false}, alignFailure{
false}, readoutOrient{
false};
329 const Amg::Transform3D tubeDistortion = testTube.localToGlobal.inverse() * refTube.localToGlobal;
333 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": In chamber "<<
reference<<
" the tube reference systems for ("<<
layer<<
", "
334 <<std::setfill(
'0')<<std::setw(3)<<
tube<<
") are not exactly aligned. "<<
Amg::toString(tubeDistortion)<<std::endl;
339 if (!stagFailure && tubeDistortion.translation().perp() >
tolerance) {
340 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": Misplaced staggering found in "<<
reference<<
" the tube ("<<
layer
341 <<
", "<<std::setfill(
'0')<<std::setw(3)<<
tube<<
") "
343 testTube.localToGlobal.translation(), 3)<<std::endl;
352 if (alignFailure || readoutOrient)
continue;
357 if (refRO.z()* testRO.z() < 0.){
358 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": The readout is on different sites for chamber: "<<
reference<<
359 ", layer "<<
layer<<
", tube: "<<std::setfill(
'0')<<std::setw(3)<<
tube<<
". "
361 readoutOrient =
true;
365 if (stagFailure || alignFailure) {
369 if (!chamberOkay) return_code = EXIT_FAILURE;
370 else std::cout<<
"runMdtGeoComparision() "<<__LINE__<<
": Found perfect agreement between new & old geometry for "<<
reference<<std::endl;
373 if (!refChambers.count(
test)) {
374 std::cerr<<
"runMdtGeoComparision() "<<__LINE__<<
": "<<
test<<
" is only in the test set."<<std::endl;
375 return_code = EXIT_FAILURE;