source: trunk/source/geometry/solids/test/SurfaceVisTest/src/DetectorConstruction.cc@ 1330

Last change on this file since 1330 was 1316, checked in by garnier, 15 years ago

update geant4-09-04-beta-cand-01 interfaces-V09-03-09 vis-V09-03-08

File size: 18.3 KB
Line 
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//
26//
27//
28//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
30
31#include "DetectorConstruction.hh"
32#include "DetectorMessenger.hh"
33
34#include "G4Material.hh"
35
36#include "G4Box.hh"
37#include "G4Orb.hh"
38#include "G4Tubs.hh"
39#include "G4Sphere.hh"
40#include "G4Cons.hh"
41#include "G4Hype.hh"
42#include "G4Para.hh"
43#include "G4Paraboloid.hh"
44#include "G4Torus.hh"
45#include "G4Trd.hh"
46#include "G4Ellipsoid.hh"
47#include "G4EllipticalTube.hh"
48#include "G4EllipticalCone.hh"
49
50#include "G4Trap.hh"
51#include "G4Trd.hh"
52#include "G4Tet.hh"
53
54#include "G4Polycone.hh"
55#include "G4Polyhedra.hh"
56
57#include "G4TwistedTubs.hh"
58#include "G4TwistedBox.hh"
59#include "G4TwistedTrd.hh"
60#include "G4TwistedTrap.hh"
61
62#include "G4BooleanSolid.hh"
63#include "G4DisplacedSolid.hh"
64#include "G4UnionSolid.hh"
65#include "G4IntersectionSolid.hh"
66#include "G4SubtractionSolid.hh"
67#include "G4ReflectedSolid.hh"
68
69#include "G4BREPSolidBox.hh"
70
71#include "G4LogicalVolume.hh"
72#include "G4PVPlacement.hh"
73#include "G4PVParameterised.hh"
74#include "G4SDManager.hh"
75
76#include "G4UserLimits.hh"
77
78#include "G4VisAttributes.hh"
79#include "G4Colour.hh"
80
81#include "G4ios.hh"
82
83#include "G4UnitsTable.hh"
84
85#include "G4RunManager.hh"
86#include "G4GeometryManager.hh"
87#include "G4PhysicalVolumeStore.hh"
88#include "G4LogicalVolumeStore.hh"
89#include "G4SolidStore.hh"
90
91//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92
93DetectorConstruction::DetectorConstruction()
94:solidWorld(0), logicWorld(0), physiWorld(0),
95 logicTracker(0),physiTracker(0),
96 fWorldLength(0.)
97{
98 detectorMessenger = new DetectorMessenger(this);
99}
100
101//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102
103DetectorConstruction::~DetectorConstruction()
104{
105 delete detectorMessenger;
106}
107
108////////////////////////////////////////////////////////////////
109
110void DetectorConstruction::SwitchDetector()
111{
112 G4RunManager::GetRunManager()->DefineWorldVolume(physiWorld);
113
114}
115
116
117G4VPhysicalVolume*
118DetectorConstruction::SelectDetector( const G4String& val )
119{
120
121 G4GeometryManager::GetInstance()->OpenGeometry();
122 G4PhysicalVolumeStore::GetInstance()->Clean();
123 G4LogicalVolumeStore::GetInstance()->Clean();
124 G4SolidStore::GetInstance()->Clean();
125 ///////
126 G4double a, z;
127
128 G4double density;
129 G4int nel;
130
131 //Air
132 G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole);
133 G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole);
134
135 G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2);
136 Air->AddElement(N, 70*perCent);
137 Air->AddElement(O, 30*perCent);
138
139 // Print all the materials defined.
140 //
141 // G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
142 //G4cout << *(G4Material::GetMaterialTable()) << G4endl;
143
144 G4Box* b1 = new G4Box ( "b1", 100*cm, 50*cm, 50*cm );
145 G4Box* b2 = new G4Box ( "b2", 50*cm, 100*cm, 50*cm );
146
147 fval = val ;
148 G4double fTrackerR1,fTrackerR2,fPhi,fPhiSegment,fTheta,fThetaSegment ;
149 G4double fSemiAxisX,fSemiAxisY,fSemiAxisZ ;
150 G4double fTrackerR,fTrackerpDx1,fTrackerpDy1,fTrackerpDz;
151 if (val == "Sphere")
152 {
153 // only solid sphere is supportet for now
154 fTrackerR1 = 0*cm ;
155 fTrackerR2 = 12*cm ;
156 fPhi = 0*deg ;
157 fPhiSegment = 360*deg ;
158 fTheta = 0*deg ;
159 fThetaSegment = 180*deg ;
160 aVolume = new G4Sphere ("aSphere", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
161 }
162
163 else if (val == "HalfSphere")
164 {
165 // only solid sphere is supportet for now
166 fTrackerR1 = 0*cm ;
167 fTrackerR2 = 12*cm ;
168 fPhi = 0*deg ;
169 fPhiSegment = 180*deg ;
170 fTheta = 0*deg ;
171 fThetaSegment = 180*deg ;
172 aVolume = new G4Sphere ("aHalfSphere", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
173
174 }
175 else if (val == "HollowSphere")
176 {
177 // only solid sphere is supportet for now
178 fTrackerR1 = 12*cm ;
179 fTrackerR2 = 14*cm ;
180 fPhi = 0*deg ;
181 fPhiSegment = 360*deg ;
182 fTheta = 0*deg ;
183 fThetaSegment = 180*deg ;
184 aVolume = new G4Sphere ("aHollowSphere", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
185
186 }
187 else if (val == "HalfHollowSphere")
188 {
189 // only solid sphere is supportet for now
190 fTrackerR1 = 12*cm ;
191 fTrackerR2 = 14*cm ;
192 fPhi = 0*deg ;
193 fPhiSegment = 180*deg ;
194 fTheta = 0*deg ;
195 fThetaSegment = 180*deg ;
196 aVolume = new G4Sphere ("aHalfHollowSphere", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
197
198 }
199 else if (val == "Q1Shell")
200 {
201 // only solid sphere is supportet for now
202 fTrackerR1 = 10*cm ;
203 fTrackerR2 = 12*cm ;
204 fPhi = 0*deg ;
205 fPhiSegment = 90*deg ;
206 fTheta = 0*deg ;
207 fThetaSegment = 90*deg ;
208 aVolume = new G4Sphere ("aQ1Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
209
210 }
211 else if (val == "Q2Shell")
212 {
213 // only solid sphere is supportet for now
214 fTrackerR1 = 10*cm ;
215 fTrackerR2 = 12*cm ;
216 fPhi = 90*deg ;
217 fPhiSegment = 90*deg ;
218 fTheta = 0*deg ;
219 fThetaSegment = 90*deg ;
220 aVolume = new G4Sphere ("aQ2Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
221
222 }
223 else if (val == "Q3Shell")
224 {
225 // only solid sphere is supportet for now
226 fTrackerR1 = 10*cm ;
227 fTrackerR2 = 12*cm ;
228 fPhi = 180*deg ;
229 fPhiSegment = 90*deg ;
230 fTheta = 0*deg ;
231 fThetaSegment = 90*deg ;
232 aVolume = new G4Sphere ("aQ3Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
233
234 }
235 else if (val == "Q4Shell")
236 {
237 // only solid sphere is supportet for now
238 fTrackerR1 = 10*cm ;
239 fTrackerR2 = 12*cm ;
240 fPhi = 270*deg ;
241 fPhiSegment = 90*deg ;
242 fTheta = 0*deg ;
243 fThetaSegment = 90*deg ;
244 aVolume = new G4Sphere ("aQ4Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
245
246 }
247 else if (val == "Q5Shell")
248 {
249 // only solid sphere is supportet for now
250 fTrackerR1 = 10*cm ;
251 fTrackerR2 = 12*cm ;
252 fPhi = 0*deg ;
253 fPhiSegment = 90*deg ;
254 fTheta = 90*deg ;
255 fThetaSegment = 90*deg ;
256 aVolume = new G4Sphere ("aQ5Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
257
258 }
259else if (val == "Q6Shell")
260 {
261 // only solid sphere is supportet for now
262 fTrackerR1 = 10*cm ;
263 fTrackerR2 = 12*cm ;
264 fPhi = 90*deg ;
265 fPhiSegment = 90*deg ;
266 fTheta = 90*deg ;
267 fThetaSegment = 90*deg ;
268 aVolume = new G4Sphere ("aQ5Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
269
270 }
271 else if (val == "Q7Shell")
272 {
273 // only solid sphere is supportet for now
274 fTrackerR1 = 10*cm ;
275 fTrackerR2 = 12*cm ;
276 fPhi = 180*deg ;
277 fPhiSegment = 90*deg ;
278 fTheta = 90*deg ;
279 fThetaSegment = 90*deg ;
280 aVolume = new G4Sphere ("aQ7Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
281
282 }
283 else if (val == "Q8Shell")
284 {
285 // only solid sphere is supportet for now
286 fTrackerR1 = 10*cm ;
287 fTrackerR2 = 12*cm ;
288 fPhi = 270*deg ;
289 fPhiSegment = 90*deg ;
290 fTheta = 90*deg ;
291 fThetaSegment = 90*deg ;
292 aVolume = new G4Sphere ("aQ8Shell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
293
294 }
295
296
297 else if (val == "Shell")
298 {
299 // only solid sphere is supportet for now
300 fTrackerR1 = 10*cm ;
301 fTrackerR2 = 12*cm ;
302 fPhi = 30*deg ;
303 fPhiSegment = 120*deg ;
304 fTheta = 10*deg ;
305 fThetaSegment = 100*deg ;
306 aVolume = new G4Sphere ("aShell", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
307
308 }
309 else if (val == "Ring")
310 {
311 // only solid sphere is supportet for now
312 fTrackerR1 = 10*cm ;
313 fTrackerR2 = 12*cm ;
314 fPhi = 30*deg ;
315 fPhiSegment = 120*deg ;
316 fTheta = 10*deg ;
317 fThetaSegment = 40*deg ;
318 aVolume = new G4Sphere ("aRing", fTrackerR1, fTrackerR2 ,fPhi, fPhiSegment, fTheta, fThetaSegment);
319
320 }
321 else if ( val == "Ellipsoid" ) {
322
323 fSemiAxisX = 1*cm ;
324 fSemiAxisY = 10*cm ;
325 fSemiAxisZ = 100*cm ;
326
327 aVolume = new G4Ellipsoid("aEllipsoid",
328 fSemiAxisX,
329 fSemiAxisY,
330 fSemiAxisZ,
331 -fSemiAxisZ,fSemiAxisZ);
332
333
334 }
335 else if (val == "Orb")
336 {
337
338 fTrackerR = 11*cm ;
339 aVolume = new G4Orb ( "aOrb", fTrackerR );
340
341 }
342 else if (val == "Box")
343 {
344
345 fTrackerpDx1 = 10*cm ;
346 fTrackerpDy1 = 10*cm ;
347 fTrackerpDz = 10*cm ;
348
349 aVolume = new G4Box ( "aBox", fTrackerpDx1, fTrackerpDy1, fTrackerpDz );
350 }
351 else if (val == "Cons")
352 {
353
354 fTrackerpDz = 80*cm ;
355 fTrackerR1 = 11*cm ;
356 fTrackerR2 = 16*cm ;
357
358 aVolume = new G4Cons ( "aCons", 0.8*fTrackerR1 , fTrackerR1, 0.8*fTrackerR2, fTrackerR2, fTrackerpDz, 10*deg, 120.*deg );
359
360 }
361 else if (val == "manyCons")
362 {
363 aVolume = new G4Cons ( "aCone", 2*cm, 6*cm, 8*cm, 14*cm,
364 10*cm, 10*deg, 300*deg );
365 // 10*cm, 10*deg, 300*deg );
366 // 0., pi);
367
368
369 }
370 else if (val == "Tubs")
371 {
372
373 // only solid Tube is supported.
374 fTrackerpDz = 80*cm ;
375 fTrackerR = 11*cm ;
376
377 aVolume = new G4Tubs ( "aTube",0.8*fTrackerR,fTrackerR,fTrackerpDz,40.,100*deg) ;
378
379 }
380 else if (val == "Hype")
381 {
382 aVolume = new G4Hype ("aHype", 7*cm, 10*cm, 40*deg, 40*deg, 40*cm );
383 }
384 else if (val == "Torus")
385 {
386
387 fPhi = 40*deg ;
388 fPhiSegment = 100*deg ;
389
390 fTrackerR1 = 5*cm ;
391 fTrackerR2 = 6*cm ;
392 fTrackerR = 20*cm ;
393
394 aVolume = new G4Torus("aTorus", fTrackerR1, fTrackerR2 ,fTrackerR, fPhi, fPhiSegment) ;
395
396 }
397 else if (val == "Para")
398 {
399 aVolume = new G4Para ("aPara", 8*cm, 10*cm, 12*cm, 30*deg, 45*deg, 60*deg);
400 }
401 else if (val == "Paraboloid")
402 {
403 aVolume = new G4Paraboloid ("aParaboloid", 8*cm, 1*cm, 12*cm);
404 }
405 else if (val == "PolyconeGen")
406 {
407 G4double rr[]={100,120,140,120};
408 G4double zz[]={-100,-100,100,100};
409 aVolume = new G4Polycone ("aPolycone",0*deg,90*deg, 4, rr,zz);
410 }
411 else if (val == "PolyconeGenComplex")
412 {
413 G4double zPlanes[] = {-11640.*mm, -11640.*mm, -11570.722*mm, -9766.005*mm,
414 -4487.828*mm, 4487.828*mm, 9766.005*mm, 11570.722*mm,
415 11640.*mm, 11640.*mm, 11580.*mm, 9750.*mm,
416 4500.*mm, -4500.*mm, -9750.*mm, -11580.*mm,
417 -11640.*mm};
418
419 G4double radius[] = {250.*mm, 305.*mm, 305.*mm, 2770.461*mm,
420 4932.*mm, 4932.*mm, 2770.461*mm, 305.*mm,
421 305.*mm, 250.*mm, 250.*mm, 2750.*mm,
422 4900.*mm, 4900.*mm, 2750.*mm, 250.*mm,
423 250.*mm};
424 aVolume = new G4Polycone ("aPolycone",0*deg,360*deg, 16, radius,zPlanes);
425 }
426 else if (val == "Polycone")
427 {
428 G4double rIn[]={100,120,0,0,120,120};
429 G4double rOut[]={120,140,140,120,140,160};
430 G4double zPlane[]={-200,-100,0,100,200,300};
431 aVolume = new G4Polycone ("aPolycone",0*deg,90*deg, 6,zPlane, rIn,rOut);
432 }
433 else if (val == "PolyhedraGen")
434 {
435 G4double rr[]={100,120,140,120};
436 G4double zz[]={-100,-100,100,100};
437 aVolume = new G4Polyhedra ("aPolycone",0*deg,90*deg,8, 4, rr,zz);
438 }
439 else if (val == "PolyhedraGenComplex")
440 {
441 G4double rr[]={ 100, 120, 0, 0,140,120,150,150,150,140, 130};
442 G4double zz[]={-150,-100,-100,-50, 0,200,200,100,0, -50,-100};
443 aVolume = new G4Polyhedra ("aPolycone",0*deg,360*deg,8, 11, rr,zz);
444 }
445 else if (val == "Polyhedra")
446 {
447 G4double rOut[5]={2100,600,1500,1500,3800.};
448 G4double rIn[5]={0,500,0,700,100};
449 G4double zPlane[5]={-100,1000,1500,2500,3000.};
450 aVolume = new G4Polyhedra ("aPolycone",0*deg,60*deg,6, 5,zPlane, rIn,rOut);
451 }
452
453 else if (val == "Trd")
454 {
455 aVolume = new G4Trd ("aTrd", 80*cm, 100*cm, 70*cm, 90*cm, 100*cm);
456 }
457 else if (val == "b1Ub2")
458 {
459 aVolume = new G4UnionSolid("b1Ub2",b1,b2);
460 /*
461 G4Box * box1 = new G4Box("Box1",1092.500000,240.103374,92.000000);
462 G4Box * box2 = new G4Box("Box2",540.103374,792.500000,92.000000);
463
464 G4double L1 = 1104;
465
466 aVolume =
467 new G4UnionSolid("ECShapeBoxes",
468 box1,
469 box2,
470 0,
471 G4ThreeVector(-L1/2.,
472 L1/2.,
473 0.));
474 */
475 }
476 else if (val == "b1Ib2")
477 {
478 aVolume = new G4IntersectionSolid("b1Ib2",b1,b2);
479 }
480 else if (val == "b1Sb2")
481 {
482 aVolume = new G4SubtractionSolid("b1Sb2",b1,b2);
483 }
484 else if (val == "b1Ib1")
485 {
486 aVolume = new G4IntersectionSolid("b1Ib1",b1,b1);
487 }
488 else if (val == "b1Ub1")
489 {
490 aVolume = new G4UnionSolid("b1Ub1",b1,b1);
491 }
492 else if (val == "b1Sb1")
493 {
494 aVolume = new G4SubtractionSolid("b1Sb1",b1,b1);
495 }
496
497 else if ( val == "Tet" )
498 {
499
500 G4ThreeVector pzero(0,0,0);
501 G4ThreeVector pnt1(10.*cm,0.*cm,0.*cm),pnt2(5.0*cm,10.*cm,0.*cm), pnt3(5.*cm,5.*cm,10.*cm);
502 G4bool goodTet;
503 G4Tet t1( "aTet", pzero, pnt1, pnt2, pnt3, &goodTet);
504 }
505 else if ( val == "Trap")
506 {
507 fTrackerpDz = 80*cm;
508 fTheta = 10*deg ;
509 fPhi = 40*deg ;
510 fTrackerpDy1 = 16*cm ;
511 fTrackerpDx1 = 24*cm ;
512 G4double fTrackerpDx2 = 14*cm ;
513 G4double fTrackerpDy2 = 8*cm ;
514 G4double fTrackerpDx3 = 16*cm ;
515 G4double fTrackerpDx4 = 11*cm ;
516 G4double fAlph = 50*deg ;
517
518 aVolume = new G4Trap("aTrap",
519 fTrackerpDz, // half z length
520 fTheta, // direction between end planes
521 fPhi, // defined by polar and azimutal angles.
522 fTrackerpDy1, // half y length at -pDz
523 fTrackerpDx1, // half x length at -pDz,-pDy
524 fTrackerpDx2, // half x length at -pDz,+pDy
525 fAlph, // tilt angle at +pDz
526 fTrackerpDy2, // half y length at +pDz
527 fTrackerpDx3, // half x length at +pDz,-pDy
528 fTrackerpDx4, // half x length at +pDz,+pDy
529 fAlph // tilt angle at +pDz
530 ) ;
531
532
533 }
534 else if ( val == "EllipticalCone" )
535 {
536 aVolume = new G4EllipticalCone("aEllipticalCone",
537 0.5*mm, // xSemiAxis
538 1*mm, // ySemiAxis
539 40*mm, // zheight
540 25*mm) ; // zTopCut
541
542 }
543 else if ( val == "EllipticalTube" )
544 {
545 aVolume = new G4EllipticalTube("aEllipticalTube" ,
546 2*cm, // xSemiAxis
547 5*cm, // ySemiAxis
548 35*cm) ; // zheight
549
550 }
551 else
552 { G4cout <<"DetectorConstruction tried to select "<<val<<G4endl;
553 G4Exception("DetectorConstruction::SelectDetector() - Invalid shape!");
554 }
555
556 fWorldLength= 10*m ;
557
558//--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
559
560 //------------------------------
561 // World
562 //------------------------------
563
564 G4double HalfWorldLength = 0.5*fWorldLength;
565 solidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength);
566 logicWorld= new G4LogicalVolume( solidWorld, Air, "World", 0, 0, 0);
567
568 // Must place the World Physical volume unrotated at (0,0,0).
569 //
570 physiWorld = new G4PVPlacement(0, // no rotation
571 G4ThreeVector(), // at (0,0,0)
572 logicWorld, // its logical volume
573 "World", // its name
574 0, // its mother volume
575 false, // no boolean operations
576 0); // no field specific to volume
577
578
579
580 G4LogicalVolume* aVolume_log = new G4LogicalVolume(aVolume, Air, "aVolume_L", 0,0,0);
581
582 // G4VPhysicalVolume * aVolume_phys1 =
583 new G4PVPlacement(0,
584 G4ThreeVector(0*cm, 0*cm, 0*cm),
585 aVolume_log,
586 val,
587 logicWorld,
588 false,
589 0);
590
591
592
593//--------- Visualization attributes -------------------------------
594
595
596// the world is transparent
597 G4VisAttributes* WorldAtt = new G4VisAttributes(G4Colour(1.,1.,1.,0.));
598 WorldAtt->SetVisibility(true);
599 logicWorld->SetVisAttributes(WorldAtt);
600
601 G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(0.0,1.0,0.0));
602 BoxVisAtt->SetVisibility(true);
603 BoxVisAtt->SetForceSolid(true);
604 aVolume_log->SetVisAttributes(BoxVisAtt);
605
606//--------- example of User Limits -------------------------------
607
608
609 return physiWorld;
610
611}
612
613//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
614
615G4VPhysicalVolume* DetectorConstruction::Construct()
616{
617
618
619 //-------------------Hall ----------------------------------
620
621 return SelectDetector ("Polyhedra"); // default is Polyhedra
622
623}
624
Note: See TracBrowser for help on using the repository browser.