|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +#ifndef TOF_CHANNEL_CALIBRATOR_H_ |
| 12 | +#define TOF_CHANNEL_CALIBRATOR_H_ |
| 13 | + |
| 14 | +#include "DetectorsCalibration/TimeSlotCalibration.h" |
| 15 | +#include "DetectorsCalibration/TimeSlot.h" |
| 16 | +#include "DataFormatsTOF/CalibInfoTOF.h" |
| 17 | +#include "TOFCalibration/CalibTOFapi.h" |
| 18 | +#include "DataFormatsTOF/CalibLHCphaseTOF.h" |
| 19 | +#include "TOFBase/Geo.h" |
| 20 | +#include "CCDB/CcdbObjectInfo.h" |
| 21 | +#include <array> |
| 22 | +#include <boost/histogram.hpp> |
| 23 | + |
| 24 | +namespace o2 |
| 25 | +{ |
| 26 | +namespace tof |
| 27 | +{ |
| 28 | + |
| 29 | +class TOFChannelData { |
| 30 | + |
| 31 | +using Slot = o2::calibration::TimeSlot<o2::tof::TOFChannelData>; |
| 32 | +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> > >; |
| 33 | + |
| 34 | +public: |
| 35 | + |
| 36 | + static constexpr int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS; |
| 37 | + |
| 38 | + TOFChannelData() { |
| 39 | + LOG(INFO) << "Default c-tor, not to be used"; |
| 40 | + } |
| 41 | + |
| 42 | + TOFChannelData(int nb, float r) : mNBins(nb), mRange(r) |
| 43 | + { |
| 44 | + if (r <= 0. || nb < 1) { |
| 45 | + throw std::runtime_error("Wrong initialization of the histogram"); |
| 46 | + } |
| 47 | + mV2Bin = mNBins / (2 * mRange); |
| 48 | + for (int isect = 0; isect < 18; isect ++){ |
| 49 | + mHisto[isect] = boost::histogram::make_histogram(boost::histogram::axis::regular<>(mNBins, -mRange, mRange, "t-texp"), |
| 50 | + boost::histogram::axis::integer<>(0, o2::tof::Geo::NPADSXSECTOR, "channel index in sector" + std::to_string(isect))); // bin is defined as [low, high[ |
| 51 | + } |
| 52 | + mEntries.resize(o2::tof::Geo::NCHANNELS, 0); |
| 53 | + } |
| 54 | + |
| 55 | + ~TOFChannelData() = default; |
| 56 | + |
| 57 | + void print() const; |
| 58 | + void print(int isect) const; |
| 59 | + void fill(const gsl::span<const o2::dataformats::CalibInfoTOF> data); |
| 60 | + void merge(const TOFChannelData* prev); |
| 61 | + int findBin(float v) const; |
| 62 | + float integral(int chmin, int chmax, float binmin, float binmax) const; |
| 63 | + float integral(int chmin, int chmax, int binxmin, int binxmax) const; |
| 64 | + float integral(int ch, float binmin, float binmax) const; |
| 65 | + float integral(int ch, int binxmin, int binxmax) const; |
| 66 | + float integral(int ch) const; |
| 67 | + bool hasEnoughData(int minEntries) const; |
| 68 | + |
| 69 | + float getRange() const { return mRange; } |
| 70 | + void setRange(float r) { mRange = r; } |
| 71 | + |
| 72 | + int getNbins() const { return mNBins; } |
| 73 | + void setNbins(int nb) { mNBins = nb; } |
| 74 | + |
| 75 | + boostHisto& getHisto(int isect) { return mHisto[isect]; } |
| 76 | + const boostHisto& getHisto(int isect) const { return mHisto[isect]; } |
| 77 | + //const boostHisto getHisto() const { return &mHisto[0]; } |
| 78 | + // boostHisto* getHisto(int isect) const { return &mHisto[isect]; } |
| 79 | + |
| 80 | + private: |
| 81 | + float mRange = 24400; |
| 82 | + int mNBins = 1000; |
| 83 | + float mV2Bin; |
| 84 | + // do I really have to initialize it like below? |
| 85 | + std::array<boostHisto,18> mHisto; |
| 86 | + std::vector<int> mEntries; // vector containing number of entries per channel |
| 87 | + |
| 88 | + ClassDefNV(TOFChannelData, 1); |
| 89 | +}; |
| 90 | + |
| 91 | +class TOFChannelCalibrator : public o2::calibration::TimeSlotCalibration<o2::dataformats::CalibInfoTOF, o2::tof::TOFChannelData> |
| 92 | +{ |
| 93 | + using TFType = uint64_t; |
| 94 | + using Slot = o2::calibration::TimeSlot<o2::tof::TOFChannelData>; |
| 95 | + using CalibTOFapi = o2::tof::CalibTOFapi; |
| 96 | + using TimeSlewing = o2::dataformats::CalibTimeSlewingParamTOF; |
| 97 | + using CcdbObjectInfo = o2::ccdb::CcdbObjectInfo; |
| 98 | + using CcdbObjectInfoVector = std::vector<CcdbObjectInfo>; |
| 99 | + using TimeSlewingVector = std::vector<TimeSlewing>; |
| 100 | + |
| 101 | + public: |
| 102 | + |
| 103 | + static const int NCHANNELSXSECTOR = o2::tof::Geo::NCHANNELS / o2::tof::Geo::NSECTORS; |
| 104 | + TOFChannelCalibrator(int minEnt = 500, int nb = 1000, float r = 24400, const std::string path = "http://ccdb-test.cern.ch:8080") : mMinEntries(minEnt), mNBins(nb), mRange(r) { mCalibTOFapi.setURL(path); } |
| 105 | + |
| 106 | + ~TOFChannelCalibrator() final = default; |
| 107 | + |
| 108 | + bool hasEnoughData(const Slot& slot) const final; |
| 109 | + void initOutput() final; |
| 110 | + void finalizeSlot(Slot& slot) final; |
| 111 | + Slot& emplaceNewSlot(bool front, TFType tstart, TFType tend) final; |
| 112 | + |
| 113 | + const TimeSlewingVector& getTimeSlewingVector() const { return mTimeSlewingVector; } |
| 114 | + const CcdbObjectInfoVector& getTimeSlewingInfoVector() const { return mInfoVector; } |
| 115 | + CcdbObjectInfoVector& getTimeSlewingInfoVector() { return mInfoVector; } |
| 116 | + |
| 117 | + private: |
| 118 | + int mMinEntries = 0; // min number of entries to calibrate the TimeSlot |
| 119 | + int mNBins = 0; // bins of the histogram with the t-text per channel |
| 120 | + float mRange = 0.; // range of the histogram with the t-text per channel |
| 121 | + CalibTOFapi mCalibTOFapi; |
| 122 | + CcdbObjectInfoVector mInfoVector; // vector of CCDB Infos , each element is filled with the CCDB description of the accompanying TimeSlewing object |
| 123 | + TimeSlewingVector mTimeSlewingVector; // vector of TimeSlewing, each element is filled in "process" |
| 124 | + // when we finalize one slot (multiple can be finalized |
| 125 | + // during the same "process", which is why we have a vector). |
| 126 | + // Each element is to be considered the output of the device, |
| 127 | + // and will go to the CCDB. Note that for the channel offset |
| 128 | + // we still fill the TimeSlewing object |
| 129 | + |
| 130 | + ClassDefOverride(TOFChannelCalibrator, 1); |
| 131 | +}; |
| 132 | + |
| 133 | +} // end namespace tof |
| 134 | +} // end namespace o2 |
| 135 | + |
| 136 | +#endif /* TOF_CHANNEL_CALIBRATOR_H_ */ |
0 commit comments