Project
Loading...
Searching...
No Matches
ResidualAggregator.h
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
15
16#ifndef O2_TPC_RESIDUALAGGREGATOR_H
17#define O2_TPC_RESIDUALAGGREGATOR_H
18
22#include "DataFormatsTPC/Defs.h"
26#include <vector>
27#include <array>
28#include <string>
29
30#include "TFile.h"
31#include "TTree.h"
32
33namespace o2
34{
35namespace tpc
36{
37
39
41
42 ResidualsContainer() = default;
44 ResidualsContainer(const ResidualsContainer&); // no copying allowed, this will yield an error message
47
48 void init(const TrackResiduals* residualsEngine, std::string outputDir, bool wFile, bool wBinnedResid, bool wUnbinnedResid, bool wTrackData, bool wTrackDataMC, int autosave, int compression, long orbitResetTime);
50 uint64_t getNEntries() const { return nResidualsTotal; }
51
52 void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const DetInfoResid> detInfoRes, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const gsl::span<const o2::tpc::TrackDataMC>* trkDataMCIn, const o2::ctp::LumiInfo* lumiInput);
53 void merge(ResidualsContainer* prev);
54 void print();
55 void writeToFile(bool closeFileAfterwards);
56
58 std::array<std::vector<TrackResiduals::LocalResid>, SECTORSPERSIDE * SIDES> residuals{};
59 std::array<std::vector<TrackResiduals::LocalResid>*, SECTORSPERSIDE * SIDES> residualsPtr{};
60 std::array<std::vector<TrackResiduals::VoxStats>, SECTORSPERSIDE * SIDES> stats{};
61 std::array<std::vector<TrackResiduals::VoxStats>*, SECTORSPERSIDE * SIDES> statsPtr{};
62 std::vector<uint32_t> tfOrbits, *tfOrbitsPtr{&tfOrbits};
65 std::vector<o2::ctp::LumiInfo> lumi, *lumiPtr{&lumi};
66 std::vector<UnbinnedResid> unbinnedRes, *unbinnedResPtr{&unbinnedRes};
67 std::vector<DetInfoResid> detInfoUnbRes, *detInfoUnbResPtr{&detInfoUnbRes};
68 std::vector<TrackData> trkData, *trkDataPtr{&trkData};
69 std::vector<TrackDataMC> trkDataMC, *trkDataMCPtr{&trkDataMC};
70 std::vector<TrackDataCompact> trackInfo, *trackInfoPtr{&trackInfo};
72 uint64_t timeMS;
73
74 std::string fileName{"o2tpc_residuals"};
75 std::unique_ptr<TFile> fileOut{nullptr};
76 std::unique_ptr<TTree> treeOutResidualsUnbinned{nullptr};
77 std::unique_ptr<TTree> treeOutTrackData{nullptr};
78 std::unique_ptr<TTree> treeOutResiduals{nullptr};
79 std::unique_ptr<TTree> treeOutStats{nullptr};
80 std::unique_ptr<TTree> treeOutRecords{nullptr};
81
82 // settings
83 bool writeToRootFile{true};
84 bool writeBinnedResid{false};
86 bool writeTrackData{false};
87 bool writeTrackDataMC{false};
89
90 // additional info
91 long orbitReset{0};
92 uint32_t firstTForbit{0};
95 uint64_t nResidualsTotal{0};
96 float TPCVDriftRef{-1.};
98
100};
101
102class ResidualAggregator final : public o2::calibration::TimeSlotCalibration<ResidualsContainer>
103{
105
106 public:
107 ResidualAggregator(size_t nMin = 1000) : mMinEntries(nMin) { mTrackResiduals.init(); }
108 ~ResidualAggregator() final;
109
110 void setDataTakingContext(o2::framework::DataTakingContext& dtc) { mDataTakingContext = dtc; }
111 void setOrbitResetTime(long t) { mOrbitResetTime = t; }
113 void setOutputDir(std::string dir)
114 {
115 mOutputDir = dir;
116 mWriteOutput = true;
117 }
118 void setMetaFileOutputDir(std::string dir)
119 {
120 mMetaOutputDir = dir;
121 mStoreMetaData = true;
122 }
123 void setLHCPeriod(std::string period) { mLHCPeriod = period; }
124 void setWriteBinnedResiduals(bool f) { mWriteBinnedResiduals = f; }
125 void setWriteUnbinnedResiduals(bool f) { mWriteUnbinnedResiduals = f; }
126 void setWriteTrackData(bool f) { mWriteTrackData = f; }
127 void setWriteTrackDataMC(bool f) { mWriteTrackDataMC = f; }
128 void setAutosaveInterval(int n) { mAutosaveInterval = n; }
129 void setCompression(int c) { mCompressionSetting = c; }
130
131 bool hasEnoughData(const Slot& slot) const final;
132 void initOutput() final;
133 void finalizeSlot(Slot& slot) final;
134 Slot& emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final;
135
136 private:
137 o2::framework::DataTakingContext mDataTakingContext{};
138 TrackResiduals mTrackResiduals;
139 std::string mOutputDir{"./"};
140 std::string mMetaOutputDir{"none"};
141 std::string mLHCPeriod{""};
142 bool mStoreMetaData{false};
143 bool mWriteOutput{false};
144 bool mWriteBinnedResiduals{false};
145 bool mWriteUnbinnedResiduals{false};
146 bool mWriteTrackData{false};
147 bool mWriteTrackDataMC{false};
148 int mAutosaveInterval{0};
149 int mCompressionSetting{101};
150 size_t mMinEntries;
151 long mOrbitResetTime;
152 float mTPCVDriftRef = -1.;
153 float mTPCDriftTimeOffsetRef = 0.;
154
155 ClassDefOverride(ResidualAggregator, 4);
156};
157
158} // namespace tpc
159} // namespace o2
160
161#endif // O2_TPC_RESIDUALAGGREGATOR_H
uint64_t TFType
uint32_t c
Definition RawData.h:2
Definition of the TrackResiduals class.
Slot & emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final
bool hasEnoughData(const Slot &slot) const final
void setOutputDir(std::string dir)
void setLHCPeriod(std::string period)
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void finalizeSlot(Slot &slot) final
void setDataTakingContext(o2::framework::DataTakingContext &dtc)
void setMetaFileOutputDir(std::string dir)
void init(bool doBinning=true)
GLdouble n
Definition glcorearb.h:1982
GLenum src
Definition glcorearb.h:1767
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
uint32_t TFType
Definition TimeSlot.h:29
constexpr TFType INFINITE_TF
Definition TimeSlot.h:30
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< TTree > treeOutResidualsUnbinned
std::vector< TrackDataCompact > * trackInfoPtr
allows to obtain track type for each unbinned residual downstream
long orbitReset
current orbit reset time in ms
std::array< std::vector< TrackResiduals::VoxStats > *, SECTORSPERSIDE *SIDES > statsPtr
std::vector< TrackData > * trkDataPtr
track data and cluster ranges
std::unique_ptr< TTree > treeOutRecords
float TPCVDriftRef
TPC nominal drift speed in cm/microseconds.
std::vector< TrackDataMC > * trkDataMCPtr
MC truth for the track data (MC only)
std::vector< uint32_t > sumBinnedResid
TFType lastSeenTF
the last TF which was added to this container
uint64_t timeMS
for each processed TF we store its absolute time in ms in the tree of unbinned residuals
bool writeTrackDataMC
flag, whether the MC truth of the seeding tracks should be written out
std::vector< DetInfoResid > * detInfoUnbResPtr
detector info associated to unbinned residuals which are sent to the aggregator
o2::calibration::TFType TFType
void fill(const o2::dataformats::TFIDInfo &ti, const gsl::span< const UnbinnedResid > resid, const gsl::span< const DetInfoResid > detInfoRes, const gsl::span< const o2::tpc::TrackDataCompact > trkRefsIn, const gsl::span< const o2::tpc::TrackData > *trkDataIn, const gsl::span< const o2::tpc::TrackDataMC > *trkDataMCIn, const o2::ctp::LumiInfo *lumiInput)
std::vector< UnbinnedResid > * unbinnedResPtr
unbinned residuals which are sent to the aggregator
std::vector< uint32_t > tfOrbits
ResidualsContainer & operator=(const ResidualsContainer &src)=delete
std::vector< uint32_t > * sumBinnedResidPtr
sum of binned residuals for each TF
std::vector< TrackDataMC > trkDataMC
uint32_t firstTForbit
stored for the first seen TF to allow conversion to time stamp
std::vector< o2::ctp::LumiInfo > * lumiPtr
luminosity information from CTP per TF
void init(const TrackResiduals *residualsEngine, std::string outputDir, bool wFile, bool wBinnedResid, bool wUnbinnedResid, bool wTrackData, bool wTrackDataMC, int autosave, int compression, long orbitResetTime)
std::array< std::vector< TrackResiduals::LocalResid > *, SECTORSPERSIDE *SIDES > residualsPtr
bool writeBinnedResid
flag, whether binned residuals should be written out
std::vector< o2::ctp::LumiInfo > lumi
bool writeTrackData
flag, whether full seeding track information should be written out
std::vector< TrackDataCompact > trackInfo
std::vector< uint32_t > * tfOrbitsPtr
first TF orbit
bool writeUnbinnedResiduals
flag, whether unbinned residuals should be written out
void writeToFile(bool closeFileAfterwards)
o2::ctp::LumiInfo lumiTF
for each processed TF we store the lumi information in the tree of unbinned residuals
std::array< std::vector< TrackResiduals::LocalResid >, SECTORSPERSIDE *SIDES > residuals
local (binned) residuals per sector
void merge(ResidualsContainer *prev)
std::vector< UnbinnedResid > unbinnedRes
float TPCDriftTimeOffsetRef
TPC nominal (e.g. at the start of run) drift time bias in cm/mus.
std::unique_ptr< TFile > fileOut
std::vector< uint32_t > sumUnbinnedResid
std::array< std::vector< TrackResiduals::VoxStats >, SECTORSPERSIDE *SIDES > stats
voxel statistics per sector
std::unique_ptr< TTree > treeOutStats
const TrackResiduals * trackResiduals
TFType firstSeenTF
the first TF which was added to this container
uint64_t nResidualsTotal
the total number of residuals for this container
std::vector< uint32_t > * sumUnbinnedResidPtr
sum of unbinned residuals for each TF
std::unique_ptr< TTree > treeOutResiduals
ClassDefNV(ResidualsContainer, 6)
int autosaveInterval
if > 0, then the output written to file for every n-th TF
std::vector< DetInfoResid > detInfoUnbRes
std::unique_ptr< TTree > treeOutTrackData
std::vector< TrackData > trkData
bool writeToRootFile
set to false to avoid that any output file is produced