Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
translation.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file translation.cxx
1 #include <vector>
2 
3 void init()
4 {
5  gSystem->Load("libGeom");
6  TGeoManager::Import("ALICE_ITS_tgeo.root");
7 }
8 
9 std::vector<TGeoNode*> path;
10 bool nodeFound = false;
11 void getNode(TString name)
12 {
13  nodeFound = false;
14  path.clear();
15 
16  dfs(gGeoManager->GetTopNode(), name);
17 
18  cout << "Node path: ";
19  for(int i = 0; i < path.size(); ++i)
20  {
21  cout << path[i]->GetName() << " ";
22  }
23  cout << endl;
24 }
25 
26 void dfs(TGeoNode* node, TString name)
27 {
28  //if(nodeFound) return;
29 
30  path.push_back(node);
31  if(node->GetName() == name)
32  {
33  nodeFound = true;
34  return;
35  }
36 
37  for(int i = 0; i < node->GetNdaughters(); ++i)
38  {
39  dfs(node->GetDaughter(i), name);
40  if(nodeFound) return;
41  }
42  path.pop_back();
43 }
44 
45 void translation(TString name, TString mothername = "")
46 {
47  //Get the node and path from world
48  getNode(name);
49 
50  //Get mother node index
51  int idx_mother = -1;
52  if(mothername == "")
53  {
54  idx_mother = 0;
55  }
56  else
57  {
58  for(int i = 0; i < path.size(); ++i)
59  {
60  if(path[i]->GetName() == mothername)
61  {
62  idx_mother = i;
63  break;
64  }
65  }
66  }
67 
68  //Get the transformation matrix level-by-level
69  TGeoHMatrix mat;
70  for(int i = idx_mother+1; i < path.size(); ++i)
71  {
72  mat *= (*path[i]->GetMatrix());
73  }
74 
75  cout << "Translation from " << name << " to " << mothername << endl;
76  mat.Print();
77 }