diff --git a/ALICE3/Core/DelphesO2TrackSmearer.cxx b/ALICE3/Core/DelphesO2TrackSmearer.cxx index f4ea4ebdf3c..2c6b23e8e83 100644 --- a/ALICE3/Core/DelphesO2TrackSmearer.cxx +++ b/ALICE3/Core/DelphesO2TrackSmearer.cxx @@ -36,6 +36,8 @@ #include "ALICE3/Core/DelphesO2TrackSmearer.h" +#include + namespace o2 { namespace delphes @@ -45,11 +47,38 @@ namespace delphes bool TrackSmearer::loadTable(int pdg, const char* filename, bool forceReload) { - auto ipdg = getIndexPDG(pdg); + if (!filename || filename[0] == '\0') { + LOG(info) << " --- No LUT file provided for PDG " << pdg << ". Skipping load."; + return false; + } + const auto ipdg = getIndexPDG(pdg); + LOGF(info, "Will load %s lut file ..: '%s'", getParticleName(pdg), filename); if (mLUTHeader[ipdg] && !forceReload) { std::cout << " --- LUT table for PDG " << pdg << " has been already loaded with index " << ipdg << std::endl; return false; } + if (strncmp(filename, "ccdb:", 5) == 0) { // Check if filename starts with "ccdb:" + LOG(info) << " --- LUT file source identified as CCDB."; + std::string path = std::string(filename).substr(5); // Remove "ccdb:" prefix + const std::string outPath = "/tmp/LUTs/"; + filename = Form("%s/%s/snapshot.root", outPath.c_str(), path.c_str()); + std::ifstream checkFile(filename); // Check if file already exists + if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB + LOG(info) << " --- CCDB source detected for PDG " << pdg << ": " << path; + if (!mCcdbManager) { + LOG(fatal) << " --- CCDB manager not set. Please set it before loading LUT from CCDB."; + } + std::map metadata; + mCcdbManager->getCCDBAccessor().retrieveBlob(path, outPath, metadata, 1); + // Add CCDB handling logic here if needed + LOG(info) << " --- Now retrieving LUT file from CCDB to: " << filename; + } else { // File exists, proceed to load + LOG(info) << " --- LUT file already exists: " << filename << ". Skipping download."; + checkFile.close(); + } + return loadTable(pdg, filename, forceReload); + } + mLUTHeader[ipdg] = new lutHeader_t; std::ifstream lutFile(filename, std::ifstream::binary); diff --git a/ALICE3/Core/DelphesO2TrackSmearer.h b/ALICE3/Core/DelphesO2TrackSmearer.h index 1e0fd873e2c..2e2198bd68f 100644 --- a/ALICE3/Core/DelphesO2TrackSmearer.h +++ b/ALICE3/Core/DelphesO2TrackSmearer.h @@ -24,12 +24,14 @@ #ifndef ALICE3_CORE_DELPHESO2TRACKSMEARER_H_ #define ALICE3_CORE_DELPHESO2TRACKSMEARER_H_ -#include -#include -#include +#include +#include -#include "TRandom.h" -#include "ReconstructionDataFormats/Track.h" +#include + +#include +#include +#include /////////////////////////////// /// DelphesO2/src/lutCovm.hh // @@ -85,7 +87,7 @@ struct map_t { if (bin > nbins - 1) return nbins - 1; return bin; - } //; + } //; void print() { printf("nbins = %d, min = %f, max = %f, log = %s \n", nbins, min, max, log ? "on" : "off"); } //; }; @@ -214,10 +216,34 @@ class TrackSmearer return 7; // Helium3 default: return 2; // Default: pion - } //; - } //; + } + } - void setdNdEta(float val) { mdNdEta = val; } //; + const char* getParticleName(int pdg) + { + switch (abs(pdg)) { + case 11: + return "electron"; + case 13: + return "muon"; + case 211: + return "pion"; + case 321: + return "kaon"; + case 2212: + return "proton"; + case 1000010020: + return "deuteron"; + case 1000010030: + return "triton"; + case 1000020030: + return "helium3"; + default: + return "pion"; // Default: pion + } + } + void setdNdEta(float val) { mdNdEta = val; } //; + void setCcdbManager(o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; } //; protected: static constexpr unsigned int nLUTs = 8; // Number of LUT available @@ -228,6 +254,9 @@ class TrackSmearer bool mSkipUnreconstructed = true; // don't smear tracks that are not reco'ed int mWhatEfficiency = 1; float mdNdEta = 1600.; + + private: + o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr; }; } // namespace delphes diff --git a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx index c858f5a753e..2005969d239 100644 --- a/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx +++ b/ALICE3/TableProducer/OTF/onTheFlyTracker.cxx @@ -239,42 +239,32 @@ struct OnTheFlyTracker { // For TGenPhaseSpace seed TRandom3 rand; + Service ccdb; void init(o2::framework::InitContext&) { + + ccdb->setURL("http://alice-ccdb.cern.ch"); + ccdb->setTimestamp(-1); + if (enableLUT) { - std::map mapPdgLut; - const char* lutElChar = lutEl->c_str(); - const char* lutMuChar = lutMu->c_str(); - const char* lutPiChar = lutPi->c_str(); - const char* lutKaChar = lutKa->c_str(); - const char* lutPrChar = lutPr->c_str(); - - LOGF(info, "Will load electron lut file ..: %s", lutElChar); - LOGF(info, "Will load muon lut file ......: %s", lutMuChar); - LOGF(info, "Will load pion lut file ......: %s", lutPiChar); - LOGF(info, "Will load kaon lut file ......: %s", lutKaChar); - LOGF(info, "Will load proton lut file ....: %s", lutPrChar); - - mapPdgLut.insert(std::make_pair(11, lutElChar)); - mapPdgLut.insert(std::make_pair(13, lutMuChar)); - mapPdgLut.insert(std::make_pair(211, lutPiChar)); - mapPdgLut.insert(std::make_pair(321, lutKaChar)); - mapPdgLut.insert(std::make_pair(2212, lutPrChar)); - - if (enableNucleiSmearing) { - const char* lutDeChar = lutDe->c_str(); - const char* lutTrChar = lutTr->c_str(); - const char* lutHe3Char = lutHe3->c_str(); - mapPdgLut.insert(std::make_pair(1000010020, lutDeChar)); - mapPdgLut.insert(std::make_pair(1000010030, lutTrChar)); - mapPdgLut.insert(std::make_pair(1000020030, lutHe3Char)); - } - for (const auto& e : mapPdgLut) { - if (!mSmearer.loadTable(e.first, e.second)) { - LOG(fatal) << "Having issue with loading the LUT " << e.first << " " << e.second; + mSmearer.setCcdbManager(ccdb.operator->()); + + auto loadLUT = [&](int pdg, const std::string& lutFile) { + bool success = mSmearer.loadTable(pdg, lutFile.c_str()); + if (!success && !lutFile.empty()) { + LOG(fatal) << "Having issue with loading the LUT " << pdg << " " << lutFile; } - } + }; + loadLUT(11, lutEl.value); + loadLUT(13, lutMu.value); + loadLUT(211, lutPi.value); + loadLUT(321, lutKa.value); + loadLUT(2212, lutPr.value); + loadLUT(1000010020, lutDe.value); + loadLUT(1000010030, lutTr.value); + loadLUT(1000020030, lutHe3.value); + // interpolate efficiencies if requested to do so mSmearer.interpolateEfficiency(static_cast(interpolateLutEfficiencyVsNch));