12#ifndef TOF_CHANNEL_CALIBRATOR_H_
13#define TOF_CHANNEL_CALIBRATOR_H_
25#include <boost/histogram.hpp>
27#include "TGraphErrors.h"
30#include "TLinearFitter.h"
31#include "Fit/Fitter.h"
34#include <boost/histogram.hpp>
35#include <boost/histogram/ostream.hpp>
38#include <boost/format.hpp>
60 using boostHisto = boost::histogram::histogram<std::tuple<boost::histogram::axis::regular<double, boost::use_default, boost::use_default, boost::use_default>, boost::histogram::axis::integer<>>, boost::histogram::unlimited_storage<std::allocator<char>>>;
67 LOG(info) <<
"Default c-tor, not to be used";
71 TOFChannelData(
int nb,
float r,
CalibTOFapi* cta,
int nElsPerSector =
o2::tof::Geo::NPADSXSECTOR,
bool perstrip =
false,
bool safe =
false) : mNBins(nb), mRange(
r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe)
73 TOFChannelData(
int nb, float
r,
CalibTOFapi* cta,
int nElsPerSector =
o2::tof::
Geo::NPADSXSECTOR, bool perstrip = false, bool safe = false, TH2F*
h = nullptr) : mNBins(nb), mRange(
r), mCalibTOFapi(cta), mNElsPerSector(nElsPerSector), mPerStrip(perstrip), mSafeMode(safe), mChannelDist(
h)
76 if (
r <= 0. || nb < 1) {
77 throw std::runtime_error(
"Wrong initialization of the histogram");
79 mV2Bin = mNBins / (2 * mRange);
80 for (
int isect = 0; isect < 18; isect++) {
81 mHisto[isect] = boost::histogram::make_histogram(boost::histogram::axis::regular<>(mNBins, -mRange, mRange,
"t-texp"),
82 boost::histogram::axis::integer<>(0, mNElsPerSector,
"channel index in sector" +
std::to_string(isect)));
84 mEntries.resize(mNElsPerSector * 18, 0);
90 void print(
int isect)
const;
92 void fill(
const gsl::span<const o2::dataformats::CalibInfoTOF>
data);
93 void fill(
const gsl::span<const o2::tof::CalibInfoCluster>
data);
96 float integral(
int chmin,
int chmax,
float binmin,
float binmax)
const;
97 float integral(
int chmin,
int chmax,
int binxmin,
int binxmax)
const;
98 float integral(
int ch,
float binmin,
float binmax)
const;
99 float integral(
int ch,
int binxmin,
int binxmax)
const;
109 boostHisto&
getHisto(
int isect) {
return mHisto[isect]; }
110 const boostHisto&
getHisto(
int isect)
const {
return mHisto[isect]; }
125 std::array<boostHisto, 18> mHisto;
126 std::vector<int> mEntries;
135 bool mPerStrip =
false;
136 bool mSafeMode =
false;
149 using CcdbObjectInfoVector = std::vector<CcdbObjectInfo>;
150 using TimeSlewingVector = std::vector<TimeSlewing>;
166 int i1 =
int(
x[0]) % 96;
167 int i2 =
int(
x[0]) / 96 ? (i1 + 48) : (i1 + 1);
184 TOFChannelCalibrator(
int minEnt = 500,
int nb = 1000,
float r = 24400,
bool perstrip =
false,
bool safe =
false) : mMinEntries(minEnt), mNBins(nb), mRange(
r), mPerStrip(perstrip), mSafeMode(safe)
189 mLinFitters[
i].SetDim(3);
190 mLinFitters[
i].SetFormula(
"pol2");
193 mFitCal =
new TProfile(
"fitCal",
";channel;offset (ps)", 157248, 0, 157248);
198 mChannelDist =
new TH2F(
"channelDist",
";channel; t - t_{exp}^{#pi} (ps)", 157248, 0, 157248, nbins, -mRange, mRange);
209 LOG(
debug) <<
"Checking statistics";
210 return (mTest ?
true :
c->hasEnoughData(mMinEntries));
217 mTimeSlewingVector.clear();
234 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
237 slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode));
239 slot.setContainer(std::make_unique<TOFChannelData>(mNBins, mRange, mCalibTOFapi, nElements, mPerStrip, mSafeMode, mChannelDist));
266 mStripOffsetFunction.clear();
267 for (
int i = 0;
i < 96;
i++) {
269 int icolumn =
i / 48;
271 mStripOffsetFunction.append(Form(
"++ ("));
273 mStripOffsetFunction.append(Form(
"("));
277 mStripOffsetFunction.append(Form(
"(x > %d && x < %d)", irow + icolumn * 48, irow + icolumn * 48 + 1));
281 mStripOffsetFunction.append(
"-");
282 mStripOffsetFunction.append(Form(
"(x > %d && x < %d)", irow + icolumn * 48 - 1, irow + icolumn * 48));
287 mStripOffsetFunction.append(
"+");
289 mStripOffsetFunction.append(Form(
"(x > %d && x < %d)", irow + 96, irow + 96 + 1));
291 mStripOffsetFunction.append(
"-");
292 mStripOffsetFunction.append(Form(
"(x > %d && x < %d)", irow + 96, irow + 96 + 1));
294 mStripOffsetFunction.append(Form(
") "));
296 TLinearFitter localFitter2(1, mStripOffsetFunction.c_str());
309 bool mPerStrip =
false;
310 bool mSafeMode =
false;
315 CcdbObjectInfoVector mInfoVector;
316 TimeSlewingVector mTimeSlewingVector;
323 bool mCalibWithCosmics =
false;
327 std::string mStripOffsetFunction;
Class to store the output of the matching to TOF for calibration.
Class to store the output of the matching to TOF for calibration.
Class to use TOF calibration (decalibration, calibration)
Utils and constants for calibration and related workflows.
Class for time synchronization of RawReader instances.
TOF geo parameters (only statics)
static constexpr Int_t NSECTORS
static constexpr Double_t BC_TIME_INPS
static constexpr Int_t NSTRIPXSECTOR
static constexpr Int_t NPADS
static constexpr Int_t NPADSXSECTOR
static constexpr Int_t NPADX
bool doCalibWithCosmics() const
CcdbObjectInfoVector & getTimeSlewingInfoVector()
~TOFChannelCalibrator() final=default
void setDoCalibWithCosmics(bool doCalibWithCosmics=true)
static double FuncDeltaOffset(double *x, double *params)
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
void finalizeSlotWithTracks(Slot &slot)
void doPerStrip(bool val=true)
std::deque< o2::calibration::TimeSlot< o2::tof::TOFChannelData > > & getSlots()
void doSafeMode(bool val=true)
void finalizeSlotWithCosmics(Slot &slot)
void setIsTest(bool isTest)
const CcdbObjectInfoVector & getTimeSlewingInfoVector() const
void finalizeSlot(Slot &slot) final
CalibTOFapi * getCalibTOFapi() const
static constexpr int NCOMBINSTRIP
static constexpr int NMAXTHREADS
void setCalibTOFapi(CalibTOFapi *api)
TOFChannelCalibrator(int minEnt=500, int nb=1000, float r=24400, bool perstrip=false, bool safe=false)
const TimeSlewingVector & getTimeSlewingVector() const
bool hasEnoughData(const Slot &slot) const final
void fill(const gsl::span< const o2::dataformats::CalibInfoTOF > data)
static constexpr int NCOMBINSTRIP
std::vector< int > getEntriesPerChannel() const
~TOFChannelData()=default
TOFChannelData(int nb, float r, CalibTOFapi *cta, int nElsPerSector=o2::tof::Geo::NPADSXSECTOR, bool perstrip=false, bool safe=false)
boostHisto & getHisto(int isect)
float integral(int chmin, int chmax, float binmin, float binmax) const
int findBin(float v) const
void doSafeMode(bool val=true)
void doPerStrip(bool val=true)
const boostHisto & getHisto(int isect) const
void resetAndReRange(float range)
void merge(const TOFChannelData *prev)
bool hasEnoughData(int minEntries) const
void printEntries() const
GLenum const GLfloat * params
Double_t fitGaus(const size_t nBins, const T *arr, const T xMin, const T xMax, std::vector< T > ¶m)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"