Skip to content

Commit ae319c5

Browse files
committed
New generator GeneratorTParticle
The generator `GeneratorTParticle` will read in particles from a `TChain` containing a branch with a `TClonesArray` of `TParticle` objects. The generator can operate in two modes - Data is read from a file(s) - Data is read from a file being generated by a child program The first mode is selected by -g tparticle --configKeyValues "TParticle.fileNames=foo.root,bar.root" The second mode is selected by -g tparticle --configKeyValues "TParticle.progCmd=<program and options>" For this latter mode, see also recent commit to `GeneratorHepMC` Above `<program and options>` specifiy a program to spawn in the background which will write to a specified file (temporary file). Suppose the program is called `eg`, then the following _must_ be possible eg -n NEVENTS -o OUTPUT_FILENAME That is, `eg` _must_ accept the option `-n` to set the number of events to produce, and the option `-o` to set the output file name (a ROOT file). The name of the `TTree` object in the file(s) can be set with --configKeyValues "TParticle.treeName=<name>" (defaults to `T`), and similar for the branch that contains the `TClonesArray` of `TParticle` --configKeyValues "TParticle.branchName=<name>" (defaults to `Particles`). The generator `GeneratorTParticle` _does not_ import any header information into the simulation event record. Some proper convention could be decided upon, e.g., one that tracks the HepMC event record format.
1 parent 2f36720 commit ae319c5

File tree

7 files changed

+396
-3
lines changed

7 files changed

+396
-3
lines changed

