From fe6c5a3b4589cdbda9ef6cd64e9b17bcbf6f0699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 27 Sep 2023 15:35:38 +0200 Subject: [PATCH 1/7] Streamline LF injector/GT, add eta window trigger --- .../pythia8/generator/strangeparticlelist.gun | 10 +- .../PWGLF/pythia8/generator_pythia8_LF.C | 113 ++++++++++-------- 2 files changed, 70 insertions(+), 53 deletions(-) diff --git a/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun b/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun index f1e5a65d1..cf8fbc9d3 100644 --- a/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun +++ b/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun @@ -1,5 +1,5 @@ -# PDG N ptMin ptMax genDecayed -3334 1 0.2 10 --3334 1 0.2 10 -3312 1 0.2 10 --3312 1 0.2 10 \ No newline at end of file +# PDG N ptMin ptMax etaMin etaMax genDecayed +3334 1 0.2 10 -1.2 1.2 +-3334 1 0.2 10 -1.2 1.2 +3312 1 0.2 10 -1.2 1.2 +-3312 1 0.2 10 -1.2 1.2 \ No newline at end of file diff --git a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C index 4428c94de..2acf7b58a 100644 --- a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +++ b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C @@ -183,7 +183,7 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 const int& pypid = pythiaObjectSignal.event[j].id(); const float& pyeta = pythiaObjectSignal.event[j].eta(); const float& pypt = pythiaObjectSignal.event[j].pT(); - if (pypid == cfg.pdg && cfg.etaMin < pyeta && pyeta < cfg.etaMax && pypt > cfg.ptMin && pypt < cfg.ptMax) { + if (pypid == cfg.mPdg && cfg.mEtaMin < pyeta && pyeta < cfg.mEtaMax && pypt > cfg.mPtMin && pypt < cfg.mPtMax) { LOG(info) << "Found particle " << j << " " << pypid << " with eta " << pyeta << " and pT " << pypt << " in event " << mEventCounter << " after " << nTries << " tries"; satisfiesTrigger = true; break; @@ -204,19 +204,19 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 continue; } // Do the injection - for (int i{0}; i < cfg.nInject; ++i) { - const double pt = gRandom->Uniform(cfg.ptMin, cfg.ptMax); - const double eta = gRandom->Uniform(cfg.etaMin, cfg.etaMax); + for (int i{0}; i < cfg.mNInject; ++i) { + const double pt = gRandom->Uniform(cfg.mPtMin, cfg.mPtMax); + const double eta = gRandom->Uniform(cfg.mEtaMin, cfg.mEtaMax); const double phi = gRandom->Uniform(0, TMath::TwoPi()); const double px{pt * std::cos(phi)}; const double py{pt * std::sin(phi)}; const double pz{pt * std::sinh(eta)}; - const double et{std::hypot(std::hypot(pt, pz), cfg.mass)}; + const double et{std::hypot(std::hypot(pt, pz), cfg.mMass)}; Particle particle; - particle.id(cfg.pdg); + particle.id(cfg.mPdg); particle.status(11); - particle.m(cfg.mass); + particle.m(cfg.mMass); particle.px(px); particle.py(py); particle.pz(pz); @@ -224,7 +224,7 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 particle.xProd(0.f); particle.yProd(0.f); particle.zProd(0.f); - mPythia.particleData.mayDecay(cfg.pdg, true); // force decay + mPythia.particleData.mayDecay(cfg.mPdg, true); // force decay mPythia.event.append(particle); } injectedForThisEvent = true; @@ -270,16 +270,16 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 if (mConfigToUse >= 0 && (nConfig - 1) != mConfigToUse) { continue; } - LOGF(info, "Injecting %i particles with PDG %i, pT in [%f, %f]", cfg.nInject, cfg.pdg, cfg.ptMin, cfg.ptMax); + LOGF(info, "Injecting %i particles with PDG %i, pT in [%f, %f]", cfg.mNInject, cfg.mPdg, cfg.mPtMin, cfg.mPtMax); - for (int i{0}; i < cfg.nInject; ++i) { - const double pt = gRandom->Uniform(cfg.ptMin, cfg.ptMax); - const double eta = gRandom->Uniform(cfg.etaMin, cfg.etaMax); + for (int i{0}; i < cfg.mNInject; ++i) { + const double pt = gRandom->Uniform(cfg.mPtMin, cfg.mPtMax); + const double eta = gRandom->Uniform(cfg.mEtaMin, cfg.mEtaMax); const double phi = gRandom->Uniform(0, TMath::TwoPi()); const double px{pt * std::cos(phi)}; const double py{pt * std::sin(phi)}; const double pz{pt * std::sinh(eta)}; - const double et{std::hypot(std::hypot(pt, pz), cfg.mass)}; + const double et{std::hypot(std::hypot(pt, pz), cfg.mMass)}; // TParticle::TParticle(Int_t pdg, // Int_t status, @@ -288,7 +288,7 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 // Double_t px, Double_t py, Double_t pz, Double_t etot, // Double_t vx, Double_t vy, Double_t vz, Double_t time) - mParticles.push_back(TParticle(cfg.pdg, + mParticles.push_back(TParticle(cfg.mPdg, MCGenStatusEncoding(1, 1).fullEncoding, -1, -1, -1, -1, @@ -311,65 +311,82 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 } struct ConfigContainer { - ConfigContainer(int input_pdg = 0, int n = 1, float p = 1, float P = 10) : pdg{input_pdg}, - nInject{n}, - ptMin{p}, - ptMax{P} + ConfigContainer(int input_pdg = 0, int n = 1, + float ptMin = 1, float ptMax = 10, + float etaMin = -1, float etaMax = 1) : mPdg{input_pdg}, + mNInject{n}, + mPtMin{ptMin}, + mPtMax{ptMax}, + mEtaMin{etaMin}, + mEtaMax{etaMax} { - mass = GeneratorPythia8LongLivedGun::getMass(pdg); - if (mass <= 0) { - LOG(fatal) << "Could not find mass for pdg " << pdg; + mMass = GeneratorPythia8LongLivedGun::getMass(mPdg); + if (mMass <= 0) { + LOG(fatal) << "Could not find mass for mPdg " << mPdg; } - LOGF(info, "ConfigContainer: pdg = %i, nInject = %i, ptMin = %f, ptMax = %f, mass = %f", pdg, nInject, ptMin, ptMax, mass); + LOGF(info, "ConfigContainer: mPdg = %i, mNInject = %i, mPtMin = %f, mPtMax = %f, mEtaMin = %f, mEtaMax = %f, mMass = %f", + mPdg, mNInject, mPtMin, mPtMax, mEtaMin, mEtaMax, mMass); }; - ConfigContainer(TObjArray* arr) : ConfigContainer(atoi(arr->At(0)->GetName()), - atoi(arr->At(1)->GetName()), - atof(arr->At(2)->GetName()), - atof(arr->At(3)->GetName())){}; - - int pdg = 0; - int nInject = 1; - float ptMin = 1; - float ptMax = 10; - float etaMin = -1.f; - float etaMax = 1.f; - double mass = 0.f; + + // ConfigContainer(const ConfigContainer cfg) : ConfigContainer(cfg.mPdg, + // cfg.mNInject, + // cfg.mPtMin, + // cfg.mPtMax, + // cfg.mEtaMin, + // cfg.mEtaMax){}; + // ConfigContainer(TObjArray* arr) : ConfigContainer(atoi(arr->At(0)->GetName()), + // atoi(arr->At(1)->GetName()), + // atof(arr->At(2)->GetName()), + // atof(arr->At(3)->GetName()), + // atof(arr->At(4)->GetName()), + // atof(arr->At(5)->GetName())){}; + // ConfigContainer(TString line) : ConfigContainer(line.Tokenize(" ")){}; + + // Data Members + int mPdg = 0; + int mNInject = 1; + float mPtMin = 1; + float mPtMax = 10; + float mEtaMin = -1.f; + float mEtaMax = 1.f; + double mMass = 0.f; + void print() const { - LOGF(info, "int pdg = %i", pdg); - LOGF(info, "int nInject = %i", nInject); - LOGF(info, "float ptMin = %f", ptMin); - LOGF(info, "float ptMax = %f", ptMax); - LOGF(info, "float etaMin = %f", etaMin); - LOGF(info, "float etaMax = %f", etaMax); - LOGF(info, "double mass = %f", mass); + LOGF(info, "int mPdg = %i", mPdg); + LOGF(info, "int mNInject = %i", mNInject); + LOGF(info, "float mPtMin = %f", mPtMin); + LOGF(info, "float mPtMax = %f", mPtMax); + LOGF(info, "float mEtaMin = %f", mEtaMin); + LOGF(info, "float mEtaMax = %f", mEtaMax); + LOGF(info, "double mMass = %f", mMass); } }; //__________________________________________________________________ - ConfigContainer addGun(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10) + ConfigContainer addGun(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10, float etaMin = 1, float etaMax = 10) { if (mUseTriggering) { // If in trigger mode, every particle needs to be generated from pythia - return addGunGenDecayed(input_pdg, nInject, ptMin, ptMax); + return addGunGenDecayed(input_pdg, nInject, ptMin, ptMax, etaMin, etaMax); } - ConfigContainer cfg{input_pdg, nInject, ptMin, ptMax}; + ConfigContainer cfg{input_pdg, nInject, ptMin, ptMax, etaMin, etaMax}; mGunConfigs.push_back(cfg); return cfg; } //__________________________________________________________________ - ConfigContainer addGun(ConfigContainer cfg) { return addGun(cfg.pdg, cfg.nInject, cfg.ptMin, cfg.ptMax); } + ConfigContainer addGun(ConfigContainer cfg) { return addGun(cfg.mPdg, cfg.mNInject, cfg.mPtMin, cfg.mPtMax, cfg.mEtaMin, cfg.mEtaMax); } //__________________________________________________________________ - ConfigContainer addGunGenDecayed(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10) + ConfigContainer addGunGenDecayed(int input_pdg, int nInject = 1, float ptMin = 1, float ptMax = 10, float etaMin = 1, float etaMax = 10) { - ConfigContainer cfg{input_pdg, nInject, ptMin, ptMax}; + ConfigContainer cfg{input_pdg, nInject, ptMin, ptMax, etaMin, etaMax}; mGunConfigsGenDecayed.push_back(cfg); return cfg; } //__________________________________________________________________ - ConfigContainer addGunGenDecayed(ConfigContainer cfg) { return addGunGenDecayed(cfg.pdg, cfg.nInject, cfg.ptMin, cfg.ptMax); } + ConfigContainer addGunGenDecayed(ConfigContainer cfg) { return addGunGenDecayed(cfg.mPdg, cfg.mNInject, cfg.mPtMin, cfg.mPtMax, cfg.mEtaMin, cfg.mEtaMax); } //__________________________________________________________________ long int getNGuns() const { return mGunConfigs.size() + mGunConfigsGenDecayed.size(); } From 5bcdbe7400b8f1457d46b8973cafdf50f389f498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Thu, 28 Sep 2023 15:14:33 +0200 Subject: [PATCH 2/7] Add 900 GeV triggered for strangeness studies --- ...GeneratorLFStrangenessTriggered_900gev.ini | 10 +++++ .../run_StrangenessTriggered_pp900gev.sh | 44 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 MC/config/PWGLF/ini/GeneratorLFStrangenessTriggered_900gev.ini create mode 100755 MC/run/PWGLF/run_StrangenessTriggered_pp900gev.sh diff --git a/MC/config/PWGLF/ini/GeneratorLFStrangenessTriggered_900gev.ini b/MC/config/PWGLF/ini/GeneratorLFStrangenessTriggered_900gev.ini new file mode 100644 index 000000000..3447669ac --- /dev/null +++ b/MC/config/PWGLF/ini/GeneratorLFStrangenessTriggered_900gev.ini @@ -0,0 +1,10 @@ +[GeneratorExternal] +fileName=${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +# funcName=generateLFTriggered("${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun", 0) +funcName=generateLFTriggered("${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun", 4) + +[GeneratorPythia8] # if triggered then this will be used as the background event +config=${O2DPG_ROOT}/MC/config/PWGLF/pythia8/generator/pythia8_inel_pp900gev.cfg + +[DecayerPythia8] +config[0]=${O2DPG_ROOT}/MC/config/common/pythia8/decayer/base.cfg diff --git a/MC/run/PWGLF/run_StrangenessTriggered_pp900gev.sh b/MC/run/PWGLF/run_StrangenessTriggered_pp900gev.sh new file mode 100755 index 000000000..dc0262c0e --- /dev/null +++ b/MC/run/PWGLF/run_StrangenessTriggered_pp900gev.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# +# A example workflow MC->RECO->AOD for a simple pp min bias +# production, targetting test beam conditions. + +# make sure O2DPG + O2 is loaded +[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1 +[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1 + +# ----------- CONFIGURE -------------------------- +export IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE=1 +#export ALICEO2_CCDB_LOCALCACHE=.ccdb + +# ----------- LOAD UTILITY FUNCTIONS -------------------------- +. ${O2_ROOT}/share/scripts/jobutils.sh + +# ----------- START ACTUAL JOB ----------------------------- + +NWORKERS=${NWORKERS:-8} +SIMENGINE=${SIMENGINE:-TGeant4} +NSIGEVENTS=${NSIGEVENTS:-10} +NTIMEFRAMES=${NTIMEFRAMES:-1} +INTRATE=${INTRATE:-50000} +SYSTEM=${SYSTEM:-pp} +ENERGY=${ENERGY:-900} +CFGINIFILE=${CFGINIFILE:-"${O2DPG_ROOT}/MC/config/PWGLF/ini/GeneratorLFStrangenessTriggered_900gev.ini"} +[[ ${SPLITID} != "" ]] && SEED="-seed ${SPLITID}" || SEED="" + +echo "NWORKERS = $NWORKERS" + +# create workflow +O2_SIM_WORKFLOW=${O2_SIM_WORKFLOW:-"${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow.py"} +$O2_SIM_WORKFLOW -eCM ${ENERGY} -col ${SYSTEM} -gen external \ + -j ${NWORKERS} \ + -ns ${NSIGEVENTS} -tf ${NTIMEFRAMES} -interactionRate ${INTRATE} \ + -confKey "Diamond.width[2]=6." \ + ${SEED} \ + -e ${SIMENGINE} \ + -ini $CFGINIFILE + +# run workflow +O2_SIM_WORKFLOW_RUNNER=${O2_SIM_WORKFLOW_RUNNER:-"${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py"} +$O2_SIM_WORKFLOW_RUNNER -f workflow.json -tt aod --cpu-limit $NWORKERS From d5da4aa88e2a4f30f2074ed6a1e516781afe536f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Wed, 4 Oct 2023 14:39:24 +0200 Subject: [PATCH 3/7] Add 900 tester --- .../GeneratorLFStrangenessTriggered_900gev.C | 58 +++++++++++++++++++ MC/config/PWGLF/pythia8/generator/nuclei.gun | 18 +++--- .../PWGLF/pythia8/generator/resonancelist.gun | 40 ++++++------- 3 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 MC/config/PWGLF/ini/tests/GeneratorLFStrangenessTriggered_900gev.C diff --git a/MC/config/PWGLF/ini/tests/GeneratorLFStrangenessTriggered_900gev.C b/MC/config/PWGLF/ini/tests/GeneratorLFStrangenessTriggered_900gev.C new file mode 100644 index 000000000..49ba5d4e2 --- /dev/null +++ b/MC/config/PWGLF/ini/tests/GeneratorLFStrangenessTriggered_900gev.C @@ -0,0 +1,58 @@ +int External() +{ + std::string path{"o2sim_Kine.root"}; + int numberOfInjectedSignalsPerEvent{1}; + std::vector injectedPDGs = { + 3334, + -3334, + 3312, + -3312}; + + auto nInjection = injectedPDGs.size(); + + TFile file(path.c_str(), "READ"); + if (file.IsZombie()) { + std::cerr << "Cannot open ROOT file " << path << "\n"; + return 1; + } + + auto tree = (TTree*)file.Get("o2sim"); + if (!tree) { + std::cerr << "Cannot find tree o2sim in file " << path << "\n"; + return 1; + } + std::vector* tracks{}; + tree->SetBranchAddress("MCTrack", &tracks); + + std::vector nSignal; + for (int i = 0; i < nInjection; i++) { + nSignal.push_back(0); + } + + auto nEvents = tree->GetEntries(); + for (int i = 0; i < nEvents; i++) { + auto check = tree->GetEntry(i); + for (int idxMCTrack = 0; idxMCTrack < tracks->size(); ++idxMCTrack) { + auto track = tracks->at(idxMCTrack); + auto pdg = track.GetPdgCode(); + auto it = std::find(injectedPDGs.begin(), injectedPDGs.end(), pdg); + int index = std::distance(injectedPDGs.begin(), it); // index of injected PDG + if (it != injectedPDGs.end()) // found + { + // count signal PDG + nSignal[index]++; + } + } + } + std::cout << "--------------------------------\n"; + std::cout << "# Events: " << nEvents << "\n"; + for (int i = 0; i < nInjection; i++) { + std::cout << "# Injected nuclei \n"; + std::cout << injectedPDGs[i] << ": " << nSignal[i] << "\n"; + if (nSignal[i] == 0) { + std::cerr << "No generated: " << injectedPDGs[i] << "\n"; + return 1; // At least one of the injected particles should be generated + } + } + return 0; +} \ No newline at end of file diff --git a/MC/config/PWGLF/pythia8/generator/nuclei.gun b/MC/config/PWGLF/pythia8/generator/nuclei.gun index e33c00a82..e1bbc7d88 100644 --- a/MC/config/PWGLF/pythia8/generator/nuclei.gun +++ b/MC/config/PWGLF/pythia8/generator/nuclei.gun @@ -1,9 +1,9 @@ -# PDG N ptMin ptMax genDecayed -1000010020 10 0.2 10 --1000010020 10 0.2 10 -1000010030 10 0.2 10 --1000010030 10 0.2 10 -1000020030 10 0.2 10 --1000020030 10 0.2 10 -1000020040 10 0.2 10 --1000020040 10 0.2 10 +# PDG N ptMin ptMax etaMin etaMax genDecayed +1000010020 10 0.2 10 -1.2 1.2 +-1000010020 10 0.2 10 -1.2 1.2 +1000010030 10 0.2 10 -1.2 1.2 +-1000010030 10 0.2 10 -1.2 1.2 +1000020030 10 0.2 10 -1.2 1.2 +-1000020030 10 0.2 10 -1.2 1.2 +1000020040 10 0.2 10 -1.2 1.2 +-1000020040 10 0.2 10 -1.2 1.2 diff --git a/MC/config/PWGLF/pythia8/generator/resonancelist.gun b/MC/config/PWGLF/pythia8/generator/resonancelist.gun index b52df8c0d..daedb88f0 100644 --- a/MC/config/PWGLF/pythia8/generator/resonancelist.gun +++ b/MC/config/PWGLF/pythia8/generator/resonancelist.gun @@ -1,20 +1,20 @@ -# PDG N ptMin ptMax DecayByGenerator -313 10 0.2 10 genDecayed --313 10 0.2 10 genDecayed -323 10 0.2 10 genDecayed --323 10 0.2 10 genDecayed -333 10 0.2 10 genDecayed -9010221 10 0.2 10 genDecayed -113 10 0.2 10 genDecayed -213 10 0.2 10 genDecayed --213 10 0.2 10 genDecayed -3114 10 0.2 10 genDecayed --3114 10 0.2 10 genDecayed -3224 10 0.2 10 genDecayed --3224 10 0.2 10 genDecayed -3124 10 0.2 10 genDecayed --3124 10 0.2 10 genDecayed -3324 10 0.2 10 genDecayed --3324 10 0.2 10 genDecayed -10323 10 0.2 10 genDecayed --10323 10 0.2 10 genDecayed \ No newline at end of file +# PDG N ptMin ptMax etaMin etaMax DecayByGenerator +313 10 0.2 10 -1.2 1.2 genDecayed +-313 10 0.2 10 -1.2 1.2 genDecayed +323 10 0.2 10 -1.2 1.2 genDecayed +-323 10 0.2 10 -1.2 1.2 genDecayed +333 10 0.2 10 -1.2 1.2 genDecayed +9010221 10 0.2 10 -1.2 1.2 genDecayed +113 10 0.2 10 -1.2 1.2 genDecayed +213 10 0.2 10 -1.2 1.2 genDecayed +-213 10 0.2 10 -1.2 1.2 genDecayed +3114 10 0.2 10 -1.2 1.2 genDecayed +-3114 10 0.2 10 -1.2 1.2 genDecayed +3224 10 0.2 10 -1.2 1.2 genDecayed +-3224 10 0.2 10 -1.2 1.2 genDecayed +3124 10 0.2 10 -1.2 1.2 genDecayed +-3124 10 0.2 10 -1.2 1.2 genDecayed +3324 10 0.2 10 -1.2 1.2 genDecayed +-3324 10 0.2 10 -1.2 1.2 genDecayed +10323 10 0.2 10 -1.2 1.2 genDecayed +-10323 10 0.2 10 -1.2 1.2 genDecayed \ No newline at end of file From f1435466159094f2c07d2546ea1d67ff18298006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Tue, 17 Oct 2023 08:04:59 +0200 Subject: [PATCH 4/7] Use const members --- .../PWGLF/pythia8/generator_pythia8_LF.C | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C index 2acf7b58a..4cc159825 100644 --- a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +++ b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C @@ -328,27 +328,26 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 mPdg, mNInject, mPtMin, mPtMax, mEtaMin, mEtaMax, mMass); }; - // ConfigContainer(const ConfigContainer cfg) : ConfigContainer(cfg.mPdg, - // cfg.mNInject, - // cfg.mPtMin, - // cfg.mPtMax, - // cfg.mEtaMin, - // cfg.mEtaMax){}; - // ConfigContainer(TObjArray* arr) : ConfigContainer(atoi(arr->At(0)->GetName()), - // atoi(arr->At(1)->GetName()), - // atof(arr->At(2)->GetName()), - // atof(arr->At(3)->GetName()), - // atof(arr->At(4)->GetName()), - // atof(arr->At(5)->GetName())){}; - // ConfigContainer(TString line) : ConfigContainer(line.Tokenize(" ")){}; + ConfigContainer(TObjArray* arr) : ConfigContainer(atoi(arr->At(0)->GetName()), + atoi(arr->At(1)->GetName()), + atof(arr->At(2)->GetName()), + atof(arr->At(3)->GetName()), + atof(arr->At(4)->GetName()), + atof(arr->At(5)->GetName())) + { + if (arr->GetEntries() != 6) { + LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); + } + }; + ConfigContainer(TString line) : ConfigContainer(line.Tokenize(" ")){}; // Data Members - int mPdg = 0; - int mNInject = 1; - float mPtMin = 1; - float mPtMax = 10; - float mEtaMin = -1.f; - float mEtaMax = 1.f; + const int mPdg = 0; + const int mNInject = 1; + const float mPtMin = 1; + const float mPtMax = 10; + const float mEtaMin = -1.f; + const float mEtaMax = 1.f; double mMass = 0.f; void print() const @@ -499,9 +498,9 @@ FairGenerator* generateLF(std::string configuration = "${O2DPG_ROOT}/MC/config/P continue; } if (line.Contains("genDecayed")) { - cfgVecGenDecayed.push_back(GeneratorPythia8LF::ConfigContainer{line.Tokenize(" ")}); + cfgVecGenDecayed.push_back(GeneratorPythia8LF::ConfigContainer{line}); } else { - cfgVec.push_back(GeneratorPythia8LF::ConfigContainer{line.Tokenize(" ")}); + cfgVec.push_back(GeneratorPythia8LF::ConfigContainer{line}); } } } else { From ee548cbcc492adb1d63b06099bc080b8d7f63ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Tue, 17 Oct 2023 10:39:44 +0200 Subject: [PATCH 5/7] Add json support --- .../generator/strangeparticlelistgun.json | 38 ++++++++++++ .../PWGLF/pythia8/generator_pythia8_LF.C | 59 +++++++++++++++---- 2 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 MC/config/PWGLF/pythia8/generator/strangeparticlelistgun.json diff --git a/MC/config/PWGLF/pythia8/generator/strangeparticlelistgun.json b/MC/config/PWGLF/pythia8/generator/strangeparticlelistgun.json new file mode 100644 index 000000000..84ba4a4c9 --- /dev/null +++ b/MC/config/PWGLF/pythia8/generator/strangeparticlelistgun.json @@ -0,0 +1,38 @@ +{ + "omega-": { + "pdg": 3334, + "n": 1, + "ptMin": 0.2, + "ptMax": 10, + "etaMin": -1.2, + "etaMax": 1.2, + "genDecayed": false + }, + "antiomega+": { + "pdg": -3334, + "n": 1, + "ptMin": 0.2, + "ptMax": 10, + "etaMin": -1.2, + "etaMax": 1.2, + "genDecayed": false + }, + "xi-": { + "pdg": 3312, + "n": 1, + "ptMin": 0.2, + "ptMax": 10, + "etaMin": -1.2, + "etaMax": 1.2, + "genDecayed": false + }, + "antixi+": { + "pdg": -3312, + "n": 1, + "ptMin": 0.2, + "ptMax": 10, + "etaMin": -1.2, + "etaMax": 1.2, + "genDecayed": false + } +} \ No newline at end of file diff --git a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C index 4cc159825..58ce4715b 100644 --- a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +++ b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C @@ -23,6 +23,7 @@ #include #include "Generators/GeneratorPythia8Param.h" #include "Generators/DecayerPythia8Param.h" +#include #endif #include "generator_pythia8_longlived.C" @@ -178,7 +179,7 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 if (!pythiaObjectSignal.next()) { continue; } - //Check if triggered condition satisfied + // Check if triggered condition satisfied for (Long_t j = 0; j < pythiaObjectSignal.event.size(); j++) { const int& pypid = pythiaObjectSignal.event[j].id(); const float& pyeta = pythiaObjectSignal.event[j].eta(); @@ -335,11 +336,31 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 atof(arr->At(4)->GetName()), atof(arr->At(5)->GetName())) { - if (arr->GetEntries() != 6) { - LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); + bool hasGenDecayed = false; + for (int i = 0; i < arr->GetEntries(); i++) { + const TString n = arr->At(i)->GetName(); + if (n == "genDecayed") { + hasGenDecayed = true; + break; + } + if (hasGenDecayed) { + if (arr->GetEntries() != 6) { + LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); + } + } else { + if (arr->GetEntries() != 7) { + LOG(fatal) << "Wrong number of entries in the configuration array, should be 7, is " << arr->GetEntries(); + } + } } }; ConfigContainer(TString line) : ConfigContainer(line.Tokenize(" ")){}; + ConfigContainer(const nlohmann::json& jsonParams) : ConfigContainer(jsonParams["pdg"], + jsonParams["n"], + jsonParams["ptMin"], + jsonParams["ptMax"], + jsonParams["etaMin"], + jsonParams["etaMax"]){}; // Data Members const int mPdg = 0; @@ -482,7 +503,23 @@ FairGenerator* generateLF(std::string configuration = "${O2DPG_ROOT}/MC/config/P std::ifstream inputFile(configuration.c_str(), ios::in); std::vector cfgVec; std::vector cfgVecGenDecayed; - if (inputFile.is_open()) { + if (!inputFile.is_open()) { + LOGF(fatal, "Can't open '%s' !", configuration.c_str()); + return nullptr; + } + if (TString(configuration.c_str()).EndsWith(".json")) { // read from JSON file + nlohmann::json paramfile = nlohmann::json::parse(inputFile); + std::cout << "paramfile " << paramfile << std::endl; + for (const auto& param : paramfile) { + std::cout << param << std::endl; + // cfgVecGenDecayed.push_back(GeneratorPythia8LF::ConfigContainer{paramfile[n].template get(), param}); + if (param["genDecayed"]) { + cfgVecGenDecayed.push_back(GeneratorPythia8LF::ConfigContainer{param}); + } else { + cfgVec.push_back(GeneratorPythia8LF::ConfigContainer{param}); + } + } + } else { std::string l; int n = 0; while (getline(inputFile, l)) { @@ -492,7 +529,6 @@ FairGenerator* generateLF(std::string configuration = "${O2DPG_ROOT}/MC/config/P if (line.IsNull() || line.IsWhitespace()) { continue; } - if (line.BeginsWith("#")) { std::cout << "Skipping\n"; continue; @@ -503,9 +539,6 @@ FairGenerator* generateLF(std::string configuration = "${O2DPG_ROOT}/MC/config/P cfgVec.push_back(GeneratorPythia8LF::ConfigContainer{line}); } } - } else { - LOGF(fatal, "Can't open '%s' !", configuration.c_str()); - return nullptr; } return generateLF(cfgVec, cfgVecGenDecayed, injectOnePDGPerEvent, gapBetweenInjection, useTrigger, pythiaCfgMb, pythiaCfgSignal); } @@ -521,7 +554,7 @@ FairGenerator* generateLFTriggered(std::string configuration = "${O2DPG_ROOT}/MC } ///___________________________________________________________ -void generator_pythia8_LF(bool testInj = true, bool testTrg = false) +void generator_pythia8_LF(bool testInj = true, bool testTrg = false, const char* particleListFile = "cfg.json") { LOG(info) << "Compiled correctly!"; if (!testInj && !testTrg) { @@ -530,7 +563,7 @@ void generator_pythia8_LF(bool testInj = true, bool testTrg = false) // Injected mode if (testInj) { LOG(info) << "Testing the injected mode"; - auto* gen = static_cast(generateLF("/home/njacazio/alice/O2DPG/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun")); + auto* gen = static_cast(generateLF(particleListFile)); gen->setVerbose(); gen->Print(); gen->print(); @@ -542,10 +575,10 @@ void generator_pythia8_LF(bool testInj = true, bool testTrg = false) // Triggered mode if (testTrg) { LOG(info) << "Testing the triggered mode"; - GeneratorPythia8LF* gen = static_cast(generateLFTriggered("/home/njacazio/alice/O2DPG/MC/config/PWGLF/pythia8/generator/strangeparticlelist.gun", + GeneratorPythia8LF* gen = static_cast(generateLFTriggered(particleListFile, /*gapBetweenInjection=*/0, - /*pythiaCfgMb=*/"/home/njacazio/alice/O2DPG/MC/config/PWGLF/pythia8/generator/inel136tev.cfg", - /*pythiaCfgSignal=*/"/home/njacazio/alice/O2DPG/MC/config/PWGLF/pythia8/generator/inel136tev.cfg")); + /*pythiaCfgMb=*/"inel136tev.cfg", + /*pythiaCfgSignal=*/"inel136tev.cfg")); gen->setVerbose(); gen->Print(); gen->print(); From 73b24f474ace87cc8989ca5965f14e0a6d8174bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Tue, 17 Oct 2023 11:54:34 +0200 Subject: [PATCH 6/7] Fix --- MC/config/PWGLF/pythia8/generator_pythia8_LF.C | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C index 58ce4715b..a225ff041 100644 --- a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +++ b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C @@ -344,11 +344,11 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 break; } if (hasGenDecayed) { - if (arr->GetEntries() != 6) { + if (arr->GetEntries() != 7) { LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); } } else { - if (arr->GetEntries() != 7) { + if (arr->GetEntries() != 6) { LOG(fatal) << "Wrong number of entries in the configuration array, should be 7, is " << arr->GetEntries(); } } From 3a02bcfd00a1ed712c473a470d106be4b350cffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Tue, 17 Oct 2023 13:09:12 +0200 Subject: [PATCH 7/7] Update --- MC/config/PWGLF/pythia8/generator_pythia8_LF.C | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C index a225ff041..b5550fb5e 100644 --- a/MC/config/PWGLF/pythia8/generator_pythia8_LF.C +++ b/MC/config/PWGLF/pythia8/generator_pythia8_LF.C @@ -339,18 +339,19 @@ class GeneratorPythia8LF : public o2::eventgen::GeneratorPythia8 bool hasGenDecayed = false; for (int i = 0; i < arr->GetEntries(); i++) { const TString n = arr->At(i)->GetName(); + std::cout << n << std::endl; if (n == "genDecayed") { hasGenDecayed = true; break; } - if (hasGenDecayed) { - if (arr->GetEntries() != 7) { - LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); - } - } else { - if (arr->GetEntries() != 6) { - LOG(fatal) << "Wrong number of entries in the configuration array, should be 7, is " << arr->GetEntries(); - } + } + if (hasGenDecayed) { + if (arr->GetEntries() != 7) { + LOG(fatal) << "Wrong number of entries in the configuration array, should be 7, is " << arr->GetEntries(); + } + } else { + if (arr->GetEntries() != 6) { + LOG(fatal) << "Wrong number of entries in the configuration array, should be 6, is " << arr->GetEntries(); } } };