Skip to content

Commit 80003af

Browse files
bazinskisawenzel
authored andcommitted
fix digit and add tests
1 parent 09e1dd4 commit 80003af

File tree

4 files changed

+212
-12
lines changed

4 files changed

+212
-12
lines changed

Detectors/TRD/base/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ o2_add_test(RawData
8888
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
8989
LABELS trd
9090
)
91+
o2_add_test(Digit
92+
COMPONENT_NAME trd
93+
PUBLIC_LINK_LIBRARIES O2::TRDBase O2::DataFormatsTRD
94+
SOURCES test/testDigit.cxx
95+
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage
96+
LABELS trd
97+
)
98+

Detectors/TRD/base/include/TRDBase/Digit.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ using ArrayADC = std::array<ADC_t, constants::TIMEBINS>;
3232
// Digit class for TRD
3333
// Notes:
3434
// Shared pads:
35-
// the lowe mcm and rob is chosen for a given shared pad.
35+
// the lower mcm and rob is chosen for a given shared pad.
3636
// this negates the need for need alternate indexing strategies.
37-
// it does however mean that if you are trying to go from pad/row to mcm/rob you need to remember to manually do the shared ones.
38-
// TODO we could change the get methods to return the value in negaitve to indicate a shared pad, but I feel this is just added complexity? Comments?
39-
// if you are going to have to check for negative you may as well check for it being shared.
37+
// if you are trying to go from mcm/rob/adc to pad/row and back to mcm/rob/adc ,
38+
// you may not end up in the same place, you need to remember to manually check for shared pads.
39+
4040
class Digit
4141
{
4242
public:
@@ -60,22 +60,22 @@ class Digit
6060
void setDetector(int det) { mDetector = det; }
6161
void setADC(ArrayADC const& adc) { mADC = adc; }
6262
// Get methods
63-
int getDetector() const { return mROB; }
63+
int getDetector() const { return mDetector; }
6464
int getRow() const { return FeeParam::getPadRowFromMCM(mROB, mMCM); }
6565
int getPad() const { return FeeParam::getPadColFromADC(mROB, mMCM, mChannel); }
6666
int getROB() const { return mROB; }
6767
int getMCM() const { return mMCM; }
6868
int getChannel() const { return mChannel; }
69-
int isSharedDigit();
69+
bool isSharedDigit();
7070

7171
ArrayADC const& getADC() const { return mADC; }
7272
ADC_t getADCsum() const { return std::accumulate(mADC.begin(), mADC.end(), (ADC_t)0); }
7373

7474
private:
75-
std::uint16_t mDetector{0}; // detector, the chamber
76-
std::uint8_t mROB{0}; // read out board with in chamber
77-
std::uint8_t mMCM{0}; // MCM chip this digit is attached to
78-
std::uint8_t mChannel{0}; // channel of this chip the digit is attached to.
75+
std::uint16_t mDetector{0}; // detector, the chamber [0-539]
76+
std::uint8_t mROB{0}; // read out board within chamber [0-7] [0-5] depending on C0 or C1
77+
std::uint8_t mMCM{0}; // MCM chip this digit is attached [0-15]
78+
std::uint8_t mChannel{0}; // channel of this chip the digit is attached to, see TDP chapter ?? TODO fill in later the figure number of ROB to MCM mapping picture
7979

8080
ArrayADC mADC{}; // ADC vector (30 time-bins)
8181
ClassDefNV(Digit, 3);

Detectors/TRD/base/src/Digit.cxx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,46 @@
1111
#include "TRDBase/Digit.h"
1212
namespace o2::trd
1313
{
14+
15+
using namespace constants;
16+
1417
Digit::Digit(const int det, const int row, const int pad, const ArrayADC adc)
1518
{
1619
setDetector(det);
1720
setROB(row, pad);
1821
setMCM(row, pad);
1922
setADC(adc);
23+
setChannel(NADCMCM - 2 - (pad % NCOLMCM));
2024
}
25+
2126
Digit::Digit(const int det, const int row, const int pad) // add adc data in a seperate step
2227
{
2328
setDetector(det);
2429
setROB(row, pad);
2530
setMCM(row, pad);
31+
setChannel(NADCMCM - 2 - (pad % NCOLMCM));
2632
}
33+
2734
Digit::Digit(const int det, const int rob, const int mcm, const int channel, const ArrayADC adc)
2835
{
36+
setDetector(det);
2937
setROB(rob);
3038
setMCM(mcm);
3139
setChannel(channel);
3240
setADC(adc);
3341
}
42+
3443
Digit::Digit(const int det, const int rob, const int mcm, const int channel) // add adc data in a seperate step
3544
{
45+
setDetector(det);
3646
setROB(rob);
3747
setMCM(mcm);
3848
setChannel(channel);
3949
}
40-
int Digit::isSharedDigit()
50+
51+
bool Digit::isSharedDigit()
4152
{
42-
if (mChannel == 0 || mChannel == 19 || mChannel == 20) {
53+
if (mChannel == 0 || mChannel == 1 || mChannel == NADCMCM - 1) {
4354
return 1;
4455
} else {
4556
return 0;
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file testTRDGeometry.cxx
12+
/// \brief This task tests the Geometry
13+
/// \author Sean Murray, murrays@cern.ch
14+
15+
#define BOOST_TEST_MODULE Test TRD_Digit
16+
#define BOOST_TEST_MAIN
17+
#define BOOST_TEST_DYN_LINK
18+
#include <boost/test/unit_test.hpp>
19+
#include <iostream>
20+
#include <numeric>
21+
22+
#include "TRDBase/Digit.h"
23+
#include "DataFormatsTRD/Constants.h"
24+
25+
namespace o2
26+
{
27+
namespace trd
28+
{
29+
30+
using namespace o2::trd::constants;
31+
32+
void testDigitDetRowPad(Digit& test, int det, int row, int pad)
33+
{
34+
BOOST_CHECK(test.getPad() == pad);
35+
BOOST_CHECK(test.getRow() == row);
36+
BOOST_CHECK(test.getDetector() == det);
37+
}
38+
39+
void testDigitDetROBMCM(Digit& test, int det, int rob, int mcm, int channel)
40+
{
41+
BOOST_CHECK(test.getMCM() == mcm);
42+
BOOST_CHECK(test.getROB() == rob);
43+
BOOST_CHECK(test.getChannel() == channel);
44+
BOOST_CHECK(test.getDetector() == det);
45+
}
46+
47+
BOOST_AUTO_TEST_CASE(TRDDigit_test)
48+
{
49+
//TPD
50+
//pg 14 for rob to chamber
51+
//
52+
// 540 read out chambers (detector)
53+
// each one is made up of 16 row of 144 pads.
54+
// each one is also made up of 8 or 6 read out boards comprising 16 mcm and 21 adc each.
55+
// we need to check the pad,row to rob,mcm and back and the inverse holds true.
56+
// also the boundaries hold true.ends, of readout boards, ends of mcm.
57+
//
58+
//check digit at bottom of row is correctly assigned.
59+
60+
// a pad row spans 2 read out boards. with 4 mcm in each.
61+
// i.e. pad row 0 will have read out board 0 and 1 and mcm 0-4 and 0-4 in each making up the 8 mcm in the pad row.
62+
// channel 0 and 1 of MCM n are shared with 18 and 19 (respectively) of MCM n+1 and channel 20 of MCM n is shared with MCM n-1 channel 2
63+
// channel 20 of MCM n is connected to the preceding MCM's highest number pad. i.e. MCM01 channel 20 is connected to MCM00 pad 17 (18th pad) of row.
64+
65+
// so check various combinations of that, mostly just the boundaries.
66+
Digit first(0, 0, 0); //det row pad
67+
BOOST_CHECK(first.getMCM() == 0);
68+
69+
Digit last(MAXCHAMBER - 1, NROWC1 - 1, NCOLUMN - 1); // last det row and pad
70+
BOOST_CHECK(last.getMCM() == NMCMROB - 1);
71+
// end of first mcm
72+
Digit a(0, 0, NCOLMCM - 1);
73+
BOOST_CHECK(a.getMCM() == 0);
74+
// start of new mcm?
75+
Digit b(0, 0, NCOLMCM);
76+
BOOST_CHECK(b.getMCM() == 1);
77+
// last pad connected to start of new mcm?
78+
Digit c(0, 0, 89);
79+
BOOST_CHECK(c.getMCM() == 0);
80+
// last pad connected to start of new mcm?
81+
Digit d(0, 0, 90);
82+
BOOST_CHECK(d.getMCM() == 1);
83+
// now to test if we set the rob and mcm do we get the correct pad and row.
84+
// using the reciprical of the values above for simplicity.
85+
//
86+
//test block 1.
87+
Digit e(0, 0, 0, 0);
88+
//first channel of the first mcm, this is in fact the 19 pad of the first row, and connected to the 18th adc of the second trap ...
89+
Digit f(0, e.getRow(), e.getPad()); // createa digit based on the above digits pad and row.
90+
// we *shoulud* end up with a rob:mcm of 0:1 and channel 18
91+
testDigitDetROBMCM(f, 0, 0, 1, NCOLMCM);
92+
93+
Digit g(0, 0, NCOLMCM - 1); // row 0 pad 17 --- should be mcm 0 and channel 2
94+
testDigitDetROBMCM(g, 0, 0, 0, 2);
95+
96+
Digit h(0, 0, 0, 2);
97+
testDigitDetRowPad(h, 0, 0, NCOLMCM - 1);
98+
99+
//test block2 repeat block1 but at the edge of a rob boundary i.e. going from row0 the 72nd pad to 73rd. Spanning the half of 144(NCOLUMN)
100+
Digit i(0, 0, (NCOLUMN / 2) - 1);
101+
testDigitDetROBMCM(i, 0, 0, 3, 2);
102+
//check the reverse creation
103+
Digit k(0, 0, 3, 2);
104+
testDigitDetRowPad(k, 0, 0, (NCOLUMN / 2) - 1);
105+
106+
Digit j(0, 0, NCOLUMN / 2);
107+
testDigitDetROBMCM(j, 0, 1, 0, 19);
108+
//check the reverse creation
109+
Digit l(0, 1, 0, 19);
110+
testDigitDetRowPad(l, 0, 0, NCOLUMN / 2);
111+
112+
// now repeat the same for another part of the first chamber, middle rows
113+
//
114+
Digit m(0, 12, (NCOLUMN / 2) - 1);
115+
testDigitDetROBMCM(m, 0, 6, 3, 2);
116+
//check the reverse creation
117+
Digit n(0, 6, 3, 2);
118+
testDigitDetRowPad(n, 0, 12, (NCOLUMN / 2) - 1);
119+
120+
Digit o(0, 12, NCOLMCM - 1);
121+
testDigitDetROBMCM(o, 0, 6, 0, 2);
122+
Digit p(0, 6, 0, 2);
123+
testDigitDetRowPad(p, 0, 12, NCOLMCM - 1);
124+
125+
//and now for the last row.
126+
Digit q(0, 15, (NCOLUMN / 2) - 1);
127+
testDigitDetROBMCM(q, 0, 6, 15, 2);
128+
//check the reverse creation
129+
Digit r(0, 6, 3, 2);
130+
testDigitDetRowPad(r, 0, 12, (NCOLUMN / 2) - 1);
131+
132+
Digit s(0, 15, NCOLMCM - 1);
133+
testDigitDetROBMCM(s, 0, 6, 12, 2);
134+
Digit t(0, 6, 0, 2);
135+
testDigitDetRowPad(t, 0, 12, NCOLMCM - 1);
136+
137+
// as a last check that for detector changes.
138+
//
139+
Digit u(1, 15, (NCOLUMN / 2) - 1);
140+
testDigitDetROBMCM(u, 1, 6, 15, 2);
141+
//check the reverse creation
142+
Digit v(1, 6, 3, 2);
143+
testDigitDetRowPad(v, 1, 12, (NCOLUMN / 2) - 1);
144+
145+
Digit w(10, 15, NCOLMCM - 1);
146+
testDigitDetROBMCM(w, 10, 6, 12, 2);
147+
Digit x(10, 6, 0, 2);
148+
testDigitDetRowPad(x, 10, 12, NCOLMCM - 1);
149+
150+
/*
151+
* The below is left in, it helps to remove confusion when debugging
152+
for(int rob=0;rob<8;rob++)for(int mcm=0;mcm<16;mcm++)for(int channel=0;channel<21;channel++){
153+
std::cout << "Digit e(0,"<<rob<<"," << mcm <<","<< channel<<");" << std::endl;
154+
Digit e(0,rob,mcm,channel);
155+
std::cout << " e is " << e.getRow() << " " << e.getPad();
156+
std::cout << " for an rob:mcm combo of " << e.getROB() << ":"<< e.getMCM() << " and adc channel:" << e.getChannel() <<std::endl;
157+
std::cout << "Digit f(0,e.getRow(),e.getPad())" << std::endl;;
158+
Digit f(0,e.getRow(),e.getPad());
159+
std::cout << " f is " << f.getRow() << " " << f.getPad();
160+
std::cout << " for an rob:mcm combo of " << f.getROB() << ":"<< f.getMCM() << " and adc channel:" << f.getChannel() <<std::endl;
161+
std::cout << "*********************************************************************" << std::endl;
162+
}
163+
*/
164+
165+
//now check that the timebins get correctly assigned on instantiation
166+
ArrayADC data;
167+
std::iota(data.begin(), data.end(), 42); // 42 for my personal amusement.
168+
Digit z(10, 15, NCOLMCM - 1, data);
169+
testDigitDetROBMCM(z, 10, 6, 12, 2);
170+
//test adc values are true.
171+
BOOST_CHECK(z.getADC()[4] == 46); // 4th time bin should be 46;
172+
BOOST_CHECK(z.getADC()[6] == 48); // 6th time bin should be 48;
173+
174+
Digit za(10, 6, 0, 2, data);
175+
testDigitDetRowPad(za, 10, 12, NCOLMCM - 1);
176+
BOOST_CHECK(za.getADC()[14] == 56); // 14th time bin should be 56;
177+
BOOST_CHECK(za.getADC()[16] == 58); // 16th time bin should be 58;
178+
}
179+
180+
} // namespace trd
181+
} // namespace o2

0 commit comments

Comments
 (0)