|
| 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 |
0 commit comments