Warning, file /geant4/examples/basic/B4/B4c/src/DetectorConstruction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 #include "DetectorConstruction.hh"
0031
0032 #include "CalorimeterSD.hh"
0033
0034 #include "G4AutoDelete.hh"
0035 #include "G4Box.hh"
0036 #include "G4Colour.hh"
0037 #include "G4GlobalMagFieldMessenger.hh"
0038 #include "G4LogicalVolume.hh"
0039 #include "G4Material.hh"
0040 #include "G4NistManager.hh"
0041 #include "G4PVPlacement.hh"
0042 #include "G4PVReplica.hh"
0043 #include "G4PhysicalConstants.hh"
0044 #include "G4SDManager.hh"
0045 #include "G4SystemOfUnits.hh"
0046 #include "G4VisAttributes.hh"
0047
0048 namespace B4c
0049 {
0050
0051
0052
0053 G4ThreadLocal G4GlobalMagFieldMessenger* DetectorConstruction::fMagFieldMessenger = nullptr;
0054
0055
0056
0057 G4VPhysicalVolume* DetectorConstruction::Construct()
0058 {
0059
0060 DefineMaterials();
0061
0062
0063 return DefineVolumes();
0064 }
0065
0066
0067
0068 void DetectorConstruction::DefineMaterials()
0069 {
0070
0071 auto nistManager = G4NistManager::Instance();
0072 nistManager->FindOrBuildMaterial("G4_Pb");
0073
0074
0075 G4double a;
0076 G4double z;
0077 G4double density;
0078 new G4Material("liquidArgon", z = 18., a = 39.95 * g / mole, density = 1.390 * g / cm3);
0079
0080
0081
0082 new G4Material("Galactic", z = 1., a = 1.01 * g / mole, density = universe_mean_density,
0083 kStateGas, 2.73 * kelvin, 3.e-18 * pascal);
0084
0085
0086 G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0087 }
0088
0089
0090
0091 G4VPhysicalVolume* DetectorConstruction::DefineVolumes()
0092 {
0093
0094 fNofLayers = 10;
0095 G4double absoThickness = 10. * mm;
0096 G4double gapThickness = 5. * mm;
0097 G4double calorSizeXY = 10. * cm;
0098
0099 auto layerThickness = absoThickness + gapThickness;
0100 auto calorThickness = fNofLayers * layerThickness;
0101 auto worldSizeXY = 1.2 * calorSizeXY;
0102 auto worldSizeZ = 1.2 * calorThickness;
0103
0104
0105 auto defaultMaterial = G4Material::GetMaterial("Galactic");
0106 auto absorberMaterial = G4Material::GetMaterial("G4_Pb");
0107 auto gapMaterial = G4Material::GetMaterial("liquidArgon");
0108
0109 if (!defaultMaterial || !absorberMaterial || !gapMaterial) {
0110 G4ExceptionDescription msg;
0111 msg << "Cannot retrieve materials already defined.";
0112 G4Exception("DetectorConstruction::DefineVolumes()", "MyCode0001", FatalException, msg);
0113 }
0114
0115
0116
0117
0118 auto worldS = new G4Box("World",
0119 worldSizeXY / 2, worldSizeXY / 2, worldSizeZ / 2);
0120
0121 auto worldLV = new G4LogicalVolume(worldS,
0122 defaultMaterial,
0123 "World");
0124
0125 auto worldPV = new G4PVPlacement(nullptr,
0126 G4ThreeVector(),
0127 worldLV,
0128 "World",
0129 nullptr,
0130 false,
0131 0,
0132 fCheckOverlaps);
0133
0134
0135
0136
0137 auto calorimeterS = new G4Box("Calorimeter",
0138 calorSizeXY / 2, calorSizeXY / 2, calorThickness / 2);
0139
0140 auto calorLV = new G4LogicalVolume(calorimeterS,
0141 defaultMaterial,
0142 "Calorimeter");
0143
0144 new G4PVPlacement(nullptr,
0145 G4ThreeVector(),
0146 calorLV,
0147 "Calorimeter",
0148 worldLV,
0149 false,
0150 0,
0151 fCheckOverlaps);
0152
0153
0154
0155
0156 auto layerS = new G4Box("Layer",
0157 calorSizeXY / 2, calorSizeXY / 2, layerThickness / 2);
0158
0159 auto layerLV = new G4LogicalVolume(layerS,
0160 defaultMaterial,
0161 "Layer");
0162
0163 new G4PVReplica("Layer",
0164 layerLV,
0165 calorLV,
0166 kZAxis,
0167 fNofLayers,
0168 layerThickness);
0169
0170
0171
0172
0173 auto absorberS = new G4Box("Abso",
0174 calorSizeXY / 2, calorSizeXY / 2, absoThickness / 2);
0175
0176 auto absorberLV = new G4LogicalVolume(absorberS,
0177 absorberMaterial,
0178 "AbsoLV");
0179
0180 new G4PVPlacement(nullptr,
0181 G4ThreeVector(0., 0., -gapThickness / 2),
0182 absorberLV,
0183 "Abso",
0184 layerLV,
0185 false,
0186 0,
0187 fCheckOverlaps);
0188
0189
0190
0191
0192 auto gapS = new G4Box("Gap",
0193 calorSizeXY / 2, calorSizeXY / 2, gapThickness / 2);
0194
0195 auto gapLV = new G4LogicalVolume(gapS,
0196 gapMaterial,
0197 "GapLV");
0198
0199 new G4PVPlacement(nullptr,
0200 G4ThreeVector(0., 0., absoThickness / 2),
0201 gapLV,
0202 "Gap",
0203 layerLV,
0204 false,
0205 0,
0206 fCheckOverlaps);
0207
0208
0209
0210
0211 G4cout << G4endl << "------------------------------------------------------------" << G4endl
0212 << "---> The calorimeter is " << fNofLayers << " layers of: [ " << absoThickness / mm
0213 << "mm of " << absorberMaterial->GetName() << " + " << gapThickness / mm << "mm of "
0214 << gapMaterial->GetName() << " ] " << G4endl
0215 << "------------------------------------------------------------" << G4endl;
0216
0217
0218
0219
0220 worldLV->SetVisAttributes(G4VisAttributes::GetInvisible());
0221 calorLV->SetVisAttributes(G4VisAttributes(G4Colour::White()));
0222
0223
0224
0225
0226 return worldPV;
0227 }
0228
0229
0230
0231 void DetectorConstruction::ConstructSDandField()
0232 {
0233
0234
0235
0236
0237
0238 auto absoSD = new CalorimeterSD("AbsorberSD", "AbsorberHitsCollection", fNofLayers);
0239 G4SDManager::GetSDMpointer()->AddNewDetector(absoSD);
0240 SetSensitiveDetector("AbsoLV", absoSD);
0241
0242 auto gapSD = new CalorimeterSD("GapSD", "GapHitsCollection", fNofLayers);
0243 G4SDManager::GetSDMpointer()->AddNewDetector(gapSD);
0244 SetSensitiveDetector("GapLV", gapSD);
0245
0246
0247
0248
0249
0250
0251
0252 G4ThreeVector fieldValue;
0253 fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
0254 fMagFieldMessenger->SetVerboseLevel(1);
0255
0256
0257 G4AutoDelete::Register(fMagFieldMessenger);
0258 }
0259
0260
0261
0262 }