herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
GeneralSampler.h
1// -*- C++ -*-
2//
3// GeneralSampler.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4// Copyright (C) 2002-2019 The Herwig Collaboration
5//
6// Herwig is licenced under version 3 of the GPL, see COPYING for details.
7// Please respect the MCnet academic guidelines, see GUIDELINES for details.
8//
9#ifndef Herwig_GeneralSampler_H
10#define Herwig_GeneralSampler_H
11//
12// This is the declaration of the GeneralSampler class.
13//
14
15#include "ThePEG/Handlers/SamplerBase.h"
16#include "BinSampler.h"
17
18namespace Herwig {
19
20using namespace ThePEG;
21
32
33public:
34
41
45 virtual ~GeneralSampler();
47
48public:
49
56 virtual void initialize();
57
62 virtual double generate();
63
67 virtual void rejectLast();
68
74 virtual int lastBin() const { return lastSampler() ? lastSampler()->bin() : 0; }
75
80 virtual CrossSection integratedXSec() const {
82 return theIntegratedXSec;
83 }
84
89 virtual CrossSection integratedXSecErr() const {
92 }
93
97 virtual CrossSection maxXSec() const {
98 if ( theAddUpSamplers )
99 return SamplerBase::maxXSec();
100 return theMaxWeight*nanobarn;
101 }
102
107 virtual double sumWeights() const { return theSumWeights; }
108
113 virtual double sumWeights2() const { return theSumWeights2; }
114
118 virtual double attempts() const {
119 if ( theAddUpSamplers )
120 return SamplerBase::attempts();
121 return theAttempts;
122 }
123
127 double accepts() const { return theAccepts; }
128
130
134 const map<double,Ptr<BinSampler>::ptr>& samplers() const { return theSamplers; }
135
139 Ptr<BinSampler>::ptr binSampler() const { return theBinSampler; }
140
144 Ptr<BinSampler>::tptr lastSampler() const { return theLastSampler; }
145
149 bool weighted() const { return eventHandler()->weighted(); }
150
154 virtual bool almostUnweighted() const { return theAlmostUnweighted; }
155
156public:
157
161 const XML::Element& grids() const { return theGrids; }
162
167
171 void writeGrids() const;
172
176 void readGrids();
177
181 unsigned int integrationJobsCreated() {
183 }
184
189 virtual void prepare();
190
191protected:
192
196 map<double,Ptr<BinSampler>::ptr>& samplers() { return theSamplers; }
197
201 void lastSampler(Ptr<BinSampler>::tptr s) { theLastSampler = s; }
202
207
212
213public:
214
222
228 void persistentInput(PersistentIStream & is, int version);
230
237 static void Init();
238
239protected:
240
247 virtual IBPtr clone() const;
248
253 virtual IBPtr fullclone() const;
255
256
257// If needed, insert declarations of virtual function defined in the
258// InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
259
260
261protected:
262
268 virtual void doinit();
269
274 virtual void doinitrun();
275
280 virtual void dofinish();
281
291 virtual void rebind(const TranslationMap & trans);
292
299
300private:
301
306
311
315 Ptr<BinSampler>::ptr theBinSampler;
316
320 map<double,Ptr<BinSampler>::ptr> theSamplers;
321
325 Ptr<BinSampler>::tptr theLastSampler;
326
330 mutable CrossSection theIntegratedXSec;
331
335 mutable CrossSection theIntegratedXSecErr;
336
343
348 mutable size_t crossSectionCalls;
349
354 mutable bool gotCrossSections;
355
360
365
370
375
380
386
394
401
406
411
417
422
426 unsigned long maximumExceeds;
427
432
439
446
451
456
460 unsigned int theIntegratePerJob;
461
465 unsigned int theIntegrationJobs;
466
471
476
481
482private:
483
489
490};
491
492}
493
494#endif /* Herwig_GeneralSampler_H */
A GeneralSampler class.
double accepts() const
Return the number of accepts.
void lastSampler(Ptr< BinSampler >::tptr s)
Set the last selected bin sampler.
unsigned int theIntegrationJobs
The maximum number of integration jobs to be created.
bool justAfterIntegrate
Indicate that initialization is only reading a grid.
double theSumWeights2
The sum of weights squared.
unsigned int theIntegratePerJob
The number of subprocesses to integrate per job.
bool isSampling
True, if we are generating events.
virtual void dofinish()
Finalize this object.
XML::Element theGrids
The XML element containing the grids.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
size_t crossSectionCalls
The number of calls to currentCrossSections since the last update.
map< double, Ptr< BinSampler >::ptr > & samplers()
Access the samplers.
Ptr< BinSampler >::tptr theLastSampler
The last selected bin sampler.
unsigned long maximumExceeds
Number of points which exceeded the maximum.
double theMaxWeight
The maximum weight encountered.
virtual double sumWeights() const
Return the sum of the weights returned by generate() so far (of the events that were not rejeted).
virtual double attempts() const
Return the number of attempts.
static void Init()
The standard Init function used to initialize the interfaces.
Ptr< BinSampler >::tptr lastSampler() const
Return the last selected bin sampler.
virtual void prepare()
An external hook to prepare the sampler for generating events, e.g.
void writeGrids() const
Write out grids.
GeneralSampler()
The default constructor.
void readGrids()
Read in grids.
virtual void rebind(const TranslationMap &trans)
Rebind pointer to other Interfaced objects.
bool weighted() const
True if we should do weighted events.
bool theFlatSubprocesses
True, if subprocesses should be selected flat.
GeneralSampler & operator=(const GeneralSampler &)=delete
The assignment operator is private and must never be called.
virtual CrossSection integratedXSec() const
Return the total integrated cross section determined from the Monte Carlo sampling so far.
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
virtual void initialize()
Initialize the the sampler, possibly doing presampling of the phase space.
bool runCombinationData
True, if information for combining unnormalized runs should be printed out.
virtual int lastBin() const
If the sampler is able to sample several different functions separately, this function should return ...
virtual bool almostUnweighted() const
Return true if this sampler is generating almost unweighted events.
virtual ~GeneralSampler()
The destructor.
double theAccepts
The number of accepts.
double theAttempts
The number of attempts.
bool theGlobalMaximumWeight
True, if the global maximum weight should be used as reference.
unsigned int theIntegrationJobsCreated
The number of integration jobs which were actually created.
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
XML::Element & grids()
Access the XML element containing the grids.
virtual IVector getReferences()
Return a vector of all pointers to Interfaced objects used in this object.
bool theVerbose
Whether or not additional information should be printed to cout.
CrossSection theIntegratedXSecErr
The integrated cross section error.
map< double, Ptr< BinSampler >::ptr > theSamplers
The selector map for the bin samplers.
virtual double sumWeights2() const
Return the sum of the weights squaredreturned by generate() so far (of the events that were not rejet...
bool didReadGrids
True, if grids have already been read.
size_t theUpdateAfter
The number of events after which cross sections should truly be updated.
Ptr< BinSampler >::ptr theBinSampler
The bin sampler to use.
double theMinSelection
A minimum selection probability for each sampler.
const XML::Element & grids() const
Return the XML element containing the grids.
bool gotCrossSections
True, if currentCrossSections has been called since the last call to generate.
bool theParallelIntegration
True, if parallel subprocess integration should be enabled.
bool theAlmostUnweighted
True, if we should perform an almost unweighted sampling.
unsigned int integrationJobsCreated()
Return the number of integration jobs which were actually created.
CrossSection theIntegratedXSec
The integrated cross section.
void updateSamplers()
Update the sampler selection.
virtual IBPtr clone() const
Make a simple clone of this object.
virtual double generate()
Generarate a new phase space point and return a weight associated with it.
virtual CrossSection integratedXSecErr() const
Return the error on the total integrated cross section determined from the Monte Carlo sampling so fa...
bool theWriteGridsOnFinish
True, if grids should be written at the end of a run.
void currentCrossSections() const
Calculate cross sections from samplers at current state.
const map< double, Ptr< BinSampler >::ptr > & samplers() const
Return the samplers.
double maximumExceededBy
The average relative deviation from the maximum weight.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
virtual void rejectLast()
Reject the last chosen phase space point.
double theMaxEnhancement
Enhancement factor to the maximum weight.
double correctWeights
The correct cross section as one would exspect with almostUnweighted.
virtual CrossSection maxXSec() const
Return the overestimated integrated cross section.
Ptr< BinSampler >::ptr binSampler() const
Return the bin sampler.
bool theAddUpSamplers
True, if cross sections are to be combined from each sampler individually.
virtual void doinitrun()
Initialize this object.
double theSumWeights
The sum of weights.
virtual double attempts() const
tStdEHPtr eventHandler() const
virtual CrossSection maxXSec() const
Element represents a (tree of) XML elements.
Definition: Element.h:56
-*- C++ -*-
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
vector< IBPtr > IVector