herwig
is hosted by
Hepforge
,
IPPP Durham
Herwig
7.3.0
Sampling
BinSampler.h
1
// -*- C++ -*-
2
//
3
// BinSampler.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_BinSampler_H
10
#define Herwig_BinSampler_H
11
//
12
// This is the declaration of the BinSampler class.
13
//
14
15
#include "ThePEG/Handlers/StandardEventHandler.h"
16
#include "ThePEG/Utilities/Exception.h"
17
#include "ThePEG/Repository/UseRandom.h"
18
19
#include "MultiIterationStatistics.h"
20
#include "Remapper.h"
21
22
namespace
Herwig
{
23
24
using namespace
ThePEG
;
25
26
class
GeneralSampler;
27
38
class
BinSampler
:
public
Herwig::MultiIterationStatistics
{
39
40
public
:
41
45
BinSampler
();
46
47
public
:
48
52
Ptr<BinSampler>::ptr
cloneMe
()
const
{
53
return
dynamic_ptr_cast<Ptr<BinSampler>::ptr>(
clone
());
54
}
55
56
public
:
57
61
double
evaluate
(vector<double> p,
62
bool
remap =
true
);
63
68
double
bias
()
const
{
return
theBias
; }
69
73
void
bias
(
double
b) {
theBias
= b; }
74
78
void
eventHandler
(tStdEHPtr eh) {
theEventHandler
= eh; }
79
83
tStdEHPtr
eventHandler
()
const
{
return
theEventHandler
; }
84
88
void
sampler
(Ptr<GeneralSampler>::tptr);
89
93
Ptr<GeneralSampler>::tptr
sampler
()
const
;
94
98
int
bin
()
const
{
return
theBin
; }
99
103
void
bin
(
int
b) {
theBin
= b; }
104
108
string
process
()
const
;
109
113
string
shortprocess
()
const
;
114
118
string
id
()
const
;
119
123
const
vector<double>&
lastPoint
()
const
{
return
theLastPoint
; }
124
128
vector<double>&
lastPoint
() {
return
theLastPoint
; }
129
133
double
referenceWeight
()
const
{
return
theReferenceWeight
; }
134
138
void
referenceWeight
(
double
w) {
theReferenceWeight
= w; }
139
146
virtual
bool
canUnweight
()
const
{
return
true
; }
147
153
virtual
bool
adaptsOnTheFly
()
const
{
return
false
; }
154
159
virtual
bool
compensating
()
const
{
return
false
; }
160
164
bool
weighted
()
const
{
return
theWeighted
; }
165
169
void
doWeighted
(
bool
yes =
true
) {
theWeighted
= yes; }
170
174
struct
NextIteration
{};
175
180
virtual
double
generate
();
181
185
void
fillRemappers
(
bool
progress);
186
190
void
saveRemappers
()
const
;
191
195
void
saveIntegrationData
()
const
;
196
200
virtual
void
saveGrid
()
const
{}
201
205
void
readIntegrationData
();
206
210
void
setupRemappers
(
bool
progress);
211
216
void
runIteration
(
unsigned
long
n,
bool
progress);
217
221
virtual
void
adapt
() {}
222
226
virtual
void
initialize
(
bool
progress);
227
231
bool
initialized
()
const
{
return
theInitialized
; }
232
236
void
isInitialized
() {
theInitialized
=
true
; }
237
241
bool
integrated
()
const
{
return
theIntegrated
; }
242
246
bool
remappersFilled
()
const
{
return
theRemappersFilled
; }
247
251
virtual
bool
existsGrid
()
const
{
return
false
; }
252
256
bool
hasGrids
()
const
{
return
theHasGrids
; }
257
261
void
didReadGrids
() {
theHasGrids
=
true
; }
262
266
virtual
void
finalize
(
bool
);
267
272
virtual
CrossSection
integratedXSec
()
const
{
273
return
averageWeight
()*nanobarn;
274
}
275
280
virtual
CrossSection
integratedXSecErr
()
const
{
281
return
sqrt
(abs(
averageWeightVariance
()))*nanobarn;
282
}
283
289
struct
RandomNumberHistogram
{
290
294
double
lower
;
295
299
map<double,double >
bins
;
300
301
map<double,double > binsw1;
305
RandomNumberHistogram
(
double
low = 0.0,
306
double
up = 1.,
307
unsigned
int
nbins = 20);
308
312
void
book
(
double
inv,
double
weight) {
313
map<double,double>::iterator b =
bins
.upper_bound(inv);
314
if
( b ==
bins
.end() )
return
;
315
b->second = b->second+weight;
316
map<double,double>::iterator b2 = binsw1.upper_bound(inv);
317
if
( b2 == binsw1.end() )
return
;
318
b2->second = b2->second+1.;
319
320
}
321
325
void
dump
(
const
std::string& folder,
const
std::string& prefix,
const
std::string&
process
,
const
int
NR)
const
;
326
327
328
};
329
330
typedef
pair<string,size_t > RandomNumberIndex;
331
332
map<RandomNumberIndex,pair<RandomNumberHistogram,double> > RandomNumberHistograms;
333
334
public
:
335
339
int
dimension
()
const
{
return
theEventHandler
->nDim(
bin
()); }
340
344
unsigned
long
initialPoints
()
const
{
return
theInitialPoints
; }
345
349
void
initialPoints
(
unsigned
long
n) {
theInitialPoints
= n; }
350
354
size_t
nIterations
()
const
{
return
theNIterations
; }
355
359
void
nIterations
(
size_t
n) {
theNIterations
= n; }
360
365
void
enhancementFactor
(
double
f) {
theEnhancementFactor
= f; }
366
371
double
enhancementFactor
()
const
{
return
theEnhancementFactor
; }
372
376
string
randomNumberString
()
const
{
return
theRandomNumbers
;}
377
385
double
kappa
()
const
{
return
theKappa
;}
386
387
public
:
388
395
void
persistentOutput
(
PersistentOStream
& os)
const
;
396
402
void
persistentInput
(
PersistentIStream
& is,
int
version);
404
411
static
void
Init
();
412
413
protected
:
414
421
virtual
IBPtr
clone
()
const
;
422
427
virtual
IBPtr
fullclone
()
const
;
429
430
431
// If needed, insert declarations of virtual function defined in the
432
// InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
433
434
private
:
435
439
double
theBias
;
440
444
bool
theWeighted
;
445
449
unsigned
long
theInitialPoints
;
450
454
size_t
theNIterations
;
455
459
double
theEnhancementFactor
;
460
465
bool
theNonZeroInPresampling
;
466
472
bool
theHalfPoints
;
473
479
int
theMaxNewMax
;
480
484
double
theReferenceWeight
;
485
489
int
theBin
;
490
494
bool
theInitialized
;
495
499
vector<double>
theLastPoint
;
500
504
tStdEHPtr
theEventHandler
;
505
509
Ptr<GeneralSampler>::tptr
theSampler
;
510
514
string
theRandomNumbers
;
515
519
map<size_t,Remapper>
remappers
;
520
524
unsigned
long
theRemapperPoints
;
525
529
bool
theRemapChannelDimension
;
530
534
unsigned
long
theLuminosityMapperBins
;
535
539
unsigned
long
theGeneralMapperBins
;
540
544
double
theRemapperMinSelection
;
545
549
bool
theIntegrated
;
550
554
bool
theRemappersFilled
;
555
559
bool
theHasGrids
;
560
561
562
570
double
theKappa
;
571
572
private
:
573
578
BinSampler
&
operator=
(
const
BinSampler
&) =
delete
;
579
580
};
581
582
}
583
584
#endif
/* Herwig_BinSampler_H */
Herwig::BinSampler
BinSampler samples XCombs bins. This default implementation performs flat MC integration.
Definition:
BinSampler.h:38
Herwig::BinSampler::theInitialized
bool theInitialized
Wether or not this sampler has already been initialized.
Definition:
BinSampler.h:494
Herwig::BinSampler::canUnweight
virtual bool canUnweight() const
Return true, if this sampler can provide unweighted events; if the proposal density is not an overest...
Definition:
BinSampler.h:146
Herwig::BinSampler::dimension
int dimension() const
Return the dimension.
Definition:
BinSampler.h:339
Herwig::BinSampler::integrated
bool integrated() const
Return true, if integration has already been performed.
Definition:
BinSampler.h:241
Herwig::BinSampler::saveGrid
virtual void saveGrid() const
Save grid data.
Definition:
BinSampler.h:200
Herwig::BinSampler::theRandomNumbers
string theRandomNumbers
Folder for the random number plots.
Definition:
BinSampler.h:514
Herwig::BinSampler::theKappa
double theKappa
In the AlmostUnweighted mode we do not need to unweight the events to the reference weight.
Definition:
BinSampler.h:570
Herwig::BinSampler::kappa
double kappa() const
In the AlmostUnweighted mode we do not need to unweight the events to the reference weight.
Definition:
BinSampler.h:385
Herwig::BinSampler::eventHandler
tStdEHPtr eventHandler() const
Return the event handler.
Definition:
BinSampler.h:83
Herwig::BinSampler::theLastPoint
vector< double > theLastPoint
The last generated point.
Definition:
BinSampler.h:499
Herwig::BinSampler::cloneMe
Ptr< BinSampler >::ptr cloneMe() const
Clone this object.
Definition:
BinSampler.h:52
Herwig::BinSampler::initialize
virtual void initialize(bool progress)
Initialize this bin sampler.
Herwig::BinSampler::finalize
virtual void finalize(bool)
Finalize this sampler.
Herwig::BinSampler::theBias
double theBias
The bias with which this sampler is selected.
Definition:
BinSampler.h:439
Herwig::BinSampler::theIntegrated
bool theIntegrated
True, if integration has already be performed.
Definition:
BinSampler.h:549
Herwig::BinSampler::adapt
virtual void adapt()
Adapt this sampler after an iteration has been run.
Definition:
BinSampler.h:221
Herwig::BinSampler::fillRemappers
void fillRemappers(bool progress)
Fill and finalize the remappers present.
Herwig::BinSampler::fullclone
virtual IBPtr fullclone() const
Make a clone of this object, possibly modifying the cloned object to make it sane.
Herwig::BinSampler::integratedXSec
virtual CrossSection integratedXSec() const
Return the total integrated cross section determined from the Monte Carlo sampling so far.
Definition:
BinSampler.h:272
Herwig::BinSampler::nIterations
size_t nIterations() const
Return the number of iterations to be considered for initialization.
Definition:
BinSampler.h:354
Herwig::BinSampler::theBin
int theBin
The bin to be sampled.
Definition:
BinSampler.h:489
Herwig::BinSampler::theRemapperPoints
unsigned long theRemapperPoints
The number of points to be used for initial filling of the remappers.
Definition:
BinSampler.h:524
Herwig::BinSampler::theEventHandler
tStdEHPtr theEventHandler
The event handler to be used.
Definition:
BinSampler.h:504
Herwig::BinSampler::theHalfPoints
bool theHalfPoints
Switch to require that we get half of the points in each iteration below the maximum weight of the it...
Definition:
BinSampler.h:472
Herwig::BinSampler::theMaxNewMax
int theMaxNewMax
The maximum number of allowed new maxima, in combination with HalfPoints, in order to prevent unstabl...
Definition:
BinSampler.h:479
Herwig::BinSampler::sampler
Ptr< GeneralSampler >::tptr sampler() const
Get the containing sampler.
Herwig::BinSampler::weighted
bool weighted() const
Return true, if weighted events should be generated.
Definition:
BinSampler.h:164
Herwig::BinSampler::existsGrid
virtual bool existsGrid() const
Return true, if grid data exists for this sampler.
Definition:
BinSampler.h:251
Herwig::BinSampler::clone
virtual IBPtr clone() const
Make a simple clone of this object.
Herwig::BinSampler::theRemapChannelDimension
bool theRemapChannelDimension
True if channels should get a remapper.
Definition:
BinSampler.h:529
Herwig::BinSampler::remappersFilled
bool remappersFilled() const
Return true, if remappers have been set up.
Definition:
BinSampler.h:246
Herwig::BinSampler::theReferenceWeight
double theReferenceWeight
The reference weight to be used.
Definition:
BinSampler.h:484
Herwig::BinSampler::theNonZeroInPresampling
bool theNonZeroInPresampling
Switch to count only non zero weights in presampling.
Definition:
BinSampler.h:465
Herwig::BinSampler::initialPoints
unsigned long initialPoints() const
Return the number of points to be used for initial integration.
Definition:
BinSampler.h:344
Herwig::BinSampler::theGeneralMapperBins
unsigned long theGeneralMapperBins
The number of bins to be used for any other dimension.
Definition:
BinSampler.h:539
Herwig::BinSampler::theLuminosityMapperBins
unsigned long theLuminosityMapperBins
The number of bins to be used for luminosity dimensions.
Definition:
BinSampler.h:534
Herwig::BinSampler::saveIntegrationData
void saveIntegrationData() const
Write integration data to grid files.
Herwig::BinSampler::operator=
BinSampler & operator=(const BinSampler &)=delete
The assignment operator is private and must never be called.
Herwig::BinSampler::theNIterations
size_t theNIterations
The number of iterations to be considered for initialization.
Definition:
BinSampler.h:454
Herwig::BinSampler::theRemappersFilled
bool theRemappersFilled
True, if remappers have been set up.
Definition:
BinSampler.h:554
Herwig::BinSampler::integratedXSecErr
virtual CrossSection integratedXSecErr() const
Return the error on the total integrated cross section determined from the Monte Carlo sampling so fa...
Definition:
BinSampler.h:280
Herwig::BinSampler::lastPoint
const vector< double > & lastPoint() const
Return the last generated point.
Definition:
BinSampler.h:123
Herwig::BinSampler::BinSampler
BinSampler()
The default constructor.
Herwig::BinSampler::theHasGrids
bool theHasGrids
True, if this sampler has already read grid data.
Definition:
BinSampler.h:559
Herwig::BinSampler::persistentOutput
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
Herwig::BinSampler::adaptsOnTheFly
virtual bool adaptsOnTheFly() const
Return true, if this sampler adapts on the fly while generating events.
Definition:
BinSampler.h:153
Herwig::BinSampler::eventHandler
void eventHandler(tStdEHPtr eh)
Set the event handler.
Definition:
BinSampler.h:78
Herwig::BinSampler::theSampler
Ptr< GeneralSampler >::tptr theSampler
The containing sampler.
Definition:
BinSampler.h:509
Herwig::BinSampler::Init
static void Init()
The standard Init function used to initialize the interfaces.
Herwig::BinSampler::randomNumberString
string randomNumberString() const
Return the folder for the random number plots.
Definition:
BinSampler.h:376
Herwig::BinSampler::referenceWeight
double referenceWeight() const
Return the reference weight to be used.
Definition:
BinSampler.h:133
Herwig::BinSampler::remappers
map< size_t, Remapper > remappers
Remapper objects indexed by dimension.
Definition:
BinSampler.h:519
Herwig::BinSampler::referenceWeight
void referenceWeight(double w)
Set the reference weight to be used.
Definition:
BinSampler.h:138
Herwig::BinSampler::bias
void bias(double b)
Set the bias with which this sampler is selected.
Definition:
BinSampler.h:73
Herwig::BinSampler::runIteration
void runIteration(unsigned long n, bool progress)
Run a single iteration of n points, optionally printing a progress bar to cout.
Herwig::BinSampler::hasGrids
bool hasGrids() const
Return true, if this sampler has already read grid data.
Definition:
BinSampler.h:256
Herwig::BinSampler::nIterations
void nIterations(size_t n)
Set the number of iterations to be considered for initialization.
Definition:
BinSampler.h:359
Herwig::BinSampler::theInitialPoints
unsigned long theInitialPoints
The number of points to use for initial integration.
Definition:
BinSampler.h:449
Herwig::BinSampler::theEnhancementFactor
double theEnhancementFactor
Factor to enhance the number of points for the next iteration.
Definition:
BinSampler.h:459
Herwig::BinSampler::bin
int bin() const
Return the bin.
Definition:
BinSampler.h:98
Herwig::BinSampler::id
string id() const
Return a string identifying the process handled by this sampler.
Herwig::BinSampler::persistentInput
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
Herwig::BinSampler::didReadGrids
void didReadGrids()
Indicate that this sampler has already read grid data.
Definition:
BinSampler.h:261
Herwig::BinSampler::generate
virtual double generate()
Generate the next point and return its weight; store the point in lastPoint().
Herwig::BinSampler::lastPoint
vector< double > & lastPoint()
Access the last generated point.
Definition:
BinSampler.h:128
Herwig::BinSampler::saveRemappers
void saveRemappers() const
Write remappers to grid file.
Herwig::BinSampler::initialPoints
void initialPoints(unsigned long n)
Set the number of points to be used for initial integration.
Definition:
BinSampler.h:349
Herwig::BinSampler::setupRemappers
void setupRemappers(bool progress)
Read remappers from grid file.
Herwig::BinSampler::sampler
void sampler(Ptr< GeneralSampler >::tptr)
Set the containing sampler.
Herwig::BinSampler::bias
double bias() const
Return the bias with which this sampler is selected.
Definition:
BinSampler.h:68
Herwig::BinSampler::enhancementFactor
double enhancementFactor() const
Return the factor to enhance the number of points for the next iteration.
Definition:
BinSampler.h:371
Herwig::BinSampler::theRemapperMinSelection
double theRemapperMinSelection
The minimum selection probability for remapper bins.
Definition:
BinSampler.h:544
Herwig::BinSampler::theWeighted
bool theWeighted
True, if weighted events should be generated.
Definition:
BinSampler.h:444
Herwig::BinSampler::isInitialized
void isInitialized()
Indicate that this sampler has already been initialized.
Definition:
BinSampler.h:236
Herwig::BinSampler::process
string process() const
Return a string describing the process handled by this sampler.
Herwig::BinSampler::enhancementFactor
void enhancementFactor(double f)
Set the factor to enhance the number of points for the next iteration.
Definition:
BinSampler.h:365
Herwig::BinSampler::compensating
virtual bool compensating() const
If this sampler features a compensation algorithm, return true if more events need to be generated to...
Definition:
BinSampler.h:159
Herwig::BinSampler::evaluate
double evaluate(vector< double > p, bool remap=true)
Evaluate the cross section.
Herwig::BinSampler::shortprocess
string shortprocess() const
Return a short string describing the process handled by this sampler.
Herwig::BinSampler::initialized
bool initialized() const
Return true, if this sampler has already been initialized.
Definition:
BinSampler.h:231
Herwig::BinSampler::readIntegrationData
void readIntegrationData()
Read integration data from grid files.
Herwig::BinSampler::doWeighted
void doWeighted(bool yes=true)
Indicate that weighted events should be generated.
Definition:
BinSampler.h:169
Herwig::BinSampler::bin
void bin(int b)
Set the bin.
Definition:
BinSampler.h:103
Herwig::GeneralStatistics::averageWeight
virtual double averageWeight() const
Return the average weight.
Definition:
GeneralStatistics.h:133
Herwig::GeneralStatistics::averageWeightVariance
virtual double averageWeightVariance() const
Return the variance of the average weight.
Definition:
GeneralStatistics.h:165
Herwig::MultiIterationStatistics
Monte Carlo statistics for multiple iterations.
Definition:
MultiIterationStatistics.h:27
ThePEG::PersistentIStream
ThePEG::PersistentOStream
Herwig
-*- C++ -*-
Definition:
BasicConsistency.h:17
ThePEG
ThePEG::sqrt
double sqrt(int x)
ThePEG::IBPtr
ThePEG::Ptr< InterfacedBase >::pointer IBPtr
Herwig::BinSampler::NextIteration
Exception to be thrown if cross section information should be updated.
Definition:
BinSampler.h:174
Herwig::BinSampler::RandomNumberHistogram
Define the key for the collinear subtraction data.
Definition:
BinSampler.h:289
Herwig::BinSampler::RandomNumberHistogram::dump
void dump(const std::string &folder, const std::string &prefix, const std::string &process, const int NR) const
Write to file given name and invariant.
Herwig::BinSampler::RandomNumberHistogram::lower
double lower
The lower bound.
Definition:
BinSampler.h:294
Herwig::BinSampler::RandomNumberHistogram::RandomNumberHistogram
RandomNumberHistogram(double low=0.0, double up=1., unsigned int nbins=20)
Constructor.
Herwig::BinSampler::RandomNumberHistogram::book
void book(double inv, double weight)
Book an event.
Definition:
BinSampler.h:312
Herwig::BinSampler::RandomNumberHistogram::bins
map< double, double > bins
The bins, indexed by upper bound.
Definition:
BinSampler.h:299
Generated on Thu Jun 20 2024 17:50:53 for Herwig by
1.9.6