FairRoot/PandaRoot
Modify_root_geometry.C
Go to the documentation of this file.
1 // this is a root script to demonstrate
2 // alignment and navigation through root geometries
3 // A geometry is loaded from a roof file
4 // please modify the path to the root file
5 // according to your needs
6 // single methods can be operated easily out
7 // and placed somewhere else
8 // author: Promme (Promme@web.de)
9 
10 // run by calling
11 // root -l Modify_root_geometry.C+
12 
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 #include <sstream>
17 
18 using namespace std;
19 
20 
21 #include "TGeoManager.h"
22 
23 const string filename = "/home/jasinski/bin/pandaroot/geometry/Luminosity-Detector.root";
24 //const string filename = "/home/jasinski/bin/pandaroot/macro/lmd/test/mom_1_5/Lumi_Params_0.root";
25 
26 // load a geometry provided by the filename above
28  TGeoManager::Import(filename.c_str());
29  //gGeoManager->Draw("ogl"); <- keeps breaking when not done within the context of PandaROOT
30  return true;
31 }
32 
33 // actually this recursive call returns a list of paths to nodes
34 // in the loaded geometry
35 // if all_nodes == true then EVERY node is returned
36 void Get_List_of_Sensors(vector <string>& list_of_sensors, bool all_nodes = false, bool first_call = true){
37  if (first_call){
38  gGeoManager->CdTop();
39  first_call = false;
40  }
41  //cout << gGeoManager->GetPath() << " ";
42  string nodename(gGeoManager->GetCurrentNavigator()->GetCurrentNode()->GetName());
43  //cout << "current node is " << nodename << endl;
44  //if (nodename.compare(0, volumename_without_copynumber.size(), volumename_without_copynumber) == 0){ <<< here you can compare to a specific name in the volume to be selective to it
45  int nnodes = gGeoManager->GetCurrentNode()->GetNdaughters();
46  if (nnodes == 0 || all_nodes){ // a leave is reached when no daughter volumes are accessible anymore
47  //cout << " found a sensor " << nav_paths[7] << endl;
48  list_of_sensors.push_back(gGeoManager->GetPath());
49  }
50  for (int i = 0; i < nnodes; i++){
51  //cout << " navigating into node " << i << endl;
52  gGeoManager->CdDown(i);
53  Get_List_of_Sensors(list_of_sensors, all_nodes, first_call);
54  //if (nodename == nav_paths[1] || found_lmd){ <<< this is lmd search specific and not part of this spinout
55  // cout << " found the lmd node! Aborting recursive search. " << endl;
56  // gGeoManager->CdUp();
57  // break;
58  //}
59  gGeoManager->CdUp();
60  }
61  //if (nodename.compare(0, nav_paths[0].size(), nav_paths[0]) == 0){
62  // result = gGeoManager->GetPath();
63  // cout << " top volume is " << result << endl;
64  //}
65 }
66 
67 /*
68 // if aligned == false the original not aligned matrix will be returned
69 TGeoHMatrix* Get_matrix(string path, bool aligned = true){
70  TGeoHMatrix* result = NULL;
71  if (!gGeoManager->CheckPath(path.c_str())){
72  cout << " Error in Get_matrix: path " << path << " is not valid " << endl;
73  return result;
74  }
75  if (!aligned){ // try to obtain the original matrix, if available
76  TGeoPNEntry *pne;
77  //TGeoHMatrix *ide; // ideal
78  //TGeoHMatrix *mis; // misaligned
79  stringstream uname;
80  uname << "foo_" <<
81  pne = gGeoManager->GetAlignableEntry(uname.c_str());
82  if (pne){
83  TGeoPhysicalNode *node = pne->GetPhysicalNode();// new TGeoPhysicalNode(path.c_str());//
84  if (node){
85  result = new TGeoHMatrix(*node->GetOriginalMatrix());
86  //if (aligned) result = new TGeoHMatrix(*node->GetNode(node->GetLevel())->GetMatrix());
87  return result;
88  } else {
89  cout << " no node found in pn entry at " << path << endl;
90  cout << " obtaining default matrix " << endl;
91  }
92  } else {
93  cout << " no pn entry (alignable node) found in " << path << endl;
94  cout << " obtaining default matrix " << endl;
95  }
96  }
97  // I don't care if it was aligned or not, use the last one
98  gGeoManager->cd(path.c_str());
99  TGeoMatrix* matrix = gGeoManager->GetCurrentNode()->GetMatrix();
100  if (!matrix)
101  return NULL;
102  result = new TGeoHMatrix(*(matrix));
103  return result;
104 }*/
105 
106 bool Set_matrix(string path, TGeoHMatrix* matrix, string uniquename, int uniqueID){
107  if (!matrix) return false;
108  if (!gGeoManager->CheckPath(path.c_str())){
109  cout << " Error in PndLmdDim::Set_matrix: path " << path << " is not valid " << endl;
110  return false;
111  }
112  TGeoPNEntry *pne;
113  TGeoPhysicalNode *node;
114  pne = gGeoManager->GetAlignableEntry(uniquename.c_str());
115  if (!pne){
116  cout << " creating alignable entry for " << path << endl;
117  pne = gGeoManager->SetAlignableEntry(uniquename.c_str(), path.c_str(), uniqueID);
118  if (pne){
119  node = new TGeoPhysicalNode(path.c_str());
120  pne->SetPhysicalNode(node);
121  }
122  }
123  if (!pne) {
124  cout << " Error: no pn entry (alignable node) at " << path << " created " << endl;
125  return false;
126  }
127  node = pne->GetPhysicalNode();
128  if (!node) {
129  cout << " no node found for pn entry (alignable node) at " << path << endl;
130  return false;
131  }
132  return node->Align(matrix);
133 }
134 
136  Load_Geometry();
137  vector <string> list_of_sensors;
138  Get_List_of_Sensors(list_of_sensors, false);
139  int uID = 0;
140  for (int inode = 0; inode = list_of_sensors.size(); inode++){
141  cout << list_of_sensors[inode] << endl;
142  stringstream uname;
143 
144  }
145  return 0;
146 }
Int_t i
Definition: run_full.C:25
void Get_List_of_Sensors(vector< string > &list_of_sensors, bool all_nodes=false, bool first_call=true)
TGeoManager * gGeoManager
int Modify_root_geometry()
bool Load_Geometry()
bool Set_matrix(string path, TGeoHMatrix *matrix, string uniquename, int uniqueID)
const string filename