Skip to content

Commit 17d40e1

Browse files
preghenellasawenzel
authored andcommitted
Provide interface to external generators that comply to TGenerator (i.e. AliGenerators)
1 parent 331a0d4 commit 17d40e1

File tree

12 files changed

+551
-0
lines changed

12 files changed

+551
-0
lines changed

Common/SimConfig/include/SimConfig/SimConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct SimConfigData {
2626
std::string mGenerator; // chosen VMC generator
2727
unsigned int mNEvents; // number of events to be simulated
2828
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
29+
std::string mExtGenFileName; // file name containing the external generator configuration
30+
std::string mExtGenFuncName; // function call to retrieve the external generator configuration
2931
unsigned int mStartEvent; // index of first event to be taken
3032
float mBMax; // maximum for impact parameter sampling
3133
bool mIsMT; // chosen MT mode (Geant4 only)
@@ -82,6 +84,8 @@ class SimConfig
8284
unsigned int getNEvents() const { return mConfigData.mNEvents; }
8385

8486
std::string getExtKinematicsFileName() const { return mConfigData.mExtKinFileName; }
87+
std::string getExtGeneratorFileName() const { return mConfigData.mExtGenFileName; }
88+
std::string getExtGeneratorFuncName() const { return mConfigData.mExtGenFuncName; }
8589
unsigned int getStartEvent() const { return mConfigData.mStartEvent; }
8690
float getBMax() const { return mConfigData.mBMax; }
8791
bool getIsMT() const { return mConfigData.mIsMT; }

Common/SimConfig/src/SimConfig.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ void SimConfig::initOptions(boost::program_options::options_description& options
2727
"startEvent", bpo::value<unsigned int>()->default_value(0), "index of first event to be used (when applicable)")(
2828
"extKinFile", bpo::value<std::string>()->default_value("Kinematics.root"),
2929
"name of kinematics file for event generator from file (when applicable)")(
30+
"extGenFile", bpo::value<std::string>()->default_value("extgen.C"),
31+
"name of .C file with definition of external event generator")(
32+
"extGenFunc", bpo::value<std::string>()->default_value(""),
33+
"function call to load the definition of external event generator")(
3034
"bMax,b", bpo::value<float>()->default_value(0.), "maximum value for impact parameter sampling (when applicable)")(
3135
"isMT", bpo::value<bool>()->default_value(false), "multi-threaded mode (Geant4 only")(
3236
"outPrefix,o", bpo::value<std::string>()->default_value("o2sim"), "prefix of output files")(
@@ -60,6 +64,8 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const&
6064
mConfigData.mGenerator = vm["generator"].as<std::string>();
6165
mConfigData.mNEvents = vm["nEvents"].as<unsigned int>();
6266
mConfigData.mExtKinFileName = vm["extKinFile"].as<std::string>();
67+
mConfigData.mExtGenFileName = vm["extGenFile"].as<std::string>();
68+
mConfigData.mExtGenFuncName = vm["extGenFunc"].as<std::string>();
6369
mConfigData.mStartEvent = vm["startEvent"].as<unsigned int>();
6470
mConfigData.mBMax = vm["bMax"].as<float>();
6571
mConfigData.mIsMT = vm["isMT"].as<bool>();

Generators/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,24 @@
33
# The extension is already found. Any number of sources could be listed here.
44
set(MODULE_NAME "Generators")
55

6+
FILE(GLOB INSTALL_SHARE "share/external/*.C")
7+
INSTALL(FILES ${INSTALL_SHARE} DESTINATION share/Generators/external/)
8+
SET(IGNORE_MACROS ${CMAKE_SOURCE_FILE}/share/Generators/external/hijing.C)
9+
610
O2_SETUP(NAME ${MODULE_NAME})
711

812
set(SRCS
13+
src/Generator.cxx
14+
src/GeneratorTGenerator.cxx
915
src/GeneratorFromFile.cxx
1016
src/Pythia6Generator.cxx
1117
src/PDG.cxx
1218
src/PrimaryGenerator.cxx
1319
src/InteractionDiamondParam.cxx
1420
)
1521
set(HEADERS
22+
include/${MODULE_NAME}/Generator.h
23+
include/${MODULE_NAME}/GeneratorTGenerator.h
1624
include/${MODULE_NAME}/GeneratorFromFile.h
1725
include/${MODULE_NAME}/Pythia6Generator.h
1826
include/${MODULE_NAME}/PDG.h
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See https://alice-o2.web.cern.ch/ for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \author R+Preghenella - August 2017
12+
13+
#ifndef ALICEO2_EVENTGEN_GENERATOR_H_
14+
#define ALICEO2_EVENTGEN_GENERATOR_H_
15+
16+
#include "FairGenerator.h"
17+
#include <vector>
18+
#include <array>
19+
20+
namespace o2
21+
{
22+
namespace eventgen
23+
{
24+
// this class implements a generic FairGenerator extension
25+
// that provides a base class for the ALICEo2 simulation needs
26+
// such that different interfaces to the event generators
27+
// (i.e. TGenerator, HEPdata reader) can be implemented
28+
// according to a common protocol
29+
class Generator : public FairGenerator
30+
{
31+
32+
public:
33+
/** default constructor **/
34+
Generator();
35+
/** constructor **/
36+
Generator(const Char_t* name, const Char_t* title = "ALICEo2 Generator");
37+
/** destructor **/
38+
virtual ~Generator() = default;
39+
40+
/** Abstract method ReadEvent must be implemented by any derived class.
41+
It has to handle the generation of input tracks (reading from input
42+
file) and the handing of the tracks to the FairPrimaryGenerator. I
43+
t is called from FairMCApplication.
44+
*@param pStack The stack
45+
*@return kTRUE if successful, kFALSE if not
46+
**/
47+
Bool_t ReadEvent(FairPrimaryGenerator* primGen) override;
48+
49+
/** setters **/
50+
void setMomentumUnit(double val) { mMomentumUnit = val; };
51+
void setEnergyUnit(double val) { mEnergyUnit = val; };
52+
void setPositionUnit(double val) { mPositionUnit = val; };
53+
void setTimeUnit(double val) { mTimeUnit = val; };
54+
void setBoost(Double_t val) { mBoost = val; };
55+
56+
protected:
57+
/** copy constructor **/
58+
Generator(const Generator&);
59+
/** operator= **/
60+
Generator& operator=(const Generator&);
61+
62+
/** methods to override **/
63+
virtual Bool_t generateEvent() = 0;
64+
virtual Bool_t boostEvent(Double_t boost) = 0;
65+
virtual Bool_t addTracks(FairPrimaryGenerator* primGen) const = 0;
66+
67+
/** conversion data members **/
68+
double mMomentumUnit = 1.; // [GeV/c]
69+
double mEnergyUnit = 1.; // [GeV/c]
70+
double mPositionUnit = 0.1; // [cm]
71+
double mTimeUnit = 3.3356410e-12; // [s]
72+
73+
/** lorentz boost data members **/
74+
Double_t mBoost;
75+
76+
ClassDefOverride(Generator, 1);
77+
78+
}; /** class Generator **/
79+
80+
/*****************************************************************/
81+
/*****************************************************************/
82+
83+
} // namespace eventgen
84+
} // namespace o2
85+
86+
#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See https://alice-o2.web.cern.ch/ for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \author R+Preghenella - June 2017
12+
13+
#ifndef ALICEO2_EVENTGEN_GENERATORTGENERATOR_H_
14+
#define ALICEO2_EVENTGEN_GENERATORTGENERATOR_H_
15+
16+
#include "Generators/Generator.h"
17+
18+
class TGenerator;
19+
class TClonesArray;
20+
21+
namespace o2
22+
{
23+
namespace eventgen
24+
{
25+
26+
/*****************************************************************/
27+
/*****************************************************************/
28+
29+
class GeneratorTGenerator : public Generator
30+
{
31+
32+
public:
33+
/** default constructor **/
34+
GeneratorTGenerator();
35+
/** constructor with name and title **/
36+
GeneratorTGenerator(const Char_t* name, const Char_t* title = "ALICEo2 TGenerator Generator");
37+
/** destructor **/
38+
virtual ~GeneratorTGenerator();
39+
40+
/** setters **/
41+
void setTGenerator(TGenerator* val) { mTGenerator = val; };
42+
43+
/** Initialize the generator if needed **/
44+
virtual Bool_t Init() override;
45+
46+
protected:
47+
/** copy constructor **/
48+
GeneratorTGenerator(const GeneratorTGenerator&);
49+
/** operator= **/
50+
GeneratorTGenerator& operator=(const GeneratorTGenerator&);
51+
52+
/** methods to override **/
53+
Bool_t generateEvent() override;
54+
Bool_t boostEvent(Double_t boost) override;
55+
Bool_t addTracks(FairPrimaryGenerator* primGen) const override;
56+
57+
/** TGenerator interface **/
58+
TGenerator* mTGenerator;
59+
TClonesArray* mParticles;
60+
61+
ClassDefOverride(GeneratorTGenerator, 1);
62+
63+
}; /** class GeneratorTGenerator **/
64+
65+
/*****************************************************************/
66+
/*****************************************************************/
67+
68+
} // namespace eventgen
69+
} // namespace o2
70+
71+
#endif /* ALICEO2_EVENTGEN_GENERATORTGENERATOR_H_ */

Generators/share/external/extgen.C

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
It is mandatory that the function returns a TGenerator*
3+
whereas there are no restrictions on the function name
4+
and the arguments to the function prototype.
5+
6+
TGenerator *extgen(double energy = 2760.);
7+
8+
It is mandatory to define the units used by the
9+
concerned generator to allow for the proper
10+
conversion to the units used by the simulation.
11+
The above is done by defining the following
12+
variable mandatory global variables
13+
14+
double momentumUnit; // [GeV/c]
15+
double energyUnit; // [GeV/c]
16+
double positionUnit; // [cm]
17+
double timeUnit; // [s]
18+
19+
and assign the proper values, either initialising them
20+
or withing the function to be called
21+
**/
22+
23+
double momentumUnit = 1.;
24+
double energyUnit = 1.;
25+
double positionUnit = 1.;
26+
double timeUnit = 1.;
27+
28+
TGenerator*
29+
extgen()
30+
{
31+
std::cout << "This is a template function for an external generator" << std::endl;
32+
auto gen = new TGenerator;
33+
return gen;
34+
}

Generators/share/external/hijing.C

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// configures a AliGenHijing class from AliRoot
2+
// usage: o2sim -g extgen --extGenFile hijing.C
3+
// options: --extGenFunc hijing(5020., 0., 20.)
4+
5+
/// \author R+Preghenella - October 2018
6+
7+
double momentumUnit = 1.; // [GeV/c]
8+
double energyUnit = 1.; // [GeV/c]
9+
double positionUnit = 0.1; // [cm]
10+
double timeUnit = 3.3356410e-12; // [s]
11+
12+
R__LOAD_LIBRARY(libTHijing)
13+
14+
TGenerator*
15+
hijing(double energy = 5020., double bMin = 0., double bMax = 20.)
16+
{
17+
auto hij = new AliGenHijing(-1);
18+
hij->SetEnergyCMS(energy);
19+
hij->SetImpactParameterRange(bMin, bMax);
20+
hij->SetReferenceFrame("CMS");
21+
hij->SetProjectile("A", 208, 82);
22+
hij->SetTarget("A", 208, 82);
23+
hij->SetSpectators(0);
24+
hij->KeepFullEvent();
25+
hij->SetJetQuenching(0);
26+
hij->SetShadowing(1);
27+
hij->SetDecaysOff(1);
28+
hij->SetSelectAll(0);
29+
hij->SetPtHardMin(2.3);
30+
hij->Init();
31+
return hij->GetMC();
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// configures a TPythia6 class
2+
// usage: o2sim -g extgen --extGenFile pythia6.C
3+
// options: --extGenFunc pythia6(14000., "pythia.settings")
4+
5+
/// \author R+Preghenella - October 2018
6+
7+
double momentumUnit = 1.; // [GeV/c]
8+
double energyUnit = 1.; // [GeV/c]
9+
double positionUnit = 0.1; // [cm]
10+
double timeUnit = 3.3356410e-12; // [s]
11+
12+
R__LOAD_LIBRARY(libpythia6)
13+
14+
void configure(TPythia6* py6, const char* params);
15+
16+
TGenerator*
17+
pythia6(double energy = 14000., const char* params = nullptr)
18+
{
19+
auto py6 = TPythia6::Instance();
20+
if (params)
21+
configure(py6, params);
22+
py6->Initialize("CMS", "p", "p", energy);
23+
return py6;
24+
}
25+
26+
void configure(TPythia6* py6, const char* params)
27+
{
28+
std::ifstream file(params);
29+
if (!file.is_open()) {
30+
std::cerr << "Cannot open configuration file: " << params << std::endl;
31+
return;
32+
};
33+
std::string line, command;
34+
while (std::getline(file, line)) {
35+
/** remove comments **/
36+
command = line.substr(0, line.find_first_of("#"));
37+
if (command.length() == 0)
38+
continue;
39+
py6->Pygive(command.c_str());
40+
}
41+
file.close();
42+
}

0 commit comments

Comments
 (0)