Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHG4ParticleGun.cc
Go to the documentation of this file.
1 #include "PHG4ParticleGun.h"
2 #include "PHG4Particlev1.h"
3 
4 #include "PHG4InEvent.h"
5 
6 #include <phool/getClass.h>
7 
9 #include <phool/PHIODataNode.h>
10 #include <phool/PHRandomSeed.h>
11 
12 #include <Geant4/G4ParticleTable.hh>
13 #include <Geant4/G4ParticleDefinition.hh>
14 
15 #include <TRandom.h>
16 
17 #include <iostream>
18 //Abi
19 #include <TGeoMaterial.h>
20 #include <phgeom/PHGeomUtility.h>
21 #include <TGeoManager.h>
22 
23 using namespace std;
24 
25 PHG4ParticleGun::PHG4ParticleGun(const string &name):
27  _beam_profile(nullptr)
28  // _legacy_vertexgenerator(nullptr)
29 {
30 // _vertexGen = new SQPrimaryVertexGen();
31 
32  return;
33 }
34 
36 {
37  delete _beam_profile;
38  //delete _vertexGen;
39  return;
40 }
41 
44  gRandom->SetSeed(PHRandomSeed());
45  return 0;
46 }
47 
48 int
50 {
51  double vx = vtx_x, vy = vtx_y;
52  if(_beam_profile) {
53  _beam_profile->GetRandom2(vx, vy);
54  }
55 
56 
57 
58 
59  PHG4InEvent *ineve = findNode::getClass<PHG4InEvent>(topNode,"PHG4INEVENT");
60  ReuseExistingVertex(topNode); // checks if we should reuse existing vertex
61 
62 
63  // cout<<" Here I am in particle gun...."<<endl;
64  //cout << "PHG4ParticleGun: {" << vx << ", " << vy << ", "<<vtx_z<< "}" << endl;
65  int vtxindex = ineve->AddVtx(vx,vy,vtx_z,t0);
66  vector<PHG4Particle *>::const_iterator iter;
67  for (iter = particlelist.begin(); iter != particlelist.end(); ++iter)
68  {
69  PHG4Particle *particle = new PHG4Particlev1(*iter);
70  SetParticleId(particle,ineve);
71  ineve->AddParticle(vtxindex, particle);
72  }
73  if (verbosity > 0)
74  {
75  ineve->identify();
76  }
77  return 0;
78 }
int verbosity
The verbosity level. 0 means not verbose at all.
Definition: Fun4AllBase.h:75
PHG4ParticleGun(const std::string &name="PGUN")
virtual int ReuseExistingVertex(PHCompositeNode *topNode)
int AddParticle(const int vtxid, PHG4Particle *particle)
Definition: PHG4InEvent.cc:63
virtual int InitRun(PHCompositeNode *topNode)
int process_event(PHCompositeNode *topNode)
std::vector< PHG4Particle * > particlelist
virtual int InitRun(PHCompositeNode *topNode)
virtual ~PHG4ParticleGun()
int AddVtx(const double x, const double y, const double z, const double t)
Definition: PHG4InEvent.cc:38
void SetParticleId(PHG4Particle *particle, PHG4InEvent *ineve)
virtual void identify(std::ostream &os=std::cout) const
Definition: PHG4InEvent.cc:134