Geant4  10.01.p03
G4PhysicalVolumeMassScene.cc
Go to the documentation of this file.
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 // $Id: G4PhysicalVolumeMassScene.cc 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 //
30 // John Allison 10th August 1998.
31 // An artificial scene to find physical volumes.
32 
34 
35 #include "G4VSolid.hh"
36 #include "G4Vector3D.hh"
37 #include "G4PhysicalVolumeModel.hh"
38 #include "G4LogicalVolume.hh"
39 #include "G4Polyhedron.hh"
40 #include "G4Material.hh"
41 #include "G4VPVParameterisation.hh"
42 #include "G4UnitsTable.hh"
43 
46  fpPVModel (pPVModel),
47  fVolume (0.),
48  fMass (0.),
49  fpLastPV (0),
50  fPVPCount (0),
51  fLastDepth (0),
52  fLastDensity (0.)
53 {}
54 
56 
58 {
59  fVolume = 0.;
60  fMass = 0.;
61  fpLastPV = 0;
62  fPVPCount = 0;
63  fLastDepth = 0;
64  fLastDensity = 0.;
65  fDensityStack.clear();
66 }
67 
69 {
70  G4int currentDepth = fpPVModel->GetCurrentDepth();
71  G4VPhysicalVolume* pCurrentPV = fpPVModel->GetCurrentPV();
72  //G4LogicalVolume* pCurrentLV = fpPVModel->GetCurrentLV();
73  G4Material* pCurrentMaterial = fpPVModel->GetCurrentMaterial();
74 
75  if (pCurrentPV != fpLastPV) {
76  fpLastPV = pCurrentPV;
77  fPVPCount = 0;
78  }
79 
80  G4double currentVolume = ((G4VSolid&)solid).GetCubicVolume();
81  G4double currentDensity = pCurrentMaterial->GetDensity();
82  /* Using G4Polyhedron... (gives slightly different answers on Tubs, e.g.).
83  G4Polyhedron* pPolyhedron = solid.GetPolyhedron();
84  if (!pPolyhedron) {
85  G4cout <<
86  "G4PhysicalVolumeMassScene::AccrueMass: WARNING:"
87  "\n No G4Polyhedron for" << solid.GetEntityType() <<
88  ". \"" << solid.GetName() << "\" will not be accounted."
89  "\n It will be as though not there, i.e., the density as its mother."
90  "\n Its daughters will still be found and accounted."
91  << G4endl;
92  currentVolume = 0.;
93  currentDensity = 0.;
94  }
95  */
96 
97  if (currentDepth == 0) fVolume = currentVolume;
98 
99  if (currentDepth > fLastDepth) {
100  fDensityStack.push_back (fLastDensity);
101  } else if (currentDepth < fLastDepth) {
102  fDensityStack.pop_back();
103  }
104  fLastDepth = currentDepth;
105  fLastDensity = currentDensity;
106  G4double motherDensity = 0.;
107  if (currentDepth > 0) motherDensity = fDensityStack.back();
108 
109  G4double subtractedMass = currentVolume * motherDensity;
110  G4double addedMass = currentVolume * currentDensity;
111  fMass -= subtractedMass;
112  fMass += addedMass;
113  /* Debug
114  G4cout << "current vol = "
115  << G4BestUnit (currentVolume,"Volume")
116  << ", current density = "
117  << G4BestUnit (currentDensity, "Volumic Mass")
118  << ", mother density = "
119  << G4BestUnit (motherDensity, "Volumic Mass")
120  << G4endl;
121  G4cout << "Subtracted mass = " << G4BestUnit (subtractedMass, "Mass")
122  << ", added mass = " << G4BestUnit (addedMass, "Mass")
123  << ", new mass = " << G4BestUnit (fMass, "Mass")
124  << G4endl;
125  */
126  if (fMass < 0.) {
127  G4cout <<
128  "G4PhysicalVolumeMassScene::AccrueMass: WARNING:"
129  "\n Mass going negative for \""
130  << pCurrentPV->GetName() <<
131  "\", copy "
132  << pCurrentPV->GetCopyNo() <<
133  ". Larger than mother?"
134  << G4endl;
135  }
136 }
G4PhysicalVolumeMassScene(G4PhysicalVolumeModel *)
G4Material * GetCurrentMaterial() const
G4double GetDensity() const
Definition: G4Material.hh:180
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
virtual G4int GetCopyNo() const =0
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4VPhysicalVolume * GetCurrentPV() const
std::deque< G4double > fDensityStack