// GLG4Gen.cc // Contact person: Phil Jones // See GLG4Gen.hh for more details //———————————————————————// #include #include #include #include #include #include #include #include #include #include #include using namespace std; GLG4Gen::~GLG4Gen() { if (fTimeGen) delete fTimeGen; if (fVertexGen) delete fVertexGen; if (fPosGen) delete fPosGen; } void GLG4Gen::BeginOfRun() { if (fTimeGen) fTimeGen->BeginOfRun(); if (fVertexGen) fVertexGen->BeginOfRun(); if (fPosGen) fPosGen->BeginOfRun(); } void GLG4Gen::EndOfRun() { if (fTimeGen) fTimeGen->EndOfRun(); if (fVertexGen) fVertexGen->EndOfRun(); if (fPosGen) fPosGen->EndOfRun(); } GLG4Gen_Combo::GLG4Gen_Combo() : GLG4Gen("combo"), fStateStr("") { // Default time generator fTimeGen = new GLG4TimeGen_Poisson(); } GLG4Gen_Combo::~GLG4Gen_Combo() { } void GLG4Gen_Combo::GenerateEvent(G4Event *event) { G4ThreeVector pos; fPosGen->GeneratePosition(pos); G4double t0 = NextTime(); fVertexGen->GeneratePrimaryVertex(event, pos, t0); } void GLG4Gen_Combo::ResetTime(double offset) { fNextTime = fTimeGen->GenerateEventTime() + offset; } void GLG4Gen_Combo::SetState(G4String state) { state = util_strip_default(state); vector parts = util_split(state, ":"); try { switch (parts.size()) { case 3: // last is optional time generator delete fTimeGen; fTimeGen = 0; // In case of exception in next line fTimeGen = RAT::GlobalFactory::New(parts[2]); case 2: delete fVertexGen; fVertexGen = 0; fVertexGen = RAT::GlobalFactory::New(parts[0]); delete fPosGen; fPosGen = 0; fPosGen = RAT::GlobalFactory::New(parts[1]); break; default: G4Exception(__FILE__, "Invalid Parameter", FatalException, ("Combo generator syntax error: "+state).c_str()); break; } fStateStr = state; // Save for later call to GetState() } catch (RAT::FactoryUnknownID &unknown) { G4cerr << "Unknown generator \"" << unknown.id << "\"" << G4endl; } } G4String GLG4Gen_Combo::GetState() const { return fStateStr; } void GLG4Gen_Combo::SetTimeState(G4String state) { if (fTimeGen) fTimeGen->SetState(state); else G4cerr << "GLG4Gen_Combo error: Cannot set time state, no time generator selected" << G4endl; } G4String GLG4Gen_Combo::GetTimeState() const { if (fTimeGen) return fTimeGen->GetState(); else return G4String("GLG4Gen_Combo error: no time generator selected"); } void GLG4Gen_Combo::SetVertexState(G4String state) { if (fVertexGen) fVertexGen->SetState(state); else G4cerr << "GLG4Gen_Combo error: Cannot set vertex state, no vertex generator selected" << G4endl; } G4String GLG4Gen_Combo::GetVertexState() const { if (fVertexGen) return fVertexGen->GetState(); else return G4String("GLG4Gen_Combo error: no vertex generator selected"); } void GLG4Gen_Combo::SetPosState(G4String state) { if (fPosGen) fPosGen->SetState(state); else G4cerr << "GLG4Gen_Combo error: Cannot set position state, no position generator selected" << G4endl; } G4String GLG4Gen_Combo::GetPosState() const { if (fPosGen) return fPosGen->GetState(); else return G4String("GLG4Gen_Combo error: no pos generator selected"); } //////////////////////////////////////////////////////////////// GLG4Gen_DeferTrack::GLG4Gen_DeferTrack(const G4Track *track) : GLG4Gen("defer_track") { fVertex = new G4PrimaryVertex( track->GetPosition(), track->GetGlobalTime() ); G4ThreeVector mom(track->GetMomentum()); G4ThreeVector pol(track->GetPolarization()); G4PrimaryParticle* particle; particle= new G4PrimaryParticle(track->GetDefinition(),// particle code mom.x(), mom.y(), mom.z() );// momentum particle->SetPolarization(pol.x(), pol.y(), pol.z()); // polarization particle->SetMass(track->GetDefinition()->GetPDGMass()); // Geant4 is silly. fVertex->SetPrimary( particle ); fNextTime = fVertex->GetT0(); } GLG4Gen_DeferTrack::~GLG4Gen_DeferTrack() { } void GLG4Gen_DeferTrack::GenerateEvent(G4Event *event) { fVertex->SetT0(fNextTime); event->AddPrimaryVertex(fVertex); } void GLG4Gen_DeferTrack::SetState(G4String /*state*/) { // No-op } G4String GLG4Gen_DeferTrack::GetState() const { return G4String(""); }