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 void setEnergyUnit(double val) { mEnergyUnit = val; };
82 void setPositionUnit(double val) { mPositionUnit = val; };
83 void setTimeUnit(double val) { mTimeUnit = val; };
84 void setBoost(Double_t val) { mBoost = val; };
86 void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
87 void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
88 // setter for global number of events
89 static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }
90
92 const std::vector<TParticle>& getParticles() const { return mParticles; };
93 static unsigned int getTotalNEvents() { return gTotalNEvents; };
94
96 void clearParticles() { mParticles.clear(); };
97
99 virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
100
101 void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
102 void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
103
104 protected:
109
111 Bool_t addTracks(FairPrimaryGenerator* primGen);
112 Bool_t boostEvent();
113
115 void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
116 void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
117
119 void* mInterface = nullptr;
120 std::string mInterfaceName;
121
124 std::vector<Trigger> mTriggers;
125 std::vector<DeepTrigger> mDeepTriggers;
126
127 // we allow to register callbacks so as to take specific user actions when
128 // a trigger was ok nor not
129 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
130 std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
131 int mReadEventCounter = 0; // counting the number of times
132
134 double mMomentumUnit = 1.; // [GeV/c]
135 double mEnergyUnit = 1.; // [GeV/c]
136 double mPositionUnit = 0.1; // [cm]
137 double mTimeUnit = 3.3356410e-12; // [s]
138
140 std::vector<TParticle> mParticles;
141
143 Double_t mBoost;
144
145 // a unique generator instance counter
146 // this can be used to make sure no two generator instances have the same seed etc.
147 static std::atomic<int> InstanceCounter;
149
150 private:
151 void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
152
153 // collect an ID and a short description of sub-generator entities
154 std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
155 // the current ID of the sub-generator used in the current event (if applicable)
156 int mSubGeneratorId = -1;
157
158 // global static information about (upper limit of) number of events to be generated
159 static unsigned int gTotalNEvents;
160
161 ClassDefOverride(Generator, 2);
162
163};
165/*****************************************************************/
166/*****************************************************************/
167
168} // namespace eventgen
169} // namespace o2
170
171#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */
void setTriggerMode(ETriggerMode_t val)
Definition Generator.h:85
virtual void updateHeader(o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:76
void setPositionUnit(double val)
Definition Generator.h:82
std::string mInterfaceName
Definition Generator.h:120
Bool_t ReadEvent(FairPrimaryGenerator *primGen) final
Definition Generator.cxx:68
void setEnergyUnit(double val)
Definition Generator.h:81
void notifySubGenerator(int subGeneratorId)
Definition Generator.h:116
static std::atomic< int > InstanceCounter
Definition Generator.h:147
void setBoost(Double_t val)
Definition Generator.h:84
std::vector< Trigger > mTriggers
Definition Generator.h:124
static unsigned int getTotalNEvents()
Definition Generator.h:93
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerOkHook
Definition Generator.h:129
virtual Bool_t generateEvent()=0
std::vector< DeepTrigger > mDeepTriggers
Definition Generator.h:125
void setTimeUnit(double val)
Definition Generator.h:83
std::function< void(std::vector< TParticle > const &p, int eventCount)> mTriggerFalseHook
Definition Generator.h:130
void addSubGenerator(int subGeneratorId, std::string const &subGeneratorDescription)
ETriggerMode_t mTriggerMode
Definition Generator.h:123
static void setTotalNEvents(unsigned int &n)
Definition Generator.h:89
Bool_t addTracks(FairPrimaryGenerator *primGen)
Generator & operator=(const Generator &)
virtual void notifyEmbedding(const o2::dataformats::MCEventHeader *eventHeader)
Definition Generator.h:99
void setTriggerFalseHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:102
const std::vector< TParticle > & getParticles() const
Definition Generator.h:92
void setTriggerOkHook(std::function< void(std::vector< TParticle > const &p, int eventCount)> f)
Definition Generator.h:101
std::vector< TParticle > mParticles
Definition Generator.h:140
void setMomentumUnit(double val)
Definition Generator.h:80
Generator(const Generator &)
void addDeepTrigger(DeepTrigger trigger)
Definition Generator.h:87
~Generator() override=default
void addTrigger(Trigger trigger)
Definition Generator.h:86
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 ...