Project
Loading...
Searching...
No Matches
Digit.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 <cmath>
14#include <fmt/format.h>
15#include <iostream>
16
17namespace o2::mch
18{
19
20std::ostream& operator<<(std::ostream& os, const o2::mch::Digit& d)
21{
22 os << fmt::format("DetID {:4d} PadId {:6d} ADC {:10d} TFtime {:10d} NofSamples {:5d} {}",
23 d.getDetID(), d.getPadID(), d.getADC(), d.getTime(), d.getNofSamples(),
24 d.isSaturated() ? "(S)" : "");
25 return os;
26}
27
28bool closeEnough(double x, double y, double eps = 1E-6)
29{
30 return std::fabs(x - y) <= eps * std::max(1.0, std::max(std::fabs(x), std::fabs(y)));
31}
32
33Digit::Digit(int detid, int pad, uint32_t adc, int32_t time, uint16_t nSamples, bool saturated)
34 : mTFtime(time), mNofSamples(nSamples), mIsSaturated(saturated), mDetID(detid), mPadID(pad), mADC(adc)
35{
36 setNofSamples(nSamples);
37}
38
39uint16_t Digit::getNofSamples() const
40{
41 return mNofSamples;
42}
43
45{
46 return mIsSaturated;
47}
48
49void Digit::setNofSamples(uint16_t n)
50{
51 constexpr uint64_t max10bits = (static_cast<uint64_t>(1) << 10);
52 if (static_cast<uint64_t>(n) >= max10bits) {
53 throw std::invalid_argument("mch digit nofsamples must fit within 10 bits");
54 }
55 mNofSamples = n;
56}
57
58void Digit::setSaturated(bool sat)
59{
60 mIsSaturated = sat;
61}
62
63bool Digit::operator==(const Digit& other) const
64{
65 return mDetID == other.mDetID &&
66 mPadID == other.mPadID &&
67 mADC == other.mADC &&
68 mTFtime == other.mTFtime &&
69 mNofSamples == other.mNofSamples &&
70 mIsSaturated == other.mIsSaturated;
71}
72
73bool Digit::operator<(const Digit& other) const
74{
75 if (mDetID == other.mDetID) {
76 if (mPadID == other.mPadID) {
77 if (mTFtime == other.mTFtime) {
78 if (mADC == other.mADC) {
79 if (mNofSamples == other.mNofSamples) {
80 return mIsSaturated != other.mIsSaturated;
81 } else {
82 return mNofSamples < other.mNofSamples;
83 }
84 } else {
85 return mADC < other.mADC;
86 }
87 } else {
88 return mTFtime < other.mTFtime;
89 }
90 } else {
91 return mPadID < other.mPadID;
92 }
93 } else {
94 return mDetID < other.mDetID;
95 }
96}
97
98} // namespace o2::mch
int16_t time
Definition RawEventData.h:4
MCH digit implementation.
Definition Digit.h:31
bool operator<(const Digit &) const
Definition Digit.cxx:73
int getPadID() const
Definition Digit.h:54
int getDetID() const
Definition Digit.h:52
bool operator==(const Digit &) const
Definition Digit.cxx:63
void setSaturated(bool sat)
Definition Digit.cxx:58
uint16_t getNofSamples() const
Definition Digit.cxx:39
bool isSaturated() const
Definition Digit.cxx:44
int32_t getTime() const
Definition Digit.h:44
Digit()=default
void setNofSamples(uint16_t n)
Definition Digit.cxx:49
uint32_t getADC() const
Definition Digit.h:57
GLdouble n
Definition glcorearb.h:1982
GLint GLenum GLint x
Definition glcorearb.h:403
std::ostream & operator<<(std::ostream &os, const o2::dataformats::MeanVertexObject &o)
bool closeEnough(double x, double y, double eps=1E-6)
Definition Digit.cxx:28
VectorOfTObjectPtrs other
ArrayADC adc