Project
Loading...
Searching...
No Matches
Generator.h
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
13
14#ifndef ALICEO2_EVENTGEN_GENERATOR_H_
15#define ALICEO2_EVENTGEN_GENERATOR_H_
16
17#include "FairGenerator.h"
18#include "TParticle.h"
19#include "Generators/Trigger.h"
20#include <functional>
21#include <vector>
22#include <unordered_map>
23
24namespace o2
25{
26namespace dataformats
27{
28class MCEventHeader;
29}
30} // namespace o2
31
32namespace o2
33{
34namespace eventgen
35{
36
37class GenTPCLoopers; // Forward declaration
38class EventDecayer;
39struct EventDecayerReport;
40
41/*****************************************************************/
42/*****************************************************************/
43
44// this class implements a generic FairGenerator extension
45// that provides a base class for the ALICEo2 simulation needs
46// such that different interfaces to the event generators
47// (i.e. TGenerator, HEPdata reader) can be implemented
48// according to a common protocol
49
51{
52
53 public:
57
59 Generator();
61 Generator(const Char_t* name, const Char_t* title = "ALICEo2 Generator");
63 ~Generator() override;
64
66 Bool_t Init() override;
67
75 Bool_t ReadEvent(FairPrimaryGenerator* primGen) final;
76
78 virtual Bool_t generateEvent() = 0; // generates event (in structure internal to generator)
79 virtual Bool_t importParticles() = 0; // fills the mParticles vector (transfer from generator state)
80 Bool_t finalizeEvent(); // final part of event generation that can be customised using external macros
81 virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader) {};
82 Bool_t triggerEvent();
83
85 void setMomentumUnit(double val) { mMomentumUnit = val; };
86 double getMomentumUnit() const { return mMomentumUnit; }
87 void setEnergyUnit(double val) { mEnergyUnit = val; };
88 double getEnergyUnit() const { return mEnergyUnit; }
89 void setPositionUnit(double val) { mPositionUnit = val; };
90 double getPositionUnit() const { return mPositionUnit; }
91 void setTimeUnit(double val) { mTimeUnit = val; };
92 double getTimeUnit() const { return mTimeUnit; }
93 void setBoost(Double_t val) { mBoost = val; };
95 void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
96 void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
97 // setter for global number of events
98 static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }
99
101 const std::vector<TParticle>& getParticles() const { return mParticles; };
102 static unsigned int getTotalNEvents() { return gTotalNEvents; };
103
104 // Check if simulation is running in Hyperloop mode
105 static bool isHyperloop();
106
107 // Number of parallel sub-generator clones a Hyperloop-aware generator expands into
108 // (currently used by the external-generator-to-hybrid expansion in GeneratorFactory).
109 // 8 matches the standard core counts of Grid/Hyperloop nodes
110 static constexpr int NHyperloopParallelGenerators = 8;
111
113 void clearParticles() { mParticles.clear(); };
114
116 virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
117
120 virtual void stop() {}
121
122 void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
123 void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
124
125 protected:
130
132 Bool_t addTracks(FairPrimaryGenerator* primGen);
133 Bool_t boostEvent();
134
136 void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
137 void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
138
140 void* mInterface = nullptr;
141 std::string mInterfaceName;
142
145 std::vector<Trigger> mTriggers;
146 std::vector<DeepTrigger> mDeepTriggers;
147
148 // we allow to register callbacks so as to take specific user actions when
149 // a trigger was ok nor not
150 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
151 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
152 int mReadEventCounter = 0; // counting the number of times
153
155 double mMomentumUnit = 1.; // [GeV/c]
156 double mEnergyUnit = 1.; // [GeV/c]
157 double mPositionUnit = 0.1; // [cm]
158 double mTimeUnit = 3.3356410e-12; // [s]
159
161 std::vector<TParticle> mParticles;
162
164 Double_t mBoost;
165
166 // a unique generator instance counter
167 // this can be used to make sure no two generator instances have the same seed etc.
168 static std::atomic<int> InstanceCounter;
170
171 private:
172 void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
173
174 // loopers flag
175 Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
176 // collect an ID and a short description of sub-generator entities
177 std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
178 // the current ID of the sub-generator used in the current event (if applicable)
179 int mSubGeneratorId = -1;
180
181 // global static information about (upper limit of) number of events to be generated
182 static unsigned int gTotalNEvents;
183
184 // Loopers generator instance
185 o2::eventgen::GenTPCLoopers* mTPCLoopersGen = nullptr;
186
187 // decay step after the trigger, created on first use when EventDecayer.enable is set
188 o2::eventgen::EventDecayer* mEventDecayer = nullptr;
189 o2::eventgen::EventDecayerReport* mEventDecayerReport = nullptr;
190 Bool_t decayParticles(o2::dataformats::MCEventHeader* header);
191#ifdef GENERATORS_WITH_TPCLOOPERS
192 bool initTPCLoopersGen();
193#endif
194
195 ClassDefOverride(Generator, 2);
196
197};
199/*****************************************************************/
200/*****************************************************************/
201
202} // namespace eventgen
203} // namespace o2
204
205#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
Decays unstable generator particles with Pythia8 before transport, keeping the full chain.
void setTriggerMode(ETriggerMode_t val)
Definition Generator.h:94
virtual void updateHeader(o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:81
double getMomentumUnit() const
Definition Generator.h:86
void setPositionUnit(double val)
Definition Generator.h:89
std::string mInterfaceName
Definition Generator.h:141
Bool_t ReadEvent(FairPrimaryGenerator *primGen) final
void setEnergyUnit(double val)
Definition Generator.h:87
void notifySubGenerator(int subGeneratorId)
Definition Generator.h:137
static std::atomic< int > InstanceCounter
Definition Generator.h:168
void setBoost(Double_t val)
Definition Generator.h:93
std::vector< Trigger > mTriggers
Definition Generator.h:145
static unsigned int getTotalNEvents()
Definition Generator.h:102
static constexpr int NHyperloopParallelGenerators
Definition Generator.h:110
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerOkHook
Definition Generator.h:150
virtual Bool_t generateEvent()=0
double getEnergyUnit() const
Definition Generator.h:88
std::vector< DeepTrigger > mDeepTriggers
Definition Generator.h:146
void setTimeUnit(double val)
Definition Generator.h:91
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerFalseHook
Definition Generator.h:151
void addSubGenerator(int subGeneratorId, std::string const &subGeneratorDescription)
ETriggerMode_t mTriggerMode
Definition Generator.h:144
static bool isHyperloop()
Definition Generator.cxx:49
static void setTotalNEvents(unsigned int &n)
Definition Generator.h:98
Bool_t addTracks(FairPrimaryGenerator *primGen)
Generator & operator=(const Generator &)
virtual void notifyEmbedding(const o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:116
void setTriggerFalseHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:123
const std::vector< TParticle > & getParticles() const
Definition Generator.h:101
void setTriggerOkHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:122
std::vector< TParticle > mParticles
Definition Generator.h:161
void setMomentumUnit(double val)
Definition Generator.h:85
Generator(const Generator &)
virtual void stop()
Definition Generator.h:120
void addDeepTrigger(DeepTrigger trigger)
Definition Generator.h:96
void addTrigger(Trigger trigger)
Definition Generator.h:95
double getPositionUnit() const
Definition Generator.h:90
double getTimeUnit() const
Definition Generator.h:92
virtual Bool_t importParticles()=0
Bool_t Init() override
GLdouble n
Definition glcorearb.h:1982
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
std::function< bool(void *, std::string)> DeepTrigger
Definition Trigger.h:26
std::function< bool(const std::vector< TParticle > &)> Trigger
Definition Trigger.h:25
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Counts of what one or more EventDecayer::decay calls did, per PDG code.