forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalGain.h
More file actions
87 lines (73 loc) · 2.32 KB
/
CalGain.h
File metadata and controls
87 lines (73 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file CalGain.h
/// \brief Object with MPV dEdx values per chamber to be written into the CCDB
#ifndef ALICEO2_CALGAIN_H
#define ALICEO2_CALGAIN_H
#include "DataFormatsTRD/Constants.h"
#include "Rtypes.h"
#include <array>
namespace o2
{
namespace trd
{
class CalGain
{
public:
CalGain() = default;
CalGain(const CalGain&) = default;
~CalGain() = default;
void setMPVdEdx(int iDet, float mpv) { mMPVdEdx[iDet] = mpv; }
float getMPVdEdx(int iDet, bool defaultAvg = true) const
{
// if defaultAvg = false, we take the value stored whatever it is
// if defaultAvg = true and we have default value or bad value stored, we take the average on all chambers instead
if (!defaultAvg || isGoodGain(iDet))
return mMPVdEdx[iDet];
else {
if (TMath::Abs(mMeanGain + 999.) < 1e-6)
mMeanGain = getAverageGain();
return mMeanGain;
}
}
float getAverageGain() const
{
float averageGain = 0.;
int ngood = 0;
for (int iDet = 0; iDet < constants::MAXCHAMBER; iDet++) {
if (isGoodGain(iDet)) {
// The chamber has correct calibration
ngood++;
averageGain += mMPVdEdx[iDet];
}
}
if (ngood == 0) {
// we should make sure it never happens
return constants::MPVDEDXDEFAULT;
}
averageGain /= ngood;
return averageGain;
}
bool isGoodGain(int iDet) const
{
if (TMath::Abs(mMPVdEdx[iDet] - constants::MPVDEDXDEFAULT) > 1e-6)
return true;
else
return false;
}
private:
std::array<float, constants::MAXCHAMBER> mMPVdEdx{}; ///< Most probable value of dEdx distribution per TRD chamber
mutable float mMeanGain{-999.}; ///! average gain, calculated only once
ClassDefNV(CalGain, 2);
};
} // namespace trd
} // namespace o2
#endif // ALICEO2_CALGAIN_H