Skip to content
Merged
Show file tree
Hide file tree
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
101 changes: 55 additions & 46 deletions ALICE3/Core/FastTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,42 @@
}
}

std::map<std::string, std::map<std::string, std::string>> FastTracker::parseTEnvConfiguration(std::string filename)
{
std::map<std::string, std::map<std::string, std::string>> configMap;

TEnv env(filename.c_str());
THashList* table = env.GetTable();
std::vector<std::string> layers;
for (int i = 0; i < table->GetEntries(); ++i) {
const std::string key = table->At(i)->GetName();
// key should contain exactly one dot
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
continue;
}
const std::string firstPart = key.substr(0, key.find('.'));
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
layers.push_back(firstPart);
}
}
env.Print();

// Layers
for (const auto& layer : layers) {
LOG(info) << " Reading layer " << layer;
for (int i = 0; i < table->GetEntries(); ++i) {
const std::string key = table->At(i)->GetName();
if (key.find(layer + ".") == 0) {
const std::string paramName = key.substr(key.find('.') + 1);
const std::string value = env.GetValue(key.c_str(), "");
configMap[layer][paramName] = value;
}
}
}
return configMap;
}

void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager)
{
LOG(info) << " Adding generic detector from file " << filename;
Expand Down Expand Up @@ -263,54 +299,27 @@
return;
}

