CMS 3D CMS Logo

SherpaSource.cc

Go to the documentation of this file.
00001 /*
00002  *  $Revision: 1.5.2.1 $
00003  *  
00004  *  Martin Niegel 
00005  *  niegel@cern.ch
00006  *  20/03/2007
00007  * 
00008  */
00009 
00010 
00011 
00012 #include "SHERPA-MC/Message.H"
00013 #include "SHERPA-MC/prof.hh"
00014 #include "SHERPA-MC/Random.H"
00015 #include "SHERPA-MC/Exception.H"
00016 #include "SHERPA-MC/Run_Parameter.H"
00017 #include "SHERPA-MC/My_Root.H"
00018 #include "SHERPA-MC/Input_Output_Handler.H"
00019 
00020 #include "GeneratorInterface/SherpaInterface/interface/SherpaSource.h"
00021 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "FWCore/ServiceRegistry/interface/Service.h"
00024 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00025 #include "CLHEP/Random/RandomEngine.h"
00026 //#include "CLHEP/Random/RandFlat.h"
00027 
00028 
00029 #include <iostream>
00030 #include "time.h"
00031 
00032 using namespace edm;
00033 using namespace std;
00034 using namespace SHERPA;
00035 using namespace HepMC;
00036 
00037 
00038 // Generator modifications
00039 // ***********************
00040 
00041 
00042 //HepMC::ConvertHEPEVT conv
00043 // ***********************
00044 //#include "HepMC/IO_Ascii.h"
00045 #include "SHERPA-MC/HepMC2_Interface.H"
00046 
00047 
00048 
00049 //used for defaults
00050 //  static const unsigned long kNanoSecPerSec = 1000000000;
00051 //  static const unsigned long kAveEventPerSec = 200;
00052 
00053 SherpaSource::SherpaSource( const ParameterSet & pset, 
00054                             InputSourceDescription const& desc ) :
00055   GeneratedInputSource(pset, desc), evt(0),
00056   libDir_(pset.getUntrackedParameter<string>("libDir","Sherpa_Process")),
00057   resultDir_(pset.getUntrackedParameter<string>("resultDir","Result"))
00058   
00059 {
00060 
00061   libDir_    =  pset.getUntrackedParameter<string>("libDir","Sherpa_Process");
00062   resultDir_ =  pset.getUntrackedParameter<string>("resultDir","Result");
00063 
00064    string shRun  = "./Sherpa";
00065    string shPath = "PATH=" + libDir_;
00066    string shRes  = "RESULT_DIRECTORY=" + libDir_ + "/" + resultDir_;
00067    string shRng  = "EXTERNAL_RNG=CMS_RNG";
00068    char* argv[4];
00069    argv[0]=(char*)shRun.c_str();
00070    argv[1]=(char*)shPath.c_str();
00071    argv[2]=(char*)shRes.c_str();
00072    argv[3]=(char*)shRng.c_str();
00073 
00074   set_prof();   
00075   cout << "SherpaSource: initializing Sherpa. " << endl;
00076   Generator.InitializeTheRun(4,argv);
00077   cout << "SherpaSource: InitializeTheRun(argc,argv)" << endl;
00078   Generator.InitializeTheEventHandler();
00079   cout << "SherpaSource: InitializeTheEventHandler() " << endl;
00080   produces<HepMCProduct>();
00081   cout << "SherpaSource: starting event generation ... " << endl;
00082 
00083 
00084 }
00085 
00086 
00087 SherpaSource::~SherpaSource(){
00088   cout << "SherpaSource: summarizing the run " << endl;
00089   Generator.SummarizeRun();
00090   cout << "SherpaSource: event generation done. " << endl;
00091   clear(); 
00092 }
00093 
00094 void SherpaSource::clear() {
00095  
00096 }
00097 
00098 
00099 bool SherpaSource::produce(Event & e) {
00100 
00101  auto_ptr<HepMCProduct> bare_product(new HepMCProduct);   
00102 
00103  if (Generator.GenerateOneEvent()) { 
00104   HepMC::GenEvent* evt = Generator.GetIOHandler()->GetHepMC2Interface()->GenEvent();
00105   HepMC::GenEvent *copyEvt = new HepMC::GenEvent (*evt);      
00106            
00107   if (evt) bare_product->addHepMCData(copyEvt);   
00108  
00109   e.put(bare_product);
00110   return true;
00111  }
00112  else {
00113    return false;
00114  } 
00115 }
00116 
00117 
00118 using namespace ATOOLS;
00119 DECLARE_GETTER(CMS_RNG_Getter,"CMS_RNG",External_RNG,RNG_Key);
00120 External_RNG *CMS_RNG_Getter::operator()(const RNG_Key &) const
00121 { return new CMS_RNG(); }
00122 void CMS_RNG_Getter::PrintInfo(std::ostream &str,const size_t) const
00123 { str<<"CMS RNG interface"; }
00124 
00125 double CMS_RNG::Get(){
00126  edm::Service<edm::RandomNumberGenerator> rng;
00127    if ( ! rng.isAvailable()) {
00128      throw cms::Exception("Configuration")
00129        << "SherpaInterface requires the RandomNumberGeneratorService\n"
00130           "which is not present in the configuration file.  You must add the service\n"
00131           "in the configuration file or remove the modules that require it.";
00132    }
00133 //   double rngNumber = RandFlat::shoot(rng->getEngine());
00134    CLHEP::HepRandomEngine& engine = rng->getEngine();
00135    double rngNumber = engine.flat();
00136 //   std::cout << "rno: " << rngNumber << std::endl;
00137    return rngNumber;
00138 }

Generated on Tue Jun 9 17:37:09 2009 for CMSSW by  doxygen 1.5.4