File indexing completed on 2025-08-03 08:22:08
0001 #pragma once
0002 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
0003 #include <fun4all/SubsysReco.h>
0004 #include <fun4all/Fun4AllServer.h>
0005 #include <fun4all/Fun4AllInputManager.h>
0006 #include <fun4all/Fun4AllDstOutputManager.h>
0007 #include <fun4all/Fun4AllOutputManager.h>
0008 #include <fun4all/Fun4AllDummyInputManager.h>
0009 #include <g4detectors/PHG4BlockSubsystem.h>
0010 #include <g4eval/PHG4DSTReader.h>
0011 #include <g4main/PHG4ParticleGun.h>
0012 #include <g4main/PHG4Reco.h>
0013 #include <g4main/PHG4TruthSubsystem.h>
0014 #include <phool/recoConsts.h>
0015 R__LOAD_LIBRARY(libg4eval.so)
0016 R__LOAD_LIBRARY(libfun4all.so)
0017 R__LOAD_LIBRARY(libg4testbench.so)
0018 R__LOAD_LIBRARY(libg4detectors.so)
0019 #endif
0020
0021 int Fun4All_G4_block(const int nEvents = 10, const char *outfile=NULL)
0022 {
0023
0024 gSystem->Load("libfun4all");
0025 gSystem->Load("libg4detectors");
0026 gSystem->Load("libg4testbench");
0027 gSystem->Load("libg4eval");
0028 gSystem->Load("libg4histos");
0029
0030
0031
0032
0033 Fun4AllServer *se = Fun4AllServer::instance();
0034
0035
0036 recoConsts *rc = recoConsts::instance();
0037
0038
0039
0040
0041 PHG4ParticleGun *gun = new PHG4ParticleGun("PGUN");
0042
0043 gun->set_name("pi-");
0044
0045 gun->set_vtx(0,0,0);
0046 gun->set_mom(0,0,1);
0047 se->registerSubsystem(gun);
0048
0049
0050 PHG4Reco* g4Reco = new PHG4Reco();
0051
0052 g4Reco->set_field(0);
0053
0054 g4Reco->SetWorldSizeX(500);
0055 g4Reco->SetWorldSizeY(500);
0056 g4Reco->SetWorldSizeZ(2000);
0057
0058 g4Reco->SetWorldShape("G4BOX");
0059
0060 g4Reco->SetWorldMaterial("G4_AIR");
0061
0062 g4Reco->SetPhysicsList("QGSP_BERT");
0063
0064
0065 double xsize = 200.;
0066 double ysize = 200.;
0067 double zsize = 400.;
0068 PHG4BlockSubsystem *box = new PHG4BlockSubsystem("box");
0069 box->set_double_param("size_x",xsize);
0070 box->set_double_param("size_y",ysize);
0071 box->set_double_param("size_z",zsize);
0072 box->set_double_param("place_z",zsize/2.+100);
0073 box->set_string_param("material","G4_POLYSTYRENE");
0074 box->SetActive();
0075 g4Reco->registerSubsystem(box);
0076
0077 PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
0078 g4Reco->registerSubsystem(truth);
0079
0080 se->registerSubsystem( g4Reco );
0081
0082
0083
0084
0085
0086 if (outfile)
0087 {
0088 Fun4AllOutputManager *out = new Fun4AllDstOutputManager("DSTOUT",outfile);
0089 se->registerOutputManager(out);
0090
0091 }
0092 if (outfile)
0093 {
0094
0095 PHG4DSTReader* ana = new PHG4DSTReader(
0096 string(outfile) + string("_DSTReader.root"));
0097 ana->set_save_particle(true);
0098 ana->set_load_all_particle(false);
0099 ana->set_load_active_particle(true);
0100 ana->set_save_vertex(true);
0101 if (nEvents > 0 && nEvents < 2)
0102 {
0103 ana->Verbosity(2);
0104 }
0105 ana->AddNode("box_0");
0106 se->registerSubsystem(ana);
0107 }
0108
0109
0110 Fun4AllInputManager *in = new Fun4AllDummyInputManager( "JADE");
0111 se->registerInputManager( in );
0112
0113
0114
0115
0116 if (nEvents > 0)
0117 {
0118 se->run(nEvents);
0119
0120 se->End();
0121 std::cout << "All done" << std::endl;
0122
0123
0124 delete se;
0125 gSystem->Exit(0);
0126 }
0127 return 0;
0128
0129 }
0130
0131 PHG4ParticleGun *get_gun(const char *name="PGUN")
0132 {
0133 Fun4AllServer *se = Fun4AllServer::instance();
0134 PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
0135 return pgun;
0136 }
0137