EDepSimNuMIRockKinematicsGenerator.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////
2 // $Id: EDepSim::NuMIRockKinematicsGenerator.cc,v 1.3 2013/01/17 14:12:03 mcgrew Exp $
3 //
4 
5 
6 #include "EDepSimVertexInfo.hh"
8 #include "EDepSimException.hh"
10 
11 #include "EDepSimLog.hh"
12 
13 #include <globals.hh>
14 #include <G4Event.hh>
15 #include <G4PrimaryVertex.hh>
16 #include <G4PrimaryParticle.hh>
17 #include <G4ParticleTable.hh>
18 #include <G4ParticleDefinition.hh>
19 #include <G4Tokenizer.hh>
20 #include <G4UnitsTable.hh>
21 #include <Randomize.hh>
22 
24  const G4String& name, const G4String& fluxName)
25  : EDepSim::VKinematicsGenerator(name), fFluxName(fluxName) { }
26 
28 
31  G4Event* anEvent,
32  const G4LorentzVector&) {
33 
34  // Make a position vertex...
35  double boxSize = 300*cm;
36  G4LorentzVector eventVertex;
37  for (int i=0; i<3; ++i) {
38  eventVertex[i] = 2*boxSize*G4UniformRand() - boxSize;
39  }
40  eventVertex[0] = -3.0*meter;
41  eventVertex[2] -= 0.5*meter;
42  eventVertex[3] = 10.0*microsecond*G4UniformRand();
43 
44  // Create a new vertex to add the new particles, and add the vertex to the
45  // event.
46  G4PrimaryVertex* theVertex
47  = new G4PrimaryVertex(G4ThreeVector(eventVertex.x(),
48  eventVertex.y(),
49  eventVertex.z()),
50  eventVertex.t());
51  anEvent->AddPrimaryVertex(theVertex);
52 
53  // Fill the particles to be tracked (status ==1). These particles are
54  // attached to the primary vertex. Also save the incident neutrino
55  // particle and the incident target nucleus; these particles are attached
56  // to informational vertex.
57  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
58  G4ParticleDefinition* particleDef = particleTable->FindParticle("mu-");
59 
60  // Get the momentum.
61  double momentum;;
62  do {
63  momentum = G4RandGauss::shoot(4.0*GeV,2*GeV);
64  } while (momentum<2*GeV);
65  momentum *= G4UniformRand();
66 
67  G4ThreeVector dir(1.0,
68  G4RandGauss::shoot(0.0,0.15),
69  G4RandGauss::shoot(0.0,0.15));
70  dir = dir.unit();
71 
72  std::cout << "Add rock muon at "
73  << " " << eventVertex.x()
74  << " " << eventVertex.y()
75  << " " << eventVertex.z()
76  << " " << eventVertex.t()
77  << " going " << dir.x()
78  << " " << dir.y()
79  << " " << dir.z()
80  << std::endl;
81 
82  // Create the particle.
83  G4PrimaryParticle* theParticle
84  = new G4PrimaryParticle(particleDef,
85  momentum*dir.x(),
86  momentum*dir.y(),
87  momentum*dir.z());
88  theVertex->SetPrimary(theParticle);
89 
90  return kSuccess;
91 }
92 
static constexpr double cm
Definition: Units.h:68
static QCString name
Definition: declinfo.cpp:673
virtual GeneratorStatus GeneratePrimaryVertex(G4Event *evt, const G4LorentzVector &position)
Add a primary vertex to the event.
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
string dir
GeneratorStatus
A status value that can be returned by GeneratePrimaryVertex.
Construct a module from components.
Definition: TG4HitSegment.h:10
static constexpr double GeV
Definition: Units.h:28
A vertex was successfully generated.
NuMIRockKinematicsGenerator(const G4String &name, const G4String &fluxName)
meter_as<> meter
Type of space stored in meters, in double precision.
Definition: spacetime.h:400
def momentum(x1, x2, x3, scale=1.)
QTextStream & endl(QTextStream &s)