thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
SamplerBase.h
1// -*- C++ -*-
2//
3// SamplerBase.h is a part of ThePEG - Toolkit for HEP Event Generation
4// Copyright (C) 1999-2019 Leif Lonnblad
5//
6// ThePEG 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 ThePEG_SamplerBase_H
10#define ThePEG_SamplerBase_H
11// This is the declaration of the SamplerBase class.
12
13#include "ThePEG/Interface/Interfaced.h"
14#include "SamplerBase.fh"
15#include "ThePEG/Handlers/StandardEventHandler.fh"
16// #include "SamplerBase.xh"
17
18namespace ThePEG {
19
35class SamplerBase: public Interfaced {
36
37public:
38
41
46 : Interfaced(),
48
52 virtual ~SamplerBase();
54
55public:
56
62 void setEventHandler(tStdEHPtr eh) { theEventHandler = eh; }
63
70 virtual void initialize() = 0;
71
76 virtual void prepare() {}
77
82 virtual double generate() = 0;
83
87 virtual void rejectLast() = 0;
88
92 const vector<double> & lastPoint() const { return theLastPoint; }
93
99 virtual int lastBin() const { return 0; }
100
105 virtual CrossSection integratedXSec() const = 0;
106
111 virtual CrossSection integratedXSecErr() const = 0;
112
120 virtual CrossSection maxXSec() const {
121 if ( sumWeights2() <= 0.0 ) return ZERO;
123 }
124
132 virtual double attempts() const {
135 double sw = sumWeights(); double sw2 = sumWeights2();
136 if ( sw2 <= 0.0 ) return 0.0;
137 return
138 sqr(sw)*(sqr(esigma)-sqr(sigma))/(sqr(sw)*sqr(esigma) - sw2*sqr(sigma));
139 }
140
145 virtual double sumWeights() const = 0;
146
151 virtual double sumWeights2() const = 0;
152
156 virtual bool almostUnweighted() const { return false; }
158
161
165 void integrationList(const string& newIntegrationList) { theIntegrationList = newIntegrationList; }
166
170 const string& integrationList() const { return theIntegrationList; }
171
176
177 UnknownMode = 0,
178 InitMode,
179 ReadMode,
180 BuildMode,
181 IntegrationMode,
182 RunMode
183
184 };
185
189 static int runLevel() {
190 return theRunLevel();
191 }
192
196 static void setRunLevel(int level) {
197 theRunLevel() = level;
198 }
199
203 static bool hasSetupFile() {
204 return theHasSetupFile();
205 }
206
210 static void setupFileUsed(bool yes = true) {
211 theHasSetupFile() = yes;
212 }
213
218 static long seed() {
219 return theSeed();
220 }
221
226 static void setSeed(long s) {
227 theSeed() = s;
228 }
229
233 static unsigned int integratePerJob() {
234 return theIntegratePerJob();
235 }
236
240 static void setIntegratePerJob(unsigned int s) {
241 theIntegratePerJob() = s;
242 }
243
247 static unsigned int integrationJobs() {
248 return theIntegrationJobs();
249 }
250
254 static void setIntegrationJobs(unsigned int s) {
255 theIntegrationJobs() = s;
256 }
257
259
260protected:
261
265 vector<double> & lastPoint() { return theLastPoint; }
266
270 tStdEHPtr eventHandler() const { return theEventHandler; }
271
272public:
273
281
287 void persistentInput(PersistentIStream & is, int version);
289
293 static void Init();
294
295private:
296
301
305 vector<double> theLastPoint;
306
311
315 static int& theRunLevel() {
316 static int lvl = UnknownMode;
317 return lvl;
318 }
319
323 static bool& theHasSetupFile() {
324 static bool flag = false;
325 return flag;
326 }
327
332 static long& theSeed() {
333 static long s = 0;
334 return s;
335 }
336
340 static unsigned int& theIntegratePerJob() {
341 static unsigned int s = 0;
342 return s;
343 }
344
348 static unsigned int& theIntegrationJobs() {
349 static unsigned int s = 0;
350 return s;
351 }
352
353private:
354
359
363 SamplerBase & operator=(const SamplerBase &) = delete;
364
365};
366
367}
368
369
370namespace ThePEG {
371
378template <>
379struct BaseClassTrait<SamplerBase,1>: public ClassTraitsType {
381 typedef Interfaced NthBase;
382};
383
388template <>
389struct ClassTraits<SamplerBase>: public ClassTraitsBase<SamplerBase> {
391 static string className() { return "ThePEG::SamplerBase"; }
392
393};
394
397}
398
399#endif /* ThePEG_SamplerBase_H */
A concreate implementation of ClassDescriptionBase describing an abstract class with persistent data.
The Interfaced class is derived from the InterfacedBase class adding a couple of things particular to...
Definition: Interfaced.h:38
PersistentIStream is used to read persistent objects from a stream where they were previously written...
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
This is the base class for all phase space sampler classes to be used by the EventHandler class to sa...
Definition: SamplerBase.h:35
static long & theSeed()
The seed that has been used for this run to disentangle grids whihch have been adapted further.
Definition: SamplerBase.h:332
virtual void prepare()
An external hook to prepare the sampler for generating events, e.g.
Definition: SamplerBase.h:76
static void setIntegratePerJob(unsigned int s)
Set the number of subprocesses to be integrated per job.
Definition: SamplerBase.h:240
void integrationList(const string &newIntegrationList)
Set a file containing a list of subprocesses to integrate.
Definition: SamplerBase.h:165
virtual ~SamplerBase()
Destructor.
static long seed()
Return the seed that has been used for this run to disentangle grids whihch have been adapted further...
Definition: SamplerBase.h:218
static bool & theHasSetupFile()
True, if a setupfile is in use.
Definition: SamplerBase.h:323
virtual double attempts() const
Return the number of attempts.
Definition: SamplerBase.h:132
virtual bool almostUnweighted() const
Return true if this sampler is generating almost unweighted events.
Definition: SamplerBase.h:156
string theIntegrationList
A file containing a list of subprocesses to integrate.
Definition: SamplerBase.h:310
virtual void rejectLast()=0
Reject the last chosen phase space point.
void setEventHandler(tStdEHPtr eh)
Set the event handler for which the function StandardEventHandler::dSigDR(const vector<double> &) fun...
Definition: SamplerBase.h:62
static bool hasSetupFile()
Return true, if a setupfile is in use.
Definition: SamplerBase.h:203
virtual double sumWeights() const =0
Return the sum of the weights returned by generate() so far (of the events that were not rejeted).
vector< double > & lastPoint()
Return the last generated phase space point.
Definition: SamplerBase.h:265
tStdEHPtr eventHandler() const
Return the associated event handler.
Definition: SamplerBase.h:270
static void setRunLevel(int level)
Set the run level.
Definition: SamplerBase.h:196
static int & theRunLevel()
The run level.
Definition: SamplerBase.h:315
virtual double generate()=0
Generarate a new phase space point and return a weight associated with it.
static AbstractClassDescription< SamplerBase > initSamplerBase
Describe an abstract base class with persistent data.
Definition: SamplerBase.h:358
static void setupFileUsed(bool yes=true)
Indicate that a setupfile is in use.
Definition: SamplerBase.h:210
RunLevels
Enumerate the possible run levels.
Definition: SamplerBase.h:175
const string & integrationList() const
Return a file containing a list of subprocesses to integrate.
Definition: SamplerBase.h:170
virtual CrossSection integratedXSec() const =0
Return the total integrated cross section determined from the Monte Carlo sampling so far.
static void setSeed(long s)
Set the seed that has been used for this run to disentangle grids whihch have been adapted further.
Definition: SamplerBase.h:226
virtual CrossSection maxXSec() const
Return the reference cross section, a.k.a.
Definition: SamplerBase.h:120
virtual double sumWeights2() const =0
Return the sum of the weights squared returned by generate() so far (of the events that were not reje...
static unsigned int & theIntegrationJobs()
The maximum number of integration jobs to be created.
Definition: SamplerBase.h:348
static void setIntegrationJobs(unsigned int s)
Set the maximum number of integration jobs to be created.
Definition: SamplerBase.h:254
static int runLevel()
Return the run level.
Definition: SamplerBase.h:189
virtual CrossSection integratedXSecErr() const =0
Return the error on the total integrated cross section determined from the Monte Carlo sampling so fa...
static void Init()
Standard Init function used to initialize the interfaces.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
tStdEHPtr theEventHandler
The associated event handler.
Definition: SamplerBase.h:300
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
virtual int lastBin() const
If the sampler is able to sample several different functions separately, this function should return ...
Definition: SamplerBase.h:99
static unsigned int integratePerJob()
Return the number of subprocesses to be integrated per job.
Definition: SamplerBase.h:233
static unsigned int & theIntegratePerJob()
The number of subprocesses to be integrated per job.
Definition: SamplerBase.h:340
static unsigned int integrationJobs()
Return the maximum number of integration jobs to be created.
Definition: SamplerBase.h:247
SamplerBase()
Constructor.
Definition: SamplerBase.h:45
SamplerBase & operator=(const SamplerBase &)=delete
Private and non-existent assignment operator.
vector< double > theLastPoint
The last generated phase space point.
Definition: SamplerBase.h:305
const vector< double > & lastPoint() const
Return the last generated phase space point.
Definition: SamplerBase.h:92
virtual void initialize()=0
Initialize the the sampler, possibly doing presampling of the phase space.
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
constexpr ZeroUnit ZERO
ZERO can be used as zero for any unitful quantity.
Definition: PhysicalQty.h:35
constexpr auto sqr(const T &x) -> decltype(x *x)
The square function should really have been included in the standard C++ library.
Definition: ThePEG.h:117
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Definition: ClassTraits.h:161
static string className()
Return the name of class T.
Definition: ClassTraits.h:66