herwig is hosted by Hepforge, IPPP Durham
Herwig 7.3.0
MPISampler.h
1// -*- C++ -*-
2//
3// MPISampler.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_MPISampler_H
10#define Herwig_MPISampler_H
11// This is the declaration of the MPISampler class.
12
13#include "ThePEG/Handlers/SamplerBase.h"
14#include "ThePEG/ACDC/ACDCGen.h"
15#include "ThePEG/Repository/RandomGenerator.h"
16#include "ThePEG/Repository/UseRandom.h"
17#include "ThePEG/Utilities/SimplePhaseSpace.xh"
18#include "MPISampler.fh"
19
20#include "ProcessHandler.h"
21
22namespace Herwig {
23
24 using namespace ThePEG;
25
38class MPISampler: public SamplerBase {
39
40public:
41
44
50 inline MPISampler();
51
55 inline MPISampler(const MPISampler &);
56
60 virtual ~MPISampler();
62
63public:
64
71 inline void setProcessHandler(tProHdlPtr mpih);
72
77 virtual void initialize();
78
83 virtual double generate();
84
90 virtual int lastBin() const;
91
95 virtual void rejectLast();
96
101 virtual CrossSection integratedXSec() const;
102
107 virtual CrossSection integratedXSecErr() const;
108
112 virtual CrossSection maxXSec() const;
113
118 virtual double sumWeights() const;
119
124 virtual double sumWeights2() const;
126
127public:
128
136
142 void persistentInput(PersistentIStream & is, int version);
144
151 static void Init();
152
153protected:
154
161 inline virtual IBPtr clone() const;
162
167 inline virtual IBPtr fullclone() const;
168
170
171protected:
172
178 inline virtual void doupdate();
179
185 inline virtual void doinit();
186
191 virtual void doinitrun();
192
197 virtual void dofinish();
198
199
208 inline virtual void rebind(const TranslationMap & trans)
209 ;
210
215 inline virtual IVector getReferences();
217
218private:
219
224
229
233 double theEps;
234
238 double theMargin;
239
244
245protected:
246
250 struct ACDCStillCompensating: public Exception {};
251
254 struct EventInitNoXSec: public Exception {};
255
259 struct EventLoopException: public Exception {};
262private:
263
267 MPISampler & operator=(const MPISampler &) = delete;
268
269};
270
271}
272
273namespace ACDCGenerator {
274
280template <>
281struct ACDCFncTraits<Herwig::tProHdlPtr>: public ACDCTraitsType {
283 typedef Herwig::tProHdlPtr tProHdlPtr;
288 static inline double value(const tProHdlPtr & mpih, const DVector & x) {
289 using namespace ThePEG::Units;
290 try {
291 return mpih->dSigDR(x)/nanobarn;
292 }
293 catch ( ThePEG::ImpossibleKinematics & v ) {
294 breakThePEG();
295 }
296 catch ( std::exception & e ) {
297 breakThePEG();
298 }
299 catch ( ... ) {
300 breakThePEG();
301 }
302 return 0.0;
303 }
304
305};
306
309template <>
310struct ACDCRandomTraits<ThePEG::UseRandom>: public ACDCTraitsType {
313
317 static inline double rnd(UseRandom *) { return UseRandom::rnd(); }
318
322 static inline double rnd(UseRandom * r, double xl, double xu) {
323 return xl + (xu - xl)*rnd(r);
324 }
325
337 template <typename InputIterator, typename OutputIterator>
338 static inline void rnd(UseRandom * r,
339 InputIterator l, InputIterator lend,
340 InputIterator u, OutputIterator res) {
341 for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
342 }
343
348 template <typename OutputIterator>
349 static inline void rnd(UseRandom * r, int D, OutputIterator res) {
350 for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
351 }
352
356 static inline bool rndBool(UseRandom, double x) {
357 return UseRandom::rndbool(x);
358 }
359
363 static inline bool rndBool(UseRandom *, double x, double y) {
364 return UseRandom::rndbool(x, y);
365 }
366
370 static inline long rndInt(UseRandom *, long x) {
371 return UseRandom::irnd(x);
372 }
373
374};
375
378}
379
380#include "MPISampler.icc"
381
382#endif /* Herwig_MPISampler_H */
This class inherits from SampleBase and implements the Auto Compensating Divide-and-Conquer phase spa...
Definition: MPISampler.h:38
ACDCGenerator::ACDCGen< UseRandom, tProHdlPtr > SamplerType
Typedef the underlying ACDCGen class.
Definition: MPISampler.h:43
virtual double generate()
Generarate a new phase space point and return a weight associated with it.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
MPISampler()
The default constructor.
MPISampler(const MPISampler &)
The copy constructor.
virtual void initialize()
Initialize the sampler, possibly doing presampling of the phase space.
virtual CrossSection integratedXSec() const
Return the total integrated cross section determined from the Monte Carlo sampling so far.
double theEps
The smallest possible division allowed.
Definition: MPISampler.h:233
static void Init()
The standard Init function used to initialize the interfaces.
void setProcessHandler(tProHdlPtr mpih)
Method to set the connected ProcessHandler pointer.
virtual void dofinish()
Finalize this object.
MPISampler & operator=(const MPISampler &)=delete
Private and non-existent assignment operator.
virtual void rejectLast()
Reject the last chosen phase space point.
virtual CrossSection integratedXSecErr() const
Return the error on the total integrated cross section determined from the Monte Carlo sampling so fa...
virtual double sumWeights2() const
Return the sum of the weights squared returned by generate() so far (of the events that were not reje...
virtual ~MPISampler()
The destructor.
double theMargin
The factor controlling the loss of efficiency when compensating.
Definition: MPISampler.h:238
SamplerType theSampler
The actual sampler object.
Definition: MPISampler.h:223
virtual void doinitrun()
Initialize this object.
virtual CrossSection maxXSec() const
Return the overestimated integrated cross section.
virtual void doupdate()
Check sanity of the object during the setup phase.
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
virtual void doinit()
Initialize this object after the setup phase before saving an EventGenerator to disk.
tProHdlPtr theProcessHandler
The ProcessHandler that calls us.
Definition: MPISampler.h:228
virtual IBPtr clone() const
Make a simple clone of this object.
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
int theNTry
The number of points to use to find initial average.
Definition: MPISampler.h:243
virtual void rebind(const TranslationMap &trans)
Rebind pointer to other Interfaced objects.
virtual int lastBin() const
ACDCSampler is able to sample several different functions separately.
virtual double sumWeights() const
Return the sum of the weights returned by generate() so far (of the events that were not rejeted).
virtual IVector getReferences()
Return a vector of all pointers to Interfaced objects used in this object.
vector< double > DVector
-*- C++ -*-
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
vector< IBPtr > IVector
static double value(const FncPtr &f, const DVector &x)
static long rndInt(Rnd *r, long x)
static double rnd(Rnd *r)
static bool rndBool(Rnd *r, double x)