This file will become a part of the Pythia version 7 event generator toolkit.
This is the definition of the Pythia7::Selector class.
Selector is a templated class for storing objects associated with probabilities in a way such that, given a random number between 0 and 1, an object can be selected according to its relative probability. Internally, the objects of class T are stored in an std::map<double,T> where the key is the probability of the corresponding object plus the accumulated sum of probabilities of all objects before the current one in the map. This allows for fast retreival of an object according to its probability. Where fast means that the time increases as a logarithm of the number of objects in the selector.
double random(); // A random generator returning a
number between 0 and 1.
class foo; // A class which can be used in std::map.
Selector<foo*> bar; // A selector.
foo f1, f2;
bar.insert(0.5,&f1) // assign probability 0.5
bar.insert(0.5,&f2) // to each of f1 and f2
foo * f = bar.select(random()) // randomly returns
a pointer to f1 or f2
Leif Lönnblad
CLASS
Selector