6#ifndef PYTHIA6_PYTHIA6TOHEPMC3_CC
7#define PYTHIA6_PYTHIA6TOHEPMC3_CC
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)
97#ifndef PYTHIA6HEPEVTSIZE
98#define PYTHIA6HEPEVTSIZE 10000
103std::map<int, std::pair<std::shared_ptr<Writer>,
GenEvent*> > hepmc3_gWriters;
105std::map<int, std::shared_ptr<GenRunInfo> > hepmc3_gGenRunInfos;
107GenEvent* hepmc3_gWriters_get_event(
const int & position)
109 if (hepmc3_gWriters.count(position) == 0) {
110 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
113 return hepmc3_gWriters[position].second;
118 int hepmc3_delete_writer_(
const int & position)
120 if (hepmc3_gWriters.count(position) == 0) {
121 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
124 hepmc3_gWriters[position].first->close();
125 hepmc3_gWriters.erase(hepmc3_gWriters.find(position));
129 int hepmc3_convert_event_(
const int & position)
131 if (hepmc3_gWriters.count(position) == 0) {
132 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
135 if (!hepmc3_gInterface.m_hepevtptr)
137 printf(
"Error in %s: HEPEVT block does not exist\n", __FUNCTION__);
140 hepmc3_gWriters[position].second =
new GenEvent(Units::GEV, Units::MM);
141 for(
int i = 1; i <= hepmc3_gInterface.number_entries(); i++ ) {
142 if (hepmc3_gInterface.m_hepevtptr->jmohep[i-1][1]<hepmc3_gInterface.m_hepevtptr->jmohep[i-1][0]) {
143 hepmc3_gInterface.m_hepevtptr->jmohep[i-1][1] = hepmc3_gInterface.m_hepevtptr->jmohep[i-1][0];
146 hepmc3_gInterface.HEPEVT_to_GenEvent(hepmc3_gWriters[position].second);
147 if (hepmc3_gGenRunInfos.count(position) == 0) hepmc3_gGenRunInfos[position] = std::make_shared<GenRunInfo>();
148 hepmc3_gWriters[position].second->set_run_info(hepmc3_gGenRunInfos[position]);
149 hepmc3_gWriters[position].second->weights() = std::vector<double>(hepmc3_gGenRunInfos[position]->weight_names().size(), 1.0);
152 int hepmc3_write_event_(
const int & position)
154 if (hepmc3_gWriters.count(position) == 0) {
155 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
158 hepmc3_gWriters[position].first->write_event(*(hepmc3_gWriters[position].second));
161 int hepmc3_clear_event_(
const int & position)
163 if (hepmc3_gWriters.count(position) == 0) {
164 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
167 hepmc3_gWriters[position].second->clear();
170 int hepmc3_set_cross_section_(
const int & position,
const double& x,
const double& xe,
const int& n1,
const int& n2)
172 if (hepmc3_gWriters.count(position) == 0) {
173 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
176 GenCrossSectionPtr cs = std::make_shared< GenCrossSection>();
177 cs->set_cross_section(x, xe, n1, n2);
178 hepmc3_gWriters[position].second->set_cross_section(cs);
182 int hepmc3_set_pdf_info_(
const int & position,
const int& parton_id1,
const int& parton_id2,
const double& x1,
const double& x2,
183 const double& scale_in,
const double& xf1,
const double& xf2,
184 const int& pdf_id1,
const int& pdf_id2)
186 if (hepmc3_gWriters.count(position) == 0) {
187 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
190 GenPdfInfoPtr pdf=std::make_shared< GenPdfInfo>();
191 pdf->set(parton_id1, parton_id2, x1, x2, scale_in, xf1, xf2, pdf_id1, pdf_id2);
192 hepmc3_gWriters[position].second->set_pdf_info(pdf);
195 int hepmc3_set_hepevt_address_(
int* a)
197 printf(
"Info in %s: setting /hepevt/ block adress\n", __FUNCTION__);
198 hepmc3_gInterface.set_hepevt_address((
char*)a);
201 int hepmc3_set_attribute_int_(
const int & position,
const int & attval,
const char* attname)
203 if (hepmc3_gWriters.count(position) == 0) {
204 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
207 hepmc3_gWriters[position].second->add_attribute(attname, std::make_shared<IntAttribute>(attval));
210 int hepmc3_set_attribute_double_(
const int & position,
const double & attval,
const char* attname)
212 if (hepmc3_gWriters.count(position) == 0) {
213 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
216 hepmc3_gWriters[position].second->add_attribute(attname, std::make_shared<DoubleAttribute>(attval));
220 int hepmc3_new_writer_(
const int & position,
const int & mode,
const char* ffilename)
222 std::string libHepMC3rootIO=
"libHepMC3rootIO.so";
224 libHepMC3rootIO=
"libHepMC3rootIO.dylib";
227 libHepMC3rootIO=
"HepMC3rootIO.dll";
229 std::string filename=std::string(ffilename);
230 int r_position=position;
233 if (!hepmc3_gWriters.empty()) r_position = 1;
234 if (!hepmc3_gWriters.empty()) r_position = hepmc3_gWriters.rend()->first+1;
236 if (hepmc3_gWriters.count(r_position) != 0) {
237 printf(
"Error in %s: Writer at position %i already exists\n", __FUNCTION__, r_position);
240 if (hepmc3_gGenRunInfos.count(r_position) != 0) {
241 printf(
"Warning in %s: RunInfo at position %i already exists\n", __FUNCTION__, r_position);
245 hepmc3_gGenRunInfos[r_position]=std::make_shared<GenRunInfo>();
251 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));
254 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));
257 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));
260 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));
263 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));
266 printf(
"Error in %s:Output format %d is unknown or not supported.\n", __FUNCTION__, mode);
272 int hepmc3_new_weight_(
const int & position,
const char* name)
274 if (hepmc3_gGenRunInfos.count(position) == 0) {
275 printf(
"Warning in %s: RunInfo at position %i does not exist\n", __FUNCTION__, position);
278 if (hepmc3_gGenRunInfos[position]->weight_index(std::string(name)) >= 0)
return 0;
279 std::vector<std::string> weight_names = hepmc3_gGenRunInfos[position]->weight_names();
280 weight_names.emplace_back(name);
281 hepmc3_gWriters[position].second->weights().push_back(1.0);
282 hepmc3_gGenRunInfos[position]->set_weight_names(weight_names);
285 int hepmc3_set_weight_by_index_(
const int & position,
const double& val,
const int & index)
287 if (hepmc3_gWriters.count(position) == 0) {
288 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
291 if (hepmc3_gWriters[position].second->weights().size() < (
unsigned long int)index) {
292 printf(
"Warning in %s: Event has no weight with index %i\n", __FUNCTION__, index);
295 hepmc3_gWriters[position].second->weights()[index] = val;
298 int hepmc3_set_weight_by_name_(
const int & position,
const double& val,
const char* name)
300 if (hepmc3_gWriters.count(position) == 0) {
301 printf(
"Warning in %s: Writer at position %i does not exist\n", __FUNCTION__, position);
304 hepmc3_new_weight_(position, name);
305 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.