File indexing completed on 2026-08-06 09:24:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef Herwig_BinSampler_H
0010 #define Herwig_BinSampler_H
0011
0012
0013
0014
0015 #include "ThePEG/Handlers/StandardEventHandler.h"
0016 #include "ThePEG/Utilities/Exception.h"
0017 #include "ThePEG/Repository/UseRandom.h"
0018
0019 #include "MultiIterationStatistics.h"
0020 #include "Remapper.h"
0021
0022 namespace Herwig {
0023
0024 using namespace ThePEG;
0025
0026 class GeneralSampler;
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class BinSampler: public Herwig::MultiIterationStatistics {
0039
0040 public:
0041
0042
0043
0044
0045 BinSampler();
0046
0047 public:
0048
0049
0050
0051
0052 Ptr<BinSampler>::ptr cloneMe() const {
0053 return dynamic_ptr_cast<Ptr<BinSampler>::ptr>(clone());
0054 }
0055
0056 public:
0057
0058
0059
0060
0061 double evaluate(vector<double> p,
0062 bool remap = true);
0063
0064
0065
0066
0067
0068 double bias() const { return theBias; }
0069
0070
0071
0072
0073 void bias(double b) { theBias = b; }
0074
0075
0076
0077
0078 void eventHandler(tStdEHPtr eh) { theEventHandler = eh; }
0079
0080
0081
0082
0083 tStdEHPtr eventHandler() const { return theEventHandler; }
0084
0085
0086
0087
0088 void sampler(Ptr<GeneralSampler>::tptr);
0089
0090
0091
0092
0093 Ptr<GeneralSampler>::tptr sampler() const;
0094
0095
0096
0097
0098 int bin() const { return theBin; }
0099
0100
0101
0102
0103 void bin(int b) { theBin = b; }
0104
0105
0106
0107
0108 string process() const;
0109
0110
0111
0112
0113 string shortprocess() const;
0114
0115
0116
0117
0118 string id() const;
0119
0120
0121
0122
0123 const vector<double>& lastPoint() const { return theLastPoint; }
0124
0125
0126
0127
0128 vector<double>& lastPoint() { return theLastPoint; }
0129
0130
0131
0132
0133 double referenceWeight() const { return theReferenceWeight; }
0134
0135
0136
0137
0138 void referenceWeight(double w) { theReferenceWeight = w; }
0139
0140
0141
0142
0143
0144
0145
0146 virtual bool canUnweight() const { return true; }
0147
0148
0149
0150
0151
0152
0153 virtual bool adaptsOnTheFly() const { return false; }
0154
0155
0156
0157
0158
0159 virtual bool compensating() const { return false; }
0160
0161
0162
0163
0164 bool weighted() const { return theWeighted; }
0165
0166
0167
0168
0169 void doWeighted(bool yes = true) { theWeighted = yes; }
0170
0171
0172
0173
0174 struct NextIteration {};
0175
0176
0177
0178
0179
0180 virtual double generate();
0181
0182
0183
0184
0185 void fillRemappers(bool progress);
0186
0187
0188
0189
0190 void saveRemappers() const;
0191
0192
0193
0194
0195 void saveIntegrationData() const;
0196
0197
0198
0199
0200 virtual void saveGrid() const {}
0201
0202
0203
0204
0205 void readIntegrationData();
0206
0207
0208
0209
0210 void setupRemappers(bool progress);
0211
0212
0213
0214
0215
0216 void runIteration(unsigned long n, bool progress);
0217
0218
0219
0220
0221 virtual void adapt() {}
0222
0223
0224
0225
0226 virtual void initialize(bool progress);
0227
0228
0229
0230
0231 bool initialized() const { return theInitialized; }
0232
0233
0234
0235
0236 void isInitialized() { theInitialized = true; }
0237
0238
0239
0240
0241 bool integrated() const { return theIntegrated; }
0242
0243
0244
0245
0246 bool remappersFilled() const { return theRemappersFilled; }
0247
0248
0249
0250
0251 virtual bool existsGrid() const { return false; }
0252
0253
0254
0255
0256 bool hasGrids() const { return theHasGrids; }
0257
0258
0259
0260
0261 void didReadGrids() { theHasGrids = true; }
0262
0263
0264
0265
0266 virtual void finalize(bool);
0267
0268
0269
0270
0271
0272 virtual CrossSection integratedXSec() const {
0273 return averageWeight()*nanobarn;
0274 }
0275
0276
0277
0278
0279
0280 virtual CrossSection integratedXSecErr() const {
0281 return sqrt(abs(averageWeightVariance()))*nanobarn;
0282 }
0283
0284
0285
0286
0287
0288
0289 struct RandomNumberHistogram {
0290
0291
0292
0293
0294 double lower;
0295
0296
0297
0298
0299 map<double,double > bins;
0300
0301 map<double,double > binsw1;
0302
0303
0304
0305 RandomNumberHistogram(double low = 0.0,
0306 double up = 1.,
0307 unsigned int nbins = 20);
0308
0309
0310
0311
0312 void book(double inv, double weight) {
0313 map<double,double>::iterator b = bins.upper_bound(inv);
0314 if ( b == bins.end() ) return;
0315 b->second = b->second+weight;
0316 map<double,double>::iterator b2 = binsw1.upper_bound(inv);
0317 if ( b2 == binsw1.end() ) return;
0318 b2->second = b2->second+1.;
0319
0320 }
0321
0322
0323
0324
0325 void dump(const std::string& folder,const std::string& prefix, const std::string& process,const int NR)const;
0326
0327
0328 };
0329
0330 typedef pair<string,size_t > RandomNumberIndex;
0331
0332 map<RandomNumberIndex,pair<RandomNumberHistogram,double> > RandomNumberHistograms;
0333
0334 public:
0335
0336
0337
0338
0339 int dimension() const { return theEventHandler->nDim(bin()); }
0340
0341
0342
0343
0344 unsigned long initialPoints() const { return theInitialPoints; }
0345
0346
0347
0348
0349 void initialPoints(unsigned long n) { theInitialPoints = n; }
0350
0351
0352
0353
0354 size_t nIterations() const { return theNIterations; }
0355
0356
0357
0358
0359 void nIterations(size_t n) { theNIterations = n; }
0360
0361
0362
0363
0364
0365 void enhancementFactor(double f) { theEnhancementFactor = f; }
0366
0367
0368
0369
0370
0371 double enhancementFactor() const { return theEnhancementFactor; }
0372
0373
0374
0375
0376 string randomNumberString() const {return theRandomNumbers;}
0377
0378
0379
0380
0381
0382
0383
0384
0385 double kappa() const {return theKappa;}
0386
0387 public:
0388
0389
0390
0391
0392
0393
0394
0395 void persistentOutput(PersistentOStream & os) const;
0396
0397
0398
0399
0400
0401
0402 void persistentInput(PersistentIStream & is, int version);
0403
0404
0405
0406
0407
0408
0409
0410
0411 static void Init();
0412
0413 protected:
0414
0415
0416
0417
0418
0419
0420
0421 virtual IBPtr clone() const;
0422
0423
0424
0425
0426
0427 virtual IBPtr fullclone() const;
0428
0429
0430
0431
0432
0433
0434 private:
0435
0436
0437
0438
0439 double theBias;
0440
0441
0442
0443
0444 bool theWeighted;
0445
0446
0447
0448
0449 unsigned long theInitialPoints;
0450
0451
0452
0453
0454 size_t theNIterations;
0455
0456
0457
0458
0459 double theEnhancementFactor;
0460
0461
0462
0463
0464
0465 bool theNonZeroInPresampling;
0466
0467
0468
0469
0470
0471
0472 bool theHalfPoints;
0473
0474
0475
0476
0477
0478
0479 int theMaxNewMax;
0480
0481
0482
0483
0484 double theReferenceWeight;
0485
0486
0487
0488
0489 int theBin;
0490
0491
0492
0493
0494 bool theInitialized;
0495
0496
0497
0498
0499 vector<double> theLastPoint;
0500
0501
0502
0503
0504 tStdEHPtr theEventHandler;
0505
0506
0507
0508
0509 Ptr<GeneralSampler>::tptr theSampler;
0510
0511
0512
0513
0514 string theRandomNumbers;
0515
0516
0517
0518
0519 map<size_t,Remapper> remappers;
0520
0521
0522
0523
0524 unsigned long theRemapperPoints;
0525
0526
0527
0528
0529 bool theRemapChannelDimension;
0530
0531
0532
0533
0534 unsigned long theLuminosityMapperBins;
0535
0536
0537
0538
0539 unsigned long theGeneralMapperBins;
0540
0541
0542
0543
0544 double theRemapperMinSelection;
0545
0546
0547
0548
0549 bool theIntegrated;
0550
0551
0552
0553
0554 bool theRemappersFilled;
0555
0556
0557
0558
0559 bool theHasGrids;
0560
0561
0562
0563
0564
0565
0566
0567
0568
0569
0570 double theKappa;
0571
0572 private:
0573
0574
0575
0576
0577
0578 BinSampler & operator=(const BinSampler &) = delete;
0579
0580 };
0581
0582 }
0583
0584 #endif