14 #include <G4PrimaryVertex.hh> 15 #include <G4PrimaryParticle.hh> 16 #include <G4ParticleTable.hh> 17 #include <G4IonTable.hh> 18 #include <G4ParticleDefinition.hh> 19 #include <G4Tokenizer.hh> 20 #include <G4UnitsTable.hh> 24 #include <TObjString.h> 37 const G4String& treeName,
const G4String& order,
42 fInput = TFile::Open(filename,
"OLD");
44 throw std::runtime_error(
"EDepSim::RooTrackerKinematicsGenerator::" 48 EDepSimLog(
"Open a RooTracker tree from " << filename);
50 fTree =
dynamic_cast<TTree*
>(
fInput->Get(treeName));
52 throw std::runtime_error(
"EDepSim::RooTrackerKinematicsGenerator::" 53 " Tree not found by constructor");
56 " File has " <<
fTree->GetEntries() <<
" entries");
59 std::string::size_type start_pos = filename.rfind(
"/");
60 if (start_pos == std::string::npos) start_pos = 0;
else ++start_pos;
84 #define PARENT_PARTICLE_PASS_THROUGH 85 #ifdef PARENT_PARTICLE_PASS_THROUGH 106 int entries =
fTree->GetEntries();
109 while (order ==
"stride") {
111 if (0 != entries%stride)
break;
113 if (0 != entries%stride)
break;
115 if (0 != entries%stride)
break;
117 if (0 != entries%stride)
break;
118 throw std::runtime_error(
"EDepSim::RooTrackerKinematicsGenerator:: " 119 "File size cannot be divisible by 215441");
123 for (
int i=0; i<entries; ++i) {
125 entry = (entry + stride)%entries;
127 if (order ==
"random") {
132 if (firstEvent > 0) {
133 EDepSimLog(
" FIRST EVENT WILL BE " << firstEvent);
134 if (firstEvent >= entries) {
135 throw std::runtime_error(
"EDepSim::RooTrackerKinematicsGenerator::" 136 " First event after last event");
147 if (!
fInput)
return G4String(
"not-open");
148 return G4String(
fInput->GetName());
154 const G4LorentzVector&) {
156 throw std::runtime_error(
"EDepSim::RooTrackerKinematicsGenerator::" 162 EDepSimLog(
"EDepSim::RooTrackerKinematicsGenerator: input file end.");
170 fTree->GetEntry(entry);
176 <<
" (entry #" << entry <<
" in tree)");
192 G4PrimaryVertex* theVertex
193 =
new G4PrimaryVertex(G4ThreeVector(
fEvtVtx[0]*
m,
197 anEvent->AddPrimaryVertex(theVertex);
199 << G4BestUnit(theVertex->GetPosition(),
"Length")
200 <<
" Time: " << G4BestUnit(theVertex->GetT0(),
"Time"));
204 theVertex->SetUserInformation(vertexInfo);
209 std::ostringstream
fs;
222 G4PrimaryVertex* theIncomingVertex
223 =
new G4PrimaryVertex(G4ThreeVector(
fEvtVtx[0]*m,
231 incomingVertexInfo->
SetName(
"initial-state");
233 theIncomingVertex->SetUserInformation(incomingVertexInfo);
239 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
240 for (
int cnt = 0; cnt <
fStdHepN; ++cnt) {
241 G4ParticleDefinition* particleDef
242 = particleTable->FindParticle(
fStdHepPdg[cnt]);
248 if (type == 10 && ionZ > 0 && ionA > ionZ) {
249 G4IonTable* ionTable = particleTable->GetIonTable();
250 particleDef = ionTable->GetIon(ionZ, ionA);
252 else if (type == 20) {
260 particleDef ? particleDef->GetParticleName():
"unknown";
270 <<
" " << particleName
271 <<
" with " << momentum.e()/
MeV 285 <<
" not recognized (not tracking)");
290 G4PrimaryParticle* theParticle
291 =
new G4PrimaryParticle(particleDef,
303 << particleDef->GetParticleName()
304 <<
" " << theParticle->GetPDGcode()
305 <<
" " << momentum.e()/
MeV <<
" MeV" 306 <<
" " << momentum.m()/
MeV <<
" MeV/c^2");
307 theIncomingVertex->SetPrimary(theParticle);
313 << particleDef->GetParticleName()
314 <<
" " << theParticle->GetPDGcode()
315 <<
" " << momentum.e()/
MeV <<
" MeV" 316 <<
" " << momentum.m()/
MeV <<
" MeV/c^2");
317 theVertex->SetPrimary(theParticle);
321 #ifdef PARENT_PARTICLE_PASS_THROUGH 324 G4PrimaryVertex* theDecayVertex
333 decayVertexInfo->
SetName(
"beam-particle:Decay");
335 std::ostringstream
tmp;
339 theDecayVertex->SetUserInformation(decayVertexInfo);
341 G4PrimaryParticle* theDecayParticle
346 theDecayVertex->SetPrimary(theDecayParticle);
349 G4PrimaryVertex* theProductionVertex
358 productionVertexInfo->
SetName(
"beam-particle:Production");
360 theProductionVertex->SetUserInformation(productionVertexInfo);
362 G4PrimaryParticle* theProductionParticle
367 theProductionVertex->SetPrimary(theProductionParticle);
370 return generatorStatus;
#define EDepSimLog(outStream)
#define EDepSimNamedInfo(trace, outStream)
void SetFilename(const G4String &f)
Set the file that this vertex came from.
double fStdHepX4[kNPmax][4]
double fStdHepP4[kNPmax][4]
The 4-momentum (px, py, pz, E) of the particle in the LAB frame (GeV)
int fNuParentPdg
The PDG code of the particle which created the parent neutrino.
void SetCrossSection(double xs)
int fStdHepN
The number of particles in the particle arrays to track.
virtual void AddInformationalVertex(G4PrimaryVertex *vtx)
Add an informational vertex to this event.
std::vector< int > fEntryVector
virtual ~RooTrackerKinematicsGenerator()
std::string fFilename
The static part of the file name field.
static constexpr double fs
TObjString * fEvtCode
The generator-specific string with the 'event code'.
int fNuParentProNVtx
The vertex ID of the parent particle vertex.
int fStdHepLd[kNPmax]
The index last daughter of the particle in the arrays.
static constexpr double MeV
#define EDepSimSevere(outStream)
GeneratorStatus
A status value that can be returned by GeneratePrimaryVertex.
TBits * fEvtFlags
The generator-specific event flags.
int fStdHepFd[kNPmax]
The index of the first daughter of the particle in the arrays.
bool AddEntry(const TTree *inputTreePtr, const int origEntry)
TFile * fInput
The RooTracker file to read.
double fEvtXSec
The cross section for the event (1E-38 cm2)
double fStdHepPolz[kNPmax][3]
The particle polarization vector.
static EDepSim::KinemPassThrough * GetInstance()
Construct a module from components.
static constexpr double cm2
static constexpr double GeV
A vertex was successfully generated.
double fEvtWght
The weight for the event.
int fEvtNum
The sequence number of the event (the event number).
TTree * fTree
The event tree that contains the output events.
bool AddInputTree(const TTree *inputTreePtr, const char *inputFileName, const char *generatorName)
void SetDiffCrossSection(double xs)
#define EDepSimVerbose(outStream)
void SetProbability(double p)
void SetInteractionNumber(int i)
Set the index of the interaction within the input interaction file.
int fStdHepStatus[kNPmax]
RooTrackerKinematicsGenerator(const G4String &name, const G4String &fileName, const G4String &treeName, const G4String &order, int firstEvent)
int fStdHepFm[kNPmax]
The index of the first mother of the particle in there arrays.
def momentum(x1, x2, x3, scale=1.)
second_as<> second
Type of time stored in seconds, in double precision.
G4String GetName() const
Return the name of the generator.
virtual G4String GetInputName()
Get the name of the open kinematics file.
int fStdHepLm[kNPmax]
The index of the last mother of the particle in the arrays.
void SetReaction(const G4String &r)
void SetName(const G4String &name)
virtual GeneratorStatus GeneratePrimaryVertex(G4Event *evt, const G4LorentzVector &position)
Add a primary vertex to the event.