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
38
39/*****************************************************************/
40/*****************************************************************/
41
42// this class implements a generic FairGenerator extension
43// that provides a base class for the ALICEo2 simulation needs
44// such that different interfaces to the event generators
45// (i.e. TGenerator, HEPdata reader) can be implemented
46// according to a common protocol
47
49{
50
51 public:
55
57 Generator();
59 Generator(const Char_t* name, const Char_t* title = "ALICEo2 Generator");
61 ~Generator() override;
62
64 Bool_t Init() override;
65
73 Bool_t ReadEvent(FairPrimaryGenerator* primGen) final;
74
76 virtual Bool_t generateEvent() = 0; // generates event (in structure internal to generator)
77 virtual Bool_t importParticles() = 0; // fills the mParticles vector (transfer from generator state)
78 Bool_t finalizeEvent(); // final part of event generation that can be customised using external macros
79 virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader) {};
80 Bool_t triggerEvent();
81
83 void setMomentumUnit(double val) { mMomentumUnit = val; };
84 double getMomentumUnit() const { return mMomentumUnit; }
85 void setEnergyUnit(double val) { mEnergyUnit = val; };
86 double getEnergyUnit() const { return mEnergyUnit; }
87 void setPositionUnit(double val) { mPositionUnit = val; };
88 double getPositionUnit() const { return mPositionUnit; }
89 void setTimeUnit(double val) { mTimeUnit = val; };
90 double getTimeUnit() const { return mTimeUnit; }
91 void setBoost(Double_t val) { mBoost = val; };
93 void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
94 void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
95 // setter for global number of events
96 static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }
97
99 const std::vector<TParticle>& getParticles() const { return mParticles; };
100 static unsigned int getTotalNEvents() { return gTotalNEvents; };
101
103 void clearParticles() { mParticles.clear(); };
104
106 virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
107
110 virtual void stop() {}
111
112 void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
113 void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
114
115 protected:
120
122 Bool_t addTracks(FairPrimaryGenerator* primGen);
123 Bool_t boostEvent();
124
126 void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
127 void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
128
130 void* mInterface = nullptr;
131 std::string mInterfaceName;
132
135 std::vector<Trigger> mTriggers;
136 std::vector<DeepTrigger> mDeepTriggers;
137
138 // we allow to register callbacks so as to take specific user actions when
139 // a trigger was ok nor not
140 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
141 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
142 int mReadEventCounter = 0; // counting the number of times
143
145 double mMomentumUnit = 1.; // [GeV/c]
146 double mEnergyUnit = 1.; // [GeV/c]
147 double mPositionUnit = 0.1; // [cm]
148 double mTimeUnit = 3.3356410e-12; // [s]
149
151 std::vector<TParticle> mParticles;
152
154 Double_t mBoost;
155
156 // a unique generator instance counter
157 // this can be used to make sure no two generator instances have the same seed etc.
158 static std::atomic<int> InstanceCounter;
160
161 private:
162 void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
163
164 // loopers flag
165 Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
166 // collect an ID and a short description of sub-generator entities
167 std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
168 // the current ID of the sub-generator used in the current event (if applicable)
169 int mSubGeneratorId = -1;
170
171 // global static information about (upper limit of) number of events to be generated
172 static unsigned int gTotalNEvents;
173
174 // Loopers generator instance
175 o2::eventgen::GenTPCLoopers* mTPCLoopersGen = nullptr;
176#ifdef GENERATORS_WITH_TPCLOOPERS
177 bool initTPCLoopersGen();
178#endif
179
180 ClassDefOverride(Generator, 2);
181
182};
184/*****************************************************************/
185/*****************************************************************/
186
187} // namespace eventgen
188} // namespace o2
189
190#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
void setTriggerMode(ETriggerMode_t val)
Definition Generator.h:92
virtual void updateHeader(o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:79
double getMomentumUnit() const
Definition Generator.h:84
void setPositionUnit(double val)
Definition Generator.h:87
std::string mInterfaceName
Definition Generator.h:131
Bool_t ReadEvent(FairPrimaryGenerator *primGen) final
void setEnergyUnit(double val)
Definition Generator.h:85
void notifySubGenerator(int subGeneratorId)
Definition Generator.h:127
static std::atomic< int > InstanceCounter
Definition Generator.h:158
void setBoost(Double_t val)
Definition Generator.h:91
std::vector< Trigger > mTriggers
Definition Generator.h:135
static unsigned int getTotalNEvents()
Definition Generator.h:100
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerOkHook
Definition Generator.h:140
virtual Bool_t generateEvent()=0
double getEnergyUnit() const
Definition Generator.h:86
std::vector< DeepTrigger > mDeepTriggers
Definition Generator.h:136
void setTimeUnit(double val)
Definition Generator.h:89
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerFalseHook
Definition Generator.h:141
void addSubGenerator(int subGeneratorId, std::string const &subGeneratorDescription)
ETriggerMode_t mTriggerMode
Definition Generator.h:134
static void setTotalNEvents(unsigned int &n)
Definition Generator.h:96
Bool_t addTracks(FairPrimaryGenerator *primGen)
Generator & operator=(const Generator &)
virtual void notifyEmbedding(const o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:106
void setTriggerFalseHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:113
const std::vector< TParticle > & getParticles() const
Definition Generator.h:99
void setTriggerOkHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:112
std::vector< TParticle > mParticles
Definition Generator.h:151
void setMomentumUnit(double val)
Definition Generator.h:83
Generator(const Generator &)
virtual void stop()
Definition Generator.h:110
void addDeepTrigger(DeepTrigger trigger)
Definition Generator.h:94
void addTrigger(Trigger trigger)
Definition Generator.h:93
double getPositionUnit() const
Definition Generator.h:88
double getTimeUnit() const
Definition Generator.h:90
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 ...