G4PhysicalVolumeMassScene.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  10th August 1998.
00031 // An artificial scene to find physical volumes.
00032 
00033 #include "G4PhysicalVolumeMassScene.hh"
00034 
00035 #include "G4VSolid.hh"
00036 #include "G4Vector3D.hh"
00037 #include "G4PhysicalVolumeModel.hh"
00038 #include "G4LogicalVolume.hh"
00039 #include "G4Polyhedron.hh"
00040 #include "G4Material.hh"
00041 #include "G4VPVParameterisation.hh"
00042 #include "G4UnitsTable.hh"
00043 
00044 G4PhysicalVolumeMassScene::G4PhysicalVolumeMassScene
00045 (G4PhysicalVolumeModel* pPVModel):
00046   fpPVModel (pPVModel),
00047   fVolume (0.),
00048   fMass (0.),
00049   fpLastPV (0),
00050   fPVPCount (0),
00051   fLastDepth (0),
00052   fLastDensity (0.)
00053 {}
00054 
00055 G4PhysicalVolumeMassScene::~G4PhysicalVolumeMassScene () {}
00056 
00057 void G4PhysicalVolumeMassScene::Reset ()
00058 {
00059   fVolume = 0.;
00060   fMass = 0.;
00061   fpLastPV = 0;
00062   fPVPCount = 0;
00063   fLastDepth = 0;
00064   fLastDensity = 0.;
00065   fDensityStack.clear();
00066 }
00067 
00068 void G4PhysicalVolumeMassScene::AccrueMass (const G4VSolid& solid)
00069 {
00070   G4int currentDepth = fpPVModel->GetCurrentDepth();
00071   G4VPhysicalVolume* pCurrentPV = fpPVModel->GetCurrentPV();
00072   //G4LogicalVolume* pCurrentLV = fpPVModel->GetCurrentLV();
00073   G4Material* pCurrentMaterial = fpPVModel->GetCurrentMaterial();
00074 
00075   if (pCurrentPV != fpLastPV) {
00076     fpLastPV = pCurrentPV;
00077     fPVPCount = 0;
00078   }
00079 
00080   G4double currentVolume = ((G4VSolid&)solid).GetCubicVolume();
00081   G4double currentDensity = pCurrentMaterial->GetDensity();
00082   /* Using G4Polyhedron... (gives slightly different answers on Tubs, e.g.).
00083   G4Polyhedron* pPolyhedron = solid.GetPolyhedron();
00084   if (!pPolyhedron) {
00085     G4cout << 
00086       "G4PhysicalVolumeMassScene::AccrueMass: WARNING:"
00087       "\n  No G4Polyhedron for" << solid.GetEntityType() <<
00088       ".  \"" << solid.GetName() << "\" will not be accounted."
00089       "\n  It will be as though not there, i.e., the density as its mother."
00090       "\n  Its daughters will still be found and accounted."
00091            << G4endl;
00092     currentVolume = 0.;
00093     currentDensity = 0.;
00094   }
00095   */
00096 
00097   if (currentDepth == 0) fVolume = currentVolume;
00098 
00099   if (currentDepth > fLastDepth) {
00100     fDensityStack.push_back (fLastDensity);
00101   } else if (currentDepth < fLastDepth) {
00102     fDensityStack.pop_back();
00103   }
00104   fLastDepth = currentDepth;
00105   fLastDensity = currentDensity;
00106   G4double motherDensity = 0.;
00107   if (currentDepth > 0) motherDensity = fDensityStack.back();
00108 
00109   G4double subtractedMass = currentVolume * motherDensity;
00110   G4double addedMass = currentVolume * currentDensity;
00111   fMass -= subtractedMass;
00112   fMass += addedMass;
00113   /* Debug
00114   G4cout << "current vol = "
00115          << G4BestUnit (currentVolume,"Volume")
00116          << ", current density = "
00117          << G4BestUnit (currentDensity, "Volumic Mass")
00118          << ", mother density = "
00119          << G4BestUnit (motherDensity, "Volumic Mass")
00120          << G4endl;
00121   G4cout << "Subtracted mass = " << G4BestUnit (subtractedMass, "Mass")
00122          << ", added mass = " << G4BestUnit (addedMass, "Mass")
00123          << ", new mass = " << G4BestUnit (fMass, "Mass")
00124          << G4endl;
00125   */
00126   if (fMass < 0.) {
00127     G4cout <<
00128       "G4PhysicalVolumeMassScene::AccrueMass: WARNING:"
00129       "\n  Mass going negative for \""
00130            << pCurrentPV->GetName() <<
00131       "\", copy "
00132            << pCurrentPV->GetCopyNo() <<
00133       ".  Larger than mother?"
00134            << G4endl;
00135   }
00136 }

Generated on Mon May 27 17:49:19 2013 for Geant4 by  doxygen 1.4.7