HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hgeomnode.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 10/11/2003
3 
4 //_HADES_CLASS_DESCRIPTION
5 ////////////////////////////////////////////////////////////////
6 // HGeomNode
7 //
8 // Class to hold the basic geometry properties of a GEANT volume
9 //
10 ////////////////////////////////////////////////////////////////
11 
12 #include "hgeomnode.h"
13 #include "TList.h"
14 #include <iostream>
15 #include <iomanip>
16 
18 
20  // Constructor
21  labTransform=0;
22  clear();
23 }
24 
26  // Copy constructor
27  points=0;
28  nPoints = 0;
29  fName=r.GetName();
30  setVolumePar(r);
31  if (r.isActive()) active=kTRUE;
32  else active=kFALSE;
36  if (r.isCreated()) created=kTRUE;
37  else created=kFALSE;
40 }
41 
43  // Destructor
44  if (points) {
45  for (Int_t i=0;i<nPoints;i++) points->RemoveAt(i);
46  delete points;
47  points=0;
48  }
49  if (labTransform) {
50  delete labTransform;
51  labTransform=0;
52  }
53 }
54 
56  // Copies all volume parameters except the name
58  medium=r.getMedium();
60  Int_t n=r.getNumPoints();
61  createPoints(n);
62  for (Int_t i=0;i<nPoints;i++) setPoint(i,*(r.getPoint(i)));
64 }
65 
67  // Clears the volume and deletes the points
68  pMother=0;
69  medium=0;
70  pShape=0;
72  active=kFALSE;
73  created=kFALSE;
74  copyNode=0;
75  rootVolume=0;
76  if (labTransform) {
77  delete labTransform;
78  labTransform=0;
79  }
81 }
82 
84  // Returns the copy number
85  Int_t n=1;
86  Int_t l=fName.Length();
87  if (l>4) {
88  TString s(fName);
89  s.Remove(0,4);
90  sscanf(s.Data(),"%i",&n);
91  }
92  return n;
93 }
94 
96  // Returns the parameters to create a GEANT/ROOT volume
97  if (pShape) return pShape->calcVoluParam(this);
98  return 0;
99 }
100 
102  // Returns the transformation to position a volume in GEANT/ROOT
103  if (pShape&&pMother) {
106  return pShape->getVoluPosition();
107  }
108  return 0;
109 }
110 
112  // Prints all parameters of a volume
113  cout<<((const Char_t*)fName)<<'\n';
114  if (pMother)cout<<((const Char_t*)mother)<<'\n';
115  else cout<<"-- unknown mother --\n";
116  if (!copyNode) {
117  if (pShape) cout<<((const Char_t*)shape)<<'\n';
118  else cout<<"-- unknown shape --\n";
119  if (medium) cout<<medium->GetName()<<'\n';
120  else cout<<"-- unknown medium --\n";
121  if (points && pShape) pShape->printPoints(this);
122  else cout<<"-- no points --\n";
123  }
126  cout<<"//----------------------------------------------------------\n";
127 }
128 
129 Bool_t HGeomNode::write(fstream& fout) {
130  // Writes all parameters of a volume to file
131  fout<<fName.Data()<<'\n';
132  if (pMother) fout<<((const Char_t*)mother)<<'\n';
133  else {
134  Error("write","Unknown mother for %s\n",fName.Data());
135  return kFALSE;
136  }
137  if (!copyNode) {
138  if (pShape) fout<<((const Char_t*)shape)<<'\n';
139  else {
140  Error("write","Unknown shape for %s\n",fName.Data());
141  return kFALSE;
142  }
143  if (medium) fout<<medium->GetName()<<'\n';
144  else {
145  Error("write","Unknown medium for %s\n",fName.Data());
146  return kFALSE;
147  }
148  if (points && pShape) pShape->writePoints(&fout,this);
149  else {
150  Error("write","No points for %s\n",fName.Data());
151  return kFALSE;
152  }
153  }
156  fout.precision(3);
157  fout<<v(0)<<" "<<v(1)<<" "<<v(2)<<'\n';
158  fout.precision(7);
159  for(Int_t i=0;i<9;i++) fout<<r(i)<<" ";
160  fout<<'\n';
161  fout<<"//----------------------------------------------------------\n";
162  return kTRUE;
163 }
164 
166  // Returns the tree of the mother volumes
167  TList* tree=new TList();
168  HGeomNode* v=this;
169  HGeomNode* mother;
170  do {
171  mother=v->getMotherNode();
172  if (mother) tree->Add(mother);
173  v=mother;
174  } while (v&&!v->isTopNode());
175  return tree;
176 }
177 
179  // Returns the lab transformation
180  if (labTransform) return labTransform;
181  else return calcLabTransform();
182 }
183 
185  // Calculates the lab transformation
187  if (!isTopNode()) {
188  if (!pMother) {
189  Error("calcLabTransform()","Mother volume of %s not found!",GetName());
190  delete labTransform;
191  return 0;
192  }
194  if (!tm) {;
195  Error("calcLabTransform()",
196  "Lab Transformation of mother volume of %s not found!",GetName());
197  delete labTransform;
198  return 0;
199  }
200  labTransform->transFrom(*tm);
201  }
202  return labTransform;
203 }
204 
206  // Sets the lab transformation
207  if (!isTopNode()) {
209  else labTransform=new HGeomTransform(t);
210  if (!pMother) {
211  Error("calcLabTransform()","Mother volume of %s not found!",GetName());
212  delete labTransform;
213  return;
214  }
216  if (!tm) {;
217  Error("calcLabTransform()",
218  "Lab Transformation of mother volume of %s not found!",GetName());
219  delete labTransform;
220  return;
221  }
222  transform=t;
223  transform.transTo(*tm);
224  }
225 }
226 
228  // Calculates the transformation relative to the detectors coordinate system
229  HGeomNode* node=this;
230  modTransform=transform;
231  while (node&&!node->isModule()) {
232  HGeomNode* pm=node->getMotherNode();
233  if (!pm) {
234  Error("calcModuleTransform","Mother volume of %s not found!",node->GetName());
235  return kFALSE;
236  }
237  modTransform.transFrom(pm->getTransform());
238  node=pm;
239  }
240  if (isTopNode()) return kFALSE;
241  else return kTRUE;
242 }
243 
245  // Calculates the position in the detectors coordinate system
246  HGeomNode* node=this;
247  refPos=center.getTransVector();
248  do {
249  refPos=node->getTransform().transFrom(refPos);
250  node=node->getMotherNode();
251  if (!node) {
252  Error("calcModuleTransform","Mother volume %s not found!",node->GetName());
253  return kFALSE;
254  }
255  } while (node&&!node->isModule());
256  if (isTopNode()) return kFALSE;
257  else return kTRUE;
258 }
259 
261  // Compares the volume with the volume rn and prints the diagnose
262  // Returns kTRUE if the volume parameters are the same
263  Int_t diff[]={0,0,0,0,0,0};
264  Int_t n=0;
265  cout<<fName<<'\t';
266  if (mother.CompareTo(rn.getMother())!=0) {
267  diff[0]=1;
268  n++;
269  }
270  if (medium&&rn.getMedium()) {
271  TString med=medium->GetName();
272  if (med.CompareTo(rn.getMedium()->GetName())!=0) {
273  diff[1]=1;
274  n++;
275  }
276  } else {
277  diff[1]=1;
278  n++;
279  }
280  if (shape.CompareTo(rn.getShape())!=0) {
281  diff[2]=1;
282  n++;
283  }
284  Int_t np=rn.getNumPoints();
285  if (points&&nPoints==np) {
286  for (Int_t i=0;i<np;i++) {
287  HGeomVector v1=*(getPoint(i));
288  HGeomVector v2=*(rn.getPoint(i));
289  if (fabs(v1(0)-v2(0))>=0.001||fabs(v1(1)-v2(1))>=0.001||fabs(v1(2)-v2(2))>=0.001) {
290  diff[3]=1;
291  n++;
292  break;
293  }
294  }
295  } else {
296  diff[3]=1;
297  n++;
298  }
301  if (fabs(v1(0)-v2(0))>=0.001||fabs(v1(1)-v2(1))>=0.001||fabs(v1(2)-v2(2))>=0.001) {
302  diff[4]=1;
303  n++;
304  }
307  for (Int_t i=0;i<9;i++) {
308  if (fabs(r1(i)-r2(i))>=1.e-7) {
309  diff[5]=1;
310  n++;
311  break;
312  }
313  }
314  if (n>0) {
315  for (Int_t i=0;i<6;i++) cout<<" "<<diff[i]<<" ";
316  cout<<'\n';
317  } else cout<<" same\n";
318  return n;
319 }
Bool_t active
Definition: hgeomnode.h:27
TArrayD * getParameters()
Definition: hgeomnode.cc:95
HGeomTransform & getTransform()
Definition: hgeomvolume.h:22
Bool_t isModule()
Definition: hgeomnode.h:41
HGeomTransform transform
Definition: hgeomvolume.h:13
HGeomNode * getCopyNode()
Definition: hgeomnode.h:51
HGeomTransform * getCenterPosition()
HGeomTransform & getCenterPosition()
Definition: hgeomnode.h:47
HGeomBasicShape * getShapePointer()
Definition: hgeomnode.h:43
HGeomMedium * getMedium()
Definition: hgeomnode.h:45
TList * getTree()
Definition: hgeomnode.cc:165
Int_t getCopyNo()
Definition: hgeomnode.cc:83
TGeoVolume * getRootVolume()
Definition: hgeomnode.h:52
void setPoint(const Int_t, const Double_t, const Double_t, const Double_t)
Definition: hgeomvolume.cc:69
HGeomTransform * getVoluPosition()
Int_t getNumPoints()
Definition: hgeomvolume.h:23
const HGeomRotation & getRotMatrix() const
virtual void printPoints(HGeomVolume *volu)
void setTransform(const HGeomTransform &t)
virtual void calcVoluPosition(HGeomVolume *, const HGeomTransform &)
void setShape(HGeomBasicShape *s)
Definition: hgeomnode.h:86
Int_t n
ClassImp(HGeomNode) HGeomNode
Definition: hgeomnode.cc:17
void print()
Definition: hgeomnode.cc:111
TGeoVolume * rootVolume
Definition: hgeomnode.h:32
void print() const
HGeomTransform * getPosition()
Definition: hgeomnode.cc:101
Int_t nPoints
Definition: hgeomvolume.h:14
void print() const
Definition: hgeomvector.h:55
void setVolumePar(HGeomNode &)
Definition: hgeomnode.cc:55
TString shape
Definition: hgeomvolume.h:10
const TString & getShape() const
Definition: hgeomvolume.h:20
Bool_t calcRefPos(HGeomVector &)
Definition: hgeomnode.cc:244
void createPoints(const Int_t)
Definition: hgeomvolume.cc:46
HGeomNode * copyNode
Definition: hgeomnode.h:30
void setLabTransform(HGeomTransform &)
Definition: hgeomnode.cc:205
void setMother(HGeomNode *s)
Definition: hgeomnode.h:94
TString mother
Definition: hgeomvolume.h:11
const HGeomVector & getTransVector() const
HGeomTransform * getLabTransform()
Definition: hgeomnode.cc:178
HGeomMedium * medium
Definition: hgeomnode.h:25
HGeomTransform * calcLabTransform()
Definition: hgeomnode.cc:184
virtual TArrayD * calcVoluParam(HGeomVolume *)
HGeomVector transFrom(const HGeomVector &p) const
EHGeomNodeType volumeType
Definition: hgeomnode.h:26
EHGeomNodeType getVolumeType()
Definition: hgeomnode.h:37
HGeomVector * getPoint(const Int_t n)
Definition: hgeomvolume.h:52
virtual Bool_t writePoints(fstream *, HGeomVolume *)
Bool_t write(fstream &)
Definition: hgeomnode.cc:129
virtual void clear()
Definition: hgeomvolume.cc:88
Bool_t isActive()
Definition: hgeomnode.h:46
Bool_t created
Definition: hgeomnode.h:31
HGeomBasicShape * pShape
Definition: hgeomnode.h:23
void clear()
Definition: hgeomnode.cc:66
HGeomNode * getMotherNode()
Definition: hgeomnode.h:44
const TString & getMother() const
Definition: hgeomvolume.h:21
Bool_t calcModuleTransform(HGeomTransform &)
Definition: hgeomnode.cc:227
HGeomTransform * labTransform
Definition: hgeomnode.h:29
HGeomNode * pMother
Definition: hgeomnode.h:24
Bool_t isTopNode()
Definition: hgeomnode.h:38
~HGeomNode()
Definition: hgeomnode.cc:42
Bool_t isCreated()
Definition: hgeomnode.h:55
HGeomTransform center
Definition: hgeomnode.h:28
HGeomVector transTo(const HGeomVector &p) const
TObjArray * points
Definition: hgeomvolume.h:12
Int_t compare(HGeomNode &)
Definition: hgeomnode.cc:260