158 std::set<TgcChamber> to_ret{};
159 std::cout<<
"Read the Tgc geometry tree dump from "<<inputFile<<std::endl;
160 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
161 if (!inFile || !inFile->IsOpen()) {
162 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": Failed to open "<<inputFile<<std::endl;
165 TTreeReader treeReader(
"TgcGeoModelTree", inFile.get());
166 if (treeReader.IsInvalid()) {
167 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The file "<<inputFile<<
" does not contain the 'TgcGeoModelTree'"<<std::endl;
171 TTreeReaderValue<unsigned short> stationIndex{treeReader,
"stationIndex"};
172 TTreeReaderValue<short> stationEta{treeReader,
"stationEta"};
173 TTreeReaderValue<short> stationPhi{treeReader,
"stationPhi"};
174 TTreeReaderValue<std::string> stationDesign{treeReader,
"stationDesign"};
175 TTreeReaderValue<uint8_t> nGasGaps{treeReader,
"nGasGaps"};
177 TTreeReaderValue<float> shortWidth{treeReader,
"ChamberWidthS"};
178 TTreeReaderValue<float> longWidth{treeReader,
"ChamberWidthL"};
179 TTreeReaderValue<float> height{treeReader,
"ChamberHeight"};
180 TTreeReaderValue<float> thickness{treeReader,
"ChamberThickness"};
182 TTreeReaderValue<std::vector<float>> geoModelTransformX{treeReader,
"GeoModelTransformX"};
183 TTreeReaderValue<std::vector<float>> geoModelTransformY{treeReader,
"GeoModelTransformY"};
184 TTreeReaderValue<std::vector<float>> geoModelTransformZ{treeReader,
"GeoModelTransformZ"};
186 TTreeReaderValue<std::vector<float>> alignableNodeX{treeReader,
"AlignableNodeX"};
187 TTreeReaderValue<std::vector<float>> alignableNodeY{treeReader,
"AlignableNodeY"};
188 TTreeReaderValue<std::vector<float>> alignableNodeZ{treeReader,
"AlignableNodeZ"};
191 TTreeReaderValue<std::vector<float>> gangCenterX{treeReader,
"gangCenterX"};
192 TTreeReaderValue<std::vector<float>> gangCenterY{treeReader,
"gangCenterY"};
193 TTreeReaderValue<std::vector<float>> gangCenterZ{treeReader,
"gangCenterZ"};
195 TTreeReaderValue<std::vector<float>> gangLocalPosX{treeReader,
"gangLocalPosX"};
196 TTreeReaderValue<std::vector<float>> gangLocalPosY{treeReader,
"gangLocalPosY"};
199 TTreeReaderValue<std::vector<float>> stripCenterX{treeReader,
"stripCenterX"};
200 TTreeReaderValue<std::vector<float>> stripCenterY{treeReader,
"stripCenterY"};
201 TTreeReaderValue<std::vector<float>> stripCenterZ{treeReader,
"stripCenterZ"};
203 TTreeReaderValue<std::vector<float>> stripBottomX{treeReader,
"stripBottomX"};
204 TTreeReaderValue<std::vector<float>> stripBottomY{treeReader,
"stripBottomY"};
205 TTreeReaderValue<std::vector<float>> stripBottomZ{treeReader,
"stripBottomZ"};
207 TTreeReaderValue<std::vector<float>> stripTopX{treeReader,
"stripTopX"};
208 TTreeReaderValue<std::vector<float>> stripTopY{treeReader,
"stripTopY"};
209 TTreeReaderValue<std::vector<float>> stripTopZ{treeReader,
"stripTopZ"};
211 TTreeReaderValue<std::vector<float>> stripLocalCenterX{treeReader,
"stripLocalCenterX"};
212 TTreeReaderValue<std::vector<float>> stripLocalCenterY{treeReader,
"stripLocalCenterY"};
213 TTreeReaderValue<std::vector<float>> stripLocalBottomX{treeReader,
"stripLocalBottomX"};
214 TTreeReaderValue<std::vector<float>> stripLocalBottomY{treeReader,
"stripLocalBottomY"};
215 TTreeReaderValue<std::vector<float>> stripLocalTopX{treeReader,
"stripLocalTopX"};
216 TTreeReaderValue<std::vector<float>> stripLocalTopY{treeReader,
"stripLocalTopY"};
218 TTreeReaderValue<std::vector<uint8_t>> stripGasGap{treeReader,
"stripGasGap"};
219 TTreeReaderValue<std::vector<unsigned int>> stripNum{treeReader,
"stripNumber"};
222 TTreeReaderValue<std::vector<uint8_t>> gangGasGap{treeReader,
"gangGasGap"};
223 TTreeReaderValue<std::vector<unsigned int>> gangNum{treeReader,
"gangNumber"};
224 TTreeReaderValue<std::vector<uint8_t>> gangNumWires{treeReader,
"gangNumWires"};
225 TTreeReaderValue<std::vector<float>> gangLength{treeReader,
"gangLength"};
227 TTreeReaderValue<std::vector<float>> layerCol0Theta{treeReader,
"layerLinearCol0Theta"};
228 TTreeReaderValue<std::vector<float>> layerCol0Phi{treeReader,
"layerLinearCol0Phi"};
230 TTreeReaderValue<std::vector<float>> layerCol1Theta{treeReader,
"layerLinearCol1Theta"};
231 TTreeReaderValue<std::vector<float>> layerCol1Phi{treeReader,
"layerLinearCol1Phi"};
233 TTreeReaderValue<std::vector<float>> layerCol2Theta{treeReader,
"layerLinearCol2Theta"};
234 TTreeReaderValue<std::vector<float>> layerCol2Phi{treeReader,
"layerLinearCol2Phi"};
236 TTreeReaderValue<std::vector<float>> layerTransX{treeReader,
"layerTranslationX"};
237 TTreeReaderValue<std::vector<float>> layerTransY{treeReader,
"layerTranslationY"};
238 TTreeReaderValue<std::vector<float>> layerTransZ{treeReader,
"layerTranslationZ"};
240 TTreeReaderValue<std::vector<bool>> layerMeasPhi{treeReader,
"layerMeasPhi"};
241 TTreeReaderValue<std::vector<uint8_t>> layerNumber{treeReader,
"layerNumber"};
243 TTreeReaderValue<std::vector<float>> layShortWidth{treeReader,
"layerWidthS"};
244 TTreeReaderValue<std::vector<float>> layLongWidth{treeReader,
"layerWidthL"};
245 TTreeReaderValue<std::vector<float>> layHeight{treeReader,
"layerHeight"};
246 TTreeReaderValue<std::vector<uint16_t>> layerNumWires{treeReader,
"layerNumWires"};
248 while (treeReader.Next()) {
251 newchamber.
stIdx = (*stationIndex);
252 newchamber.
eta = (*stationEta);
253 newchamber.
phi = (*stationPhi);
254 newchamber.
techName = (*stationDesign);
257 newchamber.
height = (*height);
260 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
262 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
263 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
264 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
267 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
268 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
269 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
270 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
274 for (
size_t g = 0; g < gangGasGap->size(); ++g) {
276 newGang.
gasGap = (*gangGasGap)[g];
277 newGang.
number = (*gangNum)[g];
278 newGang.
numWires =(*gangNumWires)[g];
281 newGang.
length = (*gangLength)[g];
282 auto insert_itr = newchamber.
etaWires.insert(std::move(newGang));
283 if (!insert_itr.second) {
284 std::stringstream err{};
285 err<<
"runTgcComparison() "<<__LINE__<<
": The wire "<<(*insert_itr.first)
286 <<
" has already been inserted. "<<std::endl;
287 throw std::runtime_error(err.str());
291 for (
size_t s = 0; s < stripNum->size(); ++s) {
294 strip.number = (*stripNum) [s];
296 strip.globCenter =
Amg::Vector3D{(*stripCenterX)[s], (*stripCenterY)[s], (*stripCenterZ)[s]};
299 strip.globBottom =
Amg::Vector3D{(*stripBottomX)[s], (*stripBottomY)[s], (*stripBottomZ)[s]};
305 auto insert_itr = newchamber.
strips.insert(std::move(
strip));
306 if (!insert_itr.second) {
307 std::stringstream err{};
308 err<<
"runTgcComparison() "<<__LINE__<<
": The strip "<<(*insert_itr.first)
309 <<
" has already been inserted. "<<std::endl;
310 throw std::runtime_error(err.str());
313 for (
size_t l = 0 ; l < layerMeasPhi->size(); ++l) {
315 layRot.col(0) =
makeDir((*layerCol0Theta)[l], (*layerCol0Phi)[l]);
316 layRot.col(1) =
makeDir((*layerCol1Theta)[l], (*layerCol1Phi)[l]);
317 layRot.col(2) =
makeDir((*layerCol2Theta)[l], (*layerCol2Phi)[l]);
318 Amg::Vector3D trans{(*layerTransX)[l],(*layerTransY)[l],(*layerTransZ)[l]};
321 layTrans.
gasGap = (*layerNumber)[l];
322 layTrans.
measPhi = (*layerMeasPhi)[l];
325 layTrans.
height = (*layHeight)[l];
326 layTrans.
numWires = (*layerNumWires)[l];
327 auto insert_itr = newchamber.
transforms.insert(std::move(layTrans));
328 if (!insert_itr.second) {
329 std::stringstream err{};
330 err<<
"runTgcComparison() "<<__LINE__<<
": The layer transformation "<<(*insert_itr.first)
331 <<
" has already been inserted. "<<std::endl;
332 throw std::runtime_error(err.str());
336 auto insert_itr = to_ret.insert(std::move(newchamber));
337 if (!insert_itr.second) {
338 std::stringstream err{};
339 err<<
"runTgcComparison() "<<__LINE__<<
": The chamber "<<(*insert_itr.first)
340 <<
" has already been inserted. "<<std::endl;
341 throw std::runtime_error(err.str());
366 std::string refFile{}, testFile{};
368 for (
int arg = 1; arg < argc; ++arg) {
369 std::string the_arg{argv[arg]};
370 if (the_arg ==
"--refFile" && arg +1 < argc) {
371 refFile = std::string{argv[arg+1]};
373 }
else if (the_arg ==
"--testFile" && arg + 1 < argc) {
374 testFile = std::string{argv[arg+1]};
378 if (refFile.empty()) {
379 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
382 if (testFile.empty()) {
383 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
390 const std::set<TgcChamber> refChambers =
readTreeDump(refFile);
391 if (refChambers.empty()) {
392 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": No chambers in reference file."<<std::endl;
395 const std::set<TgcChamber> testChambers =
readTreeDump(testFile);
396 if (testChambers.empty()) {
397 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": No chambers in test file."<<std::endl;
401 int retCode{EXIT_SUCCESS};
403 std::set<TgcChamber>::const_iterator test_itr = testChambers.find(
ref);
404 if (test_itr == testChambers.end()) {
405 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The chamber "<<
ref<<
" is not in the test geometry. "<<std::endl;
406 retCode = EXIT_FAILURE;
418 const Amg::Transform3D alignableDistort = test.alignableTransform.inverse()*(
ref.alignableTransform );
420 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The alignable nodes are at differnt places for "
421 <<
ref<<
". " <<GeoTrf::toString(alignableDistort,
true)<<std::endl;
428 std::set<TgcChamber::LayerTrans>::const_iterator l_test_itr = test.transforms.find(refTrans);
429 if (l_test_itr == test.transforms.end()) {
430 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The layer "<<refTrans
431 <<
" in chamber "<<
ref <<
" is not part of the test geometry. "<<std::endl;
439 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<refTrans
440 <<
", the transformations are orientated diffrently "<<
Amg::toString(layTest)<<std::endl;
444 if (layTest.translation().mag() >
tolerance) {
445 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The transformations in layer "<<refTrans<<
", "
446 <<
ref<<
" are pointing to different reference points "<<
Amg::toString(layTest.translation(),2)<<std::endl;
455 if (!chambOk)
continue;
457 std::set<TgcChamber::RadialStrip>::const_iterator s_test_itr = test.strips.find(refStrip);
458 if (s_test_itr == test.strips.end()) {
459 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In chamber "<<
ref
460 <<
" "<<refStrip<<
" is not part of the test geometry. "<<std::endl;
466 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
", "
474 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref
481 retCode = EXIT_FAILURE;
486 std::set<TgcChamber::WireGang>::const_iterator test_itr = test.etaWires.find(refGang);
487 if (test_itr == test.etaWires.end()) {
488 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": "<<refGang<<
" is not part of "
490 retCode = EXIT_FAILURE;
495 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": "<<refGang<<
" in "<<
ref
496 <<
" has different wires. "<<refGang.
numWires<<
" vs. "
502 constexpr double halfPitch = 0.9 * Gaudi::Units::mm;
503 if (lDiffPos.mag() - halfPitch >
tolerance) {
504 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang
507 <<
", mag="<<lDiffPos.mag()
508 <<
" "<<lDiffPos.mag() / 1.8 <<std::endl;
515 if (diffPos.mag() - halfPitch >
tolerance) {
516 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang
517 <<
" is displaced by "<<
Amg::toString(diffPos, 2)<<
", mag="<<diffPos.mag()<<std::endl;
523 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang<<
" different length detected "
524 <<refGang.
length<<
" (ref) vs. "<<testGang.
length<<
" (test). Delta: "
530 retCode = EXIT_FAILURE;
532 std::cout<<
"runTgcComparison() "<<__LINE__<<
": Agreement between ref & test for "<<
ref<<std::endl;