00001
00002
00003
00004
00005
00006
00007 #include "DetectorConstruction.hh"
00008 #include "DetectorMessenger.hh"
00009
00010 #include "G4Material.hh"
00011 #include "G4Box.hh"
00012 #include "G4Tubs.hh"
00013 #include "G4Trd.hh"
00014 #include "G4LogicalVolume.hh"
00015 #include "G4PVPlacement.hh"
00016 #include "G4RotationMatrix.hh"
00017
00018 #include "G4GeometryManager.hh"
00019 #include "G4PhysicalVolumeStore.hh"
00020 #include "G4LogicalVolumeStore.hh"
00021 #include "G4SolidStore.hh"
00022
00023 #include "G4VisAttributes.hh"
00024 #include "G4UnitsTable.hh"
00025
00026
00027 #include "SensitiveDetector.hh"
00028 #include "G4SDManager.hh"
00029 #include "G4MultiFunctionalDetector.hh"
00030 #include "G4PSEnergyDeposit.hh"
00031 #include "G4PSTrackCounter.hh"
00032 #include "G4SDParticleFilter.hh"
00033
00034
00035
00036 DetectorConstruction::DetectorConstruction()
00037 {
00038 DefineMaterials();
00039
00040
00041
00042 m_cabinRadius = 50*cm;
00043 m_cabinLength = 80*cm;
00044 m_spacecraftThickness = 2*cm;
00045
00046 m_floorThickness = 2*cm;
00047
00048 m_astronautHeight = 50*cm;
00049 m_astronautTopWidth = 40*cm;
00050 m_astronautBottomWidth = 60*cm;
00051
00052
00053 m_detectorMessenger = new DetectorMessenger(this);
00054 }
00055
00056
00057
00058 DetectorConstruction::~DetectorConstruction()
00059 {delete m_detectorMessenger; }
00060
00061
00062
00063 G4VPhysicalVolume* DetectorConstruction::Construct()
00064 {
00065 return ConstructVolumes();
00066 }
00067
00068
00069
00070 void DetectorConstruction::DefineMaterials()
00071 {
00072
00073
00074
00075 G4double Z,A,density;
00076
00077 G4Material* Al =
00078 new G4Material("Aluminium", Z=13., A=26.98*g/mole, density=2.700*g/cm3);
00079
00080
00081
00082
00083 G4Element* H = new G4Element("Hydrogen" ,"H" , Z=1., A= 1.01*g/mole);
00084 G4Element* N = new G4Element("Nitrogen" ,"N" , Z=7., A=14.01*g/mole);
00085 G4Element* O = new G4Element("Oxygen" ,"O" , Z=8., A=16.00*g/mole);
00086
00087 G4int ncomponents, natoms;
00088 G4double fractionmass;
00089
00090 G4Material* Air =
00091 new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
00092 Air->AddElement(N, fractionmass=70.*perCent);
00093 Air->AddElement(O, fractionmass=30.*perCent);
00094
00095 G4Material* H2O =
00096 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
00097 H2O->AddElement(H, natoms=2);
00098 H2O->AddElement(O, natoms=1);
00099
00100
00101
00102 G4Material* Vacuum =
00103 new G4Material("Galactic", Z=1., A=1.01*g/mole, density= 1.e-10*g/cm3,
00104 kStateGas, 2.73*kelvin, 3.e-18*pascal);
00105
00106
00107
00108 m_worldMaterial = Vacuum;
00109 m_spacecraftMaterial = m_floorMaterial = Al;
00110 m_cabinMaterial = Air;
00111 m_astronautMaterial = H2O;
00112
00113
00114
00115 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00116 }
00117
00118
00119
00120 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
00121 {
00122
00123 G4GeometryManager::GetInstance()->OpenGeometry();
00124 G4PhysicalVolumeStore::GetInstance()->Clean();
00125 G4LogicalVolumeStore::GetInstance()->Clean();
00126 G4SolidStore::GetInstance()->Clean();
00127
00128
00129
00130 m_spacecraftRadius = m_cabinRadius + m_spacecraftThickness;
00131 m_spacecraftLength = m_cabinLength + 2*m_spacecraftThickness;
00132
00133 m_floorYcenter = - 0.5*m_cabinRadius;
00134 G4double floorYtop = m_floorYcenter + 0.5*m_floorThickness;
00135 G4double floorYbottom = m_floorYcenter - 0.5*m_floorThickness;
00136 m_floorWidth =
00137 2*std::sqrt(m_cabinRadius*m_cabinRadius - floorYbottom*floorYbottom);
00138 m_floorLength = m_cabinLength;
00139
00140 m_worldSizeXY = 2.2*m_spacecraftRadius;
00141 m_worldSizeZ = 1.1*m_spacecraftLength;
00142
00143 m_astronautPosition = floorYtop + 0.5*m_astronautHeight;
00144
00145
00146
00147
00148
00149 G4Box*
00150 solidWorld = new G4Box("World",
00151 m_worldSizeXY/2,m_worldSizeXY/2,m_worldSizeZ/2);
00152
00153 G4LogicalVolume*
00154 logicWorld = new G4LogicalVolume(solidWorld,
00155 m_worldMaterial,
00156 "World");
00157
00158 m_physiWorld = new G4PVPlacement(0,
00159 G4ThreeVector(),
00160 logicWorld,
00161 "World",
00162 0,
00163 false,
00164 0);
00165
00166
00167
00168 G4Tubs*
00169 solidSpacecraft = new G4Tubs("Spacecraft",
00170 0*cm, m_spacecraftRadius,
00171 0.5*m_spacecraftLength,
00172 0., twopi);
00173
00174 G4LogicalVolume*
00175 logicSpacecraft = new G4LogicalVolume(solidSpacecraft,
00176 m_spacecraftMaterial,
00177 "Spacecraft");
00178
00179 m_physiSpacecraft = new G4PVPlacement(0,
00180 G4ThreeVector(0,0,0),
00181 logicSpacecraft,
00182 "Spacecraft",
00183 logicWorld,
00184 false,
00185 0);
00186
00187
00188
00189 G4Tubs*
00190 solidCabin = new G4Tubs("Cabin",
00191 0*cm, m_cabinRadius,
00192 0.5*m_cabinLength,
00193 0., 360*deg);
00194
00195 G4LogicalVolume*
00196 logicCabin = new G4LogicalVolume(solidCabin,
00197 m_cabinMaterial,
00198 "Cabin");
00199
00200 m_physiCabin = new G4PVPlacement(0,
00201 G4ThreeVector(0,0,0),
00202 logicCabin,
00203 "Cabin",
00204 logicSpacecraft,
00205 false,
00206 0);
00207
00208
00209
00210
00211 G4Box*
00212 solidFloor = new G4Box("Floor",
00213 m_floorWidth/2,m_floorLength/2,m_floorThickness/2);
00214
00215 G4LogicalVolume*
00216 logicFloor = new G4LogicalVolume(solidFloor, m_floorMaterial, "Floor");
00217
00218
00219 G4RotationMatrix* rotm1 = new G4RotationMatrix();
00220 rotm1->rotateX(90*deg);
00221
00222 m_physiFloor = new G4PVPlacement(rotm1,
00223 G4ThreeVector(0,m_floorYcenter,0),
00224 logicFloor,
00225 "Floor",
00226 logicCabin,
00227 false,
00228 0);
00229
00230
00231
00232 G4Trd*
00233 solidAstronaut = new G4Trd("Astronaut",
00234 0.5 * m_astronautBottomWidth,
00235 0.5 * m_astronautTopWidth,
00236 0.5 * m_astronautBottomWidth,
00237 0.5 * m_astronautTopWidth,
00238 0.5 * m_astronautHeight);
00239
00240 G4LogicalVolume*
00241 logicAstronaut = new G4LogicalVolume(solidAstronaut,
00242 m_astronautMaterial,
00243 "Astronaut");
00244
00245
00246 G4RotationMatrix* rotm2 = new G4RotationMatrix();
00247 rotm2->rotateX(90*deg);
00248
00249
00250 G4ThreeVector position = G4ThreeVector(0.,m_astronautPosition,0.);
00251
00252 m_physiAstronaut = new G4PVPlacement(rotm2,
00253 position,
00254 logicAstronaut,
00255 "Astronaut",
00256 logicCabin,
00257 false,
00258 0);
00259
00260
00261
00262
00263
00264
00265
00266
00267 SensitiveDetector* sensitive = new SensitiveDetector("astronautSD");
00268 logicAstronaut->SetSensitiveDetector(sensitive);
00269
00270 G4SDManager::GetSDMpointer()->AddNewDetector(sensitive);
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 G4MultiFunctionalDetector *floorScorer = new G4MultiFunctionalDetector("floorScorer");
00282
00283 logicFloor->SetSensitiveDetector(floorScorer);
00284
00285 G4SDManager::GetSDMpointer()->AddNewDetector(floorScorer);
00286
00287 G4VPrimitiveScorer* primitive;
00288
00289
00290 primitive = new G4PSEnergyDeposit("edepFloor",0);
00291
00292 floorScorer->RegisterPrimitive(primitive);
00293
00294
00295
00296 primitive = new G4PSTrackCounter("trackCounterFloor", fCurrent_In, 0);
00297 floorScorer->RegisterPrimitive(primitive);
00298
00299
00300 primitive = new G4PSTrackCounter("protonCounterFloor", fCurrent_In ,0);
00301
00302 G4SDParticleFilter* protonFilter = new G4SDParticleFilter("protonFilter","proton");
00303
00304 primitive->SetFilter(protonFilter);
00305 floorScorer->RegisterPrimitive(primitive);
00306
00307
00308
00309
00310
00311 G4VisAttributes* colourWhite= new G4VisAttributes(G4Colour(1.,1.,1.));
00312 colourWhite->SetVisibility(true);
00313 colourWhite->SetForceSolid(false);
00314
00315 G4VisAttributes* colourGrey= new G4VisAttributes(G4Colour(0.5,0.5,0.5));
00316 colourGrey->SetVisibility(true);
00317 colourGrey->SetForceSolid(false);
00318
00319 G4VisAttributes* colourCyan= new G4VisAttributes(G4Colour(0.,1.,1.));
00320 colourCyan->SetVisibility(true);
00321 colourCyan->SetForceSolid(false);
00322
00323 G4VisAttributes* colourMagenta= new G4VisAttributes(G4Colour(1.,0.,1.));
00324 colourMagenta->SetVisibility(true);
00325 colourMagenta->SetForceSolid(true);
00326
00327 G4VisAttributes* colourBlue= new G4VisAttributes(G4Colour(0.,0.,1.));
00328 colourBlue->SetVisibility(true);
00329 colourBlue->SetForceSolid(false);
00330
00331 logicWorld->SetVisAttributes(colourGrey);
00332 logicSpacecraft->SetVisAttributes(colourCyan);
00333 logicCabin->SetVisAttributes(colourCyan);
00334 logicFloor->SetVisAttributes(colourWhite);
00335 logicAstronaut->SetVisAttributes(colourBlue);
00336
00337
00338
00339 PrintParameters();
00340
00341
00342
00343 return m_physiWorld;
00344 }
00345
00346
00347
00348 void DetectorConstruction::PrintParameters()
00349 {
00350 G4cout << "\n---------------------------------------------------------\n";
00351 G4cout
00352 << "---> World : (" << m_worldSizeXY/m << " X " << m_worldSizeXY/m << " X "
00353 << m_worldSizeZ/m << ") m of "
00354 << m_worldMaterial->GetName() << G4endl;
00355 G4cout
00356 << "---> Spacecraft : radius = " << G4BestUnit(m_spacecraftRadius,"Length")
00357 << "\t length = " << G4BestUnit(m_spacecraftLength,"Length")
00358 << "\t thickness = " << G4BestUnit(m_spacecraftThickness,"Length")
00359 << "\t material : " << m_spacecraftMaterial->GetName() << G4endl;
00360 G4cout
00361 << "---> Cabin : radius = " << G4BestUnit(m_cabinRadius,"Length")
00362 << "\t length = " << G4BestUnit(m_cabinLength,"Length")
00363 << "\t material : " << m_cabinMaterial->GetName() << G4endl;
00364 G4cout
00365 << "---> Floor : thickness = " << G4BestUnit(m_floorThickness,"Length")
00366 << "\t width = " << G4BestUnit(m_floorWidth,"Length")
00367 << "\t length = " << G4BestUnit(m_floorLength,"Length")
00368 << "\t material : " << m_floorMaterial->GetName() << G4endl;
00369 G4cout
00370 << "---> Astronaut : height = " << G4BestUnit(m_astronautHeight,"Length")
00371 << "\t bottom width = " << G4BestUnit(m_astronautBottomWidth,"Length")
00372 << "\t top width = " << G4BestUnit(m_astronautTopWidth,"Length")
00373 << "\t material : " << m_astronautMaterial->GetName() << G4endl;
00374 G4cout << "\n---------------------------------------------------------\n";
00375 G4cout << G4endl;
00376 }
00377
00378
00379
00380 void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
00381 {
00382
00383 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00384 if (pttoMaterial) m_worldMaterial = pttoMaterial;
00385 }
00386
00387
00388
00389 void DetectorConstruction::SetSpacecraftMaterial(G4String materialChoice)
00390 {
00391
00392 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00393 if (pttoMaterial) m_spacecraftMaterial = pttoMaterial;
00394 }
00395
00396
00397
00398 void DetectorConstruction::SetCabinMaterial(G4String materialChoice)
00399 {
00400
00401 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00402 if (pttoMaterial) m_cabinMaterial = pttoMaterial;
00403 }
00404
00405
00406
00407 void DetectorConstruction::SetFloorMaterial(G4String materialChoice)
00408 {
00409
00410 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00411 if (pttoMaterial) m_floorMaterial = pttoMaterial;
00412 }
00413
00414
00415
00416 void DetectorConstruction::SetAstronautMaterial(G4String materialChoice)
00417 {
00418
00419 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00420 if (pttoMaterial) m_astronautMaterial = pttoMaterial;
00421 }
00422
00423
00424
00425 #include "G4RunManager.hh"
00426
00427 void DetectorConstruction::UpdateGeometry()
00428 {
00429 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
00430 }
00431
00432