Project
Loading...
Searching...
No Matches
BoxGenerator.cxx
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
15#include "TRandom.h"
16#include "TDatabasePDG.h"
17#include <stdexcept>
18
19using namespace o2::eventgen;
20
21double GetPDGMass(int pdg)
22{
23 static TDatabasePDG* pid = TDatabasePDG::Instance();
24 TParticlePDG* p = pid->GetParticle(pdg);
25 if (p != nullptr) {
26 // LOG(info) << this->ClassName() << ": particle with PDG =" << GetPDGType() << " Found";
27 return p->Mass(); // fPDGMass = p->Mass();
28 }
29 // LOG(warn) << "pdg not known";
30 return 0.;
31}
32
34{
35 // Primary particles are distributed uniformly along
36 // those kinematics variables which were limitted by setters.
37 // if SetCosTheta() function is used, the distribution will be uniform in
38 // cos(theta)
39
40 if (mYRangeIsSet && !mPtRangeIsSet) {
41 throw std::invalid_argument("BoxGenerator: rapidity sampling requires SetPtRange() or sampleYAndPt=true in the configuration");
42 }
43
44 // per instance, since several box generators with different PDG codes can coexist
45 const double mass = GetPDGMass(mPDG);
46
47 double pabs = 0, phi, pt = 0, theta = 0, eta, y, mt, px, py, pz = 0;
48 phi = gRandom->Uniform(mPhiMin, mPhiMax) * TMath::DegToRad();
49 if (mPRangeIsSet) {
50 pabs = gRandom->Uniform(mPMin, mPMax);
51 } else if (mPtRangeIsSet) {
52 pt = gRandom->Uniform(mPtMin, mPtMax);
53 }
54 if (mThetaRangeIsSet) {
55 if (mCosThetaIsSet) {
56 theta = acos(gRandom->Uniform(cos(mThetaMin * TMath::DegToRad()), cos(mThetaMax * TMath::DegToRad())));
57 } else {
58 theta = gRandom->Uniform(mThetaMin, mThetaMax) * TMath::DegToRad();
59 }
60 } else if (mEtaRangeIsSet) {
61 eta = gRandom->Uniform(mEtaMin, mEtaMax);
62 theta = 2 * TMath::ATan(TMath::Exp(-eta));
63 } else if (mYRangeIsSet) {
64 y = gRandom->Uniform(mYMin, mYMax);
65 mt = TMath::Sqrt(mass * mass + pt * pt);
66 pz = mt * TMath::SinH(y);
67 }
68
69 if (mThetaRangeIsSet || mEtaRangeIsSet) {
70 if (mPRangeIsSet) {
71 pz = pabs * TMath::Cos(theta);
72 pt = pabs * TMath::Sin(theta);
73 } else if (mPtRangeIsSet) {
74 pz = pt / TMath::Tan(theta);
75 }
76 }
77 px = pt * TMath::Cos(phi);
78 py = pt * TMath::Sin(phi);
79
80 double vx = 0., vy = 0., vz = 0.;
81 double etot = TMath::Sqrt(px * px + py * py + pz * pz + mass * mass);
82 return TParticle(mPDG, 1 /*status*/, -1 /* mother1 */, -1 /* mother2 */,
83 -1 /* daughter1 */, -1 /* daughter2 */, px, py, pz, etot, vx, vy, vz, 0. /*time*/);
84}
double GetPDGMass(int pdg)
uint16_t pid
Definition RawData.h:2
TParticle sampleParticle() const
generates a single particle conforming to particle gun parameters
GLint y
Definition glcorearb.h:270