|
| 1 | +#include "Pythia8/Pythia.h" |
| 2 | +#include "FairGenerator.h" |
| 3 | +#include "FairPrimaryGenerator.h" |
| 4 | +#include "Generators/GeneratorPythia8.h" |
| 5 | +#include "TRandom3.h" |
| 6 | +#include "TParticlePDG.h" |
| 7 | +#include "TDatabasePDG.h" |
| 8 | +#include "TMath.h" |
| 9 | +#include <cmath> |
| 10 | + |
| 11 | +using namespace Pythia8; |
| 12 | + |
| 13 | +class GeneratorPythia8LongLivedGun : public o2::eventgen::GeneratorPythia8 |
| 14 | +{ |
| 15 | +public: |
| 16 | + /// constructor |
| 17 | + GeneratorPythia8LongLivedGun(int input_pdg, int nInject = 1) : pdg{input_pdg}, nParticles{nInject}, m{getMass(input_pdg)} |
| 18 | + { |
| 19 | + } |
| 20 | + |
| 21 | + /// Destructor |
| 22 | + ~GeneratorPythia8LongLivedGun() = default; |
| 23 | + |
| 24 | + /// randomize the PDG code sign of core particle |
| 25 | + void setRandomizePDGsign(bool val) { randomizePDGsign = val; } |
| 26 | + |
| 27 | + /// get mass from TParticlePDG |
| 28 | + double getMass(int input_pdg) |
| 29 | + { |
| 30 | + double mass = 0; |
| 31 | + if (TDatabasePDG::Instance()) |
| 32 | + { |
| 33 | + TParticlePDG *particle = TDatabasePDG::Instance()->GetParticle(input_pdg); |
| 34 | + if (particle) |
| 35 | + { |
| 36 | + mass = particle->Mass(); |
| 37 | + } |
| 38 | + else |
| 39 | + { |
| 40 | + std::cout << "===> Unknown particle requested, mass set to 0" << std::endl; |
| 41 | + } |
| 42 | + } |
| 43 | + return mass; |
| 44 | + } |
| 45 | + |
| 46 | + //__________________________________________________________________ |
| 47 | + Bool_t importParticles() override |
| 48 | + { |
| 49 | + GeneratorPythia8::importParticles(); |
| 50 | + static int sign{1}; |
| 51 | + for (int i{0}; i < nParticles; ++i) |
| 52 | + { |
| 53 | + const double pt = gRandom->Uniform(genMinPt, genMaxPt); |
| 54 | + const double eta = gRandom->Uniform(genMinEta, genMaxEta); |
| 55 | + const double phi = gRandom->Uniform(0, TMath::TwoPi()); |
| 56 | + const double px{pt * std::cos(phi)}; |
| 57 | + const double py{pt * std::sin(phi)}; |
| 58 | + const double pz{pt * std::sinh(eta)}; |
| 59 | + const double et{std::hypot(std::hypot(pt, pz), m)}; |
| 60 | + sign *= randomizePDGsign ? -1 : 1; |
| 61 | + mParticles.push_back(TParticle(sign * pdg, 1, -1, -1, -1, -1, px, py, pz, et, 0., 0., 0., 0.)); |
| 62 | + } |
| 63 | + return true; |
| 64 | + } |
| 65 | + |
| 66 | +private: |
| 67 | + double genMinPt = 0.5; /// minimum 3-momentum for generated particles |
| 68 | + double genMaxPt = 12.; /// maximum 3-momentum for generated particles |
| 69 | + double genMinEta = -1.; /// minimum pseudorapidity for generated particles |
| 70 | + double genMaxEta = -1.; /// maximum pseudorapidity for generated particles |
| 71 | + |
| 72 | + double m = 0; /// particle mass [GeV/c^2] |
| 73 | + int pdg = 0; /// particle pdg code |
| 74 | + int nParticles = 1; /// Number of injected particles |
| 75 | + |
| 76 | + bool randomizePDGsign = true; /// bool to randomize the PDG code of the core particle |
| 77 | +}; |
| 78 | + |
| 79 | +///___________________________________________________________ |
| 80 | +FairGenerator *generateLongLived(int pdg, int nInject) |
| 81 | +{ |
| 82 | + return new GeneratorPythia8LongLivedGun(pdg, nInject); |
| 83 | +} |
0 commit comments