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
37/*****************************************************************/
38/*****************************************************************/
39
40// this class implements a generic FairGenerator extension
41// that provides a base class for the ALICEo2 simulation needs
42// such that different interfaces to the event generators
43// (i.e. TGenerator, HEPdata reader) can be implemented
44// according to a common protocol
45
47{
48
49 public:
53
55 Generator();
57 Generator(const Char_t* name, const Char_t* title = "ALICEo2 Generator");
59 ~Generator() override = default;
60
62 Bool_t Init() override;
63
71 Bool_t ReadEvent(FairPrimaryGenerator* primGen) final;
72
74 virtual Bool_t generateEvent() = 0; // generates event (in structure internal to generator)
75 virtual Bool_t importParticles() = 0; // fills the mParticles vector (transfer from generator state)
76 virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader) {};
77 Bool_t triggerEvent();
78
80 void setMomentumUnit(double val) { mMomentumUnit = val; };
81 double getMomentumUnit() const { return mMomentumUnit; }
82 void setEnergyUnit(double val) { mEnergyUnit = val; };
83 double getEnergyUnit() const { return mEnergyUnit; }
84 void setPositionUnit(double val) { mPositionUnit = val; };
85 double getPositionUnit() const { return mPositionUnit; }
86 void setTimeUnit(double val) { mTimeUnit = val; };
87 double getTimeUnit() const { return mTimeUnit; }
88 void setBoost(Double_t val) { mBoost = val; };
90 void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
91 void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
92 // setter for global number of events
93 static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }
94
96 const std::vector<TParticle>& getParticles() const { return mParticles; };
97 static unsigned int getTotalNEvents() { return gTotalNEvents; };
98
100 void clearParticles() { mParticles.clear(); };
101
103 virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
104
105 void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
106 void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
107
108 protected:
113
115 Bool_t addTracks(FairPrimaryGenerator* primGen);
116 Bool_t boostEvent();
117
119 void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
120 void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
121
123 void* mInterface = nullptr;
124 std::string mInterfaceName;
125
128 std::vector<Trigger> mTriggers;
129 std::vector<DeepTrigger> mDeepTriggers;
130
131 // we allow to register callbacks so as to take specific user actions when
132 // a trigger was ok nor not
133 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
134 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
135 int mReadEventCounter = 0; // counting the number of times
136
138 double mMomentumUnit = 1.; // [GeV/c]
139 double mEnergyUnit = 1.; // [GeV/c]
140 double mPositionUnit = 0.1; // [cm]
141 double mTimeUnit = 3.3356410e-12; // [s]
142
144 std::vector<TParticle> mParticles;
145
147 Double_t mBoost;
148
149 // a unique generator instance counter
150 // this can be used to make sure no two generator instances have the same seed etc.
151 static std::atomic<int> InstanceCounter;
153
154 private:
155 void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
156
157 // collect an ID and a short description of sub-generator entities
158 std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
159 // the current ID of the sub-generator used in the current event (if applicable)
160 int mSubGeneratorId = -1;
161
162 // global static information about (upper limit of) number of events to be generated
163 static unsigned int gTotalNEvents;
164
165 ClassDefOverride(Generator, 2);
166
167};
169/*****************************************************************/
170/*****************************************************************/
171
172} // namespace eventgen
173} // namespace o2
174
175#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
void setTriggerMode(ETriggerMode_t val)
Definition Generator.h:89
virtual void updateHeader(o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:76
double getMomentumUnit() const
Definition Generator.h:81
void setPositionUnit(double val)
Definition Generator.h:84
std::string mInterfaceName
Definition Generator.h:124
Bool_t ReadEvent(FairPrimaryGenerator *primGen) final
Definition Generator.cxx:68
void setEnergyUnit(double val)
Definition Generator.h:82
void notifySubGenerator(int subGeneratorId)
Definition Generator.h:120
static std::atomic< int > InstanceCounter
Definition Generator.h:151
void setBoost(Double_t val)
Definition Generator.h:88
std::vector< Trigger > mTriggers
Definition Generator.h:128
static unsigned int getTotalNEvents()
Definition Generator.h:97
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerOkHook
Definition Generator.h:133
virtual Bool_t generateEvent()=0
double getEnergyUnit() const
Definition Generator.h:83
std::vector< DeepTrigger > mDeepTriggers
Definition Generator.h:129
void setTimeUnit(double val)
Definition Generator.h:86
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerFalseHook
Definition Generator.h:134
void addSubGenerator(int subGeneratorId, std::string const &subGeneratorDescription)
ETriggerMode_t mTriggerMode
Definition Generator.h:127
static void setTotalNEvents(unsigned int &n)
Definition Generator.h:93
Bool_t addTracks(FairPrimaryGenerator *primGen)
Generator & operator=(const Generator &)
virtual void notifyEmbedding(const o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:103
void setTriggerFalseHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:106
const std::vector< TParticle > & getParticles() const
Definition Generator.h:96
void setTriggerOkHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:105
std::vector< TParticle > mParticles
Definition Generator.h:144
void setMomentumUnit(double val)
Definition Generator.h:80
Generator(const Generator &)
void addDeepTrigger(DeepTrigger trigger)
Definition Generator.h:91
~Generator() override=default
void addTrigger(Trigger trigger)
Definition Generator.h:90
double getPositionUnit() const
Definition Generator.h:85
double getTimeUnit() const
Definition Generator.h:87
virtual Bool_t importParticles()=0
Bool_t Init() override
Definition Generator.cxx:57
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 ...