Skip to content

Commit 28d3766

Browse files
committed
Merge branch 'new_geometry' of github.com:pkurash/AliceO2 into new_geometry
updated material properties
2 parents 996785b + 26ef75b commit 28d3766

63 files changed

Lines changed: 3188 additions & 497 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Common/SimConfig/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ o2_add_library(SimConfig
2121
src/InteractionDiamondParam.cxx
2222
src/GlobalProcessCutSimParam.cxx
2323
src/FluenceWeightCalculator.cxx
24+
src/G4ScoringMerger.cxx
2425
PUBLIC_LINK_LIBRARIES O2::CommonUtils
2526
O2::DetectorsCommonDataFormats O2::SimulationDataFormat
2627
FairRoot::Base Boost::program_options)

‎Common/SimConfig/include/SimConfig/FluenceWeightCalculator.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ class FluenceWeightCalculator
3131
static std::unique_ptr<TGraph> neutronG;
3232
static std::unique_ptr<TGraph> protonG;
3333
static std::unique_ptr<TGraph> pionG;
34+
static std::unique_ptr<TGraph> electronG;
3435
};
3536
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2019-2026 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+
#ifndef O2_SIMCONFIG_G4SCORINGMERGER_H
13+
#define O2_SIMCONFIG_G4SCORINGMERGER_H
14+
15+
#include <string>
16+
17+
namespace o2::conf
18+
{
19+
20+
/// Name of the Geant4 scoring dump written by one simulation worker
21+
std::string g4ScoringWorkerFileName(const std::string& meshName, int pid);
22+
23+
/// Sum the per-worker Geant4 scoring dumps <mesh>.worker<pid>.txt in a directory into <mesh>.txt.
24+
/// If expectedWorkers > 0, each mesh must have exactly that many dumps.
25+
/// Returns the number of merged meshes, or -1 if the worker files are inconsistent.
26+
int mergeG4ScoringDumps(const std::string& directory, int expectedWorkers = 0);
27+
28+
} // namespace o2::conf
29+
30+
#endif

‎Common/SimConfig/src/FluenceWeightCalculator.cxx‎

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@
1111

1212
#include "SimConfig/FluenceWeightCalculator.h"
1313
#include <TFile.h>
14+
#include <algorithm>
1415
#include <fstream>
1516
#include <sstream>
1617
#include <iostream>
1718

1819
std::unique_ptr<TGraph> FluenceWeightCalculator::neutronG;
1920
std::unique_ptr<TGraph> FluenceWeightCalculator::protonG;
2021
std::unique_ptr<TGraph> FluenceWeightCalculator::pionG;
22+
std::unique_ptr<TGraph> FluenceWeightCalculator::electronG;
23+
24+
namespace
25+
{
26+
// Damage weight at an energy clamped to the tabulated range
27+
double evalClamped(const TGraph& g, double kineticEnergy)
28+
{
29+
if (g.GetN() == 0) {
30+
return 0.;
31+
}
32+
const double e = std::clamp(kineticEnergy, g.GetX()[0], g.GetX()[g.GetN() - 1]);
33+
return g.Eval(e, nullptr, "S");
34+
}
35+
} // namespace
2136

2237
double FluenceWeightCalculator::GetWeight(const int pdg, const double kineticEnergy)
2338
{
@@ -27,19 +42,22 @@ double FluenceWeightCalculator::GetWeight(const int pdg, const double kineticEne
2742
std::cerr << "FluenceWeightCalculator not initialized\n";
2843
return 0.;
2944
}
30-
switch (std::abs(pdg)) {
31-
case 2112: {
32-
return neutronG->Eval(kineticEnergy, nullptr, "S");
33-
}
34-
case 2212: {
35-
return ((kineticEnergy > 1e-3) ? protonG->Eval(kineticEnergy, nullptr, "S") : 0.);
36-
}
37-
case 211: {
38-
return ((kineticEnergy > 10.) ? pionG->Eval(kineticEnergy, nullptr, "S") : 0.);
39-
}
40-
default:
41-
return 0.0;
45+
const int apdg = std::abs(pdg);
46+
if (pdg == 2112) {
47+
return evalClamped(*neutronG, kineticEnergy);
48+
}
49+
if (apdg == 11) {
50+
return electronG ? evalClamped(*electronG, kineticEnergy) : 0.;
51+
}
52+
// other (anti)baryons use the proton weights
53+
if (apdg >= 1000 && apdg < 10000) {
54+
return ((kineticEnergy > 1e-3) ? evalClamped(*protonG, kineticEnergy) : 0.);
55+
}
56+
// mesons use the pion weights
57+
if (apdg >= 100 && apdg < 1000) {
58+
return ((kineticEnergy > 10.) ? evalClamped(*pionG, kineticEnergy) : 0.);
4259
}
60+
return 0.;
4361
}
4462

4563
void FluenceWeightCalculator::InitWeights(const std::string& filename)
@@ -74,6 +92,13 @@ void FluenceWeightCalculator::InitWeights(const std::string& filename)
7492
return;
7593
}
7694
pionG->SetBit(TGraph::kIsSortedX);
95+
// electron weights are optional
96+
tmp = nullptr;
97+
inFile.GetObject("electronDW", tmp);
98+
electronG.reset(tmp ? static_cast<TGraph*>(tmp->Clone()) : nullptr);
99+
if (electronG) {
100+
electronG->SetBit(TGraph::kIsSortedX);
101+
}
77102
}
78103

