Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoParser.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoParser.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
14 
15 #include "RtypesCore.h"
16 #include "TCollection.h"
17 #include "TGeoBBox.h"
18 #include "TGeoNode.h"
19 #include "TGeoVolume.h"
20 #include "TObjArray.h"
21 #include "TObject.h"
22 
25  const TGeoMatrix& gmatrix) {
26  // Volume is present
27  if (state.volume != nullptr) {
28  std::string volumeName = state.volume->GetName();
29  // If you are on branch, you stay on branch
30  state.onBranch =
31  state.onBranch or
32  TGeoPrimitivesHelper::match(options.volumeNames, volumeName.c_str());
33  // Loop over the daughters and collect them
34  auto daughters = state.volume->GetNodes();
35  // Daughter node iteration
36  TIter iObj(daughters);
37  while (TObject* obj = iObj()) {
38  TGeoNode* node = dynamic_cast<TGeoNode*>(obj);
39  if (node != nullptr) {
40  state.volume = nullptr;
41  state.node = node;
42  select(state, options, gmatrix);
43  }
44  }
45  } else if (state.node != nullptr) {
46  // The node name for checking
47  std::string nodeName = state.node->GetName();
48  std::string nodeVolName = state.node->GetVolume()->GetName();
49  // Get the matrix of the current node for positioning
50  const TGeoMatrix* nmatrix = state.node->GetMatrix();
51  TGeoHMatrix transform = TGeoCombiTrans(gmatrix) * TGeoCombiTrans(*nmatrix);
52  std::string suffix = "_transform";
53  transform.SetName((nodeName + suffix).c_str());
54  // Check if you had found the target node
55  if (state.onBranch and
56  TGeoPrimitivesHelper::match(options.targetNames, nodeVolName.c_str())) {
57  // Get the placement and orientation in respect to its mother
58  const Double_t* rotation = transform.GetRotationMatrix();
59  const Double_t* translation = transform.GetTranslation();
60 
61  // Create a eigen transform
62  Vector3 t(options.unit * translation[0], options.unit * translation[1],
63  options.unit * translation[2]);
64  Vector3 cx(rotation[0], rotation[3], rotation[6]);
65  Vector3 cy(rotation[1], rotation[4], rotation[7]);
66  Vector3 cz(rotation[2], rotation[5], rotation[8]);
67  auto etrf = TGeoPrimitivesHelper::makeTransform(cx, cy, cz, t);
68 
69  bool accept = true;
70  if (not options.parseRanges.empty()) {
71  auto shape =
72  dynamic_cast<TGeoBBox*>(state.node->GetVolume()->GetShape());
73  // It uses the bounding box of TGeoBBox
74  // @TODO this should be replace by a proper TGeo to Acts::VolumeBounds
75  // and vertices converision which would make a more appropriate parsomg
76  double dx = options.unit * shape->GetDX();
77  double dy = options.unit * shape->GetDY();
78  double dz = options.unit * shape->GetDZ();
79  for (auto x : std::vector<double>{-dx, dx}) {
80  for (auto y : std::vector<double>{-dy, dy}) {
81  for (auto z : std::vector<double>{-dz, dz}) {
82  Vector3 edge = etrf * Vector3(x, y, z);
83  for (auto& check : options.parseRanges) {
84  double val = VectorHelpers::cast(edge, check.first);
85  if (val < check.second.first or val > check.second.second) {
86  accept = false;
87  break;
88  }
89  }
90  }
91  }
92  }
93  }
94  if (accept) {
95  state.selectedNodes.push_back(
96  {state.node, std::make_unique<TGeoHMatrix>(transform)});
97  }
98  state.node = nullptr;
99  } else {
100  // If it's not accepted, get the associated volume
101  state.volume = state.node->GetVolume();
102  state.node = nullptr;
103  // Set one further down
104  select(state, options, transform);
105  }
106  }
107  return;
108 }