diff --git a/CHANGELOG.md b/CHANGELOG.md index f708a3dd08..30b9832d77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,10 @@ it in future. - The `--SND_design` option in `macro/run_simScript.py` now accepts multiple values and an 'all' option to enable all available SND designs. - The geometry configuration and detector setup (`geometry/geometry_config.py`, `python/shipDet_conf.py`) have been updated to instantiate all requested SND detectors. - This enables running with multiple SND subdetectors simultaneously and is future-proof for additional SND designs. +* Added YAML configuration files for Geant4 VMC setup (`g4Config.yaml`, `g4Config_basic.yaml`) to replace deprecated C macros + - Includes physics lists, Monte Carlo processes/cuts, and Geant4 macro commands + - Maintains full compatibility with original C configuration functionality +* Add SHiP::VMCConfig class to setup VMC from the YAML configuration ### Fixed @@ -122,6 +126,9 @@ it in future. - Add `SetTargetCoordinates()` method for robust geometry-based target configuration - Maintain backward compatibility with legacy TGeo navigation as fallback - The decorators from decorators.py now need to be applied explicitly using the new `apply_decorators` function. +* Updated all simulation scripts to use YAML configuration (`g4Config.yaml`) instead of deprecated C macros (`g4Config.C`) + - Added explicit ShipStack instantiation in Python code to maintain custom stack functionality + - Updated 8 scripts including `run_simScript.py`, `inspectGeant4Geo.py`, and muonShieldOptimization scripts ### Removed @@ -150,6 +157,8 @@ it in future. * Remove tankDesign variable, options * Remove target versions older than CDR * Remove hadron absorber in ShipTargetStation.cxx +* Removed deprecated Geant4 VMC configuration files (`g4Config.C`, `g4Config_basic.C`, `g4config.in`, `g4config_basic.in`) +* Remove GCUTS (replaced by CUTGAM in Geant4) ## 25.01 diff --git a/gconfig/g4Config.C b/gconfig/g4Config.C deleted file mode 100644 index 6cc6e948ca..0000000000 --- a/gconfig/g4Config.C +++ /dev/null @@ -1,53 +0,0 @@ -// Configuration macro for Geant4 VirtualMC -void Config() -{ -/// Create the run configuration -/// In constructor user has to specify the geometry input -/// and select geometry navigation via the following options: -/// - geomVMCtoGeant4 - geometry defined via VMC, G4 native navigation -/// - geomVMCtoRoot - geometry defined via VMC, Root navigation -/// - geomRoot - geometry defined via Root, Root navigation -/// - geomRootToGeant4 - geometry defined via Root, G4 native navigation -/// - geomGeant4 - geometry defined via Geant4, G4 native navigation -/// -/// The second argument in the constructor selects physics list: -/// - emStandard - standard em physics (default) -/// - emStandard+optical - standard em physics + optical physics -/// - XYZ - selected hadron physics list ( XYZ = LHEP, QGSP, ...) -/// - XYZ+optical - selected hadron physics list + optical physics -/// -/// The third argument activates the special processes in the TG4SpecialPhysicsList, -/// which implement VMC features: -/// - stepLimiter - step limiter (default) -/// - specialCuts - VMC cuts -/// - specialControls - VMC controls for activation/inactivation selected processes -/// - stackPopper - stackPopper process -/// When more than one options are selected, they should be separated with '+' -/// character: eg. stepLimit+specialCuts. - TG4RunConfiguration* runConfiguration - = new TG4RunConfiguration("geomRoot", "QGSP_BERT_HP_PEN", "stepLimiter+specialCuts+specialControls"); - -/// Create the G4 VMC - TGeant4* geant4 = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration); -/// create the Specific stack - ShipStack *stack = new ShipStack(1000); - stack->StoreSecondaries(kTRUE); - stack->SetMinPoints(0); - geant4->SetStack(stack); - //if(FairRunSim::Instance()->IsExtDecayer()){ - // // does not work ! TVirtualMCDecayer* decayer = TPythia8Decayer::Instance(); - // TVirtualMCDecayer* decayer = TVirtualMCDecayer* TPythia8Decayer(); - // geant4->SetExternalDecayer(decayer); - //} - -/// Customise Geant4 setting -/// (verbose level, global range cut, ..) - - TString configm(gSystem->Getenv("VMCWORKDIR")); - TString configm1 = configm + "/gconfig/g4config.in"; - cout << " -I g4Config() using g4conf macro: " << configm1 << endl; - //set geant4 specific stuff - // still stupid bug in geant4_vmc - // geant4->SetMaxNStep(10000.); // default is 30000 - geant4->ProcessGeantMacro(configm1.Data()); -} diff --git a/gconfig/g4Config.yaml b/gconfig/g4Config.yaml new file mode 100644 index 0000000000..267a3224f3 --- /dev/null +++ b/gconfig/g4Config.yaml @@ -0,0 +1,44 @@ +Geant4_UserGeometry: "geomRoot" +Geant4_PhysicsList: "QGSP_BERT_HP_PEN" +Geant4_SpecialProcess: "stepLimiter+specialCuts+specialControls" +Geant4_SpecialStacking: false +Geant4_Multithreaded: false + +Geant4_MaxNStep: 10000 #default is 30000 +Geant4_Commands: + - /mcVerbose/all 0 + - /mcTracking/loopVerbose 0 + - /mcPhysics/g4NeutronHPVerbose 0 + - /mcPhysics/g4HadronicProcessStoreVerbose 0 + - /physics_lists/em/PositronToMuons true + - /physics_lists/em/GammaToMuons true + - /process/em/verbose 0 + - /process/eLoss/verbose 0 + - /mcDet/setIsLocalMagField true + +MonteCarlo_Process: + PAIR: 1 #pair production + COMP: 1 #Compton scattering + PHOT: 1 #photo electric effect + PFIS: 0 #photofission + DRAY: 1 #delta-ray + ANNI: 1 #annihilation + BREM: 1 #bremsstrahlung + HADR: 1 #hadronic process + MUNU: 1 #muon nuclear interaction + DCAY: 1 #decay + LOSS: 1 #energy loss + MULS: 1 #multiple scattering + +MonteCarlo_Cut: + CUTGAM: 1.0E-3 #gammas (GeV) + CUTELE: 1.0E-3 #electrons (GeV) + CUTNEU: 1.0E-3 #neutral hadrons (GeV) + CUTHAD: 1.0E-3 #charged hadrons (GeV) + CUTMUO: 1.0E-3 #muons (GeV) + BCUTE: 1.0E-3 #electron bremsstrahlung (GeV) + BCUTM: 1.0E-3 #muon and hadron bremsstrahlung (GeV) + DCUTE: 1.0E-3 #electron delta-rays (GeV) + DCUTM: 1.0E-3 #muon and hadron delta-rays (GeV) + PPCUTM: 1.0E-3 #direct pair production by muons (GeV) + TOFMAX: 1.E10 #time of flight cut (s) diff --git a/gconfig/g4Config_basic.C b/gconfig/g4Config_basic.C deleted file mode 100644 index 609c855dd9..0000000000 --- a/gconfig/g4Config_basic.C +++ /dev/null @@ -1,53 +0,0 @@ -// Configuration macro for Geant4 VirtualMC -void Config() -{ -/// Create the run configuration -/// In constructor user has to specify the geometry input -/// and select geometry navigation via the following options: -/// - geomVMCtoGeant4 - geometry defined via VMC, G4 native navigation -/// - geomVMCtoRoot - geometry defined via VMC, Root navigation -/// - geomRoot - geometry defined via Root, Root navigation -/// - geomRootToGeant4 - geometry defined via Root, G4 native navigation -/// - geomGeant4 - geometry defined via Geant4, G4 native navigation -/// -/// The second argument in the constructor selects physics list: -/// - emStandard - standard em physics (default) -/// - emStandard+optical - standard em physics + optical physics -/// - XYZ - selected hadron physics list ( XYZ = LHEP, QGSP, ...) -/// - XYZ+optical - selected hadron physics list + optical physics -/// -/// The third argument activates the special processes in the TG4SpecialPhysicsList, -/// which implement VMC features: -/// - stepLimiter - step limiter (default) -/// - specialCuts - VMC cuts -/// - specialControls - VMC controls for activation/inactivation selected processes -/// - stackPopper - stackPopper process -/// When more than one options are selected, they should be separated with '+' -/// character: eg. stepLimit+specialCuts. - TG4RunConfiguration* runConfiguration - = new TG4RunConfiguration("geomRoot", "emStandard"); - -/// Create the G4 VMC - TGeant4* geant4 = new TGeant4("TGeant4", "The Geant4 Monte Carlo", runConfiguration); -/// create the Specific stack - ShipStack *stack = new ShipStack(1000); - stack->StoreSecondaries(kTRUE); - stack->SetMinPoints(0); - geant4->SetStack(stack); - //if(FairRunSim::Instance()->IsExtDecayer()){ - // // does not work ! TVirtualMCDecayer* decayer = TPythia8Decayer::Instance(); - // TVirtualMCDecayer* decayer = TVirtualMCDecayer* TPythia8Decayer(); - // geant4->SetExternalDecayer(decayer); - //} - -/// Customise Geant4 setting -/// (verbose level, global range cut, ..) - - TString configm(gSystem->Getenv("VMCWORKDIR")); - TString configm1 = configm + "/gconfig/g4config_basic.in"; - cout << " -I g4Config() using g4conf macro: " << configm1 << endl; - //set geant4 specific stuff - // still stupid bug in geant4_vmc - // geant4->SetMaxNStep(10000.); // default is 30000 - geant4->ProcessGeantMacro(configm1.Data()); -} diff --git a/gconfig/g4Config_basic.yaml b/gconfig/g4Config_basic.yaml new file mode 100644 index 0000000000..276ed44d69 --- /dev/null +++ b/gconfig/g4Config_basic.yaml @@ -0,0 +1,42 @@ +Geant4_UserGeometry: "geomRoot" +Geant4_PhysicsList: "emStandard" +Geant4_SpecialProcess: "" +Geant4_SpecialStacking: false +Geant4_Multithreaded: false + +Geant4_MaxNStep: 10000 #default is 30000 +Geant4_Commands: + - /mcVerbose/all 0 + - /mcTracking/loopVerbose 0 + - /mcPhysics/g4NeutronHPVerbose 0 + - /mcPhysics/g4HadronicProcessStoreVerbose 0 + - /process/em/verbose 0 + - /process/eLoss/verbose 0 + - /mcDet/setIsLocalMagField true + +MonteCarlo_Process: + PAIR: 1 #pair production + COMP: 1 #Compton scattering + PHOT: 1 #photo electric effect + PFIS: 0 #photofission + DRAY: 1 #delta-ray + ANNI: 1 #annihilation + BREM: 1 #bremsstrahlung + HADR: 1 #hadronic process + MUNU: 1 #muon nuclear interaction + DCAY: 1 #decay + LOSS: 1 #energy loss + MULS: 1 #multiple scattering + +MonteCarlo_Cut: + CUTGAM: 1.0E-3 #gammas (GeV) + CUTELE: 1.0E-3 #electrons (GeV) + CUTNEU: 1.0E-3 #neutral hadrons (GeV) + CUTHAD: 1.0E-3 #charged hadrons (GeV) + CUTMUO: 1.0E-3 #muons (GeV) + BCUTE: 1.0E-3 #electron bremsstrahlung (GeV) + BCUTM: 1.0E-3 #muon and hadron bremsstrahlung (GeV) + DCUTE: 1.0E-3 #electron delta-rays (GeV) + DCUTM: 1.0E-3 #muon and hadron delta-rays (GeV) + PPCUTM: 1.0E-3 #direct pair production by muons (GeV) + TOFMAX: 1.E10 #time of flight cut (s) diff --git a/gconfig/g4config.in b/gconfig/g4config.in deleted file mode 100644 index 5847e9c33c..0000000000 --- a/gconfig/g4config.in +++ /dev/null @@ -1,33 +0,0 @@ -# -# Geant4 configuration macro for Example02 -# (called from Root macro Config.C) - -/mcVerbose/all 0 -/mcTracking/loopVerbose 0 # suggested by Ivana Hrivnacova to switch off *** Particle reached max step number .... -/mcPhysics/g4NeutronHPVerbose 0 # - suppress the warnings about missing neutron data -/mcPhysics/g4HadronicProcessStoreVerbose 0 - -# switch on other sources of di muon -/physics_lists/em/PositronToMuons true -/physics_lists/em/GammaToMuons true - -# drives me crazy how to stop this tons of output !!! -/process/em/verbose 0 -/process/eLoss/verbose 0 - -#/mcVerbose/composedPhysicsList 0 -#/mcVerbose/trackManager 2 - -#/mcVerbose/regionsManager 3 - -#/run/particle/applyCuts -#/mcTracking/saveSecondariesInStep true - -#/tracking/verbose 1 -#/control/cout/ignoreThreadsExcept 0 - -# Enable local magnetic fields -/mcDet/setIsLocalMagField true - -# Enable verbosity for VMC geometry manager -#/mcVerbose/geometryManager 2 diff --git a/gconfig/g4config_basic.in b/gconfig/g4config_basic.in deleted file mode 100644 index 0e840597e7..0000000000 --- a/gconfig/g4config_basic.in +++ /dev/null @@ -1,28 +0,0 @@ -# -# Geant4 configuration macro for Example02 -# (called from Root macro Config.C) - -/mcVerbose/all 0 -/mcTracking/loopVerbose 0 # suggested by Ivana Hrivnacova to switch off *** Particle reached max step number .... -/mcPhysics/g4NeutronHPVerbose 0 # - suppress the warnings about missing neutron data -/mcPhysics/g4HadronicProcessStoreVerbose 0 - -# drives me crazy how to stop this tons of output !!! -/process/em/verbose 0 -/process/eLoss/verbose 0 - -#/mcVerbose/composedPhysicsList 0 -#/mcVerbose/trackManager 2 - -#/mcVerbose/regionsManager 3 - -#/run/particle/applyCuts -#/mcTracking/saveSecondariesInStep true - -#/tracking/verbose 1 -#/control/cout/ignoreThreadsExcept 0 - -# Enable local magnetic fields -/mcDet/setIsLocalMagField true -# Enable verbosity for VMC geometry manager -#/mcVerbose/geometryManager 2 diff --git a/macro/ShipAna.py b/macro/ShipAna.py index 133b19c25a..2d33409cba 100644 --- a/macro/ShipAna.py +++ b/macro/ShipAna.py @@ -53,7 +53,7 @@ run = ROOT.FairRunSim() run.SetName("TGeant4") # Transport engine run.SetSink(ROOT.FairRootFileSink(ROOT.TMemFile('output', 'recreate'))) # Dummy output file -run.SetUserConfig("g4Config_basic.C") # geant4 transport not used, only needed for the mag field +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config_basic.yaml"));') # geant4 transport not used, only needed for the mag field rtdb = run.GetRuntimeDb() # -----Create geometry---------------------------------------------- modules = shipDet_conf.configure(run,ShipGeo) diff --git a/macro/ShipReco.py b/macro/ShipReco.py index 3835bb2e8f..73a765a82f 100644 --- a/macro/ShipReco.py +++ b/macro/ShipReco.py @@ -100,7 +100,7 @@ def mem_monitor(): run = ROOT.FairRunSim() run.SetName("TGeant4") # Transport engine run.SetSink(ROOT.FairRootFileSink(ROOT.TMemFile('output', 'recreate'))) # Dummy output file -run.SetUserConfig("g4Config_basic.C") # geant4 transport not used, only needed for creating VMC field +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config_basic.yaml"));') # geant4 transport not used, only needed for creating VMC field rtdb = run.GetRuntimeDb() # -----Create geometry---------------------------------------------- modules = shipDet_conf.configure(run,ShipGeo) diff --git a/macro/create_field_perturbation.py b/macro/create_field_perturbation.py index 22094e74fb..3a3c36d07d 100644 --- a/macro/create_field_perturbation.py +++ b/macro/create_field_perturbation.py @@ -32,15 +32,16 @@ def create_csv_field_map(options): run = r.FairRunSim() run.SetName('TGeant4') # Transport engine - run.SetSink(ROOT.FairRootFileSink("tmp_file")) # Output file - # user configuration file default g4Config.C - run.SetUserConfig('g4Config.C') + run.SetSink(r.FairRootFileSink("tmp_file")) # Output file + # Use SHiP::VMCConfig for YAML configuration + r.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') modules = shipDet_conf.configure(run, ship_geo) primGen = r.FairPrimaryGenerator() primGen.SetTarget(ship_geo.target.z0+70.845*u.m, 0.) # run.SetGenerator(primGen) run.SetStoreTraj(r.kFALSE) + # ShipStack is now automatically created by SHiP::VMCConfig run.Init() fieldMaker = geomGeant4.addVMCFields(ship_geo, '', True) diff --git a/macro/inspectGeant4Geo.py b/macro/inspectGeant4Geo.py index facb2c2322..926cfb8e28 100644 --- a/macro/inspectGeant4Geo.py +++ b/macro/inspectGeant4Geo.py @@ -11,15 +11,19 @@ fgeo = ROOT.TFile(fname) sGeo = fgeo.Get("FAIRGeom") import shipDet_conf + run = ROOT.FairRunSim() upkl = Unpickler(fgeo) ShipGeo = upkl.load('ShipGeo') modules = shipDet_conf.configure(run, ShipGeo) -run.SetUserConfig('g4Config.C') +# Use SHiP::VMCConfig for YAML configuration +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') run.SetName('TGeant4') run.SetSink(ROOT.FairRootFileSink(ROOT.TMemFile('output', 'recreate'))) +# ShipStack is now automatically created by SHiP::VMCConfig run.Init() run.Run(0) import geomGeant4 + geomGeant4.printVMCFields() geomGeant4.printWeightsandFields() diff --git a/macro/run_simScript.py b/macro/run_simScript.py index d3e6cbe97c..9b0ce4fe15 100755 --- a/macro/run_simScript.py +++ b/macro/run_simScript.py @@ -286,12 +286,14 @@ run = ROOT.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file -run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C +# Use SHiP::VMCConfig for YAML configuration via C++ interpreter +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') rtdb = run.GetRuntimeDb() # -----Create geometry---------------------------------------------- # import shipMuShield_only as shipDet_conf # special use case for an attempt to convert active shielding geometry for use with FLUKA # import shipTarget_only as shipDet_conf import shipDet_conf + modules = shipDet_conf.configure(run,ship_geo) # -----Create PrimaryGenerator-------------------------------------- primGen = ROOT.FairPrimaryGenerator() @@ -515,6 +517,9 @@ #--- Use it only to display but not for production! if options.eventDisplay: run.SetStoreTraj(ROOT.kTRUE) else: run.SetStoreTraj(ROOT.kFALSE) + +# ShipStack is now automatically created by SHiP::VMCConfig + # -----Initialize simulation run------------------------------------ run.Init() if options.dryrun: # Early stop after setting up Pythia 8 diff --git a/muonShieldOptimization/run_fixedTarget.py b/muonShieldOptimization/run_fixedTarget.py index 1a938e8136..3828992dbf 100644 --- a/muonShieldOptimization/run_fixedTarget.py +++ b/muonShieldOptimization/run_fixedTarget.py @@ -143,7 +143,8 @@ def get_work_dir(run_number,tag=None): run = ROOT.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file -run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C +# Use SHiP::VMCConfig for YAML configuration +run.SetSimulationConfig(ROOT.std.make_unique[ROOT.SHiP.VMCConfig]("g4Config", "g4Config.yaml")) rtdb = run.GetRuntimeDb() # -----Materials---------------------------------------------- @@ -214,6 +215,7 @@ def get_work_dir(run_number,tag=None): # run.SetGenerator(primGen) # -----Initialize simulation run------------------------------------ +# ShipStack is now automatically created by SHiP::VMCConfig run.Init() gMC = ROOT.TVirtualMC.GetMC() diff --git a/muonShieldOptimization/study_GammaConv.py b/muonShieldOptimization/study_GammaConv.py index 3b949aaed6..e3c86263b1 100644 --- a/muonShieldOptimization/study_GammaConv.py +++ b/muonShieldOptimization/study_GammaConv.py @@ -42,7 +42,8 @@ run = ROOT.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file -run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C +# Use SHiP::VMCConfig for YAML configuration +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') rtdb = run.GetRuntimeDb() # -----Materials---------------------------------------------- @@ -96,6 +97,7 @@ def makeSensitive(self,sensPlane): # run.SetGenerator(primGen) # -----Initialize simulation run------------------------------------ +# ShipStack is now automatically created by SHiP::VMCConfig run.Init() gMC = ROOT.TVirtualMC.GetMC() diff --git a/muonShieldOptimization/study_muEloss.py b/muonShieldOptimization/study_muEloss.py index e7be4742ef..b625f48a6e 100644 --- a/muonShieldOptimization/study_muEloss.py +++ b/muonShieldOptimization/study_muEloss.py @@ -58,7 +58,8 @@ def run(): run.SetName(mcEngine) # Transport engine if nev==0: run.SetSink(ROOT.FairRootFileSink("dummy.root")) else: run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file - run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C + # Use SHiP::VMCConfig for YAML configuration + ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') rtdb = run.GetRuntimeDb() # -----Materials---------------------------------------------- run.SetMaterials("media.geo") @@ -86,6 +87,7 @@ def run(): # run.SetGenerator(primGen) # -----Initialize simulation run------------------------------------ + # ShipStack is now automatically created by SHiP::VMCConfig run.Init() if nev==0: return gMC = ROOT.TVirtualMC.GetMC() diff --git a/muonShieldOptimization/study_muMSC.py b/muonShieldOptimization/study_muMSC.py index efe4612507..7a8d592c28 100644 --- a/muonShieldOptimization/study_muMSC.py +++ b/muonShieldOptimization/study_muMSC.py @@ -44,7 +44,8 @@ run = ROOT.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file -run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C +# Use SHiP::VMCConfig for YAML configuration +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') rtdb = run.GetRuntimeDb() # -----Materials---------------------------------------------- @@ -93,6 +94,7 @@ def InitParContainers(): # run.SetGenerator(primGen) # -----Initialize simulation run------------------------------------ +# ShipStack is now automatically created by SHiP::VMCConfig run.Init() gMC = ROOT.TVirtualMC.GetMC() diff --git a/muonShieldOptimization/study_thinTarget.py b/muonShieldOptimization/study_thinTarget.py index a22ce756f0..e60cdbf0b3 100644 --- a/muonShieldOptimization/study_thinTarget.py +++ b/muonShieldOptimization/study_thinTarget.py @@ -39,7 +39,8 @@ run = ROOT.FairRunSim() run.SetName(mcEngine) # Transport engine run.SetSink(ROOT.FairRootFileSink(outFile)) # Output file -run.SetUserConfig("g4Config.C") # user configuration file default g4Config.C +# Use SHiP::VMCConfig for YAML configuration +ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config.yaml"));') rtdb = run.GetRuntimeDb() # -----Materials---------------------------------------------- @@ -88,6 +89,7 @@ def InitParContainers(): # run.SetGenerator(primGen) # -----Initialize simulation run------------------------------------ +# ShipStack is now automatically created by SHiP::VMCConfig run.Init() gMC = ROOT.TVirtualMC.GetMC() diff --git a/python/SciFiMapping.py b/python/SciFiMapping.py index 3772ab2ecd..9cfd1537cc 100644 --- a/python/SciFiMapping.py +++ b/python/SciFiMapping.py @@ -343,7 +343,7 @@ def draw_many_channels( run.SetSink( ROOT.FairRootFileSink(ROOT.TMemFile("output", "recreate")) ) # Output file - run.SetUserConfig("g4Config_basic.C") # geant4 transport not used + ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config_basic.yaml"));') # geant4 transport not used rtdb = run.GetRuntimeDb() modules = shipDet_conf.configure(run, ship_geo) run.Init() diff --git a/python/shipStrawTracking.py b/python/shipStrawTracking.py index f2d170c2f9..d9f8ee7a5f 100644 --- a/python/shipStrawTracking.py +++ b/python/shipStrawTracking.py @@ -77,7 +77,7 @@ def run_track_pattern_recognition(input_file, geo_file, output_file, method): # Create dummy output file as the input file is updated directly and # histograms are written to output file (hists.root by default) run.SetSink(ROOT.FairRootFileSink(ROOT.TMemFile('output', 'recreate'))) - run.SetUserConfig("g4Config_basic.C") # geant4 transport not used, only needed for the mag field + ROOT.gInterpreter.ProcessLine('FairRunSim::Instance()->SetSimulationConfig(std::make_unique("g4Config", "g4Config_basic.yaml"));') # geant4 transport not used, only needed for the mag field rtdb = run.GetRuntimeDb() modules = shipDet_conf.configure(run,ShipGeo) diff --git a/shipdata/CMakeLists.txt b/shipdata/CMakeLists.txt index efe46d02fb..4a8b5904d5 100644 --- a/shipdata/CMakeLists.txt +++ b/shipdata/CMakeLists.txt @@ -20,13 +20,8 @@ ${genfit2_LIBDIR} link_directories( ${LINK_DIRECTORIES}) -set(SRCS -ShipHit.cxx -ShipStack.cxx -ShipMCTrack.cxx -ShipParticle.cxx -TrackInfo.cxx -) +set(SRCS ShipHit.cxx ShipStack.cxx ShipMCTrack.cxx ShipParticle.cxx + TrackInfo.cxx VMCConfig.cxx) Set(HEADERS ) Set(LINKDEF MCStackLinkDef.h) diff --git a/shipdata/MCStackLinkDef.h b/shipdata/MCStackLinkDef.h index be031fa4bc..ddc36e4a87 100644 --- a/shipdata/MCStackLinkDef.h +++ b/shipdata/MCStackLinkDef.h @@ -10,5 +10,6 @@ #pragma link C++ class ShipMCTrack+; #pragma link C++ class ShipParticle+; #pragma link C++ class TrackInfo+; +#pragma link C++ class SHiP::VMCConfig+; #endif diff --git a/shipdata/VMCConfig.cxx b/shipdata/VMCConfig.cxx new file mode 100644 index 0000000000..ff1749cefc --- /dev/null +++ b/shipdata/VMCConfig.cxx @@ -0,0 +1,72 @@ +// ------------------------------------------------------------------------- +// ----- SHiP::VMCConfig source file ----- +// ------------------------------------------------------------------------- + +#include "VMCConfig.h" +#include "ShipStack.h" + +#include "TVirtualMC.h" +#include "FairLogger.h" + +#include + + +namespace SHiP { + +// ----- Constructor --------------------------------------------------- +VMCConfig::VMCConfig(const std::string& name, const std::string& yamlFile) + : FairYamlVMCConfig() + , fYamlFile(yamlFile) +{ + LOG(info) << "SHiP::VMCConfig: Constructor called with YAML file: " << fYamlFile; +} + +// ----- Destructor ---------------------------------------------------- +VMCConfig::~VMCConfig() +{ +} + +// ----- Setup method -------------------------------------------------- +void VMCConfig::Setup(const char* mcEngine) +{ + LOG(info) << "SHiP::VMCConfig: Setting up VMC for engine: " << mcEngine; + + // Call parent Setup method to handle YAML configuration loading + // FairYamlVMCConfig will automatically find the YAML file based on mcEngine + FairYamlVMCConfig::Setup(mcEngine); + + LOG(info) << "SHiP::VMCConfig: Setup completed successfully"; +} + +// ----- SetupStack method (pure virtual from base class) ----------------- +void VMCConfig::SetupStack() +{ + LOG(info) << "SHiP::VMCConfig: Setting up stack"; + + // Create and configure ShipStack for SHiP-specific functionality + CreateShipStack(); +} + +// ----- Private method to create ShipStack --------------------------- +void VMCConfig::CreateShipStack() +{ + LOG(info) << "SHiP::VMCConfig: Creating and configuring ShipStack"; + + // Create ShipStack with default size of 1000 + ShipStack* stack = new ShipStack(1000); + + // Configure stack settings + stack->StoreSecondaries(kTRUE); + stack->SetMinPoints(0); + + // Set the stack to the VMC engine + TVirtualMC* mc = TVirtualMC::GetMC(); + if (mc) { + mc->SetStack(stack); + LOG(info) << "SHiP::VMCConfig: ShipStack successfully set to VMC engine"; + } else { + LOG(error) << "SHiP::VMCConfig: Could not get VMC instance to set stack"; + } +} + +} // namespace SHiP diff --git a/shipdata/VMCConfig.h b/shipdata/VMCConfig.h new file mode 100644 index 0000000000..5839e66b45 --- /dev/null +++ b/shipdata/VMCConfig.h @@ -0,0 +1,58 @@ +// ------------------------------------------------------------------------- +// ----- SHiP::VMCConfig header file ----- +// ------------------------------------------------------------------------- + +/** VMCConfig.h + ** + ** Custom VMC configuration class for SHiP experiment that inherits from + ** FairYamlVMCConfig and provides SHiP-specific functionality including: + ** - Automatic ShipStack instantiation and configuration + ** - YAML configuration file loading from specified path + ** - Integration with SHiP simulation framework + **/ + +#ifndef SHIPDATA_VMCCONFIG_H_ +#define SHIPDATA_VMCCONFIG_H_ + +#include "FairYamlVMCConfig.h" +#include "Rtypes.h" +#include + +class ShipStack; + +namespace SHiP { + +class VMCConfig : public FairYamlVMCConfig +{ + public: + /** Constructor with YAML file path + *@param name Configuration name (unused - kept for compatibility) + *@param yamlFile Path to YAML configuration file (unused - auto-discovered) + **/ + explicit VMCConfig(const std::string& name = "g4Config", const std::string& yamlFile = "g4Config.yaml"); + + /** Destructor **/ + virtual ~VMCConfig(); + + /** Setup VMC configuration + *@param mcEngine Monte Carlo engine name (e.g. "TGeant4") + **/ + void Setup(const char* mcEngine) override; + + protected: + /** Setup stack (pure virtual from FairYamlVMCConfig) **/ + void SetupStack() override; + + private: + /** Create and configure ShipStack **/ + void CreateShipStack(); + + /** YAML configuration file path **/ + std::string fYamlFile; + + ClassDef(VMCConfig, 1) +}; + +} // namespace SHiP + +#endif // SHIPDATA_VMCCONFIG_H_