42 static bool EGS_SOURCE_COLLECTION_LOCAL inputSet =
false;
46 vector<EGS_BaseSource *> s;
47 egsInformation(
"EGS_SourceCollection::EGS_BaseSource: input is:\n");
54 egsWarning(
"EGS_SourceCollection: got null source\n");
57 s.push_back(this_source);
61 vector<string> snames;
62 int err = input->
getInput(
"source names",snames);
64 for (
unsigned int j=0; j<snames.size(); j++) {
67 egsWarning(
"EGS_SourceCollection: got null source\n");
70 s.push_back(this_source);
75 egsWarning(
"EGS_SourceCollection: no sources\n");
78 vector<EGS_Float> prob;
79 err = input->
getInput(
"weights",prob);
81 egsWarning(
"EGS_SourceCollection: missing 'weights' input\n");
84 if (prob.size() != s.size()) {
85 egsWarning(
"EGS_SourceCollection: the number of sources (%d) is not"
86 " the same as the number of input probabilities (%d)\n",
87 s.size(),prob.size());
93 void EGS_SourceCollection::setUp(
const vector<EGS_BaseSource *> &S,
94 const vector<EGS_Float> &prob) {
95 otype =
"EGS_SourceCollection";
97 if (prob.size() < nsource) {
98 nsource = prob.size();
102 p =
new EGS_Float [nsource];
104 p_group =
new vector<EGS_I64> [nsource];
107 for (
int j=0; j<nsource; j++) {
111 if (
p[j] < 0)
egsWarning(
"EGS_SourceCollection: input "
112 "probability p[%d]=%g is less than zero.\n",j,
p[j]);
114 egsWarning(
"EGS_SourceCollection: source %d is null\n",j);
117 for (
int i=0; i<j; j++) {
133 for (
int i=0; i<nsource; i++) {
148 for (
int j=0; j<nsource; j++) {
149 bool sourceContainsDynamic =
false;
150 sources[j]->containsDynamic(sourceContainsDynamic);
151 if (sourceContainsDynamic) {
160 static void setInputs() {
163 setBaseSourceInputs(
false,
false);
165 srcBlockInput->getSingleInput(
"library")->setValues({
"egs_source_collection"});
168 srcBlockInput->addSingleInput(
"source names",
true,
"A list of names of previously defined sources.");
169 srcBlockInput->addSingleInput(
"weights",
true,
"A list of weights for the sources, used as the relative sampling probabilities.");
172 EGS_SOURCE_COLLECTION_EXPORT
string getExample() {
176 # Example of egs_source_collection
178 library = egs_source_collection
181 # create sources called p1 and p2
188 EGS_SOURCE_COLLECTION_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
192 return srcBlockInput;
198 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.