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