Project
Loading...
Searching...
No Matches
GeneratorService.cxx
Go to the documentation of this file.
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
14#include "SimConfig/SimConfig.h"
17#include <TCollection.h>
18#include <TObjArray.h>
19
20using namespace o2::eventgen;
21
22void GeneratorService::initService(std::string const& genName,
23 std::string const& triggerName,
24 VertexOption const& vxtOption)
25{
26 auto localSimConfig = o2::conf::SimConfig::make();
27 localSimConfig.getConfigData().mGenerator = genName;
28 localSimConfig.getConfigData().mTrigger = triggerName;
29 localSimConfig.getConfigData().mNEvents = o2::eventgen::Generator::getTotalNEvents();
30
32
33 // initialize vertexing based on type
34 if (dynamic_cast<MeanVertexObjectOption const*>(&vxtOption) != nullptr) {
35 auto ccdboption = dynamic_cast<MeanVertexObjectOption const*>(&vxtOption);
36 LOG(info) << "Init prim gen with MeanVertexObject";
37 // assign the mean vertex object
38 if (!ccdboption->meanVertexObject) {
39 LOG(fatal) << "No mean vertex object found - Cannot initialize Event generator";
40 }
41 mPrimGen.setVertexMode(o2::conf::VertexMode::kCCDB, ccdboption->meanVertexObject);
42 } else if (dynamic_cast<NoVertexOption const*>(&vxtOption) != nullptr) {
44 } else if (dynamic_cast<DiamondParamVertexOption const*>(&vxtOption) != nullptr) {
46 } else {
47 LOG(error) << "Unknown VertexOption passed to Generator initialization";
48 }
49
50 mStack.setExternalMode(true);
51 mPrimGen.Init();
52}
53
55{
56 mPrimGen.SetEvent(&header);
57 mStack.Reset();
58 mPrimGen.GenerateEvent(&mStack); // this is the usual FairROOT interface going via stack
59
60 tracks.reserve(mStack.getPrimaries().size());
61 for (auto& tparticle : mStack.getPrimaries()) {
62 tracks.emplace_back(tparticle);
63 }
64}
65
67{
68 mPrimGen.SetEvent(&header);
69 mStack.Reset();
70 mPrimGen.GenerateEvent(&mStack); // this is the usual FairROOT interface going via stack
71
72 tracks.reserve(mStack.getPrimaries().size());
73 for (auto& tparticle : mStack.getPrimaries()) {
74 tracks.emplace_back(tparticle);
75 }
76}
77
79{
80 std::vector<o2::MCTrack> tracks;
82 generateEvent_MCTracks(tracks, header);
83 return std::pair<std::vector<MCTrack>, o2::dataformats::MCEventHeader>(tracks, header);
84}
85
87{
88 mPrimGen.SetEvent(&header);
89 mStack.Reset();
90 mPrimGen.GenerateEvent(&mStack); // this is the usual FairROOT interface going via stack
91
92 tracks.clear();
93 tracks = mStack.getPrimaries();
94}
95
97{
98 auto* generators = mPrimGen.GetListOfGenerators();
99 if (!generators) {
100 return;
101 }
102 TIter next(generators);
103 while (TObject* obj = next()) {
104 if (auto* gen = dynamic_cast<o2::eventgen::Generator*>(obj)) {
105 gen->stop();
106 }
107 }
108}
default_random_engine gen(dev())
static SimConfig make()
Definition SimConfig.h:119
void setExternalMode(bool m)
Definition Stack.h:205
void Reset() override
Resets arrays and stack and deletes particles and tracks.
Definition Stack.cxx:588
const std::vector< TParticle > & getPrimaries() const
Definition Stack.h:187
std::pair< std::vector< MCTrack >, o2::dataformats::MCEventHeader > generateEvent()
void generateEvent_MCTracks(std::vector< MCTrack > &tracks, o2::dataformats::MCEventHeader &header)
void generateEvent_TParticles(std::vector< TParticle > &tparts, o2::dataformats::MCEventHeader &header)
void initService(std::string const &generatorName, std::string const &triggerName, VertexOption const &vtxOption)
static unsigned int getTotalNEvents()
Definition Generator.h:100
Bool_t GenerateEvent(FairGenericStack *pStack) override
void setVertexMode(o2::conf::VertexMode const &mode, o2::dataformats::MeanVertexObject const *obj=nullptr)
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
static void setPrimaryGenerator(o2::conf::SimConfig const &, FairPrimaryGenerator *)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"