9 #ifndef THEPEG_CompSelector_H 10 #define THEPEG_CompSelector_H 15 #include "ThePEG/Utilities/Selector.h" 46 template <
typename T,
typename WeightType =
double>
75 WeightType
insert(WeightType d,
const T & t) {
92 template <
typename RNDGEN>
93 T &
select(RNDGEN & rnd)
throw(range_error) {
111 WeightType newmax = oldmax*abs(weight)*
margin();
113 double rat = newmax/oldmax;
117 level.weight = 1.0/rat;
118 level.lastN = long(
N*newtot/oldtot);
122 for (
int i = 0, M =
levels.size(); i < M; ++i ) {
213 template <
typename OStream>
216 for (
int i = 0, M =
levels.size(); i < M; ++i )
223 template <
typename IStream>
228 for (
int i = 0; i < M; ++i ) is >>
levels[i].lastN >>
levels[i].weight;
291 template <
typename OStream,
typename T,
typename WeightType>
301 template <
typename IStream,
typename T,
typename WeightType>
double theMargin
The margin used to get a new overestimated probability for an object when entering compensation mode...
CompSelector(double newMargin=1.1, double newTolerance=1.0e-6)
The default constructor.
void output(OStream &os) const
Output to a stream.
void reset()
Exit compensation mode and start selection procedure from scratch.
bool compensating()
Return true if this CompSelector is in a compensating state.
void tolerance(double t)
Set the tolerance for how much a weight is allowed to be larger than unity before starting the compen...
T & select(RNDGEN &rnd)
Selct an object randomly.
This is the main namespace within which all identifiers in ThePEG are declared.
double tolerance() const
Return the tolerance for how much a weight is allowed to be larger than unity before starting the com...
void margin(double m)
Set the margin used to get a new overestimated probability for an object when entering compensation m...
WeightType reweight(double &weight)
Report the weight associated with the last selected object.
void input(IStream &is)
Input from a stream.
long N
The number of selections so far.
Level is used to increment temporarily a given integer variable.
Selector< T, WeightType > selector
The underlying selector.
vector< Level > levels
The currently active compensation levels.
vector< T > & operator>>(vector< T > &tv, U &u)
Overload the right shift operator for vector to pop objects from a vector.
Internal struct used for bookkeeping when compensating.
double weight
The minimum weight allowed when compensating on this level.
The CompSelector class works like the Selector class in that it can be used to randomly select object...
WeightType insert(WeightType d, const T &t)
Insert an object given a probability for this object.
long compleft() const
If in a compensating mode, return the number of selection needed before exiting this mode...
long lastN
The selection number at which point this level of compensation is ended.
Selector is a templated class for storing objects associated with probabilities in a way such that...
double theTolerance
Set the tolerance for how much a weight is allowed to be larger than unity before starting the compen...
WeightType sum() const
Return the sum of probabilities of the objects inserted.
T last
The last selected object.
vector< T > & operator<<(vector< T > &tv, const U &u)
Overload the left shift operator for vector to push_back objects to a vector.
double margin() const
Return the margin used to get a new overestimated probability for an object when entering compensatio...
void clear()
Erases all objects.