11/******************************************************************************
2- * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3- * Copyright (C) 2019-2025 Members of R3B Collaboration *
2+ * Copyright (C) 2020 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3+ * Copyright (C) 2020-2026 Members of R3B Collaboration *
44 * *
55 * This software is distributed under the terms of the *
66 * GNU General Public Licence (GPL) version 3, *
1717#include <iostream>
1818#include <memory>
1919
20- void testR3BPhaseSpaceGeneratorIntegration ()
20+ void testR3BPhaseSpaceGeneratorIntegration (const int nbevents = 10 )
2121{
2222 // Timer
2323 TStopwatch timer ;
@@ -34,58 +34,65 @@ void testR3BPhaseSpaceGeneratorIntegration()
3434 gSystem -> Setenv ("GEOMPATH" , workDirectory + "/geometry" );
3535 gSystem -> Setenv ("CONFIG_DIR" , workDirectory + "/gconfig" );
3636
37- // Simulation Base
37+ // Output files
38+ const TString simufile = "PhaseSpace.simu.root" ;
39+ const TString parafile = "PhaseSpace.para.root" ;
40+
41+ // Basic simulation setup
3842 FairRunSim run ;
3943 run .SetName ("TGeant4" );
40- run .SetOutputFile ( "testR3BPhaseSpaceGeneratorIntegration.root" );
44+ run .SetSink ( std :: make_unique < FairRootFileSink > ( simufile . Data ()) );
4145 run .SetMaterials ("media_r3b.geo" );
4246
43- // World
44- auto cave = new R3BCave ("Cave" );
47+ // ----- Runtime data base --------------------------------------------
48+ auto* rtdb = run .GetRuntimeDb ();
49+ UInt_t runId = 1 ;
50+ rtdb -> initContainers (runId );
51+
52+ // Geometry: Cave
53+ auto cave = std ::make_unique < R3BCave > ("CAVE ");
4554 cave -> SetGeometryFileName ("r3b_cave_vacuum.geo" );
46- run .AddModule (cave );
55+ run .AddModule (cave . release () );
4756
4857 // Magnet
49- // run.AddModule(new R3BGladMagnet("glad_v2023.1.geo.root"));
50- auto magField = new R3BGladFieldMap ("R3BGladMap" );
51- magField -> SetScale (-0.6 );
52- run .SetField (magField );
58+ auto GladField = new R3BGladFieldMap ("R3BGladMap" );
59+ GladField -> SetScale (-0.6 );
60+ run .SetField (GladField );
5361
5462 // Primaries
55- auto primGen = new FairPrimaryGenerator ();
63+ auto primGen = std :: make_unique < FairPrimaryGenerator > ();
5664 auto gen = new R3BPhaseSpaceGenerator ();
5765 gen -> GetBeam ().SetEnergyDistribution (R3BDistribution1D ::Delta (600 ));
5866 gen -> SetErelDistribution (R3BDistribution1D ::Delta (100 ));
5967 gen -> AddParticle (5 , 17 );
6068 gen -> AddNeutron ();
6169 gen -> AddProton ();
6270 primGen -> AddGenerator (gen );
63- run .SetGenerator (primGen );
71+ run .SetGenerator (primGen . release () );
6472
6573 // Logging
6674 run .SetStoreTraj (false);
67- FairLogger ::GetLogger ()-> SetLogVerbosityLevel ("low" );
68- FairLogger ::GetLogger ()-> SetLogScreenLevel ("info" );
6975
7076 // Init & Special MC Settings
7177 run .Init ();
7278
73- // Database
74- auto rtdb = run .GetRuntimeDb ();
75- auto fieldPar = (R3BFieldPar * )rtdb -> getContainer ("R3BFieldPar" );
76- fieldPar -> SetParameters (magField );
79+ // Save field parameters
80+ auto* fieldPar = dynamic_cast < R3BFieldPar * > (rtdb -> getContainer ("R3BFieldPar" ));
81+ fieldPar -> SetParameters (GladField );
7782 fieldPar -> setChanged ();
78- auto parOut = new FairParRootFileIo (true );
79- parOut -> open ("testR3BPhaseSpaceGeneratorIntegration.para.root" );
80- rtdb -> setOutput (parOut );
83+
84+ // Output file with parameters
85+ auto parOut = std ::make_unique < FairParRootFileIo > (true);
86+ parOut -> open (parafile .Data ());
87+ rtdb -> setOutput (parOut .release ());
8188 rtdb -> saveOutput ();
8289 rtdb -> print ();
8390
84- // Go
85- run .Run (10 );
91+ // Simulate
92+ run .Run (nbevents );
8693
87- // Test Output
88- auto file = TFile ::Open ("testR3BPhaseSpaceGeneratorIntegration .root" );
94+ // Report
95+ auto file = TFile ::Open ("PhaseSpace.simu .root" );
8996 auto tree = (TTree * )file -> Get ("evt" );
9097 auto mctc = new TClonesArray ("R3BMCTrack" );
9198 tree -> SetBranchAddress ("MCTrack" , & mctc );
@@ -97,14 +104,14 @@ void testR3BPhaseSpaceGeneratorIntegration()
97104 return ;
98105 }
99106
100- auto track = ( R3BMCTrack * ) mctc -> At (1 );
107+ auto track = dynamic_cast < R3BMCTrack * > ( mctc -> At (1 ) );
101108 if (track -> GetPdgCode () != 2112 || track -> GetMotherId () != -1 )
102109 {
103110 std ::cout << "Not the correct primary particle" << std ::endl ;
104111 return ;
105112 }
106113
107- const Double_t ekin = track -> GetEnergy () - track -> GetMass ();
114+ const auto ekin = track -> GetEnergy () - track -> GetMass ();
108115 std ::cout << "Ekin of primary neutron:" << ekin << std ::endl ;
109116 if (abs (ekin - 0.6 ) > 0.02 )
110117 {
@@ -116,4 +123,5 @@ void testR3BPhaseSpaceGeneratorIntegration()
116123 timer .Stop ();
117124 std ::cout << "Real time: " << timer .RealTime () << "s, CPU time: " << timer .CpuTime () << "s" << std ::endl ;
118125 std ::cout << "Macro finished successfully." << std ::endl ;
126+ gApplication -> Terminate ();
119127}
0 commit comments