HighLAND
P0DGeometryManager.hxx
1 #ifndef SetupGeometry_H_Seen
2 #define SetupGeometry_H_Seen
3 
4 #include <ND280GeomId.hxx>
5 
6 #include <iostream>
7 #include <TVector3.h>
8 #include <map>
9 
10 /// Internal class. Find TGeoManager node ids associated with the
11 /// ND::TGeometryId objects.
13 public:
15  : fSP0Dule(-1), fP0Dule(-1), fLayer(-1), fBar(-1), fTarget(-1),
16  fECalRadiator(-1), fTargetRadiator(-1) {}
17 
19 
20  bool Search(const std::vector<std::string>& names, ND::TGeometryId& id) {
21  // Assign a geometry identifier to the full P0D.
22  if (names.size()<5) return false;
23  if (names[4].find("P0D_")==std::string::npos) return false;
24 
25 #ifdef DEBUG_P0DFinder
26  for (std::vector<std::string>::const_iterator s = names.begin();
27  s != names.end();
28  ++s) std::cout << " " << *s;
29  std::cout << std::endl;
30 #endif
31 
32  if (names.back().find("P0D_")!=std::string::npos) {
34  return true;
35  }
36 
37  // Assign the super-P0Dule number.
38  if (names.back().find("USECal_")!=std::string::npos) {
39  fSP0Dule = 0;
40  id = ND::GeomId::P0D::SuperP0Dule(fSP0Dule);
41  return true;
42  }
43  else if (names.back().find("USTarget_")!=std::string::npos) {
44  fSP0Dule = 1;
45  id = ND::GeomId::P0D::SuperP0Dule(fSP0Dule);
46  return true;
47  }
48  else if (names.back().find("CTarget_")!=std::string::npos) {
49  fSP0Dule = 2;
50  id = ND::GeomId::P0D::SuperP0Dule(fSP0Dule);
51  return true;
52  }
53  else if (names.back().find("CECal_")!=std::string::npos) {
54  fSP0Dule = 3;
55  id = ND::GeomId::P0D::SuperP0Dule(fSP0Dule);
56  return true;
57  }
58 
59  // Assign the p0dule number
60  if (names.back().find("P0Dule_")!=std::string::npos) {
61  ++fP0Dule;
62  fLayer = -1;
63  fBar = -1;
64  id = ND::GeomId::P0D::P0Dule(fP0Dule);
65  return true;
66  }
67 
68  // Assign the target.
69  if (names.back().find("Target_") == 0) {
70  ++fTarget;
71  id = ND::GeomId::P0D::Target(fTarget);
72  return true;
73  }
74 
75  // Assign the radiator.
76  if (names.back().find("Radiator_") !=std::string::npos) {
77  if (fSP0Dule == 0 || fSP0Dule==3) {
78  ++fECalRadiator;
79  id = ND::GeomId::P0D::ECalRadiator(fECalRadiator);
80  }
81  else {
82  ++fTargetRadiator;
83  id = ND::GeomId::P0D::TargetRadiator(fTargetRadiator);
84  }
85  return true;
86  }
87 
88  // Assign the layer
89  if (names.back().find("X_")!=std::string::npos) {
90  fLayer = 0;
91  fBar = -1;
92  return false;
93  }
94  else if (names.back().find("Y_")!=std::string::npos) {
95  fLayer = 1;
96  fBar = -1;
97  return false;
98  }
99 
100  if (names.back().find("Bar_")!=std::string::npos) {
101  id = ND::GeomId::P0D::Bar(fP0Dule, fLayer, ++fBar);
102  return true;
103  }
104 
105  return false;
106  }
107 
108 
109 private:
110  /// The current super-P0Dule
111  int fSP0Dule;
112 
113  /// The current p0dule within the super-P0Dule
114  int fP0Dule;
115 
116  /// The current layer within the p0dule
117  int fLayer;
118 
119  /// The current bar within the layer
120  int fBar;
121 
122  /// The current target.
123  int fTarget;
124 
125  /// The most recently seen radiator in the ECal.
126  int fECalRadiator;
127 
128  /// The most recently seen radiator in the target.
129  int fTargetRadiator;
130 };
131 
132 /// A class to update the local state when the input TFile
133 /// changes. This is added to the gBasicHeader_GeometryNotify vector.
135 public:
136  P0DGeometryManager() {gSetupGeometry_P0DFinder = NULL;Notify(); }
137 
138  /// Internal function. A routine to recurse through the TGeoManager geometry.
139  void SetupGeometryRecurseGeomId(std::vector<std::string>& names);
140 
141  /// Called when the geometry has changed.
142  Bool_t Notify();
143 
144  /// Translate a geometry id into a position. If the geometry id doesn't exist
145  /// in the P0D, then this returns a value that is beyond the boundary of the
146  /// observable universe.
147  TVector3 GeomIdPosition(int geomId);
148 
149 protected:
150 
151  /// Internal pointer. A pointer to the instantiation of the P0D geometry id
152  /// finder.
154 
155  /// Internal map. A map of the geometry nodes index by the TGeometryId
156  /// values.
157  std::map<ND::TGeometryId,int> gGeometrySetup_GeomIdMap;
158 
159  /// Internal map. A map of the TGeometryId values index by the geometry
160  /// node.
161  std::map<int,ND::TGeometryId> gGeometrySetup_RootIdMap;
162 
163 };
164 
165 #endif
166 
TGeometryId Bar(int p0dule, int layer, int bar)
std::map< ND::TGeometryId, int > gGeometrySetup_GeomIdMap
TGeometryId ECalRadiator(int radiator)
SetupGeometryP0DFinder * gSetupGeometry_P0DFinder
TGeometryId Target(int target)
TGeometryId TargetRadiator(int radiator)
std::map< int, ND::TGeometryId > gGeometrySetup_RootIdMap
TGeometryId SuperP0Dule(int sP0Dule)
TGeometryId Detector()
Define a geometry identifier to the entire P0D detector.
Definition: ND280GeomId.cxx:84
TGeometryId P0Dule(int p0dule)