Project
Loading...
Searching...
No Matches
Digit.h
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
12#ifndef ALICEO2_TRD_DIGIT_H_
13#define ALICEO2_TRD_DIGIT_H_
14
15#include <cstdint>
16#include <vector>
17#include <array>
18#include <unordered_map>
19#include <numeric>
20#include "Rtypes.h" // for ClassDef
21
24#include <gsl/span>
25
26namespace o2
27{
28namespace trd
29{
30
31using ADC_t = std::uint16_t;
32using ArrayADC = std::array<ADC_t, constants::TIMEBINS>;
33
34// Digit class for TRD
35// Notes:
36// Shared pads:
37// the lower mcm and rob is chosen for a given shared pad.
38// this negates the need for need alternate indexing strategies.
39// if you are trying to go from mcm/rob/adc to pad/row and back to mcm/rob/adc ,
40// you may not end up in the same place, you need to remember to manually check for shared pads.
41// Pre Trigger phase:
42// LHC clock runs at 40.08MHz, ADC run at 1/4 or 10MHz and the trap runs at 120MHz or LHC*3.
43// The trap clock can therefore be in 1 of 12 positions relative to the ADC clock.
44// Only 4 of those positions are valid, dependent on the TRAP assembly program timing offset, as of 11/2022 pre-trigger phase: 0,3,6,9.
45// vaguely graphically below:
46// LHC ___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___---___
47// TRAP _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
48// ADC ___------------____________------------____________------------____________------------____________------------____________------------
49// _________------------____________------------____________------------____________------------____________------------____________------
50// ---____________------------____________------------____________------------____________------------____________------------____________
51// ---------____________------------____________------------____________------------____________------------____________------------______
52// PreTrig _________------________________________------________________________------________________________------________________________------
53
54class Digit
55{
56 public:
57 Digit() = default;
58 ~Digit() = default;
59 Digit(int det, int row, int pad, ArrayADC adc, int phase = 0);
60 Digit(int det, int row, int pad); // add adc data and pretrigger phase in a separate step
61 Digit(int det, int rob, int mcm, int channel, ArrayADC adc, int phase = 0);
62 Digit(int det, int rob, int mcm, int channel); // add adc data in a seperate step
63
64 // Copy
65 Digit(const Digit&) = default;
66 // Assignment
67 Digit& operator=(const Digit&) = default;
68 // Modifiers
69 void setROB(int rob) { mROB = rob; }
70 void setMCM(int mcm) { mMCM = mcm; }
71 void setROB(int row, int col) { mROB = HelperMethods::getROBfromPad(row, col); } // set ROB from pad row, column
72 void setMCM(int row, int col) { mMCM = HelperMethods::getMCMfromPad(row, col); } // set MCM from pad row, column
73 void setChannel(int channel) { mChannel = channel; }
74 void setDetector(int det) { mDetector = ((mDetector & 0xf000) | (det & 0xfff)); }
75 void setADC(ArrayADC const& adc) { mADC = adc; }
76 void setADC(const gsl::span<ADC_t>& adc) { std::copy(adc.begin(), adc.end(), mADC.begin()); }
77 void setPreTrigPhase(int phase) { mDetector = (((phase & 0xf) << 12) | (mDetector & 0xfff)); }
78 // Get methods
79 int getDetector() const { return mDetector & 0xfff; }
80 int getHCId() const { return (mDetector & 0xfff) * 2 + (mROB % 2); }
81 int getPadRow() const { return HelperMethods::getPadRowFromMCM(mROB, mMCM); }
82 int getPadCol() const { return HelperMethods::getPadColFromADC(mROB, mMCM, mChannel); }
83 int getROB() const { return mROB; }
84 int getMCM() const { return mMCM; }
85 int getMCMCol() const { return (getMCM() % constants::NMCMROBINCOL) + constants::NMCMROBINCOL * (getROB() % 2); }
86 int getChannel() const { return mChannel; }
87 int getPreTrigPhase() const { return ((mDetector >> 12) & 0xf); }
88 bool isSharedDigit() const;
89 bool isNeighbour(const Digit& other) const;
90
91 ArrayADC const& getADC() const { return mADC; }
92 ADC_t getADCsum() const { return std::accumulate(mADC.begin(), mADC.end(), (ADC_t)0); }
93 // returns the max ADC value and sets idx to the time bin with the largest ADC value
94 ADC_t getADCmax(int& idx) const;
95 ADC_t getADCval(int tb) const { return mADC[tb]; }
96
97 bool operator==(const Digit& o) const
98 {
99 return mDetector == o.mDetector && mROB == o.mROB && mMCM == o.mMCM && mChannel == o.mChannel && mADC == o.mADC;
100 }
101
102 private:
109 std::uint16_t mDetector{0};
110 std::uint8_t mROB{0};
111 std::uint8_t mMCM{0};
112 std::uint8_t mChannel{0};
113 ArrayADC mADC{};
114 ClassDefNV(Digit, 4);
115};
116
117std::ostream& operator<<(std::ostream& stream, const Digit& d);
118
119} // namespace trd
120} // namespace o2
121
122#endif
uint16_t mcm
uint16_t rob
Global TRD definitions and constants.
uint64_t phase
Definition RawEventData.h:7
bool o
uint32_t col
Definition RawData.h:4
ADC_t getADCsum() const
Definition Digit.h:92
int getPreTrigPhase() const
Definition Digit.h:87
void setMCM(int mcm)
Definition Digit.h:70
ADC_t getADCval(int tb) const
Definition Digit.h:95
ADC_t getADCmax(int &idx) const
Definition Digit.cxx:71
int getDetector() const
Definition Digit.h:79
~Digit()=default
int getPadRow() const
Definition Digit.h:81
void setADC(const gsl::span< ADC_t > &adc)
Definition Digit.h:76
Digit & operator=(const Digit &)=default
bool isNeighbour(const Digit &other) const
Definition Digit.cxx:66
bool isSharedDigit() const
Definition Digit.cxx:57
void setROB(int row, int col)
Definition Digit.h:71
void setADC(ArrayADC const &adc)
Definition Digit.h:75
void setPreTrigPhase(int phase)
Definition Digit.h:77
int getChannel() const
Definition Digit.h:86
int getMCM() const
Definition Digit.h:84
int getMCMCol() const
Definition Digit.h:85
void setMCM(int row, int col)
Definition Digit.h:72
Digit(const Digit &)=default
int getHCId() const
Definition Digit.h:80
ArrayADC const & getADC() const
Definition Digit.h:91
void setROB(int rob)
Definition Digit.h:69
int getROB() const
Definition Digit.h:83
int getPadCol() const
Definition Digit.h:82
Digit()=default
void setDetector(int det)
Definition Digit.h:74
bool operator==(const Digit &o) const
Definition Digit.h:97
void setChannel(int channel)
Definition Digit.h:73
GLuint GLuint stream
Definition glcorearb.h:1806
constexpr int NMCMROBINCOL
the number of MCMs per ROB in column direction
Definition Constants.h:49
std::uint16_t ADC_t
Definition Digit.h:31
std::array< ADC_t, constants::TIMEBINS > ArrayADC
Definition Digit.h:32
std::ostream & operator<<(std::ostream &stream, const Digit &d)
Definition Digit.cxx:78
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static int getROBfromPad(int irow, int icol)
static int getPadRowFromMCM(int irob, int imcm)
static int getPadColFromADC(int irob, int imcm, int iadc)
static int getMCMfromPad(int irow, int icol)
VectorOfTObjectPtrs other
std::vector< int > row
ArrayADC adc