00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "G4LogicalVolume.hh"
00042 #include "G4LogicalVolumeStore.hh"
00043 #include "G4VSolid.hh"
00044 #include "G4Material.hh"
00045 #include "G4VPVParameterisation.hh"
00046 #include "G4VisAttributes.hh"
00047
00048 #include "G4UnitsTable.hh"
00049
00050
00051
00052
00053
00054
00055
00056 G4LogicalVolume::G4LogicalVolume( G4VSolid* pSolid,
00057 G4Material* pMaterial,
00058 const G4String& name,
00059 G4FieldManager* pFieldMgr,
00060 G4VSensitiveDetector* pSDetector,
00061 G4UserLimits* pULimits,
00062 G4bool optimise )
00063 : fDaughters(0,(G4VPhysicalVolume*)0), fFieldManager(pFieldMgr),
00064 fVoxel(0), fOptimise(optimise), fRootRegion(false), fLock(false),
00065 fSmartless(2.), fMass(0.), fVisAttributes(0), fRegion(0), fCutsCouple(0)
00066 {
00067 SetSolid(pSolid);
00068 SetMaterial(pMaterial);
00069 SetName(name);
00070 SetSensitiveDetector(pSDetector);
00071 SetUserLimits(pULimits);
00072
00073
00074
00075 G4LogicalVolumeStore::Register(this);
00076 }
00077
00078
00079
00080
00081
00082
00083 G4LogicalVolume::G4LogicalVolume( __void__& )
00084 : fDaughters(0,(G4VPhysicalVolume*)0), fFieldManager(0),
00085 fMaterial(0), fName(""), fSensitiveDetector(0), fSolid(0), fUserLimits(0),
00086 fVoxel(0), fOptimise(true), fRootRegion(false), fLock(false), fSmartless(2.),
00087 fMass(0.), fVisAttributes(0), fRegion(0), fCutsCouple(0), fBiasWeight(0.)
00088 {
00089
00090
00091 G4LogicalVolumeStore::Register(this);
00092 }
00093
00094
00095
00096
00097
00098
00099 G4LogicalVolume::~G4LogicalVolume()
00100 {
00101 if (!fLock && fRootRegion)
00102 {
00103 fRegion->RemoveRootLogicalVolume(this, true);
00104 }
00105 G4LogicalVolumeStore::DeRegister(this);
00106 }
00107
00108
00109
00110
00111
00112 void
00113 G4LogicalVolume::SetFieldManager(G4FieldManager* pNewFieldMgr,
00114 G4bool forceAllDaughters)
00115 {
00116 fFieldManager = pNewFieldMgr;
00117
00118 G4int NoDaughters = GetNoDaughters();
00119 while ( (NoDaughters--)>0 )
00120 {
00121 G4LogicalVolume* DaughterLogVol;
00122 DaughterLogVol = GetDaughter(NoDaughters)->GetLogicalVolume();
00123 if ( forceAllDaughters || (DaughterLogVol->GetFieldManager() == 0) )
00124 {
00125 DaughterLogVol->SetFieldManager(pNewFieldMgr, forceAllDaughters);
00126 }
00127 }
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 G4bool
00139 G4LogicalVolume::IsAncestor(const G4VPhysicalVolume* aVolume) const
00140 {
00141 G4bool isDaughter = IsDaughter(aVolume);
00142 if (!isDaughter)
00143 {
00144 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin();
00145 itDau != fDaughters.end(); itDau++)
00146 {
00147 isDaughter = (*itDau)->GetLogicalVolume()->IsAncestor(aVolume);
00148 if (isDaughter) break;
00149 }
00150 }
00151 return isDaughter;
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161 G4int G4LogicalVolume::TotalVolumeEntities() const
00162 {
00163 G4int vols = 1;
00164 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin();
00165 itDau != fDaughters.end(); itDau++)
00166 {
00167 G4VPhysicalVolume* physDaughter = (*itDau);
00168 vols += physDaughter->GetMultiplicity()
00169 *physDaughter->GetLogicalVolume()->TotalVolumeEntities();
00170 }
00171 return vols;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 G4double G4LogicalVolume::GetMass(G4bool forced,
00194 G4bool propagate,
00195 G4Material* parMaterial)
00196 {
00197
00198
00199 if ( (fMass) && (!forced) ) return fMass;
00200
00201
00202
00203
00204 G4Material* logMaterial = parMaterial ? parMaterial : fMaterial;
00205 if (!logMaterial)
00206 {
00207 std::ostringstream message;
00208 message << "No material associated to the logical volume: " << fName << " !"
00209 << G4endl
00210 << "Sorry, cannot compute the mass ...";
00211 G4Exception("G4LogicalVolume::GetMass()", "GeomMgt0002",
00212 FatalException, message);
00213 return 0;
00214 }
00215 if (!fSolid)
00216 {
00217 std::ostringstream message;
00218 message << "No solid is associated to the logical volume: " << fName << " !"
00219 << G4endl
00220 << "Sorry, cannot compute the mass ...";
00221 G4Exception("G4LogicalVolume::GetMass()", "GeomMgt0002",
00222 FatalException, message);
00223 return 0;
00224 }
00225 G4double globalDensity = logMaterial->GetDensity();
00226 fMass = fSolid->GetCubicVolume() * globalDensity;
00227
00228
00229
00230
00231
00232 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin();
00233 itDau != fDaughters.end(); itDau++)
00234 {
00235 G4VPhysicalVolume* physDaughter = (*itDau);
00236 G4LogicalVolume* logDaughter = physDaughter->GetLogicalVolume();
00237 G4double subMass=0.;
00238 G4VSolid* daughterSolid = 0;
00239 G4Material* daughterMaterial = 0;
00240
00241
00242
00243
00244
00245 for (G4int i=0; i<physDaughter->GetMultiplicity(); i++)
00246 {
00247 G4VPVParameterisation*
00248 physParam = physDaughter->GetParameterisation();
00249 if (physParam)
00250 {
00251 daughterSolid = physParam->ComputeSolid(i, physDaughter);
00252 daughterSolid->ComputeDimensions(physParam, i, physDaughter);
00253 daughterMaterial = physParam->ComputeMaterial(i, physDaughter);
00254 }
00255 else
00256 {
00257 daughterSolid = logDaughter->GetSolid();
00258 daughterMaterial = logDaughter->GetMaterial();
00259 }
00260 subMass = daughterSolid->GetCubicVolume() * globalDensity;
00261
00262
00263
00264
00265 fMass -= subMass;
00266 if (propagate)
00267 {
00268 fMass += logDaughter->GetMass(true, true, daughterMaterial);
00269 }
00270 }
00271 }
00272
00273 return fMass;
00274 }
00275
00276 void G4LogicalVolume::SetVisAttributes (const G4VisAttributes& VA)
00277 {
00278 fVisAttributes = new G4VisAttributes(VA);
00279 }