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#ifdef GENERATORS_WITH_TPCLOOPERS
23#endif
24#include <functional>
25#include <vector>
26#include <unordered_map>
27
28namespace o2
29{
30namespace dataformats
31{
32class MCEventHeader;
33}
34} // namespace o2
35
36namespace o2
37{
38namespace eventgen
39{
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 = default;
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
105 void clearParticles() { mParticles.clear(); };
106
108 virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
109
110 void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
111 void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
112
113 protected:
118
120 Bool_t addTracks(FairPrimaryGenerator* primGen);
121 Bool_t boostEvent();
122
124 void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
125 void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
126
128 void* mInterface = nullptr;
129 std::string mInterfaceName;
130
133 std::vector<Trigger> mTriggers;
134 std::vector<DeepTrigger> mDeepTriggers;
135
136 // we allow to register callbacks so as to take specific user actions when
137 // a trigger was ok nor not
138 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
139 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
140 int mReadEventCounter = 0; // counting the number of times
141
143 double mMomentumUnit = 1.; // [GeV/c]
144 double mEnergyUnit = 1.; // [GeV/c]
145 double mPositionUnit = 0.1; // [cm]
146 double mTimeUnit = 3.3356410e-12; // [s]
147
149 std::vector<TParticle> mParticles;
150
152 Double_t mBoost;
153
154 // a unique generator instance counter
155 // this can be used to make sure no two generator instances have the same seed etc.
156 static std::atomic<int> InstanceCounter;
158
159 private:
160 void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
161
162 // loopers flag
163 Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
164 // collect an ID and a short description of sub-generator entities
165 std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
166 // the current ID of the sub-generator used in the current event (if applicable)
167 int mSubGeneratorId = -1;
168
169 // global static information about (upper limit of) number of events to be generated
170 static unsigned int gTotalNEvents;
171
172#ifdef GENERATORS_WITH_TPCLOOPERS
173 // Loopers generator instance
174 std::unique_ptr<o2::eventgen::GenTPCLoopers> mTPCLoopersGen = nullptr;
175 bool initTPCLoopersGen();
176#endif
177
178 ClassDefOverride(Generator, 2);
179
180};
182/*****************************************************************/
183/*****************************************************************/
184
185} // namespace eventgen
186} // namespace o2
187
188#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
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:129
Bool_t ReadEvent(FairPrimaryGenerator *primGen) final
void setEnergyUnit(double val)
Definition Generator.h:87
void notifySubGenerator(int subGeneratorId)
Definition Generator.h:125
static std::atomic< int > InstanceCounter
Definition Generator.h:156
void setBoost(Double_t val)
Definition Generator.h:93
std::vector< Trigger > mTriggers
Definition Generator.h:133
static unsigned int getTotalNEvents()
Definition Generator.h:102
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerOkHook
Definition Generator.h:138
virtual Bool_t generateEvent()=0
double getEnergyUnit() const
Definition Generator.h:88
std::vector< DeepTrigger > mDeepTriggers
Definition Generator.h:134
void setTimeUnit(double val)
Definition Generator.h:91
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerFalseHook
Definition Generator.h:139
void addSubGenerator(int subGeneratorId, std::string const &subGeneratorDescription)
ETriggerMode_t mTriggerMode
Definition Generator.h:132
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:108
void setTriggerFalseHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:111
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:110
std::vector< TParticle > mParticles
Definition Generator.h:149
void setMomentumUnit(double val)
Definition Generator.h:85
Generator(const Generator &)
void addDeepTrigger(DeepTrigger trigger)
Definition Generator.h:96
~Generator() override=default
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 ...