EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoRootBuilder.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoRootBuilder.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 10/11/03 by Ilse Koenig
3 
5 // FairGeoRootBuilder
6 //
7 // Class to create the geometry in ROOT
8 //
10 
11 #include "FairGeoRootBuilder.h"
12 
13 #include "FairGeoMedium.h"
14 #include "FairGeoNode.h"
15 #include "FairGeoTransform.h"
16 
17 #include "TGeoManager.h"
18 #include "TGeoMedium.h"
19 #include "TGeoMaterial.h"
20 #include "TGeoVolume.h"
21 #include "TGeoMatrix.h"
22 //#include "TGeoPgon.h"
23 //#include "TGeoPcon.h"
24 #include "TArrayD.h"
25 
27 
29  : FairGeoBuilder(),
30  geoManager(NULL)
31 {
32  // Default constructor
33 }
34 
36  : FairGeoBuilder(name,title),
37  geoManager(NULL)
38 {
39  // Constructor
40 }
41 
42 Bool_t FairGeoRootBuilder::createNode(FairGeoNode* volu, Int_t hadFormat)
43 {
44  // Creates the volume
45  if (!geoManager||!volu) { return kFALSE; }
46  // volu->print();
47 
48  TString nodeName= volu->GetName();
49  if ( hadFormat == 1 ) {
50  volu->setHadFormat( hadFormat );
51  nodeName=nodeName(0,4);
52  } else {
53  nodeName = (volu->GetName());
54  Ssiz_t l=nodeName.Last('#');
55  if (l>0) { nodeName=nodeName(0,l); }
56  }
57 
58  FairGeoNode* mother=volu->getMotherNode();
59  if (!mother&&!volu->isTopNode()) {
60  Error("createNode","Mother volume of %s not found\n",volu->GetName());
61  return kFALSE;
62  }
63 
64 
65 
66 
67 
68  TGeoVolume* rv=0;
69  FairGeoNode* cv=volu->getCopyNode();
70 // if (cv) cout<<"Copy of "<<cv->GetName()<<endl;
71  if (cv) { rv=cv->getRootVolume(); }
72  if (!rv) {
73  FairGeoMedium* lmedium=volu->getMedium();
74  Int_t lnMed=lmedium->getMediumIndex();
75  if (lnMed<=0) { lnMed=createMedium(lmedium); }
76  if (lnMed<=0) { return kFALSE; }
77  TArrayD* par=volu->getParameters();
78  //for (Int_t k=0;k<par->GetSize();k++) cout<<par->At(k)<<" ";
79  // cout<<endl;
80  //cout << "Create Volume of Shape " << volu->getShape() << endl;
81  if (volu->getShape().Contains("TORUS")) { // Torus is missing in the TGeoManager::Volume
82  // this should solve the problem tell it is implimented in root
83  TGeoMedium* medium =geoManager->GetMedium(lnMed);
84  rv = geoManager->MakeTorus(nodeName.Data(),medium,par->At(0),par->At(1),par->At(2),par->At(3),par->At(4));
85  // cout << "Create Torus" << nodeName.Data() << endl;
86  } else if (volu->getShape().Contains("ASSEMBLY")) {
87  rv=geoManager->MakeVolumeAssembly(nodeName.Data());
88 
89  } else {
90  rv=geoManager->Volume(nodeName.Data(),volu->getShape().Data(),
91  lnMed,par->GetArray(),par->GetSize());
92  }
93  volu->setCreated();
94  if (volu->isModule()&&cv) {
95  cv->setCreated();
96  cv->setRootVolume(rv);
97  cv->getPosition();
98  }
99  }
100  if (!rv) { return kFALSE; }
101  volu->setRootVolume(rv);
102  if (volu->isTopNode()) { geoManager->SetTopVolume(rv); }
103  else {
104  FairGeoTransform* trans=volu->getPosition();
105  const FairGeoRotation& rot=trans->getRotMatrix();
106  const FairGeoVector& pos=trans->getTransVector();
107  TGeoMatrix* tr=0;
108  if (((FairGeoRotation&)rot).isUnitMatrix()) {
109  tr=new TGeoTranslation(pos.getX(),pos.getY(),pos.getZ());
110  } else {
111  nRot++;
112  char b[10];
113  sprintf(b,"R%i",nRot);
114  TGeoRotation* r=new TGeoRotation(b);
115  Double_t a[9];
116  for (Int_t i=0; i<9; i++) { a[i]=rot(i); }
117  r->SetMatrix(a);
118  tr=new TGeoCombiTrans(pos.getX(),pos.getY(),pos.getZ(),r);
119  }
120  TGeoVolume* mo=mother->getRootVolume();
121  if (!mo) { return kFALSE; }
122  mo->AddNode(rv,volu->getCopyNo(),tr);
123  }
124  return kTRUE;
125 }
126 
128 {
129  // Creates the medium
130  if (!geoManager&&!med) { return 0; }
131  Int_t nComp=med->getNComponents();
132  Int_t weightFac=med->getWeightFac();
133  TGeoMaterial* material=0;
134  Double_t p[3];
135  if (nComp==1) {
136  med->getComponent(0,p);
137  material=new TGeoMaterial(med->GetName(),p[0],p[1],med->getDensity(),
138  med->getRadiationLength());
139  // Interaction length not defined!!!!!!
140  } else {
141  material=new TGeoMixture(med->GetName(),nComp,med->getDensity());
142  Double_t sumWeights=0.;
143  if (weightFac<0) {
144  for(Int_t i=0; i<nComp; i++) {
145  med->getComponent(i,p);
146  sumWeights+=p[0]*p[2];
147  }
148  }
149  for(Int_t i=0; i<nComp; i++) {
150  med->getComponent(i,p);
151  if (weightFac>0) {
152  ((TGeoMixture*)material)->DefineElement(i,p[0],p[1],p[2]);
153  } else {
154  ((TGeoMixture*)material)->DefineElement(i,p[0],p[1],p[0]*p[2]/sumWeights);
155  }
156  }
157  }
158  nMed++;
159  med->setMediumIndex(nMed);
160  Double_t mp[10];
161  med->getMediumPar(mp);
162  TGeoMedium* medium=new TGeoMedium(med->GetName(),nMed,material,mp);
163  if (medium) { return nMed; }
164  else { return 0; }
165 }
166 
168 {
169  // Closes the geometry input in ROOT and draws the cave
170  if (geoManager) {
171  geoManager->CloseGeometry();
172  geoManager->SetVisLevel(5);
173  geoManager->GetTopVolume()->Draw();
174  }
175 }
176 
178 {
179  // Checks the geometry for overlaps and extrusions wit a default precision of 1 micron
180  if (geoManager) {
181  geoManager->CheckOverlaps(ovlp,"SAME");
182  geoManager->PrintOverlaps();
183  }
184 }