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 "G4UniformMagField.hh"
00019 #include "G4UserLimits.hh"
00020
00021 #include "G4GeometryManager.hh"
00022 #include "G4PhysicalVolumeStore.hh"
00023 #include "G4LogicalVolumeStore.hh"
00024 #include "G4SolidStore.hh"
00025
00026 #include "G4VisAttributes.hh"
00027 #include "G4UnitsTable.hh"
00028
00029
00030
00031
00032 DetectorConstruction::DetectorConstruction()
00033 {
00034 DefineMaterials();
00035
00036
00037
00038 m_cabinRadius = 50*cm;
00039 m_cabinLength = 80*cm;
00040 m_spacecraftThickness = 2*cm;
00041
00042 m_floorThickness = 2*cm;
00043
00044 m_astronautHeight = 50*cm;
00045 m_astronautTopWidth = 40*cm;
00046 m_astronautBottomWidth = 60*cm;
00047
00048 m_magField = 0;
00049 m_stepLimiter = 0;
00050
00051
00052 m_detectorMessenger = new DetectorMessenger(this);
00053 }
00054
00055
00056
00057 DetectorConstruction::~DetectorConstruction()
00058 {delete m_stepLimiter; delete m_detectorMessenger; }
00059
00060
00061
00062 G4VPhysicalVolume* DetectorConstruction::Construct()
00063 {
00064 return ConstructVolumes();
00065 }
00066
00067
00068
00069 void DetectorConstruction::DefineMaterials()
00070 {
00071
00072
00073
00074 G4double Z,A,density;
00075
00076 G4Material* Al =
00077 new G4Material("Aluminium", Z=13., A=26.98*g/mole, density=2.700*g/cm3);
00078
00079
00080
00081
00082 G4Element* H = new G4Element("Hydrogen" ,"H" , Z=1., A= 1.01*g/mole);
00083 G4Element* N = new G4Element("Nitrogen" ,"N" , Z=7., A=14.01*g/mole);
00084 G4Element* O = new G4Element("Oxygen" ,"O" , Z=8., A=16.00*g/mole);
00085
00086 G4int ncomponents, natoms;
00087 G4double fractionmass;
00088
00089 G4Material* Air =
00090 new G4Material("Air", density= 1.290*mg/cm3, ncomponents=2);
00091 Air->AddElement(N, fractionmass=70.*perCent);
00092 Air->AddElement(O, fractionmass=30.*perCent);
00093
00094 G4Material* H2O =
00095 new G4Material("Water", density= 1.000*g/cm3, ncomponents=2);
00096 H2O->AddElement(H, natoms=2);
00097 H2O->AddElement(O, natoms=1);
00098
00099
00100
00101 G4Material* Vacuum =
00102 new G4Material("Galactic", Z=1., A=1.01*g/mole, density= 1.e-10*g/cm3,
00103 kStateGas, 2.73*kelvin, 3.e-18*pascal);
00104
00105
00106
00107 m_worldMaterial = Vacuum;
00108
00109 m_spacecraftMaterial = m_floorMaterial = Air;
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 G4VisAttributes* colourWhite= new G4VisAttributes(G4Colour(1.,1.,1.));
00263 colourWhite->SetVisibility(true);
00264 colourWhite->SetForceSolid(false);
00265
00266 G4VisAttributes* colourGrey= new G4VisAttributes(G4Colour(0.5,0.5,0.5));
00267 colourGrey->SetVisibility(true);
00268 colourGrey->SetForceSolid(false);
00269
00270 G4VisAttributes* colourCyan= new G4VisAttributes(G4Colour(0.,1.,1.));
00271 colourCyan->SetVisibility(true);
00272 colourCyan->SetForceSolid(false);
00273
00274 G4VisAttributes* colourMagenta= new G4VisAttributes(G4Colour(1.,0.,1.));
00275 colourMagenta->SetVisibility(true);
00276 colourMagenta->SetForceSolid(true);
00277
00278 G4VisAttributes* colourBlue= new G4VisAttributes(G4Colour(0.,0.,1.));
00279 colourBlue->SetVisibility(true);
00280 colourBlue->SetForceSolid(false);
00281
00282 logicWorld->SetVisAttributes(colourGrey);
00283 logicSpacecraft->SetVisAttributes(colourCyan);
00284 logicCabin->SetVisAttributes(colourCyan);
00285 logicFloor->SetVisAttributes(colourWhite);
00286 logicAstronaut->SetVisAttributes(colourBlue);
00287
00288
00289
00290 PrintParameters();
00291
00292
00293
00294
00295
00296
00297 m_stepLimiter = new G4UserLimits();
00298 logicWorld->SetUserLimits(m_stepLimiter);
00299 logicSpacecraft->SetUserLimits(m_stepLimiter);
00300 logicCabin->SetUserLimits(m_stepLimiter);
00301 logicFloor->SetUserLimits(m_stepLimiter);
00302 logicAstronaut->SetUserLimits(m_stepLimiter);
00303
00304
00305
00306 return m_physiWorld;
00307 }
00308
00309
00310
00311 void DetectorConstruction::PrintParameters()
00312 {
00313 G4cout << "\n---------------------------------------------------------\n";
00314 G4cout
00315 << "---> World : (" << m_worldSizeXY/m << " X " << m_worldSizeXY/m << " X "
00316 << m_worldSizeZ/m << ") m of "
00317 << m_worldMaterial->GetName() << G4endl;
00318 G4cout
00319 << "---> Spacecraft : radius = " << G4BestUnit(m_spacecraftRadius,"Length")
00320 << "\t length = " << G4BestUnit(m_spacecraftLength,"Length")
00321 << "\t thickness = " << G4BestUnit(m_spacecraftThickness,"Length")
00322 << "\t material : " << m_spacecraftMaterial->GetName() << G4endl;
00323 G4cout
00324 << "---> Cabin : radius = " << G4BestUnit(m_cabinRadius,"Length")
00325 << "\t length = " << G4BestUnit(m_cabinLength,"Length")
00326 << "\t material : " << m_cabinMaterial->GetName() << G4endl;
00327 G4cout
00328 << "---> Floor : thickness = " << G4BestUnit(m_floorThickness,"Length")
00329 << "\t width = " << G4BestUnit(m_floorWidth,"Length")
00330 << "\t length = " << G4BestUnit(m_floorLength,"Length")
00331 << "\t material : " << m_floorMaterial->GetName() << G4endl;
00332 G4cout
00333 << "---> Astronaut : height = " << G4BestUnit(m_astronautHeight,"Length")
00334 << "\t bottom width = " << G4BestUnit(m_astronautBottomWidth,"Length")
00335 << "\t top width = " << G4BestUnit(m_astronautTopWidth,"Length")
00336 << "\t material : " << m_astronautMaterial->GetName() << G4endl;
00337 G4cout << "\n---------------------------------------------------------\n";
00338 G4cout << G4endl;
00339 }
00340
00341
00342
00343 void DetectorConstruction::SetWorldMaterial(G4String materialChoice)
00344 {
00345
00346 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00347 if (pttoMaterial) m_worldMaterial = pttoMaterial;
00348 }
00349
00350
00351
00352 void DetectorConstruction::SetSpacecraftMaterial(G4String materialChoice)
00353 {
00354
00355 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00356 if (pttoMaterial) m_spacecraftMaterial = pttoMaterial;
00357 }
00358
00359
00360
00361 void DetectorConstruction::SetCabinMaterial(G4String materialChoice)
00362 {
00363
00364 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00365 if (pttoMaterial) m_cabinMaterial = pttoMaterial;
00366 }
00367
00368
00369
00370 void DetectorConstruction::SetFloorMaterial(G4String materialChoice)
00371 {
00372
00373 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00374 if (pttoMaterial) m_floorMaterial = pttoMaterial;
00375 }
00376
00377
00378
00379 void DetectorConstruction::SetAstronautMaterial(G4String materialChoice)
00380 {
00381
00382 G4Material* pttoMaterial = G4Material::GetMaterial(materialChoice);
00383 if (pttoMaterial) m_astronautMaterial = pttoMaterial;
00384 }
00385
00386
00387
00388 #include "G4FieldManager.hh"
00389 #include "G4TransportationManager.hh"
00390
00391 void DetectorConstruction::SetMagField(G4double fieldValue)
00392 {
00393
00394 G4FieldManager* fieldMgr
00395 = G4TransportationManager::GetTransportationManager()->GetFieldManager();
00396
00397 if (m_magField) delete m_magField;
00398
00399 if (fieldValue!=0.)
00400 {
00401 m_magField = new G4UniformMagField(G4ThreeVector(0.,0.,fieldValue));
00402 fieldMgr->SetDetectorField(m_magField);
00403 fieldMgr->CreateChordFinder(m_magField);
00404 }
00405 else
00406 {
00407 m_magField = 0;
00408 fieldMgr->SetDetectorField(m_magField);
00409 }
00410 }
00411
00412
00413
00414 void DetectorConstruction::SetMaxStep(G4double maxStep)
00415 {
00416 if ((m_stepLimiter)&&(maxStep>0.))
00417 m_stepLimiter->SetMaxAllowedStep(maxStep);
00418 }
00419
00420
00421
00422 #include "G4RunManager.hh"
00423
00424 void DetectorConstruction::UpdateGeometry()
00425 {
00426 G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
00427 }
00428
00429