Project
Loading...
Searching...
No Matches
testTPCDigitContainer.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
15
16#define BOOST_TEST_MODULE Test TPC DigitContainer
17#define BOOST_TEST_MAIN
18#define BOOST_TEST_DYN_LINK
19#include <boost/test/unit_test.hpp>
20#include <memory>
21#include <vector>
22#include <fmt/format.h>
27
28namespace o2
29{
30namespace tpc
31{
32
36BOOST_AUTO_TEST_CASE(DigitContainer_test1)
37{
38 auto& cdb = CDBInterface::instance();
39 cdb.setUseDefaults();
40 o2::conf::ConfigurableParam::updateFromString(fmt::format("TPCEleParam.DigiMode={}", (int)o2::tpc::DigitzationMode::PropagateADC)); // propagate the ADC values, otherwise the computation get complicated
41 const Mapper& mapper = Mapper::instance();
43 DigitContainer digitContainer;
45 digitContainer.reset();
46
47 const std::vector<int> MCevent = {1, 250, 3, 62, 1000};
48 const std::vector<int> MCtrack = {22, 3, 4, 23, 523};
49 const std::vector<int> cru = {0, 0, 0, 0, 0};
50 const std::vector<int> Time = {231, 2, 500, 230, 1};
51 const std::vector<int> Row = {12, 5, 6, 2, 6};
52 const std::vector<int> Pad = {1, 15, 14, 23, 5};
53 const std::vector<int> nEle = {60, 100, 250, 1023, 2};
54
55 const std::vector<int> timeMapping = {4, 1, 3, 0, 2};
56
57 for (int i = 0; i < cru.size(); ++i) {
58 const GlobalPadNumber globalPad = mapper.getPadNumberInROC(PadROCPos(CRU(cru[i]).roc(), PadPos(Row[i], Pad[i])));
59 digitContainer.addDigit(MCCompLabel(MCtrack[i], MCevent[i], 0, false), cru[i], Time[i], globalPad, nEle[i]);
60 }
61
62 std::vector<Digit> mDigitsArray;
63 std::vector<o2::tpc::CommonMode> commonMode;
64 digitContainer.fillOutputContainer(mDigitsArray, mMCTruthArray, commonMode, 0, 0, true, true);
65
66 for (size_t i = 0; i < commonMode.size(); ++i) {
67 auto digit = mDigitsArray[i];
68 const CRU cru = digit.getCRU();
69 const auto gemStack = cru.gemStack();
70 const float nPads = mapper.getNumberOfPads(GEMstack(gemStack));
71 BOOST_CHECK_CLOSE(commonMode[i].getCommonMode(), digit.getChargeFloat() * 0.5f / nPads, 1E-6);
72 }
73
74 BOOST_CHECK(cru.size() == mDigitsArray.size());
75
76 int digits = 0;
77 for (auto& digit : mDigitsArray) {
78 const int trueDigit = timeMapping[digits];
79 gsl::span<const o2::MCCompLabel> mcArray = mMCTruthArray.getLabels(digits);
80 for (int j = 0; j < static_cast<int>(mcArray.size()); ++j) {
81 BOOST_CHECK(mMCTruthArray.getElement(mMCTruthArray.getMCTruthHeader(digits).index + j).getTrackID() ==
82 MCtrack[trueDigit]);
83 BOOST_CHECK(mMCTruthArray.getElement(mMCTruthArray.getMCTruthHeader(digits).index + j).getEventID() ==
84 MCevent[trueDigit]);
85 }
86 BOOST_CHECK(digit.getCRU() == cru[trueDigit]);
87 BOOST_CHECK(digit.getTimeStamp() == Time[trueDigit]);
88 BOOST_CHECK(digit.getRow() == Row[trueDigit]);
89 BOOST_CHECK(digit.getPad() == Pad[trueDigit]);
90 ++digits;
91 }
92}
93
96BOOST_AUTO_TEST_CASE(DigitContainer_test2)
97{
98 auto& cdb = CDBInterface::instance();
99 cdb.setUseDefaults();
100 o2::conf::ConfigurableParam::updateFromString(fmt::format("TPCEleParam.DigiMode={}", (int)o2::tpc::DigitzationMode::PropagateADC)); // propagate the ADC values, otherwise the computation get complicated
101 const Mapper& mapper = Mapper::instance();
103 DigitContainer digitContainer;
104 digitContainer.reset();
106
107 // MC labels to add to each voxel
108 const std::vector<int> MCevent = {1, 62, 1, 62, 62, 50, 62, 1, 1, 1};
109 const std::vector<int> MCtrack = {22, 3, 22, 3, 3, 70, 3, 7, 7, 7};
110
111 // voxel definitions
112 const std::vector<int> cru = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
113 const std::vector<int> Time = {231, 231, 231, 231, 231, 231, 231, 231, 231, 231};
114 const std::vector<int> Row = {11, 11, 11, 11, 11, 11, 11, 11, 11, 11}; // the last region only has 12 rows, so the row number should not exceed 11
115 const std::vector<int> Pad = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15};
116 const std::vector<int> nEle = {60, 1, 252, 10, 2, 3, 5, 25, 24, 23};
117
118 // the resulting MC labels should be sorted by the number of occurrance, the one with
119 // the highest occurrance first
120 const std::vector<int> MCeventSorted = {62, 1, 1, 50};
121 const std::vector<int> MCtrackSorted = {3, 7, 22, 70};
122
123 for (int i = 0; i < cru.size(); ++i) {
124 const CRU c(cru[i]);
125 const DigitPos digiPadPos(c, PadPos(Row[i], Pad[i]));
126 const GlobalPadNumber globalPad = mapper.globalPadNumber(digiPadPos.getGlobalPadPos());
127
128 // add labels to each voxel, sum up the charge MCevent.size() times
129 for (int j = 0; j < MCevent.size(); ++j) {
130 digitContainer.addDigit(MCCompLabel(MCtrack[j], MCevent[j], 0, false), cru[i], Time[i], globalPad, nEle[i]);
131 }
132 }
133
134 std::vector<Digit> mDigitsArray;
135 std::vector<o2::tpc::CommonMode> commonMode;
136 digitContainer.fillOutputContainer(mDigitsArray, mMCTruthArray, commonMode, 0, 0, true, true);
137
138 BOOST_CHECK(mDigitsArray.size() == cru.size());
139
140 std::array<float, GEMSTACKSPERSECTOR> chargeSum;
141 chargeSum.fill(0);
142 int digits = 0;
143 for (const auto& digit : mDigitsArray) {
144 // check MC labels and proper sorting
145 const auto& mcArray = mMCTruthArray.getLabels(digits);
146 BOOST_CHECK(mcArray.size() == MCtrackSorted.size());
147 for (int j = 0; j < static_cast<int>(mcArray.size()); ++j) {
148 BOOST_CHECK(mcArray[j].getTrackID() == MCtrackSorted[j]);
149 BOOST_CHECK(mcArray[j].getEventID() == MCeventSorted[j]);
150 }
151
152 // check digit position
153 const int row = Row[digits] + mapper.getGlobalRowOffsetRegion(CRU(digit.getCRU()).region());
154 BOOST_CHECK(digit.getCRU() == cru[digits]);
155 BOOST_CHECK(digit.getTimeStamp() == Time[digits]);
156 BOOST_CHECK(digit.getRow() == row);
157 BOOST_CHECK(digit.getPad() == Pad[digits]);
158
159 const CRU cru = digit.getCRU();
160 const auto gemStack = cru.gemStack();
161 chargeSum[gemStack] += digit.getChargeFloat() * 0.5f;
162 ++digits;
163 }
164
165 for (size_t i = 0; i < commonMode.size(); ++i) {
166 const float nPads = mapper.getNumberOfPads(GEMstack(i));
167 BOOST_CHECK_CLOSE(commonMode[i].getCommonMode(), chargeSum[i] / nPads, 1E-6);
168 }
169}
170} // namespace tpc
171} // namespace o2
Simple interface to the CDB manager.
Definition of the TPC Digit.
Definition of the Digit Container.
int32_t i
uint32_t roc
Definition RawData.h:3
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Definition of the SAMPA response.
static void updateFromString(std::string const &)
static CDBInterface & instance()
unsigned char region() const
Definition CRU.h:64
GEMstack gemStack() const
Definition CRU.h:82
void fillOutputContainer(std::vector< Digit > &output, dataformats::MCTruthContainer< MCCompLabel > &mcTruth, std::vector< CommonMode > &commonModeOutput, const Sector &sector, TimeBin eventTimeBin=0, bool isContinuous=true, bool finalFlush=false)
void reset()
Reset the container.
void addDigit(const MCCompLabel &label, const CRU &cru, TimeBin timeBin, GlobalPadNumber globalPad, float signal)
PadPos getGlobalPadPos() const
Definition DigitPos.cxx:20
int getGlobalRowOffsetRegion(int region) const
Definition Mapper.h:313
GlobalPadNumber globalPadNumber(const PadPos &globalPadPosition) const
Definition Mapper.h:56
static Mapper & instance(const std::string mappingDir="")
Definition Mapper.h:44
static constexpr unsigned short getNumberOfPads(const GEMstack gemStack)
Definition Mapper.h:416
GlobalPadNumber getPadNumberInROC(const PadROCPos &rocPadPosition) const
Definition Mapper.h:96
Pad and row inside a ROC.
Definition PadROCPos.h:37
static SAMPAProcessing & instance()
BOOST_AUTO_TEST_CASE(ClusterHardware_test1)
GEMstack
TPC GEM stack types.
Definition Defs.h:53
@ PropagateADC
Just propagate the bare ADC value.
unsigned short GlobalPadNumber
global pad number
Definition Defs.h:129
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK(tree)
std::vector< Digit > digits
std::vector< int > row