00001 #include <string> 00002 #include <memory> 00003 00004 #include <boost/shared_ptr.hpp> 00005 00006 #include <HepMC/GenEvent.h> 00007 00008 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00009 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00010 #include "FWCore/PluginManager/interface/PluginManager.h" 00011 #include "FWCore/PluginManager/interface/PluginFactory.h" 00012 00013 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h" 00014 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h" 00015 #include "GeneratorInterface/LHEInterface/interface/Hadronisation.h" 00016 00017 EDM_REGISTER_PLUGINFACTORY(lhef::Hadronisation::Factory, 00018 "GeneratorInterfaceLHEHadronisation"); 00019 00020 namespace { 00021 class NoHadronisation : public lhef::Hadronisation { 00022 public: 00023 NoHadronisation(const edm::ParameterSet ¶ms) : 00024 Hadronisation(params) {} 00025 ~NoHadronisation() {} 00026 00027 private: 00028 void doInit() {} 00029 std::auto_ptr<HepMC::GenEvent> doHadronisation() 00030 { return getRawEvent()->asHepMCEvent(); } 00031 }; 00032 00033 } // anonymous namespae 00034 00035 namespace lhef { 00036 00037 Hadronisation::Hadronisation(const edm::ParameterSet ¶ms) : 00038 psRequested(false), 00039 psAsHepMC(true) 00040 { 00041 } 00042 00043 Hadronisation::~Hadronisation() 00044 { 00045 } 00046 00047 void Hadronisation::init() 00048 { 00049 doInit(); 00050 } 00051 00052 bool Hadronisation::setEvent(const boost::shared_ptr<LHEEvent> &event) 00053 { 00054 bool newRunInfo = !rawEvent || 00055 (rawEvent->getRunInfo() != event->getRunInfo() && 00056 *rawEvent->getRunInfo() != *event->getRunInfo()); 00057 rawEvent = event; 00058 if (newRunInfo) { 00059 this->newRunInfo(event->getRunInfo()); 00060 return true; 00061 } else 00062 return false; 00063 } 00064 00065 void Hadronisation::clear() 00066 { 00067 } 00068 00069 std::set<std::string> Hadronisation::capabilities() const 00070 { 00071 return std::set<std::string>(); 00072 } 00073 00074 void Hadronisation::matchingCapabilities( 00075 const std::set<std::string> &capabilities) 00076 { 00077 psRequested = false; 00078 psAsHepMC = false; 00079 for(std::set<std::string>::const_iterator iter = capabilities.begin(); 00080 iter != capabilities.end(); ++iter) { 00081 if (*iter == "hepmc") 00082 psAsHepMC = true; 00083 else if (*iter == "psFinalState") 00084 psRequested = true; 00085 else if (*iter == "matchSummary") 00086 /* nothing */; 00087 else if (!this->capabilities().count(*iter)) 00088 throw cms::Exception("Generator|LHEInterface") 00089 << "JetMatching expected capability \"" 00090 << *iter << "\", but hadronizer does not " 00091 "support it." << std::endl; 00092 } 00093 } 00094 00095 std::auto_ptr<Hadronisation> Hadronisation::create( 00096 const edm::ParameterSet ¶ms) 00097 { 00098 std::string name = params.getParameter<std::string>("generator"); 00099 00100 if (name == "None") 00101 return std::auto_ptr<Hadronisation>( 00102 new NoHadronisation(params)); 00103 00104 std::auto_ptr<Hadronisation> plugin( 00105 Factory::get()->create(name + "Hadronisation", params)); 00106 00107 if (!plugin.get()) 00108 throw cms::Exception("InvalidGenerator") 00109 << "Unknown MC generator \"" << name << "\"" 00110 " specified for hadronisation in LHEProducer." 00111 << std::endl; 00112 00113 edm::LogInfo("Generator|LHEInterface") 00114 << "Using " << name << " to hadronize LHE input." << std::endl; 00115 00116 return plugin; 00117 } 00118 00119 std::auto_ptr<HepMC::GenEvent> Hadronisation::hadronize() 00120 { 00121 std::auto_ptr<HepMC::GenEvent> event = this->doHadronisation(); 00122 if (!event.get()) 00123 return event; 00124 00125 const HepMC::GenVertex *signalVertex = event->signal_process_vertex(); 00126 if (!signalVertex) { 00127 signalVertex = LHEEvent::findSignalVertex(event.get()); 00128 event->set_signal_process_vertex( 00129 const_cast<HepMC::GenVertex*>(signalVertex)); 00130 } 00131 00132 return event; 00133 } 00134 00135 void Hadronisation::newRunInfo(const boost::shared_ptr<LHERunInfo> &runInfo) 00136 { 00137 } 00138 00139 bool Hadronisation::showeredEvent( 00140 const boost::shared_ptr<HepMC::GenEvent> &event) 00141 { 00142 if (event.get()) { 00143 const HepMC::GenVertex *signalVertex = 00144 event->signal_process_vertex(); 00145 if (!signalVertex) { 00146 signalVertex = LHEEvent::findSignalVertex(event.get(), false); 00147 event->set_signal_process_vertex( 00148 const_cast<HepMC::GenVertex*>(signalVertex)); 00149 } 00150 } 00151 00152 return sigShower.emit(event); 00153 } 00154 00155 } // namespace lhef