4 // Author: V. Berejnoi, I. Hrivnacova
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;
11 // materials, tracking media support
12 // added by I.Hrivnacova, 27.5.1999.
14 #include "TG4GeometryManager.h"
15 #include "TG4GeometryOutputManager.h"
16 #include "TG4GeometryServices.h"
17 #include "TG4Limits.h"
18 #include "TG4G3Units.h"
19 #include "TG4G3CutVector.h"
20 #include "TG4G3ControlVector.h"
21 #include "TG4Globals.h"
24 #include <G3toG4MANY.hh>
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>
33 #include <G4LogicalVolumeStore.hh>
34 #include <G4PVPlacement.hh>
35 #include <G4Material.hh>
36 #include <G4MaterialPropertiesTable.hh>
37 #include <G4Element.hh>
39 // extern global method from g3tog4
40 void G3CLRead(G4String &, char *);
42 TG4GeometryManager* TG4GeometryManager::fgInstance = 0;
43 const G4double TG4GeometryManager::fgLimitDensity = 0.001*(g/cm3);
44 const G4double TG4GeometryManager::fgMaxStep = 10*cm;
46 //_____________________________________________________________________________
47 TG4GeometryManager::TG4GeometryManager()
48 : TG4Verbose("geometryManager"),
52 fUseG3TMLimits(false),
57 TG4Globals::Exception(
58 "TG4GeometryManager: attempt to create two instances of singleton.");
62 = new TG4GeometryOutputManager();
65 = new TG4GeometryServices(&fMediumMap, &fNameMap);
69 // instantiate the default element table
70 //TG4ElementTable::Instance();
73 //_____________________________________________________________________________
74 TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right)
75 : TG4Verbose("geometryManager") {
77 TG4Globals::Exception(
78 "Attempt to copy TG4GeometryManager singleton.");
82 //_____________________________________________________________________________
83 TG4GeometryManager::~TG4GeometryManager() {
85 delete fOutputManager;
86 delete fGeometryServices;
89 //=============================================================================
93 //=============================================================================
96 //_____________________________________________________________________________
98 TG4GeometryManager::operator=(const TG4GeometryManager& right)
100 // check assignement to self
101 if (this == &right) return *this;
103 TG4Globals::Exception(
104 "Attempt to assign TG4GeometryManager singleton.");
110 //=============================================================================
114 //=============================================================================
116 //_____________________________________________________________________________
117 void TG4GeometryManager::FillMediumMap()
119 // Maps G3 tracking medium IDs to volumes names.
123 static G4int done = 0;
125 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
127 for (G4int i=done; i<lvStore->size(); i++) {
128 G4String name = ((*lvStore)[i])->GetName();
130 G4String g3Name(name);
131 if (name.find("_refl")) g3Name = g3Name.substr(0, g3Name.find("_refl"));
133 G4int mediumID = G3Vol.GetVTE(g3Name)->GetNmed();
134 fMediumMap.Add(name, mediumID);
137 done = lvStore->size();
141 //=============================================================================
143 // public methods - AliMC implementation
145 //=============================================================================
148 //_____________________________________________________________________________
149 void 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,
153 // Creates G4Material.
154 // !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
156 // absl - this parameter is ignored by GEANT3, too
159 kmat = ++fMaterialCounter;
160 G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf);
161 G4String namein = fGeometryServices->CutMaterialName(name);
163 // write token to the output file
165 fOutputManager->WriteGsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
167 // create new material only if it does not yet exist
168 G4Material* material = fGeometryServices->FindMaterial(a, z, dens);
171 if (VerboseLevel() > 1) {
172 G4cout << "!!! Material " << namein << " already exists as "
173 << material->GetName() << G4endl;
175 G3Mat.put(kmat, material);
178 G4gsmate(kmat, namein, a, z, dens, radl, nwbuf, bufin);
180 // save the original material name
181 fMaterialNameVector.push_back(namein);
187 = "TG4GeometryManager: user defined parameters for material ";
188 text = text + namein;
189 text = text + " are ignored by Geant4.";
190 TG4Globals::Warning(text);
195 //_____________________________________________________________________________
196 void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a,
197 Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
199 // Creates G4Material composed of more elements.
200 // !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
202 // absl - this parameter is ignored by GEANT3, too
205 Int_t npar = abs(nlmat);
206 G4double *ain = fGeometryServices->CreateG4doubleArray(a, npar);
207 G4double *zin = fGeometryServices->CreateG4doubleArray(z, npar);
208 G4double *wmatin = fGeometryServices->CreateG4doubleArray(wmat, npar);
209 G4String namein = fGeometryServices->CutMaterialName(name);
211 kmat = ++fMaterialCounter;
213 // write token to the output file
215 fOutputManager->WriteGsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
217 // create new material only if it does not yet exist
219 = fGeometryServices->FindMaterial(ain, zin, dens, nlmat, wmatin);
222 if (VerboseLevel() > 1) {
223 G4cout << "!!! Material " << namein << " already exists as "
224 << material->GetName() << G4endl;
226 G3Mat.put(kmat, material);
229 G4gsmixt(kmat, namein, ain, zin, dens, nlmat, wmatin);
231 // save the original material name
232 fMaterialNameVector.push_back(namein);
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
240 // wmatin may be modified
241 for (G4int i=0; i<npar; i++) wmat[i] = wmatin[i];
248 //_____________________________________________________________________________
249 void 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)
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;
257 // ISVOL is used for builing G3SensVolVector;
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.
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)
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.
282 G4String namein = fGeometryServices->CutMaterialName(name);
284 kmed = ++fMediumCounter;
286 // write token to the output file
288 fOutputManager->WriteGstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd,
289 stemax, deemax, epsil, stmin, 0, 0);
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
295 // generate new unique name
298 ->GenerateLimitsName(kmed, namein, fMaterialNameVector[nmat-1]);
299 fMediumNameVector.push_back(newName);
302 G4String medName = name;
304 = "TG4GeometryManager: user defined parameters for medium ";
305 text = text + medName;
306 text = text + " are ignored by Geant4.";
307 TG4Globals::Warning(text);
312 //_____________________________________________________________________________
313 void TG4GeometryManager::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
314 Double_t thetaY, Double_t phiY, Double_t thetaZ, Double_t phiZ)
316 // Creates G4RotationMatrix.
319 krot = ++fMatrixCounter;
321 // write token to the output file
323 fOutputManager->WriteGsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
325 G4gsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
329 //_____________________________________________________________________________
330 void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
331 Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
333 // Single precision interface.
336 //TG4Globals::Warning("TG4GeometryManager::Matrix in single precision.");
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;
345 Matrix(krot, dthetaX, dphiX, dthetaY, dphiY, dthetaZ, dphiZ);
349 //_____________________________________________________________________________
350 void TG4GeometryManager::Ggclos()
352 // Sets the top VTE in temporary G3 volume table.
353 // Close geometry output file (if fWriteGeometry is set true).
355 // Geant3 desription:
356 // ==================
357 // close out the geometry
360 if (fWriteGeometry) fOutputManager->WriteGgclos();
366 //_____________________________________________________________________________
367 void 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)
371 // Geant3 desription:
372 // ==================
373 // Return parameters for material IMAT
376 G4Material* material = G3Mat.get(imat);
379 // to do: change this correctly
380 // !! unsafe conversion
381 const char* chName = material->GetName();
382 name = (char*)chName;
383 a = fGeometryServices->GetEffA(material);
384 z = fGeometryServices->GetEffZ(material);
386 dens = material->GetDensity();
387 dens /= TG4G3Units::MassDensity();
389 radl = material->GetRadlen();
390 radl /= TG4G3Units::Length();
392 // the following parameters are not defined in Geant4
398 TG4Globals::Exception(
399 "TG4GeometryManager::Gfmate: material has not been found.");
404 //_____________________________________________________________________________
405 void TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
408 // Write token to the output file only,
409 // the method is performed by TG4PhysicsManager.
413 fOutputManager->WriteGstpar(itmed, param, parval);
417 //_____________________________________________________________________________
418 void TG4GeometryManager::SetCerenkov(Int_t itmed, Int_t npckov,
419 Float_t* ppckov, Float_t* absco, Float_t* effic,
423 // Geant3 desription:
424 // ==================
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:
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)
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);
448 for (i=0; i<npckov; i++) {
449 ppckovDbl[i] = ppckovDbl[i]*TG4G3Units::Energy();
450 abscoDbl[i] = abscoDbl[i]*TG4G3Units::Length();
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
462 // get material of medium from table
463 G3MedTableEntry* medium = G3Med.get(itmed);
465 G4String text = "TG4GeometryManager::SetCerenkov: \n";
466 text = text + " Medium not found.";
469 G4Material* material = medium->GetMaterial();
471 // set material properties table
472 material->SetMaterialPropertiesTable(table);
475 if (VerboseLevel() > 0) {
476 G4cout << "The tables for UV photon tracking set for "
477 << material->GetName() << G4endl;
479 for (i=0; i<npckov; i++)
480 G4cout << ppckovDbl[i] << " " << rindexDbl[i] << G4endl;
489 //_____________________________________________________________________________
490 void TG4GeometryManager::Gsdvn(const char *name, const char *mother,
491 Int_t ndiv, Int_t iaxis)
493 // Geant3 desription:
494 // ==================
496 // MOTHER Mother volume name
497 // NDIV Number of divisions
500 // X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
501 // It divides a previously defined volume.
504 // write token to the output file
506 fOutputManager->WriteGsdvn(name, mother, ndiv, iaxis);
508 G4gsdvn(fGeometryServices->CutName(name),
509 fGeometryServices->CutName(mother), ndiv, iaxis);
511 // register name in name map
512 fNameMap.AddName(fGeometryServices->CutName(name));
516 //_____________________________________________________________________________
517 void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
518 Int_t ndiv, Int_t iaxis, Double_t c0i, Int_t numed)
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.
527 // write token to the output file
529 fOutputManager->WriteGsdvn2(name, mother, ndiv, iaxis, c0i, numed);
531 G4gsdvn2(fGeometryServices->CutName(name),
532 fGeometryServices->CutName(mother), ndiv, iaxis, c0i, numed);
534 // register name in name map
535 fNameMap.AddName(fGeometryServices->CutName(name));
539 //_____________________________________________________________________________
540 void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
541 Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed)
543 // Single precision interface.
546 //TG4Globals::Warning("TG4GeometryManager::Gsdvn2 in single precision.");
550 Gsdvn2(name, mother, ndiv, iaxis, dc0i, numed);
554 //_____________________________________________________________________________
555 void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
556 Double_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
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)
569 // write token to the output file
571 fOutputManager->WriteGsdvt(name, mother, step, iaxis, numed, ndvmx);
573 G4gsdvt(fGeometryServices->CutName(name),
574 fGeometryServices->CutName(mother), step, iaxis, numed, ndvmx);
576 // register name in name map
577 fNameMap.AddName(fGeometryServices->CutName(name));
581 //_____________________________________________________________________________
582 void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
583 Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
585 // Single precision interface.
588 //TG4Globals::Warning("TG4GeometryManager::Gsdvt in single precision.");
590 G4double dstep = step;
592 Gsdvt(name, mother, dstep, iaxis, numed, ndvmx);
596 //_____________________________________________________________________________
597 void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
598 Double_t step, Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx)
600 // Geant3 desription:
601 // ==================
602 // Create a new volume by dividing an existing one
604 // Divides MOTHER into divisions called NAME along
605 // axis IAXIS starting at coordinate value C0 with 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)
613 // write token to the output file
615 fOutputManager->WriteGsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
617 G4gsdvt2(fGeometryServices->CutName(name),
618 fGeometryServices->CutName(mother), step, iaxis, c0, numed, ndvmx);
620 // register name in name map
621 fNameMap.AddName(fGeometryServices->CutName(name));
625 //_____________________________________________________________________________
626 void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
627 Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
629 // Single precision interface.
632 //TG4Globals::Warning("TG4GeometryManager::Gsdvt2 in single precision.");
634 G4double dstep = step;
637 Gsdvt2(name, mother, dstep, iaxis, dc0, numed, ndvmx);
641 //_____________________________________________________________________________
642 void TG4GeometryManager::Gsord(const char *name, Int_t iax)
644 // No corresponding action in G4.
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
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)
661 TG4Globals::Warning("TG4GeometryManager::Gsord: dummy method.");
665 //_____________________________________________________________________________
666 void TG4GeometryManager::Gspos(const char *vname, Int_t num,
667 const char *vmoth, Double_t x, Double_t y, Double_t z, Int_t irot,
670 // Geant3 desription:
671 // ==================
672 // Position a volume into an existing one
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
683 // It positions a previously defined volume in the mother.
686 // write token to the output file
688 fOutputManager->WriteGspos(vname, num, vmoth, x, y, z, irot, vonly);
690 G4gspos(fGeometryServices->CutName(vname), num,
691 fGeometryServices->CutName(vmoth), x, y, z, irot, vonly);
693 // register name in name map
694 fNameMap.AddName(fGeometryServices->CutName(vname));
698 //_____________________________________________________________________________
699 void TG4GeometryManager::Gspos(const char *vname, Int_t num,
700 const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot,
703 // Single precision interface.
706 //TG4Globals::Warning("TG4GeometryManager::Gspos in single precision.");
712 Gspos(vname, num, vmoth, dx, dy, dz, irot, vonly);
716 //_____________________________________________________________________________
717 void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
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 )
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)
727 // write token to the output file
729 fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
731 G4gsposp(fGeometryServices->CutName(name), nr,
732 fGeometryServices->CutName(mother), x, y, z, irot, konly,
735 // register name in name map
736 fNameMap.AddName(fGeometryServices->CutName(name));
740 //_____________________________________________________________________________
741 void 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 )
745 // Single precision interface.
748 //TG4Globals::Warning("TG4GeometryManager::Gsposp in single precision.");
753 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, np);
755 Gsposp(name, nr, mother, dx, dy, dz, irot, konly, parin, np);
761 //_____________________________________________________________________________
762 void TG4GeometryManager::Gsbool(const char* onlyVolName,
763 const char* manyVolName)
765 // Helps for resolving MANY.
766 // Specifies the ONLY volume that overlaps with the
767 // specified MANY and has to be substracted.
770 // write token to the output file
771 //if (fWriteGeometry)
772 // fOutputManager->WriteGsbool(onlyVolName, manyVolName);
774 G4gsbool(onlyVolName, manyVolName);
778 //_____________________________________________________________________________
779 Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
780 Int_t nmed, Double_t *upar, Int_t npar)
782 // Geant3 desription:
783 // ==================
786 // NUMED Tracking medium number
787 // NPAR Number of shape parameters
788 // UPAR Vector containing shape parameters
790 // It creates a new volume in the JVOLUM data structure.
793 // write token to the output file
795 fOutputManager->WriteGsvolu(name, shape, nmed, upar, npar);
797 G4gsvolu(fGeometryServices->CutName(name),
798 fGeometryServices->CutName(shape), nmed, upar, npar);
800 // register name in name map
801 fNameMap.AddName(fGeometryServices->CutName(name));
807 //_____________________________________________________________________________
808 Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
809 Int_t nmed, Float_t *upar, Int_t npar)
811 // Single precision interface.
814 //TG4Globals::Warning("TG4GeometryManager::Gsvolu in single precision.");
816 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, npar);
819 = Gsvolu(name, shape, nmed, parin, npar);
827 //_____________________________________________________________________________
828 void TG4GeometryManager::WriteEuclid(const char* fileName,
829 const char* topVolName, Int_t number, Int_t nlevel)
831 // Geant3 desription:
832 // ==================
834 // ******************************************************************
836 // * Write out the geometry of the detector in EUCLID file format *
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 *
844 // * Author : M. Maire *
846 // ******************************************************************
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
859 "TG4GeometryManager::WriteEuclid(..) is not yet implemented.");
863 //=============================================================================
865 // public methods - Geant4 only
867 //=============================================================================
870 //_____________________________________________________________________________
871 G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
873 // Creates G4 geometry objects according to the G3VolTable
874 // and returns the world physical volume.
877 // set the first entry in the G3Vol table
879 G3VolTableEntry* first = G3Vol.GetFirstVTE();
881 // transform MANY to Boolean solids
884 // create G4 geometry
885 G3toG4BuildTree(first,0);
890 // print G3 volume table statistics
893 // print G4 geometry statistics
894 if (VerboseLevel() > 0) {
895 G4cout << "G4 Stat: instantiated "
896 << fGeometryServices->NofG4LogicalVolumes()
897 << " logical volumes \n"
899 << fGeometryServices->NofG4PhysicalVolumes()
900 << " physical volumes" << G4endl;
903 // position the first entry
904 // (in Geant3 the top volume cannot be positioned)
906 if (!fGeometryServices->GetWorld()) {
907 G4VPhysicalVolume* world
908 = new G4PVPlacement(0, G4ThreeVector(), first->GetName(),
909 first->GetLV(), 0, false, 0);
910 fGeometryServices->SetWorld(world);
912 return fGeometryServices->GetWorld();
916 //_____________________________________________________________________________
917 void TG4GeometryManager::SetUserLimits(const TG4G3CutVector& cuts,
918 const TG4G3ControlVector& controls) const
920 // Sets user limits defined in G3MedTable for all logical volumes.
923 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
925 for (G4int i=0; i<lvStore->size(); i++) {
926 G4LogicalVolume* lv = (*lvStore)[i];
928 // get limits from G3Med
929 G4int mediumIndex = fGeometryServices->GetMediumId(lv);
930 G4UserLimits* limits = G3Med.get(mediumIndex)->GetLimits();
931 TG4Limits* tg4Limits = fGeometryServices->GetLimits(limits);
933 // get tracking medium name
934 G4String name = fMediumNameVector[mediumIndex-1];
937 tg4Limits->SetName(name);
939 tg4Limits = fGeometryServices->FindLimits(name, true);
941 tg4Limits = new TG4Limits(name, cuts, controls);
944 // limit max step for low density materials (< AIR)
945 if (lv->GetMaterial()->GetDensity() < fgLimitDensity )
946 tg4Limits->SetMaxAllowedStep(fgMaxStep);
948 // update controls in limits according to the setup
949 // in the passed vector
950 tg4Limits->Update(controls);
952 // set limits to logical volume
953 lv->SetUserLimits(tg4Limits);
954 //NO TG4 lv->SetUserLimits(0);
958 //_____________________________________________________________________________
959 void TG4GeometryManager::ReadG3Geometry(G4String filePath)
961 // Processes g3calls.dat file and fills G3 tables.
965 if (VerboseLevel() > 0) {
966 G4cout << "Reading the call list file " << filePath << "..." << G4endl;
969 G3CLRead(filePath, NULL);
971 if (VerboseLevel() > 0) {
972 G4cout << "Call list file read completed. Build geometry" << G4endl;
977 //_____________________________________________________________________________
978 void TG4GeometryManager::UseG3TrackingMediaLimits()
980 // Sets fUseG3TMLimits option.
981 // !! This method has to be called only before starting
982 // creating geometry.
985 if (fMediumCounter == 0) {
986 fUseG3TMLimits = true;
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);
997 //_____________________________________________________________________________
998 void TG4GeometryManager::ClearG3Tables()
1000 // Clears G3 volumes, materials, rotations(?) tables
1001 // and sensitive volumes vector.
1002 // The top volume is kept in the vol table.
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());
1017 // clear other tables
1023 //_____________________________________________________________________________
1024 void TG4GeometryManager::ClearG3TablesFinal()
1026 // Clears G3 medias and volumes tables
1027 // (the top volume is removed from the vol table)
1036 //_____________________________________________________________________________
1037 void TG4GeometryManager::OpenOutFile(G4String filePath)
1039 // Opens output file.
1042 fOutputManager->OpenFile(filePath);
1046 //_____________________________________________________________________________
1047 void TG4GeometryManager::CloseOutFile()
1049 // Closes output file.
1052 fOutputManager->CloseFile();
1056 //_____________________________________________________________________________
1057 void TG4GeometryManager::SetWriteGeometry(G4bool writeGeometry)
1059 // Controls geometry output.
1062 fWriteGeometry = writeGeometry;
1066 //_____________________________________________________________________________
1067 void TG4GeometryManager::SetMapSecond(const G4String& name)
1069 // Sets the second name for the map of volumes names.
1072 fNameMap.SetSecond(name);