CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/GeneratorInterface/ThePEGInterface/plugins/ThePEGLesHouchesInterface.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <string>
00005 #include <memory>
00006 #include <set>
00007 
00008 #include <boost/shared_ptr.hpp>
00009 
00010 #include <ThePEG/Interface/ClassDocumentation.h>
00011 #include <ThePEG/Interface/InterfacedBase.h>
00012 #include <ThePEG/Interface/Parameter.h>
00013 #include <ThePEG/Utilities/ClassTraits.h>
00014 
00015 #include <ThePEG/LesHouches/LesHouches.h>
00016 #include <ThePEG/LesHouches/LesHouchesReader.h>
00017 
00018 #include "FWCore/Utilities/interface/Exception.h"
00019 
00020 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
00021 
00022 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
00023 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
00024 #include "GeneratorInterface/LHEInterface/interface/LHEProxy.h"
00025 
00026 using namespace lhef;
00027 
00028 namespace ThePEG {
00029 
00030 class LesHouchesInterface : public LesHouchesReader {
00031     public:
00032         LesHouchesInterface();
00033         virtual ~LesHouchesInterface();
00034 
00035         static void Init();
00036 
00037     protected:          
00038         virtual IBPtr clone() const { return new_ptr(*this); }
00039         virtual IBPtr fullclone() const { return new_ptr(*this); }
00040 
00041     private:
00042         virtual void open();
00043         virtual void close();
00044         virtual long scan();
00045 
00046         virtual double eventWeight();
00047         virtual double reweight();
00048         virtual double getEvent();
00049         virtual bool doReadEvent();
00050 
00051         LHEProxy::ProxyID       proxyID;
00052         bool                    initialized;
00053 
00054         static ClassDescription<LesHouchesInterface> initLesHouchesInterface;
00055 };
00056 
00057 // registration with ThePEG plugin system
00058 
00059 template<>
00060 struct BaseClassTrait<LesHouchesInterface, 1> : public ClassTraitsType {
00062         typedef LesHouchesReader NthBase;
00063 };
00064 
00065 template<>
00066 struct ClassTraits<LesHouchesInterface> :
00067                         public ClassTraitsBase<LesHouchesInterface> {
00068         static string className() { return "ThePEG::LesHouchesInterface"; }
00069         static string library() { return "pluginGeneratorInterfaceThePEGHadronisation.so"; }
00070 };
00071 
00072 } // namespace ThePEG
00073 
00074 using namespace ThePEG;
00075 
00076 LesHouchesInterface::LesHouchesInterface() :
00077         initialized(false)
00078 {
00079 }
00080 
00081 LesHouchesInterface::~LesHouchesInterface()
00082 {
00083 }
00084 
00085 long LesHouchesInterface::scan()
00086 {
00087         return 1000000000;
00088 }
00089 
00090 void LesHouchesInterface::open()
00091 {
00092         const LHERunInfo *runInfo = LHEProxy::find(proxyID)->getRunInfo().get();
00093         const lhef::HEPRUP &orig = *runInfo->getHEPRUP();
00094 
00095         heprup.IDBMUP   = orig.IDBMUP;
00096         heprup.EBMUP    = orig.EBMUP;
00097         heprup.PDFGUP   = orig.PDFGUP;
00098         heprup.PDFSUP   = orig.PDFSUP;
00099         heprup.NPRUP    = orig.NPRUP;
00100         heprup.LPRUP    = orig.LPRUP;
00101         heprup.XSECUP   = orig.XSECUP;
00102         heprup.XERRUP   = orig.XERRUP;
00103         heprup.XMAXUP   = orig.XMAXUP;
00104 
00105         // We are cheating here, ThePEG does not need to know the real
00106         // weighting method, as it complains about anything but 3 anyway.
00107         // We just need to trick ThePEG into just processing each event
00108         // passed without doing anything fancy with it (and shut up).
00109         heprup.IDWTUP = 1;
00110 }
00111 
00112 void LesHouchesInterface::close()
00113 {
00114 }
00115 
00116 double LesHouchesInterface::eventWeight()
00117 {
00118         return 1.0;
00119 }
00120 
00121 // no reweighting
00122 double LesHouchesInterface::reweight()
00123 {
00124         preweight = 1.0;
00125         return 1.0;
00126 }
00127 
00128 // overwrite parent routine doing fancy stuff and just pass the event
00129 double LesHouchesInterface::getEvent()
00130 {
00131         reset();
00132 
00133         if (!doReadEvent())
00134                 return 0.0;
00135 
00136         if (!initialized && !checkPartonBin())
00137                 throw cms::Exception("ThePEGLesHouchesInterface")
00138                         << "Found event which cannot be handled by "
00139                         << "the assigned PartonExtractor." << std::endl;
00140         initialized = true;
00141 
00142         fillEvent();
00143         getSubProcess();
00144 
00145         return 1.0;
00146 }
00147 
00148 bool LesHouchesInterface::doReadEvent()
00149 {
00150         reset();
00151 
00152         boost::shared_ptr<LHEEvent> event =
00153                                 LHEProxy::find(proxyID)->releaseEvent();
00154         if (!event)
00155                 throw Stop();
00156 
00157         hepeup.XPDWUP.first = hepeup.XPDWUP.second = 0;
00158 
00159         const lhef::HEPEUP &orig = *event->getHEPEUP();
00160 
00161         hepeup.NUP      = orig.NUP;
00162         hepeup.IDPRUP   = orig.IDPRUP;
00163         hepeup.XWGTUP   = orig.XWGTUP;
00164         hepeup.SCALUP   = orig.SCALUP;
00165         hepeup.AQEDUP   = orig.AQEDUP;
00166         hepeup.AQCDUP   = orig.AQCDUP;
00167         hepeup.resize();
00168 
00169         std::copy(orig.IDUP.begin(), orig.IDUP.end(), hepeup.IDUP.begin());
00170         hepeup.ISTUP    = orig.ISTUP;
00171         hepeup.MOTHUP   = orig.MOTHUP;
00172         hepeup.ICOLUP   = orig.ICOLUP;
00173         hepeup.VTIMUP   = orig.VTIMUP;
00174         hepeup.SPINUP   = orig.SPINUP;
00175 
00176         for(int i = 0; i < hepeup.NUP; i++)
00177                 std::copy(&orig.PUP[i].x[0], &orig.PUP[i].x[5],
00178                           hepeup.PUP[i].begin());
00179 
00180         fillEvent();
00181 
00182         return true;
00183 }
00184 
00185 // register with ThePEG plugin system
00186 
00187 ClassDescription<LesHouchesInterface> LesHouchesInterface::initLesHouchesInterface;
00188 
00189 void LesHouchesInterface::Init() {
00190         typedef LHEProxy::ProxyID ProxyID;
00191 
00192         static ClassDocumentation<LesHouchesInterface> documentation
00193                 ("ThePEG::LesHouchesInterface interfaces with LHEInterface");
00194 
00195         static Parameter<LesHouchesInterface, ProxyID> interfaceProxyID
00196                 ("ProxyID", "The ProxyID.",
00197                  &LesHouchesInterface::proxyID, ProxyID(),
00198                  ProxyID(), ProxyID(), false, false, false);
00199 
00200         interfaceProxyID.rank(11);
00201 }