Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 deletions Common/Tools/TrackTuner.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <ReconstructionDataFormats/Track.h>

#include <TGraphErrors.h>
#include <TList.h>

#include <fmt/core.h>

Expand All @@ -57,8 +58,8 @@
DECLARE_SOA_COLUMN(TunedQOverPt, tunedQOverPt, float);

/// configuration source
enum configSource : int { InputString = 1,

Check failure on line 61 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/enum]

Use UpperCamelCase for names of enumerators and their values.
Configurables };

Check failure on line 62 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
} // namespace track_tuner

DECLARE_SOA_TABLE(TrackTunerTable, "AOD", "TRACKTUNERTABLE", //!
Expand All @@ -68,10 +69,10 @@
struct TrackTuner : o2::framework::ConfigurableGroup {

std::string prefix = "trackTuner"; // JSON group name
o2::framework::Configurable<bool> cfgDebugInfo{"debugInfo", false, "Flag to switch on the debug printout"};

Check failure on line 72 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
o2::framework::Configurable<bool> cfgUpdateTrackDCAs{"updateTrackDCAs", false, "Flag to enable the DCA smearing"};

Check failure on line 73 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
o2::framework::Configurable<bool> cfgUpdateTrackCovMat{"updateTrackCovMat", false, "Flag to enable the DCA covariance-matrix smearing"};

Check failure on line 74 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
o2::framework::Configurable<bool> cfgUpdateCurvature{"updateCurvature", false, "Flag to enable the Q/Pt smearing after the propagation to the production point"};

Check failure on line 75 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
o2::framework::Configurable<bool> cfgUpdateCurvatureIU{"updateCurvatureIU", false, "Flag to enable the Q/Pt smearing before the propagation to the production point"};
o2::framework::Configurable<bool> cfgUpdatePulls{"updatePulls", false, "Flag to enable the pulls smearing"};
o2::framework::Configurable<bool> cfgIsInputFileFromCCDB{"isInputFileFromCCDB", false, "True: files from CCDB; False: fils from local path (debug)"};
Expand Down Expand Up @@ -104,7 +105,6 @@
bool isConfigFromConfigurables = false;
int nPhiBins = 1;

o2::ccdb::CcdbApi ccdbApi;
std::map<std::string, std::string> metadata;

std::vector<std::unique_ptr<TGraphErrors>> grDcaXYResVsPtPionMC;
Expand Down Expand Up @@ -249,7 +249,7 @@

LOG(info) << "[TrackTuner]";
LOG(info) << "[TrackTuner] >>> String slices:";
for (const std::string& s : slices)

Check failure on line 252 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[const-ref-in-for-loop]

Use constant references for non-modified iterators in range-based for loops.
LOG(info) << "[TrackTuner] " << s;

/// check if the number of input parameters is correct
Expand Down Expand Up @@ -449,51 +449,52 @@

void getDcaGraphs()
{
std::string fullNameInputFile = "";
std::string fullNameFileQoverPt = "";
std::string fullNameInputFile = pathInputFile + std::string("/") + nameInputFile;
std::string fullNameFileQoverPt = pathFileQoverPt + std::string("/") + nameFileQoverPt;
TList* ccdb_object_dca = nullptr;

Check failure on line 454 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/function-variable]

Use lowerCamelCase for names of functions and variables.
TList* ccdb_object_qoverpt = nullptr;

Check failure on line 455 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[name/function-variable]

Use lowerCamelCase for names of functions and variables.

std::string grOneOverPtPionNameMC = "sigmaVsPtMc";
std::string grOneOverPtPionNameData = "sigmaVsPtData";

if (isInputFileFromCCDB) {
/// use input correction file from CCDB

// properly init the ccdb
std::string tmpDir = ".";
ccdbApi.init("http://alice-ccdb.cern.ch");
// get the TList from the DCA correction file present in CCDB
ccdb_object_dca = o2::ccdb::BasicCCDBManager::instance().get<TList>(pathInputFile);
LOG(info) << " [TrackTuner] ccdb_object_dca " << ccdb_object_dca;

// get the DCA correction file from CCDB
if (!ccdbApi.retrieveBlob(pathInputFile.data(), tmpDir, metadata, 0, false, nameInputFile.data())) {
LOG(fatal) << "[TrackTuner] input file for DCA corrections not found on CCDB, please check the pathInputFile and nameInputFile!";
// get the TList from the Q/Pt correction file from CCDB
if (updateCurvature || updateCurvatureIU) {
ccdb_object_qoverpt = o2::ccdb::BasicCCDBManager::instance().get<TList>(pathFileQoverPt);
LOG(info) << " [TrackTuner] ccdb_object_qoverpt " << ccdb_object_qoverpt;
}

// get the Q/Pt correction file from CCDB
if (!ccdbApi.retrieveBlob(pathFileQoverPt.data(), tmpDir, metadata, 0, false, nameFileQoverPt.data())) {
LOG(fatal) << "[TrackTuner] input file for Q/Pt corrections not found on CCDB, please check the pathFileQoverPt and nameFileQoverPt!";
}
// point to the file in the tmp local folder
fullNameInputFile = tmpDir + std::string("/") + nameInputFile;
fullNameFileQoverPt = tmpDir + std::string("/") + nameFileQoverPt;
} else {
/// use input correction file from local filesystem
fullNameInputFile = pathInputFile + std::string("/") + nameInputFile;
fullNameFileQoverPt = pathFileQoverPt + std::string("/") + nameFileQoverPt;
}
/// open the input correction file
std::unique_ptr<TFile> inputFile(TFile::Open(fullNameInputFile.c_str(), "READ"));
if (!inputFile.get()) {
LOG(fatal) << "Something wrong with the input file" << fullNameInputFile << " for dca correction. Fix it!";
}
std::unique_ptr<TFile> inputFileQoverPt(TFile::Open(fullNameFileQoverPt.c_str(), "READ"));
if (!inputFileQoverPt.get() && (updateCurvature || updateCurvatureIU)) {
LOG(fatal) << "Something wrong with the Q/Pt input file" << fullNameFileQoverPt << " for Q/Pt correction. Fix it!";

/// open the input correction file - dca correction
TFile* inputFile = TFile::Open(fullNameInputFile.c_str(), "READ");
if (!inputFile) {
LOG(fatal) << "[TrackTuner] Something wrong with the local input file" << fullNameInputFile << " for dca correction. Fix it!";
}
ccdb_object_dca = dynamic_cast<TList*>(inputFile->Get("ccdb_object"));

/// open the input correction file - q/pt correction
TFile* inputFileQoverPt = TFile::Open(fullNameFileQoverPt.c_str(), "READ");
if (!inputFileQoverPt && (updateCurvature || updateCurvatureIU)) {
LOG(fatal) << "Something wrong with the Q/Pt input file" << fullNameFileQoverPt << " for Q/Pt correction. Fix it!";
}
ccdb_object_qoverpt = dynamic_cast<TList*>(inputFileQoverPt->Get("ccdb_object"));
}

// choose wheter to use corrections w/ PV refit or w/o it, and retrieve the proper TDirectory
// choose wheter to use corrections w/ PV refit or w/o it, and retrieve the proper TList
std::string dir = "woPvRefit";
if (usePvRefitCorrections) {
dir = "withPvRefit";
}
TDirectory* td = dynamic_cast<TDirectory*>(inputFile->Get(dir.c_str()));
TList* td = dynamic_cast<TList*>(ccdb_object_dca->FindObject(dir.c_str()));
if (!td) {
LOG(fatal) << "TDirectory " << td << " not found in input file" << inputFile->GetName() << ". Fix it!";
LOG(fatal) << "[TrackTuner] TList " << td << " not found in ccdb_object_dca. Fix it!";
}

int inputNphiBins = nPhiBins;
Expand Down Expand Up @@ -522,7 +523,7 @@
/// Lambda expression to get the TGraphErrors from file
auto loadGraph = [&](int phiBin, const std::string& strBaseName) -> TGraphErrors* {
std::string strGraphName = inputNphiBins != 0 ? fmt::format("{}_{}", strBaseName, phiBin) : strBaseName;
TObject* obj = td->Get(strGraphName.c_str());
TObject* obj = td->FindObject(strGraphName.c_str());
if (!obj) {
LOG(fatal) << "[TrackTuner] TGraphErrors not found in the Input Root file: " << strGraphName;
td->ls();
Expand Down Expand Up @@ -564,12 +565,9 @@
}
}

std::string grOneOverPtPionNameMC = "sigmaVsPtMc";
std::string grOneOverPtPionNameData = "sigmaVsPtData";

if (updateCurvature || updateCurvatureIU) {
grOneOverPtPionMC.reset(dynamic_cast<TGraphErrors*>(inputFileQoverPt->Get(grOneOverPtPionNameMC.c_str())));
grOneOverPtPionData.reset(dynamic_cast<TGraphErrors*>(inputFileQoverPt->Get(grOneOverPtPionNameData.c_str())));
grOneOverPtPionMC.reset(dynamic_cast<TGraphErrors*>(ccdb_object_qoverpt->FindObject(grOneOverPtPionNameMC.c_str())));
grOneOverPtPionData.reset(dynamic_cast<TGraphErrors*>(ccdb_object_qoverpt->FindObject(grOneOverPtPionNameData.c_str())));
}
} // getDcaGraphs() ends here

Expand All @@ -595,7 +593,7 @@
// get phibin
double phiMC = mcparticle.phi();
if (phiMC < 0.)
phiMC += o2::constants::math::TwoPI; // 2 * std::numbers::pi;//

Check failure on line 596 in Common/Tools/TrackTuner.h

View workflow job for this annotation

GitHub Actions / O2 linter

[two-pi-add-subtract]

Use RecoDecay::constrainAngle to restrict angle to a given range.
int phiBin = phiMC / (o2::constants::math::TwoPI + 0.0000001) * nPhiBins; // 0.0000001 just a numerical protection

dcaXYResMC = evalGraph(ptMC, grDcaXYResVsPtPionMC[phiBin].get());
Expand Down
Loading