File indexing completed on 2025-11-03 09:04:11
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 
0031 
0032 
0033 #include "DetectorConstruction.hh"
0034 
0035 #include "DetectorMessenger.hh"
0036 
0037 #include "G4Box.hh"
0038 #include "G4GeometryManager.hh"
0039 #include "G4LogicalVolume.hh"
0040 #include "G4LogicalVolumeStore.hh"
0041 #include "G4Material.hh"
0042 #include "G4NistManager.hh"
0043 #include "G4PVPlacement.hh"
0044 #include "G4PhysicalVolumeStore.hh"
0045 #include "G4RunManager.hh"
0046 #include "G4SolidStore.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4UniformMagField.hh"
0049 #include "G4UnitsTable.hh"
0050 #include "G4UserLimits.hh"
0051 
0052 
0053 
0054 DetectorConstruction::DetectorConstruction()
0055   : G4VUserDetectorConstruction(),
0056     fP_Box(0),
0057     fL_Box(0),
0058     fBoxSize(500 * m),
0059     fMaterial(0),
0060     fMagField(0),
0061     fUserLimits(0),
0062     fDetectorMessenger(0)
0063 {
0064   DefineMaterials();
0065   SetMaterial("Iron");
0066 
0067   
0068   fUserLimits = new G4UserLimits();
0069 
0070   
0071   fDetectorMessenger = new DetectorMessenger(this);
0072 }
0073 
0074 
0075 
0076 DetectorConstruction::~DetectorConstruction()
0077 {
0078   delete fDetectorMessenger;
0079 }
0080 
0081 
0082 
0083 G4VPhysicalVolume* DetectorConstruction::Construct()
0084 {
0085   return ConstructVolumes();
0086 }
0087 
0088 
0089 
0090 void DetectorConstruction::DefineMaterials()
0091 {
0092   G4double a, z, density;
0093 
0094   new G4Material("Beryllium", z = 4., a = 9.012182 * g / mole, density = 1.848 * g / cm3);
0095   new G4Material("Carbon", z = 6., a = 12.011 * g / mole, density = 2.265 * g / cm3);
0096   new G4Material("Iron", z = 26., a = 55.85 * g / mole, density = 7.870 * g / cm3);
0097 
0098   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0099 }
0100 
0101 
0102 
0103 G4VPhysicalVolume* DetectorConstruction::ConstructVolumes()
0104 {
0105   G4GeometryManager::GetInstance()->OpenGeometry();
0106   G4PhysicalVolumeStore::GetInstance()->Clean();
0107   G4LogicalVolumeStore::GetInstance()->Clean();
0108   G4SolidStore::GetInstance()->Clean();
0109 
0110   G4Box* sBox = new G4Box("Container",  
0111                           fBoxSize / 2, fBoxSize / 2, fBoxSize / 2);  
0112 
0113   fL_Box = new G4LogicalVolume(sBox,  
0114                                fMaterial,  
0115                                fMaterial->GetName());  
0116 
0117   fL_Box->SetUserLimits(fUserLimits);
0118 
0119   fP_Box = new G4PVPlacement(0,  
0120                              G4ThreeVector(),  
0121                              fL_Box,  
0122                              fMaterial->GetName(),  
0123                              0,  
0124                              false,  
0125                              0);  
0126 
0127   PrintParameters();
0128 
0129   
0130   
0131   
0132   return fP_Box;
0133 }
0134 
0135 
0136 
0137 void DetectorConstruction::PrintParameters()
0138 {
0139   G4cout << "\n The Box is " << G4BestUnit(fBoxSize, "Length") << " of " << fMaterial->GetName()
0140          << G4endl;
0141 }
0142 
0143 
0144 
0145 void DetectorConstruction::SetMaterial(const G4String& name)
0146 {
0147   G4cout << "###SetMaterial" << G4endl;
0148 
0149   
0150   G4Material* mat = G4Material::GetMaterial(name, false);
0151 
0152   
0153   if (!mat) {
0154     mat = G4NistManager::Instance()->FindOrBuildMaterial(name);
0155   }
0156 
0157   if (mat && mat != fMaterial) {
0158     G4cout << "### New target material: " << mat->GetName() << G4endl;
0159     fMaterial = mat;
0160     if (fL_Box) {
0161       fL_Box->SetMaterial(mat);
0162       G4RunManager::GetRunManager()->PhysicsHasBeenModified();
0163     }
0164   }
0165 }
0166 
0167 
0168 
0169 void DetectorConstruction::SetSize(G4double value)
0170 {
0171   fBoxSize = value;
0172 }
0173 
0174 
0175 
0176 #include "G4FieldManager.hh"
0177 #include "G4TransportationManager.hh"
0178 
0179 void DetectorConstruction::SetMagField(G4double fieldValue)
0180 {
0181   
0182   G4FieldManager* fieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();
0183 
0184   if (fMagField) delete fMagField;  
0185 
0186   if (fieldValue != 0.)  
0187   {
0188     fMagField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue));
0189     fieldMgr->SetDetectorField(fMagField);
0190     fieldMgr->CreateChordFinder(fMagField);
0191   }
0192   else {
0193     fMagField = 0;
0194     fieldMgr->SetDetectorField(fMagField);
0195   }
0196 }
0197 
0198 
0199 
0200 void DetectorConstruction::SetMaxStepSize(G4double val)
0201 {
0202   
0203   
0204   if (val <= DBL_MIN) {
0205     G4cout << "\n --->warning from SetMaxStepSize: maxStep " << val
0206            << " out of range. Command refused" << G4endl;
0207     return;
0208   }
0209   fUserLimits->SetMaxAllowedStep(val);
0210 }
0211 
0212 
0213 
0214 #include "G4RunManager.hh"
0215 
0216 void DetectorConstruction::UpdateGeometry()
0217 {
0218   G4RunManager::GetRunManager()->DefineWorldVolume(ConstructVolumes());
0219 }
0220 
0221