Skip to content

Commit 6d512bb

Browse files
committed
Included HepMC basic functionality in Hybrid Gen
1 parent 8997c84 commit 6d512bb

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

Generators/include/Generators/GeneratorHepMC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class GeneratorHepMC : public Generator, public GeneratorFileOrCmd
8383

8484
/** setters **/
8585
void setEventsToSkip(uint64_t val) { mEventsToSkip = val; };
86+
void setVersion(const int& ver) { mVersion = ver; };
8687

8788
protected:
8889
/** copy constructor **/

Generators/include/Generators/GeneratorHybrid.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
#include "Generators/Generator.h"
1818
#include "Generators/BoxGenerator.h"
1919
#include <Generators/GeneratorPythia8.h>
20+
#include <Generators/GeneratorHepMC.h>
2021
#include <Generators/GeneratorFromFile.h>
2122
#include "SimulationDataFormat/MCEventHeader.h"
2223
#include "SimulationDataFormat/MCGenProperties.h"
2324
#include "SimulationDataFormat/ParticleStatus.h"
2425
#include "Generators/GeneratorHybridParam.h"
26+
#include "Generators/GeneratorHepMCParam.h"
27+
#include "Generators/GeneratorFileOrCmdParam.h"
2528
#include "Generators/GeneratorFromO2KineParam.h"
26-
#include <Generators/GeneratorPythia8.h>
2729
#include <TRandom3.h>
2830
#include "CommonUtils/ConfigurationMacroHelper.h"
2931
#include "FairGenerator.h"
3032
#include <DetectorsBase/Stack.h>
33+
#include <SimConfig/SimConfig.h>
3134

3235
namespace o2
3336
{
@@ -39,7 +42,7 @@ class GeneratorHybrid : public Generator
3942

4043
public:
4144
GeneratorHybrid() = default;
42-
GeneratorHybrid(std::vector<std::string> gens);
45+
GeneratorHybrid(const std::vector<std::string>& gens);
4346
~GeneratorHybrid() = default;
4447

4548
Bool_t Init() override;

Generators/src/GeneratorHybrid.cxx

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace o2
1818
{
1919
namespace eventgen
2020
{
21-
GeneratorHybrid::GeneratorHybrid(std::vector<std::string> inputgens)
21+
GeneratorHybrid::GeneratorHybrid(const std::vector<std::string>& inputgens)
2222
{
2323
auto configs = GeneratorHybridParam::Instance().Configs;
2424
mRandomize = GeneratorHybridParam::Instance().Randomize;
@@ -88,33 +88,49 @@ namespace o2
8888
gens.push_back(std::make_unique<o2::eventgen::GeneratorPythia8>());
8989
mConfsPythia8.push_back(mConfigs[index]);
9090
mGens.push_back(gen);
91-
} else if(gen.compare("extkinO2") == 0){
92-
gens.push_back(std::make_unique<o2::eventgen::GeneratorFromO2Kine>(mConfigs[index].c_str()));
93-
mGens.push_back(gen);
91+
} else if (gen.compare("extkinO2") == 0){
92+
gens.push_back(std::make_unique<o2::eventgen::GeneratorFromO2Kine>(mConfigs[index].c_str()));
93+
mGens.push_back(gen);
9494
} else if (gen.compare("external") == 0) {
95-
if (mConfigs[index].compare("") == 0) {
96-
LOG(fatal) << "No configuration provided";
97-
exit(1);
98-
} else {
99-
std::stringstream ss(mConfigs[index]);
100-
std::string pars;
101-
std::vector<std::string> params;
102-
while (std::getline(ss, pars, ',')) {
103-
params.push_back(pars);
95+
if (mConfigs[index].compare("") == 0) {
96+
LOG(fatal) << "No configuration provided";
97+
exit(1);
98+
} else {
99+
std::stringstream ss(mConfigs[index]);
100+
std::string pars;
101+
std::vector<std::string> params;
102+
while (std::getline(ss, pars, ',')) {
103+
params.push_back(pars);
104+
}
105+
auto& extgen_filename = params[0];
106+
auto& extgen_func = params[1];
107+
auto extGen = std::unique_ptr<o2::eventgen::Generator>(o2::conf::GetFromMacro<o2::eventgen::Generator*>(extgen_filename, extgen_func, "FairGenerator*", "extgen"));
108+
if (!extGen) {
109+
LOG(fatal) << "Failed to load external generator from " << extgen_filename << " with function " << extgen_func;
110+
exit(1);
111+
}
112+
gens.push_back(std::move(extGen));
113+
mGens.push_back(gen);
104114
}
105-
auto& extgen_filename = params[0];
106-
auto& extgen_func = params[1];
107-
auto extGen = std::unique_ptr<o2::eventgen::Generator>(o2::conf::GetFromMacro<o2::eventgen::Generator*>(extgen_filename, extgen_func, "FairGenerator*", "extgen"));
108-
if (!extGen) {
109-
LOG(fatal) << "Failed to load external generator from " << extgen_filename << " with function " << extgen_func;
115+
} else if (gen.compare("hepmc") == 0) {
116+
if (mConfigs[index].compare("") == 0) {
117+
LOG(fatal) << "No configuration provided";
110118
exit(1);
119+
} else {
120+
std::stringstream ss(mConfigs[index]);
121+
std::string pars;
122+
std::vector<std::string> params;
123+
while (std::getline(ss, pars, ',')) {
124+
params.push_back(pars);
125+
}
126+
gens.push_back(std::make_unique<o2::eventgen::GeneratorHepMC>());
127+
dynamic_cast<o2::eventgen::GeneratorHepMC*>(gens.back().get())->setFileNames(std::string(params[0]));
128+
dynamic_cast<o2::eventgen::GeneratorHepMC*>(gens.back().get())->setVersion(std::stoi(params[1]));
129+
mGens.push_back(gen);
130+
}
131+
} else {
132+
LOG(info) << "Generator " << gen << " not found in the list of available generators \n";
111133
}
112-
gens.push_back(std::move(extGen));
113-
mGens.push_back(gen);
114-
}
115-
} else{
116-
LOG(info) << "Generator " << gen << " not found in the list of available generators \n";
117-
}
118134
}
119135
index++;
120136
}

0 commit comments

Comments
 (0)