Skip to content

Commit 6d482bb

Browse files
committed
Pulled from first hybrid generator implementation
1 parent 7c0b93e commit 6d482bb

File tree

7 files changed

+383
-0
lines changed

7 files changed

+383
-0
lines changed

Generators/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ o2_add_library(Generators
2424
src/GeneratorTGenerator.cxx
2525
src/GeneratorExternalParam.cxx
2626
src/GeneratorFromFile.cxx
27+
src/GeneratorHybrid.cxx
28+
src/GeneratorHybridParam.cxx
2729
src/GeneratorFromO2KineParam.cxx
2830
src/GeneratorFileOrCmd.cxx
2931
src/GeneratorFileOrCmdParam.cxx
@@ -68,6 +70,8 @@ set(headers
6870
include/Generators/GeneratorTGenerator.h
6971
include/Generators/GeneratorExternalParam.h
7072
include/Generators/GeneratorFromFile.h
73+
include/Generators/GeneratorHybrid.h
74+
include/Generators/GeneratorHybridParam.h
7175
include/Generators/GeneratorFromO2KineParam.h
7276
include/Generators/GeneratorFileOrCmd.h
7377
include/Generators/GeneratorFileOrCmdParam.h
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \author M. Giacalone - October 2024
13+
14+
#ifndef ALICEO2_EVENTGEN_GENERATORHYBRID_H_
15+
#define ALICEO2_EVENTGEN_GENERATORHYBRID_H_
16+
17+
#include "Generators/Generator.h"
18+
#include "Generators/BoxGenerator.h"
19+
#include <Generators/GeneratorPythia8.h>
20+
#include <Generators/GeneratorFromFile.h>
21+
#include "SimulationDataFormat/MCEventHeader.h"
22+
#include "SimulationDataFormat/MCGenProperties.h"
23+
#include "SimulationDataFormat/ParticleStatus.h"
24+
#include "Generators/GeneratorHybridParam.h"
25+
#include "Generators/GeneratorFromO2KineParam.h"
26+
#include <Generators/GeneratorPythia8.h>
27+
#include <TRandom3.h>
28+
#include "CommonUtils/ConfigurationMacroHelper.h"
29+
#include "FairGenerator.h"
30+
#include <DetectorsBase/Stack.h>
31+
32+
namespace o2
33+
{
34+
namespace eventgen
35+
{
36+
37+
class GeneratorHybrid : public Generator
38+
{
39+
40+
public:
41+
GeneratorHybrid() = default;
42+
GeneratorHybrid(std::vector<std::string> gens);
43+
~GeneratorHybrid() = default;
44+
45+
Bool_t Init() override;
46+
Bool_t generateEvent() override;
47+
Bool_t importParticles() override;
48+
49+
private:
50+
o2::eventgen::Generator* currentgen = nullptr;
51+
std::vector<std::unique_ptr<o2::eventgen::Generator>> gens;
52+
std::vector<std::unique_ptr<FairGenerator>> mExternal;
53+
std::vector<int> mExtFlag;
54+
std::vector<std::unique_ptr<FairPrimaryGenerator>> mPrimaryExternal;
55+
std::vector<o2::dataformats::MCEventHeader> mExtEventHeader;
56+
const std::vector<std::string> generatorNames = {"extkinO2", "boxgen", "external", "hepmc", "pythia8", "pythia8pp", "pythia8hi", "pythia8hf", "pythia8powheg"};
57+
std::vector<std::string> mGens;
58+
std::vector<std::string> mConfigs;
59+
std::vector<std::string> mConfsPythia8;
60+
bool mRandomize = false;
61+
std::vector<int> mFractions;
62+
int mseqCounter = 0;
63+
int mCurrentFraction = 0;
64+
int mIndex = 0;
65+
int mCurrentExt = 0;
66+
67+
std::unique_ptr<o2::data::Stack> mExtStack;
68+
};
69+
70+
} // namespace eventgen
71+
} // namespace o2
72+
73+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \author M. Giacalone - October 2024
13+
14+
#ifndef ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_
15+
#define ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_
16+
17+
#include "CommonUtils/ConfigurableParam.h"
18+
#include "CommonUtils/ConfigurableParamHelper.h"
19+
20+
namespace o2
21+
{
22+
namespace eventgen
23+
{
24+
25+
/**
26+
** a parameter class/struct to keep the settings of
27+
** the Hybrid event generator and
28+
** allow the user to modify them
29+
**/
30+
31+
struct GeneratorHybridParam : public o2::conf::ConfigurableParamHelper<GeneratorHybridParam> {
32+
std::string Generators = ""; // generators to be used in the cocktail, each divided by a comma
33+
std::string Configs = ""; // configurations for the generators, each divided by a colon
34+
bool Randomize = false; // randomize the order of the generators, if not generator using fractions
35+
std::string Fractions = ""; // events fractions for each generator, works only for sequence
36+
O2ParamDef(GeneratorHybridParam, "GeneratorHybrid");
37+
};
38+
39+
} // end namespace eventgen
40+
} // end namespace o2
41+
42+
#endif // ALICEO2_EVENTGEN_GENERATORHYBRIDPARAM_H_

Generators/src/GeneratorFactory.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <fairlogger/Logger.h>
1919
#include <SimConfig/SimConfig.h>
2020
#include <Generators/GeneratorFromFile.h>
21+
#include <Generators/GeneratorHybrid.h>
2122
#include <Generators/GeneratorTParticle.h>
2223
#include <Generators/GeneratorTParticleParam.h>
2324
#ifdef GENERATORS_WITH_PYTHIA8
@@ -26,6 +27,7 @@
2627
#endif
2728
#include <Generators/GeneratorTGenerator.h>
2829
#include <Generators/GeneratorExternalParam.h>
30+
#include <Generators/GeneratorHybridParam.h>
2931
#include "Generators/GeneratorFromO2KineParam.h"
3032
#ifdef GENERATORS_WITH_HEPMC3
3133
#include <Generators/GeneratorHepMC.h>
@@ -240,6 +242,19 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
240242
primGen->AddGenerator(boxGen);
241243
}
242244
}
245+
} else if (genconfig.compare("hybrid") == 0) { // hybrid using multiple generators
246+
LOG(info) << "Init hybrid generator";
247+
auto& hybridparam = GeneratorHybridParam::Instance();
248+
std::string genslist = hybridparam.Generators;
249+
LOG(info) << "Generators list: " << genslist;
250+
std::vector<std::string> generators;
251+
std::stringstream ss(genslist);
252+
std::string item;
253+
while (std::getline(ss, item, ',')) {
254+
generators.push_back(item);
255+
}
256+
auto hybrid = new o2::eventgen::GeneratorHybrid(generators);
257+
primGen->AddGenerator(hybrid);
243258
} else {
244259
LOG(fatal) << "Invalid generator";
245260
}

0 commit comments

Comments
 (0)