]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4GeometryManager.cxx
added Gsbool() method
[u/mrichter/AliRoot.git] / TGeant4 / TG4GeometryManager.cxx
CommitLineData
2817d3e2 1// $Id$
2// Category: geometry
3//
e5967ab3 4// Author: V. Berejnoi, I. Hrivnacova
2817d3e2 5//
e5967ab3 6// Class TG4GeometryManager
7// ------------------------
8// See the class description in the header file.
9// C++ interface to Geant3 basic routines for building Geant4 geometry
10// by V. Berejnoi, 25.2.1999;
2817d3e2 11// materials, tracking media support
e5967ab3 12// added by I.Hrivnacova, 27.5.1999.
2817d3e2 13
14#include "TG4GeometryManager.h"
15#include "TG4GeometryOutputManager.h"
154fc5a5 16#include "TG4GeometryServices.h"
e5967ab3 17#include "TG4Limits.h"
f1bdb708 18#include "TG4G3Units.h"
e5967ab3 19#include "TG4G3CutVector.h"
20#include "TG4G3ControlVector.h"
2817d3e2 21#include "TG4Globals.h"
2817d3e2 22
23#include <G3toG4.hh>
24#include <G3toG4BuildTree.hh>
25#include <G3VolTable.hh>
26#include <G3RotTable.hh>
27#include <G3EleTable.hh>
28#include <G3MatTable.hh>
29#include <G3MedTable.hh>
30#include <G3SensVolVector.hh>
31
2817d3e2 32#include <G4LogicalVolumeStore.hh>
33#include <G4PVPlacement.hh>
34#include <G4Material.hh>
35#include <G4MaterialPropertiesTable.hh>
36#include <G4Element.hh>
37
2817d3e2 38// extern global method from g3tog4
39void G3CLRead(G4String &, char *);
40
41TG4GeometryManager* TG4GeometryManager::fgInstance = 0;
42
f45653e2 43//_____________________________________________________________________________
2817d3e2 44TG4GeometryManager::TG4GeometryManager()
45 : fMediumCounter(0),
46 fMaterialCounter(0),
47 fMatrixCounter(0),
48 fUseG3TMLimits(false),
49 fWriteGeometry(true)
50{
51//
52 if (fgInstance) {
53 TG4Globals::Exception(
54 "TG4GeometryManager: attempt to create two instances of singleton.");
55 }
56
e5967ab3 57 fOutputManager
58 = new TG4GeometryOutputManager();
2817d3e2 59
e5967ab3 60 fGeometryServices
61 = new TG4GeometryServices(&fMediumMap, &fNameMap);
154fc5a5 62
2817d3e2 63 fgInstance = this;
64
65 // instantiate the default element table
66 //TG4ElementTable::Instance();
67}
68
f45653e2 69//_____________________________________________________________________________
2817d3e2 70TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right) {
71//
72 TG4Globals::Exception(
73 "Attempt to copy TG4GeometryManager singleton.");
74}
75
76
f45653e2 77//_____________________________________________________________________________
2817d3e2 78TG4GeometryManager::~TG4GeometryManager() {
79//
80 delete fOutputManager;
154fc5a5 81 delete fGeometryServices;
2817d3e2 82}
83
f45653e2 84//=============================================================================
2817d3e2 85//
86// operators
87//
f45653e2 88//=============================================================================
2817d3e2 89
f45653e2 90
91//_____________________________________________________________________________
2817d3e2 92TG4GeometryManager&
93TG4GeometryManager::operator=(const TG4GeometryManager& right)
94{
95 // check assignement to self
96 if (this == &right) return *this;
97
98 TG4Globals::Exception(
99 "Attempt to assign TG4GeometryManager singleton.");
100
101 return *this;
102}
103
104
105//=============================================================================
106//
107// private methods
108//
109//=============================================================================
2817d3e2 110
f45653e2 111//_____________________________________________________________________________
e5967ab3 112void TG4GeometryManager::FillMediumMap()
2817d3e2 113{
e5967ab3 114// Maps G3 tracking medium IDs to volumes names.
2817d3e2 115// ---
116
f45653e2 117
e5967ab3 118 static G4int done = 0;
119
f45653e2 120 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
121
e5967ab3 122 for (G4int i=done; i<lvStore->size(); i++) {
123 G4String name = ((*lvStore)[i])->GetName();
d499787d 124
125 G4String g3Name(name);
126 if (name.find("_refl")) g3Name = g3Name.substr(0, g3Name.find("_refl"));
127
128 G4int mediumID = G3Vol.GetVTE(g3Name)->GetNmed();
e5967ab3 129 fMediumMap.Add(name, mediumID);
130 }
131
132 done = lvStore->size();
133}
f45653e2 134
2817d3e2 135
136//=============================================================================
137//
138// public methods - AliMC implementation
139//
140//=============================================================================
141
142
f45653e2 143//_____________________________________________________________________________
2817d3e2 144void TG4GeometryManager::Material(Int_t& kmat, const char* name, Float_t a,
145 Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t* buf,
146 Int_t nwbuf)
147{
148// Creates G4Material.
149// !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
150// Comment:
151// absl - this parameter is ignored by GEANT3, too
152// ---
153
154 kmat = ++fMaterialCounter;
154fc5a5 155 G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf);
e5967ab3 156 G4String namein = fGeometryServices->CutMaterialName(name);
2817d3e2 157
158 // write token to the output file
159 if (fWriteGeometry)
e5967ab3 160 fOutputManager->WriteGsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
161
162 // create new material only if it does not yet exist
163 G4Material* material = fGeometryServices->FindMaterial(a, z, dens);
164 if (material) {
165 // add verbose
166 G4cout << "!!! Material " << namein << " already exists as "
167 << material->GetName() << G4endl;
168 G3Mat.put(kmat, material);
169 }
170 else
171 G4gsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
172
173 // save the original material name
174 fMaterialNameVector.push_back(namein);
2817d3e2 175
176 delete [] bufin;
177
178 if (nwbuf > 0) {
2817d3e2 179 G4String text
180 = "TG4GeometryManager: user defined parameters for material ";
e5967ab3 181 text = text + namein;
2817d3e2 182 text = text + " are ignored by Geant4.";
183 TG4Globals::Warning(text);
184 }
185}
186
187
f45653e2 188//_____________________________________________________________________________
2817d3e2 189void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a,
190 Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
191{
192// Creates G4Material composed of more elements.
193// !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
194// Comment:
195// absl - this parameter is ignored by GEANT3, too
196// ---
197
198 Int_t npar = abs(nlmat);
154fc5a5 199 G4double *ain = fGeometryServices->CreateG4doubleArray(a, npar);
200 G4double *zin = fGeometryServices->CreateG4doubleArray(z, npar);
201 G4double *wmatin = fGeometryServices->CreateG4doubleArray(wmat, npar);
e5967ab3 202 G4String namein = fGeometryServices->CutMaterialName(name);
2817d3e2 203
204 kmat = ++fMaterialCounter;
205
206 // write token to the output file
207 if (fWriteGeometry)
e5967ab3 208 fOutputManager->WriteGsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
209
210 // create new material only if it does not yet exist
211 G4Material* material
212 = fGeometryServices->FindMaterial(ain, zin, dens, nlmat, wmatin);
213 if (material) {
214 // add verbose
215 G4cout << "!!! Material " << namein << " already exists as "
216 << material->GetName() << G4endl;
217 G3Mat.put(kmat, material);
218 }
219 else
220 G4gsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
221
222 // save the original material name
223 fMaterialNameVector.push_back(namein);
2817d3e2 224
2817d3e2 225 // !!! in Geant3:
226 // After a call with ratios by number (negative number of elements),
227 // the ratio array is changed to the ratio by weight, so all successive
228 // calls with the same array must specify the number of elements as
229 // positive
230
231 // wmatin may be modified
232 for (G4int i=0; i<npar; i++) wmat[i] = wmatin[i];
233
234 delete [] ain;
235 delete [] zin;
236 delete [] wmatin;
237}
238
f45653e2 239//_____________________________________________________________________________
2817d3e2 240void TG4GeometryManager::Medium(Int_t& kmed, const char *name, Int_t nmat,
241 Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd,
242 Float_t stemax, Float_t deemax, Float_t epsil,
243 Float_t stmin, Float_t* ubuf, Int_t nbuf)
244{
245// Creates a temporary "medium" that is used for
246// assigning corresponding parameters to G4 objects:
247// NTMED is stored as a second material index;
f1bdb708 248// ISVOL is used for builing G3SensVolVector;
2817d3e2 249// STEMAX is passed in TG4Limits (if fUseG3TMLimits is set true);
250// !! The other parameters (IFIELD, FIELDM, TMAXFD, DEEMAX, EPSIL, STMIN)
251// are ignored by Geant4.
252// ---
253
254// Geant3 desription:
255// ==================
256// NTMED Tracking medium number
257// NAME Tracking medium name
258// NMAT Material number
259// ISVOL Sensitive volume flag
260// IFIELD Magnetic field
261// FIELDM Max. field value (Kilogauss)
262// TMAXFD Max. angle due to field (deg/step)
263// STEMAX Max. step allowed
264// DEEMAX Max. fraction of energy lost in a step
265// EPSIL Tracking precision (cm)
266// STMIN Min. step due to continuos processes (cm)
267//
268// IFIELD = 0 if no magnetic field; IFIELD = -1 if user decision in GUSWIM;
269// IFIELD = 1 if tracking performed with GRKUTA; IFIELD = 2 if tracking
270// performed with GHELIX; IFIELD = 3 if tracking performed with GHELX3.
271// ---
272
e5967ab3 273 G4String namein = fGeometryServices->CutMaterialName(name);
274
2817d3e2 275 kmed = ++fMediumCounter;
276
277 // write token to the output file
278 if (fWriteGeometry)
279 fOutputManager->WriteGstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd,
280 stemax, deemax, epsil, stmin, 0, 0);
281
282 G4gstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
283 epsil, stmin, 0, fUseG3TMLimits);
284 // !! instead of the nbuf argument the bool fIsG3Default is passed
285
e5967ab3 286 // generate new unique name
287 G4String newName
288 = fGeometryServices
289 ->GenerateLimitsName(kmed, namein, fMaterialNameVector[nmat-1]);
290 fMediumNameVector.push_back(newName);
291
2817d3e2 292 if (nbuf > 0) {
293 G4String medName = name;
294 G4String text
295 = "TG4GeometryManager: user defined parameters for medium ";
296 text = text + medName;
297 text = text + " are ignored by Geant4.";
298 TG4Globals::Warning(text);
299 }
300}
301
302
f45653e2 303//_____________________________________________________________________________
304void TG4GeometryManager::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
305 Double_t thetaY, Double_t phiY, Double_t thetaZ, Double_t phiZ)
2817d3e2 306{
307// Creates G4RotationMatrix.
308// ---
309
310 krot = ++fMatrixCounter;
311
312 // write token to the output file
313 if (fWriteGeometry)
314 fOutputManager->WriteGsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
315
316 G4gsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
317}
318
319
f45653e2 320//_____________________________________________________________________________
321void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
322 Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
323{
324// Single precision interface.
325// ---
326
42b91f68 327 //TG4Globals::Warning("TG4GeometryManager::Matrix in single precision.");
f45653e2 328
329 Double_t dthetaX = thetaX;
330 Double_t dphiX = phiX;
331 Double_t dthetaY = thetaY;
332 Double_t dphiY = phiY;
333 Double_t dthetaZ = thetaZ;
334 Double_t dphiZ = phiZ;
335
336 Matrix(krot, dthetaX, dphiX, dthetaY, dphiY, dthetaZ, dphiZ);
337}
338
339
340//_____________________________________________________________________________
2817d3e2 341void TG4GeometryManager::Ggclos()
f45653e2 342{
2817d3e2 343// Sets the top VTE in temporary G3 volume table.
344// Close geometry output file (if fWriteGeometry is set true).
345//
346// Geant3 desription:
347// ==================
348// close out the geometry
349// ---
350
351 if (fWriteGeometry) fOutputManager->WriteGgclos();
352
353 G4ggclos();
354}
355
356
f45653e2 357//_____________________________________________________________________________
2817d3e2 358void TG4GeometryManager::Gfmate(Int_t imat, char *name, Float_t &a,
359 Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl,
360 Float_t* ubuf, Int_t& nbuf)
361{
362// Geant3 desription:
363// ==================
364// Return parameters for material IMAT
365// ---
366
367 G4Material* material = G3Mat.get(imat);
368
369 if (material) {
370 // to do: change this correctly
371 // !! unsafe conversion
372 const char* chName = material->GetName();
373 name = (char*)chName;
154fc5a5 374 a = fGeometryServices->GetEffA(material);
375 z = fGeometryServices->GetEffZ(material);
2817d3e2 376
377 dens = material->GetDensity();
f1bdb708 378 dens /= TG4G3Units::MassDensity();
2817d3e2 379
380 radl = material->GetRadlen();
f1bdb708 381 radl /= TG4G3Units::Length();
2817d3e2 382
383 // the following parameters are not defined in Geant4
384 absl = 0.;
385 ubuf = 0;
386 nbuf = 0;
387 }
388 else {
389 TG4Globals::Exception(
390 "TG4GeometryManager::Gfmate: material has not been found.");
391 }
392}
393
394
f45653e2 395//_____________________________________________________________________________
2817d3e2 396void TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
397 Float_t parval)
398{
42b91f68 399// Write token to the output file only,
400// the method is performed by TG4PhysicsManager.
2817d3e2 401// ---
402
2817d3e2 403 if (fWriteGeometry)
404 fOutputManager->WriteGstpar(itmed, param, parval);
2817d3e2 405}
406
407
f45653e2 408//_____________________________________________________________________________
ad390979 409void TG4GeometryManager::SetCerenkov(Int_t itmed, Int_t npckov,
410 Float_t* ppckov, Float_t* absco, Float_t* effic,
411 Float_t* rindex)
2817d3e2 412{
413//
414// Geant3 desription:
415// ==================
416//
417// Stores the tables for UV photon tracking in medium ITMED
418// Please note that it is the user's responsability to
419// provide all the coefficients:
420//
421//
422// ITMED Tracking medium number
423// NPCKOV Number of bins of each table
424// PPCKOV Value of photon momentum (in GeV)
425// ABSCO Absorbtion coefficients
426// dielectric: absorbtion length in cm
427// metals : absorbtion fraction (0<=x<=1)
428// EFFIC Detection efficiency for UV photons
429// RINDEX Refraction index (if=0 metal)
430// ---
431
154fc5a5 432 G4double* ppckovDbl = fGeometryServices->CreateG4doubleArray(ppckov, npckov);
433 G4double* abscoDbl = fGeometryServices->CreateG4doubleArray(absco, npckov);
434 G4double* efficDbl = fGeometryServices->CreateG4doubleArray(effic, npckov);
435 G4double* rindexDbl = fGeometryServices->CreateG4doubleArray(rindex, npckov);
2817d3e2 436
437 // add units
438 G4int i;
439 for (i=0; i<npckov; i++) {
f1bdb708 440 ppckovDbl[i] = ppckovDbl[i]*TG4G3Units::Energy();
441 abscoDbl[i] = abscoDbl[i]*TG4G3Units::Length();
2817d3e2 442 }
443
444 // create material properties table
445 G4MaterialPropertiesTable* table = new G4MaterialPropertiesTable();
446 table->AddProperty("ABSLENGTH", ppckovDbl, abscoDbl, npckov);
447 // used in G4OpAbsorption process
448 table->AddProperty("EFFICIENCY", ppckovDbl, efficDbl, npckov);
449 // used in G4OpBoundary process
450 table->AddProperty("RINDEX", ppckovDbl, rindexDbl, npckov);
451 // used in G4Cerenkov, G4OpRayleigh, G4OpBoundary
452
453 // get material of medium from table
454 G3MedTableEntry* medium = G3Med.get(itmed);
455 if (!medium) {
ad390979 456 G4String text = "TG4GeometryManager::SetCerenkov: \n";
2817d3e2 457 text = text + " Medium not found.";
458 G4Exception(text);
459 }
460 G4Material* material = medium->GetMaterial();
461
462 // set material properties table
463 material->SetMaterialPropertiesTable(table);
464
465 G4cout << "The tables for UV photon tracking set for "
3c7cd15a 466 << material->GetName() << G4endl;
2817d3e2 467 for (i=0; i<npckov; i++)
3c7cd15a 468 G4cout << ppckovDbl[i] << " " << rindexDbl[i] << G4endl;
2817d3e2 469
470 delete ppckovDbl;
471 delete abscoDbl;
472 delete efficDbl;
473 delete rindexDbl;
474}
475
476
f45653e2 477//_____________________________________________________________________________
2817d3e2 478void TG4GeometryManager::Gsdvn(const char *name, const char *mother,
479 Int_t ndiv, Int_t iaxis)
480{
481// Geant3 desription:
482// ==================
483// NAME Volume name
484// MOTHER Mother volume name
485// NDIV Number of divisions
486// IAXIS Axis value
487//
488// X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
489// It divides a previously defined volume.
490// ---
491
492 // write token to the output file
493 if (fWriteGeometry)
494 fOutputManager->WriteGsdvn(name, mother, ndiv, iaxis);
495
154fc5a5 496 G4gsdvn(fGeometryServices->CutName(name),
497 fGeometryServices->CutName(mother), ndiv, iaxis);
2817d3e2 498
499 // register name in name map
154fc5a5 500 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 501}
502
503
f45653e2 504//_____________________________________________________________________________
2817d3e2 505void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
f45653e2 506 Int_t ndiv, Int_t iaxis, Double_t c0i, Int_t numed)
2817d3e2 507{
508// Geant3 desription:
509// ==================
510// DIVIDES MOTHER INTO NDIV DIVISIONS CALLED NAME
511// ALONG AXIS IAXIS STARTING AT COORDINATE VALUE C0.
512// THE NEW VOLUME CREATED WILL BE MEDIUM NUMBER NUMED.
513// ---
514
515 // write token to the output file
516 if (fWriteGeometry)
517 fOutputManager->WriteGsdvn2(name, mother, ndiv, iaxis, c0i, numed);
518
154fc5a5 519 G4gsdvn2(fGeometryServices->CutName(name),
520 fGeometryServices->CutName(mother), ndiv, iaxis, c0i, numed);
2817d3e2 521
522 // register name in name map
154fc5a5 523 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 524}
525
526
f45653e2 527//_____________________________________________________________________________
528void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
529 Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed)
530{
531// Single precision interface.
532// ---
533
42b91f68 534 //TG4Globals::Warning("TG4GeometryManager::Gsdvn2 in single precision.");
f45653e2 535
536 G4double dc0i = c0i;
537
538 Gsdvn2(name, mother, ndiv, iaxis, dc0i, numed);
539}
540
541
542//_____________________________________________________________________________
2817d3e2 543void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
f45653e2 544 Double_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
2817d3e2 545{
546// Geant3 desription:
547// ==================
548// Divides MOTHER into divisions called NAME along
549// axis IAXIS in steps of STEP. If not exactly divisible
550// will make as many as possible and will centre them
551// with respect to the mother. Divisions will have medium
552// number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
553// NDVMX is the expected maximum number of divisions
554// (If 0, no protection tests are performed)
555// ---
556
557 // write token to the output file
558 if (fWriteGeometry)
559 fOutputManager->WriteGsdvt(name, mother, step, iaxis, numed, ndvmx);
560
154fc5a5 561 G4gsdvt(fGeometryServices->CutName(name),
562 fGeometryServices->CutName(mother), step, iaxis, numed, ndvmx);
2817d3e2 563
564 // register name in name map
154fc5a5 565 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 566}
567
568
f45653e2 569//_____________________________________________________________________________
570void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
571 Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
572{
573// Single precision interface.
574// ---
575
42b91f68 576 //TG4Globals::Warning("TG4GeometryManager::Gsdvt in single precision.");
f45653e2 577
578 G4double dstep = step;
579
580 Gsdvt(name, mother, dstep, iaxis, numed, ndvmx);
581}
582
583
584//_____________________________________________________________________________
2817d3e2 585void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
f45653e2 586 Double_t step, Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx)
2817d3e2 587{
588// Geant3 desription:
589// ==================
590// Create a new volume by dividing an existing one
591//
592// Divides MOTHER into divisions called NAME along
593// axis IAXIS starting at coordinate value C0 with step
594// size STEP.
595// The new volume created will have medium number NUMED.
596// If NUMED is 0, NUMED of mother is taken.
597// NDVMX is the expected maximum number of divisions
598// (If 0, no protection tests are performed)
599// ---
600
601 // write token to the output file
602 if (fWriteGeometry)
603 fOutputManager->WriteGsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
604
154fc5a5 605 G4gsdvt2(fGeometryServices->CutName(name),
606 fGeometryServices->CutName(mother), step, iaxis, c0, numed, ndvmx);
2817d3e2 607
608 // register name in name map
154fc5a5 609 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 610}
611
612
f45653e2 613//_____________________________________________________________________________
614void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
615 Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
616{
617// Single precision interface.
618// ---
619
42b91f68 620 //TG4Globals::Warning("TG4GeometryManager::Gsdvt2 in single precision.");
f45653e2 621
622 G4double dstep = step;
623 G4double dc0 = c0;
624
625 Gsdvt2(name, mother, dstep, iaxis, dc0, numed, ndvmx);
626}
627
628
629//_____________________________________________________________________________
2817d3e2 630void TG4GeometryManager::Gsord(const char *name, Int_t iax)
631{
632// No corresponding action in G4.
633//
634// Geant3 desription:
635// ==================
636// Flags volume CHNAME whose contents will have to be ordered
637// along axis IAX, by setting the search flag to -IAX
638// IAX = 1 X axis
639// IAX = 2 Y axis
640// IAX = 3 Z axis
641// IAX = 4 Rxy (static ordering only -> GTMEDI)
642// IAX = 14 Rxy (also dynamic ordering -> GTNEXT)
643// IAX = 5 Rxyz (static ordering only -> GTMEDI)
644// IAX = 15 Rxyz (also dynamic ordering -> GTNEXT)
645// IAX = 6 PHI (PHI=0 => X axis)
646// IAX = 7 THETA (THETA=0 => Z axis)
647// ---
648
649 TG4Globals::Warning("TG4GeometryManager::Gsord: dummy method.");
650}
651
652
f45653e2 653//_____________________________________________________________________________
2817d3e2 654void TG4GeometryManager::Gspos(const char *vname, Int_t num,
f45653e2 655 const char *vmoth, Double_t x, Double_t y, Double_t z, Int_t irot,
2817d3e2 656 const char *vonly)
657{
658// Geant3 desription:
659// ==================
660// Position a volume into an existing one
661//
662// NAME Volume name
663// NUMBER Copy number of the volume
664// MOTHER Mother volume name
665// X X coord. of the volume in mother ref. sys.
666// Y Y coord. of the volume in mother ref. sys.
667// Z Z coord. of the volume in mother ref. sys.
668// IROT Rotation matrix number w.r.t. mother ref. sys.
669// ONLY ONLY/MANY flag
670//
671// It positions a previously defined volume in the mother.
672// ---
673
674 // write token to the output file
675 if (fWriteGeometry)
676 fOutputManager->WriteGspos(vname, num, vmoth, x, y, z, irot, vonly);
677
154fc5a5 678 G4gspos(fGeometryServices->CutName(vname), num,
679 fGeometryServices->CutName(vmoth), x, y, z, irot, vonly);
2817d3e2 680
681 // register name in name map
154fc5a5 682 fNameMap.AddName(fGeometryServices->CutName(vname));
2817d3e2 683}
684
685
f45653e2 686//_____________________________________________________________________________
687void TG4GeometryManager::Gspos(const char *vname, Int_t num,
688 const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot,
689 const char *vonly)
690{
691// Single precision interface.
692// ---
693
42b91f68 694 //TG4Globals::Warning("TG4GeometryManager::Gspos in single precision.");
f45653e2 695
696 G4double dx = x;
697 G4double dy = y;
698 G4double dz = z;
699
700 Gspos(vname, num, vmoth, dx, dy, dz, irot, vonly);
701}
702
703
704//_____________________________________________________________________________
2817d3e2 705void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
f45653e2 706 const char *mother, Double_t x, Double_t y, Double_t z, Int_t irot,
707 const char *konly, Double_t *upar, Int_t np )
2817d3e2 708{
709// Geant3 desription:
710// ==================
711// Place a copy of generic volume NAME with user number
712// NR inside MOTHER, with its parameters UPAR(1..NP)
713// ---
714
2817d3e2 715 // write token to the output file
716 if (fWriteGeometry)
f45653e2 717 fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
2817d3e2 718
154fc5a5 719 G4gsposp(fGeometryServices->CutName(name), nr,
720 fGeometryServices->CutName(mother), x, y, z, irot, konly,
f45653e2 721 upar, np);
2817d3e2 722
723 // register name in name map
154fc5a5 724 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 725}
726
727
f45653e2 728//_____________________________________________________________________________
729void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
730 const char *mother, Float_t x, Float_t y, Float_t z, Int_t irot,
731 const char *konly, Float_t *upar, Int_t np )
732{
733// Single precision interface.
734// ---
735
42b91f68 736 //TG4Globals::Warning("TG4GeometryManager::Gsposp in single precision.");
f45653e2 737
738 G4double dx = x;
739 G4double dy = y;
740 G4double dz = z;
741 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, np);
742
743 Gsposp(name, nr, mother, dx, dy, dz, irot, konly, parin, np);
744
745 delete [] parin;
746}
747
748
749//_____________________________________________________________________________
2817d3e2 750Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
f45653e2 751 Int_t nmed, Double_t *upar, Int_t npar)
2817d3e2 752{
753// Geant3 desription:
754// ==================
755// NAME Volume name
756// SHAPE Volume type
757// NUMED Tracking medium number
758// NPAR Number of shape parameters
759// UPAR Vector containing shape parameters
760//
761// It creates a new volume in the JVOLUM data structure.
762// ---
763
2817d3e2 764 // write token to the output file
765 if (fWriteGeometry)
f45653e2 766 fOutputManager->WriteGsvolu(name, shape, nmed, upar, npar);
2817d3e2 767
154fc5a5 768 G4gsvolu(fGeometryServices->CutName(name),
f45653e2 769 fGeometryServices->CutName(shape), nmed, upar, npar);
2817d3e2 770
771 // register name in name map
154fc5a5 772 fNameMap.AddName(fGeometryServices->CutName(name));
2817d3e2 773
774 return 0;
775}
776
777
f45653e2 778//_____________________________________________________________________________
779Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
780 Int_t nmed, Float_t *upar, Int_t npar)
781{
782// Single precision interface.
783// ---
784
42b91f68 785 //TG4Globals::Warning("TG4GeometryManager::Gsvolu in single precision.");
f45653e2 786
787 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, npar);
788
789 G4int result
790 = Gsvolu(name, shape, nmed, parin, npar);
791
792 delete [] parin;
793
794 return result;
795}
796
797
798//_____________________________________________________________________________
57f88f6f 799void TG4GeometryManager::WriteEuclid(const char* fileName,
800 const char* topVolName, Int_t number, Int_t nlevel)
2817d3e2 801{
802// Geant3 desription:
803// ==================
804//
805// ******************************************************************
806// * *
807// * Write out the geometry of the detector in EUCLID file format *
808// * *
809// * filnam : will be with the extension .euc *
810// * topvol : volume name of the starting node *
811// * number : copy number of topvol (relevant for gsposp) *
812// * nlevel : number of levels in the tree structure *
813// * to be written out, starting from topvol *
814// * *
815// * Author : M. Maire *
816// * *
817// ******************************************************************
818//
819// File filnam.tme is written out with the definitions of tracking
820// medias and materials.
821// As to restore original numbers for materials and medias, program
822// searches in the file euc_medi.dat and comparing main parameters of
823// the mat. defined inside geant and the one in file recognizes them
824// and is able to take number from file. If for any material or medium,
825// this procedure fails, ordering starts from 1.
826// Arrays IOTMED and IOMATE are used for this procedure
827// ---
828
829 TG4Globals::Warning(
830 "TG4GeometryManager::WriteEuclid(..) is not yet implemented.");
831}
832
833
2817d3e2 834//=============================================================================
835//
836// public methods - Geant4 only
837//
838//=============================================================================
839
840
f45653e2 841//_____________________________________________________________________________
2817d3e2 842G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
843{
844// Creates G4 geometry objects according to the G3VolTable
d499787d 845// and returns the world physical volume.
2817d3e2 846// ---
847
848 // set the first entry in the G3Vol table
849 Ggclos();
850 G3VolTableEntry* first = G3Vol.GetFirstVTE();
d499787d 851
2817d3e2 852 // create G4 geometry
853 G3toG4BuildTree(first,0);
e5967ab3 854
855 // fill medium map
856 FillMediumMap();
2817d3e2 857
858 // print G3 volume table statistics
859 G3Vol.VTEStat();
860
861 // print G4 geometry statistics
862 G4cout << "G4 Stat: instantiated "
154fc5a5 863 << fGeometryServices->NofG4LogicalVolumes()
864 << " logical volumes \n"
2817d3e2 865 << " "
154fc5a5 866 << fGeometryServices->NofG4PhysicalVolumes()
867 << " physical volumes" << G4endl;
2817d3e2 868
869 // position the first entry
870 // (in Geant3 the top volume cannot be positioned)
871 //
d499787d 872 if (!fGeometryServices->GetWorld()) {
873 G4VPhysicalVolume* world
874 = new G4PVPlacement(0, G4ThreeVector(), first->GetName(),
875 first->GetLV(), 0, false, 0);
876 fGeometryServices->SetWorld(world);
2817d3e2 877 }
d499787d 878 return fGeometryServices->GetWorld();
2817d3e2 879}
880
881
e5967ab3 882//_____________________________________________________________________________
883void TG4GeometryManager::SetUserLimits(const TG4G3CutVector& cuts,
884 const TG4G3ControlVector& controls) const
885{
886// Sets user limits defined in G3MedTable for all logical volumes.
887// ---
888
889 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
890
891 for (G4int i=0; i<lvStore->size(); i++) {
892 G4LogicalVolume* lv = (*lvStore)[i];
893
894 // get limits from G3Med
895 G4int mediumIndex = fGeometryServices->GetMediumId(lv);
896 G4UserLimits* limits = G3Med.get(mediumIndex)->GetLimits();
897 TG4Limits* tg4Limits = fGeometryServices->GetLimits(limits);
898
899 // get tracking medium name
900 G4String name = fMediumNameVector[mediumIndex-1];
901
902 if (tg4Limits)
903 tg4Limits->SetName(name);
904 else {
905 tg4Limits = fGeometryServices->FindLimits(name, true);
906 if (!tg4Limits)
907 tg4Limits = new TG4Limits(name, cuts, controls);
908 }
909
910 // update controls in limits according to the setup
911 // in the passed vector
912 tg4Limits->Update(controls);
913
914 // set limits to logical volume
915 lv->SetUserLimits(tg4Limits);
916 }
917}
918
f45653e2 919//_____________________________________________________________________________
154fc5a5 920void TG4GeometryManager::ReadG3Geometry(G4String filePath)
921{
922// Processes g3calls.dat file and fills G3 tables.
923// ---
924
925 // add verbose
926 G4cout << "Reading the call list file " << filePath << "..." << G4endl;
927 G3CLRead(filePath, NULL);
928 G4cout << "Call list file read completed. Build geometry" << G4endl;
929}
930
931
f45653e2 932//_____________________________________________________________________________
2817d3e2 933void TG4GeometryManager::UseG3TrackingMediaLimits()
934{
935// Sets fUseG3TMLimits option.
936// !! This method has to be called only before starting
937// creating geometry.
938// ---
939
940 if (fMediumCounter == 0) {
941 fUseG3TMLimits = true;
942 }
943 else {
944 G4String text = "TG4GeometryManager::UseG3TMLimits: \n";
945 text = text + " It is too late to set G3 defaults. \n";
946 text = text + " Some media has been already processed.";
947 TG4Globals::Exception(text);
948 }
949}
950
951
f45653e2 952//_____________________________________________________________________________
2817d3e2 953void TG4GeometryManager::ClearG3Tables()
954{
955// Clears G3 volumes, materials, rotations(?) tables
956// and sensitive volumes vector.
957// The top volume is kept in the vol table.
958// ---
959
960 // clear volume table
961 // but keep the top volume in the table
962 G3VolTableEntry* top = G3Vol.GetFirstVTE();
963 G4String name = top->GetName();
964 G4String shape = top->GetShape();
965 G3VolTableEntry* keep
966 = new G3VolTableEntry(name, shape, top->GetRpar(), top->GetNpar(),
967 top->GetNmed(), top->GetSolid(), false);
968 keep->SetLV(top->GetLV());
969 G3Vol.Clear();
970 G3Vol.PutVTE(keep);
971
972 // clear other tables
2817d3e2 973 //G3Rot.Clear();
974 G3SensVol.clear();
975}
976
977
f45653e2 978//_____________________________________________________________________________
2817d3e2 979void TG4GeometryManager::ClearG3TablesFinal()
980{
981// Clears G3 medias and volumes tables
982// (the top volume is removed from the vol table)
983// ---
984
e5967ab3 985 G3Mat.Clear();
2817d3e2 986 G3Med.Clear();
987 G3Vol.Clear();
2817d3e2 988}
989
990
f45653e2 991//_____________________________________________________________________________
2817d3e2 992void TG4GeometryManager::OpenOutFile(G4String filePath)
993{
994// Opens output file.
995// ---
996
997 fOutputManager->OpenFile(filePath);
998}
999
1000
f45653e2 1001//_____________________________________________________________________________
08b8559d 1002void TG4GeometryManager::CloseOutFile()
1003{
1004// Closes output file.
1005// ---
1006
1007 fOutputManager->CloseFile();
1008}
1009
1010
f45653e2 1011//_____________________________________________________________________________
2817d3e2 1012void TG4GeometryManager::SetWriteGeometry(G4bool writeGeometry)
1013{
1014// Controls geometry output.
1015// ---
1016
1017 fWriteGeometry = writeGeometry;
1018}
1019
1020
f45653e2 1021//_____________________________________________________________________________
2817d3e2 1022void TG4GeometryManager::SetMapSecond(const G4String& name)
1023{
1024// Sets the second name for the map of volumes names.
1025// ---
1026
1027 fNameMap.SetSecond(name);
1028}