Project
Loading...
Searching...
No Matches
FV0ChannelTimeOffsetSlotContainer.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
13#include "FV0Base/Constants.h"
14#include "MathUtils/fit.h"
15
16using namespace o2::fv0;
17
19
21 : mMinEntries(minEntries)
22{
23
24 mHistogram = boost::histogram::make_histogram(boost::histogram::axis::integer<>(-HISTOGRAM_RANGE, HISTOGRAM_RANGE, "channel_times"),
25 boost::histogram::axis::integer<>(0, Constants::nFv0Channels, "channel_ID"));
26}
27
29{
30 return *std::min_element(mEntriesPerChannel.begin(), mEntriesPerChannel.end()) > mMinEntries;
31}
32void FV0ChannelTimeOffsetSlotContainer::fill(const gsl::span<const FV0CalibrationInfoObject>& data)
33{
34
35 for (auto& entry : data) {
36
37 updateFirstCreation(entry.getTimeStamp());
38
39 const auto chID = entry.getChannelIndex();
40 const auto chTime = entry.getTime();
41
42 // i dont really know when should it be marked as invalid
43 if (chID < Constants::nFv0Channels) {
44 mHistogram(chTime, chID);
45 ++mEntriesPerChannel[chID];
46 LOG(debug) << "FV0ChannelTimeOffsetSlotContainer::fill entries " << mEntriesPerChannel[chID] << " chID " << int(chID) << " time " << chTime << " tiestamp " << uint64_t(entry.getTimeStamp());
47 }
48 // else {
49 // LOG(fatal) << "Invalid channel data";
50 // }
51 }
52}
53
55{
56
57 mHistogram += prev->mHistogram;
58 for (unsigned int iCh = 0; iCh < Constants::nFv0Channels; ++iCh) {
59 mEntriesPerChannel[iCh] += prev->mEntriesPerChannel[iCh];
60 }
61 mFirstCreation = std::min(mFirstCreation, prev->mFirstCreation);
62}
63
65{
66
67 static constexpr size_t MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR = 1;
68
69 if (0 == mEntriesPerChannel[channelID]) {
70 return 0;
71 }
72 LOG(debug) << " for channel " << int(channelID) << " entries " << mEntriesPerChannel[channelID];
73
74 std::vector<double> channelHistogramData(NUMBER_OF_HISTOGRAM_BINS, 0);
75
76 std::vector<double> outputGaussianFitValues;
77 double binWidth = (HISTOGRAM_RANGE - (-HISTOGRAM_RANGE)) / NUMBER_OF_HISTOGRAM_BINS;
78 double minGausFitRange = 0;
79 double maxGausFitRange = 0;
80 double MaxValOfHistogram = 0.0;
81
82 for (int iBin = 0; iBin < NUMBER_OF_HISTOGRAM_BINS; ++iBin) {
83 channelHistogramData[iBin] = mHistogram.at(iBin, channelID);
84 }
85
86 int maxElementIndex = std::max_element(channelHistogramData.begin(), channelHistogramData.end()) - channelHistogramData.begin();
87 int maxElement = *std::max_element(channelHistogramData.begin(), channelHistogramData.end());
88
89 // calculating the min & max range values to fit gaussian
90 minGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex - sGausFitBins) * binWidth + binWidth / 2.0);
91 maxGausFitRange = (-HISTOGRAM_RANGE + (maxElementIndex + sGausFitBins) * binWidth + binWidth / 2.0);
92
93 double returnCode = math_utils::fitGaus<double>(NUMBER_OF_HISTOGRAM_BINS, channelHistogramData.data(),
94 minGausFitRange, maxGausFitRange, outputGaussianFitValues);
95
96 MaxValOfHistogram = (-HISTOGRAM_RANGE + maxElementIndex * binWidth + binWidth / 2.0);
97
98 if (returnCode < 0) {
99 LOG(error) << "Gaussian fit error!";
100 return static_cast<int16_t>(std::round(MaxValOfHistogram));
101 // return 0;
102 }
103
104 return static_cast<int16_t>(std::round(outputGaussianFitValues[MEAN_VALUE_INDEX_IN_OUTPUT_VECTOR]));
105}
107{
108 FV0ChannelTimeCalibrationObject calibrationObject;
109
110 for (unsigned int iCh = 0; iCh < Constants::nFv0Channels; ++iCh) {
111 calibrationObject.mTimeOffsets[iCh] = getMeanGaussianFitValue(iCh);
112 }
113
114 return calibrationObject;
115}
116
118{
119 // QC will do that part
120}
General constants in FV0.
uint8_t channelID
Definition RawEventData.h:8
std::ostringstream debug
void fill(const gsl::span< const FV0CalibrationInfoObject > &data)
void merge(FV0ChannelTimeOffsetSlotContainer *prev)
FV0ChannelTimeCalibrationObject generateCalibrationObject(long, long, const std::string &) const
GLuint entry
Definition glcorearb.h:5735
GLboolean * data
Definition glcorearb.h:298
static constexpr int nFv0Channels
Definition Constants.h:32
std::array< int16_t, Constants::nFv0Channels > mTimeOffsets
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"