-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathGenerator.h
More file actions
186 lines (148 loc) · 6.72 KB
/
Generator.h
File metadata and controls
186 lines (148 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \author R+Preghenella - August 2017
#ifndef ALICEO2_EVENTGEN_GENERATOR_H_
#define ALICEO2_EVENTGEN_GENERATOR_H_
#include "FairGenerator.h"
#include "TParticle.h"
#include "Generators/Trigger.h"
#include <functional>
#include <vector>
#include <unordered_map>
namespace o2
{
namespace dataformats
{
class MCEventHeader;
}
} // namespace o2
namespace o2
{
namespace eventgen
{
class GenTPCLoopers; // Forward declaration
/*****************************************************************/
/*****************************************************************/
// this class implements a generic FairGenerator extension
// that provides a base class for the ALICEo2 simulation needs
// such that different interfaces to the event generators
// (i.e. TGenerator, HEPdata reader) can be implemented
// according to a common protocol
class Generator : public FairGenerator
{
public:
enum ETriggerMode_t { kTriggerOFF,
kTriggerOR,
kTriggerAND };
/** default constructor **/
Generator();
/** constructor **/
Generator(const Char_t* name, const Char_t* title = "ALICEo2 Generator");
/** destructor **/
~Generator() override;
/** Initialize the generator if needed **/
Bool_t Init() override;
/** Abstract method ReadEvent must be implemented by any derived class.
has to handle the generation of input tracks (reading from input
file) and the handing of the tracks to the FairPrimaryGenerator. It is
called from FairMCApplication.
*@param pStack The stack
*@return kTRUE if successful, kFALSE if not
**/
Bool_t ReadEvent(FairPrimaryGenerator* primGen) final;
/** methods to override **/
virtual Bool_t generateEvent() = 0; // generates event (in structure internal to generator)
virtual Bool_t importParticles() = 0; // fills the mParticles vector (transfer from generator state)
Bool_t finalizeEvent(); // final part of event generation that can be customised using external macros
virtual void updateHeader(o2::dataformats::MCEventHeader* eventHeader) {};
Bool_t triggerEvent();
/** setters **/
void setMomentumUnit(double val) { mMomentumUnit = val; };
double getMomentumUnit() const { return mMomentumUnit; }
void setEnergyUnit(double val) { mEnergyUnit = val; };
double getEnergyUnit() const { return mEnergyUnit; }
void setPositionUnit(double val) { mPositionUnit = val; };
double getPositionUnit() const { return mPositionUnit; }
void setTimeUnit(double val) { mTimeUnit = val; };
double getTimeUnit() const { return mTimeUnit; }
void setBoost(Double_t val) { mBoost = val; };
void setTriggerMode(ETriggerMode_t val) { mTriggerMode = val; };
void addTrigger(Trigger trigger) { mTriggers.push_back(trigger); };
void addDeepTrigger(DeepTrigger trigger) { mDeepTriggers.push_back(trigger); };
// setter for global number of events
static void setTotalNEvents(unsigned int& n) { gTotalNEvents = n; }
/** getters **/
const std::vector<TParticle>& getParticles() const { return mParticles; }; //!
static unsigned int getTotalNEvents() { return gTotalNEvents; };
/** other **/
void clearParticles() { mParticles.clear(); };
/** notification methods **/
virtual void notifyEmbedding(const o2::dataformats::MCEventHeader* eventHeader){};
void setTriggerOkHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerOkHook = f; }
void setTriggerFalseHook(std::function<void(std::vector<TParticle> const& p, int eventCount)> f) { mTriggerFalseHook = f; }
protected:
/** copy constructor **/
Generator(const Generator&);
/** operator= **/
Generator& operator=(const Generator&);
/** internal methods **/
Bool_t addTracks(FairPrimaryGenerator* primGen);
Bool_t boostEvent();
/** to handle cocktail constituents **/
void addSubGenerator(int subGeneratorId, std::string const& subGeneratorDescription);
void notifySubGenerator(int subGeneratorId) { mSubGeneratorId = subGeneratorId; }
/** generator interface **/
void* mInterface = nullptr;
std::string mInterfaceName;
/** trigger data members **/
ETriggerMode_t mTriggerMode = kTriggerOFF;
std::vector<Trigger> mTriggers; //!
std::vector<DeepTrigger> mDeepTriggers; //!
// we allow to register callbacks so as to take specific user actions when
// a trigger was ok nor not
std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerOkHook = [](std::vector<TParticle> const& p, int eventCount) {};
std::function<void(std::vector<TParticle> const& p, int eventCount)> mTriggerFalseHook = [](std::vector<TParticle> const& p, int eventCount) {};
int mReadEventCounter = 0; // counting the number of times
/** conversion data members **/
double mMomentumUnit = 1.; // [GeV/c]
double mEnergyUnit = 1.; // [GeV/c]
double mPositionUnit = 0.1; // [cm]
double mTimeUnit = 3.3356410e-12; // [s]
/** particle array **/
std::vector<TParticle> mParticles; //!
/** lorentz boost data members **/
Double_t mBoost;
// a unique generator instance counter
// this can be used to make sure no two generator instances have the same seed etc.
static std::atomic<int> InstanceCounter;
int mThisInstanceID = 0;
private:
void updateSubGeneratorInformation(o2::dataformats::MCEventHeader* header) const;
// loopers flag
Bool_t mAddTPCLoopers = kFALSE; // Flag is automatically set to true if TPC is in readout detectors, loopers are not vetoed and transport is enabled
// collect an ID and a short description of sub-generator entities
std::unordered_map<int, std::string> mSubGeneratorsIdToDesc;
// the current ID of the sub-generator used in the current event (if applicable)
int mSubGeneratorId = -1;
// global static information about (upper limit of) number of events to be generated
static unsigned int gTotalNEvents;
// Loopers generator instance
o2::eventgen::GenTPCLoopers* mTPCLoopersGen = nullptr;
#ifdef GENERATORS_WITH_TPCLOOPERS
bool initTPCLoopersGen();
#endif
ClassDefOverride(Generator, 2);
}; /** class Generator **/
/*****************************************************************/
/*****************************************************************/
} // namespace eventgen
} // namespace o2
#endif /* ALICEO2_EVENTGEN_GENERATOR_H_ */