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