2 // ********************************************************************
 
    3 // * License and Disclaimer                                           *
 
    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.                             *
 
   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.         *
 
   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 // ********************************************************************
 
   27 // $Id: G4LogicalVolume.icc 91010 2015-06-15 09:55:26Z gcosmo $
 
   30 // class G4LogicalVolume Inline Implementation file
 
   32 // 15.01.13 - G.Cosmo, A.Dotti: Modified for thread-safety for MT
 
   33 // 10.20.97 - P. MoraDeFreitas : Added SetFastSimulation method
 
   34 // 05.11.98 - M. Verderi: Add Get/Set methods for fBiasWeight
 
   35 // 09.11.98 - J. Apostolakis:  Changed MagneticField to FieldManager
 
   36 // 12.02.99 - S.Giani: Added set/get methods for voxelization quality
 
   37 // 18.04.01 - G.Cosmo: Migrated to STL vector
 
   38 // 17.05.02 - G.Cosmo: Added IsToOptimise() method
 
   39 // --------------------------------------------------------------------
 
   42 // These macros change the references to fields that are now encapsulated
 
   43 // in the class G4LVData.
 
   45 #define G4MT_solid     ((subInstanceManager.offset[instanceID]).fSolid)
 
   46 #define G4MT_sdetector ((subInstanceManager.offset[instanceID]).fSensitiveDetector)
 
   47 #define G4MT_fmanager  ((subInstanceManager.offset[instanceID]).fFieldManager)
 
   48 #define G4MT_material  ((subInstanceManager.offset[instanceID]).fMaterial)
 
   49 #define G4MT_mass      ((subInstanceManager.offset[instanceID]).fMass)
 
   50 #define G4MT_ccouple   ((subInstanceManager.offset[instanceID]).fCutsCouple)
 
   51 #define G4MT_instance  (subInstanceManager.offset[instanceID])
 
   53 #include "G4Threading.hh"
 
   54 // ********************************************************************
 
   56 // ********************************************************************
 
   59 const G4String& G4LogicalVolume::GetName() const
 
   64 // ********************************************************************
 
   66 // ********************************************************************
 
   69 void G4LogicalVolume::SetName(const G4String& pName)
 
   74 // ********************************************************************
 
   76 // ********************************************************************
 
   79 G4int G4LogicalVolume::GetInstanceID() const
 
   84 // ********************************************************************
 
   86 // ********************************************************************
 
   89 G4FieldManager* G4LogicalVolume::GetFieldManager() const
 
   94 inline void G4LogicalVolume::AssignFieldManager( G4FieldManager *fldMgr)
 
   96   G4MT_fmanager= fldMgr;
 
   97   if(G4Threading::IsMasterThread())  fFieldManager = fldMgr;
 
  101 // ********************************************************************
 
  102 // GetMasterFieldManager
 
  103 // ********************************************************************
 
  106 G4FieldManager* G4LogicalVolume::GetMasterFieldManager() const
 
  108   return fFieldManager;
 
  111 // ********************************************************************
 
  113 // ********************************************************************
 
  116 G4int G4LogicalVolume::GetNoDaughters() const
 
  118   return fDaughters.size();
 
  121 // ********************************************************************
 
  123 // ********************************************************************
 
  126 G4VPhysicalVolume* G4LogicalVolume::GetDaughter(const G4int i) const
 
  128   return fDaughters[i];
 
  131 // ********************************************************************
 
  132 // GetFastSimulationManager
 
  133 // ********************************************************************
 
  136 G4FastSimulationManager* G4LogicalVolume::GetFastSimulationManager () const 
 
  138   G4FastSimulationManager* fFSM = 0;
 
  139   if(fRegion) fFSM = fRegion->GetFastSimulationManager();
 
  143 // ********************************************************************
 
  145 // ********************************************************************
 
  148 void G4LogicalVolume::AddDaughter(G4VPhysicalVolume* pNewDaughter)
 
  150   if( !fDaughters.empty() && fDaughters[0]->IsReplicated() )
 
  152     std::ostringstream message;
 
  153     message << "ERROR - Attempt to place a volume in a mother volume" << G4endl
 
  154             << "        already containing a replicated volume." << G4endl
 
  155             << "        A volume can either contain several placements" << G4endl
 
  156             << "        or a unique replica or parameterised volume !" << G4endl
 
  157             << "           Mother logical volume: " << GetName() << G4endl
 
  158             << "           Placing volume: " << pNewDaughter->GetName() << G4endl;
 
  159     G4Exception("G4LogicalVolume::AddDaughter()", "GeomMgt0002",
 
  160                 FatalException, message,
 
  161                 "Replica or parameterised volume must be the only daughter !");
 
  164   // Invalidate previous calculation of mass - if any - for all threads
 
  166   // SignalVolumeChange();  // fVolumeChanged= true;
 
  167   fDaughters.push_back(pNewDaughter);
 
  169   G4LogicalVolume* pDaughterLogical = pNewDaughter->GetLogicalVolume();
 
  171   // Propagate the Field Manager, if the daughter has no field Manager.
 
  173   G4FieldManager* pDaughterFieldManager = pDaughterLogical->GetFieldManager();
 
  175   if( pDaughterFieldManager == 0 )
 
  177     pDaughterLogical->SetFieldManager(G4MT_fmanager, false);
 
  182     fRegion->RegionModified(true);
 
  186 // ********************************************************************
 
  188 // ********************************************************************
 
  191 G4bool G4LogicalVolume::IsDaughter(const G4VPhysicalVolume* p) const
 
  193   G4PhysicalVolumeList::const_iterator i;
 
  194   for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
 
  196     if (**i==*p) return true;
 
  201 // ********************************************************************
 
  203 // ********************************************************************
 
  206 void G4LogicalVolume::RemoveDaughter(const G4VPhysicalVolume* p)
 
  208   G4PhysicalVolumeList::iterator i;
 
  209   for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
 
  219     fRegion->RegionModified(true);
 
  224 // ********************************************************************
 
  226 // ********************************************************************
 
  229 void G4LogicalVolume::ClearDaughters()
 
  231   G4PhysicalVolumeList::iterator i;
 
  232   for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i )
 
  238     fRegion->RegionModified(true);
 
  243 // ********************************************************************
 
  244 // CharacteriseDaughters
 
  245 // ********************************************************************
 
  248 EVolume G4LogicalVolume::CharacteriseDaughters() const
 
  251   G4VPhysicalVolume *pVol;
 
  253   if ( GetNoDaughters()==1 )
 
  255     pVol = GetDaughter(0);
 
  256     type = pVol->VolumeType();
 
  266 void G4LogicalVolume::ResetMass()
 
  271 // ********************************************************************
 
  273 // ********************************************************************
 
  276 G4VSolid* G4LogicalVolume::GetSolid(G4LVData &instLVdata) // const
 
  278   return instLVdata.fSolid;
 
  282 G4VSolid* G4LogicalVolume::GetSolid() const
 
  284   // return G4MT_solid;
 
  285   // return ((subInstanceManager.offset[instanceID]).fSolid);
 
  286   return this->GetSolid( subInstanceManager.offset[instanceID] ); 
 
  289 // ********************************************************************
 
  291 // ********************************************************************
 
  294 G4VSolid* G4LogicalVolume::GetMasterSolid() const
 
  299 // ********************************************************************
 
  301 // ********************************************************************
 
  304 void G4LogicalVolume::SetSolid(G4VSolid *pSolid)
 
  307   // ((subInstanceManager.offset[instanceID]).fSolid) = pSolid;
 
  314 void G4LogicalVolume::SetSolid(G4LVData &instLVdata, G4VSolid *pSolid)
 
  316   instLVdata.fSolid = pSolid;
 
  317   // G4MT_solid=pSolid;
 
  319   // A fast way to reset the mass ... ie G4MT_mass = 0.;
 
  322 // ********************************************************************
 
  324 // ********************************************************************
 
  327 G4Material* G4LogicalVolume::GetMaterial() const
 
  329   return G4MT_material;
 
  332 // ********************************************************************
 
  334 // ********************************************************************
 
  337 void G4LogicalVolume::SetMaterial(G4Material *pMaterial)
 
  339   G4MT_material=pMaterial;
 
  343 // ********************************************************************
 
  345 // ********************************************************************
 
  348 void G4LogicalVolume::UpdateMaterial(G4Material *pMaterial)
 
  350   G4MT_material=pMaterial;
 
  351   if(fRegion) { G4MT_ccouple = fRegion->FindCouple(pMaterial); }
 
  355 // ********************************************************************
 
  356 // GetSensitiveDetector
 
  357 // ********************************************************************
 
  360 G4VSensitiveDetector* G4LogicalVolume::GetSensitiveDetector() const
 
  362   return G4MT_sdetector;
 
  365 // ********************************************************************
 
  366 // GetMasterSensitiveDetector
 
  367 // ********************************************************************
 
  370 G4VSensitiveDetector* G4LogicalVolume::GetMasterSensitiveDetector() const
 
  372   return fSensitiveDetector;
 
  375 // ********************************************************************
 
  376 // SetSensitiveDetector
 
  377 // ********************************************************************
 
  380 void G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector* pSDetector)
 
  382   G4MT_sdetector = pSDetector;
 
  383   if(G4Threading::IsMasterThread()) fSensitiveDetector = pSDetector;
 
  386 // ********************************************************************
 
  388 // ********************************************************************
 
  391 G4UserLimits* G4LogicalVolume::GetUserLimits() const
 
  393   if(fUserLimits) return fUserLimits;
 
  394   if(fRegion) return fRegion->GetUserLimits();
 
  398 // ********************************************************************
 
  400 // ********************************************************************
 
  403 void G4LogicalVolume::SetUserLimits(G4UserLimits* pULimits)
 
  405   fUserLimits = pULimits;
 
  408 // ********************************************************************
 
  410 // ********************************************************************
 
  413 G4SmartVoxelHeader* G4LogicalVolume::GetVoxelHeader() const
 
  418 // ********************************************************************
 
  420 // ********************************************************************
 
  423 void G4LogicalVolume::SetVoxelHeader(G4SmartVoxelHeader* pVoxel)
 
  428 // ********************************************************************
 
  430 // ********************************************************************
 
  433 G4double G4LogicalVolume::GetSmartless() const
 
  438 // ********************************************************************
 
  440 // ********************************************************************
 
  443 void G4LogicalVolume::SetSmartless(G4double smt)
 
  448 // ********************************************************************
 
  450 // ********************************************************************
 
  453 G4bool G4LogicalVolume::IsToOptimise() const
 
  458 // ********************************************************************
 
  460 // ********************************************************************
 
  463 void G4LogicalVolume::SetOptimisation(G4bool optim)
 
  468 // ********************************************************************
 
  470 // ********************************************************************
 
  473 G4bool G4LogicalVolume::IsRootRegion() const
 
  478 // ********************************************************************
 
  480 // ********************************************************************
 
  483 void G4LogicalVolume::SetRegionRootFlag(G4bool rreg)
 
  488 // ********************************************************************
 
  490 // ********************************************************************
 
  493 G4bool G4LogicalVolume::IsRegion() const
 
  496   if (fRegion) reg = true;
 
  500 // ********************************************************************
 
  502 // ********************************************************************
 
  505 void G4LogicalVolume::SetRegion(G4Region* reg)
 
  510 // ********************************************************************
 
  512 // ********************************************************************
 
  515 G4Region* G4LogicalVolume::GetRegion() const
 
  520 // ********************************************************************
 
  522 // ********************************************************************
 
  525 void G4LogicalVolume::PropagateRegion()
 
  527   fRegion->ScanVolumeTree(this, true);
 
  530 // ********************************************************************
 
  531 // GetMaterialCutsCouple
 
  532 // ********************************************************************
 
  535 const G4MaterialCutsCouple* G4LogicalVolume::GetMaterialCutsCouple() const
 
  540 // ********************************************************************
 
  541 // SetMaterialCutsCouple
 
  542 // ********************************************************************
 
  545 void G4LogicalVolume::SetMaterialCutsCouple(G4MaterialCutsCouple* cuts)
 
  550 // ********************************************************************
 
  552 // ********************************************************************
 
  555 void G4LogicalVolume::Lock()
 
  560 // ********************************************************************
 
  562 // ********************************************************************
 
  565 G4bool G4LogicalVolume::operator == ( const G4LogicalVolume& lv) const
 
  567   return (this==&lv) ? true : false;
 
  570 // ********************************************************************
 
  572 // ********************************************************************
 
  575 const G4VisAttributes* G4LogicalVolume::GetVisAttributes () const
 
  577   return fVisAttributes;
 
  580 // ********************************************************************
 
  582 // ********************************************************************
 
  585 void G4LogicalVolume::SetVisAttributes (const G4VisAttributes* pVA)
 
  587   fVisAttributes = pVA;
 
  590 // ********************************************************************
 
  592 // ********************************************************************
 
  595 void G4LogicalVolume::SetBiasWeight(G4double weight)
 
  597   fBiasWeight = weight;
 
  600 // ********************************************************************
 
  602 // ********************************************************************
 
  605 G4double G4LogicalVolume::GetBiasWeight() const
 
  610 #undef G4MT_sdetector
 
  614 // #undef G4MT_ccouple