43 vector<EGS_BaseSource *> s;
44 egsInformation(
"EGS_SourceCollection::EGS_BaseSource: input is:\n");
51 egsWarning(
"EGS_SourceCollection: got null source\n");
54 s.push_back(this_source);
58 vector<string> snames;
59 int err = input->
getInput(
"source names",snames);
61 for (
unsigned int j=0; j<snames.size(); j++) {
64 egsWarning(
"EGS_SourceCollection: got null source\n");
67 s.push_back(this_source);
72 egsWarning(
"EGS_SourceCollection: no sources\n");
75 vector<EGS_Float> prob;
76 err = input->
getInput(
"weights",prob);
78 egsWarning(
"EGS_SourceCollection: missing 'weights' input\n");
81 if (prob.size() != s.size()) {
82 egsWarning(
"EGS_SourceCollection: the number of sources (%d) is not"
83 " the same as the number of input probabilities (%d)\n",
84 s.size(),prob.size());
90 void EGS_SourceCollection::setUp(
const vector<EGS_BaseSource *> &S,
91 const vector<EGS_Float> &prob) {
92 otype =
"EGS_SourceCollection";
94 if (prob.size() < nsource) {
95 nsource = prob.size();
99 p =
new EGS_Float [nsource];
101 p_group =
new vector<EGS_I64> [nsource];
104 for (
int j=0; j<nsource; j++) {
108 if (
p[j] < 0)
egsWarning(
"EGS_SourceCollection: input "
109 "probability p[%d]=%g is less than zero.\n",j,
p[j]);
111 egsWarning(
"EGS_SourceCollection: source %d is null\n",j);
114 for (
int i=0; i<j; j++) {
130 for (
int i=0; i<nsource; i++) {
145 for (
int j=0; j<nsource; j++) {
146 bool sourceContainsDynamic =
false;
147 sources[j]->containsDynamic(sourceContainsDynamic);
148 if (sourceContainsDynamic) {
160 createSourceTemplate<EGS_SourceCollection>(input,f,
"source collection");
Base source class. All particle sources must be derived from this class.
static EGS_BaseSource * getSource(const string &Name)
Get a pointer to the source named Name.
virtual EGS_Float getEmax() const =0
Return the maximum energy of this source.
string description
A short source description.
static EGS_BaseSource * createSource(EGS_Input *)
Create sources from the information pointed to by input.
int ref()
Increase the reference count to this object.
static void deleteObject(EGS_Object *o)
Delete an object.
string otype
The object type.
A class for sampling random bins from a given probability distribution using the alias table techniqu...
EGS_Float * last_flu
Saved value of source_flu.
EGS_SimpleAliasTable * table
Alias table for randomly picking a source.
EGS_SourceCollection(const vector< EGS_BaseSource * > &S, const vector< EGS_Float > &prob, const string &Name="", EGS_ObjectFactory *f=0)
Constructor.
bool i_add
Set to true if parallel results have been combined.
EGS_Float Emax
Maximum energy (max of s[j]->getEmax()).
vector< EGS_I64 > * p_group
Vector of sources using the same base source.
EGS_BaseSource ** sources
The sources in the collection.
EGS_Float * p
The probabilities.
void containsDynamic(bool &hasdynamic)
Check if the simulation source contains time indices.
EGS_I64 * last_cases
Last case returned from each source.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.