79104
void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename)
@@ -89,6 +114,9 @@ void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename)
89114
pionG = std::make_unique<TGraph>();
90115
pionG->SetName("pionDW");
91116
auto pioN = 0;
117+
electronG = std::make_unique<TGraph>();
118+
electronG->SetName("electronDW");
119+
auto eleN = 0;
92120

93121
std::ifstream in(filename);
94122
if (!in.is_open()) {
@@ -127,12 +155,21 @@ void FluenceWeightCalculator::InitWeightsFromCSV(const std::string& filename)
127155
pionG->SetPoint(pioN++, e, w);
128156
break;
129157
}
158+
case 11: {
159+
electronG->SetPoint(eleN++, e, w);
160+
break;
161+
}
130162
default:;
131163
}
132164
}
165+
neutronG->Sort();
166+
protonG->Sort();
167+
pionG->Sort();
168+
electronG->Sort();
133169
auto fout = new TFile("rd50_niel.root", "recreate");
134170
neutronG->Write();
135171
protonG->Write();
136172
pionG->Write();
173+
electronG->Write();
137174
fout->Close();
138175
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2019-2026 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+
#include "SimConfig/G4ScoringMerger.h"
13+
#include <fairlogger/Logger.h>
14+
#include <filesystem>
15+
#include <fstream>
16+
#include <iomanip>
17+
#include <map>
18+
#include <regex>
19+
#include <sstream>
20+
#include <vector>
21+
22+
namespace o2::conf
23+
{
24+
25+
namespace
26+
{
27+
// One scorer block of a Geant4 mesh dump: its header lines and the summed rows
28+
struct ScorerBlock {
29+
std::vector<std::string> header;
30+
std::vector<std::string> keys; // "iZ,iPHI,iR" in file order
31+
std::vector<double> sum;
32+
std::vector<double> sum2;
33+
std::vector<long> entries;
34+
};
35+
36+
// Read one mesh dump into scorer blocks; returns false on a format error
37+
bool readDump(const std::string& fileName, std::vector<std::string>& meshHeader, std::vector<ScorerBlock>& blocks)
38+
{
39+
std::ifstream in(fileName);
40+
if (!in) {
41+
return false;
42+
}
43+
std::string line;
44+
ScorerBlock* current = nullptr;
45+
while (std::getline(in, line)) {
46+
if (line.rfind("# mesh name", 0) == 0) {
47+
meshHeader.push_back(line);
48+
} else if (line.rfind("# primitive scorer name", 0) == 0) {
49+
blocks.emplace_back();
50+
current = &blocks.back();
51+
current->header.push_back(line);
52+
} else if (line.rfind("#", 0) == 0) {
53+
if (!current) {
54+
return false;
55+
}
56+
current->header.push_back(line);
57+
} else if (!line.empty()) {
58+
if (!current) {
59+
return false;
60+
}
61+
// iZ, iPHI, iR, total, total^2, entries
62+
std::vector<std::string> fields;
63+
std::stringstream ss(line);
64+
std::string field;
65+
while (std::getline(ss, field, ',')) {
66+
fields.push_back(field);
67+
}
68+
if (fields.size() != 6) {
69+
return false;
70+
}
71+
current->keys.push_back(fields[0] + "," + fields[1] + "," + fields[2]);
72+
current->sum.push_back(std::stod(fields[3]));
73+
current->sum2.push_back(std::stod(fields[4]));
74+
current->entries.push_back(std::stol(fields[5]));
75+
}
76+
}
77+
return !blocks.empty();
78+
}
79+
} // namespace
80+
81+
std::string g4ScoringWorkerFileName(const std::string& meshName, int pid)
82+
{
83+
return meshName + ".worker" + std::to_string(pid) + ".txt";
84+
}
85+
86+
int mergeG4ScoringDumps(const std::string& directory, int expectedWorkers)
87+
{
88+
namespace fs = std::filesystem;
89+
const std::regex pattern(R"((.+)\.worker([0-9]+)\.txt)");
90+
std::map<std::string, std::vector<fs::path>> filesPerMesh;
91+
for (auto& entry : fs::directory_iterator(directory)) {
92+
std::smatch match;
93+
const auto name = entry.path().filename().string();
94+
if (entry.is_regular_file() && std::regex_match(name, match, pattern)) {
95+
filesPerMesh[match[1]].push_back(entry.path());
96+
}
97+
}
98+
99+
int merged = 0;
100+
for (auto& [mesh, files] : filesPerMesh) {
101+
if (expectedWorkers > 0 && static_cast<int>(files.size()) != expectedWorkers) {
102+
LOG(error) << "Found " << files.size() << " Geant4 scoring dumps for mesh " << mesh << " but expected " << expectedWorkers;
103+
return -1;
104+
}
105+
std::vector<std::string> meshHeader;
106+
std::vector<ScorerBlock> total;
107+
for (auto& file : files) {
108+
std::vector<std::string> header;
109+
std::vector<ScorerBlock> blocks;
110+
if (!readDump(file.string(), header, blocks)) {
111+
LOG(error) << "Cannot read Geant4 scoring dump " << file;
112+
return -1;
113+
}
114+
if (total.empty()) {
115+
meshHeader = header;
116+
total = std::move(blocks);
117+
continue;
118+
}
119+
if (blocks.size() != total.size()) {
120+
LOG(error) << "Geant4 scoring dump " << file << " has a different set of scorers";
121+
return -1;
122+
}
123+
for (size_t b = 0; b < blocks.size(); ++b) {
124+
if (blocks[b].header != total[b].header || blocks[b].keys != total[b].keys) {
125+
LOG(error) << "Geant4 scoring dump " << file << " does not match the mesh layout of the other workers";
126+
return -1;
127+
}
128+
for (size_t i = 0; i < blocks[b].keys.size(); ++i) {
129+
total[b].sum[i] += blocks[b].sum[i];
130+
total[b].sum2[i] += blocks[b].sum2[i];
131+
total[b].entries[i] += blocks[b].entries[i];
132+
}
133+
}
134+
}
135+
136+
const auto outName = (fs::path(directory) / (mesh + ".txt")).string();
137+
std::ofstream out(outName);
138+
out << std::setprecision(16);
139+
for (auto& line : meshHeader) {
140+
out << line << "\n";
141+
}
142+
for (auto& block : total) {
143+
for (auto& line : block.header) {
144+
out << line << "\n";
145+
}
146+
for (size_t i = 0; i < block.keys.size(); ++i) {
147+
out << block.keys[i] << "," << block.sum[i] << "," << block.sum2[i] << "," << block.entries[i] << "\n";
148+
}
149+
}
150+
LOG(info) << "Merged " << files.size() << " Geant4 scoring dumps into " << outName;
151+
++merged;
152+
}
153+
return merged;
154+
}
155+
156+
} // namespace o2::conf

