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