-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathGateDetectorConstruction.cc
executable file
·531 lines (443 loc) · 19.2 KB
/
GateDetectorConstruction.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*----------------------
Copyright (C): OpenGATE Collaboration
This software is distributed under the terms
of the GNU Lesser General Public Licence (LGPL)
See LICENSE.md for further details
----------------------*/
#include "GateConfiguration.h"
#include "GateDetectorConstruction.hh"
#include "GateDetectorMessenger.hh"
#include "GateRunManager.hh"
#include "GateVVolume.hh"
#include "GateBox.hh"
#include "GateObjectStore.hh"
#include "GateSystemListManager.hh"
#include "GateMaterialDatabase.hh"
#include "GateCrystalSD.hh"
#include "GatePhantomSD.hh"
#include "GateMessageManager.hh"
#include "GateObjectMoveListMessenger.hh"
#include "GateARFSD.hh"
#include "GateMagTabulatedField3D.hh"
#include "GateElectricTabulatedField3D.hh"
#include "GateElectricMagTabulatedField3D.hh"
#include "globals.hh"
#include "G4Navigator.hh"
#include "G4SDManager.hh"
#include "G4Material.hh"
#include "G4NistManager.hh"
#ifdef GATE_USE_OPTICAL
#include "GateSurfaceList.hh"
#endif
GateDetectorConstruction* GateDetectorConstruction::pTheGateDetectorConstruction=0;
//---------------------------------------------------------------------------------
GateDetectorConstruction::GateDetectorConstruction()
: pworld(0),
pworldPhysicalVolume(0),
nGeometryStatus(geometry_needs_rebuild),
flagAutoUpdate(false),
m_crystalSD(0),
m_phantomSD(0),
pdetectorMessenger(0),
moveFlag(0),
m_magField(0), m_magFieldValue(0),
e_electFieldValue(0),
m_magFieldUniform(false), m_magFieldTabulated(false),
e_electFieldUniform(false), e_electFieldTabulated(false),
em_electmagFieldTabulated(false),
m_MagField(0), e_ElecField(0), em_ElecMagField(0),
fEquation_B(0), fEquation_E(0),
fFieldMgr(0), fStepper(0),
fMinStep(1*um),
fDeltaChord(1*um),
fDeltaIntersection(1*nm),
fDeltaOneStep(1*nm),
fMinimumEpsilonStep(1e-11),
fMaximumEpsilonStep(1e-10),
fIntegratorStepper("ClassicalRK4"),
nvarOfIntegratorStepper(8) // The Equation of motion for Electric (or combined Electric/Magnetic)
// field requires 8 integration variables
{
GateMessage("Geometry", 1, "GateDetectorConstruction instantiating...\n");
GateMessage("Geometry", 5, " GateDetectorConstruction constructor -- begin ");
GateMessage("Geometry", 5, " nGeometryStatus = " << nGeometryStatus << Gateendl;);
pTheGateDetectorConstruction = this;
pcreatorStore = GateObjectStore::GetInstance();
psystemStore=GateSystemListManager::GetInstance();
pdetectorMessenger = new GateDetectorMessenger(this);
m_magFieldValue = G4ThreeVector(0.,0.,0. * tesla);
e_electFieldValue = G4ThreeVector(0.,0.,0. * keV);
G4double pworld_x = 50.*cm;
G4double pworld_y = 50.*cm;
G4double pworld_z = 50.*cm;
//-------------------------------------------------------------------------
// Create default material (air) for the world
G4String AirName = "worldDefaultAir";
G4Material* Air = G4NistManager::Instance()->FindOrBuildMaterial("G4_AIR"); // Use Air for NIST Manager
if (Air==NULL)//will never enter here
{
G4Element* N = new G4Element("worldDefaultN","N" , 7., 14.01*g/mole );
G4Element* O = new G4Element("worldDefaultO","O" , 8., 16.00*g/mole);
G4Material* Air = new G4Material(AirName , 1.290*mg/cm3, 2);
Air->AddElement(N, 0.7);
Air->AddElement(O, 0.3);
}
else Air->SetName(AirName);//For compatibility put name of this Air material to "worldDefaultAir"
//-------------------------------------------------------------------------
pworld = new GateBox("world", "worldDefaultAir", pworld_x, pworld_y, pworld_z, true);
pworld->SetMaterialName("worldDefaultAir");
G4SDManager* SDman = G4SDManager::GetSDMpointer();
if(!m_crystalSD) {
G4String crystalSDname = "/gate/crystal";
m_crystalSD = new GateCrystalSD(crystalSDname);
SDman->AddNewDetector(m_crystalSD);
}
if(!m_phantomSD) {
G4String phantomSDname = "/gate/phantom";
m_phantomSD = new GatePhantomSD(phantomSDname);
SDman->AddNewDetector(m_phantomSD);
}
GateMessage("Geometry", 5, " GateDetectorConstruction constructor -- end ");
/* instantiate the singleton RTPhantom Manager - PY Descourt 08/09/2008 */
m_RTPhantomMgr = GateRTPhantomMgr::GetInstance();
m_ARFSD = 0;
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
GateDetectorConstruction::~GateDetectorConstruction()
{
if (pworld) {
DestroyGeometry();
delete pworld;
pworld = 0;
}
delete pdetectorMessenger;
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
G4VPhysicalVolume* GateDetectorConstruction::Construct()
{
GateMessage("Geometry", 3, "Geometry construction starts. \n");
pworldPhysicalVolume = pworld->GateVVolume::Construct();
SetGeometryStatusFlag(geometry_is_uptodate);
GateMessage("Physic", 1, " \n");
GateMessage("Physic", 1, "----------------------------------------------------------\n");
GateMessage("Physic", 1, " Ionization potential \n");
const G4MaterialTable * theTable = G4Material::GetMaterialTable();
for(unsigned int i =0;i<(*theTable).size();i++){
if(theListOfIonisationPotential[(*theTable)[i]->GetName()]){
(*theTable)[i]->GetIonisation()->SetMeanExcitationEnergy(theListOfIonisationPotential[(*theTable)[i]->GetName()]);
GateMessage("Physic", 1, " - " << (*theTable)[i]->GetName() << "\t defaut value: I = " <<
G4BestUnit((*theTable)[i]->GetIonisation()->GetMeanExcitationEnergy(),"Energy") <<
"\t--> new value: I = " <<
G4BestUnit((*theTable)[i]->GetIonisation()->GetMeanExcitationEnergy(),"Energy") << Gateendl);
}
else {
GateMessage("Physic", 1, " - " << (*theTable)[i]->GetName() << "\t defaut value: I = " <<
G4BestUnit((*theTable)[i]->GetIonisation()->GetMeanExcitationEnergy(),"Energy") << Gateendl);
}
}
GateMessage("Physic", 1, "----------------------------------------------------------\n");
GateMessage("Geometry", 3, "Geometry has been constructed (status = " << nGeometryStatus << ").\n");
#ifdef GATE_USE_OPTICAL
BuildSurfaces();
#endif
BuildField();
return pworldPhysicalVolume;
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
// Adds a Material Database
void GateDetectorConstruction::AddFileToMaterialDatabase(const G4String& f)
{
mMaterialDatabase.AddMDBFile(f);
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetElectField(G4ThreeVector fieldValue)
{
e_electFieldValue = fieldValue;
e_electFieldUniform = true;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetElectFieldTabulatedFile(G4String filenameFieldTable)
{
e_electFieldTabulatedFile = filenameFieldTable;
e_electFieldTabulated = true;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetElectMagFieldTabulatedFile(G4String filenameFieldTable)
{
em_electmagFieldTabulatedFile = filenameFieldTable;
em_electmagFieldTabulated = true;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagField(G4ThreeVector fieldValue)
{
m_magFieldValue = fieldValue;
m_magFieldUniform = true;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagFieldTabulatedFile(G4String filenameFieldTable)
{
m_magFieldTabulatedFile = filenameFieldTable;
m_magFieldTabulated = true;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagStepMinimum(G4double MinStep){
fMinStep = MinStep;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagDeltaChord(G4double DeltaChord){
fDeltaChord = DeltaChord;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagDeltaIntersection(G4double DeltaIntersection){
fDeltaIntersection = DeltaIntersection;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagDeltaOneStep(G4double DeltaOneStep){
fDeltaOneStep = DeltaOneStep;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagMinimumEpsilonStep(G4double MinEpsilonStep){
fMinimumEpsilonStep = MinEpsilonStep;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetMagMaximumEpsilonStep(G4double MaxEpsilonStep){
fMaximumEpsilonStep = MaxEpsilonStep;
}
void GateDetectorConstruction::SetMagIntegratorStepper(G4String IntegratorStepper ){
fIntegratorStepper = IntegratorStepper;
}
//---------------------------------------------------------------------------------
void GateDetectorConstruction::SetField(){
if (m_magFieldTabulated){
fEquation_B = new G4Mag_UsualEqRhs (m_MagField);
if (fIntegratorStepper == "ExplicitEuler"){
fStepper = new G4ExplicitEuler (fEquation_B, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "ImplicitEuler") {
fStepper = new G4ImplicitEuler (fEquation_B, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleRunge") {
fStepper = new G4SimpleRunge (fEquation_B, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleHeum") {
fStepper = new G4SimpleHeum (fEquation_B, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "NystromRK4") {
fStepper = new G4NystromRK4 (fEquation_B);
}
else {
fStepper = new G4ClassicalRK4 (fEquation_B,nvarOfIntegratorStepper);
}
fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
G4MagInt_Driver* pIntgrDriver_B = new G4MagInt_Driver(1*mm,fStepper,nvarOfIntegratorStepper);
G4ChordFinder* fChordFinder_B = new G4ChordFinder(pIntgrDriver_B);
fFieldMgr->SetChordFinder(fChordFinder_B);
fFieldMgr->SetDetectorField(m_MagField);
GateMessage("Core", 0, " THE FOLLOWING INTEGRATOR STEPPER FOR MAGNETIC FIELD HAS BEEN ACTIVATED: "
<< fIntegratorStepper << Gateendl);
}
if (e_electFieldTabulated){
fEquation_E = new G4EqMagElectricField(e_ElecField);
if (fIntegratorStepper == "ExplicitEuler"){
fStepper = new G4ExplicitEuler (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "ImplicitEuler") {
fStepper = new G4ImplicitEuler (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleRunge") {
fStepper = new G4SimpleRunge (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleHeum") {
fStepper = new G4SimpleHeum (fEquation_E, nvarOfIntegratorStepper);
}
else {
fStepper = new G4ClassicalRK4 (fEquation_E,nvarOfIntegratorStepper);
}
fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
G4MagInt_Driver *pIntgrDriver_E = new G4MagInt_Driver(1*mm, fStepper, nvarOfIntegratorStepper);
G4ChordFinder *fChordFinder_E = new G4ChordFinder(pIntgrDriver_E);
fFieldMgr -> SetChordFinder(fChordFinder_E);
fFieldMgr->SetDetectorField(e_ElecField);
GateMessage("Core", 0, " THE FOLLOWING INTEGRATOR STEPPER FOR ELECTRIC FIELD HAS BEEN ACTIVATED: "
<< fIntegratorStepper << Gateendl);
}
if (em_electmagFieldTabulated){
fEquation_E = new G4EqMagElectricField(em_ElecMagField);
if (fIntegratorStepper == "ExplicitEuler"){
fStepper = new G4ExplicitEuler (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "ImplicitEuler") {
fStepper = new G4ImplicitEuler (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleRunge") {
fStepper = new G4SimpleRunge (fEquation_E, nvarOfIntegratorStepper);
}
else if (fIntegratorStepper == "SimpleHeum") {
fStepper = new G4SimpleHeum (fEquation_E, nvarOfIntegratorStepper);
}
else {
fStepper = new G4ClassicalRK4 (fEquation_E,nvarOfIntegratorStepper);
}
fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
G4MagInt_Driver *pIntgrDriver_EB = new G4MagInt_Driver(1*mm, fStepper, nvarOfIntegratorStepper);
G4ChordFinder *fChordFinder_EB = new G4ChordFinder(pIntgrDriver_EB);
fFieldMgr -> SetChordFinder(fChordFinder_EB);
fFieldMgr->SetDetectorField(em_ElecMagField);
GateMessage("Core", 0, " THE FOLLOWING INTEGRATOR STEPPER FOR ELECTROMAGNETIC FIELD HAS BEEN ACTIVATED: "
<< fIntegratorStepper << Gateendl);
}
fFieldMgr->GetChordFinder()->SetDeltaChord(fDeltaChord);
fFieldMgr->SetDeltaIntersection(fDeltaIntersection);
fFieldMgr->SetDeltaOneStep(fDeltaOneStep);
G4PropagatorInField *fPropInField = G4TransportationManager::GetTransportationManager()->GetPropagatorInField();
fPropInField->SetMinimumEpsilonStep(fMinimumEpsilonStep);
fPropInField->SetMaximumEpsilonStep(fMaximumEpsilonStep);
GateMessage("Core", 0, "\n" <<
"---> fMinStep " << fMinStep/mm << " mm \n"
"---> fDeltaChord "<<fDeltaChord/mm <<" mm \n"
"---> fDeltaIntersection "<<fFieldMgr->GetDeltaIntersection()/mm <<" mm \n"
"---> fDeltaOneStep "<<fFieldMgr->GetDeltaOneStep()/mm <<" mm \n"
"---> fMinimumEpsilonStep "<<fMinimumEpsilonStep << " \n"
"---> fMaximumEpsilonStep "<<fMaximumEpsilonStep << " \n"
"-----------------------------------------------------------"<< Gateendl);
}
void GateDetectorConstruction::BuildField()
{
if (m_magFieldUniform){
fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
if(m_magField) delete m_magField; //delete the existing mag field
if(m_magFieldValue.mag()!=0.){ // create a new one if non null
m_magField = new G4UniformMagField(m_magFieldValue);
fFieldMgr->SetDetectorField(m_magField);
fFieldMgr->CreateChordFinder(m_magField);
} else {
m_magField = NULL;
fFieldMgr->SetDetectorField(m_magField);
}
} else if (m_magFieldTabulated) {
if(m_MagField) delete m_MagField;
m_MagField = new GateMagTabulatedField3D(m_magFieldTabulatedFile);
SetField();
} else if (e_electFieldUniform){
fFieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
if(e_ElecField) delete e_ElecField; //delete the existing elect field
if(e_electFieldValue.mag()!=0.){ // create a new one if non null
e_ElecField = new G4UniformElectricField(e_electFieldValue);
fFieldMgr->SetDetectorField(e_ElecField);
} else {
e_ElecField = NULL;
fFieldMgr->SetDetectorField(m_magField);
}
} else if (e_electFieldTabulated) {
fFieldMgr = new G4FieldManager();
e_ElecField = new GateElectricTabulatedField3D(e_electFieldTabulatedFile);
SetField();
} else if (em_electmagFieldTabulated) {
fFieldMgr = new G4FieldManager();
em_ElecMagField = new GateElectricMagTabulatedField3D(em_electmagFieldTabulatedFile);
SetField();
}
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
#ifdef GATE_USE_OPTICAL
void GateDetectorConstruction::BuildSurfaces()
{
GateObjectStore* store = GateObjectStore::GetInstance();
for (GateObjectStore::iterator p = store->begin(); p != store->end(); p++)
{
p->second->GetSurfaceList()->BuildSurfaces();
}
}
#endif
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
void GateDetectorConstruction::UpdateGeometry()
{
GateMessage("Geometry", 3,"UpdateGeometry starts (status = " << nGeometryStatus << "). \n");
if (nGeometryStatus == geometry_is_uptodate){
GateMessage("Geometry", 3,"Geometry is uptodate.\n");
return;
}
switch (nGeometryStatus){
case geometry_needs_update:
pworld->Construct(true);
break;
case geometry_needs_rebuild:
default:
DestroyGeometry();
Construct();
break;
}
GateRunManager::GetRunManager()->DefineWorldVolume(pworldPhysicalVolume);
nGeometryStatus = geometry_is_uptodate;
GateMessage("Geometry", 3, "nGeometryStatus = geometry_is_uptodate \n");
GateMessage("Geometry", 3, "UpdateGeometry finished. \n");
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
void GateDetectorConstruction::DestroyGeometry()
{
GateMessageInc("Geometry", 4,"Geometry is going to be destroyed.\n");
pworld->DestroyGeometry();
nGeometryStatus = geometry_needs_rebuild;
GateMessage("Geometry", 4,"nGeometryStatus = geometry_needs_rebuild\n");
GateMessageDec("Geometry", 4,"Geometry has been destroyed.\n");
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
/*
void GateDetectorConstruction::GeometryHasChanged(GeometryStatus changeLevel)
{
GateMessage("Geometry", 3, " nGeometryStatus = " << nGeometryStatus << " changeLevel = " << changeLevel << Gateendl;);
if (flagAutoUpdate == 0)
GateMessage("Geometry", 3, " flagAutoUpdate = " << flagAutoUpdate << Gateendl;);
if ( changeLevel > nGeometryStatus )
nGeometryStatus = changeLevel;
if (nGeometryStatus == 0){
GateMessage("Geometry", 3, " The geometry is uptodate.\n";);
}
else if (nGeometryStatus == 1){
GateMessage("Geometry", 3, " The geometry needs to be uptodated.\n";);
}
else if (nGeometryStatus == 2){
GateMessage("Geometry", 3, " The geometry needs to be rebuilt.\n";);
}
if (flagAutoUpdate){
GateMessage("Geometry", 0,"The geometry is going to be updated.\n");
UpdateGeometry();}
}
*/
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
void GateDetectorConstruction::ClockHasChanged()
{
GateMessage("Move", 5, "ClockHasChanged = " << GetFlagMove() << Gateendl; );
if ( GetFlagMove()) {
GateMessage("Move", 6, "moveFlag = 1\n");
nGeometryStatus = geometry_needs_update;
}
else {
GateMessage("Move", 6, "Geometry is uptodate.\n");
nGeometryStatus = geometry_is_uptodate;
}
GateMessage("Move", 6, " Geometry status = " << nGeometryStatus << Gateendl;);
UpdateGeometry();
GateMessage("Move", 6, "Clock has changed.\n");
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
void GateDetectorConstruction::insertARFSD( G4String aName , G4int stage )
{
GateMessage("Geometry", 2, "GateDetectorConstruction::insertARFSD entered");
if (m_ARFSD == 0) {
m_ARFSD = new GateARFSD("/gate/arf", aName );
G4SDManager* SDMan = G4SDManager::GetSDMpointer();
SDMan->AddNewDetector( m_ARFSD );
}
m_ARFSD->SetStage( stage );
}
//---------------------------------------------------------------------------------