‎Common/SimConfig/src/SimConfig.cxx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
#include "CommonUtils/NameConf.h"
1213
#include <SimConfig/SimConfig.h>
1314
#include <SimConfig/DetectorLists.h>
1415
#include <DetectorsCommonDataFormats/DetID.h>
@@ -69,7 +70,7 @@ void SimConfig::initOptions(boost::program_options::options_description& options
6970
"field", bpo::value<std::string>()->default_value("-5"), "L3 field rounded to kGauss, allowed values +-2,+-5 and 0; +-<intKGaus>U for uniform field; \"ccdb\" for taking it from CCDB ")("vertexMode", bpo::value<std::string>()->default_value("kDiamondParam"), "Where the beam-spot vertex should come from. Must be one of kNoVertex, kDiamondParam, kCCDB")(
7071
"nworkers,j", bpo::value<int>()->default_value(nsimworkersdefault), "number of parallel simulation workers (only for parallel mode)")(
7172
"noemptyevents", "only writes events with at least one hit")(
72-
"CCDBUrl", bpo::value<std::string>()->default_value("http://alice-ccdb.cern.ch"), "URL for CCDB to be used.")(
73+
"CCDBUrl", bpo::value<std::string>()->default_value(o2::base::NameConf::getCCDBServer()), "URL for CCDB to be used.")(
7374
"timestamp", bpo::value<uint64_t>(), "global timestamp value in ms (for anchoring) - default is now ... or beginning of run if ALICE run number was given")(
7475
"run", bpo::value<int>()->default_value(-1), "ALICE run number")(
7576
"asservice", bpo::value<bool>()->default_value(false), "run in service/server mode")(

‎Common/Utils/src/NameConf.cxx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "CommonUtils/NameConf.h"
1313
#include <fmt/format.h>
14+
#include <cstdlib>
1415
#include <memory>
1516

1617
O2ParamImpl(o2::base::NameConf);
@@ -111,10 +112,27 @@ std::string NameConf::getTFIDInfoFileName(const std::string_view prefix)
111112
return buildFileName(prefix, "_", "o2", TFIDINFO, ROOT_EXT_STRING, Instance().mDirTFIDINFO);
112113
}
113114

