Skip to content

Commit 3ac73fa

Browse files
jackal1-66alcaliva
authored andcommitted
Implementation of hybrid generator (#13699)
* Implementation of hybrid generator This new meta-generator allows the users to use all the O2 implemented generators combined together, configuring them via a JSON file. Each gen will be defined as a subgenerator of the primary hybrid one, whose initialisation happens at the GeneratorFactory level. * Include SimExamples folder in installation (cherry picked from commit d6a50f0)
1 parent b46fb0f commit 3ac73fa

28 files changed

+866
-18
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
@@ -67,6 +69,8 @@ set(headers
6769
include/Generators/GeneratorTGenerator.h
6870
include/Generators/GeneratorExternalParam.h
6971
include/Generators/GeneratorFromFile.h
72+
include/Generators/GeneratorHybrid.h
73+
include/Generators/GeneratorHybridParam.h
7074
include/Generators/GeneratorFromO2KineParam.h
7175
include/Generators/GeneratorFileOrCmd.h
7276
include/Generators/GeneratorFileOrCmdParam.h

Generators/include/Generators/BoxGenerator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Generators/Generator.h"
1818
#include "TParticle.h"
1919
#include <vector>
20+
#include <Generators/BoxGunParam.h>
2021

2122
namespace o2::eventgen
2223
{
@@ -45,6 +46,13 @@ class BoxGenerator : public Generator
4546
SetPhiRange(phimin, phimax);
4647
}
4748

49+
BoxGenerator(BoxGenConfig const& config) : mPDG{config.pdg}, mMult{config.number}
50+
{
51+
SetEtaRange(config.eta[0], config.eta[1]);
52+
SetPRange(config.prange[0], config.prange[1]);
53+
SetPhiRange(config.phirange[0], config.phirange[1]);
54+
}
55+
4856
void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10)
4957
{
5058
mPMin = pmin;

Generators/include/Generators/BoxGunParam.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ struct BoxGunParam : public o2::conf::ConfigurableParamHelper<BoxGunParam> {
3737
O2ParamDef(BoxGunParam, "BoxGun");
3838
};
3939

40+
struct BoxGenConfig {
41+
int pdg = 211; // which particle (default pion); could make this an enum
42+
int number = 10; // how many particles
43+
double eta[2] = {-1, 1}; // eta range
44+
double prange[2] = {0.1, 5}; // energy range min, max in GeV
45+
double phirange[2] = {0., 360.}; // phi range
46+
};
47+
4048
} // end namespace eventgen
4149
} // end namespace o2
4250

Generators/include/Generators/GeneratorExternalParam.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ struct GeneratorExternalParam : public o2::conf::ConfigurableParamHelper<Generat
3434
O2ParamDef(GeneratorExternalParam, "GeneratorExternal");
3535
};
3636

37+
struct ExternalGenConfig {
38+
std::string fileName = "";
39+
std::string funcName = "";
40+
};
41+
3742
} // end namespace eventgen
3843
} // end namespace o2
3944

