File indexing completed on 2025-08-03 08:18:53
0001 #ifndef MACRO_FUN4ALLG4MYDETECTOR_C
0002 #define MACRO_FUN4ALLG4MYDETECTOR_C
0003
0004 #include <mydetector/MyDetectorSubsystem.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(libMyDetector.so)
0028 R__LOAD_LIBRARY(libg4histos.so)
0029
0030
0031 void Fun4All_G4_MyDetector(int nEvents = 10000)
0032 {
0033
0034
0035
0036 Fun4AllServer *se = Fun4AllServer::instance();
0037 recoConsts *rc = recoConsts::instance();
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 PHG4ParticleGenerator *gen = new PHG4ParticleGenerator();
0049 gen->set_name("geantino");
0050 gen->set_mom_range(1.0, 1.0);
0051 gen->set_z_range(0., 0.);
0052
0053 gen->set_vtx(-50, 0, 0);
0054 gen->set_phi_range(-14.5 / 180 * TMath::Pi(), 14.5 / 180 * TMath::Pi());
0055 gen->set_eta_range(-0.26, 0.26);
0056 se->registerSubsystem(gen);
0057
0058
0059 PHG4ParticleGun *gun = new PHG4ParticleGun();
0060
0061 gun->set_name("geantino");
0062 gun->set_vtx(0, 0, -20);
0063 gun->set_mom(0, 0, 1);
0064
0065
0066
0067
0068
0069 PHG4Reco *g4Reco = new PHG4Reco();
0070
0071
0072
0073
0074 g4Reco->set_field(0);
0075 g4Reco->save_DST_geometry(false);
0076
0077 MyDetectorSubsystem *mydet = new MyDetectorSubsystem("MyDetector1");
0078 mydet->SetActive();
0079 g4Reco->registerSubsystem(mydet);
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 se->registerSubsystem(g4Reco);
0090
0091
0092
0093
0094
0095 G4HitNtuple *hits = new G4HitNtuple("Hits");
0096 hits->AddNode("MyDetector1_0", 0);
0097 se->registerSubsystem(hits);
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 Fun4AllInputManager *in = new Fun4AllDummyInputManager("Dummy");
0109 se->registerInputManager(in);
0110
0111 if (nEvents <= 0)
0112 {
0113 return 0;
0114 }
0115 se->run(nEvents);
0116 cout << "Print out Detector parameters" << endl;
0117 mydet->Print();
0118 se->End();
0119 delete se;
0120 cout << endl
0121 << endl;
0122 cout << "Now open the ntuple file with " << endl;
0123 cout << " root.exe G4HitNtuple.root" << endl;
0124 cout << "and draw the 3d hit distribution," << endl;
0125 cout << "exit hits in black, entry hits in red:" << endl;
0126 cout << " hitntup->Draw(\"x1:y1:z1\")" << endl;
0127 cout << " hitntup->SetMarkerColor(2)" << endl;
0128 cout << " hitntup->Draw(\"x0:y0:z0\",\"\",\"same\")" << endl;
0129 cout << endl;
0130 gSystem->Exit(0);
0131 }
0132
0133 #endif