Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // 23 // >> 24 // $Id: G4PhysicalVolumeMassScene.cc,v 1.4 2005/01/26 16:48:56 johna Exp $ >> 25 // GEANT4 tag $Name: geant4-08-00 $ 27 // 26 // 28 // 27 // 29 // John Allison 10th August 1998. 28 // John Allison 10th August 1998. 30 // An artificial scene to find physical volume 29 // An artificial scene to find physical volumes. 31 30 32 #include "G4PhysicalVolumeMassScene.hh" 31 #include "G4PhysicalVolumeMassScene.hh" 33 32 34 #include "G4VSolid.hh" 33 #include "G4VSolid.hh" 35 #include "G4Vector3D.hh" 34 #include "G4Vector3D.hh" 36 #include "G4PhysicalVolumeModel.hh" 35 #include "G4PhysicalVolumeModel.hh" 37 #include "G4LogicalVolume.hh" 36 #include "G4LogicalVolume.hh" 38 #include "G4Polyhedron.hh" 37 #include "G4Polyhedron.hh" 39 #include "G4Material.hh" 38 #include "G4Material.hh" 40 #include "G4VPVParameterisation.hh" 39 #include "G4VPVParameterisation.hh" 41 #include "G4UnitsTable.hh" 40 #include "G4UnitsTable.hh" 42 41 43 #define G4warn G4cout << 42 G4PhysicalVolumeMassScene::G4PhysicalVolumeMassScene (): 44 << 45 G4PhysicalVolumeMassScene::G4PhysicalVolumeMas << 46 (G4PhysicalVolumeModel* pPVModel): << 47 fpPVModel (pPVModel), << 48 fVolume (0.), 43 fVolume (0.), 49 fMass (0.), 44 fMass (0.), 50 fpLastPV (0), 45 fpLastPV (0), 51 fPVPCount (0), 46 fPVPCount (0), 52 fLastDepth (0), 47 fLastDepth (0), 53 fLastDensity (0.) << 48 fLastDensity (0.), >> 49 fCurrentDepth (0), >> 50 fpCurrentPV (0), >> 51 fpCurrentLV (0), >> 52 fpCurrentMaterial (0) 54 {} 53 {} 55 54 56 G4PhysicalVolumeMassScene::~G4PhysicalVolumeMa 55 G4PhysicalVolumeMassScene::~G4PhysicalVolumeMassScene () {} 57 56 >> 57 void G4PhysicalVolumeMassScene::EstablishSpecials >> 58 (G4PhysicalVolumeModel& pvModel) { >> 59 pvModel.DefinePointersToWorkingSpace (&fCurrentDepth, >> 60 &fpCurrentPV, >> 61 &fpCurrentLV, >> 62 &fpCurrentMaterial); >> 63 } >> 64 58 void G4PhysicalVolumeMassScene::Reset () 65 void G4PhysicalVolumeMassScene::Reset () 59 { 66 { 60 fVolume = 0.; 67 fVolume = 0.; 61 fMass = 0.; 68 fMass = 0.; 62 fpLastPV = 0; 69 fpLastPV = 0; 63 fPVPCount = 0; 70 fPVPCount = 0; 64 fLastDepth = 0; 71 fLastDepth = 0; 65 fLastDensity = 0.; 72 fLastDensity = 0.; 66 fDensityStack.clear(); 73 fDensityStack.clear(); >> 74 fCurrentDepth = 0; >> 75 fpCurrentPV = 0; >> 76 fpCurrentLV = 0; >> 77 fpCurrentMaterial = 0; 67 } 78 } 68 79 69 void G4PhysicalVolumeMassScene::ProcessVolume << 80 void G4PhysicalVolumeMassScene::AccrueMass (const G4VSolid& solid) 70 { 81 { 71 G4int currentDepth = fpPVModel->GetCurrentDe << 82 if (fpCurrentPV != fpLastPV) { 72 G4VPhysicalVolume* pCurrentPV = fpPVModel->G << 83 fpLastPV = fpCurrentPV; 73 //G4LogicalVolume* pCurrentLV = fpPVModel->G << 74 G4Material* pCurrentMaterial = fpPVModel->Ge << 75 << 76 if (pCurrentPV != fpLastPV) { << 77 fpLastPV = pCurrentPV; << 78 fPVPCount = 0; 84 fPVPCount = 0; 79 } 85 } 80 86 81 G4double currentVolume = ((G4VSolid&)solid). 87 G4double currentVolume = ((G4VSolid&)solid).GetCubicVolume(); 82 G4double currentDensity = pCurrentMaterial? << 88 G4double currentDensity = fpCurrentMaterial->GetDensity(); 83 /* Using G4Polyhedron... (gives slightly dif 89 /* Using G4Polyhedron... (gives slightly different answers on Tubs, e.g.). 84 G4Polyhedron* pPolyhedron = solid.GetPolyhed 90 G4Polyhedron* pPolyhedron = solid.GetPolyhedron(); 85 if (!pPolyhedron) { << 91 if (pPolyhedron) { >> 92 G4Material* pMaterial; >> 93 G4VPVParameterisation* pP = fpCurrentPV->GetParameterisation(); >> 94 if (pP) { >> 95 pMaterial = pP -> ComputeMaterial (fPVPCount++, fpCurrentPV); >> 96 } else { >> 97 pMaterial = fpCurrentLV->GetMaterial(); >> 98 } >> 99 assert(pMaterial == fpCurrentMaterial); >> 100 currentVolume = pPolyhedron->GetVolume(); >> 101 currentDensity = pMaterial->GetDensity(); >> 102 } else { 86 G4cout << 103 G4cout << 87 "G4PhysicalVolumeMassScene::AccrueMass: 104 "G4PhysicalVolumeMassScene::AccrueMass: WARNING:" 88 "\n No G4Polyhedron for" << solid.GetEn 105 "\n No G4Polyhedron for" << solid.GetEntityType() << 89 ". \"" << solid.GetName() << "\" will n 106 ". \"" << solid.GetName() << "\" will not be accounted." 90 "\n It will be as though not there, i.e 107 "\n It will be as though not there, i.e., the density as its mother." 91 "\n Its daughters will still be found a 108 "\n Its daughters will still be found and accounted." 92 << G4endl; 109 << G4endl; 93 currentVolume = 0.; 110 currentVolume = 0.; 94 currentDensity = 0.; 111 currentDensity = 0.; 95 } 112 } 96 */ 113 */ 97 114 98 if (currentDepth == 0) fVolume = currentVolu << 115 if (fCurrentDepth == 0) fVolume = currentVolume; 99 116 100 if (currentDepth > fLastDepth) { << 117 if (fCurrentDepth > fLastDepth) { 101 fDensityStack.push_back (fLastDensity); 118 fDensityStack.push_back (fLastDensity); 102 } else if (currentDepth < fLastDepth) { << 119 } else if (fCurrentDepth < fLastDepth) { 103 fDensityStack.pop_back(); 120 fDensityStack.pop_back(); 104 } 121 } 105 fLastDepth = currentDepth; << 122 fLastDepth = fCurrentDepth; 106 fLastDensity = currentDensity; 123 fLastDensity = currentDensity; 107 G4double motherDensity = 0.; 124 G4double motherDensity = 0.; 108 if (currentDepth > 0) motherDensity = fDensi << 125 if (fCurrentDepth > 0) motherDensity = fDensityStack.back(); 109 126 110 G4double subtractedMass = currentVolume * mo 127 G4double subtractedMass = currentVolume * motherDensity; 111 G4double addedMass = currentVolume * current 128 G4double addedMass = currentVolume * currentDensity; 112 fMass -= subtractedMass; 129 fMass -= subtractedMass; 113 fMass += addedMass; 130 fMass += addedMass; 114 /* Debug 131 /* Debug 115 G4cout << "current vol = " 132 G4cout << "current vol = " 116 << G4BestUnit (currentVolume,"Volume") 133 << G4BestUnit (currentVolume,"Volume") 117 << ", current density = " 134 << ", current density = " 118 << G4BestUnit (currentDensity, "Volumic Mas 135 << G4BestUnit (currentDensity, "Volumic Mass") 119 << ", mother density = " 136 << ", mother density = " 120 << G4BestUnit (motherDensity, "Volumic Mass 137 << G4BestUnit (motherDensity, "Volumic Mass") 121 << G4endl; 138 << G4endl; 122 G4cout << "Subtracted mass = " << G4BestUnit 139 G4cout << "Subtracted mass = " << G4BestUnit (subtractedMass, "Mass") 123 << ", added mass = " << G4BestUnit (addedMa 140 << ", added mass = " << G4BestUnit (addedMass, "Mass") 124 << ", new mass = " << G4BestUnit (fMass, "M 141 << ", new mass = " << G4BestUnit (fMass, "Mass") 125 << G4endl; 142 << G4endl; 126 */ 143 */ 127 if (fMass < 0.) { 144 if (fMass < 0.) { 128 G4warn << << 145 G4cout << 129 "G4PhysicalVolumeMassScene::AccrueMass: 146 "G4PhysicalVolumeMassScene::AccrueMass: WARNING:" 130 "\n Mass going negative for \"" 147 "\n Mass going negative for \"" 131 << pCurrentPV->GetName() << << 148 << fpCurrentPV->GetName() << 132 "\", copy " 149 "\", copy " 133 << pCurrentPV->GetCopyNo() << << 150 << fpCurrentPV->GetCopyNo() << 134 ". Larger than mother?" 151 ". Larger than mother?" 135 << G4endl; 152 << G4endl; 136 } 153 } 137 } 154 } 138 155