Project
Loading...
Searching...
No Matches
TPCMShapeCorrection.cxx
Go to the documentation of this file.
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
16
18#include <TFile.h>
19#include <TTree.h>
20#include "Framework/Logger.h"
21
22using namespace o2::tpc;
23
24void TPCMShapeCorrection::dumpToFile(const char* file, const char* name)
25{
26 TFile out(file, "RECREATE");
27 TTree tree(name, name);
28 tree.SetAutoSave(0);
29 tree.Branch("TPCMShapeCorrection", this);
30 tree.Fill();
31 out.WriteObject(&tree, name);
32}
33
34void TPCMShapeCorrection::dumpToFileSlices(const char* file, const char* name, int nSlices)
35{
36 const int nPotentials = mMShapes.mTimeMS.size();
37 const int nValuesPerSlice = std::round(nPotentials / float(nSlices) + 0.5);
38 for (int i = 0; i < nSlices; ++i) {
39 TPCMShapeCorrection corr = *this;
40 const int idx = i * nValuesPerSlice;
41 const int nOffsStart = (i == 0) ? 0 : 1;
42 const size_t idxStart = idx - nOffsStart;
43 const int nOffsEnd = (i == nSlices - 1) ? 0 : 1;
44 int idxEnd = (idx + nValuesPerSlice + 2 * nOffsEnd);
45 idxEnd = std::clamp(idxEnd, 0, nPotentials);
46
47 corr.mMShapes.mTimeMS = std::vector<double>(mMShapes.mTimeMS.begin() + idxStart, mMShapes.mTimeMS.begin() + idxEnd);
48 corr.mMShapes.mBoundaryPotentialIFC = std::vector<BoundaryPotentialIFC>(mMShapes.mBoundaryPotentialIFC.begin() + idxStart, mMShapes.mBoundaryPotentialIFC.begin() + idxEnd);
49
50 long tsCCDBStart = corr.mMShapes.mTimeMS[nOffsStart];
51 if (i == 0) {
52 tsCCDBStart -= 2. * mMaxDeltaTimeMS;
53 }
54
55 long tsCCDBEnd = corr.mMShapes.mTimeMS[corr.mMShapes.mTimeMS.size() - 1 - nOffsEnd];
56 // add additional validation offset for last object
57 if (i == nSlices - 1) {
58 tsCCDBEnd += 2. * mMaxDeltaTimeMS;
59 }
60 const std::string fileOut = fmt::format("{}_{}_{}_{}.root", file, i, tsCCDBStart, tsCCDBEnd);
61 corr.dumpToFile(fileOut.data(), name);
62 }
63}
64
65void TPCMShapeCorrection::loadFromFile(const char* inpf, const char* name)
66{
67 TFile out(inpf, "READ");
68 TTree* tree = (TTree*)out.Get(name);
70}
71
72void TPCMShapeCorrection::setFromTree(TTree& tpcMShapeTree)
73{
74 TPCMShapeCorrection* mshapeTmp = this;
75 tpcMShapeTree.SetBranchAddress("TPCMShapeCorrection", &mshapeTmp);
76 const int entries = tpcMShapeTree.GetEntries();
77 if (entries > 0) {
78 tpcMShapeTree.GetEntry(0);
79 } else {
80 LOGP(error, "TPCMShapeCorrection not found in input file");
81 }
82 tpcMShapeTree.SetBranchAddress("TPCMShapeCorrection", nullptr);
83}
84
86{
87 const auto& time = mMShapes.mTimeMS;
88 // find closest stored M-Shape
89 const auto lower = std::lower_bound(time.begin(), time.end(), timestamp);
90 const int idx = std::distance(time.begin(), lower);
91 if ((idx > 0) && (idx < time.size())) {
92 // if idx > 0 check preceeding value
93 double diff1 = std::abs(timestamp - *lower);
94 double diff2 = std::abs(timestamp - *(lower - 1));
95 if (diff2 < diff1) {
96 if (diff2 < mMaxDeltaTimeMS) {
97 return mMShapes.mBoundaryPotentialIFC[idx - 1];
98 }
99 } else {
100 if (diff1 < mMaxDeltaTimeMS) {
101 return mMShapes.mBoundaryPotentialIFC[idx];
102 }
103 }
104 }
105 return BoundaryPotentialIFC{};
106}
int16_t time
Definition RawEventData.h:4
int32_t i
void loadFromFile(const char *inpf, const char *name)
void dumpToFileSlices(const char *file, const char *name, int nSlices)
void dumpToFile(const char *file, const char *name)
BoundaryPotentialIFC getBoundaryPotential(const double timestamp) const
void setFromTree(TTree &tpcMShapeTree)
set this object from input tree
GLuint const GLchar * name
Definition glcorearb.h:781
Global TPC definitions and constants.
Definition SimTraits.h:167
arbitrary boundary potential at the IFC
std::vector< BoundaryPotentialIFC > mBoundaryPotentialIFC
definition of boundary potential
std::vector< double > mTimeMS
time of the boundary potential
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))