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