Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:18:53

0001 #ifndef MACRO_FUN4ALLG4GEANTINO_C
0002 #define MACRO_FUN4ALLG4GEANTINO_C
0003 
0004 #include <g4exampledetector01/G4Example01Subsystem.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(libg4example01detector.so)
0028 R__LOAD_LIBRARY(libg4histos.so)
0029 
0030 void Fun4All_G4_Geantino(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   // rc->set_IntFlag("RANDOMSEED",12345);
0040 
0041   //
0042   // Particle Generator
0043   //
0044 
0045   // the PHG4ParticleGenerator makes cones using phi and eta
0046   PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
0047   gen->set_name("geantino");
0048   gen->set_vtx(0, 3, 0);
0049   gen->set_eta_range(-0.9, 0.9);
0050   gen->set_mom_range(1.0, 1.0);
0051   gen->set_z_range(0., 0.);
0052   gen->set_phi_range(0. * TMath::Pi(), 2. * TMath::Pi());
0053   se->registerSubsystem(gen);
0054 
0055   PHG4ParticleGun *gun = new PHG4ParticleGun();
0056   gun->set_name("pi-");
0057   //gun->set_name("geantino");
0058   //gun->set_name("proton");
0059   gun->set_vtx(0, -5, -20);  // shoots right into the original Examle01 volume
0060   gun->set_mom(0, 0, 1);
0061   //  se->registerSubsystem(gun);
0062 
0063   //
0064   // Geant4 setup
0065   //
0066   PHG4Reco *g4Reco = new PHG4Reco();
0067   g4Reco->set_field(0);  // no field
0068   g4Reco->save_DST_geometry(false);
0069   // try non default physics lists
0070   //g4Reco->SetPhysicsList("FTFP_BERT_HP");
0071 
0072   G4Example01Subsystem *example01 = new G4Example01Subsystem("HoleInBox");
0073   g4Reco->registerSubsystem(example01);
0074 
0075   se->registerSubsystem(g4Reco);
0076 
0077   ///////////////////////////////////////////
0078   // Fun4All modules
0079   ///////////////////////////////////////////
0080 
0081   G4HitNtuple *hits = new G4HitNtuple("Hits", "HitNtuple.root");
0082   hits->AddNode("HoleInBox", 0);
0083   se->registerSubsystem(hits);
0084 
0085   ///////////////////////////////////////////
0086   // IOManagers...
0087   ///////////////////////////////////////////
0088 
0089   // Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT","G4Example01.root");
0090   // out->Verbosity(10);
0091   // se->registerOutputManager(out);
0092 
0093   // this (dummy) input manager just drives the event loop
0094   Fun4AllInputManager *in = new Fun4AllDummyInputManager("Dummy");
0095   se->registerInputManager(in);
0096   // events = 0 => run forever
0097   if (nEvents <= 0)
0098   {
0099     return 0;
0100   }
0101   se->run(nEvents);
0102   example01->Print();
0103   se->End();
0104   std::cout << "All done" << std::endl;
0105   delete se;
0106   gSystem->Exit(0);
0107 }
0108 
0109 #endif