diff --git a/MC/config/PWGDQ/external/generator/GeneratorParamMuon.C b/MC/config/PWGDQ/external/generator/GeneratorParamMuon.C deleted file mode 100644 index 8e9176070..000000000 --- a/MC/config/PWGDQ/external/generator/GeneratorParamMuon.C +++ /dev/null @@ -1,142 +0,0 @@ -// Parameterized generator for muons -// Port of the Run 2 generator by P. Pillot: -// https://github.com/alisw/AliDPG/blob/master/MC/CustomGenerators/PWGDQ/Muon_GenParamSingle_PbPb5TeV_1.C - -// clang-format off -R__ADD_INCLUDE_PATH($O2DPG_MC_CONFIG_ROOT/MC/config/PWGDQ/EvtGen) -// clang-format on -R__LOAD_LIBRARY(libpythia6) - -#include "GeneratorEvtGen.C" - -namespace o2 -{ -namespace eventgen -{ - -class O2_GeneratorParamMuon : public GeneratorTGenerator -{ - public: - // parameters tuned to Pb-Pb @ 5.02 TeV - inline static Double_t fPtP0{797.446}; - inline static Double_t fPtP1{0.830278}; - inline static Double_t fPtP2{0.632177}; - inline static Double_t fPtP3{10.2202}; - inline static Double_t fPtP4{-0.000614809}; - inline static Double_t fPtP5{-1.70993}; - - inline static Double_t fYP0{1.87732}; - inline static Double_t fYP1{0.00658212}; - inline static Double_t fYP2{-0.0988071}; - inline static Double_t fYP3{-0.000452746}; - inline static Double_t fYP4{0.00269782}; - - O2_GeneratorParamMuon() : GeneratorTGenerator("ParamMuon") - { - fParamMuon = new GeneratorParam(2, -1, PtMuon, YMuon, V2Muon, IpMuon); - fParamMuon->SetPtRange(0.1, 999.); - fParamMuon->SetYRange(-4.3, -2.3); - fParamMuon->SetPhiRange(0., 360.); - fParamMuon->SetDecayer(new TPythia6Decayer()); // "no decayer" error otherwise - fParamMuon->SetForceDecay(kNoDecay); - setTGenerator(fParamMuon); - } - - ~O2_GeneratorParamMuon() { delete fParamMuon; }; - - Bool_t Init() override - { - GeneratorTGenerator::Init(); - fParamMuon->Init(); - return true; - } - - // for tuning steps - static void SetPtPars(Double_t p0, Double_t p1, Double_t p2, Double_t p3, - Double_t p4, Double_t p5) - { - fPtP0 = p0; - fPtP1 = p1; - fPtP2 = p2; - fPtP3 = p3; - fPtP4 = p4; - fPtP5 = p5; - } - - // for tuning steps - static void SetYPars(Double_t p0, Double_t p1, Double_t p2, Double_t p3, - Double_t p4) - { - fYP0 = p0; - fYP1 = p1; - fYP2 = p2; - fYP3 = p3; - fYP4 = p4; - } - - void SetNSignalPerEvent(Int_t nsig) { fParamMuon->SetNumberParticles(nsig); } - - // muon composition - static Int_t IpMuon(TRandom* ran) - { - if (ran->Rndm() < 0.5) { - return 13; - } else { - return -13; - } - } - - // muon pT - static Double_t PtMuon(const Double_t* px, const Double_t*) - { - Double_t x = px[0]; - return fPtP0 * (1. / TMath::Power(fPtP1 + TMath::Power(x, fPtP2), fPtP3) + - fPtP4 * TMath::Exp(fPtP5 * x)); - } - - // muon y - static Double_t YMuon(const Double_t* py, const Double_t*) - { - Double_t y = py[0]; - return fYP0 * (1. + fYP1 * y + fYP2 * y * y + fYP3 * y * y * y + - fYP4 * y * y * y * y); - } - - static Double_t V2Muon(const Double_t*, const Double_t*) - { - // muon v2 - return 0.; - } - - private: - GeneratorParam* fParamMuon{nullptr}; -}; - -} // namespace eventgen -} // namespace o2 - -FairGenerator* paramMuGen(Double_t ptP0 = 797.446, Double_t ptP1 = 0.830278, - Double_t ptP2 = 0.632177, Double_t ptP3 = 10.2202, - Double_t ptP4 = -0.000614809, Double_t ptP5 = -1.70993, - Double_t yP0 = 1.87732, Double_t yP1 = 0.00658212, - Double_t yP2 = -0.0988071, Double_t yP3 = -0.000452746, - Double_t yP4 = 0.00269782, Int_t nMuons = 2) -{ - auto gen = new o2::eventgen::GeneratorEvtGen(); - o2::eventgen::O2_GeneratorParamMuon::SetPtPars(ptP0, ptP1, ptP2, ptP3, ptP4, ptP5); - o2::eventgen::O2_GeneratorParamMuon::SetYPars(yP0, yP1, yP2, yP3, yP4); - gen->SetNSignalPerEvent(nMuons); // number of muons per event - - TString pdgs = "13"; - std::string spdg; - TObjArray* obj = pdgs.Tokenize(";"); - gen->SetSizePdg(obj->GetEntriesFast()); - for (int i = 0; i < obj->GetEntriesFast(); i++) { - spdg = obj->At(i)->GetName(); - gen->AddPdg(std::stoi(spdg), i); - printf("PDG %d \n", std::stoi(spdg)); - } - - gen->PrintDebug(); - return gen; -} \ No newline at end of file diff --git a/MC/config/PWGDQ/external/generator/GeneratorParamSingleMuon_PbPb_5TeV.C b/MC/config/PWGDQ/external/generator/GeneratorParamSingleMuon_PbPb_5TeV.C new file mode 100644 index 000000000..91f20acd4 --- /dev/null +++ b/MC/config/PWGDQ/external/generator/GeneratorParamSingleMuon_PbPb_5TeV.C @@ -0,0 +1,161 @@ +// Parameterized generator for muons +// Adaptation of the Run 2 generator by P. Pillot: +// https://github.com/alisw/AliDPG/blob/master/MC/CustomGenerators/PWGDQ/Muon_GenParamSingle_PbPb5TeV_1.C + +#include "FairGenerator.h" +#include "TF1.h" +#include "TRandom.h" +#include "TDatabasePDG.h" +#include "TParticlePDG.h" + +class O2_GeneratorParamMuon : public FairGenerator +{ + public: + O2_GeneratorParamMuon(int npart = 2, int pdg = 13, double ymin = -4.3, double ymax = -2.3, double ptmin = 0.1, double ptmax = 999.) + : FairGenerator("ParaMuon"), fNParticles(npart), fPDGCode(pdg), fYMin(ymin), fYMax(ymax), fPtMin(ptmin), fPtMax(ptmax) + { + TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPDGCode); + fMass = particle->Mass(); + fMass2 = fMass * fMass; + } + + ~O2_GeneratorParamMuon() = default; + + void SetRandomCharge(bool flag) { fRandomizeCharge = flag; } + + void SetPtPars(double p0, double p1, double p2, double p3, double p4, double p5) + { + fPtP0 = p0; + fPtP1 = p1; + fPtP2 = p2; + fPtP3 = p3; + fPtP4 = p4; + fPtP5 = p5; + } + + void SetYPars(double p0, double p1, double p2, double p3, double p4) + { + fYP0 = p0; + fYP1 = p1; + fYP2 = p2; + fYP3 = p3; + fYP4 = p4; + } + + void InitParaFuncs() + { + fPtPara = new TF1("pt-para", PtMuon, fPtMin, fPtMax, 6); + fPtPara->SetParameter(0, fPtP0); + fPtPara->SetParameter(1, fPtP1); + fPtPara->SetParameter(2, fPtP2); + fPtPara->SetParameter(3, fPtP3); + fPtPara->SetParameter(4, fPtP4); + fPtPara->SetParameter(5, fPtP5); + fYPara = new TF1("y-para", YMuon, fYMin, fYMax, 5); + fYPara->SetParameter(0, fYP0); + fYPara->SetParameter(1, fYP1); + fYPara->SetParameter(2, fYP2); + fYPara->SetParameter(3, fYP3); + fYPara->SetParameter(4, fYP4); + } + + static double PtMuon(const double* xx, const double* par) + { + double x = xx[0]; + double p0 = par[0]; + double p1 = par[1]; + double p2 = par[2]; + double p3 = par[3]; + double p4 = par[4]; + double p5 = par[5]; + return p0 * (1. / std::pow(p1 + std::pow(x, p2), p3) + p4 * std::exp(p5 * x)); + } + + static double YMuon(const double* xx, const double* par) + { + double x = xx[0]; + double p0 = par[0]; + double p1 = par[1]; + double p2 = par[2]; + double p3 = par[3]; + double p4 = par[4]; + double x2 = x * x; + return p0 * (1. + p1 * x + p2 * x2 + p3 * x2 * x + p4 * x2 * x2); + } + + bool ReadEvent(FairPrimaryGenerator* primGen) override + { + // no kinematic cuts -> accepting all + for (int i = 0; i < fNParticles; ++i) { + double pt = fPtPara->GetRandom(); + double ty = std::tanh(fYPara->GetRandom()); + double xmt = std::sqrt(pt * pt + fMass2); + double pl = xmt * ty / std::sqrt((1. - ty * ty)); + double phi = gRandom->Uniform(0., 2. * M_PI); + double px = pt * std::cos(phi); + double py = pt * std::sin(phi); + int pdg = fPDGCode; + if (fRandomizeCharge) { + int charge; + if (gRandom->Rndm() < 0.5) { + charge = 1; + } else { + charge = -1; + } + pdg = std::abs(pdg) * charge; + } + primGen->AddTrack(pdg, px, py, pl, 0, 0, 0); + printf("Add track %d %.2f %.2f %.2f \n", pdg, px, py, pl); + } + return kTRUE; + } + + private: + TF1* fPtPara{nullptr}; + TF1* fYPara{nullptr}; + TF1* fdNdPhi{nullptr}; + + // parameters tuned to Pb-Pb @ 5.02 TeV + double fPtP0{797.446}; + double fPtP1{0.830278}; + double fPtP2{0.632177}; + double fPtP3{10.2202}; + double fPtP4{-0.000614809}; + double fPtP5{-1.70993}; + + double fYP0{1.87732}; + double fYP1{0.00658212}; + double fYP2{-0.0988071}; + double fYP3{-0.000452746}; + double fYP4{0.00269782}; + + // configuration + int fPDGCode{13}; + int fNParticles{2}; + double fYMin{-4.3}; + double fYMax{-2.3}; + double fPtMin{0.1}; + double fPtMax{999.}; + bool fRandomizeCharge{true}; + double fMass{0.10566}; + double fMass2{0}; +}; + +FairGenerator* paramMuGen(double ptP0 = 797.446, double ptP1 = 0.830278, + double ptP2 = 0.632177, double ptP3 = 10.2202, + double ptP4 = -0.000614809, double ptP5 = -1.70993, + double yP0 = 1.87732, double yP1 = 0.00658212, + double yP2 = -0.0988071, double yP3 = -0.000452746, + double yP4 = 0.00269782, + int nPart = 2, int pdg = 13, + double ymin = -4.3, double ymax = -2.3, + double ptmin = 0.1, float ptmax = 999., + int randCharge = 1) +{ + auto* gen = new O2_GeneratorParamMuon(nPart, pdg, ymin, ymax, ptmin, ptmax); + gen->SetPtPars(ptP0, ptP1, ptP2, ptP3, ptP4, ptP5); + gen->SetYPars(yP0, yP1, yP2, yP3, yP4); + gen->InitParaFuncs(); + gen->SetRandomCharge(randCharge); + return gen; +} \ No newline at end of file