6#ifndef Pythia6_Pythia6ToHepMC3_H
7#define Pythia6_Pythia6ToHepMC3_H
8#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32)) && !defined(__CYGWIN__)
9#define hepmc3_delete_writer_ HEPMC3_DELETE_WRITER
10#define hepmc3_convert_event_ HEPMC3_CONVERT_EVENT
11#define hepmc3_clear_event_ HEPMC3_CLEAR_EVENT
12#define hepmc3_write_event_ HEPMC3_WRITE_EVENT
13#define hepmc3_set_cross_section_ HEPMC3_SET_CROSS_SECTION
14#define hepmc3_set_pdf_info_ HEPMC3_SET_PDF_INFO
15#define hepmc3_set_event_number_ HEPMC3_SET_EVENT_NUMBER
16#define hepmc3_set_hepevt_address_ HEPMC3_SET_HEPEVT_ADDRESS
17#define hepmc3_set_attribute_int_ HEPMC3_SET_ATTRIBUTE_INT
18#define hepmc3_set_attribute_double_ HEPMC3_SET_ATTRIBUTE_DOUBLE
19#define hepmc3_new_writer_ HEPMC3_NEW_WRITER
20#define hepmc3_new_weight_ HEPMC3_NEW_WEIGHT
21#define hepmc3_set_weight_by_index_ HEPMC3_SET_WEIGHT_BY_INDEX
22#define hepmc3_set_weight_by_name_ HEPMC3_SET_WEIGHT_BY_NAME
24#ifdef DUMMYPYTHIA6TOHEPMC3
27 int hepmc3_delete_writer_(
const int & position)
31 int hepmc3_convert_event_(
const int & position)
35 int hepmc3_write_event_(
const int & position)
39 int hepmc3_clear_event_(
const int & position)
43 int hepmc3_set_cross_section_(
const int & position,
const double& x,
const double& xe,
const int& n1,
const int& n2)
48 int hepmc3_set_pdf_info_(
const int & position,
const int& parton_id1,
const int& parton_id2,
const double& x1,
const double& x2,
49 const double& scale_in,
const double& xf1,
const double& xf2,
50 const int& pdf_id1,
const int& pdf_id2)
54 int hepmc3_set_hepevt_address_(
int* a)
58 int hepmc3_set_attribute_int_(
const int & position,
const int & attval,
const char* attname)
62 int hepmc3_set_attribute_double_(
const int & position,
const double & attval,
const char* attname)
66 int hepmc3_new_writer_(
const int & position,
const int & mode,
const char* ffilename)
70 int hepmc3_new_weight_(
const int & position,
const char* name)
74 int hepmc3_set_weight_by_index_(
const int & position,
const double& val,
const int & pos)
78 int hepmc3_set_weight_by_name_(
const int & position,
const double& val,
const char* name)
98#ifndef PYTHIA6HEPEVTSIZE
99#define PYTHIA6HEPEVTSIZE 10000
104std::map<int, std::pair<std::shared_ptr<Writer>,
GenEvent*> > hepmc3_gWriters;
106std::map<int, std::shared_ptr<GenRunInfo> > hepmc3_gGenRunInfos;
108GenEvent* hepmc3_gWriters_get_event(
const int & position)
110 if (hepmc3_gWriters.count(position) == 0) {
111 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
114 return hepmc3_gWriters[position].second;
119 int hepmc3_delete_writer_(
const int & position)
121 if (hepmc3_gWriters.count(position) == 0) {
122 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
125 hepmc3_gWriters[position].first->close();
126 hepmc3_gWriters.erase(hepmc3_gWriters.find(position));
130 int hepmc3_convert_event_(
const int & position)
132 if (hepmc3_gWriters.count(position) == 0) {
133 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
136 if (!hepmc3_gInterface.m_hepevtptr)
138 printf(
"Error in %s: HEPEVT block does not exist\n", __FUNCTION__);
141 hepmc3_gWriters[position].second =
new GenEvent(Units::GEV, Units::MM);
142 for(
int i = 1; i <= hepmc3_gInterface.number_entries(); i++ )
143 if (hepmc3_gInterface.m_hepevtptr->jmohep[i-1][1]<hepmc3_gInterface.m_hepevtptr->jmohep[i-1][0]) hepmc3_gInterface.m_hepevtptr->jmohep[i-1][1] = hepmc3_gInterface.m_hepevtptr->jmohep[i-1][0];
144 hepmc3_gInterface.HEPEVT_to_GenEvent(hepmc3_gWriters[position].second);
145 if (hepmc3_gGenRunInfos.count(position) == 0) hepmc3_gGenRunInfos[position] = std::make_shared<GenRunInfo>();
146 hepmc3_gWriters[position].second->set_run_info(hepmc3_gGenRunInfos[position]);
147 hepmc3_gWriters[position].second->weights() = std::vector<double>(hepmc3_gGenRunInfos[position]->weight_names().size(), 1.0);
150 int hepmc3_write_event_(
const int & position)
152 if (hepmc3_gWriters.count(position) == 0) {
153 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
156 hepmc3_gWriters[position].first->write_event(*(hepmc3_gWriters[position].second));
159 int hepmc3_clear_event_(
const int & position)
161 if (hepmc3_gWriters.count(position) == 0) {
162 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
165 hepmc3_gWriters[position].second->clear();
168 int hepmc3_set_cross_section_(
const int & position,
const double& x,
const double& xe,
const int& n1,
const int& n2)
170 if (hepmc3_gWriters.count(position) == 0) {
171 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
174 GenCrossSectionPtr cs = std::make_shared< GenCrossSection>();
175 cs->set_cross_section(x, xe, n1, n2);
176 hepmc3_gWriters[position].second->set_cross_section(cs);
180 int hepmc3_set_pdf_info_(
const int & position,
const int& parton_id1,
const int& parton_id2,
const double& x1,
const double& x2,
181 const double& scale_in,
const double& xf1,
const double& xf2,
182 const int& pdf_id1,
const int& pdf_id2)
184 if (hepmc3_gWriters.count(position) == 0) {
185 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
188 GenPdfInfoPtr pdf=std::make_shared< GenPdfInfo>();
189 pdf->set(parton_id1, parton_id2, x1, x2, scale_in, xf1, xf2, pdf_id1, pdf_id2);
190 hepmc3_gWriters[position].second->set_pdf_info(pdf);
193 int hepmc3_set_hepevt_address_(
int* a)
195 printf(
"Info in %s: setting /hepevt/ block adress\n", __FUNCTION__);
196 hepmc3_gInterface.set_hepevt_address((
char*)a);
199 int hepmc3_set_attribute_int_(
const int & position,
const int & attval,
const char* attname)
201 if (hepmc3_gWriters.count(position) == 0) {
202 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
205 hepmc3_gWriters[position].second->add_attribute(attname, std::make_shared<IntAttribute>(attval));
208 int hepmc3_set_attribute_double_(
const int & position,
const double & attval,
const char* attname)
210 if (hepmc3_gWriters.count(position) == 0) {
211 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
214 hepmc3_gWriters[position].second->add_attribute(attname, std::make_shared<DoubleAttribute>(attval));
218 int hepmc3_new_writer_(
const int & position,
const int & mode,
const char* ffilename)
220 std::string libHepMC3rootIO=
"libHepMC3rootIO.so";
222 libHepMC3rootIO=
"libHepMC3rootIO.dylib";
225 libHepMC3rootIO=
"HepMC3rootIO.dll";
227 std::string filename=std::string(ffilename);
228 int r_position=position;
231 if (hepmc3_gWriters.size() == 0) r_position = 1;
232 if (hepmc3_gWriters.size() != 0) r_position = hepmc3_gWriters.rend()->first+1;
234 if (hepmc3_gWriters.count(r_position) != 0) {
235 printf(
"Error in %s: Writer at position %i already exists\n", __FUNCTION__, r_position);
238 if (hepmc3_gGenRunInfos.count(r_position) != 0) {
239 printf(
"Warning in %s: RunInfo at position %i already exists\n", __FUNCTION__, r_position);
243 hepmc3_gGenRunInfos[r_position]=std::make_shared<GenRunInfo>();
249 hepmc3_gWriters[r_position] = std::pair<std::shared_ptr<Writer>,
GenEvent*>(std::make_shared<WriterAscii>(filename.c_str(), hepmc3_gGenRunInfos[position]),
new GenEvent(hepmc3_gGenRunInfos[position], Units::GEV, Units::MM));
252 hepmc3_gWriters[r_position] = std::pair<std::shared_ptr<Writer>,
GenEvent*>(std::make_shared<WriterAsciiHepMC2>(filename.c_str(), hepmc3_gGenRunInfos[position]),
new GenEvent(hepmc3_gGenRunInfos[position], Units::GEV, Units::MM));
255 hepmc3_gWriters[r_position] = std::pair<std::shared_ptr<Writer>,
GenEvent*>(std::make_shared<WriterHEPEVT>(filename.c_str()),
new GenEvent(hepmc3_gGenRunInfos[position], Units::GEV, Units::MM));
258 hepmc3_gWriters[r_position] = std::pair<std::shared_ptr<Writer>,
GenEvent*>(std::make_shared<WriterPlugin>(filename.c_str(), libHepMC3rootIO, std::string(
"newWriterRootfile"), hepmc3_gGenRunInfos[position]),
new GenEvent(hepmc3_gGenRunInfos[position], Units::GEV, Units::MM));
261 hepmc3_gWriters[r_position] = std::pair<std::shared_ptr<Writer>,
GenEvent*>(std::make_shared<WriterPlugin>(filename.c_str(), libHepMC3rootIO, std::string(
"newWriterRootTreefile"), hepmc3_gGenRunInfos[position]),
new GenEvent(hepmc3_gGenRunInfos[position], Units::GEV, Units::MM));
264 printf(
"Error in %s:Output format %d is unknown or not supported.\n", __FUNCTION__, mode);
270 int hepmc3_new_weight_(
const int & position,
const char* name)
272 if (hepmc3_gGenRunInfos.count(position) == 0) {
273 printf(
"Warning in %s: RunInfo at position %i does not exist\n", __FUNCTION__, position);
276 if (hepmc3_gGenRunInfos[position]->weight_index(std::string(name)) >= 0)
return 0;
277 std::vector<std::string> weight_names = hepmc3_gGenRunInfos[position]->weight_names();
278 weight_names.push_back(std::string(name));
279 hepmc3_gWriters[position].second->weights().push_back(1.0);
280 hepmc3_gGenRunInfos[position]->set_weight_names(weight_names);
283 int hepmc3_set_weight_by_index_(
const int & position,
const double& val,
const int & index)
285 if (hepmc3_gWriters.count(position) == 0) {
286 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
289 if (hepmc3_gWriters[position].second->weights().size() < index) {
290 printf(
"Warning in %s: Event has no weight with index %i\n", __FUNCTION__, index);
293 hepmc3_gWriters[position].second->weights()[index] = val;
296 int hepmc3_set_weight_by_name_(
const int & position,
const double& val,
const char* name)
298 if (hepmc3_gWriters.count(position) == 0) {
299 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
302 hepmc3_new_weight_(position, name);
303 hepmc3_gWriters[position].second->weight(std::string(name)) = val;
Definition of class Attribute, class IntAttribute and class StringAttribute.
Definition of class GenEvent.
Definition of class GenRunInfo.
Definition of class HEPEVT_Wrapper_Template.
Definition of static class Print.
Definition of class WriterAsciiHepMC2.
Definition of class WriterAscii.
Definition of class WriterHEPEVT.
Definition of class WriterPlugin.
Definition of interface Writer.
Stores event-related information.
An interface to HEPEVT common block implemented as template class.