181 lines
5.9 KiB
C++
181 lines
5.9 KiB
C++
//
|
|
// ********************************************************************
|
|
// * DISCLAIMER *
|
|
// * *
|
|
// * The following disclaimer summarizes all the specific disclaimers *
|
|
// * of contributors to this software. The specific disclaimers,which *
|
|
// * govern, are listed with their locations in: *
|
|
// * http://cern.ch/geant4/license *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. *
|
|
// * *
|
|
// * This code implementation is the intellectual property of the *
|
|
// * GEANT4 collaboration. *
|
|
// * By copying, distributing or modifying the Program (or any work *
|
|
// * based on the Program) you indicate your acceptance of this *
|
|
// * statement, and all its terms. *
|
|
// ********************************************************************
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// MODULE: G4GeneralParticleSource.cc
|
|
//
|
|
// Version: 2.0
|
|
// Date: 5/02/04
|
|
// Author: Fan Lei
|
|
// Organisation: QinetiQ ltd.
|
|
// Customer: ESA/ESTEC
|
|
//
|
|
// Documentation avaialable at http://reat.space.qinetiq.com/gps
|
|
// These include:
|
|
// User Requirement Document (URD)
|
|
// Software Specification Documents (SSD)
|
|
// Software User Manual (SUM): on-line version available
|
|
// Technical Note (TN) on the physics and algorithms
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// CHANGE HISTORY
|
|
// --------------
|
|
//
|
|
// Version 2.0, 05/02/2004, Fan Lei, Created.
|
|
// After changes to version 1.1 as in Geant4 v6.0
|
|
// - Mutilple particle source definition
|
|
// - Re-structured commands
|
|
// - Split the task into smaller classes
|
|
//
|
|
// - old commonds have been retained for backward compatibility, will be
|
|
// removed in the future.
|
|
//
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
#include "G4Event.hh"
|
|
#include "Randomize.hh"
|
|
#include "G4GeneralParticleSource.hh"
|
|
|
|
G4GeneralParticleSource::G4GeneralParticleSource()
|
|
: multiple_vertex(false)
|
|
{
|
|
sourceVector.clear();
|
|
sourceIntensity.clear();
|
|
sourceProbability.clear();
|
|
currentSource = new G4SingleParticleSource();
|
|
sourceVector.push_back(currentSource);
|
|
sourceIntensity.push_back(1.);
|
|
currentSourceIdx = G4int(sourceVector.size() - 1);
|
|
theMessenger = new G4GeneralParticleSourceMessenger(this);
|
|
theMessenger->SetParticleGun(currentSource);
|
|
IntensityNormalization();
|
|
}
|
|
|
|
G4GeneralParticleSource::~G4GeneralParticleSource()
|
|
{
|
|
delete theMessenger;
|
|
}
|
|
|
|
void G4GeneralParticleSource::AddaSource(G4double aV)
|
|
{
|
|
currentSource = new G4SingleParticleSource();
|
|
theMessenger->SetParticleGun(currentSource);
|
|
sourceVector.push_back(currentSource);
|
|
sourceIntensity.push_back(aV);
|
|
currentSourceIdx = G4int(sourceVector.size() - 1);
|
|
IntensityNormalization();
|
|
}
|
|
|
|
void G4GeneralParticleSource::IntensityNormalization()
|
|
{
|
|
G4double total = 0.;
|
|
size_t i = 0 ;
|
|
for (i = 0; i < sourceIntensity.size(); i++)
|
|
total += sourceIntensity[i] ;
|
|
//
|
|
sourceProbability.clear();
|
|
sourceProbability.push_back(sourceIntensity[0]/total);
|
|
for ( i = 1 ; i < sourceIntensity.size(); i++)
|
|
sourceProbability.push_back(sourceIntensity[i]/total + sourceProbability[i-1]);
|
|
normalised = true;
|
|
}
|
|
|
|
void G4GeneralParticleSource::ListSource()
|
|
{
|
|
G4cout << " The number of particle source is " << sourceIntensity.size() << G4endl;
|
|
for (size_t i = 0 ; i < sourceIntensity.size(); i++)
|
|
G4cout << " source " << i << " intensity is " << sourceIntensity[i] << G4endl;
|
|
}
|
|
|
|
void G4GeneralParticleSource::SetCurrentSourceto(G4int aV)
|
|
{
|
|
size_t id = size_t (aV) ;
|
|
if ( id <= sourceIntensity.size() ) {
|
|
currentSourceIdx = aV;
|
|
currentSource = sourceVector[id];
|
|
theMessenger->SetParticleGun(currentSource);
|
|
//
|
|
} else {
|
|
G4cout << " source index is invalid " << G4endl;
|
|
G4cout << " it shall be <= " << sourceIntensity.size() << G4endl;
|
|
}
|
|
}
|
|
|
|
void G4GeneralParticleSource::SetCurrentSourceIntensity(G4double aV)
|
|
{
|
|
sourceIntensity[currentSourceIdx] = aV;
|
|
normalised = false;
|
|
}
|
|
|
|
void G4GeneralParticleSource::ClearAll()
|
|
{
|
|
currentSourceIdx = -1;
|
|
currentSource = 0;
|
|
sourceVector.clear();
|
|
sourceIntensity.clear();
|
|
sourceProbability.clear();
|
|
}
|
|
|
|
void G4GeneralParticleSource::DeleteaSource(G4int aV)
|
|
{
|
|
size_t id = size_t (aV) ;
|
|
if ( id <= sourceIntensity.size() ) {
|
|
sourceVector.erase(sourceVector.begin()+aV);
|
|
sourceIntensity.erase(sourceIntensity.begin()+aV);
|
|
normalised = false ;
|
|
if (currentSourceIdx == aV ) {
|
|
if ( sourceIntensity.size() > 0 ) {
|
|
currentSource = sourceVector[0];
|
|
currentSourceIdx = 1;
|
|
} else {
|
|
currentSource = 0;
|
|
currentSourceIdx = -1;
|
|
}
|
|
}
|
|
} else {
|
|
G4cout << " source index is invalid " << G4endl;
|
|
G4cout << " it shall be <= " << sourceIntensity.size() << G4endl;
|
|
}
|
|
}
|
|
|
|
void G4GeneralParticleSource::GeneratePrimaryVertex(G4Event* evt)
|
|
{
|
|
if (!multiple_vertex){
|
|
if (sourceIntensity.size() > 1) {
|
|
if (!normalised) IntensityNormalization();
|
|
G4double rndm = G4UniformRand();
|
|
size_t i = 0 ;
|
|
while ( rndm > sourceProbability[i] ) i++;
|
|
(currentSource = sourceVector[i]);
|
|
}
|
|
currentSource-> GeneratePrimaryVertex(evt);
|
|
}
|
|
else {
|
|
for (size_t i = 0; i < sourceIntensity.size(); i++) {
|
|
sourceVector[i]->GeneratePrimaryVertex(evt);
|
|
}
|
|
}
|
|
}
|