Skip to content

Latest commit

 

History

History
694 lines (633 loc) · 23.3 KB

G4LogicalVolume.cc

File metadata and controls

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