source: trunk/source/digits_hits/utils/test/test2/src/Test2DetectorConstruction.cc @ 1350

Last change on this file since 1350 was 1350, checked in by garnier, 13 years ago

update to last version 4.9.4

File size: 4.9 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// $Id: Test2DetectorConstruction.cc,v 1.3 2010/11/03 08:48:57 taso Exp $
28// GEANT4 tag $Name:  $
29//
30//
31
32#include "Test2DetectorConstruction.hh"
33#include "Test2GeometryConstruction.hh"
34
35#include "G4Material.hh"
36#include "G4Box.hh"
37#include "G4LogicalVolume.hh"
38#include "G4PVPlacement.hh"
39#include "G4PVReplica.hh"
40#include "G4PVDivision.hh"
41#include "G4VisAttributes.hh"
42#include "G4Colour.hh"
43#include "G4ios.hh"
44
45Test2DetectorConstruction::Test2DetectorConstruction()
46  :G4VUserDetectorConstruction(),fbConstructed(false),
47  GEOM(0),SDC(0),PSC(0),fSensitivityType(0)
48{;}
49
50Test2DetectorConstruction::~Test2DetectorConstruction()
51{
52  if(GEOM) delete GEOM;
53  if(SDC) delete SDC;
54  if(PSC) delete PSC;
55}
56
57G4VPhysicalVolume* Test2DetectorConstruction::Construct()
58{
59  if(!fbConstructed)
60  { 
61    fbConstructed = true;
62    DefineMaterials();
63    SetupGeometry();
64    switch ( fSensitivityType ){
65    case 0:
66      break;
67    case 1:
68      SetupPSDetectors();
69      break;
70    case 2:
71      SetupSDDetectors();
72      break;
73    default:
74      break;
75    }
76  }
77  return fWorldPhys;
78}
79
80void Test2DetectorConstruction::DefineMaterials()
81{ 
82  G4String name, symbol;             //a=mass of a mole;
83  G4double a, z, density;            //z=mean number of protons; 
84
85  G4int ncomponents, natoms;
86  G4double fractionmass;
87
88  //
89  // define Elements
90  //
91
92  a = 1.01*g/mole;
93  G4Element* H  = new G4Element(name="Hydrogen",symbol="H" , z= 1., a);
94
95  a = 14.01*g/mole;
96  G4Element* N  = new G4Element(name="Nitrogen",symbol="N" , z= 7., a);
97
98  a = 16.00*g/mole;
99  G4Element* O  = new G4Element(name="Oxygen"  ,symbol="O" , z= 8., a);
100
101  //
102  // define a material from elements.   case 1: chemical molecule
103  //
104 
105  density = 1.000*g/cm3;
106  fWaterMat = new G4Material(name="Water", density, ncomponents=2);
107  fWaterMat->AddElement(H, natoms=2);
108  fWaterMat->AddElement(O, natoms=1);
109
110  //
111  // define a material from elements.   case 2: mixture by fractional mass
112  //
113
114  density = 1.290*mg/cm3;
115  fAirMat = new G4Material(name="Air"  , density, ncomponents=2);
116  fAirMat->AddElement(N, fractionmass=0.7);
117  fAirMat->AddElement(O, fractionmass=0.3);
118}
119
120void Test2DetectorConstruction::SetupGeometry()
121{
122  //     
123  // World
124  //
125  G4VSolid* worldSolid = new G4Box("World",2.*m,2.*m,2.*m);
126  G4LogicalVolume* worldLogical = new G4LogicalVolume(worldSolid,fAirMat,"World");
127  fWorldPhys = new G4PVPlacement(0,G4ThreeVector(),worldLogical,"World",
128                        0,false,0);
129 
130  //                               
131  // 3D nested phantom
132  //
133  // parameters
134  phantomSize[0] = 1.*m;
135  phantomSize[1] = 1.*m;
136  phantomSize[2] = 1.*m;
137  nSegment[0] = 10;
138  nSegment[1] = 10;
139  nSegment[2] = 10;
140
141  GEOM = 
142    new Test2GeometryConstruction(phantomSize,fWaterMat,nSegment);
143  fWorldPhys = GEOM->ConstructGeometry(fWorldPhys);
144
145}
146
147#include "G4SDManager.hh"
148#include "Test2PhantomSD.hh"
149void Test2DetectorConstruction::SetupSDDetectors() {
150  G4LogicalVolume* phantomLogical = GEOM->GetSensitiveLogical();
151
152  SDC = new Test2SDConstruction("MassWorldSD",nSegment);
153  SDC->SetupSensitivity(phantomLogical);
154}
155
156#include "Test2PSConstruction.hh"
157
158void Test2DetectorConstruction::SetupPSDetectors() {
159  G4LogicalVolume* phantomLogical = GEOM->GetSensitiveLogical();
160
161  PSC = new Test2PSConstruction("MassWorldPS",nSegment);
162  PSC->SetupSensitivity(phantomLogical);
163}
164
Note: See TracBrowser for help on using the repository browser.