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
38 BoxGenerator(int pdgid,
39 int mult,
40 double etamin,
41 double etamax,
42 double pmin,
43 double pmax,
44 double phimin,
45 double phimax) : mPDG{pdgid}, mMult{mult}
46 {
47 SetEtaRange(etamin, etamax);
48 SetPRange(pmin, pmax);
49 SetPhiRange(phimin, phimax);
50 }
51
52 BoxGenerator(BoxGenConfig const& config) : mPDG{config.pdg}, mMult{config.number}
53 {
54 SetEtaRange(config.eta[0], config.eta[1]);
55 SetPRange(config.prange[0], config.prange[1]);
56 SetPhiRange(config.phirange[0], config.phirange[1]);
57 }
58
59 void SetPRange(Double32_t pmin = 0, Double32_t pmax = 10)
60 {
61 mPMin = pmin;
62 mPMax = pmax;
63 mPRangeIsSet = true;
64 }
65
66 void SetPhiRange(double phimin = 0, double phimax = 360)
67 {
68 mPhiMin = phimin;
69 mPhiMax = phimax;
70 }
71
72 void SetEtaRange(double etamin = -5, double etamax = 5)
73 {
74 mEtaMin = etamin;
75 mEtaMax = etamax;
76 mEtaRangeIsSet = true;
77 }
78
80 TParticle sampleParticle() const;
81
83 bool generateEvent() override
84 {
85 mEvent.clear();
86 for (int i = 0; i < mMult; ++i) {
87 mEvent.push_back(sampleParticle());
88 }
89 return true;
90 }
91 bool importParticles() override
92 {
93 mParticles.clear();
94 std::copy(mEvent.begin(), mEvent.end(), std::back_insert_iterator(mParticles));
95 for (auto& particle : mParticles) {
96 auto statusCode = particle.GetStatusCode();
97 if (!mcgenstatus::isEncoded(statusCode)) {
98 particle.SetStatusCode(mcgenstatus::MCGenStatusEncoding(statusCode, 0).fullEncoding);
99 }
100 // Set the transport bit according to the HepMC status code
101 particle.SetBit(ParticleStatus::kToBeDone, mcgenstatus::getHepMCStatusCode(particle.GetStatusCode()) == 1);
102 }
103 return true;
104 }
105
107 {
109 if (eventHeader) {
110 eventHeader->putInfo<std::string>(Key::generator, "o2::eventgen::BoxGenerator");
111 }
112 }
113
114 private:
115 double mPtMin{0.}, mPtMax{0.}; // Transverse momentum range [GeV]
116 double mPhiMin{0.}, mPhiMax{360.}; // Azimuth angle range [degree]
117 double mEtaMin{0.}, mEtaMax{0.}; // Pseudorapidity range in lab system
118 double mYMin{0.}, mYMax{0.}; // Rapidity range in lab system
119 double mPMin{0.}, mPMax{0.}; // Momentum range in lab system
120 double mThetaMin{0.}, mThetaMax{0.}; // Polar angle range in lab system [degree]
121 double mEkinMin{0.}, mEkinMax{0.}; // Kinetic Energy range in lab system [GeV]
122
123 int mPDG{0};
124 int mMult{1};
125
126 bool mEtaRangeIsSet{false}; // True if eta range is set
127 bool mYRangeIsSet{false}; // True if rapidity range is set
128 bool mThetaRangeIsSet{false}; // True if theta range is set
129 bool mCosThetaIsSet{false}; // True if uniform distribution in
130 // cos(theta) is set (default -> not set)
131 bool mPtRangeIsSet{false}; // True if transverse momentum range is set
132 bool mPRangeIsSet{false}; // True if abs.momentum range is set
133 bool mEkinRangeIsSet{false}; // True if kinetic energy range is set
134
135 std::vector<TParticle> mEvent; // internal event container
136};
137
138} // namespace o2::eventgen
139
140#endif
o2::monitoring::tags::Key Key
int32_t i
@ kToBeDone
void putInfo(std::string const &key, T const &value)
void updateHeader(o2::dataformats::MCEventHeader *eventHeader) override
TParticle sampleParticle() const
generates a single particle conforming to particle gun parameters
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
BoxGenerator(int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax)
void SetPhiRange(double phimin=0, double phimax=360)
BoxGenerator(int pdgid, int mult=1)
BoxGenerator(BoxGenConfig const &config)
std::vector< TParticle > mParticles
Definition Generator.h:140
int getHepMCStatusCode(MCGenStatusEncoding enc)
bool isEncoded(MCGenStatusEncoding statusCode)