Skip to content

Commit e2c86f5

Browse files
committed
Add A3 geo provider
1 parent 778a327 commit e2c86f5

File tree

6 files changed

+185
-39
lines changed

6 files changed

+185
-39
lines changed

ALICE3/Core/FastTracker.cxx

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
#include "FastTracker.h"
1313

14+
#include "Common/Core/TableHelper.h"
15+
1416
#include "ReconstructionDataFormats/TrackParametrization.h"
1517

16-
#include "TMath.h"
17-
#include "TMatrixD.h"
18-
#include "TMatrixDSymEigen.h"
19-
#include "TRandom.h"
20-
#include <TEnv.h>
21-
#include <THashList.h>
18+
#include <TMath.h>
19+
#include <TMatrixD.h>
20+
#include <TMatrixDSymEigen.h>
2221
#include <TObject.h>
22+
#include <TRandom.h>
2323

2424
#include <fstream>
2525
#include <map>
@@ -31,6 +31,21 @@ namespace o2
3131
namespace fastsim
3232
{
3333

34+
void GeometryContainer::init(o2::framework::InitContext& initContext)
35+
{
36+
std::vector<std::string> detectorConfiguration;
37+
const bool found = common::core::getTaskOptionValue(initContext, "on-the-fly-detector-geometry-provider", "detectorConfiguration", detectorConfiguration, false);
38+
if (!found) {
39+
LOG(fatal) << "Could not retrieve detector configuration from OnTheFlyDetectorGeometryProvider task.";
40+
return;
41+
}
42+
LOG(info) << "Size of detector configuration: " << detectorConfiguration.size();
43+
for (const auto& configFile : detectorConfiguration) {
44+
LOG(info) << "Detector geometry configuration file used: " << configFile;
45+
addEntry(configFile);
46+
}
47+
}
48+
3449
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
3550

3651
DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
@@ -238,38 +253,7 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
238253

239254
std::map<std::string, std::map<std::string, std::string>> FastTracker::parseTEnvConfiguration(std::string filename)
240255
{
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";
251-
continue;
252-
}
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();
259-
260-
// Layers
261-
for (const auto& layer : layers) {
262-
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;
256+
return GeometryContainer::parseTEnvConfiguration(filename);
273257
}
274258

275259
void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager)

ALICE3/Core/FastTracker.h

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
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>
22+
#include <TEnv.h>
23+
#include <THashList.h>
24+
#include <TObject.h>
2125

2226
#include <map>
2327
#include <string>
@@ -28,6 +32,74 @@ namespace o2
2832
namespace fastsim
2933
{
3034

35+
class GeometryContainer
36+
{
37+
public:
38+
GeometryContainer() = default;
39+
virtual ~GeometryContainer() = default;
40+
41+
void init(o2::framework::InitContext& initContext);
42+
43+
/**
44+
* @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
45+
* @param filename Path to the TEnv configuration file
46+
* @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
47+
*/
48+
static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string filename)
49+
{
50+
std::map<std::string, std::map<std::string, std::string>> configMap;
51+
TEnv env(filename.c_str());
52+
THashList* table = env.GetTable();
53+
std::vector<std::string> layers;
54+
for (int i = 0; i < table->GetEntries(); ++i) {
55+
const std::string key = table->At(i)->GetName();
56+
// key should contain exactly one dot
57+
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
58+
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
59+
continue;
60+
}
61+
const std::string firstPart = key.substr(0, key.find('.'));
62+
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
63+
layers.push_back(firstPart);
64+
}
65+
}
66+
env.Print();
67+
// Layers
68+
for (const auto& layer : layers) {
69+
LOG(info) << " Reading layer " << layer;
70+
for (int i = 0; i < table->GetEntries(); ++i) {
71+
const std::string key = table->At(i)->GetName();
72+
if (key.find(layer + ".") == 0) {
73+
const std::string paramName = key.substr(key.find('.') + 1);
74+
const std::string value = env.GetValue(key.c_str(), "");
75+
configMap[layer][paramName] = value;
76+
}
77+
}
78+
}
79+
return configMap;
80+
}
81+
struct GeometryEntry {
82+
// Default constructor
83+
GeometryEntry() = default;
84+
explicit GeometryEntry(std::string filename) : name(filename)
85+
{
86+
mConfigurations = GeometryContainer::parseTEnvConfiguration(filename);
87+
}
88+
89+
private:
90+
std::string name; // Filename of the geometry
91+
std::map<std::string, std::map<std::string, std::string>> mConfigurations;
92+
};
93+
94+
void addEntry(const std::string& filename)
95+
{
96+
entries.emplace_back(filename);
97+
}
98+
99+
private:
100+
std::vector<GeometryEntry> entries;
101+
};
102+
31103
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
32104

