Project
Loading...
Searching...
No Matches
FairGeoRootBuilder.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8//*-- AUTHOR : Ilse Koenig
9//*-- Created : 10/11/03 by Ilse Koenig
10
12// FairGeoRootBuilder
13//
14// Class to create the geometry in ROOT
15//
17#include "FairGeoRootBuilder.h"
18
19#include "FairGeoMedium.h" // for FairGeoMedium
20#include "FairGeoNode.h" // for FairGeoNode
21#include "FairGeoRotation.h" // for FairGeoRotation
22#include "FairGeoTransform.h" // for FairGeoTransform
23#include "FairGeoVector.h" // for FairGeoVector
24
25#include <TArrayD.h> // for TArrayD
26#include <TGeoManager.h> // for TGeoManager
27#include <TGeoMaterial.h> // for TGeoMixture, TGeoMaterial
28#include <TGeoMatrix.h> // for TGeoCombiTrans, etc
29#include <TGeoMedium.h> // for TGeoMedium
30#include <TGeoVolume.h> // for TGeoVolume, etc
31#include <TString.h> // for TString
32#include <cstdio> // for sprintf
33#include <fstream>
34
36
39 , geoManager(nullptr)
40{
41 // Default constructor
42}
43
44FairGeoRootBuilder::FairGeoRootBuilder(const char* name, const char* title)
45 : FairGeoBuilder(name, title)
46 , geoManager(nullptr)
47{
48 // Constructor
49}
50
51Bool_t FairGeoRootBuilder::createNode(FairGeoNode* volu, Int_t hadFormat)
52{
53 // Creates the volume
54 if (!geoManager || !volu) {
55 return kFALSE;
56 }
57 // volu->print();
58
59 TString nodeName = volu->GetName();
60 if (hadFormat == 1) {
61 volu->setHadFormat(hadFormat);
62 nodeName = nodeName(0, 4);
63 } else {
64 nodeName = (volu->GetName());
65 Ssiz_t l = nodeName.Last('#');
66 if (l > 0) {
67 nodeName = nodeName(0, l);
68 }
69 }
70
71 FairGeoNode* mother = volu->getMotherNode();
72 if (!mother && !volu->isTopNode()) {
73 Error("createNode", "Mother volume of %s not found\n", volu->GetName());
74 return kFALSE;
75 }
76
77 TGeoVolume* rv = 0;
78 FairGeoNode* cv = volu->getCopyNode();
79 // if (cv) cout<<"Copy of "<<cv->GetName()<<endl;
80 if (cv) {
81 rv = cv->getRootVolume();
82 }
83 if (!rv) {
84 FairGeoMedium* lmedium = volu->getMedium();
85 Int_t lnMed = lmedium->getMediumIndex();
86 if (lnMed <= 0) {
87 lnMed = createMedium(lmedium);
88 }
89 if (lnMed <= 0) {
90 return kFALSE;
91 }
92 TArrayD* par = volu->getParameters();
93 // for (Int_t k=0;k<par->GetSize();k++) cout<<par->At(k)<<" ";
94 // cout<<endl;
95 // cout << "Create Volume of Shape " << volu->getShape() << endl;
96 if (volu->getShape().Contains("TORUS")) { // Torus is missing in the TGeoManager::Volume
97 // this should solve the problem tell it is implimented in root
98 TGeoMedium* medium = geoManager->GetMedium(lnMed);
99 rv = geoManager->MakeTorus(
100 nodeName.Data(), medium, par->At(0), par->At(1), par->At(2), par->At(3), par->At(4));
101 // cout << "Create Torus" << nodeName.Data() << endl;
102 } else if (volu->getShape().Contains("ASSEMBLY")) {
103 rv = geoManager->MakeVolumeAssembly(nodeName.Data());
104
105 } else {
106 rv = geoManager->Volume(nodeName.Data(), volu->getShape().Data(), lnMed, par->GetArray(), par->GetSize());
107 }
108 volu->setCreated();
109 if (volu->isModule() && cv) {
110 cv->setCreated();
111 cv->setRootVolume(rv);
112 cv->getPosition();
113 }
114 }
115 if (!rv) {
116 return kFALSE;
117 }
118 volu->setRootVolume(rv);
119 if (volu->isTopNode()) {
120 geoManager->SetTopVolume(rv);
121 } else {
122 FairGeoTransform* trans = volu->getPosition();
123 const FairGeoRotation& rot = trans->getRotMatrix();
124 const FairGeoVector& pos = trans->getTransVector();
125 TGeoMatrix* tr = 0;
126 if ((const_cast<FairGeoRotation&>(rot)).isUnitMatrix()) {
127 tr = new TGeoTranslation(pos.getX(), pos.getY(), pos.getZ());
128 } else {
129 nRot++;
130 char b[13];
131 snprintf(b, sizeof(b), "R%i", nRot);
132 TGeoRotation* r = new TGeoRotation(b);
133 Double_t a[9];
134 for (Int_t i = 0; i < 9; i++) {
135 a[i] = rot(i);
136 }
137 r->SetMatrix(a);
138 tr = new TGeoCombiTrans(pos.getX(), pos.getY(), pos.getZ(), r);
139 }
140 TGeoVolume* mo = mother->getRootVolume();
141 if (!mo) {
142 return kFALSE;
143 }
144 mo->AddNode(rv, volu->getCopyNo(), tr);
145 }
146 return kTRUE;
147}
148
150{
151 // Creates the medium
152 if (!geoManager && !med) {
153 return 0;
154 }
155 Int_t nComp = med->getNComponents();
156 Int_t weightFac = med->getWeightFac();
157 TGeoMaterial* material = 0;
158 Double_t p[3];
159 if (nComp == 1) {
160 med->getComponent(0, p);
161 material = new TGeoMaterial(med->GetName(), p[0], p[1], med->getDensity(), med->getRadiationLength());
162 // Interaction length not defined!!!!!!
163 } else {
164 material = new TGeoMixture(med->GetName(), nComp, med->getDensity());
165 Double_t sumWeights = 0.;
166 if (weightFac < 0) {
167 for (Int_t i = 0; i < nComp; i++) {
168 med->getComponent(i, p);
169 sumWeights += p[0] * p[2];
170 }
171 }
172 for (Int_t i = 0; i < nComp; i++) {
173 med->getComponent(i, p);
174 if (weightFac > 0) {
175 (static_cast<TGeoMixture*>(material))->DefineElement(i, p[0], p[1], p[2]);
176 } else {
177 (static_cast<TGeoMixture*>(material))->DefineElement(i, p[0], p[1], p[0] * p[2] / sumWeights);
178 }
179 }
180 }
181 nMed++;
182 med->setMediumIndex(nMed);
183 Double_t mp[10];
184 med->getMediumPar(mp);
185 TGeoMedium* medium = new TGeoMedium(med->GetName(), nMed, material, mp);
186 if (medium) {
187 return nMed;
188 } else {
189 return 0;
190 }
191}
192
194{
195 // Closes the geometry input in ROOT and draws the cave
196 if (geoManager) {
197 geoManager->CloseGeometry();
198 geoManager->SetVisLevel(5);
199 geoManager->GetTopVolume()->Draw();
200 }
201}
202
204{
205 // Checks the geometry for overlaps and extrusions wit a default precision of 1 micron
206 if (geoManager) {
207 geoManager->CheckOverlaps(ovlp, "SAME");
208 geoManager->PrintOverlaps();
209 }
210}
ClassImp(FairGeoRootBuilder)
int32_t i
uint16_t pos
Definition RawData.h:3
Int_t getWeightFac()
void getMediumPar(Double_t *)
Double_t getDensity()
Int_t getMediumIndex()
Double_t getRadiationLength()
void getComponent(Int_t, Double_t *)
Int_t getNComponents()
void setMediumIndex(Int_t i)
FairGeoTransform * getPosition()
Int_t getCopyNo()
FairGeoNode * getMotherNode()
Definition FairGeoNode.h:73
Bool_t isTopNode()
Definition FairGeoNode.h:67
Bool_t isModule()
Definition FairGeoNode.h:70
void setRootVolume(TGeoVolume *p)
Definition FairGeoNode.h:95
void setCreated()
Definition FairGeoNode.h:85
TGeoVolume * getRootVolume()
Definition FairGeoNode.h:81
TArrayD * getParameters()
FairGeoNode * getCopyNode()
Definition FairGeoNode.h:80
FairGeoMedium * getMedium()
Definition FairGeoNode.h:74
Bool_t createNode(FairGeoNode *, Int_t hadFormat=0)
Int_t createMedium(FairGeoMedium *)
void checkOverlaps(Double_t ovlp=0.0001)
const FairGeoVector & getTransVector() const
const FairGeoRotation & getRotMatrix() const
const TString & getShape() const
virtual void setHadFormat(Int_t i)
GLuint const GLchar * name
Definition glcorearb.h:781
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233