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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 //
 27 //
 28 // modified by I. Hrivnacova, 2.8.99 
 29 
 30 #include "globals.hh"
 31 #include "G3toG4BuildTree.hh"
 32 #include "G3RotTable.hh"
 33 #include "G3MedTable.hh"
 34 #include "G3VolTable.hh"
 35 #include "G3SensVolVector.hh"
 36 #include "G3Pos.hh"
 37 #include "G4LogicalVolume.hh"
 38 #include "G4PVPlacement.hh"
 39 #include "G4ReflectionFactory.hh"
 40 #include "G4Transform3D.hh"
 41 
 42 void G3toG4BuildTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
 43 {
 44   G3toG4BuildLVTree(curVTE, motherVTE);
 45   G3toG4BuildPVTree(curVTE);
 46 }  
 47 
 48 void G3toG4BuildLVTree(G3VolTableEntry* curVTE, G3VolTableEntry* motherVTE)
 49 {
 50   // check existence of the solid
 51   if (curVTE->GetSolid()) {
 52     G4LogicalVolume* curLog = curVTE->GetLV();
 53     if (!curLog) {
 54       // skip creating logical volume
 55       // in case it already exists
 56     
 57       // material
 58       G4Material* material = 0;
 59       G3MedTableEntry* mte = G3Med.get(curVTE->GetNmed());
 60       if (mte) material = mte->GetMaterial();
 61       if (!material) {
 62         G4String err_message = "VTE " + curVTE->GetName()
 63                              + " has not defined material!!";
 64         G4Exception("G3toG4BuildLVTree()", "G3toG40001",
 65                     FatalException, err_message);
 66         return;
 67       } 
 68 
 69       // logical volume
 70       curLog = 
 71         new G4LogicalVolume(curVTE->GetSolid(), material, curVTE->GetName());
 72       curVTE->SetLV(curLog);
 73       
 74       // insert logical volume to G3SensVol vector
 75       // in case it is sensitive
 76       if (mte->GetISVOL()) G3SensVol.push_back(curLog);
 77     }  
 78   }
 79   else {
 80     if ( !(curVTE->GetDivision() && motherVTE->GetMasterClone() == motherVTE &&
 81            motherVTE->GetNoClones()>1)) {
 82       // ignore dummy vte's 
 83       // (this should be the only case when the vte is dummy but
 84       // is present in mother <-> daughters tree
 85       G4String err_message = "VTE " + curVTE->GetName()
 86                            + " has not defined solid!!";
 87       G4Exception("G3toG4BuildLVTree()", "G3toG40002",
 88                   FatalException, err_message);
 89       return;
 90     }
 91   }  
 92   
 93   // process daughters
 94   G4int Ndau = curVTE->GetNoDaughters();
 95   for (int Idau=0; Idau<Ndau; Idau++){
 96     G3toG4BuildLVTree(curVTE->GetDaughter(Idau), curVTE);
 97   }
 98 }
 99 
100 void G3toG4BuildPVTree(G3VolTableEntry* curVTE)
101 {
102   // check existence of the solid
103   if (curVTE->GetSolid()) {
104     G4LogicalVolume* curLog = curVTE->GetLV();
105   
106     // positions in motherVTE
107     for (G4int i=0; i<curVTE->NPCopies(); i++){
108 
109       G3Pos* theG3Pos = curVTE->GetG3PosCopy(i);
110       if (theG3Pos) {
111 
112         // loop over all mothers 
113         for (G4int im=0; im<curVTE->GetNoMothers(); im++) {
114 
115           G3VolTableEntry* motherVTE = curVTE->GetMother(im);
116           if (theG3Pos->GetMotherName() == motherVTE->GetMasterClone()->GetName()) {
117      
118             // get mother logical volume
119             G4LogicalVolume* mothLV=0;
120             G4String motherName = motherVTE->GetName();    
121             if (!curVTE->FindMother(motherName)) continue;
122             if (curVTE->FindMother(motherName)->GetName() != motherName) {
123               // check consistency - tbr
124               G4String err_message =
125                        "G3toG4BuildTree: Inconsistent mother <-> daughter !!";
126               G4Exception("G3toG4BuildPVTree()", "G3toG40003",
127                           FatalException, err_message);
128               return;
129             }
130             mothLV = motherVTE->GetLV();
131     
132             // copy number
133             // (in G3 numbering starts from 1 but in G4 from 0)
134             G4int copyNo = theG3Pos->GetCopy() - 1;
135       
136             // position it if not top-level volume
137 
138       if (mothLV != 0) {
139 
140               // transformation
141               G4int irot = theG3Pos->GetIrot();
142               G4RotationMatrix* theMatrix = 0;
143               if (irot>0) theMatrix = G3Rot.Get(irot);
144               G4Rotate3D rotation;
145               if (theMatrix) {            
146             rotation = G4Rotate3D(*theMatrix);
147         }
148 
149               #ifndef G3G4_NO_REFLECTION
150               G4Translate3D translation(*(theG3Pos->GetPos()));
151         G4Transform3D transform3D = translation * (rotation.inverse());
152 
153               G4ReflectionFactory::Instance()
154           ->Place(transform3D,       // transformation
155                   curVTE->GetName(), // PV name
156       curLog,            // its logical volume 
157       mothLV,            // mother logical volume
158       false,             // only
159       copyNo);           // copy
160               #else
161               new G4PVPlacement(theMatrix,            // rotation matrix
162                               *(theG3Pos->GetPos()),  // its position
163                               curLog,                 // its LogicalVolume 
164                               curVTE->GetName(),      // PV name
165                               mothLV,                 // Mother LV
166                               0,                      // only
167                               copyNo);                // copy
168               #endif
169 
170               // verbose
171           #ifdef G3G4DEBUG
172           G4cout << "PV: " << i << "th copy of " << curVTE->GetName()
173              << "  in " << motherVTE->GetName() << "  copyNo: " 
174            << copyNo << "  irot: " << irot << "  pos: " 
175            << *(theG3Pos->GetPos()) << G4endl;
176         #endif
177             }     
178     }
179         }
180         // clear this position
181         curVTE->ClearG3PosCopy(i);
182         i--;
183       }
184     }
185 
186     // divisions     
187     if (curVTE->GetDivision()) {
188       curVTE->GetDivision()->CreatePVReplica();
189       // verbose
190       #ifdef G3G4DEBUG
191   G4cout << "CreatePVReplica: " << curVTE->GetName() 
192          << " in "  <<  curVTE->GetMother()->GetName() << G4endl;
193       #endif
194 
195       // clear this divison
196       curVTE->ClearDivision(); 
197     }
198   }
199   
200   // process daughters
201   G4int Ndau = curVTE->GetNoDaughters();
202   for (int Idau=0; Idau<Ndau; Idau++){
203     G3toG4BuildPVTree(curVTE->GetDaughter(Idau));
204   }
205 }
206 
207