TEnv env(filename.c_str());
THashList* table = env.GetTable();
std::vector<std::string> layers;
for (int i = 0; i < table->GetEntries(); ++i) {
const std::string key = table->At(i)->GetName();
// key should contain exactly one dot
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
continue;
}
const std::string firstPart = key.substr(0, key.find('.'));
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
layers.push_back(firstPart);
}
}
// env.Print();
std::map<std::string, std::map<std::string, std::string>> configMap = parseTEnvConfiguration(filename);
// Layers
for (const auto& layer : layers) {
LOG(info) << " Reading layer " << layer;

auto getKey = [&layer, &env](const std::string& name, const bool required = true) {
std::string key = layer + "." + name;
if (!env.Defined(key.c_str())) {
if (required) {
LOG(fatal) << "Key " << key << " not defined in configuration file";
}
LOG(debug) << "Key " << key << " not defined in configuration file, getting the default value";
}
LOG(debug) << " Getting key " << key << " from configuration file";
return key;
};
const float r = env.GetValue(getKey("r").c_str(), -1.0f);
LOG(info) << " Layer " << layer << " has radius " << r;
const float z = env.GetValue(getKey("z").c_str(), -1.0f);
const float x0 = env.GetValue(getKey("x0").c_str(), 0.0f);
const float xrho = env.GetValue(getKey("xrho").c_str(), 0.0f);
const float resRPhi = env.GetValue(getKey("resRPhi").c_str(), 0.0f);
const float resZ = env.GetValue(getKey("resZ").c_str(), 0.0f);
const float eff = env.GetValue(getKey("eff").c_str(), 0.0f);
const int type = env.GetValue(getKey("type").c_str(), 0);
const char* deadPhiRegions = env.GetValue(getKey("deadPhiRegions", false).c_str(), "");
for (const auto& layer : configMap) {
LOG(info) << " Reading layer " << layer.first;
const float r = std::stof(layer.second.at("r"));
LOG(info) << " Layer " << layer.first << " has radius " << r;
const float z = std::stof(layer.second.at("z"));
const float x0 = std::stof(layer.second.at("x0"));
const float xrho = std::stof(layer.second.at("xrho"));
const float resRPhi = std::stof(layer.second.at("resRPhi"));
const float resZ = std::stof(layer.second.at("resZ"));
const float eff = std::stof(layer.second.at("eff"));
const int type = std::stoi(layer.second.at("type"));
const std::string deadPhiRegions = layer.second.at("deadPhiRegions");

// void AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
LOG(info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
LOG(info) << " Adding layer " << layer.first << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;

DetLayer* addedLayer = AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
if (strlen(deadPhiRegions) > 0) { // Taking it as ccdb path or local file
// Check if it begins with ccdb:
DetLayer* addedLayer = AddLayer(layer.first.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
if (!deadPhiRegions.empty()) { // Taking it as ccdb path or local file
// Check if it begins with ccdb:
if (std::string(deadPhiRegions).rfind("ccdb:", 0) == 0) {
std::string ccdbPath = std::string(deadPhiRegions).substr(5); // remove "ccdb:" prefix
if (ccdbManager == nullptr) {
Expand All @@ -321,7 +330,7 @@
addedLayer->setDeadPhiRegions(g);
} else {
// Taking it as local file
TFile infile(deadPhiRegions, "READ");
TFile infile(deadPhiRegions.c_str(), "READ");
if (!infile.IsOpen()) {
LOG(fatal) << "Cannot open dead phi regions file " << deadPhiRegions;
return;
Expand All @@ -331,7 +340,7 @@
addedLayer->setDeadPhiRegions(g);
}
} else {
LOG(debug) << " No dead phi regions for layer " << layer;
LOG(debug) << " No dead phi regions for layer " << layer.first;
}
}
}
Expand All @@ -351,7 +360,7 @@
index = 1;
z0 = -4 * sigmaD + i * dz0;
dist += index * (dz0 / 3.) * (1 / o2::math_utils::sqrt(o2::constants::math::TwoPI) / sigmaD) * std::exp(-z0 * z0 / 2. / sigmaD / sigmaD) * (1 / o2::math_utils::sqrt((z - z0) * (z - z0) + r * r));
if (index != 4)

Check failure on line 363 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
index = 4;
else
index = 2;
Expand Down Expand Up @@ -481,7 +490,7 @@
// check if layer is reached
float targetX = 1e+3;
inputTrack.getXatLabR(layers[il].getRadius(), targetX, magneticField);
if (targetX > 999.f) {

Check failure on line 493 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
LOGF(debug, "Failed to find intercept for layer %d at radius %.2f cm", il, layers[il].getRadius());
break; // failed to find intercept
}
Expand Down Expand Up @@ -563,7 +572,7 @@

float targetX = 1e+3;
inputTrack.getXatLabR(layers[il].getRadius(), targetX, magneticField);
if (targetX > 999)

Check failure on line 575 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
continue; // failed to find intercept

if (!inputTrack.propagateTo(targetX, magneticField)) {
Expand Down Expand Up @@ -635,7 +644,7 @@
// backpropagate to original radius
float finalX = 1e+3;
bool inPropStatus = inwardTrack.getXatLabR(initialRadius, finalX, magneticField);
if (finalX > 999) {

Check failure on line 647 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
LOG(debug) << "Failed to find intercept for initial radius " << initialRadius << " cm, x = " << finalX << " and status " << inPropStatus << " and sn = " << inwardTrack.getSnp() << " r = " << inwardTrack.getY() * inwardTrack.getY();
return -3; // failed to find intercept
}
Expand All @@ -645,7 +654,7 @@
}

// only attempt to continue if intercepts are at least four
if (nIntercepts < 4)

Check failure on line 657 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
return nIntercepts;

// generate efficiency
Expand All @@ -672,7 +681,7 @@
TMatrixDSym m(5);
double fcovm[5][5]; // double precision is needed for regularisation

for (int ii = 0, k = 0; ii < 5; ++ii) {

Check failure on line 684 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
for (int j = 0; j < ii + 1; ++j, ++k) {
fcovm[ii][j] = covMat[k];
fcovm[j][ii] = covMat[k];
Expand All @@ -680,7 +689,7 @@
}

// evaluate ruben's conditional, regularise
const bool makePositiveDefinite = (covMatFactor > -1e-5); // apply fix

Check failure on line 692 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
bool rubenConditional = false;
for (int ii = 0; ii < 5; ii++) {
for (int jj = 0; jj < 5; jj++) {
Expand All @@ -689,7 +698,7 @@
if (fcovm[ii][jj] * fcovm[ii][jj] > std::abs(fcovm[ii][ii] * fcovm[jj][jj])) {
rubenConditional = true;
if (makePositiveDefinite) {
fcovm[ii][jj] = TMath::Sign(1, fcovm[ii][jj]) * covMatFactor * sqrt(std::abs(fcovm[ii][ii] * fcovm[jj][jj]));

Check failure on line 701 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
}
}
}
Expand Down Expand Up @@ -727,7 +736,7 @@
for (int j = 0; j < 5; ++j)
val += eigVec[j][ii] * outputTrack.getParam(j);
// smear parameters according to eigenvalues
params_[ii] = gRandom->Gaus(val, sqrt(eigVal[ii]));

Check failure on line 739 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
}

// invert eigenvector matrix
Expand All @@ -740,7 +749,7 @@
outputTrack.setParam(val, ii);
}
// should make a sanity check that par[2] sin(phi) is in [-1, 1]
if (fabs(outputTrack.getParam(2)) > 1.) {

Check failure on line 752 in ALICE3/Core/FastTracker.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[std-prefix]

Use std:: prefix for names from the std namespace.
LOG(info) << " --- smearTrack failed sin(phi) sanity check: " << outputTrack.getParam(2);
return -2;
}
Expand Down
8 changes: 8 additions & 0 deletions ALICE3/Core/FastTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ class FastTracker
void AddSiliconALICE3v2(std::vector<float> pixelResolution);
void AddSiliconALICE3(float scaleX0VD, std::vector<float> pixelResolution);
void AddTPC(float phiResMean, float zResMean);

/**
* @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
* @param filename Path to the TEnv configuration file
* @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
*/
std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string filename);

/**
* @brief Adds a generic detector configuration from the specified file.
*
Expand Down
Loading