|
1 | | -#include <TParticle.h> |
2 | | -#include "Generators/Trigger.h" |
3 | | -#include <vector> |
4 | | -#include <TMath.h> |
5 | | - |
6 | | -///============================================================================ |
7 | | - |
8 | 1 | /// Select π⁰ and η within a given rapidity window for enhancement |
9 | 2 | /// pdgPartForAccCut: PDG of the particle to select (111=π⁰, 221=η) |
10 | 3 | /// minNb: minimum number of such particles per event for enhancement |
11 | 4 |
|
12 | 5 | //// authors: Rashi Gupta (rashi.gupta@cern.ch) |
13 | 6 | /// authors: Ravindra Singh (ravindra.singh@cern.ch) |
14 | | -/// ============================================================================ |
15 | | -o2::eventgen::Trigger selectPionEtaWithinAcc(TString pdgPartForAccCut = "111;221", double rapidityMin = -1.5, double rapidityMax = 1.5, int minNb = 1) |
| 7 | + |
| 8 | + |
| 9 | +#if !defined(__CLING__) || defined(__ROOTCLING__) |
| 10 | +#include "FairGenerator.h" |
| 11 | +#include "FairPrimaryGenerator.h" |
| 12 | +#include "Generators/GeneratorPythia8.h" |
| 13 | +#include "TRandom3.h" |
| 14 | +#include "TParticlePDG.h" |
| 15 | +#include "TDatabasePDG.h" |
| 16 | +#include "TMath.h" |
| 17 | +#include <cmath> |
| 18 | +#include <vector> |
| 19 | +#endif |
| 20 | + |
| 21 | +#include "Pythia8/Pythia.h" |
| 22 | +using namespace Pythia8; |
| 23 | + |
| 24 | +class GeneratorPythia8Box : public o2::eventgen::GeneratorPythia8 |
| 25 | +{ |
| 26 | +public: |
| 27 | + |
| 28 | + GeneratorPythia8Box(std::vector<int> pdgList, int nInject = 3, float ptMin = 0.1, float ptMax = 50.0, float etaMin = -0.8, float etaMax = 0.8) |
| 29 | + : mPdgList(pdgList), nParticles(nInject), genMinPt(ptMin), genMaxPt(ptMax), genMinEta(etaMin), genMaxEta(etaMax) |
| 30 | + { |
| 31 | + } |
| 32 | + |
| 33 | + ~GeneratorPythia8Box() = default; |
| 34 | + |
| 35 | +Bool_t generateEvent() override |
16 | 36 | { |
17 | | - return [pdgPartForAccCut, rapidityMin, rapidityMax, minNb](const std::vector<TParticle>& particles) -> bool { |
18 | | - TObjArray* obj = pdgPartForAccCut.Tokenize(";"); |
19 | | - int count = 0; |
20 | | - for (const auto& particle : particles) { |
21 | | - int pdg = TMath::Abs(particle.GetPdgCode()); |
22 | | - double y = particle.Y(); |
| 37 | + bool hasElectron = false; |
| 38 | + |
| 39 | + while (!hasElectron) { |
| 40 | + mPythia.event.reset(); |
23 | 41 |
|
24 | | - if (y < rapidityMin || y > rapidityMax) continue; |
| 42 | + for (int i{0}; i < nParticles; ++i) |
| 43 | + { |
| 44 | + int currentPdg = mPdgList[gRandom->Integer(mPdgList.size())]; |
| 45 | + double mass = TDatabasePDG::Instance()->GetParticle(currentPdg)->Mass(); |
25 | 46 |
|
26 | | - for (int i = 0; i < obj->GetEntriesFast(); ++i) { |
27 | | - int pdgCode = std::stoi(obj->At(i)->GetName()); |
| 47 | + const double pt = gRandom->Uniform(genMinPt, genMaxPt); |
| 48 | + const double eta = gRandom->Uniform(genMinEta, genMaxEta); |
| 49 | + const double phi = gRandom->Uniform(0, TMath::TwoPi()); |
28 | 50 |
|
29 | | - if (pdg == pdgCode) { |
30 | | - count++; |
31 | | - break; |
| 51 | + const double px{pt * std::cos(phi)}; |
| 52 | + const double py{pt * std::sin(phi)}; |
| 53 | + const double pz{pt * std::sinh(eta)}; |
| 54 | + const double et{std::hypot(std::hypot(pt, pz), mass)}; |
| 55 | + |
| 56 | + |
| 57 | + mPythia.event.append(currentPdg, 11, 0, 0, px, py, pz, et, mass); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + if (!mPythia.next()) continue; |
| 62 | + |
| 63 | + |
| 64 | + for (int i = 0; i < mPythia.event.size(); ++i) { |
| 65 | + if (std::abs(mPythia.event[i].id()) == 11) { |
| 66 | + |
| 67 | + |
| 68 | + double childPt = mPythia.event[i].pT(); |
| 69 | + double childEta = mPythia.event[i].eta(); |
| 70 | + |
| 71 | + if (childPt > 0.1 && std::abs(childEta) < 1.2) { |
| 72 | + hasElectron = true; // Mil gaya! |
| 73 | + break; |
32 | 74 | } |
33 | 75 | } |
34 | 76 | } |
35 | | - // Only accept events with at least minNb π⁰/η |
36 | | - if (count >= minNb) |
37 | | - return kTRUE; |
38 | | - else |
39 | | - return kFALSE; |
40 | | - }; |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + return true; |
| 81 | +} |
| 82 | + |
| 83 | +private: |
| 84 | + std::vector<int> mPdgList; |
| 85 | + double genMinPt, genMaxPt; |
| 86 | + double genMinEta, genMaxEta; |
| 87 | + int nParticles; |
| 88 | +}; |
| 89 | + |
| 90 | + |
| 91 | +FairGenerator *generatePythia8Box(float ptMin = 0.1, float ptMax = 50.0) |
| 92 | +{ |
| 93 | + |
| 94 | + std::vector<int> pdgList = {111, 221}; |
| 95 | + return new GeneratorPythia8Box(pdgList, 3, ptMin, ptMax, -0.8, 0.8); |
41 | 96 | } |
0 commit comments