Generators/include/Generators/GeneratorFileOrCmd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ struct GeneratorFileOrCmd {
3535
* function so as to better facilitate changes. */
3636
void setup(const GeneratorFileOrCmdParam& param,
3737
const conf::SimConfig& config);
38+
// Configure with local parameters
39+
void setup(const FileOrCmdGenConfig& param,
40+
const conf::SimConfig& config);
3841
/**
3942
* Set command to execute in bacground rather than reading from
4043
* existing file(s)

Generators/include/Generators/GeneratorFileOrCmdParam.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ struct GeneratorFileOrCmdParam : public o2::conf::ConfigurableParamHelper<Genera
3939
O2ParamDef(GeneratorFileOrCmdParam, "GeneratorFileOrCmd");
4040
};
4141

42+
struct FileOrCmdGenConfig {
43+
std::string fileNames = "";
44+
std::string cmd = ""; // Program command line to spawn
45+
};
46+
4247
} // end namespace eventgen
4348
} // end namespace o2
4449

Generators/include/Generators/GeneratorFromFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "FairGenerator.h"
1818
#include "Generators/Generator.h"
19+
#include "Generators/GeneratorFromO2KineParam.h"
1920
#include <TRandom3.h>
2021
#include <TGrid.h>
2122

@@ -69,6 +70,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator
6970
public:
7071
GeneratorFromO2Kine() = default;
7172
GeneratorFromO2Kine(const char* name);
73+
GeneratorFromO2Kine(O2KineGenConfig const& pars);
7274

7375
bool Init() override;
7476

@@ -100,6 +102,7 @@ class GeneratorFromO2Kine : public o2::eventgen::Generator
100102
unsigned int mRngSeed = 0; //! randomizer seed, 0 for random value
101103
bool mRandomPhi = false; //! whether we want to randomize the phi angle of the particles
102104
TGrid* mAlienInstance = nullptr; // a cached connection to TGrid (needed for Alien locations)
105+
std::unique_ptr<O2KineGenConfig> mConfig; //! Configuration object
103106

104107
std::unique_ptr<o2::dataformats::MCEventHeader> mOrigMCEventHeader; //! the MC event header of the original file
105108

Generators/include/Generators/GeneratorFromO2KineParam.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ struct GeneratorFromO2KineParam : public o2::conf::ConfigurableParamHelper<Gener
3939
O2ParamDef(GeneratorFromO2KineParam, "GeneratorFromO2Kine");
4040
};
4141

42+
struct O2KineGenConfig {
43+
bool skipNonTrackable = true;
44+
bool continueMode = false;
45+
bool roundRobin = false; // read events with period boundary conditions
46+
bool randomize = false; // randomize the order of events
47+
unsigned int rngseed = 0; // randomizer seed, 0 for random value
48+
bool randomphi = false; // randomize phi angle
49+
std::string fileName = ""; // filename to read from - takes precedence over SimConfig if given
50+
};
51+
4252
} // end namespace eventgen
4353
} // end namespace o2
4454

Generators/include/Generators/GeneratorHepMC.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Generators/Generator.h"
1818
#include "Generators/GeneratorFileOrCmd.h"
1919
#include "Generators/GeneratorHepMCParam.h"
20+
#include "Generators/GeneratorFileOrCmdParam.h"
2021

2122
#ifdef GENERATORS_WITH_HEPMC3_DEPRECATED
2223
namespace HepMC
@@ -69,6 +70,10 @@ class GeneratorHepMC : public Generator, public GeneratorFileOrCmd
6970
void setup(const GeneratorFileOrCmdParam& param0,
7071
const GeneratorHepMCParam& param,
7172
const conf::SimConfig& config);
73+
// Generator configuration from external local parameters
74+
void setup(const FileOrCmdGenConfig& param0,
75+
const HepMCGenConfig& param,
76+
const conf::SimConfig& config);
7277
/**
7378
* Generate a single event. The event is read in from the current
7479
* input file. Returns false if a new event could not be read.
@@ -83,6 +88,7 @@ class GeneratorHepMC : public Generator, public GeneratorFileOrCmd
8388

8489
/** setters **/
8590
void setEventsToSkip(uint64_t val) { mEventsToSkip = val; };
91+
void setVersion(const int& ver) { mVersion = ver; };
8692

8793
protected:
8894
/** copy constructor **/

Generators/include/Generators/GeneratorHepMCParam.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ struct GeneratorHepMCParam : public o2::conf::ConfigurableParamHelper<GeneratorH
5454
O2ParamDef(GeneratorHepMCParam, "HepMC");
5555
};
5656

57+
struct HepMCGenConfig {
58+
// Same parameters as GeneratorHepMCParam
59+
int version = 0;
60+
uint64_t eventsToSkip = 0;
61+
std::string fileName = "";
62+
bool prune = false;
63+
};
64+
5765
} // end namespace eventgen
5866
} // end namespace o2
5967

0 commit comments

Comments
 (0)