Skip to content

Commit deabeed

Browse files
committed
Add A3 geo provider
1 parent 7b487e9 commit deabeed

File tree

7 files changed

+381
-243
lines changed

7 files changed

+381
-243
lines changed

ALICE3/Core/FastTracker.cxx

Lines changed: 101 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@
1111

1212
#include "FastTracker.h"
1313

14-
#include "ReconstructionDataFormats/TrackParametrization.h"
14+
#include "Common/Core/TableHelper.h"
15+
16+
#include <ReconstructionDataFormats/TrackParametrization.h>
1517

16-
#include "TMath.h"
17-
#include "TMatrixD.h"
18-
#include "TMatrixDSymEigen.h"
19-
#include "TRandom.h"
2018
#include <TEnv.h>
2119
#include <THashList.h>
20+
#include <TMath.h>
21+
#include <TMatrixD.h>
22+
#include <TMatrixDSymEigen.h>
2223
#include <TObject.h>
24+
#include <TRandom.h>
25+
#include <TSystem.h>
2326

2427
#include <fstream>
2528
#include <map>
@@ -31,6 +34,81 @@ namespace o2
3134
namespace fastsim
3235
{
3336

37+
std::map<std::string, std::map<std::string, std::string>> GeometryContainer::parseTEnvConfiguration(std::string filename, std::vector<std::string>& layers)
38+
{
39+
std::map<std::string, std::map<std::string, std::string>> configMap;
40+
filename = gSystem->ExpandPathName(filename.c_str());
41+
TEnv env(filename.c_str());
42+
THashList* table = env.GetTable();
43+
layers.clear();
44+
for (int i = 0; i < table->GetEntries(); ++i) {
45+
const std::string key = table->At(i)->GetName();
46+
// key should contain exactly one dot
47+
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
48+
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
49+
continue;
50+
}
51+
const std::string firstPart = key.substr(0, key.find('.'));
52+
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
53+
layers.push_back(firstPart);
54+
}
55+
}
56+
env.Print();
57+
// Layers
58+
for (const auto& layer : layers) {
59+
LOG(info) << " Reading layer " << layer;
60+
for (int i = 0; i < table->GetEntries(); ++i) {
61+
const std::string key = table->At(i)->GetName();
62+
if (key.find(layer + ".") == 0) {
63+
const std::string paramName = key.substr(key.find('.') + 1);
64+
const std::string value = env.GetValue(key.c_str(), "");
65+
configMap[layer][paramName] = value;
66+
}
67+
}
68+
}
69+
return configMap;
70+
}
71+
72+
void GeometryContainer::init(o2::framework::InitContext& initContext)
73+
{
74+
std::vector<std::string> detectorConfiguration;
75+
const bool found = common::core::getTaskOptionValue(initContext, "on-the-fly-detector-geometry-provider", "detectorConfiguration", detectorConfiguration, false);
76+
if (!found) {
77+
LOG(fatal) << "Could not retrieve detector configuration from OnTheFlyDetectorGeometryProvider task.";
78+
return;
79+
}
80+
LOG(info) << "Size of detector configuration: " << detectorConfiguration.size();
81+
for (const auto& configFile : detectorConfiguration) {
82+
LOG(info) << "Detector geometry configuration file used: " << configFile;
83+
addEntry(configFile);
84+
}
85+
}
86+
87+
std::map<std::string, std::string> GeometryContainer::GeometryEntry::getConfiguration(const std::string& layerName) const
88+
{
89+
auto it = mConfigurations.find(layerName);
90+
if (it != mConfigurations.end()) {
91+
return it->second;
92+
} else {
93+
LOG(fatal) << "Layer " << layerName << " not found in geometry configurations.";
94+
return {};
95+
}
96+
}
97+
98+
std::string GeometryContainer::GeometryEntry::getValue(const std::string& layerName, const std::string& key, bool require) const
99+
{
100+
auto layer = getConfiguration(layerName);
101+
auto entry = layer.find(key);
102+
if (entry != layer.end()) {
103+
return layer.at(key);
104+
} else if (require) {
105+
return "";
106+
} else {
107+
LOG(fatal) << "Key " << key << " not found in layer " << layerName << " configurations.";
108+
return "";
109+
}
110+
}
111+
34112
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
35113