114-
// Default CCDB server
115+
// Default CCDB server.
116+
//
117+
// Precedence: an explicit NameConf.mCCDBServer (configKeyValues) wins; otherwise
118+
// ALICEO2_CCDB_PRODUCTION_HOST, then ALICEO2_CCDB_HOST, then the compiled-in
119+
// production server. The environment lets a build container reach CCDB through
120+
// a broker (CI's security-proxy) without every tool growing its own option --
121+
// the CCDB test suites, GRPTool and testTPCCalDet already read these names.
122+
// Unset, behaviour is unchanged.
115123
std::string NameConf::getCCDBServer()
116124
{
117-
return Instance().mCCDBServer;
125+
static const std::string kCompiledDefault = "http://alice-ccdb.cern.ch/"; // keep equal to mCCDBServer's initializer
126+
const auto& configured = Instance().mCCDBServer;
127+
if (configured != kCompiledDefault) {
128+
return configured;
129+
}
130+
for (const char* var : {"ALICEO2_CCDB_PRODUCTION_HOST", "ALICEO2_CCDB_HOST"}) {
131+
if (const char* host = std::getenv(var); host && *host) {
132+
return host;
133+
}
134+
}
135+
return configured;
118136
}
119137

120138
std::string NameConf::getConfigOutputFileName(const std::string& procName, const std::string& confName, bool json)

‎DataFormats/Detectors/TPC/include/DataFormatsTPC/Constants.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef AliceO2_TPC_Constants_H
1818
#define AliceO2_TPC_Constants_H
1919

20+
#include "GPUCommonDef.h"
21+
2022
namespace o2
2123
{
2224
namespace tpc
@@ -25,17 +27,17 @@ namespace constants
2527
{
2628

2729
// the number of sectors
28-
constexpr int MAXSECTOR = 36;
30+
GPUglobalconstexpr() int MAXSECTOR = 36;
2931

3032
// the number of global pad rows
3133
#if defined(GPUCA_STANDALONE) && defined(GPUCA_RUN2)
32-
constexpr int MAXGLOBALPADROW = 159; // Number of pad rows in Run 2, used for GPU TPC tests with Run 2 data
34+
GPUglobalconstexpr() int MAXGLOBALPADROW = 159; // Number of pad rows in Run 2, used for GPU TPC tests with Run 2 data
3335
#else
34-
constexpr int MAXGLOBALPADROW = 152; // Correct number of pad rows in Run 3
36+
GPUglobalconstexpr() int MAXGLOBALPADROW = 152; // Correct number of pad rows in Run 3
3537
#endif
3638

3739
// number of LHC bunch crossings per TPC time bin (40 MHz / 5 MHz)
38-
constexpr int LHCBCPERTIMEBIN = 8;
40+
GPUglobalconstexpr() int LHCBCPERTIMEBIN = 8;
3941
} // namespace constants
4042
} // namespace tpc
4143
} // namespace o2

0 commit comments

Comments
 (0)