150 std::set<TgcChamber> to_ret{};
151 std::cout<<
"Read the Tgc geometry tree dump from "<<inputFile<<std::endl;
152 std::unique_ptr<TFile> inFile{TFile::Open(inputFile.c_str())};
153 if (!inFile || !inFile->IsOpen()) {
154 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": Failed to open "<<inputFile<<std::endl;
157 TTreeReader treeReader(
"TgcGeoModelTree", inFile.get());
158 if (treeReader.IsInvalid()) {
159 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The file "<<inputFile<<
" does not contain the 'TgcGeoModelTree'"<<std::endl;
163 TTreeReaderValue<unsigned short> stationIndex{treeReader,
"stationIndex"};
164 TTreeReaderValue<short> stationEta{treeReader,
"stationEta"};
165 TTreeReaderValue<short> stationPhi{treeReader,
"stationPhi"};
166 TTreeReaderValue<std::string> stationDesign{treeReader,
"stationDesign"};
167 TTreeReaderValue<uint8_t> nGasGaps{treeReader,
"nGasGaps"};
169 TTreeReaderValue<float> shortWidth{treeReader,
"ChamberWidthS"};
170 TTreeReaderValue<float> longWidth{treeReader,
"ChamberWidthL"};
171 TTreeReaderValue<float> height{treeReader,
"ChamberHeight"};
172 TTreeReaderValue<float> thickness{treeReader,
"ChamberThickness"};
174 TTreeReaderValue<std::vector<float>> geoModelTransformX{treeReader,
"GeoModelTransformX"};
175 TTreeReaderValue<std::vector<float>> geoModelTransformY{treeReader,
"GeoModelTransformY"};
176 TTreeReaderValue<std::vector<float>> geoModelTransformZ{treeReader,
"GeoModelTransformZ"};
178 TTreeReaderValue<std::vector<float>> alignableNodeX{treeReader,
"AlignableNodeX"};
179 TTreeReaderValue<std::vector<float>> alignableNodeY{treeReader,
"AlignableNodeY"};
180 TTreeReaderValue<std::vector<float>> alignableNodeZ{treeReader,
"AlignableNodeZ"};
183 TTreeReaderValue<std::vector<float>> gangCenterX{treeReader,
"gangCenterX"};
184 TTreeReaderValue<std::vector<float>> gangCenterY{treeReader,
"gangCenterY"};
185 TTreeReaderValue<std::vector<float>> gangCenterZ{treeReader,
"gangCenterZ"};
187 TTreeReaderValue<std::vector<float>> gangLocalPosX{treeReader,
"gangLocalPosX"};
188 TTreeReaderValue<std::vector<float>> gangLocalPosY{treeReader,
"gangLocalPosY"};
191 TTreeReaderValue<std::vector<float>> stripCenterX{treeReader,
"stripCenterX"};
192 TTreeReaderValue<std::vector<float>> stripCenterY{treeReader,
"stripCenterY"};
193 TTreeReaderValue<std::vector<float>> stripCenterZ{treeReader,
"stripCenterZ"};
195 TTreeReaderValue<std::vector<float>> stripBottomX{treeReader,
"stripBottomX"};
196 TTreeReaderValue<std::vector<float>> stripBottomY{treeReader,
"stripBottomY"};
197 TTreeReaderValue<std::vector<float>> stripBottomZ{treeReader,
"stripBottomZ"};
199 TTreeReaderValue<std::vector<float>> stripTopX{treeReader,
"stripTopX"};
200 TTreeReaderValue<std::vector<float>> stripTopY{treeReader,
"stripTopY"};
201 TTreeReaderValue<std::vector<float>> stripTopZ{treeReader,
"stripTopZ"};
203 TTreeReaderValue<std::vector<float>> stripLocalCenterX{treeReader,
"stripLocalCenterX"};
204 TTreeReaderValue<std::vector<float>> stripLocalCenterY{treeReader,
"stripLocalCenterY"};
205 TTreeReaderValue<std::vector<float>> stripLocalBottomX{treeReader,
"stripLocalBottomX"};
206 TTreeReaderValue<std::vector<float>> stripLocalBottomY{treeReader,
"stripLocalBottomY"};
207 TTreeReaderValue<std::vector<float>> stripLocalTopX{treeReader,
"stripLocalTopX"};
208 TTreeReaderValue<std::vector<float>> stripLocalTopY{treeReader,
"stripLocalTopY"};
210 TTreeReaderValue<std::vector<uint8_t>> stripGasGap{treeReader,
"stripGasGap"};
211 TTreeReaderValue<std::vector<unsigned int>> stripNum{treeReader,
"stripNumber"};
214 TTreeReaderValue<std::vector<uint8_t>> gangGasGap{treeReader,
"gangGasGap"};
215 TTreeReaderValue<std::vector<unsigned int>> gangNum{treeReader,
"gangNumber"};
216 TTreeReaderValue<std::vector<uint8_t>> gangNumWires{treeReader,
"gangNumWires"};
217 TTreeReaderValue<std::vector<float>> gangLength{treeReader,
"gangLength"};
219 TTreeReaderValue<std::vector<float>> layerCol1X{treeReader,
"layerLinearCol1X"};
220 TTreeReaderValue<std::vector<float>> layerCol1Y{treeReader,
"layerLinearCol1Y"};
221 TTreeReaderValue<std::vector<float>> layerCol1Z{treeReader,
"layerLinearCol1Z"};
223 TTreeReaderValue<std::vector<float>> layerCol2X{treeReader,
"layerLinearCol2X"};
224 TTreeReaderValue<std::vector<float>> layerCol2Y{treeReader,
"layerLinearCol2Y"};
225 TTreeReaderValue<std::vector<float>> layerCol2Z{treeReader,
"layerLinearCol2Z"};
227 TTreeReaderValue<std::vector<float>> layerCol3X{treeReader,
"layerLinearCol3X"};
228 TTreeReaderValue<std::vector<float>> layerCol3Y{treeReader,
"layerLinearCol3Y"};
229 TTreeReaderValue<std::vector<float>> layerCol3Z{treeReader,
"layerLinearCol3Z"};
231 TTreeReaderValue<std::vector<float>> layerTransX{treeReader,
"layerTranslationX"};
232 TTreeReaderValue<std::vector<float>> layerTransY{treeReader,
"layerTranslationY"};
233 TTreeReaderValue<std::vector<float>> layerTransZ{treeReader,
"layerTranslationZ"};
235 TTreeReaderValue<std::vector<bool>> layerMeasPhi{treeReader,
"layerMeasPhi"};
236 TTreeReaderValue<std::vector<uint8_t>> layerNumber{treeReader,
"layerNumber"};
238 TTreeReaderValue<std::vector<float>> layShortWidth{treeReader,
"layerWidthS"};
239 TTreeReaderValue<std::vector<float>> layLongWidth{treeReader,
"layerWidthL"};
240 TTreeReaderValue<std::vector<float>> layHeight{treeReader,
"layerHeight"};
241 TTreeReaderValue<std::vector<uint16_t>> layerNumWires{treeReader,
"layerNumWires"};
243 while (treeReader.Next()) {
246 newchamber.
stIdx = (*stationIndex);
247 newchamber.
eta = (*stationEta);
248 newchamber.
phi = (*stationPhi);
249 newchamber.
techName = (*stationDesign);
252 newchamber.
height = (*height);
255 Amg::Vector3D geoTrans{(*geoModelTransformX)[0], (*geoModelTransformY)[0], (*geoModelTransformZ)[0]};
257 geoRot.col(0) =
Amg::Vector3D((*geoModelTransformX)[1], (*geoModelTransformY)[1], (*geoModelTransformZ)[1]);
258 geoRot.col(1) =
Amg::Vector3D((*geoModelTransformX)[2], (*geoModelTransformY)[2], (*geoModelTransformZ)[2]);
259 geoRot.col(2) =
Amg::Vector3D((*geoModelTransformX)[3], (*geoModelTransformY)[3], (*geoModelTransformZ)[3]);
262 geoRot.col(0) =
Amg::Vector3D((*alignableNodeX)[1], (*alignableNodeY)[1], (*alignableNodeZ)[1]);
263 geoRot.col(1) =
Amg::Vector3D((*alignableNodeX)[2], (*alignableNodeY)[2], (*alignableNodeZ)[2]);
264 geoRot.col(2) =
Amg::Vector3D((*alignableNodeX)[3], (*alignableNodeY)[3], (*alignableNodeZ)[3]);
265 geoTrans =
Amg::Vector3D{(*alignableNodeX)[0], (*alignableNodeY)[0], (*alignableNodeZ)[0]};
269 for (
size_t g = 0; g < gangGasGap->size(); ++g) {
271 newGang.
gasGap = (*gangGasGap)[g];
272 newGang.
number = (*gangNum)[g];
273 newGang.
numWires =(*gangNumWires)[g];
276 newGang.
length = (*gangLength)[g];
277 auto insert_itr = newchamber.
etaWires.insert(std::move(newGang));
278 if (!insert_itr.second) {
279 std::stringstream err{};
280 err<<
"runTgcComparison() "<<__LINE__<<
": The wire "<<(*insert_itr.first)
281 <<
" has already been inserted. "<<std::endl;
282 throw std::runtime_error(err.str());
286 for (
size_t s = 0; s < stripNum->size(); ++s) {
288 strip.gasGap = (*stripGasGap)[s];
289 strip.number = (*stripNum) [s];
291 strip.globCenter =
Amg::Vector3D{(*stripCenterX)[s], (*stripCenterY)[s], (*stripCenterZ)[s]};
294 strip.globBottom =
Amg::Vector3D{(*stripBottomX)[s], (*stripBottomY)[s], (*stripBottomZ)[s]};
300 auto insert_itr = newchamber.
strips.insert(std::move(
strip));
301 if (!insert_itr.second) {
302 std::stringstream err{};
303 err<<
"runTgcComparison() "<<__LINE__<<
": The strip "<<(*insert_itr.first)
304 <<
" has already been inserted. "<<std::endl;
305 throw std::runtime_error(err.str());
308 for (
size_t l = 0 ; l < layerMeasPhi->size(); ++l) {
310 layRot.col(0) =
Amg::Vector3D{(*layerCol1X)[l], (*layerCol1Y)[l], (*layerCol1Z)[l]};
311 layRot.col(1) =
Amg::Vector3D{(*layerCol2X)[l], (*layerCol2Y)[l], (*layerCol2Z)[l]};
312 layRot.col(2) =
Amg::Vector3D{(*layerCol3X)[l], (*layerCol3Y)[l], (*layerCol3Z)[l]};
313 Amg::Vector3D trans{(*layerTransX)[l],(*layerTransY)[l],(*layerTransZ)[l]};
316 layTrans.
gasGap = (*layerNumber)[l];
317 layTrans.
measPhi = (*layerMeasPhi)[l];
320 layTrans.
height = (*layHeight)[l];
321 layTrans.
numWires = (*layerNumWires)[l];
322 auto insert_itr = newchamber.
transforms.insert(std::move(layTrans));
323 if (!insert_itr.second) {
324 std::stringstream err{};
325 err<<
"runTgcComparison() "<<__LINE__<<
": The layer transformation "<<(*insert_itr.first)
326 <<
" has already been inserted. "<<std::endl;
327 throw std::runtime_error(err.str());
331 auto insert_itr = to_ret.insert(std::move(newchamber));
332 if (!insert_itr.second) {
333 std::stringstream err{};
334 err<<
"runTgcComparison() "<<__LINE__<<
": The chamber "<<(*insert_itr.first)
335 <<
" has already been inserted. "<<std::endl;
336 throw std::runtime_error(err.str());
360int main(
int argc,
char** argv ) {
361 std::string refFile{}, testFile{};
363 for (
int arg = 1; arg < argc; ++arg) {
364 std::string the_arg{argv[arg]};
365 if (the_arg ==
"--refFile" && arg +1 < argc) {
366 refFile = std::string{argv[arg+1]};
368 }
else if (the_arg ==
"--testFile" && arg + 1 < argc) {
369 testFile = std::string{argv[arg+1]};
373 if (refFile.empty()) {
374 std::cerr<<
"Please parse the path of the reference file via --refFile "<<std::endl;
377 if (testFile.empty()) {
378 std::cerr<<
"Please parse the path of the test file via --testFile "<<std::endl;
385 const std::set<TgcChamber> refChambers =
readTreeDump(refFile);
386 if (refChambers.empty()) {
387 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": No chambers in reference file."<<std::endl;
390 const std::set<TgcChamber> testChambers =
readTreeDump(testFile);
391 if (testChambers.empty()) {
392 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": No chambers in test file."<<std::endl;
396 int retCode{EXIT_SUCCESS};
398 std::set<TgcChamber>::const_iterator test_itr = testChambers.find(
ref);
399 if (test_itr == testChambers.end()) {
400 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The chamber "<<
ref<<
" is not in the test geometry. "<<std::endl;
401 retCode = EXIT_FAILURE;
413 const Amg::Transform3D alignableDistort = test.alignableTransform.inverse()*(
ref.alignableTransform );
415 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The alignable nodes are at differnt places for "
416 <<
ref<<
". " <<GeoTrf::toString(alignableDistort,
true)<<std::endl;
423 std::set<TgcChamber::LayerTrans>::const_iterator l_test_itr = test.transforms.find(refTrans);
424 if (l_test_itr == test.transforms.end()) {
425 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The layer "<<refTrans
426 <<
" in chamber "<<
ref <<
" is not part of the test geometry. "<<std::endl;
434 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<refTrans
435 <<
", the transformations are orientated diffrently "<<
Amg::toString(layTest)<<std::endl;
439 if (layTest.translation().mag() >
tolerance) {
440 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": The transformations in layer "<<refTrans<<
", "
441 <<
ref<<
" are pointing to different reference points "<<
Amg::toString(layTest.translation(),2)<<std::endl;
450 if (!chambOk)
continue;
452 std::set<TgcChamber::RadialStrip>::const_iterator s_test_itr = test.strips.find(refStrip);
453 if (s_test_itr == test.strips.end()) {
454 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In chamber "<<
ref
455 <<
" "<<refStrip<<
" is not part of the test geometry. "<<std::endl;
461 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
", "
469 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref
476 retCode = EXIT_FAILURE;
481 std::set<TgcChamber::WireGang>::const_iterator test_itr = test.etaWires.find(refGang);
482 if (test_itr == test.etaWires.end()) {
483 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": "<<refGang<<
" is not part of "
485 retCode = EXIT_FAILURE;
490 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": "<<refGang<<
" in "<<
ref
491 <<
" has different wires. "<<refGang.
numWires<<
" vs. "
497 constexpr double halfPitch = 0.9 * Gaudi::Units::mm;
498 if (lDiffPos.mag() - halfPitch >
tolerance) {
499 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang
502 <<
", mag="<<lDiffPos.mag()
503 <<
" "<<lDiffPos.mag() / 1.8 <<std::endl;
510 if (diffPos.mag() - halfPitch >
tolerance) {
511 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang
512 <<
" is displaced by "<<
Amg::toString(diffPos, 2)<<
", mag="<<diffPos.mag()<<std::endl;
518 std::cerr<<
"runTgcComparison() "<<__LINE__<<
": In "<<
ref<<
" "<<testGang<<
" different length detected "
519 <<refGang.
length<<
" (ref) vs. "<<testGang.
length<<
" (test). Delta: "
525 retCode = EXIT_FAILURE;
527 std::cout<<
"runTgcComparison() "<<__LINE__<<
": Agreement between ref & test for "<<
ref<<std::endl;