HighLAND
P0DGeometryManager.cxx
1 #include "P0DGeometryManager.hxx"
2 #include "TGeoNode.h"
3 #include "TGeoManager.h"
4 #include "TGeoVolume.h"
5 
6 //****************************************************************
7 void P0DGeometryManager::SetupGeometryRecurseGeomId(std::vector<std::string>& names) {
8 //****************************************************************
9 
10  if (!gSetupGeometry_P0DFinder) return;
11 
12  TGeoNode* node = gGeoManager->GetCurrentNode();
13  names.push_back(node->GetName());
14 
15  // Search with a particular finder. The finder will throw an
16  // EGeomIdStop exception when it doesn't want to search any further.
17  ND::TGeometryId id;
18  if (gSetupGeometry_P0DFinder->Search(names, id)) {
19 
20  int rootKey = gGeoManager->GetCurrentNodeId();
21 
22  std::map<ND::TGeometryId,int>::iterator g
23  = gGeometrySetup_GeomIdMap.find(id);
24  if (g != gGeometrySetup_GeomIdMap.end()) {
25  std::cout << "ERROR: Duplicate id: " << id << std::endl;;
26  }
27  gGeometrySetup_GeomIdMap[id] = rootKey;
28  gGeometrySetup_RootIdMap[rootKey] = id;
29  }
30 
31  // Recurse through all of the daughters.
32  for (int i=0; i<node->GetNdaughters(); ++i) {
33  gGeoManager->CdDown(i);
35  }
36 
37  // Pop this node off the "stack"
38  gGeoManager->CdUp();
39  names.pop_back();
40 }
41 
42 //****************************************************************
44 //****************************************************************
45 
46  if (!gGeoManager) return true;
47 
50 
51  // Make sure that the node id array has been initialized in the
52  // TGeoNodeCache.
53  if (!gGeoManager->GetCache()->HasIdArray()) {
54  gGeoManager->GetCache()->BuildIdArray();
55  }
56 
57  // Set the top volume.
58  TGeoVolume* top = gGeoManager->GetTopVolume();
59  std::string topName(top->GetName());
60  if (topName != "t2k") {
61  top = gGeoManager->GetVolume("t2k");
62  gGeoManager->SetTopVolume(top);
63  }
64 
65  // Clear the current geom id map.
68 
69  // Save the current geometry state.
70  gGeoManager->PushPath();
71  gGeoManager->CdTop();
72 
73  std::vector<std::string> names(20); names.clear();
75 
76  // Restore the state.
77  gGeoManager->PopPath();
78 
79  std::cout << "Geometry identifier map with "
80  << gGeometrySetup_GeomIdMap.size() << " entries."
81  << std::endl;;
82 
83  return true;
84 }
85 
86 //****************************************************************
87 TVector3 P0DGeometryManager::GeomIdPosition(int geomId) {
88 //****************************************************************
89 
90  std::map<ND::TGeometryId,int>::const_iterator pair = gGeometrySetup_GeomIdMap.find(geomId);
91  if (pair == gGeometrySetup_GeomIdMap.end()) {
92  return TVector3(9E+99,9E+99,9E+99);
93  }
94  int nodeId = pair->second;
95  gGeoManager->PushPath();
96  gGeoManager->CdNode(nodeId);
97  // Find the global position
98  double local[3] = {0,0,0};
99  double master[3] = {0,0,0};
100  gGeoManager->LocalToMaster(local,master);
101  gGeoManager->PopPath();
102  return TVector3(master[0],master[1],master[2]);
103 }
std::map< ND::TGeometryId, int > gGeometrySetup_GeomIdMap
Bool_t Notify()
Called when the geometry has changed.
void SetupGeometryRecurseGeomId(std::vector< std::string > &names)
Internal function. A routine to recurse through the TGeoManager geometry.
SetupGeometryP0DFinder * gSetupGeometry_P0DFinder
TVector3 GeomIdPosition(int geomId)
std::map< int, ND::TGeometryId > gGeometrySetup_RootIdMap