#include "construction.hh" #include #include #include MyDetectorConstruction::MyDetectorConstruction() : G4VUserDetectorConstruction(), solidWorld(nullptr), logicWorld(nullptr), physWorld(nullptr), worldMat(nullptr), fElectricField(nullptr), fFieldManager(nullptr), fChordFinder(nullptr) {} MyDetectorConstruction::~MyDetectorConstruction() {} G4VPhysicalVolume *MyDetectorConstruction::Construct() { G4NistManager *nist = G4NistManager::Instance(); G4double atomicNumberVac = 1.; G4double massOfMole = 1.008*g/mole; G4double vacDensity = 1.e-25*g/cm3; G4double temperature = 293*kelvin; G4double pressure = 3.e-8*pascal; //typical pressure in an electron microscope worldMat = new G4Material("vaccum_microscope", atomicNumberVac, massOfMole, vacDensity, kStateGas, temperature, pressure); solidWorld = new G4Box("solidWorld", 0.06*m, 0.06*m, 0.015*m); logicWorld = new G4LogicalVolume(solidWorld, worldMat,"logicWorld"); physWorld = new G4PVPlacement(0, G4ThreeVector(0.,0.,0.), logicWorld, "physWorld", 0, false, 0, true); // specify the field file name here G4String fieldFilename = "uniform_field.txt"; ConstructField(fieldFilename); return physWorld; } void MyDetectorConstruction::ConstructField(const G4String& fieldFilename) { fElectricField = new MyElectricField(fieldFilename); G4EqMagElectricField* equation = new G4EqMagElectricField(fElectricField); G4MagIntegratorStepper* stepper = new G4ClassicalRK4(equation, 8); G4double minStep = 0.01*mm; G4MagInt_Driver* driver = new G4MagInt_Driver(minStep, stepper, stepper->GetNumberOfVariables()); fChordFinder = new G4ChordFinder(driver); fFieldManager = new G4FieldManager(fElectricField); fFieldManager->SetChordFinder(fChordFinder); // assign the field manager to the logical volume logicWorld->SetFieldManager(fFieldManager, true); G4TransportationManager::GetTransportationManager()->GetFieldManager()->SetDetectorField(fElectricField); G4TransportationManager::GetTransportationManager()->GetFieldManager()->SetChordFinder(fChordFinder); // print field values at some random points for debugging std::vector debugPoints = { G4ThreeVector(0, 0, 0), G4ThreeVector(1, 1, 1), G4ThreeVector(2, 2, 2) }; fElectricField->PrintFieldValues(debugPoints); // verbosity commands G4UImanager* UImanager = G4UImanager::GetUIpointer(); UImanager->ApplyCommand("/tracking/verbose 1"); UImanager->ApplyCommand("/step/verbose 1"); }