FairRoot/PandaRoot
PndHypGeoHandling.cxx
Go to the documentation of this file.
1 //
2 // C++ Implementation: PndGeoHandling
3 //
4 // Description:
5 //
6 //
7 // Author: t.stockmanns <stockman@ikp455>, (C) 2007
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #include "PndHypGeoHandling.h"
13 #include "PndStringVector.h"
14 #include <vector>
15 #include <string>
16 #include "PndStringVector.h"
17 #include "TROOT.h"
18 #include "TGeoManager.h"
19 #include "TGeoMatrix.h"
20 #include <math.h>
21 #include "TGeoShape.h"
22 #include "TGeoBBox.h"
23 #include "stdlib.h"
24 
26 
28 {
29  if (gROOT->FindObjectAny("FAIRGeom") == 0){
30  std::cout << " -E- PndHypGeoHandling: No Geometry existing!" << std::endl;
31  return;
32  }
34 }
35 
37 {
38  if (gROOT->FindObjectAny("FAIRGeom") == 0){
39  fGeoMan = new TGeoManager("geoMan","geoMan");
40  fGeoMan->Import(fileName.Data());
41  }
43 }
44 
46 {
47  Int_t level;
48  Int_t copyNr[100];
49  Int_t volNr[100];
50  TString result;
51 
52  level = fGeoMan->GetLevel();
53  level++;
54 
55  fGeoMan->GetBranchNumbers(copyNr, volNr);
56  for (int i=0; i<level; i++){
57  result += volNr[i];
58  result += "_";
59  result += copyNr[i];
60  result += "/";
61  }
62  return result;
63 }
64 
66 {
67  TString result;
68  TString currentPath = fGeoMan->GetPath();
69  fGeoMan->cd(path.Data());
70  result = GetCurrentID();
71  fGeoMan->cd(currentPath.Data());
72  return result;
73 }
74 
75 
77 {
78  TString result;
79  std::vector<std::string> idVector;
80  PndStringVector pathAna(id.Data(), "/_");
81  idVector = pathAna.GetStringVector();
82 
83  for(Int_t i = 0; i < (int)idVector.size(); i+=2){
84  result += "/";
85  Int_t VolId = atoi(idVector[i].c_str());
86  Int_t CopyNr = atoi(idVector[i+1].c_str());
87  result += fGeoMan->GetVolume(VolId)->GetName();
88  result += "_";
89  result += CopyNr;
90  }
91  return result;
92 }
93 
95 {
96  return fGeoMan->cd(GetPath(id).Data());
97 }
98 
100 {
101  TString result;
102  TGeoVolume* vol = fGeoMan->FindVolumeFast(name);
103  if (vol == 0)
104  return result;
105  result += vol->GetNumber();
106  return result;
107 }
108 
109 std::vector<TString> PndHypGeoHandling::GetNamesLevel(Int_t level, TString startPath, bool ) // fullPath //[R.K.03/2017] unused variable(s)
110 {
111  TString actPath = fGeoMan->GetPath();
112  fLevelNames.clear();
113 
114  if (startPath == ""){
115  fGeoMan->CdTop();
116  fLevel = level;
117  }
118  else{
119  if (fGeoMan->cd(startPath.Data())== 0)
120  return fLevelNames;
121  else {
122  fLevel = fGeoMan->GetLevel() + level;
123  }
124  }
125  FillLevelNames();
126  return fLevelNames;
127 }
128 
130 {
131  TGeoNode* myNode = fGeoMan->GetCurrentNode();
132  if (fLevel == fGeoMan->GetLevel()){
133  if (fFullPath)
134  fLevelNames.push_back(fGeoMan->GetPath());
135  else
136  fLevelNames.push_back(myNode->GetName());
137  }
138  else {
139  Int_t nDaughters = myNode->GetNdaughters();
140  for (Int_t i = 0; i < nDaughters; i++){
141  fGeoMan->CdDown(i);
142  FillLevelNames();
143  fGeoMan->CdUp();
144  }
145  }
146 }
147 
148 void PndHypGeoHandling::GetOUVPath(TString path, TVector3& o, TVector3& u, TVector3& v)
149 {
150  Double_t result[3];
151  Double_t* temp;
152  TString actPath = fGeoMan->GetPath();
153  fGeoMan->cd(path);
154 
155  TGeoHMatrix* currMatrix = fGeoMan->GetCurrentMatrix();
156  temp = currMatrix->GetTranslation();
157  o.SetXYZ(temp[0], temp[1], temp[2]);
158 
159  temp[0] = 1;
160  temp[1] = 0;
161  temp[2] = 0;
162  fGeoMan->LocalToMasterVect(temp, result);
163  u.SetXYZ(result[0], result[1], result[2]);
164 
165  temp[0] = 0;
166  temp[1] = 1;
167  temp[2] = 0;
168  fGeoMan->LocalToMasterVect(temp, result);
169  v.SetXYZ(result[0], result[1], result[2]);
170  if(actPath!="" && actPath!=" ") fGeoMan->cd(actPath);
171 }
172 
173 void PndHypGeoHandling::GetOUVId(TString id, TVector3& o, TVector3& u, TVector3& v)
174 {
175  GetOUVPath(GetPath(id),o,u,v);
176 }
177 
178 
180 {
181  TVector3 dim;
182  TString actPath = fGeoMan->GetPath();
183  fGeoMan->cd(path);
184 
185  TGeoVolume* actVolume = gGeoManager->GetCurrentVolume();
186  TGeoBBox* actBox = (TGeoBBox*)(actVolume->GetShape());
187  dim.SetX(actBox->GetDX());
188  dim.SetY(actBox->GetDY());
189  dim.SetZ(actBox->GetDZ());
190 
191  if(actPath!="" && actPath!=" ") fGeoMan->cd(actPath);
192  return dim;
193 }
194 
195 
197 {
198  return GetSensorDimensionsPath(GetPath(id));
199 }
200 
201 // ----- conversions of POINTS (not vectors) here -----
202 TVector3 PndHypGeoHandling::MasterToLocalId(const TVector3& master, const TString& id)
203 { return MasterToLocalPath(master, GetPath(id) ); }
204 
205 TVector3 PndHypGeoHandling::MasterToLocalPath(const TVector3& master, const TString& path)
206 {
207  // if(fVerbose>1) std::cout<<" -I- PndHypGeoHandling::MasterToLocalPath"<<std::endl;
208  Double_t result[3];
209  Double_t temp[3];
210 
211  temp[0] = master.X();
212  temp[1] = master.Y();
213  temp[2] = master.Z();
214 
215  TString actPath = fGeoMan->GetPath();
216  fGeoMan->cd(path);
217  fGeoMan->MasterToLocal(temp, result);
218  // fGeoMan->cd(actPath);
219  if(actPath != "" && actPath != " ") fGeoMan->cd(actPath);
220  return TVector3(result[0],result[1],result[2]);
221 }
222 
223 
224 
225 TVector3 PndHypGeoHandling::LocalToMasterId(const TVector3& local, const TString& id)
226 { return LocalToMasterPath(local, GetPath(id) ); }
227 
228 TVector3 PndHypGeoHandling::LocalToMasterPath(const TVector3& local, const TString& path)
229 {
230  Double_t result[3];
231  Double_t temp[3];
232 
233  temp[0] = local.X();
234  temp[1] = local.Y();
235  temp[2] = local.Z();
236 
237  TString actPath = fGeoMan->GetPath();
238  fGeoMan->cd(path);
239  fGeoMan->LocalToMaster(temp, result);
240  fGeoMan->cd(actPath);
241  if(actPath != "" && actPath != " ") fGeoMan->cd(actPath);
242  return TVector3(result[0],result[1],result[2]);
243 }
244 
245 
246 // ROTATION of error values, CAUTION - these are always psitive defined
247 TVector3 PndHypGeoHandling::MasterToLocalErrorsId(const TVector3& master, const TString& id)
248 { return MasterToLocalErrorsPath(master, GetPath(id) ); }
249 
250 TVector3 PndHypGeoHandling::MasterToLocalErrorsPath(const TVector3& master, const TString& path)
251 {
252  Double_t result[3];
253  Double_t temp[3];
254  TString actPath = fGeoMan->GetPath();
255  fGeoMan->cd(path);
256 
257 
258  temp[0] = master.X();
259  temp[1] = master.Y();
260  temp[2] = master.Z();
261 
262  // rotate "error vector"
263  fGeoMan->MasterToLocalVect(temp,result);
264  // positive error values
265  for(Int_t i=0;i<3;i++) result[i]=fabs(result[i]);
266 
267 
268 
269  if(actPath != "" && actPath != " ") fGeoMan->cd(actPath);
270  return TVector3(result[0],result[1],result[2]);
271 
272 
273 }
274 
275 
276 
277 TVector3 PndHypGeoHandling::LocalToMasterErrorsId(const TVector3& local, const TString& id)
278 { return LocalToMasterErrorsPath(local, GetPath(id) ); }
279 
280 TVector3 PndHypGeoHandling::LocalToMasterErrorsPath(const TVector3& local, const TString& path)
281 {
282  Double_t result[3];
283  Double_t tmp[3];
284  TString actPath = fGeoMan->GetPath();
285  fGeoMan->cd(path);
286 
287 
288  tmp[0] = local.X();
289  tmp[1] = local.Y();
290  tmp[2] = local.Z();
291 
292  // rotate "error vector"
293  fGeoMan->LocalToMasterVect(tmp,result);
294  // positive error values
295  for(Int_t i=0;i<3;i++) result[i]=fabs(result[i]);
296 
297  if(actPath != "" && actPath != " ") fGeoMan->cd(actPath);
298  return TVector3(result[0],result[1],result[2]);
299 
300 }
301 
TVector3 LocalToMasterId(const TVector3 &local, const TString &id)
Int_t i
Definition: run_full.C:25
void GetOUVPath(TString path, TVector3 &o, TVector3 &u, TVector3 &v)
for a volume given by its path the o, u, v vectors for the plane are returned
TVector3 GetSensorDimensionsID(TString id)
Bool_t cd(TString id)
as the cd command of TGeoManager just with the ID
TVector3 MasterToLocalErrorsPath(const TVector3 &master, const TString &id)
TString GetVolumeID(TString name)
returns the volume ID for a given volume name
std::vector< std::string > GetStringVector(void)
void GetOUVId(TString id, TVector3 &o, TVector3 &u, TVector3 &v)
for a volume given by its ID the o, u, v vectors for the plane are returned
Class to access the naming information of the MVD.
TGeoManager * gGeoManager
__m128 v
Definition: P4_F32vec4.h:4
TVector3 GetSensorDimensionsPath(TString path)
TVector3 MasterToLocalErrorsId(const TVector3 &master, const TString &id)
std::vector< TString > GetNamesLevel(Int_t level, TString startPath="", bool fullPath=false)
TString GetPath(TString id)
for a given ID the path is returned
Double_t
std::vector< TString > fLevelNames
TString GetCurrentID()
returns the ID of the current node
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TVector3 MasterToLocalPath(const TVector3 &master, const TString &id)
void FillLevelNames()
fills vector&lt;TString&gt; fLevelNames with the names (or the paths) of the volumes down to the level give...
TString name
TString GetID(TString path)
for a given TGeoManager-path the ID is returned
TVector3 LocalToMasterErrorsPath(const TVector3 &local, const TString &id)
TVector3 MasterToLocalId(const TVector3 &master, const TString &id)
ClassImp(PndAnaContFact)
TVector3 LocalToMasterErrorsId(const TVector3 &local, const TString &id)
TGeoManager * fGeoMan
TVector3 LocalToMasterPath(const TVector3 &local, const TString &id)