Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F10881179
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Subscribers
None
View Options
diff --git a/Exsample2/BinSampler.cc b/Exsample2/BinSampler.cc
--- a/Exsample2/BinSampler.cc
+++ b/Exsample2/BinSampler.cc
@@ -1,166 +1,182 @@
// -*- C++ -*-
//
// BinSampler.cc is a part of Herwig++ - A multi-purpose Monte Carlo event generator
// Copyright (C) 2002-2012 The Herwig Collaboration
//
// Herwig++ is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
//
// This is the implementation of the non-inlined, non-templated member
// functions of the BinSampler class.
//
#include "BinSampler.h"
#include "ThePEG/Interface/ClassDocumentation.h"
#include "ThePEG/EventRecord/Particle.h"
#include "ThePEG/Repository/UseRandom.h"
#include "ThePEG/Repository/EventGenerator.h"
#include "ThePEG/Utilities/DescribeClass.h"
#include "ThePEG/Interface/Parameter.h"
#include "ThePEG/Persistency/PersistentOStream.h"
#include "ThePEG/Persistency/PersistentIStream.h"
#include "ThePEG/Handlers/StandardEventHandler.h"
#include "ThePEG/Handlers/StandardXComb.h"
#include <boost/progress.hpp>
using namespace Herwig;
BinSampler::BinSampler()
: MultiIterationStatistics(),
theInitialPoints(1000000),
theEnhanceInitialPoints(1.0),
theOversamplingFactor(1.0),
theBin(-1),
theInitialized(false) {}
BinSampler::~BinSampler() {}
IBPtr BinSampler::clone() const {
return new_ptr(*this);
}
IBPtr BinSampler::fullclone() const {
return new_ptr(*this);
}
string BinSampler::process() const {
ostringstream os("");
const StandardEventHandler& eh = *theEventHandler;
const StandardXComb& xc = *eh.xCombs()[theBin];
os << xc.matrixElement()->name() << " : ";
os << xc.mePartonData()[0]->PDGName() << " "
<< xc.mePartonData()[1]->PDGName() << " -> ";
for ( cPDVector::const_iterator pid =
xc.mePartonData().begin() + 2;
pid != xc.mePartonData().end(); ++pid )
os << (**pid).PDGName() << " ";
return os.str();
}
+string BinSampler::id() const {
+ ostringstream os("");
+ const StandardEventHandler& eh = *theEventHandler;
+ const StandardXComb& xc = *eh.xCombs()[theBin];
+ string name = xc.matrixElement()->name();
+ string::size_type i = name.find_first_of("[");
+ name = name.substr(0,i);
+ os << name << ":";
+ for ( cPDVector::const_iterator pid =
+ xc.mePartonData().begin();
+ pid != xc.mePartonData().end(); ++pid )
+ os << (**pid).id() << (pid != (--xc.mePartonData().end()) ? "," : "");
+ return os.str();
+}
+
+
void BinSampler::generate(bool noMaxInfo) {
double w = 1.;
for ( size_t k = 0; k < lastPoint().size(); ++k ) {
lastPoint()[k] = UseRandom::rnd();
}
try {
w = theEventHandler->dSigDR(lastPoint()) / nanobarn;
} catch (Veto&) {
w = 0.0;
} catch (...) {
throw;
}
if ( abs(w) > maxWeight() && !noMaxInfo ) {
double old = maxWeight();
select(w);
throw NewMaximum(old,abs(w));
}
select(w);
}
void BinSampler::runIteration(unsigned long points, bool progress) {
boost::progress_display* progressBar = 0;
if ( progress ) {
cout << "integrating " << process() << " , iteration "
<< (iterations().size() + 1);
progressBar = new boost::progress_display(points,cout);
}
for ( unsigned long k = 0; k < points; ++k ) {
generate(true);
if ( progress ) {
++(*progressBar);
}
}
if ( progress ) {
cout << "integrated ( "
<< averageWeight() << " +/- " << sqrt(averageWeightVariance())
<< " ) nb\nepsilon = "
<< (abs(maxWeight()) != 0. ? averageAbsWeight()/abs(maxWeight()) : 0.);
if ( !iterations().empty() )
cout << " chi2 = " << chi2();
cout << "\n";
cout << "--------------------------------------------------------------------------------\n";
}
if ( progressBar )
delete progressBar;
}
void BinSampler::initialize(bool progress) {
if ( initialized() )
return;
lastPoint().resize(dimension());
runIteration(initialPoints(),progress);
isInitialized();
}
// If needed, insert default implementations of virtual function defined
// in the InterfacedBase class here (using ThePEG-interfaced-impl in Emacs).
void BinSampler::persistentOutput(PersistentOStream & os) const {
MultiIterationStatistics::put(os);
os << theInitialPoints << theEnhanceInitialPoints
<< theOversamplingFactor << theBin << theInitialized << theLastPoint;
}
void BinSampler::persistentInput(PersistentIStream & is, int) {
MultiIterationStatistics::get(is);
is >> theInitialPoints >> theEnhanceInitialPoints
>> theOversamplingFactor >> theBin >> theInitialized >> theLastPoint;
}
// *** Attention *** The following static variable is needed for the type
// description system in ThePEG. Please check that the template arguments
// are correct (the class and its base class), and that the constructor
// arguments are correct (the class name and the name of the dynamically
// loadable library where the class implementation can be found).
DescribeClass<BinSampler,MultiIterationStatistics>
describeHerwigBinSampler("Herwig::BinSampler", "HwExsample2.so");
void BinSampler::Init() {
static ClassDocumentation<BinSampler> documentation
("BinSampler samples XCombs bins. This default implementation performs flat MC integration.");
static Parameter<BinSampler,unsigned long> interfaceInitialPoints
("InitialPoints",
"The number of points to use for initial integration.",
&BinSampler::theInitialPoints, 1000000, 1, 0,
false, false, Interface::lowerlim);
}
diff --git a/Exsample2/BinSampler.h b/Exsample2/BinSampler.h
--- a/Exsample2/BinSampler.h
+++ b/Exsample2/BinSampler.h
@@ -1,287 +1,292 @@
// -*- C++ -*-
//
// BinSampler.h is a part of Herwig++ - A multi-purpose Monte Carlo event generator
// Copyright (C) 2002-2012 The Herwig Collaboration
//
// Herwig++ is licenced under version 2 of the GPL, see COPYING for details.
// Please respect the MCnet academic guidelines, see GUIDELINES for details.
//
#ifndef Herwig_BinSampler_H
#define Herwig_BinSampler_H
//
// This is the declaration of the BinSampler class.
//
#include "ThePEG/Handlers/StandardEventHandler.h"
#include "ThePEG/Utilities/Exception.h"
#include "ThePEG/Repository/UseRandom.h"
#include "MultiIterationStatistics.h"
namespace Herwig {
using namespace ThePEG;
/**
* \ingroup Matchbox
* \author Simon Platzer
*
* \brief BinSampler samples XCombs bins. This default implementation
* performs flat MC integration.
*
* @see \ref BinSamplerInterfaces "The interfaces"
* defined for BinSampler.
*/
class BinSampler: public Herwig::MultiIterationStatistics {
public:
/** @name Standard constructors and destructors. */
//@{
/**
* The default constructor.
*/
BinSampler();
/**
* The destructor.
*/
virtual ~BinSampler();
//@}
public:
/**
* Clone this object.
*/
Ptr<BinSampler>::ptr cloneMe() const {
return dynamic_ptr_cast<Ptr<BinSampler>::ptr>(clone());
}
public:
/**
* Set the event handler
*/
void eventHandler(tStdEHPtr eh) { theEventHandler = eh; }
/**
* Return the event handler
*/
tStdEHPtr eventHandler() const { return theEventHandler; }
/**
* Return the bin
*/
int bin() const { return theBin; }
/**
* Set the bin
*/
void bin(int b) { theBin = b; }
/**
* Return a string describing the process handled by this sampler.
*/
string process() const;
/**
+ * Return a string identifying the process handled by this sampler.
+ */
+ string id() const;
+
+ /**
* Return the last generated point.
*/
const vector<double>& lastPoint() const { return theLastPoint; }
/**
* Access the last generated point.
*/
vector<double>& lastPoint() { return theLastPoint; }
/**
* Return true, if this bin sampler produces unweighted events.
*/
virtual bool isUnweighting() const { return false; }
/**
* Return true, if this sampler is in a compensating mode.
*/
virtual bool compensating() const { return false; }
/**
* Exception to be thrown, if a new maximum weight has been encountered
* which should be taken care of by the unweighting performed in GeneralSampler
*/
struct NewMaximum {
double oldMaxWeight;
double newMaxWeight;
NewMaximum(double oldm, double newm)
: oldMaxWeight(oldm), newMaxWeight(newm) {}
};
/**
* Exception to be thrown if cross section information should be updated.
*/
struct UpdateCrossSections {};
/**
* Generate the next point; store the point in lastPoint() and its
* weight using select(); if noMaxInfo is true, do not throw
* NewMaximum or UpdateCrossSections exceptions.
*/
virtual void generate(bool noMaxInfo = false);
/**
* Run a single iteration of n points, optionally printing a
* progress bar to cout. Calls generate n times.
*/
void runIteration(unsigned long n, bool progress);
/**
* Initialize this bin sampler. This default version calls runIteration.
*/
virtual void initialize(bool progress);
/**
* Return true, if this sampler has already been initialized.
*/
bool initialized() const { return theInitialized; }
/**
* Indicate that this sampler has already been initialized.
*/
void isInitialized() { theInitialized = true; }
/**
* Finalize this sampler.
*/
virtual void finalize(bool) {}
public:
/**
* Return the dimension.
*/
int dimension() const { return theEventHandler->nDim(bin()); }
/**
* Return the number of points to be used for initial integration.
*/
unsigned long initialPoints() const { return (unsigned long)(theEnhanceInitialPoints*theInitialPoints); }
/**
* Set an enhancement factor for the number of initial points.
*/
void enhanceInitialPoints(double f) { theEnhanceInitialPoints = f; }
/**
* Set an oversampling factor for this sampler.
*/
void oversamplingFactor(double f) { theOversamplingFactor = f; }
/**
* Return enhancement factor for the number of initial points.
*/
double enhanceInitialPoints() const { return theEnhanceInitialPoints; }
/**
* Return the oversampling factor for this sampler.
*/
double oversamplingFactor() const { return theOversamplingFactor; }
public:
/** @name Functions used by the persistent I/O system. */
//@{
/**
* Function used to write out object persistently.
* @param os the persistent output stream written to.
*/
void persistentOutput(PersistentOStream & os) const;
/**
* Function used to read in object persistently.
* @param is the persistent input stream read from.
* @param version the version number of the object when written.
*/
void persistentInput(PersistentIStream & is, int version);
//@}
/**
* The standard Init function used to initialize the interfaces.
* Called exactly once for each class by the class description system
* before the main function starts or
* when this class is dynamically loaded.
*/
static void Init();
protected:
/** @name Clone Methods. */
//@{
/**
* Make a simple clone of this object.
* @return a pointer to the new object.
*/
virtual IBPtr clone() const;
/** Make a clone of this object, possibly modifying the cloned object
* to make it sane.
* @return a pointer to the new object.
*/
virtual IBPtr fullclone() const;
//@}
// If needed, insert declarations of virtual function defined in the
// InterfacedBase class here (using ThePEG-interfaced-decl in Emacs).
private:
/**
* The number of points to use for initial integration.
*/
unsigned long theInitialPoints;
/**
* An enhancement factor for the number of initial points.
*/
double theEnhanceInitialPoints;
/**
* An oversampling factor for this sampler.
*/
double theOversamplingFactor;
/**
* The bin to be sampled.
*/
int theBin;
/**
* Wether or not this sampler has already been initialized.
*/
bool theInitialized;
/**
* The last generated point.
*/
vector<double> theLastPoint;
protected:
/**
* The event handler to be used.
*/
tStdEHPtr theEventHandler;
private:
/**
* The assignment operator is private and must never be called.
* In fact, it should not even be implemented.
*/
BinSampler & operator=(const BinSampler &);
};
}
#endif /* Herwig_BinSampler_H */
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, May 3, 5:58 AM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4982891
Default Alt Text
(12 KB)
Attached To
rHERWIGHG herwighg
Event Timeline
Log In to Comment