CMS 3D CMS Logo

Herwig7Hadronizer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <sstream>
3 #include <fstream>
4 
5 #include <HepMC/GenEvent.h>
6 #include <HepMC/IO_BaseClass.h>
7 
8 #include <ThePEG/Repository/Repository.h>
9 #include <ThePEG/EventRecord/Event.h>
10 #include <ThePEG/Config/ThePEG.h>
11 #include <ThePEG/LesHouches/LesHouchesReader.h>
12 
16 
20 
24 
26 
28 
29 #include <Herwig/API/HerwigAPI.h>
30 #include "CLHEP/Random/RandomEngine.h"
31 
32 namespace CLHEP {
33  class HepRandomEngine;
34 }
35 
37 public:
39  ~Herwig7Hadronizer() override;
40 
41  bool readSettings(int) { return true; }
44  bool declareStableParticles(const std::vector<int>& pdgIds);
45  bool declareSpecialSettings(const std::vector<std::string>) { return true; }
46 
47  void statistics();
48 
50  bool hadronize();
51  bool decay();
52  bool residualDecay();
53  void finalizeEvent();
54 
55  const char* classname() const { return "Herwig7Hadronizer"; }
56  std::unique_ptr<GenLumiInfoHeader> getGenLumiInfoHeader() const override;
58  void randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine);
59 
60 private:
61  void doSetRandomEngine(CLHEP::HepRandomEngine* v) override { setPEGRandomEngine(v); }
62 
63  unsigned int eventsToPrint;
64 
65  ThePEG::EventPtr thepegEvent;
66 
67  std::shared_ptr<lhef::LHEProxy> proxy_;
71 
72  unsigned int firstLumiBlock = 0;
73  unsigned int currentLumiBlock = 0;
74 };
75 
78  BaseHadronizer(pset),
79  eventsToPrint(pset.getUntrackedParameter<unsigned int>("eventsToPrint", 0)),
80  handlerDirectory_(pset.getParameter<std::string>("eventHandlers")),
81  runFileName(pset.getParameter<std::string>("run")) {
84 }
85 
87 
90  std::ifstream runFile(runFileName + ".run");
91  if (runFile.fail()) //required for showering of LHE files
92  {
94  }
95  if (!initGenerator()) {
96  edm::LogInfo("Generator|Herwig7Hadronizer") << "No run step for Herwig chosen. Program will be aborted.";
97  exit(0);
98  }
99  }
100  return true;
101 }
102 
104  edm::LogError("Herwig7 interface")
105  << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
106  return false;
107 }
108 
109 bool Herwig7Hadronizer::declareStableParticles(const std::vector<int>& pdgIds) { return false; }
110 
112  if (eg_) {
114  GenRunInfoProduct::XSec(eg_->integratedXSec() / ThePEG::picobarn, eg_->integratedXSecErr() / ThePEG::picobarn));
115  }
116 }
117 
119  edm::LogInfo("Generator|Herwig7Hadronizer") << "Start production";
120 
121  try {
122  thepegEvent = eg_->shoot();
123  } catch (std::exception& exc) {
124  edm::LogWarning("Generator|Herwig7Hadronizer")
125  << "EGPtr::shoot() thrown an exception, event skipped: " << exc.what();
126  return false;
127  }
128 
129  if (!thepegEvent) {
130  edm::LogWarning("Generator|Herwig7Hadronizer") << "thepegEvent not initialized";
131  return false;
132  }
133 
135  if (!event().get()) {
136  edm::LogWarning("Generator|Herwig7Hadronizer") << "genEvent not initialized";
137  return false;
138  }
139 
140  return true;
141 }
142 
144  edm::LogError("Herwig7 interface")
145  << "Read in of LHE files is not supported in this way. You can read them manually if necessary.";
146  return false;
147 }
148 
150  eventInfo() = std::make_unique<GenEventInfoProduct>(event().get());
151  eventInfo()->setBinningValues(std::vector<double>(1, pthat(thepegEvent)));
152 
153  if (eventsToPrint) {
154  eventsToPrint--;
155  event()->print();
156  }
157 
158  if (iobc_.get())
159  iobc_->write_event(event().get());
160 
161  edm::LogInfo("Generator|Herwig7Hadronizer") << "Event produced";
162 }
163 
164 bool Herwig7Hadronizer::decay() { return true; }
165 
166 bool Herwig7Hadronizer::residualDecay() { return true; }
167 
168 std::unique_ptr<GenLumiInfoHeader> Herwig7Hadronizer::getGenLumiInfoHeader() const {
169  auto genLumiInfoHeader = BaseHadronizer::getGenLumiInfoHeader();
170 
171  if (thepegEvent) {
172  int weights_number = thepegEvent->optionalWeights().size();
173 
174  if (weights_number > 1) {
175  genLumiInfoHeader->weightNames().reserve(weights_number + 1);
176  genLumiInfoHeader->weightNames().push_back("nominal");
177  std::map<std::string, double> weights_map = thepegEvent->optionalWeights();
178  for (std::map<std::string, double>::iterator it = weights_map.begin(); it != weights_map.end(); it++) {
179  genLumiInfoHeader->weightNames().push_back(it->first);
180  }
181  }
182  }
183 
184  return genLumiInfoHeader;
185 }
186 
187 void Herwig7Hadronizer::randomizeIndex(edm::LuminosityBlock const& lumi, CLHEP::HepRandomEngine* rengine) {
188  BaseHadronizer::randomizeIndex(lumi, rengine);
189 
190  if (firstLumiBlock == 0) {
191  firstLumiBlock = lumi.id().luminosityBlock();
192  }
193  currentLumiBlock = lumi.id().luminosityBlock();
194 }
195 
197 
200 
genWeightsTable_cfi.genLumiInfoHeader
genLumiInfoHeader
Definition: genWeightsTable_cfi.py:5
MessageLogger.h
Herwig7Hadronizer::statistics
void statistics()
Definition: Herwig7Hadronizer.cc:111
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
LuminosityBlock.h
BaseHadronizer.h
ExternalDecayDriver.h
Herwig7Interface
Definition: Herwig7Interface.h:41
Herwig7Hadronizer::classname
const char * classname() const
Definition: Herwig7Hadronizer.cc:55
Herwig7Hadronizer::declareSpecialSettings
bool declareSpecialSettings(const std::vector< std::string >)
Definition: Herwig7Hadronizer.cc:45
GenRunInfoProduct::setInternalXSec
void setInternalXSec(const XSec &xsec)
Definition: GenRunInfoProduct.h:26
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
findQualityFiles.v
v
Definition: findQualityFiles.py:179
gen::BaseHadronizer
Definition: BaseHadronizer.h:46
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
GenRunInfoProduct.h
LHEProxy.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Herwig7Interface.h
edm::GeneratorFilter
Definition: GeneratorFilter.h:40
Herwig7Hadronizer::eventsToPrint
unsigned int eventsToPrint
Definition: Herwig7Hadronizer.cc:63
Herwig7Hadronizer::finalizeEvent
void finalizeEvent()
Definition: Herwig7Hadronizer.cc:149
Herwig7Hadronizer::decay
bool decay()
Definition: Herwig7Hadronizer.cc:164
Herwig7Hadronizer::getGenLumiInfoHeader
std::unique_ptr< GenLumiInfoHeader > getGenLumiInfoHeader() const override
Definition: Herwig7Hadronizer.cc:168
Herwig7Hadronizer::initializeForInternalPartons
bool initializeForInternalPartons()
Definition: Herwig7Hadronizer.cc:88
gen::BaseHadronizer::eventInfo
std::unique_ptr< GenEventInfoProduct > & eventInfo()
Definition: BaseHadronizer.h:87
Herwig7Hadronizer::initializeForExternalPartons
bool initializeForExternalPartons()
Definition: Herwig7Hadronizer.cc:103
Herwig7Hadronizer::hadronize
bool hadronize()
Definition: Herwig7Hadronizer.cc:143
CLHEP
Definition: CocoaGlobals.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
Herwig7Interface::initRepository
void initRepository(const edm::ParameterSet &params)
Definition: Herwig7Interface.cc:85
edm::ParameterSet
Definition: ParameterSet.h:47
GenRunInfoProduct::XSec
Definition: GenRunInfoProduct.h:32
GenEventInfoProduct.h
Herwig7Hadronizer::thepegEvent
ThePEG::EventPtr thepegEvent
Definition: Herwig7Hadronizer.cc:65
GeneratorFilter.h
Herwig7Interface::initGenerator
bool initGenerator()
Definition: Herwig7Interface.cc:192
Herwig7Interface::iobc_
std::auto_ptr< HepMC::IO_BaseClass > iobc_
Definition: Herwig7Interface.h:59
Herwig7Interface::setPEGRandomEngine
void setPEGRandomEngine(CLHEP::HepRandomEngine *)
Definition: Herwig7Interface.cc:76
CosmicGenFilterHelix_cfi.pdgIds
pdgIds
Definition: CosmicGenFilterHelix_cfi.py:5
createfilelist.int
int
Definition: createfilelist.py:10
Herwig7Hadronizer::paramSettings
edm::ParameterSet paramSettings
Definition: Herwig7Hadronizer.cc:69
Herwig7Hadronizer::proxy_
std::shared_ptr< lhef::LHEProxy > proxy_
Definition: Herwig7Hadronizer.cc:67
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
Herwig7Hadronizer::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &)
Herwig7Interface::pthat
static double pthat(const ThePEG::EventPtr &event)
Definition: Herwig7Interface.cc:232
Herwig7Hadronizer::Herwig7Hadronizer
Herwig7Hadronizer(const edm::ParameterSet &params)
Definition: Herwig7Hadronizer.cc:76
HadronizerFilter.h
Herwig7Hadronizer::doSetRandomEngine
void doSetRandomEngine(CLHEP::HepRandomEngine *v) override
Definition: Herwig7Hadronizer.cc:61
std
Definition: JetResolutionObject.h:76
gen::BaseHadronizer::event
std::unique_ptr< HepMC::GenEvent > & event()
Definition: BaseHadronizer.h:86
Herwig7Hadronizer::residualDecay
bool residualDecay()
Definition: Herwig7Hadronizer.cc:166
Herwig7Hadronizer::handlerDirectory_
const std::string handlerDirectory_
Definition: Herwig7Hadronizer.cc:68
Herwig7Hadronizer::randomizeIndex
void randomizeIndex(edm::LuminosityBlock const &lumi, CLHEP::HepRandomEngine *rengine)
Definition: Herwig7Hadronizer.cc:187
Herwig7Hadronizer::runFileName
const std::string runFileName
Definition: Herwig7Hadronizer.cc:70
EventSetup.h
Herwig7Hadronizer
Definition: Herwig7Hadronizer.cc:36
edm::HadronizerFilter
Definition: HadronizerFilter.h:53
Herwig7Hadronizer::readSettings
bool readSettings(int)
Definition: Herwig7Hadronizer.cc:41
Herwig7Hadronizer::currentLumiBlock
unsigned int currentLumiBlock
Definition: Herwig7Hadronizer.cc:73
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:53
HepMCProduct.h
Herwig7Interface::convert
static std::auto_ptr< HepMC::GenEvent > convert(const ThePEG::EventPtr &event)
Definition: Herwig7Interface.cc:228
Herwig7HadronizerFilter
edm::HadronizerFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7HadronizerFilter
Definition: Herwig7Hadronizer.cc:201
event
Definition: event.py:1
Herwig7Interface::eg_
ThePEG::EGPtr eg_
Definition: Herwig7Interface.h:48
lumi
Definition: LumiSectionData.h:20
gen::BaseHadronizer::runInfo
GenRunInfoProduct & runInfo()
Definition: BaseHadronizer.h:85
Herwig7Hadronizer::declareStableParticles
bool declareStableParticles(const std::vector< int > &pdgIds)
Definition: Herwig7Hadronizer.cc:109
Herwig7GeneratorFilter
edm::GeneratorFilter< Herwig7Hadronizer, gen::ExternalDecayDriver > Herwig7GeneratorFilter
Definition: Herwig7Hadronizer.cc:198
Herwig7Hadronizer::~Herwig7Hadronizer
~Herwig7Hadronizer() override
Definition: Herwig7Hadronizer.cc:86
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
Herwig7Hadronizer::firstLumiBlock
unsigned int firstLumiBlock
Definition: Herwig7Hadronizer.cc:72
Herwig7Hadronizer::generatePartonsAndHadronize
bool generatePartonsAndHadronize()
Definition: Herwig7Hadronizer.cc:118