|
| 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 CalibdEdxCorrection.h |
| 13 | +/// \author Thiago Badaró <thiago.saramela@usp.br> |
| 14 | + |
| 15 | +#ifndef ALICEO2_TPC_CALIBDEDXCORRECTION_H_ |
| 16 | +#define ALICEO2_TPC_CALIBDEDXCORRECTION_H_ |
| 17 | + |
| 18 | +#include "GPUCommonDef.h" |
| 19 | +#ifndef GPUCA_ALIGPUCODE |
| 20 | +#include <cstddef> |
| 21 | +#include <array> |
| 22 | +#include <string_view> |
| 23 | +#endif |
| 24 | + |
| 25 | +// o2 includes |
| 26 | +#include "DataFormatsTPC/Defs.h" |
| 27 | + |
| 28 | +namespace o2::tpc |
| 29 | +{ |
| 30 | + |
| 31 | +class CalibdEdxCorrection |
| 32 | +{ |
| 33 | + public: |
| 34 | + using Params = std::array<float, 6>; |
| 35 | +#if !defined(GPUCA_GPUCODE) |
| 36 | + CalibdEdxCorrection() |
| 37 | + { |
| 38 | + clear(); |
| 39 | + } |
| 40 | + CalibdEdxCorrection(std::string_view fileName) { loadFile(fileName); } |
| 41 | +#else |
| 42 | + CalibdEdxCorrection() CON_DEFAULT; |
| 43 | +#endif |
| 44 | + ~CalibdEdxCorrection() CON_DEFAULT; |
| 45 | + |
| 46 | + GPUd() float getCorrection(const StackID& stack, ChargeType charge, float z = 0, float tgl = 0) const |
| 47 | + { |
| 48 | + // by default return 1 if no correction was loaded |
| 49 | + if (mDims < 0) { |
| 50 | + return 1; |
| 51 | + } |
| 52 | + |
| 53 | + const auto& p = mParams[stackIndex(stack, charge)]; |
| 54 | + float corr = p[0]; |
| 55 | + |
| 56 | + if (mDims > 0) { |
| 57 | + corr += p[1] * z + p[2] * z * z; |
| 58 | + if (mDims > 1) { |
| 59 | + corr += p[3] * tgl + p[4] * z * tgl + p[5] * tgl * tgl; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return corr; |
| 64 | + } |
| 65 | + |
| 66 | +#if !defined(GPUCA_GPUCODE) |
| 67 | + float getChi2(const StackID& stack, ChargeType charge) const |
| 68 | + { |
| 69 | + return mChi2[stackIndex(stack, charge)]; |
| 70 | + } |
| 71 | + int getDims() const { return mDims; } |
| 72 | + |
| 73 | + void setParams(const StackID& stack, ChargeType charge, const Params& params) { mParams[stackIndex(stack, charge)] = params; } |
| 74 | + void setChi2(const StackID& stack, ChargeType charge, float chi2) { mChi2[stackIndex(stack, charge)] = chi2; } |
| 75 | + void setDims(int dims) { mDims = dims; } |
| 76 | + |
| 77 | + void clear(); |
| 78 | + |
| 79 | + void saveFile(std::string_view fileName) const; |
| 80 | + void loadFile(std::string_view fileName); |
| 81 | +#endif |
| 82 | + |
| 83 | + private: |
| 84 | + GPUd() static size_t stackIndex(const StackID& stack, ChargeType charge) |
| 85 | + { |
| 86 | + return static_cast<size_t>(stack.index() + charge * SECTORSPERSIDE * SIDES * GEMSTACKSPERSECTOR); |
| 87 | + } |
| 88 | + |
| 89 | + std::array<Params, 288> mParams{}; |
| 90 | + std::array<float, 288> mChi2{}; |
| 91 | + int mDims{-1}; ///< Fit dimension |
| 92 | +}; |
| 93 | + |
| 94 | +} // namespace o2::tpc |
| 95 | + |
| 96 | +#endif |
0 commit comments