Generators/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ o2_add_library(Generators
3838
src/GenCosmicsParam.cxx
3939
src/GeneratorFactory.cxx
4040
src/GeneratorGeantinos.cxx
41+
src/GeneratorTParticle.cxx
42+
src/GeneratorTParticleParam.cxx
4143
$<$<BOOL:${pythia6_FOUND}>:src/GeneratorPythia6.cxx>
4244
$<$<BOOL:${pythia6_FOUND}>:src/GeneratorPythia6Param.cxx>
4345
$<$<BOOL:${pythia_FOUND}>:src/GeneratorPythia8.cxx>
@@ -79,6 +81,8 @@ set(headers
7981
include/Generators/QEDGenParam.h
8082
include/Generators/GenCosmicsParam.h
8183
include/Generators/GeneratorGeantinos.h
84+
include/Generators/GeneratorTParticle.h
85+
include/Generators/GeneratorTParticleParam.h
8286
)
8387

8488
if (pythia6_FOUND)
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// -*- C++ -*-
2+
// Copyright 2023 CERN and copyright holders of ALICE O2.
3+
//
4+
// See https://alice-o2.web.cern.ch/copyright for details of the
5+
// copyright holders. All rights not expressly granted are reserved.
6+
//
7+
// This software is distributed under the terms of the GNU General
8+
// Public License v3 (GPL Version 3), copied verbatim in the file
9+
// "COPYING".
10+
//
11+
// In applying this license CERN does not waive the privileges and
12+
// immunities granted to it by virtue of its status as an
13+
// Intergovernmental Organization or submit itself to any
14+
// jurisdiction.
15+
//
16+
/// @author: Christian Holm Christensen <cholm@nbi.dk>
17+
#ifndef ALICEO2_GENERATORTPARTICLE_H_
18+
#define ALICEO2_GENERATORTPARTICLE_H_
19+
#include <FairGenerator.h>
20+
#include <Generators/Generator.h>
21+
#include <list>
22+
23+
// Forward decls
24+
class TChain;
25+
class TParticle;
26+
class TClonesArray;
27+
28+
namespace o2
29+
{
30+
namespace eventgen
31+
{
32+
/// A class that reads in particles of class @c TParticle from a
33+
/// branch in a @c TChain.
34+
///
35+
/// Optionally, a program that generates such a @c TTree can be
36+
/// spawn, and the @c TParticles written to a file from which this
37+
/// object reads them in. This is done with
38+
///
39+
/// --configKeyValues "TParticle.progCmd=<eg program and options>"
40+
///
41+
/// which will execute the specified EG program with the given
42+
/// options. The EG program _must_ support the command line options
43+
///
44+
/// -n NUMBER Number of events to generate
45+
/// -o FILENAME Name of file to write to
46+
///
47+
/// The tree name and particle branch names can be configured.
48+
///
49+
/// --configKeyValues "TParticle.treeName=T,TParticle.branchName=P"
50+
///
51+
/// File(s) to read are also configurable
52+
///
53+
/// --configKeyValues "TParticle.fileNames=foo.root,bar.root"
54+
///
55+
class GeneratorTParticle : public Generator
56+
{
57+
public:
58+
/** CTOR */
59+
GeneratorTParticle() = default;
60+
/** CTOR */
61+
GeneratorTParticle(const std::string& name)
62+
: Generator(name.c_str(),"ALICEo2 TParticle Generator")
63+
{}
64+
/** DTOR */
65+
virtual ~GeneratorTParticle();
66+
67+
/** Initialize this generator. This will set up the chain.
68+
Optionally, if a command line was specified by @c
69+
TParticle.progCmd then that command line is executed in the
70+
background and events are read from the output file of that
71+
program */
72+
Bool_t Init() override;
73+
74+
/** Read in the next entry from the chain. Returns false in
75+
case of errors or no more entries to read. */
76+
Bool_t generateEvent() override;
77+
78+
/** Import the read-in particles into the steer particle
79+
stack */
80+
Bool_t importParticles() override;
81+
82+
/** Set the names of files to read, separated by commas */
83+
void setFileNames(const std::string& val);
84+
/** Set the name of the tree in the files. The tree _must_
85+
reside in the top-level directory of the files. */
86+
void setTreeName(const std::string& val) { mTreeName = val; }
87+
/** Set the branch name of the branch that holds a @c
88+
TClonesArray of @c TParticle objects */
89+
void setBranchName(const std::string& val) { mBranchName = val; }
90+
/** Set child program command line to (optionally) execute */
91+
void setProgCmd(const std::string& val) { mProgCmd = val; }
92+
/** Set the number of events to generate. */
93+
void setNEvents(unsigned int nev) { mNEvents = nev; }
94+
protected:
95+
std::string mTreeName = "T";
96+
std::string mBranchName = "Particles";
97+
std::string mProgCmd = "";
98+
std::list<std::string> mFileNames;
99+
unsigned int mNEvents = 0;
100+
unsigned int mEntry = 0;
101+
TChain* mChain;
102+
TClonesArray* mTParticles;
103+
104+
void waitForData();
105+
106+
ClassDefOverride(GeneratorTParticle,1);
107+
};
108+
}
109+
}
110+
#endif
111+
//
112+
// EOF
113+
//
114+
115+
116+
117+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
//
3+
// See https://alice-o2.web.cern.ch/copyright for details of the
4+
// copyright holders. All rights not expressly granted are reserved.
5+
//
6+
// This software is distributed under the terms of the GNU General
7+
// Public License v3 (GPL Version 3), copied verbatim in the file
8+
// "COPYING".
9+
//
10+
// In applying this license CERN does not waive the privileges and
11+
// immunities granted to it by virtue of its status as an
12+
// Intergovernmental Organization or submit itself to any
13+
// jurisdiction.
14+
//
15+
// @author: Christian Holm Christensen <cholm@nbi.dk>
16+
#ifndef ALICEO2_EVENTGEN_GENERATORTPARTICLEPARAM_H_
17+
#define ALICEO2_EVENTGEN_GENERATORTPARTICLEPARAM_H_
18+
19+
#include "CommonUtils/ConfigurableParam.h"
20+
#include "CommonUtils/ConfigurableParamHelper.h"
21+
#include <string>
22+
23+
namespace o2
24+
{
25+
namespace eventgen
26+
{
27+
28+
/**
29+
a parameter class/struct to keep the settings of the TGenerator
30+
event generator and allow the user to modify them */
31+
struct GeneratorTParticleParam :
32+
public o2::conf::ConfigurableParamHelper<GeneratorTParticleParam>
33+
{
34+
std::string treeName = "T";
35+
std::string branchName = "Particles";
36+
std::string fileNames = "tparticle.root";
37+
std::string progCmd = "";
38+
O2ParamDef(GeneratorTParticleParam, "TParticle");
39+
};
40+
} // end namespace eventgen
41+
} // end namespace o2
42+
43+
#endif // ALICEO2_EVENTGEN_GENERATORHEPMCPARAM_H_

Generators/src/GeneratorFactory.cxx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <fairlogger/Logger.h>
1919
#include <SimConfig/SimConfig.h>
2020
#include <Generators/GeneratorFromFile.h>
21+
#include <Generators/GeneratorTParticle.h>
22+
#include <Generators/GeneratorTParticleParam.h>
2123
#ifdef GENERATORS_WITH_PYTHIA6
2224
#include <Generators/GeneratorPythia6.h>
2325
#include <Generators/GeneratorPythia6Param.h>
@@ -86,6 +88,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
8688

8789
o2::O2DatabasePDG::addALICEParticles(TDatabasePDG::Instance());
8890
auto genconfig = conf.getGenerator();
91+
LOG(info) << "** Generator to use: '" << genconfig << "'";
8992
if (genconfig.compare("boxgen") == 0) {
9093
// a simple "box" generator configurable via BoxGunparam
9194
auto& boxparam = BoxGunParam::Instance();
@@ -154,18 +157,33 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
154157
if (o2PrimGen) {
155158
o2PrimGen->setApplyVertex(false);
156159
}
157-
}
158-
LOG(info) << "using external O2 kinematics";
160+
} LOG(info) << "using external O2 kinematics";
161+
} else if (genconfig.compare("tparticle") == 0) {
162+
// External ROOT file(s) with tree of TParticle in clones array,
163+
// or external program generating such a file
164+
auto& param = GeneratorTParticleParam::Instance();
165+
LOG(info) << "Init 'GeneratorTParticle' with the following parameters";
166+
LOG(info) << param;
167+
auto tgen = new o2::eventgen::GeneratorTParticle();
168+
tgen->setFileNames(param.fileNames);
169+
tgen->setProgCmd(param.progCmd);
170+
tgen->setTreeName(param.treeName);
171+
tgen->setBranchName(param.branchName);
172+
tgen->setNEvents(conf.getNEvents());
173+
primGen->AddGenerator(tgen);
159174
#ifdef GENERATORS_WITH_HEPMC3
160175
} else if (genconfig.compare("hepmc") == 0) {
161-
// external HepMC file
176+
// external HepMC file, or external program writing HepMC event
177+
// records to standard output.
162178
auto& param = GeneratorHepMCParam::Instance();
163179
LOG(info) << "Init \'GeneratorHepMC\' with following parameters";
164180
LOG(info) << param;
165181
auto hepmcGen = new o2::eventgen::GeneratorHepMC();
166182
hepmcGen->setFileName(param.fileName);
183+
hepmcGen->setProgCmd(param.progCmd);
167184
hepmcGen->setVersion(param.version);
168185
hepmcGen->setEventsToSkip(param.eventsToSkip);
186+
hepmcGen->setNEvents(conf.getNEvents());
169187
primGen->AddGenerator(hepmcGen);
170188
#endif
171189
#ifdef GENERATORS_WITH_PYTHIA6

0 commit comments

Comments
 (0)