diff --git a/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml b/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml index 4c6e2d616c85648a018cecf07d7c1f6ce7874527..9d00426806e14fdb9a8961b751ff5a3dd6fc17b0 100644 --- a/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml +++ b/Detector/DetCEPCv4/compact/CepC_v4-onlyTracker.xml @@ -74,4 +74,13 @@ <!--include ref="Field_Solenoid_Map_s_4.0T.xml"/> <include ref="Field_AntiDID_Map_s.xml"/> <include ref="Field_FwdMagnets_Ideal_1000GeV.xml"/--> + + + <fields> + + <field name="MagnetFields_Constant" type="ConstantField" field="magnetic"> + <strength x="0" y="0" z="3.0*tesla"/> + </field> + + </fields> </lccdd> diff --git a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp index ff31cdf11c5cf4167272597d227ea9c58a0f997e..87ad61b35a7fb05c9bd18999bcc3ea5e40d66c9f 100644 --- a/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp +++ b/Simulation/DetSimGeom/src/AnExampleDetElemTool.cpp @@ -19,11 +19,16 @@ #include "G4PhysicalVolumeStore.hh" #include "G4OpticalSurface.hh" +// Field +#include "G4UniformMagField.hh" +#include "G4FieldManager.hh" +#include "G4TransportationManager.hh" + #include "DD4hep/Detector.h" #include "DD4hep/Plugins.h" #include "DDG4/Geant4Converter.h" #include "DDG4/Geant4Mapping.h" - +#include "DDG4/Geant4Field.h" DECLARE_COMPONENT(AnExampleDetElemTool) @@ -143,6 +148,31 @@ AnExampleDetElemTool::ConstructSDandField() { } } + // ======================================================================= + // Construct Field + // ======================================================================= + // TODO: integrate the field between DD4hep and Geant4 + // Note: + // DD4hep provides the parameters of fields + // Geant4 will setup the field based on the DD4hep fields + + // Related Examples: + // - G4: G4GlobalMagFieldMessenger.cc + + G4FieldManager* fieldManager + = G4TransportationManager::GetTransportationManager()->GetFieldManager(); + + // // Below is a uniform B-field + // G4ThreeVector value(0,0,3.*tesla); + // G4UniformMagField* mag_field = new G4UniformMagField(value); + + // DDG4 based B-field + dd4hep::OverlayedField fld = lcdd->field(); + G4MagneticField* mag_field = new dd4hep::sim::Geant4Field(fld); + + fieldManager->SetDetectorField(mag_field); + fieldManager->CreateChordFinder(mag_field); + }