Skip to content

Commit cc03d3d

Browse files
authored
Add files via upload
1 parent e0c18b0 commit cc03d3d

2 files changed

Lines changed: 279 additions & 0 deletions

File tree

‎ALICE3/Core/FlatLutRootWriter.cxx‎

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

‎ALICE3/Core/FlatLutRootWriter.h‎

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

0 commit comments

Comments
 (0)