EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoNode.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoNode.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 10/11/2003
3 //*---Modified: 21/06/2005 D.Bertini
4 
6 // FairGeoNode
7 //
8 // Class to hold the basic geometry properties of a GEANT volume
9 //
11 
12 #include "FairGeoNode.h"
13 
14 #include "TList.h"
15 #include <cmath>
16 using std::cout;
17 using std::endl;
18 
20 
22  : FairGeoVolume(),
23  active(kFALSE),
24  center(FairGeoTransform()),
25  volumeType(kFairGeoElement),
26  created(kFALSE),
27  copyNode(NULL),
28  rootVolume(NULL),
29  pShape(0),
30  pMother(NULL),
31  medium(NULL),
32  labTransform(NULL),
33  fDaughterList(new TObjArray(5)),
34  fTruncName("")
35 {
36  // Constructor
37  clear();
38 
39 }
40 
42  :FairGeoVolume(r),
43  active(kFALSE),
44  center(r.getCenterPosition()),
45  volumeType(r.getVolumeType()),
46  created(kFALSE),
47  copyNode(r.getCopyNode()),
48  rootVolume(r.getRootVolume()),
49  pShape(NULL),
50  pMother(NULL),
51  medium(NULL),
52  labTransform(new FairGeoTransform(*(r.getLabTransform()))),
53  fDaughterList(new TObjArray(*(r.GetListOfDaughters()))),
54  fTruncName(r.getTruncName())
55 {
56  // Copy constructor
57  points=0;
58  nPoints = 0;
59  fName=r.GetName();
60  setVolumePar(r);
61  if (r.isActive()) { active=kTRUE; }
62  if (r.isCreated()) { created=kTRUE; }
63 
64 }
65 
67 {
68  // Destructor
69  if (points) {
70  for (Int_t i=0; i<nPoints; i++) { points->RemoveAt(i); }
71  delete points;
72  points=0;
73  }
74  if (labTransform) {
75  delete labTransform;
76  labTransform=0;
77  }
78  if(fDaughterList) {
79  fDaughterList->Delete();
80  delete fDaughterList;
81  }
82 }
83 
85 {
86  // Copies all volume parameters except the name
88  medium=r.getMedium();
90  Int_t n=r.getNumPoints();
91  createPoints(n);
92  for (Int_t i=0; i<nPoints; i++) { setPoint(i,*(r.getPoint(i))); }
94 }
95 
97 {
98  // Clears the volume and deletes the points
99  /* pMother=0;
100  medium=0;
101  pShape=0;
102  volumeType=kFairGeoElement;
103  active=kFALSE;
104  created=kFALSE;
105  copyNode=0;
106  rootVolume=0;
107  */
108  if (labTransform) {
109  delete labTransform;
110  labTransform=0;
111  }
113 }
114 
116 {
117  // Returns the copy number
118  Int_t n=0;
119  if (fHadFormat == 1 ) {
120 
121  Int_t l=fName.Length();
122  if (l>4) {
123  TString s(fName);
124  s.Remove(0,4);
125  sscanf(s.Data(),"%i",&n);
126  }
127  } else {
128 
129  Ssiz_t l=fName.Last('#');
130  if (l>0) {
131  TString s(fName);
132  s.Remove(0,l+1);
133  sscanf(s.Data(),"%i",&n);
134  }
135  }
136 
137  return n;
138 }
139 
141 {
142  // Returns the parameters to create a GEANT/ROOT volume
143  if (pShape) { return pShape->calcVoluParam(this); }
144  return 0;
145 }
146 
148 {
149  // Returns the transformation to position a volume in GEANT/ROOT
150  if (pShape&&pMother) {
153  return pShape->getVoluPosition();
154  }
155  return 0;
156 }
157 
159 {
160  // Prints all parameters of a volume
161  cout<<"//----------------------------------------------------------\n";
163  cout<<"//----------------------------------------------------------\n";
164  return;
165 
166  cout<<((const char*)fName)<<'\n';
167  if (pMother) { cout<<((const char*)mother)<<'\n'; }
168  else { cout<<"-- unknown mother --\n"; }
169  if (!copyNode) {
170  if (pShape) { cout<<((const char*)shape)<<'\n'; }
171  else { cout<<"-- unknown shape --\n"; }
172  if (medium) { cout<<medium->GetName()<<'\n'; }
173  else { cout<<"-- unknown medium --\n"; }
174  if (points && pShape) { pShape->printPoints(this); }
175  else { cout<<"-- no points --\n"; }
176  }
179  cout<<"//----------------------------------------------------------\n";
180 }
181 
182 Bool_t FairGeoNode::write(std::fstream& fout)
183 {
184  // Writes all parameters of a volume to file
185  fout<<fName.Data()<<'\n';
186  if (pMother) { fout<<((const char*)mother)<<'\n'; }
187  else {
188  Error("write","Unknown mother for %s\n",fName.Data());
189  return kFALSE;
190  }
191  if (!copyNode) {
192  if (pShape) { fout<<((const char*)shape)<<'\n'; }
193  else {
194  Error("write","Unknown shape for %s\n",fName.Data());
195  return kFALSE;
196  }
197  if (medium) { fout<<medium->GetName()<<'\n'; }
198  else {
199  Error("write","Unknown medium for %s\n",fName.Data());
200  return kFALSE;
201  }
202  if (points && pShape) { pShape->writePoints(&fout,this); }
203  else {
204  Error("write","No points for %s\n",fName.Data());
205  return kFALSE;
206  }
207  }
210  fout.precision(3);
211  fout<<v(0)<<" "<<v(1)<<" "<<v(2)<<'\n';
212  fout.precision(7);
213  for(Int_t i=0; i<9; i++) { fout<<r(i)<<" "; }
214  fout<<'\n';
215  fout<<"//----------------------------------------------------------\n";
216  return kTRUE;
217 }
218 
220 {
221  // Returns the tree of the mother volumes
222  TList* tree=new TList();
223  FairGeoNode* v=this;
224  FairGeoNode* lmother;
225  do {
226  lmother=v->getMotherNode();
227  if (lmother) { tree->Add(lmother); }
228  v=lmother;
229  } while (v&&!v->isTopNode());
230  return tree;
231 }
232 
234 {
235  // Returns the lab transformation
236  if (labTransform) { return labTransform; }
237  else { return calcLabTransform(); }
238 }
239 
241 {
242  // Calculates the lab transformation
243 
245 
246  if (!isTopNode()) {
247  if (!pMother) {
248  Error("calcLabTransform()","Mother volume of %s not found!",GetName());
249  delete labTransform;
250  return 0;
251  }
253  if (!tm) {
254  ;
255  Error("calcLabTransform()",
256  "Lab Transformation of mother volume of %s not found!",GetName());
257  delete labTransform;
258  return 0;
259  }
260  labTransform->transFrom(*tm);
261  }
262 
264  fMedium = *medium;
265  return labTransform;
266 }
267 
269 {
270  // Sets the lab transformation
271  if (!isTopNode()) {
273  else { labTransform=new FairGeoTransform(t); }
274  if (!pMother) {
275  Error("calcLabTransform()","Mother volume of %s not found!",GetName());
276  delete labTransform;
277  return;
278  }
280  if (!tm) {
281  ;
282  Error("calcLabTransform()",
283  "Lab Transformation of mother volume of %s not found!",GetName());
284  delete labTransform;
285  return;
286  }
287  transform=t;
288  transform.transTo(*tm);
289  }
290 }
291 
293 {
294  // Calculates the transformation relative to the detectors coordinate system
295  FairGeoNode* node=this;
296  modTransform=transform;
297  while (node&&!node->isModule()) {
298  FairGeoNode* pm=node->getMotherNode();
299  if (!pm) {
300  Error("calcModuleTransform","Mother volume of %s not found!",node->GetName());
301  return kFALSE;
302  }
303  modTransform.transFrom(pm->getTransform());
304  node=pm;
305  }
306  if (isTopNode()) { return kFALSE; }
307  else { return kTRUE; }
308 }
309 
311 {
312  // Calculates the position in the detectors coordinate system
313  FairGeoNode* node=this;
314  refPos=center.getTransVector();
315  do {
316  refPos=node->getTransform().transFrom(refPos);
317  node=node->getMotherNode();
318  if (!node) {
319  Error("calcModuleTransform","Mother volume %s not found!",node->GetName());
320  return kFALSE;
321  }
322  } while (node&&!node->isModule());
323  if (isTopNode()) { return kFALSE; }
324  else { return kTRUE; }
325 }
326 
328 {
329  // Compares the volume with the volume rn and prints the diagnose
330  // Returns kTRUE if the volume parameters are the same
331  Int_t diff[]= {0,0,0,0,0,0};
332  Int_t n=0;
333  cout<<fName<<'\t';
334  if (mother.CompareTo(rn.getMother())!=0) {
335  diff[0]=1;
336  n++;
337  }
338  if (medium&&rn.getMedium()) {
339  TString med=medium->GetName();
340  if (med.CompareTo(rn.getMedium()->GetName())!=0) {
341  diff[1]=1;
342  n++;
343  }
344  } else {
345  diff[1]=1;
346  n++;
347  }
348  if (shape.CompareTo(rn.getShape())!=0) {
349  diff[2]=1;
350  n++;
351  }
352  Int_t np=rn.getNumPoints();
353  if (points&&nPoints==np) {
354  for (Int_t i=0; i<np; i++) {
355  FairGeoVector v1=*(getPoint(i));
356  FairGeoVector v2=*(rn.getPoint(i));
357  if (fabs(v1(0)-v2(0))>=0.001||fabs(v1(1)-v2(1))>=0.001||fabs(v1(1)-v2(1))>=0.001) {
358  diff[3]=1;
359  n++;
360  break;
361  }
362  }
363  } else {
364  diff[3]=1;
365  n++;
366  }
369  if (fabs(v1(0)-v2(0))>=0.001||fabs(v1(1)-v2(1))>=0.001||fabs(v1(1)-v2(1))>=0.001) {
370  diff[4]=1;
371  n++;
372  }
375  for (Int_t i=0; i<9; i++) {
376  if (fabs(r1(i)-r2(i))>=1.e-7) {
377  diff[5]=1;
378  n++;
379  break;
380  }
381  }
382  if (n>0) {
383  for (Int_t i=0; i<6; i++) { cout<<" "<<diff[i]<<" "; }
384  cout<<'\n';
385  } else { cout<<" same\n"; }
386  return n;
387 }