Project
Loading...
Searching...
No Matches
BoxGenerator.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_BOX
15#define ALICEO2_EVENTGEN_BOX
16
18#include "TParticle.h"
19#include <vector>
24
25namespace o2::eventgen
26{
27
28/*
29 * A simple mono-pdg "BoxGenerator". Or particle gun.
30 * Re-implements FairBoxGenerator for more convenient O2-processing.
31 */
32class BoxGenerator : public Generator
33{
34 public:
35 BoxGenerator() = default;
36 BoxGenerator(int pdgid, int mult = 1);
37
39 BoxGenerator(int pdgid,
40 int mult,
41 double etamin,
42 double etamax,
43 double pmin,
44 double pmax,
45 double phimin,
46 double phimax,
47 bool sampleYAndPt = false) : mPDG{pdgid}, mMult{mult}
48 {
49 if (sampleYAndPt) {
50 SetYRange(etamin, etamax);
51 SetPtRange(pmin, pmax);
52 } else {
53 SetEtaRange(etamin, etamax);
54 SetPRange(pmin, pmax);
55 }
56 SetPhiRange(phimin, phimax);
57 }
58
60 : BoxGenerator(config.pdg, config.number, config.eta[0], config.eta[1],
61 config.prange[0], config.prange[1], config.phirange[0], config.phirange[1], config.sampleYAndPt)
62 {
63 }
64
65 void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10)
66 {
67 mPMin = pmin;
68 mPMax = pmax;
69 mPRangeIsSet = true;
70 mPtRangeIsSet = false;
71 }
72
73 void SetPtRange(Double32_t ptmin = 0, Double32_t ptmax = 10)
74 {
75 mPtMin = ptmin;
76 mPtMax = ptmax;
77 mPtRangeIsSet = true;
78 mPRangeIsSet = false;
79 }
80
81 void SetPhiRange(double phimin = 0, double phimax = 360)
82 {
83 mPhiMin = phimin;
84 mPhiMax = phimax;
85 }
86
87 void SetEtaRange(double etamin = -5, double etamax = 5)
88 {
89 mEtaMin = etamin;
90 mEtaMax = etamax;
91 mEtaRangeIsSet = true;
92 mYRangeIsSet = false;
93 }
94
96 void SetYRange(double ymin = -5, double ymax = 5)
97 {
98 mYMin = ymin;
99 mYMax = ymax;
100 mYRangeIsSet = true;
101 mEtaRangeIsSet = false;
102 }
103
105 TParticle sampleParticle() const;
106
108 bool generateEvent() override
109 {
110 mEvent.clear();
111 for (int i = 0; i < mMult; ++i) {
112 mEvent.push_back(sampleParticle());
113 }
114 return true;
115 }
116 bool importParticles() override
117 {
118 mParticles.clear();
119 std::copy(mEvent.begin(), mEvent.end(), std::back_insert_iterator(mParticles));
120 for (auto& particle : mParticles) {
121 auto statusCode = particle.GetStatusCode();
122 if (!mcgenstatus::isEncoded(statusCode)) {
123 particle.SetStatusCode(mcgenstatus::MCGenStatusEncoding(statusCode, 0).fullEncoding);
124 }
125 // Set the transport bit according to the HepMC status code
126 particle.SetBit(ParticleStatus::kToBeDone, mcgenstatus::getHepMCStatusCode(particle.GetStatusCode()) == 1);
127 }
128 return true;
129 }
130
132 {
134 if (eventHeader) {
135 eventHeader->putInfo<std::string>(Key::generator, "o2::eventgen::BoxGenerator");
136 }
137 }
138
139 private:
140 double mPtMin{0.}, mPtMax{0.}; // Transverse momentum range [GeV]
141 double mPhiMin{0.}, mPhiMax{360.}; // Azimuth angle range [degree]
142 double mEtaMin{0.}, mEtaMax{0.}; // Pseudorapidity range in lab system
143 double mYMin{0.}, mYMax{0.}; // Rapidity range in lab system
144 double mPMin{0.}, mPMax{0.}; // Momentum range in lab system
145 double mThetaMin{0.}, mThetaMax{0.}; // Polar angle range in lab system [degree]
146 double mEkinMin{0.}, mEkinMax{0.}; // Kinetic Energy range in lab system [GeV]
147
148 int mPDG{0};
149 int mMult{1};
150
151 bool mEtaRangeIsSet{false}; // True if eta range is set
152 bool mYRangeIsSet{false}; // True if rapidity range is set
153 bool mThetaRangeIsSet{false}; // True if theta range is set
154 bool mCosThetaIsSet{false}; // True if uniform distribution in
155 // cos(theta) is set (default -> not set)
156 bool mPtRangeIsSet{false}; // True if transverse momentum range is set
157 bool mPRangeIsSet{false}; // True if abs.momentum range is set
158 bool mEkinRangeIsSet{false}; // True if kinetic energy range is set
159
160 std::vector<TParticle> mEvent; // internal event container
161};
162
163} // namespace o2::eventgen
164
165#endif
o2::monitoring::tags::Key Key
int32_t i
@ kToBeDone
void putInfo(std::string const &key, T const &value)
BoxGenerator(int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool sampleYAndPt=false)
With sampleYAndPt, eta bounds specify rapidity and p bounds specify pT.
void updateHeader(o2::dataformats::MCEventHeader *eventHeader) override
TParticle sampleParticle() const
generates a single particle conforming to particle gun parameters
void SetPtRange(Double32_t ptmin=0, Double32_t ptmax=10)
void SetEtaRange(double etamin=-5, double etamax=5)
bool generateEvent() override
implements the main O2 generator interfaces
void SetPRange(Double32_t pmin=0, Double32_t pmax=10)
bool importParticles() override
void SetPhiRange(double phimin=0, double phimax=360)
void SetYRange(double ymin=-5, double ymax=5)
Sample rapidity uniformly; requires a transverse momentum range.
BoxGenerator(int pdgid, int mult=1)
BoxGenerator(BoxGenConfig const &config)
std::vector< TParticle > mParticles
Definition Generator.h:151
int getHepMCStatusCode(MCGenStatusEncoding enc)
bool isEncoded(MCGenStatusEncoding statusCode)