Files
geant4/source/geometry/management/include/G4LogicalVolume.icc
T
2016-06-10 11:51:14 +02:00

617 lines
17 KiB
Plaintext

//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4LogicalVolume.icc 78050 2013-12-03 08:17:33Z gcosmo $
//
//
// class G4LogicalVolume Inline Implementation file
//
// 15.01.13 - G.Cosmo, A.Dotti: Modified for thread-safety for MT
// 10.20.97 - P. MoraDeFreitas : Added SetFastSimulation method
// 05.11.98 - M. Verderi: Add Get/Set methods for fBiasWeight
// 09.11.98 - J. Apostolakis: Changed MagneticField to FieldManager
// 12.02.99 - S.Giani: Added set/get methods for voxelization quality
// 18.04.01 - G.Cosmo: Migrated to STL vector
// 17.05.02 - G.Cosmo: Added IsToOptimise() method
// --------------------------------------------------------------------
// These macros change the references to fields that are now encapsulated
// in the class G4LVData.
//
#define G4MT_solid ((subInstanceManager.offset[instanceID]).fSolid)
#define G4MT_sdetector ((subInstanceManager.offset[instanceID]).fSensitiveDetector)
#define G4MT_fmanager ((subInstanceManager.offset[instanceID]).fFieldManager)
#define G4MT_material ((subInstanceManager.offset[instanceID]).fMaterial)
#define G4MT_mass ((subInstanceManager.offset[instanceID]).fMass)
#define G4MT_ccouple ((subInstanceManager.offset[instanceID]).fCutsCouple)
#define G4MT_instance (subInstanceManager.offset[instanceID])
#include "G4Threading.hh"
// ********************************************************************
// GetName
// ********************************************************************
//
inline
G4String G4LogicalVolume::GetName() const
{
return fName;
}
// ********************************************************************
// SetName
// ********************************************************************
//
inline
void G4LogicalVolume::SetName(const G4String& pName)
{
fName = pName;
}
// ********************************************************************
// GetInstanceID
// ********************************************************************
//
inline
G4int G4LogicalVolume::GetInstanceID() const
{
return instanceID;
}
// ********************************************************************
// GetFieldManager
// ********************************************************************
//
inline
G4FieldManager* G4LogicalVolume::GetFieldManager() const
{
return G4MT_fmanager;
}
inline void G4LogicalVolume::AssignFieldManager( G4FieldManager *fldMgr)
{
G4MT_fmanager= fldMgr;
if(!G4Threading::IsWorkerThread()) fFieldManager = fldMgr;
}
// ********************************************************************
// GetMasterFieldManager
// ********************************************************************
//
inline
G4FieldManager* G4LogicalVolume::GetMasterFieldManager() const
{
return fFieldManager;
}
// ********************************************************************
// GetNoDaughters
// ********************************************************************
//
inline
G4int G4LogicalVolume::GetNoDaughters() const
{
return fDaughters.size();
}
// ********************************************************************
// GetDaughter
// ********************************************************************
//
inline
G4VPhysicalVolume* G4LogicalVolume::GetDaughter(const G4int i) const
{
return fDaughters[i];
}
// ********************************************************************
// GetFastSimulationManager
// ********************************************************************
//
inline
G4FastSimulationManager* G4LogicalVolume::GetFastSimulationManager () const
{
G4FastSimulationManager* fFSM = 0;
if(fRegion) fFSM = fRegion->GetFastSimulationManager();
return fFSM;
}
// ********************************************************************
// AddDaughter
// ********************************************************************
//
inline
void G4LogicalVolume::AddDaughter(G4VPhysicalVolume* pNewDaughter)
{
if( !fDaughters.empty() && fDaughters[0]->IsReplicated() )
{
std::ostringstream message;
message << "ERROR - Attempt to place a volume in a mother volume" << G4endl
<< " already containing a replicated volume." << G4endl
<< " A volume can either contain several placements" << G4endl
<< " or a unique replica or parameterised volume !" << G4endl
<< " Mother logical volume: " << GetName() << G4endl
<< " Placing volume: " << pNewDaughter->GetName() << G4endl;
G4Exception("G4LogicalVolume::AddDaughter()", "GeomMgt0002",
FatalException, message,
"Replica or parameterised volume must be the only daughter !");
}
// Invalidate previous calculation of mass - if any - for all threads
G4MT_mass = 0.;
// SignalVolumeChange(); // fVolumeChanged= true;
fDaughters.push_back(pNewDaughter);
G4LogicalVolume* pDaughterLogical = pNewDaughter->GetLogicalVolume();
// Propagate the Field Manager, if the daughter has no field Manager.
//
G4FieldManager* pDaughterFieldManager = pDaughterLogical->GetFieldManager();
if( pDaughterFieldManager == 0 )
{
pDaughterLogical->SetFieldManager(G4MT_fmanager, false);
}
if (fRegion)
{
PropagateRegion();
fRegion->RegionModified(true);
}
}
// ********************************************************************
// IsDaughter
// ********************************************************************
//
inline
G4bool G4LogicalVolume::IsDaughter(const G4VPhysicalVolume* p) const
{
G4PhysicalVolumeList::const_iterator i;
for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
{
if (**i==*p) return true;
}
return false;
}
// ********************************************************************
// RemoveDaughter
// ********************************************************************
//
inline
void G4LogicalVolume::RemoveDaughter(const G4VPhysicalVolume* p)
{
G4PhysicalVolumeList::iterator i;
for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
{
if (**i==*p)
{
fDaughters.erase(i);
break;
}
}
if (fRegion)
{
fRegion->RegionModified(true);
}
G4MT_mass = 0.;
}
// ********************************************************************
// ClearDaughters
// ********************************************************************
//
inline
void G4LogicalVolume::ClearDaughters()
{
G4PhysicalVolumeList::iterator i;
for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
{
fDaughters.erase(i);
}
if (fRegion)
{
fRegion->RegionModified(true);
}
G4MT_mass = 0.;
}
// ********************************************************************
// CharacteriseDaughters
// ********************************************************************
//
inline
EVolume G4LogicalVolume::CharacteriseDaughters() const
{
EVolume type;
G4VPhysicalVolume *pVol;
if ( GetNoDaughters()==1 )
{
pVol = GetDaughter(0);
type = pVol->VolumeType();
}
else
{
type = kNormal;
}
return type;
}
inline
void G4LogicalVolume::ResetMass()
{
G4MT_mass= 0.0;
// Do not fChangedState= 1;
}
// ********************************************************************
// GetSolid
// ********************************************************************
//
inline
G4VSolid* G4LogicalVolume::GetSolid(G4LVData &instLVdata) // const
{
return instLVdata.fSolid;
}
inline
G4VSolid* G4LogicalVolume::GetSolid() const
{
// return G4MT_solid;
// return ((subInstanceManager.offset[instanceID]).fSolid);
return this->GetSolid( subInstanceManager.offset[instanceID] );
}
// ********************************************************************
// GetMasterSolid
// ********************************************************************
//
inline
G4VSolid* G4LogicalVolume::GetMasterSolid() const
{
return fSolid;
}
// ********************************************************************
// SetSolid
// ********************************************************************
//
inline
void G4LogicalVolume::SetSolid(G4VSolid *pSolid)
{
// ((subInstanceManager.offset[instanceID]).fSolid) = pSolid;
G4MT_solid=pSolid;
// G4MT_mass = 0.;
this->ResetMass();
}
inline
void G4LogicalVolume::SetSolid(G4LVData &instLVdata, G4VSolid *pSolid)
{
instLVdata.fSolid = pSolid;
// G4MT_solid=pSolid;
instLVdata.fMass= 0;
// A fast way to reset the mass ... ie G4MT_mass = 0.;
}
// ********************************************************************
// GetMaterial
// ********************************************************************
//
inline
G4Material* G4LogicalVolume::GetMaterial() const
{
return G4MT_material;
}
// ********************************************************************
// SetMaterial
// ********************************************************************
//
inline
void G4LogicalVolume::SetMaterial(G4Material *pMaterial)
{
G4MT_material=pMaterial;
G4MT_mass = 0.;
}
// ********************************************************************
// UpdateMaterial
// ********************************************************************
//
inline
void G4LogicalVolume::UpdateMaterial(G4Material *pMaterial)
{
G4MT_material=pMaterial;
if(fRegion) { G4MT_ccouple = fRegion->FindCouple(pMaterial); }
G4MT_mass = 0.;
}
// ********************************************************************
// GetSensitiveDetector
// ********************************************************************
//
inline
G4VSensitiveDetector* G4LogicalVolume::GetSensitiveDetector() const
{
return G4MT_sdetector;
}
// ********************************************************************
// GetMasterSensitiveDetector
// ********************************************************************
//
inline
G4VSensitiveDetector* G4LogicalVolume::GetMasterSensitiveDetector() const
{
return fSensitiveDetector;
}
// ********************************************************************
// SetSensitiveDetector
// ********************************************************************
//
inline
void G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector* pSDetector)
{
G4MT_sdetector = pSDetector;
if(!G4Threading::IsWorkerThread()) fSensitiveDetector = pSDetector;
}
// ********************************************************************
// GetUserLimits
// ********************************************************************
//
inline
G4UserLimits* G4LogicalVolume::GetUserLimits() const
{
if(fUserLimits) return fUserLimits;
if(fRegion) return fRegion->GetUserLimits();
return 0;
}
// ********************************************************************
// SetUserLimits
// ********************************************************************
//
inline
void G4LogicalVolume::SetUserLimits(G4UserLimits* pULimits)
{
fUserLimits = pULimits;
}
// ********************************************************************
// GetVoxelHeader
// ********************************************************************
//
inline
G4SmartVoxelHeader* G4LogicalVolume::GetVoxelHeader() const
{
return fVoxel;
}
// ********************************************************************
// SetVoxelHeader
// ********************************************************************
//
inline
void G4LogicalVolume::SetVoxelHeader(G4SmartVoxelHeader* pVoxel)
{
fVoxel = pVoxel;
}
// ********************************************************************
// GetSmartless
// ********************************************************************
//
inline
G4double G4LogicalVolume::GetSmartless() const
{
return fSmartless;
}
// ********************************************************************
// SetSmartless
// ********************************************************************
//
inline
void G4LogicalVolume::SetSmartless(G4double smt)
{
fSmartless = smt;
}
// ********************************************************************
// IsToOptimise
// ********************************************************************
//
inline
G4bool G4LogicalVolume::IsToOptimise() const
{
return fOptimise;
}
// ********************************************************************
// SetOptimisation
// ********************************************************************
//
inline
void G4LogicalVolume::SetOptimisation(G4bool optim)
{
fOptimise = optim;
}
// ********************************************************************
// IsRootRegion
// ********************************************************************
//
inline
G4bool G4LogicalVolume::IsRootRegion() const
{
return fRootRegion;
}
// ********************************************************************
// SetRegionRootFlag
// ********************************************************************
//
inline
void G4LogicalVolume::SetRegionRootFlag(G4bool rreg)
{
fRootRegion = rreg;
}
// ********************************************************************
// IsRegion
// ********************************************************************
//
inline
G4bool G4LogicalVolume::IsRegion() const
{
G4bool reg = false;
if (fRegion) reg = true;
return reg;
}
// ********************************************************************
// SetRegion
// ********************************************************************
//
inline
void G4LogicalVolume::SetRegion(G4Region* reg)
{
fRegion = reg;
}
// ********************************************************************
// GetRegion
// ********************************************************************
//
inline
G4Region* G4LogicalVolume::GetRegion() const
{
return fRegion;
}
// ********************************************************************
// PropagateRegion
// ********************************************************************
//
inline
void G4LogicalVolume::PropagateRegion()
{
fRegion->ScanVolumeTree(this, true);
}
// ********************************************************************
// GetMaterialCutsCouple
// ********************************************************************
//
inline
const G4MaterialCutsCouple* G4LogicalVolume::GetMaterialCutsCouple() const
{
return G4MT_ccouple;
}
// ********************************************************************
// SetMaterialCutsCouple
// ********************************************************************
//
inline
void G4LogicalVolume::SetMaterialCutsCouple(G4MaterialCutsCouple* cuts)
{
G4MT_ccouple = cuts;
}
// ********************************************************************
// Lock
// ********************************************************************
//
inline
void G4LogicalVolume::Lock()
{
fLock = true;
}
// ********************************************************************
// Operator ==
// ********************************************************************
//
inline
G4bool G4LogicalVolume::operator == ( const G4LogicalVolume& lv) const
{
return (this==&lv) ? true : false;
}
// ********************************************************************
// GetVisAttributes
// ********************************************************************
//
inline
const G4VisAttributes* G4LogicalVolume::GetVisAttributes () const
{
return fVisAttributes;
}
// ********************************************************************
// SetVisAttributes
// ********************************************************************
//
inline
void G4LogicalVolume::SetVisAttributes (const G4VisAttributes* pVA)
{
fVisAttributes = pVA;
}
// ********************************************************************
// SetBiasWeight
// ********************************************************************
//
inline
void G4LogicalVolume::SetBiasWeight(G4double weight)
{
fBiasWeight = weight;
}
// ********************************************************************
// GetBiasWeight
// ********************************************************************
//
inline
G4double G4LogicalVolume::GetBiasWeight() const
{
return fBiasWeight;
}
#undef G4MT_solid
#undef G4MT_sdetector
#undef G4MT_fmanager
#undef G4MT_material
// #undef G4MT_mass
// #undef G4MT_ccouple
#undef G4MT_instance