00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ThePEG_ACDCSampler_H
00010 #define ThePEG_ACDCSampler_H
00011
00012
00013 #include "ThePEG/Handlers/SamplerBase.h"
00014 #include "ThePEG/ACDC/ACDCGen.h"
00015 #include "ThePEG/Handlers/StandardEventHandler.h"
00016 #include "ThePEG/Repository/RandomGenerator.h"
00017 #include "ThePEG/Repository/UseRandom.h"
00018 #include "ThePEG/Utilities/SimplePhaseSpace.xh"
00019
00020
00021
00022
00023 namespace ThePEG {
00024
00034 class ACDCSampler: public SamplerBase {
00035
00036 public:
00037
00039 typedef ACDCGenerator::ACDCGen<UseRandom,tStdEHPtr> SamplerType;
00040
00046 ACDCSampler() : theEps(100*Constants::epsilon), theMargin(1.1), theNTry(1000) {}
00047
00051 ACDCSampler(const ACDCSampler & x)
00052 : SamplerBase(x), theSampler(),
00053 theEps(x.theEps), theMargin(x.theMargin),
00054 theNTry(x.theNTry) {}
00055
00059 virtual ~ACDCSampler();
00061
00062 public:
00063
00070 virtual void initialize();
00071
00076 virtual double generate();
00077
00083 virtual int lastBin() const;
00084
00088 virtual void rejectLast();
00089
00094 virtual CrossSection integratedXSec() const;
00095
00100 virtual CrossSection integratedXSecErr() const;
00101
00105 virtual CrossSection maxXSec() const;
00106
00111 virtual double sumWeights() const;
00112
00114
00115 public:
00116
00123 void persistentOutput(PersistentOStream & os) const;
00124
00130 void persistentInput(PersistentIStream & is, int version);
00132
00139 static void Init();
00140
00141 protected:
00142
00149 virtual IBPtr clone() const;
00150
00155 virtual IBPtr fullclone() const;
00156
00158
00159 protected:
00160
00167 virtual void doinitrun();
00168
00173 virtual void dofinish();
00175
00176 private:
00177
00181 SamplerType theSampler;
00182
00186 double theEps;
00187
00191 double theMargin;
00192
00196 int theNTry;
00197
00198 protected:
00199
00203 struct ACDCStillCompensating: public Exception {};
00204
00207 struct EventInitNoXSec: public InitException {};
00208
00212 struct EventLoopException: public Exception {};
00215 private:
00216
00220 static ClassDescription<ACDCSampler> initACDCSampler;
00221
00225 ACDCSampler & operator=(const ACDCSampler &);
00226
00227 };
00228
00229 }
00230
00231 namespace ThePEG {
00232
00239 template <>
00240 struct BaseClassTrait<ACDCSampler,1>: public ClassTraitsType {
00242 typedef SamplerBase NthBase;
00243 };
00244
00249 template <>
00250 struct ClassTraits<ACDCSampler>: public ClassTraitsBase<ACDCSampler> {
00254 static string className() { return "ThePEG::ACDCSampler"; }
00259 static string library() { return "ACDCSampler.so"; }
00260
00261 };
00262
00265 }
00266
00267 namespace ACDCGenerator {
00268
00274 template <>
00275 struct ACDCFncTraits<ThePEG::tStdEHPtr>: public ACDCTraitsType {
00277 typedef ThePEG::tStdEHPtr tStdEHPtr;
00282 static inline double value(const tStdEHPtr & eh, const DVector & x) {
00283 using namespace ThePEG::Units;
00284 try {
00285 return eh->dSigDR(x)/nanobarn;
00286 }
00287 catch ( ThePEG::ImpossibleKinematics & v ) {
00288 breakThePEG();
00289 }
00290 catch ( std::exception & e ) {
00291 breakThePEG();
00292 }
00293 catch ( ... ) {
00294 breakThePEG();
00295 }
00296 return 0.0;
00297 }
00298
00299 };
00300
00303 template <>
00304 struct ACDCRandomTraits<ThePEG::UseRandom>: public ACDCTraitsType {
00306 typedef ThePEG::UseRandom UseRandom;
00307
00311 static inline double rnd(UseRandom *) { return UseRandom::rnd(); }
00312
00316 static inline double rnd(UseRandom * r, double xl, double xu) {
00317 return xl + (xu - xl)*rnd(r);
00318 }
00319
00331 template <typename InputIterator, typename OutputIterator>
00332 static inline void rnd(UseRandom * r,
00333 InputIterator l, InputIterator lend,
00334 InputIterator u, OutputIterator res) {
00335 for ( ; l != lend; ++l ) *res++ = *l + (*u++ - *l)*rnd(r);
00336 }
00337
00342 template <typename OutputIterator>
00343 static inline void rnd(UseRandom * r, int D, OutputIterator res) {
00344 for ( int d = 0; d < D; ++d ) *res++ = rnd(r);
00345 }
00346
00350 static inline bool rndBool(UseRandom, double x) {
00351 return UseRandom::rndbool(x);
00352 }
00353
00357 static inline bool rndBool(UseRandom *, double x, double y) {
00358 return UseRandom::rndbool(x, y);
00359 }
00360
00364 static inline long rndInt(UseRandom *, long x) {
00365 return UseRandom::irnd(x);
00366 }
00367
00368 };
00369
00372 }
00373
00374 #endif