EDepSimPrimaryGenerator.cc
Go to the documentation of this file.
1 #include <G4UnitsTable.hh>
2 #include <G4Event.hh>
3 #include <G4TransportationManager.hh>
4 #include <G4Navigator.hh>
5 #include <G4ThreeVector.hh>
6 #include <G4VPhysicalVolume.hh>
7 #include <G4LogicalVolume.hh>
8 #include <G4Material.hh>
9 #include <G4VisExtent.hh>
10 #include <G4SystemOfUnits.hh>
11 #include <G4PhysicalConstants.hh>
12 
13 #include <Randomize.hh>
14 
15 #include <EDepSimLog.hh>
16 
17 #include "EDepSimVertexInfo.hh"
23 
28  : fKinematics(kine), fCount(count), fPosition(position), fTime(time) {
29 }
30 
32 
34 
35  int count = fCount->GetCount();
36  int brake = 0;
37  EDepSimVerbose("# Generate " << count << " vertices w/ " << GetName());
38  while (count > 0 && brake<1000) {
39  // Stash the most recent primary vertex. This is saving the last
40  // existing primary vertex before the call to the
41  // EDepSim::VKinematicsGenerator::GeneratePrimaryVertex().
42  G4PrimaryVertex* vtx = evt->GetPrimaryVertex();
43  for (;vtx && vtx->GetNext(); vtx = vtx->GetNext());
44  // Generate a candidate position and time for the event vertex.
45  G4LorentzVector vertex = fPosition->GetPosition();
46  vertex.setT(fTime->GetTime(vertex));
47  // Generate the new kinematics. This will add new primary vertices to
48  // the G4Event.
50  = fKinematics->GeneratePrimaryVertex(evt,vertex);
51  if (generatorStatus == EDepSim::VKinematicsGenerator::kFail) {
52  ++brake; // Apply the brakes
53  continue;
54  }
55  if (generatorStatus == EDepSim::VKinematicsGenerator::kEndEvent) {
56  break;
57  }
58  // If the vertex should be forced, then make sure that it is. This
59  // updates the position and time for all of the vertices that were
60  // added to the event by the previous EDepSim::VKinematicsGenerator
61  // call. Get the first new vertex.
62  if (!vtx) vtx = evt->GetPrimaryVertex();
63  else vtx = vtx->GetNext();
64  // Update the vertex for the new vertices.
65  for (;vtx; vtx = vtx->GetNext()) {
66  // Update the vertex info (and make sure it exists). This sets
67  // the generator name.
68  EDepSim::VertexInfo* vInfo
69  = dynamic_cast<EDepSim::VertexInfo*>(vtx->GetUserInformation());
70  if (!vInfo) {
71  vInfo = new EDepSim::VertexInfo();
72  vtx->SetUserInformation(vInfo);
73  }
74  vInfo->SetName(GetName());
75  if (fPosition->ForcePosition()) {
76  EDepSimVerbose("# Force position to"
77  << " x: " << vertex.x()/cm << " cm"
78  << " y: " << vertex.y()/cm << " cm"
79  << " z: " << vertex.z()/cm << " cm");
80  vtx->SetPosition(vertex.x(), vertex.y(), vertex.z());
81  }
82  if (fTime->ForceTime()) {
83  EDepSimVerbose("# Force time to "
84  << vertex.t()/ns << " ns");
85  vtx->SetT0(vertex.t());
86  }
87  }
88  brake = 0; // Remove the brakes.
89  --count;
90 
91  // Check if the generator flagged that this vertex must end an event.
92  if (generatorStatus == EDepSim::VKinematicsGenerator::kLastVertex) {
93  break;
94  }
95  }
96 }
97 
99  G4String name = fKinematics->GetName();
100  name += ":" + fCount->GetName();
101  name += "@" + fPosition->GetName();
102  name += "-" + fTime->GetName();
103  return name;
104 }
static constexpr double cm
Definition: Units.h:68
static QCString name
Definition: declinfo.cpp:673
virtual int GetCount()=0
virtual bool ForcePosition()=0
GeneratorStatus
A status value that can be returned by GeneratePrimaryVertex.
EDepSim::VTimeGenerator * fTime
G4String GetName() const
Return the name of the generator.
virtual G4LorentzVector GetPosition()=0
Return the candidate position for the primary vertex.
PrimaryGenerator(EDepSim::VKinematicsGenerator *kine, EDepSim::VCountGenerator *count, EDepSim::VPositionGenerator *position, EDepSim::VTimeGenerator *time)
#define EDepSimVerbose(outStream)
Definition: EDepSimLog.hh:787
virtual bool ForceTime()=0
Return true if this time should be forced for the primary vertex.
G4String GetName()
Return the name of this generator.
virtual double GetTime(const G4LorentzVector &vertex)=0
Return the time of the primary vertex.
virtual GeneratorStatus GeneratePrimaryVertex(G4Event *evt, const G4LorentzVector &position)=0
EDepSim::VPositionGenerator * fPosition
The generation failed and should be tried again.
TCEvent evt
Definition: DataStructs.cxx:7
EDepSim::VKinematicsGenerator * fKinematics
virtual void GeneratePrimaryVertex(G4Event *evt)
G4String GetName() const
Return the name of the generator.
EDepSim::VCountGenerator * fCount
QAsciiDict< Entry > ns
G4String GetName() const
Return the name of the generator.
G4String GetName() const
Return the name of the generator.
void SetName(const G4String &name)
vertex reconstruction