Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4Sim.C
Go to the documentation of this file.
1 
2 #include <iostream>
3 
4 using namespace std;
5 
6 int Fun4Sim(const int nEvents = 1)
7 {
8  const int use_g4steps = 1;
9  const double target_l = 7.9; //cm
10  const double target_z = (7.9-target_l)/2.; //cm
11 
12  const bool gen_gun = false;
13  const bool gen_pythia8 = false;
14  const bool gen_test = true;
15 
16  gSystem->Load("libfun4all");
17  gSystem->Load("libg4detectors");
18  gSystem->Load("libg4testbench");
19  gSystem->Load("libg4eval");
20  gSystem->Load("libtruth_eval.so");
21 
23  // Make the Server
26  se->Verbosity(100);
27 
28  // particle gun
29  if(gen_gun) {
30  PHG4ParticleGun *gun_beam = new PHG4ParticleGun("GUN_beam");
31  gun_beam->set_name("proton");//proton
32  gun_beam->set_vtx(0, 0, -400); //-363.32 cm
33  gun_beam->set_mom(0, 0, 120);
34  TF2 *beam_profile = new TF2("beam_profile",
35  //"(((x**2+y**2)<=0.81)*exp(-(x**2+y**2)/0.18))+(((x**2+y**2)>0.81&&(x**2+y**2)<=25&&abs(y)<1.)*0.9*exp(-4.5)/(sqrt(x**2+y**2)))",
36  "(((x**2+y**2)<=0.81)*exp(-(x**2+y**2)/0.18))+(((x**2+y**2)>0.81&&(x**2+y**2)<=25)*0.9*exp(-4.5)/(sqrt(x**2+y**2)))",
37  -5,5,-5,5);
38  //gun_beam->set_beam_profile(beam_profile);
39  //se->registerSubsystem(gun_beam);
40  }
41 
42  if(gen_pythia8) {
43  gSystem->Load("libPHPythia8.so");
44 
45  PHPythia8 *pythia8 = new PHPythia8();
46  pythia8->set_config_file("phpythia8.cfg");
47  pythia8->set_vertex_distribution_mean(0, 0, -130, 0);
48  se->registerSubsystem(pythia8);
49 
51  trigger->AddParticles("13,-13");
52  pythia8->register_trigger(trigger);
53 
54  HepMCNodeReader *hr = new HepMCNodeReader();
55  se->registerSubsystem(hr);
56  }
57 
58  if(gen_test) {
59  double mass = 7;
60  double cot = 7.4;
61  PHG4ParticleGun *gun_mup = new PHG4ParticleGun("GUN_mup");
62  gun_mup->set_name("mu+");
63  gun_mup->set_vtx(0, 0, -130);
64  gun_mup->set_mom(mass/2., 0, mass/2.*cot);
65  //gun_mup->set_vtx(0, 0, 500);
66  //gun_mup->set_mom(0, 0, 2);
67  se->registerSubsystem(gun_mup);
68 
69  PHG4ParticleGun *gun_mum = new PHG4ParticleGun("GUN_mum");
70  gun_mum->set_name("mu-");
71  gun_mum->set_vtx(0, 0, -130);
72  gun_mum->set_mom(mass/-2., 0, mass/2.*cot);
73  //se->registerSubsystem(gun_mum);
74  }
75 
76  // Fun4All G4 module
77  PHG4Reco *g4Reco = new PHG4Reco();
78  //g4Reco->G4Seed(123);
79  //g4Reco->set_field(5.);
80  g4Reco->set_field_map(
81  "/e906/app/users/liuk/seaquest/seaquest/geometry/magnetic_fields/tab.Fmag "
82  "/e906/app/users/liuk/seaquest/seaquest/geometry/magnetic_fields/tab.Kmag",
83  4);
84  // size of the world - every detector has to fit in here
85  g4Reco->SetWorldSizeX(1000);
86  g4Reco->SetWorldSizeY(1000);
87  g4Reco->SetWorldSizeZ(5000);
88  // shape of our world - it is a tube
89  g4Reco->SetWorldShape("G4BOX");
90  // this is what our world is filled with
91  g4Reco->SetWorldMaterial("G4_Galactic");
92  // Geant4 Physics list to use
93  g4Reco->SetPhysicsList("FTFP_BERT");
94 
95 
96  PHG4E1039InsensSubsystem* insens = new PHG4E1039InsensSubsystem("Insens");
97  g4Reco->registerSubsystem(insens);
98 
99  gROOT->LoadMacro("G4_Target.C");
100  SetupTarget(g4Reco, use_g4steps, target_l, target_z);
101 
102  gROOT->LoadMacro("G4_DriftChamber.C");
103  SetupDriftChamber(g4Reco);
104 
105  PHG4TruthSubsystem *truth = new PHG4TruthSubsystem();
106  g4Reco->registerSubsystem(truth);
107 
108  se->registerSubsystem(g4Reco);
109 
110  DPDigitizer *digitizer = new DPDigitizer();
111  digitizer->Verbosity(100);
112  se->registerSubsystem(digitizer);
113 
115  // Output
117 
118  // save a comprehensive evaluation file
120  string("DSTReader.root"));
121  ana->set_save_particle(true);
122  ana->set_load_all_particle(false);
123  ana->set_load_active_particle(true);
124  ana->set_save_vertex(true);
125  ana->AddNode("Coil");
126  ana->AddNode("Target");
127  ana->AddNode("C1X");
128  ana->AddNode("C2X");
129  se->registerSubsystem(ana);
130 
131  // input - we need a dummy to drive the event loop
133  se->registerInputManager(in);
134 
135  Fun4AllDstOutputManager *out = new Fun4AllDstOutputManager("DSTOUT", "DST.root");
136  se->registerOutputManager(out);
137 
138  // a quick evaluator to inspect on hit/particle/tower level
139 
140  if (nEvents > 0)
141  {
142  se->run(nEvents);
143 
144  PHGeomUtility::ExportGeomtry(se->topNode(),"geom.root");
145 
146  // finish job - close and save output files
147  se->End();
148  std::cout << "All done" << std::endl;
149 
150  // cleanup - delete the server and exit
151  delete se;
152  gSystem->Exit(0);
153  }
154  return;
155 }
156 
157 PHG4ParticleGun *get_gun(const char *name = "PGUN")
158 {
160  PHG4ParticleGun *pgun = (PHG4ParticleGun *) se->getSubsysReco(name);
161  return pgun;
162 }
int registerInputManager(Fun4AllInputManager *InManager)
virtual int End()
Runs G4 as a subsystem.
Definition: PHG4Reco.h:38
void set_load_all_particle(bool b)
Definition: PHG4DSTReader.h:73
void AddParticles(std::string particles)
PHG4DSTReader save information from DST to an evaluator, which could include hit. particle...
Definition: PHG4DSTReader.h:39
void SetWorldMaterial(const std::string &s)
Definition: PHG4Reco.h:118
SQDigitizer DPDigitizer
void SetWorldShape(const std::string &s)
Definition: PHG4Reco.h:117
static Fun4AllServer * instance()
Fun4AllServer * se
static void ExportGeomtry(PHCompositeNode *topNode, const std::string &geometry_file)
DST node -&gt; TGeoManager -&gt; export files, like gdml, .root or .C formats.
int registerSubsystem(SubsysReco *subsystem, const std::string &topnodename="TOP")
void set_config_file(const char *cfg_file)
Definition: PHPythia8.h:46
int run(const int nevnts=0, const bool require_nevents=false)
run n events (0 means up to end of file)
int registerOutputManager(Fun4AllOutputManager *manager)
void set_field_map(const std::string &fmap, const PHFieldConfig::FieldConfigTypes dim)
Definition: PHG4Reco.h:87
void set_vertex_distribution_mean(const double x, const double y, const double z, const double t)
set the mean value of the vertex distribution, use PHENIX units of cm, ns
Definition: PHPythia8.h:86
void set_save_vertex(bool b)
Switch for vertex.
Definition: PHG4DSTReader.h:94
void SetupTarget(PHG4Reco *g4Reco, const double target_coil_pos_z=-300, const double target_l=7.9, const double target_z=0., const int use_g4steps=1, const int register_hits=0)
Definition: G4_Target.C:10
void SetupDriftChamber(PHG4Reco *g4Reco, std::string _server_name="seaquestdb01.fnal.gov", int _port=3310, std::string _user_name="seaguest", std::string _password="qqbar2mu+mu-", std::string _input_shcema="geometry_G17_run3")
void AddNode(const std::string &name)
Definition: PHG4DSTReader.h:59
PHCompositeNode * topNode() const
Definition: Fun4AllServer.h:59
void set_save_particle(bool b)
Switch for saving any particles at all.
Definition: PHG4DSTReader.h:87
void ana()
Definition: ana.C:291
int Fun4Sim(const int nEvents=1)
Definition: Fun4Sim.C:6
void SetWorldSizeX(const double sx)
Definition: PHG4Reco.h:111
void SetPhysicsList(const std::string &s)
Definition: PHG4Reco.h:119
virtual void set_vtx(const double x, const double y, const double z)
SubsysReco * getSubsysReco(const std::string &name)
virtual void Verbosity(const int ival)
Sets the verbosity of this module (0 by default=quiet).
Definition: Fun4AllBase.h:58
void set_load_active_particle(bool b)
load all particle that produced a saved hit
Definition: PHG4DSTReader.h:80
void register_trigger(PHPy8GenTrigger *theTrigger)
set event selection criteria
Definition: PHPythia8.C:303
virtual void set_name(const std::string &particle="proton")
virtual void set_mom(const double x, const double y, const double z)
PHG4ParticleGun * get_gun(const char *name="PGUN")
void registerSubsystem(PHG4Subsystem *subsystem)
register subsystem
Definition: PHG4Reco.h:65
void SetWorldSizeZ(const double sz)
Definition: PHG4Reco.h:113
void SetWorldSizeY(const double sy)
Definition: PHG4Reco.h:112