Skip to content

Commit 59933dc

Browse files
authored
[ALICE3] Add root writers for LUTs (#18406)
1 parent c1c4b5d commit 59933dc

3 files changed

Lines changed: 286 additions & 1 deletion

File tree

‎ALICE3/Core/CMakeLists.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ o2physics_add_library(ALICE3Core
1313
SOURCES TrackUtilities.cxx
1414
ConfigurationParser.cxx
1515
FlatLutEntry.cxx
16+
FlatLutRootWriter.cxx
1617
FlatTrackSmearer.cxx
1718
GeometryContainer.cxx
1819
PUBLIC_LINK_LIBRARIES O2::Framework
19-
O2Physics::AnalysisCore)
20+
O2Physics::AnalysisCore
21+
PRIVATE_LINK_LIBRARIES ROOT::Core
22+
ROOT::RIO
23+
ROOT::Tree)
2024

2125
o2physics_target_root_dictionary(ALICE3Core
2226
HEADERS TrackUtilities.h

‎ALICE3/Core/FlatLutRootWriter.cxx‎

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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+
#include "ALICE3/Core/FlatLutRootWriter.h"
13+
14+
#include <TFile.h>
15+
#include <TTree.h>
16+
17+
#include <algorithm>
18+
#include <string>
19+
#include <utility>
20+
21+
namespace o2::fastsim
22+
{
23+
24+
FlatLutRootWriter::FlatLutRootWriter(const lutHeader_t& header, bool covarianceStoresSigma)
25+
: mHeader(header),
26+
mCovarianceStoresSigma(covarianceStoresSigma)
27+
{
28+
}
29+
30+
void FlatLutRootWriter::reserve(std::size_t n)
31+
{
32+
mRows.reserve(n);
33+
}
34+
35+
void FlatLutRootWriter::addEntry(int entryIndex,
36+
int nchBin,
37+
int radBin,
38+
int etaBin,
39+
int ptBin,
40+
const lutEntry_t& entry)
41+
{
42+
FlatLutRootRow row;
43+
row.entryIndex = entryIndex;
44+
row.nchBin = nchBin;
45+
row.radBin = radBin;
46+
row.etaBin = etaBin;
47+
row.ptBin = ptBin;
48+
49+
row.nch = entry.nch;
50+
row.eta = entry.eta;
51+
row.pt = entry.pt;
52+
53+
row.valid = entry.valid;
54+
row.eff = entry.eff;
55+
row.eff2 = entry.eff2;
56+
row.itof = entry.itof;
57+
row.otof = entry.otof;
58+
59+
std::copy(entry.covm.begin(), entry.covm.end(), row.covm.begin());
60+
std::copy(entry.eigval.begin(), entry.eigval.end(), row.eigval.begin());
61+
row.eigvec = entry.eigvec;
62+
row.eiginv = entry.eiginv;
63+
64+
mRows.push_back(std::move(row));
65+
}
66+
67+
bool FlatLutRootWriter::writeToFile(const std::string& rootFileName) const
68+
{
69+
TFile output(rootFileName.c_str(), "RECREATE");
70+
if (output.IsZombie()) {
71+
return false;
72+
}
73+
74+
int version = mHeader.version;
75+
int pdg = mHeader.pdg;
76+
float mass = mHeader.mass;
77+
float field = mHeader.field;
78+
79+
int nch_nbins = mHeader.nchmap.nbins;
80+
float nch_min = mHeader.nchmap.min;
81+
float nch_max = mHeader.nchmap.max;
82+
bool nch_log = mHeader.nchmap.log;
83+
84+
int rad_nbins = mHeader.radmap.nbins;
85+
float rad_min = mHeader.radmap.min;
86+
float rad_max = mHeader.radmap.max;
87+
bool rad_log = mHeader.radmap.log;
88+
89+
int eta_nbins = mHeader.etamap.nbins;
90+
float eta_min = mHeader.etamap.min;
91+
float eta_max = mHeader.etamap.max;
92+
bool eta_log = mHeader.etamap.log;
93+
94+
int pt_nbins = mHeader.ptmap.nbins;
95+
float pt_min = mHeader.ptmap.min;
96+
float pt_max = mHeader.ptmap.max;
97+
bool pt_log = mHeader.ptmap.log;
98+
99+
bool covarianceStoresSigma = mCovarianceStoresSigma;
100+
101+
TTree headerTree("lutHeader", "LUT header");
102+
headerTree.Branch("version", &version, "version/I");
103+
headerTree.Branch("pdg", &pdg, "pdg/I");
104+
headerTree.Branch("mass", &mass, "mass/F");
105+
headerTree.Branch("field", &field, "field/F");
106+
107+
headerTree.Branch("nch_nbins", &nch_nbins, "nch_nbins/I");
108+
headerTree.Branch("nch_min", &nch_min, "nch_min/F");
109+
headerTree.Branch("nch_max", &nch_max, "nch_max/F");
110+
headerTree.Branch("nch_log", &nch_log, "nch_log/O");
111+
112+
headerTree.Branch("rad_nbins", &rad_nbins, "rad_nbins/I");
113+
headerTree.Branch("rad_min", &rad_min, "rad_min/F");
114+
headerTree.Branch("rad_max", &rad_max, "rad_max/F");
115+
headerTree.Branch("rad_log", &rad_log, "rad_log/O");
116+
117+
headerTree.Branch("eta_nbins", &eta_nbins, "eta_nbins/I");
118+
headerTree.Branch("eta_min", &eta_min, "eta_min/F");
119+
headerTree.Branch("eta_max", &eta_max, "eta_max/F");
120+
headerTree.Branch("eta_log", &eta_log, "eta_log/O");
121+
122+
headerTree.Branch("pt_nbins", &pt_nbins, "pt_nbins/I");
123+
headerTree.Branch("pt_min", &pt_min, "pt_min/F");
124+
headerTree.Branch("pt_max", &pt_max, "pt_max/F");
125+
headerTree.Branch("pt_log", &pt_log, "pt_log/O");
126+
127+
headerTree.Branch("covarianceStoresSigma", &covarianceStoresSigma, "covarianceStoresSigma/O");
128+
headerTree.Fill();
129+
130+
TTree entryTree("lutEntries", "LUT entries");
131+
132+
int entryIndex = -1;
133+
int nchBin = -1;
134+
int radBin = -1;
135+
int etaBin = -1;
136+
int ptBin = -1;
137+
138+
float nch = 0.f;
139+
float eta = 0.f;
140+
float pt = 0.f;
141+
142+
bool valid = false;
143+
float eff = 0.f;
144+
float eff2 = 0.f;
145+
float itof = 0.f;
146+
float otof = 0.f;
147+
148+
float covm[kNumCovarianceTerms] = {0.f};
149+
float eigval[kNumEigenModes] = {0.f};
150+
float eigvec[kNumEigenModes * kNumEigenModes] = {0.f};
151+
float eiginv[kNumEigenModes * kNumEigenModes] = {0.f};
152+
153+
entryTree.Branch("entryIndex", &entryIndex, "entryIndex/I");
154+
entryTree.Branch("nchBin", &nchBin, "nchBin/I");
155+
entryTree.Branch("radBin", &radBin, "radBin/I");
156+
entryTree.Branch("etaBin", &etaBin, "etaBin/I");
157+
entryTree.Branch("ptBin", &ptBin, "ptBin/I");
158+
159+
entryTree.Branch("nch", &nch, "nch/F");
160+
entryTree.Branch("eta", &eta, "eta/F");
161+
entryTree.Branch("pt", &pt, "pt/F");
162+
163+
entryTree.Branch("valid", &valid, "valid/O");
164+
entryTree.Branch("eff", &eff, "eff/F");
165+
entryTree.Branch("eff2", &eff2, "eff2/F");
166+
entryTree.Branch("itof", &itof, "itof/F");
167+
entryTree.Branch("otof", &otof, "otof/F");
168+
169+
entryTree.Branch("covm", covm, "covm[15]/F");
170+
entryTree.Branch("eigval", eigval, "eigval[5]/F");
171+
entryTree.Branch("eigvec", eigvec, "eigvec[25]/F");
172+
entryTree.Branch("eiginv", eiginv, "eiginv[25]/F");
173+
174+
for (const auto& row : mRows) {
175+
entryIndex = row.entryIndex;
176+
nchBin = row.nchBin;
177+
radBin = row.radBin;
178+
etaBin = row.etaBin;
179+
ptBin = row.ptBin;
180+
181+
nch = row.nch;
182+
eta = row.eta;
183+
pt = row.pt;
184+
185+
valid = row.valid;
186+
eff = row.eff;
187+
eff2 = row.eff2;
188+
itof = row.itof;
189+
otof = row.otof;
190+
191+
std::copy(row.covm.begin(), row.covm.end(), covm);
192+
std::copy(row.eigval.begin(), row.eigval.end(), eigval);
193+
for (int i = 0; i < kNumEigenModes; ++i) {
194+
for (int j = 0; j < kNumEigenModes; ++j) {
195+
eigvec[kNumEigenModes * i + j] = row.eigvec[i][j];
196+
eiginv[kNumEigenModes * i + j] = row.eiginv[i][j];
197+
}
198+
}
199+
200+
entryTree.Fill();
201+
}
202+
203+
headerTree.Write();
204+
entryTree.Write();
205+
output.Close();
206+
207+
return true;
208+
}
209+
210+
} // namespace o2::fastsim

‎ALICE3/Core/FlatLutRootWriter.h‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
#ifndef ALICE3_CORE_FLATLUTROOTWRITER_H_
13+
#define ALICE3_CORE_FLATLUTROOTWRITER_H_
14+
15+
#include "ALICE3/Core/FlatLutEntry.h"
16+
17+
#include <array>
18+
#include <cstddef>
19+
#include <string>
20+
#include <vector>
21+
22+
namespace o2::fastsim
23+
{
24+
25+
struct FlatLutRootRow {
26+
int entryIndex = -1;
27+
int nchBin = -1;
28+
int radBin = -1;
29+
int etaBin = -1;
30+
int ptBin = -1;
31+
32+
float nch = 0.f;
33+
float eta = 0.f;
34+
float pt = 0.f;
35+
36+
bool valid = false;
37+
float eff = 0.f;
38+
float eff2 = 0.f;
39+
float itof = 0.f;
40+
float otof = 0.f;
41+
42+
std::array<float, kNumCovarianceTerms> covm{};
43+
std::array<float, kNumEigenModes> eigval{};
44+
EigenMatrix eigvec{};
45+
EigenMatrix eiginv{};
46+
};
47+
48+
class FlatLutRootWriter
49+
{
50+
public:
51+
FlatLutRootWriter(const lutHeader_t& header, bool covarianceStoresSigma);
52+
53+
void reserve(std::size_t n);
54+
void addEntry(int entryIndex,
55+
int nchBin,
56+
int radBin,
57+
int etaBin,
58+
int ptBin,
59+
const lutEntry_t& entry);
60+
61+
bool writeToFile(const std::string& rootFileName) const;
62+
63+
private:
64+
lutHeader_t mHeader;
65+
bool mCovarianceStoresSigma = false;
66+
std::vector<FlatLutRootRow> mRows;
67+
};
68+
69+
} // namespace o2::fastsim
70+
71+
#endif // ALICE3_CORE_FLATLUTROOTWRITER_H_

0 commit comments

Comments
 (0)