Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #ifndef MACRO_FUN4ALLG4WRITEDST_C
0002 #define MACRO_FUN4ALLG4WRITEDST_C
0003 
0004 #include <g4exampledetector01/G4Example01Subsystem.h>
0005 
0006 #include <g4detectors/PHG4DetectorSubsystem.h>
0007 
0008 #include <g4main/PHG4ParticleGenerator.h>
0009 #include <g4main/PHG4ParticleGeneratorBase.h>
0010 #include <g4main/PHG4ParticleGun.h>
0011 #include <g4main/PHG4Reco.h>
0012 #include <g4main/PHG4SimpleEventGenerator.h>
0013 
0014 #include <fun4all/Fun4AllDstOutputManager.h>
0015 #include <fun4all/Fun4AllDummyInputManager.h>
0016 #include <fun4all/Fun4AllInputManager.h>
0017 #include <fun4all/Fun4AllOutputManager.h>
0018 #include <fun4all/Fun4AllServer.h>
0019 #include <fun4all/SubsysReco.h>
0020 
0021 #include <phool/recoConsts.h>
0022 
0023 R__LOAD_LIBRARY(libfun4all.so)
0024 R__LOAD_LIBRARY(libg4detectors.so)
0025 R__LOAD_LIBRARY(libg4example01detector.so)
0026 
0027 void Fun4All_G4_Write_Dst(int nEvents = 1)
0028 {
0029   ///////////////////////////////////////////
0030   // Make the Server
0031   //////////////////////////////////////////
0032   Fun4AllServer *se = Fun4AllServer::instance();
0033   recoConsts *rc = recoConsts::instance();
0034   // if you want to fix the random seed to reproduce results
0035   // set this flag
0036   // rc->set_IntFlag("RANDOMSEED",12345);
0037 
0038   //
0039   // Particle Generator
0040   //
0041 
0042   // the PHG4ParticleGenerator makes cones using phi and eta
0043   PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
0044   gen->set_name("geantino");
0045   gen->set_vtx(0, 3, 0);
0046   gen->set_eta_range(-0.9, 0.9);
0047   gen->set_mom_range(1.0, 10.0);
0048   gen->set_z_range(0., 0.);
0049   gen->set_phi_range(0. * TMath::Pi(), 2. * TMath::Pi());
0050   se->registerSubsystem(gen);
0051 
0052   PHG4ParticleGun *gun = new PHG4ParticleGun();
0053   gun->set_name("pi-");
0054   //gun->set_name("geantino");
0055   //gun->set_name("proton");
0056   gun->set_vtx(0, -5, -20);  // shoots right into the original Examle01 volume
0057   gun->set_mom(0, 0, 1);
0058   //  se->registerSubsystem(gun);
0059 
0060   //
0061   // Geant4 setup
0062   //
0063   PHG4Reco *g4Reco = new PHG4Reco();
0064   g4Reco->set_field(0);  // no field
0065   g4Reco->save_DST_geometry(false);
0066   // try non default physics lists
0067   //g4Reco->SetPhysicsList("FTFP_BERT_HP");
0068 
0069   G4Example01Subsystem *example01 = new G4Example01Subsystem("HoleInBox");
0070   g4Reco->registerSubsystem(example01);
0071 
0072   se->registerSubsystem(g4Reco);
0073 
0074   ///////////////////////////////////////////
0075   // IOManagers...
0076   ///////////////////////////////////////////
0077 
0078   Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "G4Example01.root");
0079   out->Verbosity(10);
0080   se->registerOutputManager(out);
0081 
0082   // this (dummy) input manager just drives the event loop
0083   Fun4AllInputManager *in = new Fun4AllDummyInputManager("Dummy");
0084   se->registerInputManager(in);
0085   // events = 0 => run forever
0086   if (nEvents <= 0)
0087   {
0088     return 0;
0089   }
0090   se->run(nEvents);
0091   example01->Print();
0092   se->End();
0093   std::cout << "All done" << std::endl;
0094   delete se;
0095   gSystem->Exit(0);
0096 }
0097 
0098 #endif