36114
DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
@@ -236,88 +314,31 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
236314
}
237315
}
238316

239-
std::map<std::string, std::map<std::string, std::string>> FastTracker::parseTEnvConfiguration(std::string filename)
317+
void FastTracker::AddGenericDetector(GeometryContainer::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager)
240318
{
241-
std::map<std::string, std::map<std::string, std::string>> configMap;
242-
243-
TEnv env(filename.c_str());
244-
THashList* table = env.GetTable();
245-
std::vector<std::string> layers;
246-
for (int i = 0; i < table->GetEntries(); ++i) {
247-
const std::string key = table->At(i)->GetName();
248-
// key should contain exactly one dot
249-
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
250-
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
319+
// Layers
320+
for (const auto& layer : configMap.getLayerNames()) {
321+
if (layer.find("global") != std::string::npos) { // Layers with global tag are skipped
322+
LOG(info) << " Skipping global configuration entry " << layer;
251323
continue;
252324
}
253-
const std::string firstPart = key.substr(0, key.find('.'));
254-
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
255-
layers.push_back(firstPart);
256-
}
257-
}
258-
env.Print();
259325

260-
// Layers
261-
for (const auto& layer : layers) {
262326
LOG(info) << " Reading layer " << layer;
263-
for (int i = 0; i < table->GetEntries(); ++i) {
264-
const std::string key = table->At(i)->GetName();
265-
if (key.find(layer + ".") == 0) {
266-
const std::string paramName = key.substr(key.find('.') + 1);
267-
const std::string value = env.GetValue(key.c_str(), "");
268-
configMap[layer][paramName] = value;
269-
}
270-
}
271-
}
272-
return configMap;
273-
}
274-
275-
void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager)
276-
{
277-
LOG(info) << " Adding generic detector from file " << filename;
278-
// If the filename starts with ccdb: then take the file from the ccdb
279-
if (filename.rfind("ccdb:", 0) == 0) {
280-
std::string ccdbPath = filename.substr(5); // remove "ccdb:" prefix
281-
if (ccdbManager == nullptr) {
282-
LOG(fatal) << "CCDB manager is null, cannot retrieve file " << ccdbPath;
283-
return;
284-
}
285-
const std::string outPath = "/tmp/DetGeo/";
286-
filename = Form("%s/%s/snapshot.root", outPath.c_str(), ccdbPath.c_str());
287-
std::ifstream checkFile(filename); // Check if file already exists
288-
if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB
289-
LOG(info) << " --- CCDB source detected for detector geometry " << filename;
290-
std::map<std::string, std::string> metadata;
291-
ccdbManager->getCCDBAccessor().retrieveBlob(ccdbPath, outPath, metadata, 1);
292-
// Add CCDB handling logic here if needed
293-
LOG(info) << " --- Now retrieving geometry configuration from CCDB to: " << filename;
294-
} else { // File exists, proceed to load
295-
LOG(info) << " --- Geometry configuration file already exists: " << filename << ". Skipping download.";
296-
checkFile.close();
297-
}
298-
AddGenericDetector(filename, nullptr);
299-
return;
300-
}
301-
302-
std::map<std::string, std::map<std::string, std::string>> configMap = parseTEnvConfiguration(filename);
303-
// Layers
304-
for (const auto& layer : configMap) {
305-
LOG(info) << " Reading layer " << layer.first;
306-
const float r = std::stof(layer.second.at("r"));
307-
LOG(info) << " Layer " << layer.first << " has radius " << r;
308-
const float z = std::stof(layer.second.at("z"));
309-
const float x0 = std::stof(layer.second.at("x0"));
310-
const float xrho = std::stof(layer.second.at("xrho"));
311-
const float resRPhi = std::stof(layer.second.at("resRPhi"));
312-
const float resZ = std::stof(layer.second.at("resZ"));
313-
const float eff = std::stof(layer.second.at("eff"));
314-
const int type = std::stoi(layer.second.at("type"));
315-
const std::string deadPhiRegions = layer.second.at("deadPhiRegions");
327+
const float r = configMap.getFloatValue(layer, "r");
328+
LOG(info) << " Layer " << layer << " has radius " << r;
329+
const float z = configMap.getFloatValue(layer, "z");
330+
const float x0 = configMap.getFloatValue(layer, "x0");
331+
const float xrho = configMap.getFloatValue(layer, "xrho");
332+
const float resRPhi = configMap.getFloatValue(layer, "resRPhi");
333+
const float resZ = configMap.getFloatValue(layer, "resZ");
334+
const float eff = configMap.getFloatValue(layer, "eff");
335+
const int type = configMap.getIntValue(layer, "type");
336+
const std::string deadPhiRegions = configMap.getValue(layer, "deadPhiRegions");
316337

317338
// 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);
318-
LOG(info) << " Adding layer " << layer.first << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
339+
LOG(info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
319340

320-
DetLayer* addedLayer = AddLayer(layer.first.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
341+
DetLayer* addedLayer = AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
321342
if (!deadPhiRegions.empty()) { // Taking it as ccdb path or local file
322343
// Check if it begins with ccdb:
323344
if (std::string(deadPhiRegions).rfind("ccdb:", 0) == 0) {
@@ -340,7 +361,7 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
340361
addedLayer->setDeadPhiRegions(g);
341362
}
342363
} else {
343-
LOG(debug) << " No dead phi regions for layer " << layer.first;
364+
LOG(debug) << " No dead phi regions for layer " << layer;
344365
}
345366
}
346367
}

ALICE3/Core/FastTracker.h

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include "DetLayer.h"
1616

1717
#include <CCDB/BasicCCDBManager.h>
18+
#include <Framework/InitContext.h>
19+
#include <Framework/Logger.h>
1820
#include <ReconstructionDataFormats/Track.h>
1921

20-
#include <fairlogger/Logger.h>
21-
2222
#include <map>
2323
#include <string>
2424
#include <vector>
@@ -28,6 +28,54 @@ namespace o2
2828
namespace fastsim
2929
{
3030

31+
class GeometryContainer
32+
{
33+
public:
34+
GeometryContainer() = default;
35+
virtual ~GeometryContainer() = default;
36+
37+
void init(o2::framework::InitContext& initContext);
38+
39+
/**
40+
* @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
41+
* @param filename Path to the TEnv configuration file
42+
* @param layers Vector to store the order of the layers as they appear in the file
43+
* @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
44+
*/
45+
static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string filename, std::vector<std::string>& layers);
46+
47+
// A container for the geometry info
48+
struct GeometryEntry {
49+
// Default constructor
50+
GeometryEntry() = default;
51+
explicit GeometryEntry(std::string filename) : name(filename)
52+
{
53+
mConfigurations = GeometryContainer::parseTEnvConfiguration(filename, layerNames);
54+
}
55+
std::map<std::string, std::map<std::string, std::string>> getConfigurations() const { return mConfigurations; }
56+
std::map<std::string, std::string> getConfiguration(const std::string& layerName) const;
57+
std::vector<std::string> getLayerNames() const { return layerNames; }
58+
std::string getValue(const std::string& layerName, const std::string& key, bool require = true) const;
59+
float getFloatValue(const std::string& layerName, const std::string& key) const { return std::stof(getValue(layerName, key)); }
60+
int getIntValue(const std::string& layerName, const std::string& key) const { return std::stoi(getValue(layerName, key)); }
61+
62+
private:
63+
std::string name; // Filename of the geometry
64+
std::map<std::string, std::map<std::string, std::string>> mConfigurations;
65+
std::vector<std::string> layerNames; // Ordered names of the layers
66+
};
67+
68+
void addEntry(const std::string& filename) { entries.emplace_back(filename); }
69+
const std::vector<GeometryEntry>& getEntries() const { return entries; }
70+
const GeometryEntry& getEntry(const int id) const { return entries.at(id); }
71+
std::map<std::string, std::map<std::string, std::string>> getConfigurations(const int id) const { return entries.at(id).getConfigurations(); }
72+
std::map<std::string, std::string> getConfiguration(const int id, const std::string& layerName) const { return entries.at(id).getConfiguration(layerName); }
73+
int getNumberOfConfigurations() const { return entries.size(); }
74+
75+
private:
76+
std::vector<GeometryEntry> entries;
77+
};
78+
3179
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
3280

3381
// this class implements a synthetic smearer that allows
@@ -70,24 +118,16 @@ class FastTracker
70118
void AddSiliconALICE3(float scaleX0VD, std::vector<float> pixelResolution);
71119
void AddTPC(float phiResMean, float zResMean);
72120

73-
/**
74-
* @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
75-
* @param filename Path to the TEnv configuration file
76-
* @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
77-
*/
78-
std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string filename);
79-
80121
/**
81122
* @brief Adds a generic detector configuration from the specified file.
82123
*
83124
* This function loads and integrates a detector configuration into the tracker
84125
* using the provided filename. The file should contain the necessary parameters
85126
* and settings for the detector to be added.
86127
*
87-
* @param filename Path to the configuration file describing the detector.
88-
* @param ccdbManager Pointer to a BasicCCDBManager instance for database access (if needed).
128+
* @param configMap Configuration map describing the detector.
89129
*/
90-
void AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
130+
void AddGenericDetector(GeometryContainer::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
91131

92132
void Print();
93133

ALICE3/Core/FastTrackerLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#pragma link off all classes;
1717
#pragma link off all functions;
1818

19+
#pragma link C++ class o2::fastsim::GeometryContainer + ;
1920
#pragma link C++ class o2::fastsim::FastTracker + ;
2021
#pragma link C++ class o2::fastsim::DelphesO2LutWriter + ;
2122

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
# All rights not expressly granted are reserved.
4+
#
5+
# This software is distributed under the terms of the GNU General Public
6+
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
#
8+
# In applying this license CERN does not waive the privileges and immunities
9+
# granted to it by virtue of its status as an Intergovernmental Organization
10+
# or submit itself to any jurisdiction.
11+
12+
install(FILES a3geo.ini
13+
a3geometry_v2.ini
14+
a3geometry_v4.ini
15+
PERMISSIONS GROUP_READ GROUP_EXECUTE OWNER_EXECUTE OWNER_WRITE OWNER_READ WORLD_EXECUTE WORLD_READ
16+
DESTINATION share/alice3/)

ALICE3/TableProducer/OTF/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ o2physics_add_dpl_workflow(on-the-fly-tracker-pid
2828
SOURCES onTheFlyTrackerPid.cxx
2929
PUBLIC_LINK_LIBRARIES O2::Framework O2::DetectorsBase O2Physics::AnalysisCore O2::ReconstructionDataFormats O2::DetectorsCommonDataFormats O2Physics::ALICE3Core
3030
COMPONENT_NAME Analysis)
31+
32+
o2physics_add_dpl_workflow(on-the-fly-detector-geometry-provider
33+
SOURCES onTheFlyDetectorGeometryProvider.cxx
34+
PUBLIC_LINK_LIBRARIES O2::Framework O2Physics::AnalysisCore O2Physics::ALICE3Core O2Physics::FastTracker
35+
COMPONENT_NAME Analysis)

0 commit comments

Comments
 (0)