ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
DetectorConstruction.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file DetectorConstruction.cc
1
//
2
// ********************************************************************
3
// * License and Disclaimer *
4
// * *
5
// * The Geant4 software is copyright of the Copyright Holders of *
6
// * the Geant4 Collaboration. It is provided under the terms and *
7
// * conditions of the Geant4 Software License, included in the file *
8
// * LICENSE and available at http://cern.ch/geant4/license . These *
9
// * include a list of copyright holders. *
10
// * *
11
// * Neither the authors of this software system, nor their employing *
12
// * institutes,nor the agencies providing financial support for this *
13
// * work make any representation or warranty, express or implied, *
14
// * regarding this software system or assume any liability for its *
15
// * use. Please see the license in the file LICENSE and URL above *
16
// * for the full disclaimer and the limitation of liability. *
17
// * *
18
// * This code implementation is the result of the scientific and *
19
// * technical work of the GEANT4 collaboration. *
20
// * By using, copying, modifying or distributing the software (or *
21
// * any work based on the software) you agree to acknowledge its *
22
// * use in resulting scientific publications, and indicate your *
23
// * acceptance of all terms of the Geant4 Software license. *
24
// ********************************************************************
25
//
28
//
29
//
30
//
32
//
33
// TestEm9: Crystal calorimeter
34
//
35
// Created: 31.01.03 V.Ivanchenko
36
//
37
// Modified:
38
//
40
//
41
42
43
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45
46
#include "DetectorConstruction.hh"
47
#include "DetectorMessenger.hh"
48
49
#include "
G4Box.hh
"
50
#include "
G4LogicalVolume.hh
"
51
#include "
G4PVPlacement.hh
"
52
#include "
G4PVReplica.hh
"
53
54
#include "
G4TransportationManager.hh
"
55
56
#include "
G4GeometryManager.hh
"
57
#include "
G4RunManager.hh
"
58
#include "
G4Region.hh
"
59
#include "
G4RegionStore.hh
"
60
#include "
G4ProductionCuts.hh
"
61
#include "
G4PhysicalVolumeStore.hh
"
62
#include "
G4LogicalVolumeStore.hh
"
63
#include "
G4SolidStore.hh
"
64
#include "
G4NistManager.hh
"
65
66
#include "
G4VisAttributes.hh
"
67
#include "
G4Colour.hh
"
68
69
#include "
G4UnitsTable.hh
"
70
#include "
G4SystemOfUnits.hh
"
71
#include "
G4ios.hh
"
72
73
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74
75
DetectorConstruction::DetectorConstruction
()
76
:
G4VUserDetectorConstruction
(),
77
fCalMaterial(0),
78
fVertMaterial(0),
79
fAbsMaterial(0),
80
fWorldMaterial(0),
81
fYorkMaterial(0),
82
fLogicWorld(0),
83
fLogicCal(0),
84
fLogicA1(0),
85
fLogicA2(0),
86
fLogicA3(0),
87
fLogicA4(0),
88
fVertexRegion(0),
89
fMuonRegion(0),
90
fVertexDetectorCuts(0),
91
fMuonDetectorCuts(0),
92
fDetectorMessenger(0)
93
{
94
fDetectorMessenger
=
new
DetectorMessenger
(
this
);
95
96
fEcalLength
= 36.*
cm
;
97
fEcalWidth
= 6.*
cm
;
98
fVertexLength
= 3.*
cm
;
99
fPadLength
= 0.1*
mm
;
100
fPadWidth
= 0.02*
mm
;
101
fAbsLength
= 2.*
mm
;
102
fWorldZ
= 0.0;
103
fLogicWorld
= 0;
104
fLogicCal
= 0;
105
fLogicA1
= 0;
106
fLogicA2
= 0;
107
fLogicA3
= 0;
108
fLogicA4
= 0;
109
fVertexRegion
= 0;
110
fMuonRegion
= 0;
111
112
DefineMaterials
();
113
fVertexDetectorCuts
=
new
G4ProductionCuts
();
114
fMuonDetectorCuts
=
new
G4ProductionCuts
();
115
}
116
117
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118
119
DetectorConstruction::~DetectorConstruction
()
120
{
121
delete
fDetectorMessenger
;
122
delete
fVertexDetectorCuts
;
123
delete
fMuonDetectorCuts
;
124
}
125
126
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
127
128
G4VPhysicalVolume
*
DetectorConstruction::Construct
()
129
{
130
return
ConstructVolumes
();
131
}
132
133
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134
135
void
DetectorConstruction::DefineMaterials
()
136
{
137
// Default materials
138
139
G4NistManager
* man =
G4NistManager::Instance
();
140
// man->SetVerbose(1);
141
fWorldMaterial
= man->
FindOrBuildMaterial
(
"G4_AIR"
);
142
fAbsMaterial
= man->
FindOrBuildMaterial
(
"G4_Al"
);
143
fVertMaterial
= man->
FindOrBuildMaterial
(
"G4_Si"
);
144
fYorkMaterial
= man->
FindOrBuildMaterial
(
"G4_Fe"
);
145
fCalMaterial
= man->
FindOrBuildMaterial
(
"G4_CESIUM_IODIDE"
);
146
}
147
148
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149
150
G4VPhysicalVolume
*
DetectorConstruction::ConstructVolumes
()
151
{
152
// Cleanup old geometry
153
154
G4GeometryManager::GetInstance
()->
OpenGeometry
();
155
156
if
(
G4NistManager::Instance
()->
GetVerbose
() > 0)
157
G4cout
<< *(
G4Material::GetMaterialTable
()) <<
G4endl
;
158
159
if
(
fVertexRegion
) {
160
delete
fVertexRegion
;
161
delete
fMuonRegion
;
162
}
163
fVertexRegion
=
new
G4Region
(
"VertexDetector"
);
164
fVertexRegion
->
SetProductionCuts
(
fVertexDetectorCuts
);
165
166
fMuonRegion
=
new
G4Region
(
"MuonDetector"
);
167
fMuonRegion
->
SetProductionCuts
(
fMuonDetectorCuts
);
168
169
G4SolidStore::GetInstance
()->
Clean
();
170
G4LogicalVolumeStore::GetInstance
()->
Clean
();
171
G4PhysicalVolumeStore::GetInstance
()->
Clean
();
172
173
if
(
fVertexLength
<
fPadLength
*5.0)
fVertexLength
=
fPadLength
*5.0;
174
G4double
gap
= 0.01*
mm
;
175
G4double
biggap = 2.*
cm
;
176
G4double
york = 10.*
cm
;
177
178
fWorldZ
= 2.*
fVertexLength
+ 3.*
fAbsLength
+ 0.5*(
fEcalLength
+ york) + biggap*2.;
179
180
G4double
worldX =
fEcalWidth
*3.0;
181
G4double
vertexZ= -
fWorldZ
+
fVertexLength
*2.0 +
fAbsLength
+ biggap;
182
G4double
absZ2 = -
fWorldZ
+
fVertexLength
*4.0 +
fAbsLength
*3.5 + biggap;
183
G4double
ecalZ = -
fWorldZ
+
fVertexLength
*4.0 +
fAbsLength
*4.0 +
fEcalLength
*0.5
184
+ 2.*biggap;
185
G4double
yorkZ = -
fWorldZ
+
fVertexLength
*4.0 +
fAbsLength
*5.0 +
fEcalLength
186
+ york*0.5 + 3.*biggap;
187
188
//
189
// World
190
//
191
G4Box
* solidW =
new
G4Box
(
"World"
,worldX,worldX,
fWorldZ
);
192
fLogicWorld
=
new
G4LogicalVolume
( solidW,
fWorldMaterial
,
"World"
);
193
G4VPhysicalVolume
*
world
=
new
G4PVPlacement
(0,
G4ThreeVector
(),
194
"World"
,
fLogicWorld
,0,
false
,0);
195
196
//
197
// Ecal
198
//
199
G4Box
* solidE =
new
G4Box
(
"VolE"
,worldX,worldX,
fEcalLength
*0.5 + gap);
200
G4LogicalVolume
* logicECal =
201
new
G4LogicalVolume
( solidE,
fWorldMaterial
,
"VolE"
);
202
G4VPhysicalVolume
* physE =
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,ecalZ),
203
"VolE"
,logicECal,world,
false
,0);
204
205
G4Box
* solidC =
new
G4Box
(
"Ecal"
,
fEcalWidth
*0.5,
fEcalWidth
*0.5,
fEcalLength
*0.5);
206
fLogicCal
=
new
G4LogicalVolume
( solidC,
fCalMaterial
,
"Ecal"
);
207
208
G4cout
<<
"Ecal is "
<<
G4BestUnit
(
fEcalLength
,
"Length"
)
209
<<
" of "
<<
fCalMaterial
->
GetName
() <<
G4endl
;
210
211
// Crystals
212
213
G4double
x0 = -(
fEcalWidth
+
gap
)*2.0;
214
G4double
y
= x0;
215
G4double
x
;
216
G4int
k
= 0;
217
G4int
i,j;
218
219
for
(i=0; i<5; i++) {
220
x = x0;
221
for
(j=0; j<5; j++) {
222
223
new
G4PVPlacement
(0,
G4ThreeVector
(x,y,0.),
"Ecal"
,
fLogicCal
,
224
physE,
false
,k);
225
k++;
226
x +=
fEcalWidth
+
gap
;
227
}
228
y +=
fEcalWidth
+
gap
;
229
}
230
231
//Absorber
232
233
G4Box
* solidA =
new
G4Box
(
"Abso"
,worldX,worldX,
fAbsLength
*0.5);
234
fLogicA2
=
new
G4LogicalVolume
( solidA,
fAbsMaterial
,
"Abs2"
);
235
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,absZ2),
236
"Abs2"
,
fLogicA2
,world,
false
,0);
237
238
G4cout
<<
"Absorber is "
<<
G4BestUnit
(
fAbsLength
,
"Length"
)
239
<<
" of "
<<
fAbsMaterial
->
GetName
() <<
G4endl
;
240
241
//York
242
243
G4Box
* solidYV =
new
G4Box
(
"VolY"
,worldX,worldX,york*0.5+
fAbsLength
);
244
G4LogicalVolume
* logicYV =
245
new
G4LogicalVolume
( solidYV,
fYorkMaterial
,
"VolY"
);
246
G4VPhysicalVolume
* physYV =
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,yorkZ),
247
"VolY"
,logicYV,world,
false
,0);
248
249
G4Box
* solidY =
new
G4Box
(
"York"
,worldX,worldX,york*0.5);
250
G4LogicalVolume
* logicY =
251
new
G4LogicalVolume
( solidY,
fYorkMaterial
,
"York"
);
252
new
G4PVPlacement
(0,
G4ThreeVector
(),
253
"York"
,logicY,physYV,
false
,0);
254
255
fLogicA3
=
new
G4LogicalVolume
( solidA,
fAbsMaterial
,
"Abs3"
);
256
fLogicA4
=
new
G4LogicalVolume
( solidA,
fAbsMaterial
,
"Abs4"
);
257
258
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,-(york+
fAbsLength
)*0.5),
259
"Abs3"
,
fLogicA3
,physYV,
false
,0);
260
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,(york+
fAbsLength
)*0.5),
261
"Abs4"
,
fLogicA4
,physYV,
false
,0);
262
263
//Vertex volume
264
G4Box
* solidVV =
new
G4Box
(
"VolV"
,worldX,worldX,
fVertexLength
*2.+
fAbsLength
+gap);
265
G4LogicalVolume
* logicVV =
266
new
G4LogicalVolume
( solidVV,
fWorldMaterial
,
"VolV"
);
267
G4VPhysicalVolume
* physVV =
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,vertexZ),
268
"VolV"
,logicVV,world,
false
,0);
269
270
//Absorber
271
fLogicA1
=
new
G4LogicalVolume
( solidA,
fAbsMaterial
,
"Abs1"
);
272
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,
fVertexLength
*2.-
fAbsLength
*0.5),
273
"Abs1"
,
fLogicA1
,physVV,
false
,0);
274
275
//Vertex
276
G4double
vertWidth =
fEcalWidth
/5.;
277
G4int
npads = (
G4int
)(vertWidth/
fPadWidth
);
278
//G4cout << " vertWidth= " << vertWidth << " padWidth= " << padWidth
279
// << " npads= " << npads << G4endl;
280
// insure beam to hit a middle of central pad
281
npads = (npads/2)*2 + 1;
282
x0 = -0.5*(
fPadWidth
+ vertWidth);
283
G4double
x1
= 0.5*vertWidth +
gap
;
284
G4double
z
= -(
fVertexLength
+
fAbsLength
);
285
286
G4Box
* solidVD =
new
G4Box
(
"VertDet"
,x1,
fEcalWidth
*0.5+gap,
fPadLength
*0.5);
287
G4LogicalVolume
* logicVD =
288
new
G4LogicalVolume
( solidVD,
fVertMaterial
,
"VertDet"
);
289
logicVD->
SetSolid
(solidVD);
290
291
G4Box
* solidV =
new
G4Box
(
"Vert"
,
fPadWidth
*0.5,
fEcalWidth
*0.5,
fPadLength
*0.5);
292
G4LogicalVolume
* logicV =
new
G4LogicalVolume
( solidV,
fVertMaterial
,
"Vert"
);
293
294
for
(i=0; i<3; i++) {
295
new
G4PVPlacement
(0,
G4ThreeVector
(0.,0.,z),
"VertDet"
,logicVD,
296
physVV,
false
,i);
297
z +=
fVertexLength
;
298
}
299
x = x0;
300
301
for
(j=0; j<npads; j++) {
302
303
new
G4PVPlacement
(0,
G4ThreeVector
(x,0.,0.),logicV,
"Vert"
,logicVD,
304
false
,k);
305
x +=
fPadWidth
;
306
}
307
308
G4cout
<<
"Vertex is "
<<
G4BestUnit
(
fVertexLength
,
"Length"
)
309
<<
" of 3 layers of Si of "
<<
G4BestUnit
(
fPadLength
,
"Length"
)
310
<<
" npads= "
<< npads
311
<<
G4endl
;
312
313
// Define region for the vertex detector
314
fVertexRegion
->
AddRootLogicalVolume
(logicVV);
315
fVertexRegion
->
AddRootLogicalVolume
(
fLogicA3
);
316
317
// Define region for the muon detector
318
fMuonRegion
->
AddRootLogicalVolume
(logicYV);
319
320
// color regions
321
logicVV-> SetVisAttributes(
G4VisAttributes::GetInvisible
());
322
logicV-> SetVisAttributes(
G4VisAttributes::GetInvisible
());
323
logicECal-> SetVisAttributes(
G4VisAttributes::GetInvisible
());
324
logicYV-> SetVisAttributes(
G4VisAttributes::GetInvisible
());
325
326
G4VisAttributes
* regWcolor =
new
G4VisAttributes
(
G4Colour
(0.3, 0.3, 0.3));
327
fLogicWorld
->
SetVisAttributes
(regWcolor);
328
329
G4VisAttributes
* regVcolor =
new
G4VisAttributes
(
G4Colour
(0., 0.3, 0.7));
330
logicVD->
SetVisAttributes
(regVcolor);
331
332
G4VisAttributes
* regCcolor =
new
G4VisAttributes
(
G4Colour
(0., 0.7, 0.3));
333
fLogicCal
->
SetVisAttributes
(regCcolor);
334
335
G4VisAttributes
* regAcolor =
new
G4VisAttributes
(
G4Colour
(1., 0.5, 0.5));
336
fLogicA1
->
SetVisAttributes
(regAcolor);
337
fLogicA2
->
SetVisAttributes
(regAcolor);
338
fLogicA3
->
SetVisAttributes
(regAcolor);
339
fLogicA4
->
SetVisAttributes
(regAcolor);
340
341
G4VisAttributes
* regMcolor =
new
G4VisAttributes
(
G4Colour
(1., 1., 0.));
342
logicY->
SetVisAttributes
(regMcolor);
343
344
// always return world
345
G4cout
<<
"### New geometry is constructed"
<<
G4endl
;
346
347
return
world
;
348
}
349
350
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
351
352
void
DetectorConstruction::SetEcalMaterial
(
const
G4String
&
mat
)
353
{
354
// search the material by its name
355
G4Material
* pttoMaterial =
356
G4NistManager::Instance
()->
FindOrBuildMaterial
(mat);
357
if
(pttoMaterial && pttoMaterial !=
fCalMaterial
) {
358
fCalMaterial
= pttoMaterial;
359
if
(
fLogicCal
) {
360
fLogicCal
->
SetMaterial
(
fCalMaterial
);
361
G4RunManager::GetRunManager
()->
PhysicsHasBeenModified
();
362
}
363
}
364
}
365
366
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
367
368
void
DetectorConstruction::SetAbsMaterial
(
const
G4String
&
mat
)
369
{
370
// search the material by its name
371
G4Material
* pttoMaterial =
372
G4NistManager::Instance
()->
FindOrBuildMaterial
(mat);
373
if
(pttoMaterial && pttoMaterial !=
fAbsMaterial
) {
374
fAbsMaterial
= pttoMaterial;
375
if
(
fLogicA1
) {
376
fLogicA1
->
SetMaterial
(
fAbsMaterial
);
377
fLogicA2
->
SetMaterial
(
fAbsMaterial
);
378
fLogicA3
->
SetMaterial
(
fAbsMaterial
);
379
fLogicA4
->
SetMaterial
(
fAbsMaterial
);
380
G4RunManager::GetRunManager
()->
PhysicsHasBeenModified
();
381
}
382
}
383
}
384
385
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
386
387
void
DetectorConstruction::UpdateGeometry
()
388
{
389
G4RunManager::GetRunManager
()->
PhysicsHasBeenModified
();
390
G4RunManager::GetRunManager
()->
DefineWorldVolume
(
ConstructVolumes
());
391
}
392
393
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
394
395
void
DetectorConstruction::SetEcalLength
(
G4double
val)
396
{
397
if
(val > 0.0) {
398
fEcalLength
= val;
399
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
400
}
401
}
402
403
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
404
405
void
DetectorConstruction::SetEcalWidth
(
G4double
val)
406
{
407
if
(val > 0.0) {
408
fEcalWidth
= val;
409
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
410
}
411
}
412
413
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
414
415
void
DetectorConstruction::SetVertexLength
(
G4double
val)
416
{
417
if
(val > 0.0) {
418
fVertexLength
= val;
419
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
420
}
421
}
422
423
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
424
425
void
DetectorConstruction::SetPadLength
(
G4double
val)
426
{
427
if
(val > 0.0) {
428
fPadLength
= val;
429
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
430
}
431
}
432
433
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
434
435
void
DetectorConstruction::SetPadWidth
(
G4double
val)
436
{
437
if
(val > 0.0) {
438
fPadWidth
= val;
439
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
440
}
441
}
442
443
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
444
445
void
DetectorConstruction::SetAbsLength
(
G4double
val)
446
{
447
if
(val > 0.0) {
448
fAbsLength
= val;
449
G4RunManager::GetRunManager
()->
GeometryHasBeenModified
();
450
}
451
}
452
453
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
geant4
tree
geant4-10.6-release
examples
extended
electromagnetic
TestEm9
src
DetectorConstruction.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:24:49
using
1.8.2 with
ECCE GitHub integration