// **************************************************************************** // // Author: Mihaly Novak // Date : 12 May 2022 // ------------------- // // Description: // ------------ // // The main of our application at the state where we stopped at the end of day3 // I added comments that explain some of the details. This is the state where // we start developing further our application at the beginning of day4: // - first we will add User Interaction possibilities // - then we will extend our application with (optinal) user actions // that will make possible to collect some infomation during teh simualtion // // **************************************************************************** // for some Geant4 types and io #include "globals.hh" // to obtain a run manager, the top level manager // - where we need to register our detector, physics // and action objects after their construction // - that controls the complete flow of initialisation // and simulation #include "G4RunManagerFactory.hh" // for our detector implementation (mandatory) #include "YourDetectorConstruction.hh" // for our action implementation (mandatory) // this includes our primary generator action #include "YourActionInitialization.hh" // for the physics list (mandatory) // (we use a reference physics list to keep is simple) #include "G4PhysListFactory.hh" // to able to use units e.g. CLHEP::cm #include "G4SystemOfUnits.hh" // only to set the tracking verbose to see that simulation happens // (see more on day4) #include "G4UImanager.hh" int main() { // ============================================================================== // Create the run manager then construct all mandatory user initializations and // register them in the run manager // ============================================================================== // Construct the run manager auto* runMgr = G4RunManagerFactory::CreateRunManager(); // Construct our detector description object and register in the run manager YourDetectorConstruction* det = new YourDetectorConstruction(); runMgr->SetUserInitialization( det ); // Construct a (reference: "FTFP_BERT") physics list and register in the run manager const G4String plName = "FTFP_BERT"; G4PhysListFactory plFactory; G4VModularPhysicsList* pl= plFactory.GetReferencePhysList(plName); runMgr->SetUserInitialization( pl ); // Construct our action initialization and register in the run manager // ------------------------------------------------------------------------------ // NOTE: it's action INITIALIZATION since it encapsulates the construction and // registration of ALL user ACTIONS (at least the primary generator action) YourActionInitialization* action = new YourActionInitialization(det); runMgr->SetUserInitialization( action ); // ============================================================================== // The bare minimum setup is ready at this point, the simulation can be // initialized and executed now // ============================================================================== // Ask the run manager to initialize the simulation // ------------------------------------------------------------------------------ // NOTE: a chain of action will be done/triggered at this point by the run // manager calling some interace methods. First the Constrcut() interface // method of our registerred detetctor construction as part of the // geometry initialization. Then the physics initialization is triggered // by the run manager invoking the physics list ConstrcutParticles() and // ConstructProcesses() interafec methods (many more happens inside all). // // NOTE: // - the interface methods that we have implemented are not necessarily // invoked at the construction of the given object but later at this // initialisation of only during the run // - the complete initialization chain is invoked by the run maneger // before the very first run of an execution which is not necessarily // the case for subsequent runs // - what is exactly re-constructed/re-initialised and how, might be // controlled by G4RunManager: // + PhysicsHasBeenModified() --> re-initialize physics // + GeometryHasBeenModified() --> re-compute some geometry optimisations // (! the geometry is not re-constrcuted !) // + ReinitializeGeometry() --> re-initialize geometry by re-calling // the Construct() interface method of the // detector construction // ------------------------------------------------------------------------------ runMgr->Initialize(); // NOTE: this is just to see that simulation actually indeed happens since we // could not see anything otherwise as long as we don't implement further, // optional user actions. Those will make possible to interact with the // simulation during the process at each level and collect information // (see form day4). G4UImanager::GetUIpointer()->ApplyCommand("/tracking/verbose 1"); // After the initialisation is done, we can ask the run manager to simulate // a given number of event (1 event this case) runMgr->BeamOn(1); // When the very first run is completed, we might change the target thickness // ------------------------------------------------------------------------------ // We can investigate: // - if our `soft` solution, implemented in the detector construction to handle // the possible change of the target thickness/material works fine (yes) // - we can see that we need to update by hand the gun-position! We do this // now (temporarily) inside our `YourPrimaryGenerator::GeneratePrimaries()` // interafec method. Please see the related comments there. // // - we might deactivate the `soft` solution related code in our detector // constrcution and try to see what happens (target is not resized then) // - try to call again runMgr->Initialize() and see if it helps (NO, it // doesn't see above at runMgr->Initialize() why!) // - we can try runMgr->GeometryHasBeenModified() and see if it helps (NO, // doesn't and see above at runMgr->Initialize() why!) // - we can try then runMgr->ReinitializeGeometry() that will work well! // (also possible with UI command e.g. "/run/reinitializeGeometry" // ------------------------------------------------------------------------------ // // Chnage the target thickness (from the default 1 cm) to 10 cm now det->SetTargetThickness(10*CLHEP::cm); // Simulate 1 event again and inspect the output (thanks to tracking verbose 1) runMgr->BeamOn(1); // Delete the run manager at the end of the run delete runMgr; return 0; }