Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** >> 25 // >> 26 // >> 27 // 25 // 28 // 26 // class G4LogicalVolume implementation << 29 // class G4LogicalVolume Implementation 27 // 30 // >> 31 // History: 28 // 15.01.13 G.Cosmo, A.Dotti: Modified for thr 32 // 15.01.13 G.Cosmo, A.Dotti: Modified for thread-safety for MT 29 // 01.03.05 G.Santin: Added flag for optional 33 // 01.03.05 G.Santin: Added flag for optional propagation of GetMass() 30 // 17.05.02 G.Cosmo: Added flag for optional o 34 // 17.05.02 G.Cosmo: Added flag for optional optimisation 31 // 12.02.99 S.Giani: Default initialization of 35 // 12.02.99 S.Giani: Default initialization of voxelization quality 32 // 04.08.97 P.M.DeFreitas: Added methods for p 36 // 04.08.97 P.M.DeFreitas: Added methods for parameterised simulation >> 37 // 19.08.96 P.Kent: Modified for G4VSensitive Detector 33 // 11.07.95 P.Kent: Initial version 38 // 11.07.95 P.Kent: Initial version 34 // ------------------------------------------- 39 // -------------------------------------------------------------------- 35 40 36 #include "G4LogicalVolume.hh" 41 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolumeStore.hh" 42 #include "G4LogicalVolumeStore.hh" 38 #include "G4VSolid.hh" 43 #include "G4VSolid.hh" 39 #include "G4Material.hh" 44 #include "G4Material.hh" 40 #include "G4VPVParameterisation.hh" 45 #include "G4VPVParameterisation.hh" 41 #include "G4VisAttributes.hh" 46 #include "G4VisAttributes.hh" 42 47 43 #include "G4UnitsTable.hh" 48 #include "G4UnitsTable.hh" 44 49 45 G4LVData::G4LVData() {;} << 50 G4LVData::G4LVData() >> 51 : fSolid(0),fSensitiveDetector(0),fFieldManager(0), >> 52 fMaterial(0),fMass(0.),fCutsCouple(0) >> 53 {;} 46 54 47 // This new field helps to use the class G4LVM 55 // This new field helps to use the class G4LVManager 48 // 56 // 49 G4LVManager G4LogicalVolume::subInstanceManage 57 G4LVManager G4LogicalVolume::subInstanceManager; 50 58 51 // These macros change the references to field 59 // These macros change the references to fields that are now encapsulated 52 // in the class G4LVData. 60 // in the class G4LVData. 53 // 61 // 54 #define G4MT_solid ((subInstanceManager.of 62 #define G4MT_solid ((subInstanceManager.offset[instanceID]).fSolid) 55 #define G4MT_sdetector ((subInstanceManager.of 63 #define G4MT_sdetector ((subInstanceManager.offset[instanceID]).fSensitiveDetector) 56 #define G4MT_fmanager ((subInstanceManager.of 64 #define G4MT_fmanager ((subInstanceManager.offset[instanceID]).fFieldManager) 57 #define G4MT_material ((subInstanceManager.of 65 #define G4MT_material ((subInstanceManager.offset[instanceID]).fMaterial) 58 #define G4MT_mass ((subInstanceManager.of 66 #define G4MT_mass ((subInstanceManager.offset[instanceID]).fMass) 59 #define G4MT_ccouple ((subInstanceManager.of 67 #define G4MT_ccouple ((subInstanceManager.offset[instanceID]).fCutsCouple) 60 #define G4MT_instance (subInstanceManager.off 68 #define G4MT_instance (subInstanceManager.offset[instanceID]) 61 69 62 // ******************************************* 70 // ******************************************************************** 63 // Constructor - sets member data and adds to 71 // Constructor - sets member data and adds to logical Store, 64 // voxel pointer for optimisatio 72 // voxel pointer for optimisation set to 0 by default. 65 // Initialises daughter vector t 73 // Initialises daughter vector to 0 length. 66 // ******************************************* 74 // ******************************************************************** 67 // 75 // 68 G4LogicalVolume::G4LogicalVolume( G4VSolid* pS 76 G4LogicalVolume::G4LogicalVolume( G4VSolid* pSolid, 69 G4Material* 77 G4Material* pMaterial, 70 const G4String& na 78 const G4String& name, 71 G4FieldManag 79 G4FieldManager* pFieldMgr, 72 G4VSensitive 80 G4VSensitiveDetector* pSDetector, 73 G4UserLimits 81 G4UserLimits* pULimits, 74 G4bool optim 82 G4bool optimise ) 75 : fDaughters(0,(G4VPhysicalVolume*)nullptr), << 83 : fDaughters(0,(G4VPhysicalVolume*)0), 76 fOptimise(optimise) << 84 fVoxel(0), fOptimise(optimise), fRootRegion(false), fLock(false), >> 85 fSmartless(2.), fVisAttributes(0), fRegion(0), fBiasWeight(1.) 77 { 86 { 78 // Initialize 'Shadow'/master pointers - for 87 // Initialize 'Shadow'/master pointers - for use in copying to workers 79 // 88 // 80 fSolid = pSolid; 89 fSolid = pSolid; 81 fSensitiveDetector = pSDetector; 90 fSensitiveDetector = pSDetector; 82 fFieldManager = pFieldMgr; 91 fFieldManager = pFieldMgr; 83 92 84 instanceID = subInstanceManager.CreateSubIns 93 instanceID = subInstanceManager.CreateSubInstance(); 85 AssignFieldManager(pFieldMgr); 94 AssignFieldManager(pFieldMgr); 86 95 87 G4MT_mass = 0.; 96 G4MT_mass = 0.; 88 G4MT_ccouple = nullptr; << 97 G4MT_ccouple = 0; 89 98 90 SetSolid(pSolid); 99 SetSolid(pSolid); 91 SetMaterial(pMaterial); 100 SetMaterial(pMaterial); 92 SetName(name); 101 SetName(name); 93 SetSensitiveDetector(pSDetector); 102 SetSensitiveDetector(pSDetector); 94 SetUserLimits(pULimits); 103 SetUserLimits(pULimits); 95 104 96 // Initialize 'Shadow' data structure - for 105 // Initialize 'Shadow' data structure - for use by object persistency 97 // 106 // 98 lvdata = new G4LVData(); 107 lvdata = new G4LVData(); 99 lvdata->fSolid = pSolid; 108 lvdata->fSolid = pSolid; 100 lvdata->fMaterial = pMaterial; 109 lvdata->fMaterial = pMaterial; 101 110 102 // 111 // 103 // Add to store 112 // Add to store 104 // 113 // 105 G4LogicalVolumeStore::Register(this); 114 G4LogicalVolumeStore::Register(this); 106 } 115 } 107 116 108 // ******************************************* 117 // ******************************************************************** 109 // Fake default constructor - sets only member 118 // Fake default constructor - sets only member data and allocates memory 110 // for usage restri 119 // for usage restricted to object persistency. 111 // ******************************************* 120 // ******************************************************************** 112 // 121 // 113 G4LogicalVolume::G4LogicalVolume( __void__& ) 122 G4LogicalVolume::G4LogicalVolume( __void__& ) 114 : fDaughters(0,(G4VPhysicalVolume*)nullptr), << 123 : fDaughters(0,(G4VPhysicalVolume*)0), >> 124 fName(""), fUserLimits(0), >> 125 fVoxel(0), fOptimise(true), fRootRegion(false), fLock(false), >> 126 fSmartless(2.), fVisAttributes(0), fRegion(0), fBiasWeight(1.), >> 127 fSolid(0), fSensitiveDetector(0), fFieldManager(0), lvdata(0) 115 { 128 { 116 instanceID = subInstanceManager.CreateSubIns 129 instanceID = subInstanceManager.CreateSubInstance(); 117 130 118 SetSensitiveDetector(nullptr); // G4MT_sd << 131 SetSensitiveDetector(0); // G4MT_sdetector = 0; 119 SetFieldManager(nullptr, false); // G4MT_fm << 132 SetFieldManager(0, false); // G4MT_fmanager = 0; 120 133 121 G4MT_mass = 0.; 134 G4MT_mass = 0.; 122 G4MT_ccouple = nullptr; << 135 G4MT_ccouple = 0; 123 136 124 // Add to store 137 // Add to store 125 // 138 // 126 G4LogicalVolumeStore::Register(this); 139 G4LogicalVolumeStore::Register(this); 127 } 140 } 128 141 129 // ******************************************* 142 // ******************************************************************** 130 // Destructor - Removes itself from solid Stor 143 // Destructor - Removes itself from solid Store 131 // NOTE: Not virtual 144 // NOTE: Not virtual 132 // ******************************************* 145 // ******************************************************************** 133 // 146 // 134 G4LogicalVolume::~G4LogicalVolume() 147 G4LogicalVolume::~G4LogicalVolume() 135 { 148 { 136 if (!fLock && fRootRegion) // De-register r 149 if (!fLock && fRootRegion) // De-register root region first if not locked 137 { // and flagged a 150 { // and flagged as root logical-volume 138 fRegion->RemoveRootLogicalVolume(this, tru 151 fRegion->RemoveRootLogicalVolume(this, true); 139 } 152 } 140 delete lvdata; 153 delete lvdata; 141 G4LogicalVolumeStore::DeRegister(this); 154 G4LogicalVolumeStore::DeRegister(this); 142 } 155 } 143 156 144 // ******************************************* 157 // ******************************************************************** 145 // SetName - Set volume name and notify store << 146 // ******************************************* << 147 // << 148 void G4LogicalVolume::SetName(const G4String& << 149 { << 150 fName = pName; << 151 G4LogicalVolumeStore::GetInstance()->SetMapV << 152 } << 153 << 154 // ******************************************* << 155 // InitialiseWorker 158 // InitialiseWorker 156 // 159 // 157 // This method is similar to the constructor. 160 // This method is similar to the constructor. It is used by each worker 158 // thread to achieve the same effect as that o 161 // thread to achieve the same effect as that of the master thread exept 159 // to register the new created instance. This 162 // to register the new created instance. This method is invoked explicitly. 160 // It does not create a new G4LogicalVolume in 163 // It does not create a new G4LogicalVolume instance. It only assign the value 161 // for the fields encapsulated by the class G4 164 // for the fields encapsulated by the class G4LVData. 162 // ******************************************* 165 // ******************************************************************** 163 // 166 // 164 void G4LogicalVolume:: 167 void G4LogicalVolume:: 165 InitialiseWorker( G4LogicalVolume* /*pMasterOb 168 InitialiseWorker( G4LogicalVolume* /*pMasterObject*/, 166 G4VSolid* pSolid, 169 G4VSolid* pSolid, 167 G4VSensitiveDetector* pSDete 170 G4VSensitiveDetector* pSDetector) 168 { 171 { 169 subInstanceManager.SlaveCopySubInstanceArray 172 subInstanceManager.SlaveCopySubInstanceArray(); 170 173 171 SetSolid(pSolid); 174 SetSolid(pSolid); 172 SetSensitiveDetector(pSDetector); // How th 175 SetSensitiveDetector(pSDetector); // How this object is available now ? 173 AssignFieldManager(fFieldManager); 176 AssignFieldManager(fFieldManager); 174 // Should be set - but a per-thread copy is 177 // Should be set - but a per-thread copy is not available yet 175 // Must not call SetFieldManager(), which p 178 // Must not call SetFieldManager(), which propagates FieldMgr 176 179 177 #ifdef CLONE_FIELD_MGR 180 #ifdef CLONE_FIELD_MGR 178 // Create a field FieldManager by cloning 181 // Create a field FieldManager by cloning 179 // 182 // 180 G4FieldManager workerFldMgr = fFieldManager- << 183 G4FieldManager workerFldMgr= fFieldManager->GetWorkerClone(G4bool* created); 181 if( created || (GetFieldManager() != workerF 184 if( created || (GetFieldManager() != workerFldMgr) ) 182 { 185 { 183 SetFieldManager(fFieldManager, false); // 186 SetFieldManager(fFieldManager, false); // which propagates FieldMgr 184 } 187 } 185 else 188 else 186 { 189 { 187 // Field manager existed and is equal to c 190 // Field manager existed and is equal to current one 188 // 191 // 189 AssignFieldManager(workerFldMgr); 192 AssignFieldManager(workerFldMgr); 190 } 193 } 191 #endif 194 #endif 192 } 195 } 193 196 194 // ******************************************* 197 // ******************************************************************** 195 // Clean 198 // Clean 196 // ******************************************* 199 // ******************************************************************** 197 // 200 // 198 void G4LogicalVolume::Clean() 201 void G4LogicalVolume::Clean() 199 { 202 { 200 subInstanceManager.FreeSlave(); 203 subInstanceManager.FreeSlave(); 201 } 204 } 202 205 203 // ******************************************* 206 // ******************************************************************** 204 // TerminateWorker 207 // TerminateWorker 205 // 208 // 206 // This method is similar to the destructor. I 209 // This method is similar to the destructor. It is used by each worker 207 // thread to achieve the partial effect as tha 210 // thread to achieve the partial effect as that of the master thread. 208 // For G4LogicalVolume instances, nothing more 211 // For G4LogicalVolume instances, nothing more to do here. 209 // ******************************************* 212 // ******************************************************************** 210 // 213 // 211 void G4LogicalVolume:: 214 void G4LogicalVolume:: 212 TerminateWorker( G4LogicalVolume* /*pMasterObj 215 TerminateWorker( G4LogicalVolume* /*pMasterObject*/) 213 { 216 { 214 } 217 } 215 218 216 // ******************************************* 219 // ******************************************************************** 217 // GetSubInstanceManager 220 // GetSubInstanceManager 218 // 221 // 219 // Returns the private data instance manager. 222 // Returns the private data instance manager. 220 // ******************************************* 223 // ******************************************************************** 221 // 224 // 222 const G4LVManager& G4LogicalVolume::GetSubInst 225 const G4LVManager& G4LogicalVolume::GetSubInstanceManager() 223 { 226 { 224 return subInstanceManager; 227 return subInstanceManager; 225 } 228 } 226 229 227 // ******************************************* 230 // ******************************************************************** 228 // GetFieldManager 231 // GetFieldManager 229 // ******************************************* 232 // ******************************************************************** 230 // 233 // 231 G4FieldManager* G4LogicalVolume::GetFieldManag 234 G4FieldManager* G4LogicalVolume::GetFieldManager() const 232 { 235 { 233 return G4MT_fmanager; 236 return G4MT_fmanager; 234 } 237 } 235 238 236 // ******************************************* 239 // ******************************************************************** 237 // AssignFieldManager 240 // AssignFieldManager 238 // ******************************************* 241 // ******************************************************************** 239 // 242 // 240 void G4LogicalVolume::AssignFieldManager( G4Fi 243 void G4LogicalVolume::AssignFieldManager( G4FieldManager *fldMgr) 241 { 244 { 242 G4MT_fmanager= fldMgr; 245 G4MT_fmanager= fldMgr; 243 if(G4Threading::IsMasterThread()) { fFieldM 246 if(G4Threading::IsMasterThread()) { fFieldManager = fldMgr; } 244 } 247 } 245 248 246 // ******************************************* 249 // ******************************************************************** 247 // IsExtended 250 // IsExtended 248 // ******************************************* 251 // ******************************************************************** 249 // 252 // 250 G4bool G4LogicalVolume::IsExtended() const 253 G4bool G4LogicalVolume::IsExtended() const 251 { 254 { 252 return false; 255 return false; 253 } 256 } 254 257 255 // ******************************************* 258 // ******************************************************************** 256 // SetFieldManager 259 // SetFieldManager 257 // ******************************************* 260 // ******************************************************************** 258 // 261 // 259 void 262 void 260 G4LogicalVolume::SetFieldManager(G4FieldManage 263 G4LogicalVolume::SetFieldManager(G4FieldManager* pNewFieldMgr, 261 G4bool 264 G4bool forceAllDaughters) 262 { 265 { 263 AssignFieldManager(pNewFieldMgr); 266 AssignFieldManager(pNewFieldMgr); 264 267 265 auto NoDaughters = GetNoDaughters(); << 268 G4int NoDaughters = GetNoDaughters(); 266 while ( (NoDaughters--)>0 ) 269 while ( (NoDaughters--)>0 ) 267 { 270 { 268 G4LogicalVolume* DaughterLogVol; 271 G4LogicalVolume* DaughterLogVol; 269 DaughterLogVol = GetDaughter(NoDaughters)- 272 DaughterLogVol = GetDaughter(NoDaughters)->GetLogicalVolume(); 270 if ( forceAllDaughters || (DaughterLogVol- << 273 if ( forceAllDaughters || (DaughterLogVol->GetFieldManager() == 0) ) 271 { 274 { 272 DaughterLogVol->SetFieldManager(pNewFiel 275 DaughterLogVol->SetFieldManager(pNewFieldMgr, forceAllDaughters); 273 } 276 } 274 } 277 } 275 } 278 } 276 279 277 // ******************************************* 280 // ******************************************************************** 278 // AddDaughter 281 // AddDaughter 279 // ******************************************* 282 // ******************************************************************** 280 // 283 // 281 void G4LogicalVolume::AddDaughter(G4VPhysicalV 284 void G4LogicalVolume::AddDaughter(G4VPhysicalVolume* pNewDaughter) 282 { 285 { 283 EVolume daughterType = pNewDaughter->VolumeT << 286 if( !fDaughters.empty() && fDaughters[0]->IsReplicated() ) 284 << 285 // The type of the navigation needed is dete << 286 // << 287 if( fDaughters.empty() ) << 288 { 287 { 289 fDaughtersVolumeType = daughterType; << 288 std::ostringstream message; 290 } << 289 message << "ERROR - Attempt to place a volume in a mother volume" << G4endl 291 else << 290 << " already containing a replicated volume." << G4endl 292 { << 291 << " A volume can either contain several placements" << G4endl 293 // Check consistency of detector descripti << 292 << " or a unique replica or parameterised volume !" << G4endl 294 << 293 << " Mother logical volume: " << GetName() << G4endl 295 // 1. A replica or parameterised volume ca << 294 << " Placing volume: " << pNewDaughter->GetName() << G4endl; 296 // << 295 G4Exception("G4LogicalVolume::AddDaughter()", "GeomMgt0002", 297 if( fDaughters[0]->IsReplicated() ) << 296 FatalException, message, 298 { << 297 "Replica or parameterised volume must be the only daughter !"); 299 std::ostringstream message; << 300 message << "ERROR - Attempt to place a v << 301 << G4endl << 302 << " already containing a repli << 303 << " A volume can either contai << 304 << " or a unique replica or par << 305 << " Mother logical volume: << 306 << " Placing volume: " << pN << 307 << G4endl; << 308 G4Exception("G4LogicalVolume::AddDaughte << 309 FatalException, message, << 310 "Replica or parameterised vo << 311 } << 312 else << 313 { << 314 // 2. Ensure that Placement and External << 315 // << 316 if( daughterType != fDaughtersVolumeTyp << 317 { << 318 std::ostringstream message; << 319 message << "ERROR - Attempt to place a << 320 << G4endl << 321 << " already containing a dif << 322 << " A volume can either cont << 323 << " - one or more placements << 324 << " - one or more 'external' << 325 << " Mother logical volume: << 326 << " Volume being placed: " << 327 << G4endl; << 328 G4Exception("G4LogicalVolume::AddDaugh << 329 FatalException, message, << 330 "Cannot mix placements and << 331 } << 332 } << 333 } 298 } 334 299 335 // Invalidate previous calculation of mass - 300 // Invalidate previous calculation of mass - if any - for all threads 336 // 301 // 337 G4MT_mass = 0.; 302 G4MT_mass = 0.; 338 fDaughters.push_back(pNewDaughter); 303 fDaughters.push_back(pNewDaughter); 339 304 340 G4LogicalVolume* pDaughterLogical = pNewDaug 305 G4LogicalVolume* pDaughterLogical = pNewDaughter->GetLogicalVolume(); 341 306 342 // Propagate the Field Manager, if the daugh 307 // Propagate the Field Manager, if the daughter has no field Manager 343 // 308 // 344 G4FieldManager* pDaughterFieldManager = pDau 309 G4FieldManager* pDaughterFieldManager = pDaughterLogical->GetFieldManager(); 345 310 346 // Avoid propagating the fieldManager pointe 311 // Avoid propagating the fieldManager pointer if null 347 // and daughter's one is null as well... 312 // and daughter's one is null as well... 348 // 313 // 349 if( (G4MT_fmanager != nullptr ) && (pDaughte << 314 if( (G4MT_fmanager !=0 ) && (pDaughterFieldManager == 0) ) 350 { 315 { 351 pDaughterLogical->SetFieldManager(G4MT_fma 316 pDaughterLogical->SetFieldManager(G4MT_fmanager, false); 352 } 317 } 353 if (fRegion != nullptr) << 318 if (fRegion) 354 { 319 { 355 PropagateRegion(); 320 PropagateRegion(); 356 fRegion->RegionModified(true); 321 fRegion->RegionModified(true); 357 } 322 } 358 } 323 } 359 324 360 // ******************************************* 325 // ******************************************************************** 361 // RemoveDaughter 326 // RemoveDaughter 362 // ******************************************* 327 // ******************************************************************** 363 // 328 // 364 void G4LogicalVolume::RemoveDaughter(const G4V 329 void G4LogicalVolume::RemoveDaughter(const G4VPhysicalVolume* p) 365 { 330 { 366 for (auto i=fDaughters.cbegin(); i!=fDaughte << 331 G4PhysicalVolumeList::iterator i; >> 332 for ( i=fDaughters.begin(); i!=fDaughters.end(); ++i ) 367 { 333 { 368 if (**i==*p) 334 if (**i==*p) 369 { 335 { 370 fDaughters.erase(i); 336 fDaughters.erase(i); 371 break; 337 break; 372 } 338 } 373 } 339 } 374 if (fRegion != nullptr) << 340 if (fRegion) 375 { 341 { 376 fRegion->RegionModified(true); 342 fRegion->RegionModified(true); 377 } 343 } 378 G4MT_mass = 0.; 344 G4MT_mass = 0.; 379 } 345 } 380 346 381 // ******************************************* 347 // ******************************************************************** 382 // ClearDaughters 348 // ClearDaughters 383 // ******************************************* 349 // ******************************************************************** 384 // 350 // 385 void G4LogicalVolume::ClearDaughters() 351 void G4LogicalVolume::ClearDaughters() 386 { 352 { 387 fDaughters.erase(fDaughters.cbegin(), fDaugh << 353 fDaughters.erase(fDaughters.begin(), fDaughters.end()); 388 if (fRegion != nullptr) << 354 if (fRegion) 389 { 355 { 390 fRegion->RegionModified(true); 356 fRegion->RegionModified(true); 391 } 357 } 392 G4MT_mass = 0.; 358 G4MT_mass = 0.; 393 } 359 } 394 360 395 // ******************************************* 361 // ******************************************************************** 396 // ResetMass 362 // ResetMass 397 // ******************************************* 363 // ******************************************************************** 398 // 364 // 399 void G4LogicalVolume::ResetMass() 365 void G4LogicalVolume::ResetMass() 400 { 366 { 401 G4MT_mass= 0.0; 367 G4MT_mass= 0.0; 402 } 368 } 403 369 404 // ******************************************* 370 // ******************************************************************** 405 // GetSolid 371 // GetSolid 406 // ******************************************* 372 // ******************************************************************** 407 // 373 // 408 G4VSolid* G4LogicalVolume::GetSolid(G4LVData & 374 G4VSolid* G4LogicalVolume::GetSolid(G4LVData &instLVdata) // const 409 { 375 { 410 return instLVdata.fSolid; 376 return instLVdata.fSolid; 411 } 377 } 412 378 413 G4VSolid* G4LogicalVolume::GetSolid() const 379 G4VSolid* G4LogicalVolume::GetSolid() const 414 { 380 { 415 return this->GetSolid( subInstanceManager.of 381 return this->GetSolid( subInstanceManager.offset[instanceID] ); 416 } 382 } 417 383 418 // ******************************************* 384 // ******************************************************************** 419 // SetSolid 385 // SetSolid 420 // ******************************************* 386 // ******************************************************************** 421 // 387 // 422 void G4LogicalVolume::SetSolid(G4VSolid *pSoli 388 void G4LogicalVolume::SetSolid(G4VSolid *pSolid) 423 { 389 { 424 390 425 G4MT_solid = pSolid; 391 G4MT_solid = pSolid; 426 this->ResetMass(); 392 this->ResetMass(); 427 } 393 } 428 394 429 void G4LogicalVolume::SetSolid(G4LVData& instL << 395 void G4LogicalVolume::SetSolid(G4LVData &instLVdata, G4VSolid *pSolid) 430 { 396 { 431 instLVdata.fSolid = pSolid; 397 instLVdata.fSolid = pSolid; 432 instLVdata.fMass = 0.0; << 398 instLVdata.fMass= 0; >> 399 // A fast way to reset the mass... i.e. G4MT_mass = 0.; 433 } 400 } 434 401 435 // ******************************************* 402 // ******************************************************************** 436 // GetMaterial 403 // GetMaterial 437 // ******************************************* 404 // ******************************************************************** 438 // 405 // 439 G4Material* G4LogicalVolume::GetMaterial() con 406 G4Material* G4LogicalVolume::GetMaterial() const 440 { 407 { 441 return G4MT_material; 408 return G4MT_material; 442 } 409 } 443 410 444 // ******************************************* 411 // ******************************************************************** 445 // SetMaterial 412 // SetMaterial 446 // ******************************************* 413 // ******************************************************************** 447 // 414 // 448 void G4LogicalVolume::SetMaterial(G4Material* << 415 void G4LogicalVolume::SetMaterial(G4Material *pMaterial) 449 { 416 { 450 G4MT_material = pMaterial; 417 G4MT_material = pMaterial; 451 G4MT_mass = 0.0; << 418 G4MT_mass = 0.; 452 } 419 } 453 420 454 // ******************************************* 421 // ******************************************************************** 455 // UpdateMaterial 422 // UpdateMaterial 456 // ******************************************* 423 // ******************************************************************** 457 // 424 // 458 void G4LogicalVolume::UpdateMaterial(G4Materia << 425 void G4LogicalVolume::UpdateMaterial(G4Material *pMaterial) 459 { 426 { 460 G4MT_material=pMaterial; 427 G4MT_material=pMaterial; 461 if (fRegion != nullptr) { G4MT_ccouple = fRe << 428 if (fRegion) { G4MT_ccouple = fRegion->FindCouple(pMaterial); } 462 G4MT_mass = 0.0; << 429 G4MT_mass = 0.; 463 } 430 } 464 431 465 // ******************************************* 432 // ******************************************************************** 466 // GetSensitiveDetector 433 // GetSensitiveDetector 467 // ******************************************* 434 // ******************************************************************** 468 // 435 // 469 G4VSensitiveDetector* G4LogicalVolume::GetSens 436 G4VSensitiveDetector* G4LogicalVolume::GetSensitiveDetector() const 470 { 437 { 471 return G4MT_sdetector; 438 return G4MT_sdetector; 472 } 439 } 473 440 474 // ******************************************* 441 // ******************************************************************** 475 // SetSensitiveDetector 442 // SetSensitiveDetector 476 // ******************************************* 443 // ******************************************************************** 477 // 444 // 478 void G4LogicalVolume::SetSensitiveDetector(G4V 445 void G4LogicalVolume::SetSensitiveDetector(G4VSensitiveDetector* pSDetector) 479 { 446 { 480 G4MT_sdetector = pSDetector; 447 G4MT_sdetector = pSDetector; 481 if (G4Threading::IsMasterThread()) { fSensi 448 if (G4Threading::IsMasterThread()) { fSensitiveDetector = pSDetector; } 482 } 449 } 483 450 484 // ******************************************* 451 // ******************************************************************** 485 // GetMaterialCutsCouple 452 // GetMaterialCutsCouple 486 // ******************************************* 453 // ******************************************************************** 487 // 454 // 488 const G4MaterialCutsCouple* G4LogicalVolume::G 455 const G4MaterialCutsCouple* G4LogicalVolume::GetMaterialCutsCouple() const 489 { 456 { 490 return G4MT_ccouple; 457 return G4MT_ccouple; 491 } 458 } 492 459 493 // ******************************************* 460 // ******************************************************************** 494 // SetMaterialCutsCouple 461 // SetMaterialCutsCouple 495 // ******************************************* 462 // ******************************************************************** 496 // 463 // 497 void G4LogicalVolume::SetMaterialCutsCouple(G4 464 void G4LogicalVolume::SetMaterialCutsCouple(G4MaterialCutsCouple* cuts) 498 { 465 { 499 G4MT_ccouple = cuts; 466 G4MT_ccouple = cuts; 500 } 467 } 501 468 502 // ******************************************* 469 // ******************************************************************** 503 // IsAncestor 470 // IsAncestor 504 // 471 // 505 // Finds out if the current logical volume is 472 // Finds out if the current logical volume is an ancestor of a given 506 // physical volume 473 // physical volume 507 // ******************************************* 474 // ******************************************************************** 508 // 475 // 509 G4bool 476 G4bool 510 G4LogicalVolume::IsAncestor(const G4VPhysicalV 477 G4LogicalVolume::IsAncestor(const G4VPhysicalVolume* aVolume) const 511 { 478 { 512 G4bool isDaughter = IsDaughter(aVolume); 479 G4bool isDaughter = IsDaughter(aVolume); 513 if (!isDaughter) 480 if (!isDaughter) 514 { 481 { 515 for (auto itDau = fDaughters.cbegin(); itD << 482 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin(); >> 483 itDau != fDaughters.end(); itDau++) 516 { 484 { 517 isDaughter = (*itDau)->GetLogicalVolume( 485 isDaughter = (*itDau)->GetLogicalVolume()->IsAncestor(aVolume); 518 if (isDaughter) break; 486 if (isDaughter) break; 519 } 487 } 520 } 488 } 521 return isDaughter; 489 return isDaughter; 522 } 490 } 523 491 524 // ******************************************* 492 // ******************************************************************** 525 // TotalVolumeEntities 493 // TotalVolumeEntities 526 // 494 // 527 // Returns the total number of physical volume 495 // Returns the total number of physical volumes (replicated or placed) 528 // in the tree represented by the current logi 496 // in the tree represented by the current logical volume. 529 // ******************************************* 497 // ******************************************************************** 530 // 498 // 531 G4int G4LogicalVolume::TotalVolumeEntities() c 499 G4int G4LogicalVolume::TotalVolumeEntities() const 532 { 500 { 533 G4int vols = 1; 501 G4int vols = 1; 534 for (auto itDau = fDaughters.cbegin(); itDau << 502 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin(); >> 503 itDau != fDaughters.end(); itDau++) 535 { 504 { 536 G4VPhysicalVolume* physDaughter = (*itDau) 505 G4VPhysicalVolume* physDaughter = (*itDau); 537 vols += physDaughter->GetMultiplicity() 506 vols += physDaughter->GetMultiplicity() 538 *physDaughter->GetLogicalVolume()-> 507 *physDaughter->GetLogicalVolume()->TotalVolumeEntities(); 539 } 508 } 540 return vols; 509 return vols; 541 } 510 } 542 511 543 // ******************************************* 512 // ******************************************************************** 544 // GetMass 513 // GetMass 545 // 514 // 546 // Returns the mass of the logical volume tree 515 // Returns the mass of the logical volume tree computed from the 547 // estimated geometrical volume of each solid 516 // estimated geometrical volume of each solid and material associated 548 // to the logical volume and its daughters. 517 // to the logical volume and its daughters. 549 // NOTE: the computation may require considera 518 // NOTE: the computation may require considerable amount of time, 550 // depending from the complexity of the 519 // depending from the complexity of the geometry tree. 551 // The returned value is cached and can 520 // The returned value is cached and can be used for successive 552 // calls (default), unless recomputation 521 // calls (default), unless recomputation is forced by providing 553 // 'true' for the boolean argument in in 522 // 'true' for the boolean argument in input. Computation should 554 // be forced if the geometry setup has c 523 // be forced if the geometry setup has changed after the previous 555 // call. By setting the 'propagate' bool 524 // call. By setting the 'propagate' boolean flag to 'false' the 556 // method returns the mass of the presen 525 // method returns the mass of the present logical volume only 557 // (subtracted for the volume occupied b 526 // (subtracted for the volume occupied by the daughter volumes). 558 // The extra argument 'parMaterial' is i 527 // The extra argument 'parMaterial' is internally used to 559 // consider cases of geometrical paramet 528 // consider cases of geometrical parameterisations by material. 560 // ******************************************* 529 // ******************************************************************** 561 // 530 // 562 G4double G4LogicalVolume::GetMass(G4bool force 531 G4double G4LogicalVolume::GetMass(G4bool forced, 563 G4bool propa 532 G4bool propagate, 564 G4Material* 533 G4Material* parMaterial) 565 { 534 { 566 // Return the cached non-zero value, if not 535 // Return the cached non-zero value, if not forced 567 // 536 // 568 if ( ((G4MT_mass) != 0.0) && (!forced) ) { << 537 if ( (G4MT_mass) && (!forced) ) { return G4MT_mass; } 569 538 570 // Global density and computed mass associat 539 // Global density and computed mass associated to the logical 571 // volume without considering its daughters 540 // volume without considering its daughters 572 // 541 // 573 G4Material* logMaterial = parMaterial != nul << 542 G4Material* logMaterial = parMaterial ? parMaterial : GetMaterial(); 574 if (logMaterial == nullptr) << 543 if (!logMaterial) 575 { 544 { 576 std::ostringstream message; 545 std::ostringstream message; 577 message << "No material associated to the 546 message << "No material associated to the logical volume: " 578 << fName << " !" << G4endl 547 << fName << " !" << G4endl 579 << "Sorry, cannot compute the mass 548 << "Sorry, cannot compute the mass ..."; 580 G4Exception("G4LogicalVolume::GetMass()", 549 G4Exception("G4LogicalVolume::GetMass()", "GeomMgt0002", 581 FatalException, message); 550 FatalException, message); 582 return 0.0; << 551 return 0; 583 } 552 } 584 if ( GetSolid() == nullptr ) << 553 if ( !GetSolid() ) 585 { 554 { 586 std::ostringstream message; 555 std::ostringstream message; 587 message << "No solid is associated to the 556 message << "No solid is associated to the logical volume: " 588 << fName << " !" << G4endl 557 << fName << " !" << G4endl 589 << "Sorry, cannot compute the mass 558 << "Sorry, cannot compute the mass ..."; 590 G4Exception("G4LogicalVolume::GetMass()", 559 G4Exception("G4LogicalVolume::GetMass()", "GeomMgt0002", 591 FatalException, message); 560 FatalException, message); 592 return 0.0; << 561 return 0; 593 } 562 } 594 G4double globalDensity = logMaterial->GetDen 563 G4double globalDensity = logMaterial->GetDensity(); 595 G4double motherMass = GetSolid()->GetCubicVo << 564 G4double motherMass= GetSolid()->GetCubicVolume() * globalDensity; 596 G4double massSum = motherMass; 565 G4double massSum = motherMass; 597 566 598 // For each daughter in the tree, subtract t 567 // For each daughter in the tree, subtract the mass occupied 599 // and if required by the propagate flag, ad 568 // and if required by the propagate flag, add the real daughter's 600 // one computed recursively 569 // one computed recursively 601 570 602 for (auto itDau = fDaughters.cbegin(); itDau << 571 for (G4PhysicalVolumeList::const_iterator itDau = fDaughters.begin(); >> 572 itDau != fDaughters.end(); itDau++) 603 { 573 { 604 G4VPhysicalVolume* physDaughter = (*itDau) 574 G4VPhysicalVolume* physDaughter = (*itDau); 605 G4LogicalVolume* logDaughter = physDaughte 575 G4LogicalVolume* logDaughter = physDaughter->GetLogicalVolume(); 606 G4double subMass = 0.0; << 576 G4double subMass=0.; 607 G4VSolid* daughterSolid = nullptr; << 577 G4VSolid* daughterSolid = 0; 608 G4Material* daughterMaterial = nullptr; << 578 G4Material* daughterMaterial = 0; 609 579 610 // Compute the mass to subtract and to add 580 // Compute the mass to subtract and to add for each daughter 611 // considering its multiplicity (i.e. repl 581 // considering its multiplicity (i.e. replicated or not) and 612 // eventually its parameterisation (by sol 582 // eventually its parameterisation (by solid and/or by material) 613 // 583 // 614 for (auto i=0; i<physDaughter->GetMultipli << 584 for (G4int i=0; i<physDaughter->GetMultiplicity(); i++) 615 { 585 { 616 G4VPVParameterisation* physParam = physD 586 G4VPVParameterisation* physParam = physDaughter->GetParameterisation(); 617 if (physParam != nullptr) << 587 if (physParam) 618 { 588 { 619 daughterSolid = physParam->ComputeSoli 589 daughterSolid = physParam->ComputeSolid(i, physDaughter); 620 daughterSolid->ComputeDimensions(physP 590 daughterSolid->ComputeDimensions(physParam, i, physDaughter); 621 daughterMaterial = physParam->ComputeM 591 daughterMaterial = physParam->ComputeMaterial(i, physDaughter); 622 } 592 } 623 else 593 else 624 { 594 { 625 daughterSolid = logDaughter->GetSolid( 595 daughterSolid = logDaughter->GetSolid(); 626 daughterMaterial = logDaughter->GetMat 596 daughterMaterial = logDaughter->GetMaterial(); 627 } 597 } 628 subMass = daughterSolid->GetCubicVolume( 598 subMass = daughterSolid->GetCubicVolume() * globalDensity; 629 599 630 // Subtract the daughter's portion for t 600 // Subtract the daughter's portion for the mass and, if required, 631 // add the real daughter's mass computed 601 // add the real daughter's mass computed recursively 632 // 602 // 633 massSum -= subMass; 603 massSum -= subMass; 634 if (propagate) 604 if (propagate) 635 { 605 { 636 massSum += logDaughter->GetMass(true, 606 massSum += logDaughter->GetMass(true, true, daughterMaterial); 637 } 607 } 638 } 608 } 639 } 609 } 640 G4MT_mass = massSum; << 610 G4MT_mass= massSum; 641 return massSum; 611 return massSum; 642 } 612 } 643 613 644 // ******************************************* << 645 // Change the daughters volume type -- checkin << 646 // << 647 // Undertakes primitive checking, to ensure t << 648 // are made: << 649 // - any type to 'external' ( user respons << 650 // - the type proposed is checked against t << 651 // (for potential switch back to 'intern << 652 // Returns success (true) or failure (false) << 653 // << 654 G4bool G4LogicalVolume::ChangeDaughtersType(EV << 655 { << 656 G4bool works = false; << 657 if( aType == kExternal ) << 658 { << 659 // It is the responsibility of External Na << 660 // << 661 fDaughtersVolumeType = aType; << 662 works = true; << 663 } << 664 else << 665 { << 666 EVolume expectedVType = DeduceDaughtersTyp << 667 works = (expectedVType == aType); << 668 if ( works ) << 669 { << 670 fDaughtersVolumeType = aType; << 671 } << 672 } << 673 return works; << 674 } << 675 << 676 // ******************************************* << 677 // SetVisAttributes - copy version << 678 // ******************************************* << 679 // << 680 void G4LogicalVolume::SetVisAttributes (const 614 void G4LogicalVolume::SetVisAttributes (const G4VisAttributes& VA) 681 { 615 { 682 if (G4Threading::IsWorkerThread()) return; << 616 fVisAttributes = new G4VisAttributes(VA); 683 fVisAttributes = std::make_shared<const G4Vi << 684 } << 685 << 686 // ******************************************* << 687 // SetVisAttributes << 688 // ******************************************* << 689 // << 690 void G4LogicalVolume::SetVisAttributes (const << 691 { << 692 if (G4Threading::IsWorkerThread()) return; << 693 fVisAttributes = std::shared_ptr<const G4Vis << 694 } 617 } 695 618