File indexing completed on 2025-08-05 08:10:21
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/TGeo/TGeoParser.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Plugins/TGeo/TGeoPrimitivesHelper.hpp"
0013 #include "Acts/Utilities/VectorHelpers.hpp"
0014
0015 #include "RtypesCore.h"
0016 #include "TCollection.h"
0017 #include "TGeoBBox.h"
0018 #include "TGeoNode.h"
0019 #include "TGeoVolume.h"
0020 #include "TObjArray.h"
0021 #include "TObject.h"
0022
0023 void Acts::TGeoParser::select(Acts::TGeoParser::State& state,
0024 const Acts::TGeoParser::Options& options,
0025 const TGeoMatrix& gmatrix) {
0026
0027 if (state.volume != nullptr) {
0028 std::string volumeName = state.volume->GetName();
0029
0030 state.onBranch =
0031 state.onBranch ||
0032 TGeoPrimitivesHelper::match(options.volumeNames, volumeName.c_str());
0033
0034 auto daughters = state.volume->GetNodes();
0035
0036 TIter iObj(daughters);
0037 while (TObject* obj = iObj()) {
0038 TGeoNode* node = dynamic_cast<TGeoNode*>(obj);
0039 if (node != nullptr) {
0040 state.volume = nullptr;
0041 state.node = node;
0042 select(state, options, gmatrix);
0043 }
0044 }
0045 } else if (state.node != nullptr) {
0046
0047 std::string nodeName = state.node->GetName();
0048 std::string nodeVolName = state.node->GetVolume()->GetName();
0049
0050 const TGeoMatrix* nmatrix = state.node->GetMatrix();
0051 TGeoHMatrix transform = TGeoCombiTrans(gmatrix) * TGeoCombiTrans(*nmatrix);
0052 std::string suffix = "_transform";
0053 transform.SetName((nodeName + suffix).c_str());
0054
0055 if (state.onBranch &&
0056 TGeoPrimitivesHelper::match(options.targetNames, nodeVolName.c_str())) {
0057
0058 const Double_t* rotation = transform.GetRotationMatrix();
0059 const Double_t* translation = transform.GetTranslation();
0060
0061
0062 Vector3 t(options.unit * translation[0], options.unit * translation[1],
0063 options.unit * translation[2]);
0064 Vector3 cx(rotation[0], rotation[3], rotation[6]);
0065 Vector3 cy(rotation[1], rotation[4], rotation[7]);
0066 Vector3 cz(rotation[2], rotation[5], rotation[8]);
0067 auto etrf = TGeoPrimitivesHelper::makeTransform(cx, cy, cz, t);
0068
0069 bool accept = true;
0070 if (!options.parseRanges.empty()) {
0071 auto shape =
0072 dynamic_cast<TGeoBBox*>(state.node->GetVolume()->GetShape());
0073
0074
0075
0076 double dx = options.unit * shape->GetDX();
0077 double dy = options.unit * shape->GetDY();
0078 double dz = options.unit * shape->GetDZ();
0079 for (auto x : std::vector<double>{-dx, dx}) {
0080 for (auto y : std::vector<double>{-dy, dy}) {
0081 for (auto z : std::vector<double>{-dz, dz}) {
0082 Vector3 edge = etrf * Vector3(x, y, z);
0083 for (auto& check : options.parseRanges) {
0084 double val = VectorHelpers::cast(edge, check.first);
0085 if (val < check.second.first || val > check.second.second) {
0086 accept = false;
0087 break;
0088 }
0089 }
0090 }
0091 }
0092 }
0093 }
0094 if (accept) {
0095 state.selectedNodes.push_back(
0096 {state.node, std::make_unique<TGeoHMatrix>(transform)});
0097 }
0098 state.node = nullptr;
0099 } else {
0100
0101 state.volume = state.node->GetVolume();
0102 state.node = nullptr;
0103
0104 select(state, options, transform);
0105 }
0106 }
0107 return;
0108 }