Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:20

0001 #ifndef MACRO_FUN4ALLG4EXAMPLE02_C
0002 #define MACRO_FUN4ALLG4EXAMPLE02_C
0003 
0004 #include <g4exampledetector02/G4Example02Subsystem.h>
0005 
0006 #include <g4detectors/PHG4DetectorSubsystem.h>
0007 
0008 #include <g4histos/G4HitNtuple.h>
0009 
0010 #include <g4main/PHG4ParticleGenerator.h>
0011 #include <g4main/PHG4ParticleGeneratorBase.h>
0012 #include <g4main/PHG4ParticleGun.h>
0013 #include <g4main/PHG4Reco.h>
0014 #include <g4main/PHG4SimpleEventGenerator.h>
0015 
0016 #include <fun4all/Fun4AllDstOutputManager.h>
0017 #include <fun4all/Fun4AllDummyInputManager.h>
0018 #include <fun4all/Fun4AllInputManager.h>
0019 #include <fun4all/Fun4AllOutputManager.h>
0020 #include <fun4all/Fun4AllServer.h>
0021 #include <fun4all/SubsysReco.h>
0022 
0023 #include <phool/recoConsts.h>
0024 
0025 R__LOAD_LIBRARY(libfun4all.so)
0026 R__LOAD_LIBRARY(libg4detectors.so)
0027 R__LOAD_LIBRARY(libg4example02detector.so)
0028 R__LOAD_LIBRARY(libg4histos.so)
0029 
0030 void Fun4All_G4_Example02(int nEvents = 1)
0031 {
0032   ///////////////////////////////////////////
0033   // Make the Server
0034   //////////////////////////////////////////
0035   Fun4AllServer *se = Fun4AllServer::instance();
0036   recoConsts *rc = recoConsts::instance();
0037   // if you want to fix the random seed to reproduce results
0038   // set this flag
0039   // nail this down so I know what the first event looks like...
0040   rc->set_IntFlag("RANDOMSEED", 12345);
0041 
0042   //
0043   // Particle Generator
0044   //
0045 
0046   // the PHG4ParticleGenerator makes cones using phi and eta
0047   // PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
0048   // gen->set_name("e-");
0049   // gen->set_vtx(0, 0, 0);
0050   // gen->set_eta_range(-0.9, 0.9);
0051   // gen->set_mom_range(1.0, 10.0);
0052   // gen->set_z_range(0.,0.);
0053   //   gen->set_phi_range(-5/180.*TMath::Pi(), 5/180.*TMath::Pi());
0054   //             se->registerSubsystem(gen);
0055 
0056   PHG4ParticleGun *gun = new PHG4ParticleGun();
0057   gun->set_name("pi-");
0058   //gun->set_name("geantino");
0059   //gun->set_name("proton");
0060   gun->set_vtx(0, -5, -20);  // shoots right into the original Example02 volume
0061   gun->set_mom(0, 0, 1);
0062   se->registerSubsystem(gun);
0063 
0064   //
0065   // Geant4 setup
0066   //
0067   PHG4Reco *g4Reco = new PHG4Reco();
0068   g4Reco->set_field(0);  // no field
0069   g4Reco->save_DST_geometry(false);
0070   // try non default physics lists
0071   //g4Reco->SetPhysicsList("FTFP_BERT_HP");
0072 
0073   G4Example02Subsystem *example02 = new G4Example02Subsystem("HoleInBox");
0074   example02->SetActive();
0075   g4Reco->registerSubsystem(example02);
0076 
0077   example02 = new G4Example02Subsystem("AnotherHoleInBox");
0078   example02->set_double_param("place_x", 40.);
0079   example02->set_double_param("place_y", 40.);
0080   example02->set_double_param("rot_x", 45.);
0081   example02->set_string_param("material", "G4_Fe");
0082   example02->SetActive();
0083   g4Reco->registerSubsystem(example02);
0084 
0085   example02 = new G4Example02Subsystem("YetAnotherHoleInBox");
0086   example02->set_double_param("place_x", -40.);
0087   example02->set_double_param("place_z", 40.);
0088   example02->set_double_param("rot_y", 45.);
0089   example02->set_double_param("rot_z", 45.);
0090   example02->set_string_param("material", "G4_Cu");
0091   example02->SetActive();
0092   g4Reco->registerSubsystem(example02);
0093 
0094   // This is our Black Hole - absorbs every particle
0095   example02 = new G4Example02Subsystem("BewareOfTheBlackHole");
0096   example02->set_double_param("place_z", 40.);
0097   example02->set_double_param("rot_y", 45.);
0098   example02->set_double_param("rot_z", 45.);
0099   example02->BlackHole();
0100   example02->SetActive();
0101   g4Reco->registerSubsystem(example02);
0102 
0103   // this is an inactive volume (no hits will be created)
0104   example02 = new G4Example02Subsystem("InActiveHoleInBox");
0105   example02->set_double_param("place_z", -40.);
0106   example02->set_double_param("rot_y", 45.);
0107   example02->set_double_param("rot_z", 45.);
0108   example02->set_string_param("material", "G4_W");
0109   g4Reco->registerSubsystem(example02);
0110 
0111   se->registerSubsystem(g4Reco);
0112 
0113   ///////////////////////////////////////////
0114   // Fun4All modules
0115   ///////////////////////////////////////////
0116 
0117   G4HitNtuple *hits = new G4HitNtuple("Hits");
0118   hits->AddNode("HoleInBox", 0);
0119   se->registerSubsystem(hits);
0120 
0121   ///////////////////////////////////////////
0122   // IOManagers...
0123   ///////////////////////////////////////////
0124 
0125   // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example02.root");
0126   // out->Verbosity(10);
0127   // se->registerOutputManager(out);
0128 
0129   // this (dummy) input manager just drives the event loop
0130   Fun4AllInputManager *in = new Fun4AllDummyInputManager("Dummy");
0131   se->registerInputManager(in);
0132   // events = 0 => run forever
0133   if (nEvents <= 0)
0134   {
0135     return 0;
0136   }
0137   se->run(nEvents);
0138   example02->Print();
0139   se->End();
0140   std::cout << "All done" << std::endl;
0141   delete se;
0142   gSystem->Exit(0);
0143 }
0144 
0145 #endif