herwig is hosted by Hepforge, IPPP Durham
Herwig  7.2.1
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 
18 namespace Herwig {
19 
20 using namespace ThePEG;
21 
31 class GeneralSampler: public SamplerBase {
32 
33 public:
34 
41 
45  virtual ~GeneralSampler();
47 
48 public:
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 {
81  currentCrossSections();
82  return theIntegratedXSec;
83  }
84 
89  virtual CrossSection integratedXSecErr() const {
90  currentCrossSections();
91  return theIntegratedXSecErr;
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 
156 public:
157 
161  const XML::Element& grids() const { return theGrids; }
162 
166  XML::Element& grids() { return theGrids; }
167 
171  void writeGrids() const;
172 
176  void readGrids();
177 
181  unsigned int integrationJobsCreated() {
182  return theIntegrationJobsCreated;
183  }
184 
189  virtual void prepare();
190 
191 protected:
192 
196  map<double,Ptr<BinSampler>::ptr>& samplers() { return theSamplers; }
197 
201  void lastSampler(Ptr<BinSampler>::tptr s) { theLastSampler = s; }
202 
206  void currentCrossSections() const;
207 
211  void updateSamplers();
212 
213 public:
214 
221  void persistentOutput(PersistentOStream & os) const;
222 
228  void persistentInput(PersistentIStream & is, int version);
230 
237  static void Init();
238 
239 protected:
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 
261 protected:
262 
268  virtual void doinit();
269 
274  virtual void doinitrun();
275 
280  virtual void dofinish();
281 
291  virtual void rebind(const TranslationMap & trans);
292 
298  virtual IVector getReferences();
299 
300 private:
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 
369  double theAttempts;
370 
374  double theAccepts;
375 
379  double theMaxWeight;
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 
482 private:
483 
488  GeneralSampler & operator=(const GeneralSampler &) = delete;
489 
490 };
491 
492 }
493 
494 #endif /* Herwig_GeneralSampler_H */
A GeneralSampler class.
bool gotCrossSections
True, if currentCrossSections has been called since the last call to generate.
bool theVerbose
Whether or not additional information should be printed to cout.
void lastSampler(Ptr< BinSampler >::tptr s)
Set the last selected bin sampler.
virtual bool almostUnweighted() const
Return true if this sampler is generating almost unweighted events.
Ptr< BinSampler >::ptr theBinSampler
The bin sampler to use.
CrossSection theIntegratedXSec
The integrated cross section.
CrossSection theIntegratedXSecErr
The integrated cross section error.
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
unsigned int theIntegrationJobs
The maximum number of integration jobs to be created.
map< double, Ptr< BinSampler >::ptr > & samplers()
Access the samplers.
bool theParallelIntegration
True, if parallel subprocess integration should be enabled.
size_t theUpdateAfter
The number of events after which cross sections should truly be updated.
virtual CrossSection maxXSec() const
Return the overestimated integrated cross section.
virtual double sumWeights2() const
Return the sum of the weights squaredreturned by generate() so far (of the events that were not rejet...
bool weighted() const
True if we should do weighted events.
XML::Element & grids()
Access the XML element containing the grids.
double theMaxWeight
The maximum weight encountered.
bool runCombinationData
True, if information for combining unnormalized runs should be printed out.
bool didReadGrids
True, if grids have already been read.
double theMaxEnhancement
Enhancement factor to the maximum weight.
map< double, Ptr< BinSampler >::ptr > theSamplers
The selector map for the bin samplers.
Ptr< BinSampler >::tptr theLastSampler
The last selected bin sampler.
unsigned int theIntegrationJobsCreated
The number of integration jobs which were actually created.
double theAttempts
The number of attempts.
bool justAfterIntegrate
Indicate that initialization is only reading a grid.
bool theAddUpSamplers
True, if cross sections are to be combined from each sampler individually.
unsigned long maximumExceeds
Number of points which exceeded the maximum.
virtual double attempts() const
bool theWriteGridsOnFinish
True, if grids should be written at the end of a run.
double theMinSelection
A minimum selection probability for each sampler.
bool theGlobalMaximumWeight
True, if the global maximum weight should be used as reference.
double theSumWeights2
The sum of weights squared.
unsigned int integrationJobsCreated()
Return the number of integration jobs which were actually created.
virtual CrossSection maxXSec() const
double maximumExceededBy
The average relative deviation from the maximum weight.
virtual double attempts() const
Return the number of attempts.
bool isSampling
True, if we are generating events.
virtual int lastBin() const
If the sampler is able to sample several different functions separately, this function should return ...
const XML::Element & grids() const
Return the XML element containing the grids.
const map< double, Ptr< BinSampler >::ptr > & samplers() const
Return the samplers.
unsigned int theIntegratePerJob
The number of subprocesses to integrate per job.
Element represents a (tree of) XML elements.
Definition: Element.h:56
virtual CrossSection integratedXSecErr() const
Return the error on the total integrated cross section determined from the Monte Carlo sampling so fa...
pair< double, double > generate(const Generator< Density > &gen, double r)
Generate a random variable and return its weight.
Ptr< BinSampler >::tptr lastSampler() const
Return the last selected bin sampler.
bool theAlmostUnweighted
True, if we should perform an almost unweighted sampling.
double theAccepts
The number of accepts.
virtual CrossSection integratedXSec() const
Return the total integrated cross section determined from the Monte Carlo sampling so far...
double accepts() const
Return the number of accepts.
-*- C++ -*-
bool theFlatSubprocesses
True, if subprocesses should be selected flat.
double correctWeights
The correct cross section as one would exspect with almostUnweighted.
Ptr< BinSampler >::ptr binSampler() const
Return the bin sampler.
vector< IBPtr > IVector
size_t crossSectionCalls
The number of calls to currentCrossSections since the last update.
virtual double sumWeights() const
Return the sum of the weights returned by generate() so far (of the events that were not rejeted)...
double theSumWeights
The sum of weights.
XML::Element theGrids
The XML element containing the grids.