Message: Setting Up Constant EM Field Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question Setting Up Constant EM Field 

Forum: Fields: Magnetic and Otherwise
Date: 17 Apr, 2017
From: <DrumMumble>

Hello Geant4 Users,

I am currently trying to define a constant electromagnetic field. I understand you must define your field class, create a field manager and attach the field manager to the logical volume in question. My code will compile but it doesn't seem to be setting up the electric field portion of the EM field. Also, Geant4 doesn't seem to be calling my GetFieldValue function. Any help would be greatly appreciated. I've included below the header and source file for EMField class as well as my initialization.

/////HEADER class UniformEMField : public G4ElectroMagneticField {

     public:

		G4ThreeVector MagneticField;
		G4ThreeVector ElectricField;

		UniformEMField(G4ThreeVector MagneticField, G4ThreeVector ElectricField);
		virtual ~UniformEMField();

		virtual G4bool DoesFieldChangeEnergy() const { return true; };

		virtual void GetFieldValue(const G4double Point[4], G4double* EMField) const;
};

/////SOURCE UniformEMField::UniformEMField(G4ThreeVector MagneticField, G4ThreeVector ElectricField) : G4ElectroMagneticField(){

	this->MagneticField = MagneticField;
	this->ElectricField = ElectricField;

}

UniformEMField::~UniformEMField() {

}

void UniformEMField::GetFieldValue(const G4double Point[4], G4double* EMField) const {

	EMField[0] = this->MagneticField.x();
	EMField[1] = this->MagneticField.y();
	EMField[2] = this->MagneticField.z();

	EMField[3] = this->ElectricField.x();
	EMField[4] = this->ElectricField.y();
	EMField[5] = this->ElectricField.z();

}

/////INITIALIZATION void DetectorComponent::SetEMField() {

	cout << "IN SET EM FIELD\n";

	UniformEMField *Field = new UniformEMField(this->MagneticField, this->ElectricField);

	cout << " FIELD IS: \n";
	cout << Field->ElectricField.x() << "\n";
	cout << Field->ElectricField.y() << "\n";
	cout << Field->ElectricField.z() << "\n";

	G4EqEMFieldWithSpin* Equation = new G4EqEMFieldWithSpin(Field);
	G4FieldManager* FieldMgr = G4TransportationManager::GetTransportationManager()->GetFieldManager();

	FieldMgr->SetFieldChangesEnergy(true);

	G4double minStep = 0.01*mm;
	G4MagIntegratorStepper* Stepper = new G4ClassicalRK4(Equation,8);

	G4ChordFinder* ChordFinder = new G4ChordFinder((G4MagneticField*)Field,minStep,Stepper);
	G4double deltaChord        = 3.0*mm;
	ChordFinder->SetDeltaChord( deltaChord );

	G4double deltaOneStep      = 0.01*mm;
	FieldMgr->SetAccuraciesWithDeltaOneStep(deltaOneStep);

	G4double deltaIntersection = 0.1*mm;
	FieldMgr->SetDeltaIntersection(deltaIntersection);

	G4TransportationManager* TransportManager = G4TransportationManager::GetTransportationManager();
	TransportManager->SetFieldManager(FieldMgr);
	G4PropagatorInField* FieldPropagator = TransportManager->GetPropagatorInField();

	G4double epsMin            = 2.5e-7*mm;
	G4double epsMax            = 0.05*mm;

	FieldPropagator->SetMinimumEpsilonStep(epsMin);
	FieldPropagator->SetMaximumEpsilonStep(epsMax);

	FieldMgr->SetChordFinder(ChordFinder);
	FieldMgr->SetDetectorField(Field);

}

 Add Message Add Message
to: "Setting Up Constant EM Field"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]