33105
// this class implements a synthetic smearer that allows

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

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)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
/// \file onTheFlyDetectorGeometryProvider.cxx
13+
///
14+
/// \brief Reader and and provider of the detector geometry for on-the-fly simulation
15+
///
16+
/// \author Nicolò Jacazio <nicolo.jacazio@cern.ch>, Universita del Piemonte Orientale (IT)
17+
///
18+
19+
#include "ALICE3/Core/FastTracker.h"
20+
21+
#include <CCDB/BasicCCDBManager.h>
22+
#include <Framework/AnalysisTask.h>
23+
#include <Framework/runDataProcessing.h>
24+
25+
#include <string>
26+
#include <vector>
27+
28+
struct OnTheFlyDetectorGeometryProvider {
29+
30+
o2::framework::Configurable<std::vector<std::string>> detectorConfiguration{"detectorConfiguration",
31+
std::vector<std::string>{"a3geo.ini"},
32+
"Paths of the detector geometry configuration files"};
33+
void init(o2::framework::InitContext&)
34+
{
35+
// ccdb->setURL("http://alice-ccdb.cern.ch");
36+
// ccdb->setTimestamp(-1);
37+
}
38+
void run(o2::framework::ProcessingContext& pc)
39+
{
40+
o2::fastsim::GeometryContainer geometryContainer; // Checking that the geometry files can be accessed and loaded
41+
LOG(info) << "On-the-fly detector geometry provider running.";
42+
if (detectorConfiguration.value.empty()) {
43+
LOG(fatal) << "No detector configuration files provided.";
44+
return;
45+
}
46+
for (const auto& configFile : detectorConfiguration.value) {
47+
LOG(info) << "Loading detector geometry from configuration file: " << configFile;
48+
geometryContainer.addEntry(configFile);
49+
}
50+
pc.services().get<o2::framework::ControlService>().endOfStream();
51+
pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me);
52+
}
53+
};
54+
55+
// #define VERIFY_ALICE3
56+
#ifdef VERIFY_ALICE3
57+
struct OnTheFlyDetectorGeometryUser {
58+
void init(o2::framework::InitContext& initContext)
59+
{
60+
o2::fastsim::GeometryContainer geometryContainer; // Checking that the configuration can be inherited
61+
geometryContainer.init(initContext);
62+
}
63+
void run(o2::framework::ProcessingContext& pc)
64+
{
65+
pc.services().get<o2::framework::ControlService>().endOfStream();
66+
pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me);
67+
}
68+
};
69+
#endif
70+
71+
o2::framework::WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& cfgc)
72+
{
73+
o2::framework::WorkflowSpec spec;
74+
spec.push_back(adaptAnalysisTask<OnTheFlyDetectorGeometryProvider>(cfgc));
75+
#ifdef VERIFY_ALICE3
76+
spec.push_back(adaptAnalysisTask<OnTheFlyDetectorGeometryUser>(cfgc));
77+
#endif
78+
return spec;
79+
}

Common/Core/TableHelper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <Framework/RunningWorkflowInfo.h>
2626

2727
#include <string>
28+
#include <vector>
2829

2930
namespace o2::common::core
3031
{
@@ -89,6 +90,10 @@ bool getTaskOptionValue(o2::framework::InitContext& initContext, const std::stri
8990
value = option.defaultValue.get<ValueType>();
9091
if (verbose) {
9192
if constexpr (!std::is_same_v<ValueType, o2::framework::LabeledArray<float>>) {
93+
LOG(info) << " Found option '" << optName << " of type LabeledArray<float>";
94+
} else if constexpr (!std::is_same_v<ValueType, std::vector<std::string>>) {
95+
LOG(info) << " Found option '" << optName << " of type vector<string>";
96+
} else {
9297
LOG(info) << " Found option '" << optName << "' with value '" << value << "'";
9398
}
9499
found = true;

0 commit comments

Comments
 (0)