Project
Loading...
Searching...
No Matches
MeanVertexData.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 "Framework/Logger.h"
15#include "CCDB/CcdbApi.h"
17#include <cmath>
18
19using namespace o2::calibration;
20
21namespace o2
22{
23namespace calibration
24{
25
29
30//_____________________________________________
32{
33 LOG(info) << entries << " entries";
34}
35
36//_____________________________________________
37void MeanVertexData::fill(const gsl::span<const PVertex> data)
38{
39 // fill container
40
41 LOG(debug) << "input size = " << data.size();
42 for (int i = data.size(); i--;) {
43 // filling the histogram in binned mode
44 std::array<float, 3> xyz{data[i].getX(), data[i].getY(), data[i].getZ()};
45 auto entries1 = entries + 1;
46 for (int j = 0; j < 3; j++) {
47 means[j] = (means[j] * entries + xyz[j]) / entries1;
48 meanSquares[j] = (meanSquares[j] * entries + xyz[j] * xyz[j]) / entries1;
49 }
50 if (mVerbose) {
51 LOG(info) << "i = " << i << " --> x = " << xyz[0] << ", y = " << xyz[1] << ", z = " << xyz[2];
52 }
53 entries = entries + 1;
54 histoVtx.push_back(xyz);
55 }
56}
57
58//_____________________________________________
60{
61 // remove entries from prev
62 int totEntries = entries - prev->entries;
63 if (totEntries > 0) {
64 for (int i = 0; i < 3; i++) {
65 means[i] = (means[i] * entries - prev->means[i] * prev->entries) / totEntries;
66 meanSquares[i] = (meanSquares[i] * entries - prev->meanSquares[i] * prev->entries) / totEntries;
67 }
68 } else {
69 for (int i = 0; i < 3; i++) {
70 means[i] = meanSquares[i] = 0.;
71 }
72 }
73 histoVtx.erase(histoVtx.begin(), histoVtx.begin() + prev->entries);
74 entries -= prev->entries;
75}
76
77//_____________________________________________
79{
80 // merge data of 2 slots
81 histoVtx.insert(histoVtx.end(), prev->histoVtx.begin(), prev->histoVtx.end());
82 auto totEntries = entries + prev->entries;
83 if (totEntries) {
84 for (int i = 0; i < 3; i++) {
85 means[i] = (means[i] * entries + prev->means[i] * prev->entries) / totEntries;
86 meanSquares[i] = (meanSquares[i] * entries + prev->meanSquares[i] * prev->entries) / totEntries;
87 }
88 }
89 entries = totEntries;
90}
91
92double MeanVertexData::getRMS(int i) const
93{
94 double rms2 = meanSquares[i] - means[i] * means[i];
95 return rms2 > 0. ? std::sqrt(rms2) : 0;
96}
97
98} // end namespace calibration
99} // end namespace o2
Utils and constants for calibration and related workflows.
int32_t i
uint32_t j
Definition RawData.h:0
std::ostringstream debug
GLboolean * data
Definition glcorearb.h:298
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void subtract(const MeanVertexData *prev)
std::array< double, 3 > meanSquares
std::vector< std::array< float, 3 > > histoVtx
void fill(const gsl::span< const PVertex > data)
void merge(const MeanVertexData *prev)
std::array< double, 3 > means
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"