forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxGenerator.h
More file actions
140 lines (121 loc) · 4.4 KB
/
BoxGenerator.h
File metadata and controls
140 lines (121 loc) · 4.4 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
// 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 Sandro Wenzel - April 2024
#ifndef ALICEO2_EVENTGEN_BOX
#define ALICEO2_EVENTGEN_BOX
#include "Generators/Generator.h"
#include "TParticle.h"
#include <vector>
#include <Generators/BoxGunParam.h>
#include "SimulationDataFormat/MCEventHeader.h"
#include "SimulationDataFormat/ParticleStatus.h"
#include <SimulationDataFormat/MCGenProperties.h>
namespace o2::eventgen
{
/*
* A simple mono-pdg "BoxGenerator". Or particle gun.
* Re-implements FairBoxGenerator for more convenient O2-processing.
*/
class BoxGenerator : public Generator
{
public:
BoxGenerator() = default;
BoxGenerator(int pdgid, int mult = 1);
BoxGenerator(int pdgid,
int mult,
double etamin,
double etamax,
double pmin,
double pmax,
double phimin,
double phimax) : mPDG{pdgid}, mMult{mult}
{
SetEtaRange(etamin, etamax);
SetPRange(pmin, pmax);
SetPhiRange(phimin, phimax);
}
BoxGenerator(BoxGenConfig const& config) : mPDG{config.pdg}, mMult{config.number}
{
SetEtaRange(config.eta[0], config.eta[1]);
SetPRange(config.prange[0], config.prange[1]);
SetPhiRange(config.phirange[0], config.phirange[1]);
}
void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10)
{
mPMin = pmin;
mPMax = pmax;
mPRangeIsSet = true;
}
void SetPhiRange(double phimin = 0, double phimax = 360)
{
mPhiMin = phimin;
mPhiMax = phimax;
}
void SetEtaRange(double etamin = -5, double etamax = 5)
{
mEtaMin = etamin;
mEtaMax = etamax;
mEtaRangeIsSet = true;
}
/// generates a single particle conforming to particle gun parameters
TParticle sampleParticle() const;
/// implements the main O2 generator interfaces
bool generateEvent() override
{
mEvent.clear();
for (int i = 0; i < mMult; ++i) {
mEvent.push_back(sampleParticle());
}
return true;
}
bool importParticles() override
{
mParticles.clear();
std::copy(mEvent.begin(), mEvent.end(), std::back_insert_iterator(mParticles));
for (auto& particle : mParticles) {
auto statusCode = particle.GetStatusCode();
if (!mcgenstatus::isEncoded(statusCode)) {
particle.SetStatusCode(mcgenstatus::MCGenStatusEncoding(statusCode, 0).fullEncoding);
}
// Set the transport bit according to the HepMC status code
particle.SetBit(ParticleStatus::kToBeDone, mcgenstatus::getHepMCStatusCode(particle.GetStatusCode()) == 1);
}
return true;
}
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override
{
using Key = o2::dataformats::MCInfoKeys;
if (eventHeader) {
eventHeader->putInfo<std::string>(Key::generator, "o2::eventgen::BoxGenerator");
}
}
private:
double mPtMin{0.}, mPtMax{0.}; // Transverse momentum range [GeV]
double mPhiMin{0.}, mPhiMax{360.}; // Azimuth angle range [degree]
double mEtaMin{0.}, mEtaMax{0.}; // Pseudorapidity range in lab system
double mYMin{0.}, mYMax{0.}; // Rapidity range in lab system
double mPMin{0.}, mPMax{0.}; // Momentum range in lab system
double mThetaMin{0.}, mThetaMax{0.}; // Polar angle range in lab system [degree]
double mEkinMin{0.}, mEkinMax{0.}; // Kinetic Energy range in lab system [GeV]
int mPDG{0};
int mMult{1};
bool mEtaRangeIsSet{false}; // True if eta range is set
bool mYRangeIsSet{false}; // True if rapidity range is set
bool mThetaRangeIsSet{false}; // True if theta range is set
bool mCosThetaIsSet{false}; // True if uniform distribution in
// cos(theta) is set (default -> not set)
bool mPtRangeIsSet{false}; // True if transverse momentum range is set
bool mPRangeIsSet{false}; // True if abs.momentum range is set
bool mEkinRangeIsSet{false}; // True if kinetic energy range is set
std::vector<TParticle> mEvent; // internal event container
};
} // namespace o2::eventgen
#endif