4 // C++ interface to Geant3 basic routines
5 // for building Geant4 geometry
7 // by V. Berejnoi, 25.2.1999
8 // materials, tracking media support
9 // added by I.Hrivnacova, 27.5.1999
11 #include "TG4GeometryManager.h"
12 #include "TG4GeometryOutputManager.h"
13 #include "TG4GeometryServices.h"
14 #include "TG4G3PhysicsManager.h"
15 #include "TG4G3Units.h"
16 #include "TG4VSensitiveDetector.h"
17 #include "TG4Limits.h"
18 #include "TG4Globals.h"
21 #include <G3toG4BuildTree.hh>
22 #include <G3VolTable.hh>
23 #include <G3RotTable.hh>
24 #include <G3EleTable.hh>
25 #include <G3MatTable.hh>
26 #include <G3MedTable.hh>
27 #include <G3SensVolVector.hh>
29 #include <G4VSensitiveDetector.hh>
30 #include <G4LogicalVolumeStore.hh>
31 #include <G4PVPlacement.hh>
32 #include <G4Material.hh>
33 #include <G4MaterialPropertiesTable.hh>
34 #include <G4Element.hh>
36 // extern global method from g3tog4
37 void G3CLRead(G4String &, char *);
39 TG4GeometryManager* TG4GeometryManager::fgInstance = 0;
41 //_____________________________________________________________________________
42 TG4GeometryManager::TG4GeometryManager()
46 fUseG3TMLimits(false),
51 TG4Globals::Exception(
52 "TG4GeometryManager: attempt to create two instances of singleton.");
55 fOutputManager = new TG4GeometryOutputManager();
57 fGeometryServices = new TG4GeometryServices(&fMediumIdVector, &fNameMap);
61 // instantiate the default element table
62 //TG4ElementTable::Instance();
65 //_____________________________________________________________________________
66 TG4GeometryManager::TG4GeometryManager(const TG4GeometryManager& right) {
68 TG4Globals::Exception(
69 "Attempt to copy TG4GeometryManager singleton.");
73 //_____________________________________________________________________________
74 TG4GeometryManager::~TG4GeometryManager() {
76 delete fOutputManager;
77 delete fGeometryServices;
80 //=============================================================================
84 //=============================================================================
87 //_____________________________________________________________________________
89 TG4GeometryManager::operator=(const TG4GeometryManager& right)
91 // check assignement to self
92 if (this == &right) return *this;
94 TG4Globals::Exception(
95 "Attempt to assign TG4GeometryManager singleton.");
101 //=============================================================================
105 //=============================================================================
108 //_____________________________________________________________________________
109 void TG4GeometryManager::GstparCut(G4int itmed, TG4G3Cut par, G4double parval)
111 // Sets special tracking medium parameter.
112 // It is applied to all logical volumes that use the specified
116 // get medium from table
117 G3MedTableEntry* medium = G3Med.get(itmed);
119 G4String text = "TG4GeometryManager::GstparCut: \n";
120 text = text + " Medium not found.";
124 // get/create user limits
125 G4UserLimits* limits = medium->GetLimits();
126 TG4Limits* tg4Limits;
128 tg4Limits = dynamic_cast<TG4Limits*> (limits);
130 G4Exception("TG4GeometryManager::GstparCut: Wrong limits type.");
133 tg4Limits = new TG4Limits();
134 medium->SetLimits(tg4Limits);
137 G4cout << "TG4GeometryManager::GstparCut: new TG4Limits() for medium "
138 << itmed << " has been created." << G4endl;
141 tg4Limits->SetG3Cut(par, parval*GeV);
145 //_____________________________________________________________________________
146 void TG4GeometryManager::GstparControl(G4int itmed, TG4G3Control par,
149 // Sets special tracking medium parameter.
150 // It is applied to all logical volumes that use the specified
154 // get medium from table
155 G3MedTableEntry* medium = G3Med.get(itmed);
157 G4String text = "TG4GeometryManager::GstparControl: \n";
158 text = text + " Medium not found.";
162 // get/create user limits
163 G4UserLimits* limits = medium->GetLimits();
164 TG4Limits* tg4Limits;
166 tg4Limits = dynamic_cast<TG4Limits*> (limits);
168 G4Exception("TG4GeometryManager::GstparControl: Wrong limits type.");
171 tg4Limits = new TG4Limits();
172 medium->SetLimits(tg4Limits);
175 G4cout << "TG4GeometryManager::GstparControl: new TG4Limits() for medium"
176 << itmed << " has been created." << G4endl;
179 tg4Limits->SetG3Control(par, parval);
183 //_____________________________________________________________________________
184 void TG4GeometryManager::FillMediumIdVector()
186 // The second index for materials (having its origin in
187 // G4 tracking media concept) is stored in a vector of G4int
188 // parallel to G4MaterialTable.
192 G4int nofMaterials = G4Material::GetNumberOfMaterials();
194 for (i=0; i<nofMaterials; i++)
195 fMediumIdVector.push_back(0);
198 for (i=0; i<fMediumCounter; i++) {
199 // material index (index in G4Material table)
200 G3MedTableEntry* mte = G3Med.get(i+1);
201 G4int materialIndex = mte->GetMaterial()->GetIndex();
203 // medium index (ID of G3MedTableEntry)
204 G4int mediumIndex = mte->GetID();
206 // store medium index in the vector
207 fMediumIdVector[materialIndex] = mediumIndex;
211 G4cout << "Total nof materials: " << nofMaterials << G4endl;
212 G4cout << "Total nof tracking medias: " << fMediumCounter << G4endl;
215 //_____________________________________________________________________________
216 void TG4GeometryManager::SetUserLimits()
218 // Sets user limits defined in G3MedTable for all logical volumes.
221 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
223 for (G4int i=0; i<lvStore->size(); i++) {
224 G4LogicalVolume* lv = (*lvStore)[i];
226 // get limits from G3Med
227 G4int materialIndex = lv->GetMaterial()->GetIndex();
228 G4int mediumIndex = fMediumIdVector[materialIndex];
229 G4UserLimits* limits = G3Med.get(mediumIndex)->GetLimits();
231 lv->SetUserLimits(limits);
235 //=============================================================================
237 // public methods - AliMC implementation
239 //=============================================================================
242 //_____________________________________________________________________________
243 void TG4GeometryManager::Material(Int_t& kmat, const char* name, Float_t a,
244 Float_t z, Float_t dens, Float_t radl, Float_t absl, Float_t* buf,
247 // Creates G4Material.
248 // !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
250 // absl - this parameter is ignored by GEANT3, too
253 kmat = ++fMaterialCounter;
254 G4double* bufin = fGeometryServices->CreateG4doubleArray(buf, nwbuf);
256 // write token to the output file
258 fOutputManager->WriteGsmate(kmat, name, a, z, dens, radl, nwbuf, bufin);
260 G4gsmate(kmat, name, a, z, dens, radl, nwbuf, bufin);
265 G4String matName = name;
267 = "TG4GeometryManager: user defined parameters for material ";
268 text = text + matName;
269 text = text + " are ignored by Geant4.";
270 TG4Globals::Warning(text);
275 //_____________________________________________________________________________
276 void TG4GeometryManager::Mixture(Int_t& kmat, const char *name, Float_t *a,
277 Float_t *z, Float_t dens, Int_t nlmat, Float_t *wmat)
279 // Creates G4Material composed of more elements.
280 // !! Parameters radl, absl, buf, nwbuf are ignored in G4gsmate
282 // absl - this parameter is ignored by GEANT3, too
285 Int_t npar = abs(nlmat);
286 G4double *ain = fGeometryServices->CreateG4doubleArray(a, npar);
287 G4double *zin = fGeometryServices->CreateG4doubleArray(z, npar);
288 G4double *wmatin = fGeometryServices->CreateG4doubleArray(wmat, npar);
290 kmat = ++fMaterialCounter;
292 // write token to the output file
294 fOutputManager->WriteGsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
296 G4gsmixt(kmat, name, ain, zin, dens, nlmat, wmatin);
299 // After a call with ratios by number (negative number of elements),
300 // the ratio array is changed to the ratio by weight, so all successive
301 // calls with the same array must specify the number of elements as
304 // wmatin may be modified
305 for (G4int i=0; i<npar; i++) wmat[i] = wmatin[i];
312 //_____________________________________________________________________________
313 void TG4GeometryManager::Medium(Int_t& kmed, const char *name, Int_t nmat,
314 Int_t isvol, Int_t ifield, Float_t fieldm, Float_t tmaxfd,
315 Float_t stemax, Float_t deemax, Float_t epsil,
316 Float_t stmin, Float_t* ubuf, Int_t nbuf)
318 // Creates a temporary "medium" that is used for
319 // assigning corresponding parameters to G4 objects:
320 // NTMED is stored as a second material index;
321 // ISVOL is used for builing G3SensVolVector;
322 // STEMAX is passed in TG4Limits (if fUseG3TMLimits is set true);
323 // !! The other parameters (IFIELD, FIELDM, TMAXFD, DEEMAX, EPSIL, STMIN)
324 // are ignored by Geant4.
327 // Geant3 desription:
328 // ==================
329 // NTMED Tracking medium number
330 // NAME Tracking medium name
331 // NMAT Material number
332 // ISVOL Sensitive volume flag
333 // IFIELD Magnetic field
334 // FIELDM Max. field value (Kilogauss)
335 // TMAXFD Max. angle due to field (deg/step)
336 // STEMAX Max. step allowed
337 // DEEMAX Max. fraction of energy lost in a step
338 // EPSIL Tracking precision (cm)
339 // STMIN Min. step due to continuos processes (cm)
341 // IFIELD = 0 if no magnetic field; IFIELD = -1 if user decision in GUSWIM;
342 // IFIELD = 1 if tracking performed with GRKUTA; IFIELD = 2 if tracking
343 // performed with GHELIX; IFIELD = 3 if tracking performed with GHELX3.
346 kmed = ++fMediumCounter;
348 // write token to the output file
350 fOutputManager->WriteGstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd,
351 stemax, deemax, epsil, stmin, 0, 0);
353 G4gstmed(kmed, name, nmat, isvol, ifield, fieldm, tmaxfd, stemax, deemax,
354 epsil, stmin, 0, fUseG3TMLimits);
355 // !! instead of the nbuf argument the bool fIsG3Default is passed
358 G4String medName = name;
360 = "TG4GeometryManager: user defined parameters for medium ";
361 text = text + medName;
362 text = text + " are ignored by Geant4.";
363 TG4Globals::Warning(text);
368 //_____________________________________________________________________________
369 void TG4GeometryManager::Matrix(Int_t& krot, Double_t thetaX, Double_t phiX,
370 Double_t thetaY, Double_t phiY, Double_t thetaZ, Double_t phiZ)
372 // Creates G4RotationMatrix.
375 krot = ++fMatrixCounter;
377 // write token to the output file
379 fOutputManager->WriteGsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
381 G4gsrotm(krot, thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
385 //_____________________________________________________________________________
386 void TG4GeometryManager::Matrix(Int_t& krot, Float_t thetaX, Float_t phiX,
387 Float_t thetaY, Float_t phiY, Float_t thetaZ, Float_t phiZ)
389 // Single precision interface.
392 TG4Globals::Warning("TG4GeometryManager::Matrix in single precision.");
394 Double_t dthetaX = thetaX;
395 Double_t dphiX = phiX;
396 Double_t dthetaY = thetaY;
397 Double_t dphiY = phiY;
398 Double_t dthetaZ = thetaZ;
399 Double_t dphiZ = phiZ;
401 Matrix(krot, dthetaX, dphiX, dthetaY, dphiY, dthetaZ, dphiZ);
405 //_____________________________________________________________________________
406 void TG4GeometryManager::Ggclos()
408 // Sets the top VTE in temporary G3 volume table.
409 // Close geometry output file (if fWriteGeometry is set true).
411 // Geant3 desription:
412 // ==================
413 // close out the geometry
416 if (fWriteGeometry) fOutputManager->WriteGgclos();
422 //_____________________________________________________________________________
423 void TG4GeometryManager::Gfmate(Int_t imat, char *name, Float_t &a,
424 Float_t &z, Float_t &dens, Float_t &radl, Float_t &absl,
425 Float_t* ubuf, Int_t& nbuf)
427 // Geant3 desription:
428 // ==================
429 // Return parameters for material IMAT
432 G4Material* material = G3Mat.get(imat);
435 // to do: change this correctly
436 // !! unsafe conversion
437 const char* chName = material->GetName();
438 name = (char*)chName;
439 a = fGeometryServices->GetEffA(material);
440 z = fGeometryServices->GetEffZ(material);
442 dens = material->GetDensity();
443 dens /= TG4G3Units::MassDensity();
445 radl = material->GetRadlen();
446 radl /= TG4G3Units::Length();
448 // the following parameters are not defined in Geant4
454 TG4Globals::Exception(
455 "TG4GeometryManager::Gfmate: material has not been found.");
460 //_____________________________________________________________________________
461 void TG4GeometryManager::Gstpar(Int_t itmed, const char *param,
464 // Passes the tracking medium parameter to TG4Limits.
465 // The tracking medium parameter is set only in case
466 // its value is different from the "global" physics setup.
467 // (If: CheckCut/ControlWithG3Defaults is used checking
468 // is performed with respect to G3 default values.)
469 // When any cut/control parameter is set in limits
470 // the physics manager is locked and the physics setup
471 // cannot be changed.
472 // Applying this TG4Limits to particles and physical
473 // processes is still in development.
475 // Geant3 desription:
476 // ==================
477 // To change the value of cut or mechanism "CHPAR"
478 // to a new value PARVAL for tracking medium ITMED
479 // The data structure JTMED contains the standard tracking
480 // parameters (CUTS and flags to control the physics processes) which
481 // are used by default for all tracking media. It is possible to
482 // redefine individually with GSTPAR any of these parameters for a
483 // given tracking medium.
484 // ITMED tracking medium number
485 // CHPAR is a character string (variable name)
486 // PARVAL must be given as a floating point.
489 // write token to the output file
491 fOutputManager->WriteGstpar(itmed, param, parval);
493 // get G3 physics setup
494 TG4G3PhysicsManager* g3PhysicsManager = TG4G3PhysicsManager::Instance();
496 G4String name = fGeometryServices->CutName(param);
498 if (g3PhysicsManager->CheckCutWithTheVector(name, parval, cut)) {
499 GstparCut(itmed, cut, parval);
500 g3PhysicsManager->Lock();
503 TG4G3Control control;
504 if (g3PhysicsManager->CheckControlWithTheVector(name, parval, control)) {
505 GstparControl(itmed, control, parval);
506 g3PhysicsManager->Lock();
508 else if (cut==kNoG3Cuts && control==kNoG3Controls) {
509 G4String text = "TG4GeometryManager::Gstpar:";
511 text = text + " parameter is not yet implemented.";
512 TG4Globals::Warning(text);
518 //_____________________________________________________________________________
519 void TG4GeometryManager::SetCerenkov(Int_t itmed, Int_t npckov,
520 Float_t* ppckov, Float_t* absco, Float_t* effic,
524 // Geant3 desription:
525 // ==================
527 // Stores the tables for UV photon tracking in medium ITMED
528 // Please note that it is the user's responsability to
529 // provide all the coefficients:
532 // ITMED Tracking medium number
533 // NPCKOV Number of bins of each table
534 // PPCKOV Value of photon momentum (in GeV)
535 // ABSCO Absorbtion coefficients
536 // dielectric: absorbtion length in cm
537 // metals : absorbtion fraction (0<=x<=1)
538 // EFFIC Detection efficiency for UV photons
539 // RINDEX Refraction index (if=0 metal)
542 G4double* ppckovDbl = fGeometryServices->CreateG4doubleArray(ppckov, npckov);
543 G4double* abscoDbl = fGeometryServices->CreateG4doubleArray(absco, npckov);
544 G4double* efficDbl = fGeometryServices->CreateG4doubleArray(effic, npckov);
545 G4double* rindexDbl = fGeometryServices->CreateG4doubleArray(rindex, npckov);
549 for (i=0; i<npckov; i++) {
550 ppckovDbl[i] = ppckovDbl[i]*TG4G3Units::Energy();
551 abscoDbl[i] = abscoDbl[i]*TG4G3Units::Length();
554 // create material properties table
555 G4MaterialPropertiesTable* table = new G4MaterialPropertiesTable();
556 table->AddProperty("ABSLENGTH", ppckovDbl, abscoDbl, npckov);
557 // used in G4OpAbsorption process
558 table->AddProperty("EFFICIENCY", ppckovDbl, efficDbl, npckov);
559 // used in G4OpBoundary process
560 table->AddProperty("RINDEX", ppckovDbl, rindexDbl, npckov);
561 // used in G4Cerenkov, G4OpRayleigh, G4OpBoundary
563 // get material of medium from table
564 G3MedTableEntry* medium = G3Med.get(itmed);
566 G4String text = "TG4GeometryManager::SetCerenkov: \n";
567 text = text + " Medium not found.";
570 G4Material* material = medium->GetMaterial();
572 // set material properties table
573 material->SetMaterialPropertiesTable(table);
575 G4cout << "The tables for UV photon tracking set for "
576 << material->GetName() << G4endl;
577 for (i=0; i<npckov; i++)
578 G4cout << ppckovDbl[i] << " " << rindexDbl[i] << G4endl;
587 //_____________________________________________________________________________
588 void TG4GeometryManager::Gsdvn(const char *name, const char *mother,
589 Int_t ndiv, Int_t iaxis)
591 // Geant3 desription:
592 // ==================
594 // MOTHER Mother volume name
595 // NDIV Number of divisions
598 // X,Y,Z of CAXIS will be translated to 1,2,3 for IAXIS.
599 // It divides a previously defined volume.
602 // write token to the output file
604 fOutputManager->WriteGsdvn(name, mother, ndiv, iaxis);
606 G4gsdvn(fGeometryServices->CutName(name),
607 fGeometryServices->CutName(mother), ndiv, iaxis);
609 // register name in name map
610 fNameMap.AddName(fGeometryServices->CutName(name));
614 //_____________________________________________________________________________
615 void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
616 Int_t ndiv, Int_t iaxis, Double_t c0i, Int_t numed)
618 // Geant3 desription:
619 // ==================
620 // DIVIDES MOTHER INTO NDIV DIVISIONS CALLED NAME
621 // ALONG AXIS IAXIS STARTING AT COORDINATE VALUE C0.
622 // THE NEW VOLUME CREATED WILL BE MEDIUM NUMBER NUMED.
625 // write token to the output file
627 fOutputManager->WriteGsdvn2(name, mother, ndiv, iaxis, c0i, numed);
629 G4gsdvn2(fGeometryServices->CutName(name),
630 fGeometryServices->CutName(mother), ndiv, iaxis, c0i, numed);
632 // register name in name map
633 fNameMap.AddName(fGeometryServices->CutName(name));
637 //_____________________________________________________________________________
638 void TG4GeometryManager::Gsdvn2(const char *name, const char *mother,
639 Int_t ndiv, Int_t iaxis, Float_t c0i, Int_t numed)
641 // Single precision interface.
644 TG4Globals::Warning("TG4GeometryManager::Gsdvn2 in single precision.");
648 Gsdvn2(name, mother, ndiv, iaxis, dc0i, numed);
652 //_____________________________________________________________________________
653 void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
654 Double_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
656 // Geant3 desription:
657 // ==================
658 // Divides MOTHER into divisions called NAME along
659 // axis IAXIS in steps of STEP. If not exactly divisible
660 // will make as many as possible and will centre them
661 // with respect to the mother. Divisions will have medium
662 // number NUMED. If NUMED is 0, NUMED of MOTHER is taken.
663 // NDVMX is the expected maximum number of divisions
664 // (If 0, no protection tests are performed)
667 // write token to the output file
669 fOutputManager->WriteGsdvt(name, mother, step, iaxis, numed, ndvmx);
671 G4gsdvt(fGeometryServices->CutName(name),
672 fGeometryServices->CutName(mother), step, iaxis, numed, ndvmx);
674 // register name in name map
675 fNameMap.AddName(fGeometryServices->CutName(name));
679 //_____________________________________________________________________________
680 void TG4GeometryManager::Gsdvt(const char *name, const char *mother,
681 Float_t step, Int_t iaxis, Int_t numed, Int_t ndvmx)
683 // Single precision interface.
686 TG4Globals::Warning("TG4GeometryManager::Gsdvt in single precision.");
688 G4double dstep = step;
690 Gsdvt(name, mother, dstep, iaxis, numed, ndvmx);
694 //_____________________________________________________________________________
695 void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
696 Double_t step, Int_t iaxis, Double_t c0, Int_t numed, Int_t ndvmx)
698 // Geant3 desription:
699 // ==================
700 // Create a new volume by dividing an existing one
702 // Divides MOTHER into divisions called NAME along
703 // axis IAXIS starting at coordinate value C0 with step
705 // The new volume created will have medium number NUMED.
706 // If NUMED is 0, NUMED of mother is taken.
707 // NDVMX is the expected maximum number of divisions
708 // (If 0, no protection tests are performed)
711 // write token to the output file
713 fOutputManager->WriteGsdvt2(name, mother, step, iaxis, c0, numed, ndvmx);
715 G4gsdvt2(fGeometryServices->CutName(name),
716 fGeometryServices->CutName(mother), step, iaxis, c0, numed, ndvmx);
718 // register name in name map
719 fNameMap.AddName(fGeometryServices->CutName(name));
723 //_____________________________________________________________________________
724 void TG4GeometryManager::Gsdvt2(const char *name, const char *mother,
725 Float_t step, Int_t iaxis, Float_t c0, Int_t numed, Int_t ndvmx)
727 // Single precision interface.
730 TG4Globals::Warning("TG4GeometryManager::Gsdvt2 in single precision.");
732 G4double dstep = step;
735 Gsdvt2(name, mother, dstep, iaxis, dc0, numed, ndvmx);
739 //_____________________________________________________________________________
740 void TG4GeometryManager::Gsord(const char *name, Int_t iax)
742 // No corresponding action in G4.
744 // Geant3 desription:
745 // ==================
746 // Flags volume CHNAME whose contents will have to be ordered
747 // along axis IAX, by setting the search flag to -IAX
751 // IAX = 4 Rxy (static ordering only -> GTMEDI)
752 // IAX = 14 Rxy (also dynamic ordering -> GTNEXT)
753 // IAX = 5 Rxyz (static ordering only -> GTMEDI)
754 // IAX = 15 Rxyz (also dynamic ordering -> GTNEXT)
755 // IAX = 6 PHI (PHI=0 => X axis)
756 // IAX = 7 THETA (THETA=0 => Z axis)
759 TG4Globals::Warning("TG4GeometryManager::Gsord: dummy method.");
763 //_____________________________________________________________________________
764 void TG4GeometryManager::Gspos(const char *vname, Int_t num,
765 const char *vmoth, Double_t x, Double_t y, Double_t z, Int_t irot,
768 // Geant3 desription:
769 // ==================
770 // Position a volume into an existing one
773 // NUMBER Copy number of the volume
774 // MOTHER Mother volume name
775 // X X coord. of the volume in mother ref. sys.
776 // Y Y coord. of the volume in mother ref. sys.
777 // Z Z coord. of the volume in mother ref. sys.
778 // IROT Rotation matrix number w.r.t. mother ref. sys.
779 // ONLY ONLY/MANY flag
781 // It positions a previously defined volume in the mother.
784 // write token to the output file
786 fOutputManager->WriteGspos(vname, num, vmoth, x, y, z, irot, vonly);
788 G4gspos(fGeometryServices->CutName(vname), num,
789 fGeometryServices->CutName(vmoth), x, y, z, irot, vonly);
791 // register name in name map
792 fNameMap.AddName(fGeometryServices->CutName(vname));
796 //_____________________________________________________________________________
797 void TG4GeometryManager::Gspos(const char *vname, Int_t num,
798 const char *vmoth, Float_t x, Float_t y, Float_t z, Int_t irot,
801 // Single precision interface.
804 TG4Globals::Warning("TG4GeometryManager::Gspos in single precision.");
810 Gspos(vname, num, vmoth, dx, dy, dz, irot, vonly);
814 //_____________________________________________________________________________
815 void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
816 const char *mother, Double_t x, Double_t y, Double_t z, Int_t irot,
817 const char *konly, Double_t *upar, Int_t np )
819 // Geant3 desription:
820 // ==================
821 // Place a copy of generic volume NAME with user number
822 // NR inside MOTHER, with its parameters UPAR(1..NP)
825 // write token to the output file
827 fOutputManager->WriteGsposp(name, nr, mother, x, y, z, irot, konly, upar, np);
829 G4gsposp(fGeometryServices->CutName(name), nr,
830 fGeometryServices->CutName(mother), x, y, z, irot, konly,
833 // register name in name map
834 fNameMap.AddName(fGeometryServices->CutName(name));
838 //_____________________________________________________________________________
839 void TG4GeometryManager::Gsposp(const char *name, Int_t nr,
840 const char *mother, Float_t x, Float_t y, Float_t z, Int_t irot,
841 const char *konly, Float_t *upar, Int_t np )
843 // Single precision interface.
846 TG4Globals::Warning("TG4GeometryManager::Gsposp in single precision.");
851 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, np);
853 Gsposp(name, nr, mother, dx, dy, dz, irot, konly, parin, np);
859 //_____________________________________________________________________________
860 Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
861 Int_t nmed, Double_t *upar, Int_t npar)
863 // Geant3 desription:
864 // ==================
867 // NUMED Tracking medium number
868 // NPAR Number of shape parameters
869 // UPAR Vector containing shape parameters
871 // It creates a new volume in the JVOLUM data structure.
874 // write token to the output file
876 fOutputManager->WriteGsvolu(name, shape, nmed, upar, npar);
878 G4gsvolu(fGeometryServices->CutName(name),
879 fGeometryServices->CutName(shape), nmed, upar, npar);
881 // register name in name map
882 fNameMap.AddName(fGeometryServices->CutName(name));
888 //_____________________________________________________________________________
889 Int_t TG4GeometryManager::Gsvolu(const char *name, const char *shape,
890 Int_t nmed, Float_t *upar, Int_t npar)
892 // Single precision interface.
895 TG4Globals::Warning("TG4GeometryManager::Gsvolu in single precision.");
897 G4double* parin = fGeometryServices->CreateG4doubleArray(upar, npar);
900 = Gsvolu(name, shape, nmed, parin, npar);
908 //_____________________________________________________________________________
909 void TG4GeometryManager::WriteEuclid(const char* fileName,
910 const char* topVolName, Int_t number, Int_t nlevel)
912 // Geant3 desription:
913 // ==================
915 // ******************************************************************
917 // * Write out the geometry of the detector in EUCLID file format *
919 // * filnam : will be with the extension .euc *
920 // * topvol : volume name of the starting node *
921 // * number : copy number of topvol (relevant for gsposp) *
922 // * nlevel : number of levels in the tree structure *
923 // * to be written out, starting from topvol *
925 // * Author : M. Maire *
927 // ******************************************************************
929 // File filnam.tme is written out with the definitions of tracking
930 // medias and materials.
931 // As to restore original numbers for materials and medias, program
932 // searches in the file euc_medi.dat and comparing main parameters of
933 // the mat. defined inside geant and the one in file recognizes them
934 // and is able to take number from file. If for any material or medium,
935 // this procedure fails, ordering starts from 1.
936 // Arrays IOTMED and IOMATE are used for this procedure
940 "TG4GeometryManager::WriteEuclid(..) is not yet implemented.");
944 //_____________________________________________________________________________
945 Int_t TG4GeometryManager::VolId(const Text_t* volName) const
947 // Returns the sensitive detector identifier.
950 return fGeometryServices->GetVolumeID(volName);
954 //_____________________________________________________________________________
955 const char* TG4GeometryManager::VolName(Int_t id) const
957 // Returns the name of the sensitive detector with the given identifier.
960 return fGeometryServices->GetVolumeName(id);
964 //_____________________________________________________________________________
965 Int_t TG4GeometryManager::NofVolumes() const
967 // Returns the total number of sensitive detectors.
970 return fGeometryServices->NofSensitiveDetectors();
974 //_____________________________________________________________________________
975 Int_t TG4GeometryManager::VolId2Mate(Int_t volumeId) const
977 // Return the material number for a given volume id
980 return fGeometryServices->GetMediumId(volumeId);
984 //=============================================================================
986 // public methods - Geant4 only
988 //=============================================================================
991 //_____________________________________________________________________________
992 G4VPhysicalVolume* TG4GeometryManager::CreateG4Geometry()
994 // Creates G4 geometry objects according to the G3VolTable
995 // and returns the top physical volume in case it was created
996 // (return zero otherwise).
999 // set the first entry in the G3Vol table
1001 G3VolTableEntry* first = G3Vol.GetFirstVTE();
1003 // create G4 geometry
1004 G3toG4BuildTree(first,0);
1006 // print G3 volume table statistics
1009 // print G4 geometry statistics
1010 G4cout << "G4 Stat: instantiated "
1011 << fGeometryServices->NofG4LogicalVolumes()
1012 << " logical volumes \n"
1014 << fGeometryServices->NofG4PhysicalVolumes()
1015 << " physical volumes" << G4endl;
1017 // position the first entry
1018 // (in Geant3 the top volume cannot be positioned)
1020 G4VPhysicalVolume* top = 0;
1021 if (first->GetLV()->GetNoDaughters() == 0) {
1022 top = new G4PVPlacement(0, G4ThreeVector(), first->GetName(),
1023 first->GetLV(), 0, false, 0);
1029 //_____________________________________________________________________________
1030 void TG4GeometryManager::ReadG3Geometry(G4String filePath)
1032 // Processes g3calls.dat file and fills G3 tables.
1036 G4cout << "Reading the call list file " << filePath << "..." << G4endl;
1037 G3CLRead(filePath, NULL);
1038 G4cout << "Call list file read completed. Build geometry" << G4endl;
1042 //_____________________________________________________________________________
1043 void TG4GeometryManager::UseG3TrackingMediaLimits()
1045 // Sets fUseG3TMLimits option.
1046 // !! This method has to be called only before starting
1047 // creating geometry.
1050 if (fMediumCounter == 0) {
1051 fUseG3TMLimits = true;
1054 G4String text = "TG4GeometryManager::UseG3TMLimits: \n";
1055 text = text + " It is too late to set G3 defaults. \n";
1056 text = text + " Some media has been already processed.";
1057 TG4Globals::Exception(text);
1062 //_____________________________________________________________________________
1063 void TG4GeometryManager::ClearG3Tables()
1065 // Clears G3 volumes, materials, rotations(?) tables
1066 // and sensitive volumes vector.
1067 // The top volume is kept in the vol table.
1070 // clear volume table
1071 // but keep the top volume in the table
1072 G3VolTableEntry* top = G3Vol.GetFirstVTE();
1073 G4String name = top->GetName();
1074 G4String shape = top->GetShape();
1075 G3VolTableEntry* keep
1076 = new G3VolTableEntry(name, shape, top->GetRpar(), top->GetNpar(),
1077 top->GetNmed(), top->GetSolid(), false);
1078 keep->SetLV(top->GetLV());
1082 // clear other tables
1089 //_____________________________________________________________________________
1090 void TG4GeometryManager::ClearG3TablesFinal()
1092 // Clears G3 medias and volumes tables
1093 // (the top volume is removed from the vol table)
1101 // reset medium counter
1102 //fMaterialCounter = 0;
1107 //_____________________________________________________________________________
1108 void TG4GeometryManager::OpenOutFile(G4String filePath)
1110 // Opens output file.
1113 fOutputManager->OpenFile(filePath);
1117 //_____________________________________________________________________________
1118 void TG4GeometryManager::CloseOutFile()
1120 // Closes output file.
1123 fOutputManager->CloseFile();
1127 //_____________________________________________________________________________
1128 void TG4GeometryManager::PrintNameMap()
1130 // Prints the map of volumes names to second names.
1133 fNameMap.PrintAll();
1137 //_____________________________________________________________________________
1138 void TG4GeometryManager::SetWriteGeometry(G4bool writeGeometry)
1140 // Controls geometry output.
1143 fWriteGeometry = writeGeometry;
1147 //_____________________________________________________________________________
1148 void TG4GeometryManager::SetMapSecond(const G4String& name)
1150 // Sets the second name for the map of volumes names.
1153 fNameMap.SetSecond(name);