EDepSimUserPrimaryGeneratorAction.cc
Go to the documentation of this file.
3 #include "EDepSimException.hh"
4 
7 
8 #include <EDepSimLog.hh>
9 
10 #include <G4Event.hh>
11 #include <G4StateManager.hh>
12 #include <G4RunManager.hh>
13 #include <G4VPrimaryGenerator.hh>
14 #include <Randomize.hh>
15 
18  fAllowEmptyEvents = true;
19  fAddFakeGeantino = false;
20 }
21 
23  delete fMessenger;
24 }
25 
27  // Make sure that at least one generater is in the list. If the list is
28  // empty, then create the default generator.
29  if (fPrimaryGenerators.size()<1) {
31  }
32 
33  for (int finiteLoop = 0; finiteLoop<1000; ++finiteLoop) {
35  = fPrimaryGenerators.begin();
37  ++generator) {
38  try {
39  (*generator)->GeneratePrimaryVertex(anEvent);
40  }
41  catch (EDepSim::NoMoreEvents&) {
42  if (fAllowPartialEvents) {
43  EDepSimLog("GeneratePrimaries: "
44  << "Ran out of primaries will filling event.");
45  continue;
46  }
47  EDepSimError("Run aborted. No more input events.");
48  G4RunManager::GetRunManager()->AbortRun();
49  return;
50  }
51  }
52  if (fAddFakeGeantino) {
53  EDepSimWarn("Add a GEANTINO vertex.");
54  // Put the vertex far way, and far in the future.
55  G4PrimaryVertex* theVertex =
56  new G4PrimaryVertex(G4ThreeVector(1E+20, 1E+20, 1E+20),
57  1E+20);
58  anEvent->AddPrimaryVertex(theVertex);
59  // Create the GEANTINO
60  G4ParticleTable* particleTable
61  = G4ParticleTable::GetParticleTable();
62  G4ParticleDefinition* def = particleTable->FindParticle("geantino");
63  G4PrimaryParticle* part
64  = new G4PrimaryParticle(def,0.0, 0.0, 1.0);
65  theVertex->SetPrimary(part);
66  break;
67  }
68  if (anEvent->GetNumberOfPrimaryVertex()>0) break;
69  if (fAllowEmptyEvents) continue;
70  EDepSimError("EDepSim::UserPrimaryGeneratorAction::GeneratePrimaries():"
71  << " Event generated without any primary verticies.");
72  EDepSimThrow("No primaries generated.");
73  }
74 }
75 
78  = fPrimaryGenerators.begin();
79  gen != fPrimaryGenerators.end();
80  ++gen) {
81  delete (*gen);
82  }
83  fPrimaryGenerators.clear();
84 }
#define EDepSimLog(outStream)
Definition: EDepSimLog.hh:717
intermediate_table::iterator iterator
EDepSim::UserPrimaryGeneratorMessenger * fMessenger
The messenger for this action.
EDepSim::PrimaryGenerator * CreateGenerator()
Create a new generator using the current generator factories.
void AddGenerator(G4VPrimaryGenerator *generator)
#define EDepSimThrow(message)
Print an error message, and then throw an exception.
void ClearGenerators()
Clear the current list of generators.
gen
Definition: demo.py:24
generator
Definition: train.py:468
#define EDepSimError(outStream)
Definition: EDepSimLog.hh:503
#define EDepSimWarn(outStream)
Definition: EDepSimLog.hh:576
std::vector< G4VPrimaryGenerator * > fPrimaryGenerators