Project
Loading...
Searching...
No Matches
testRecoContainer.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#define BOOST_TEST_MODULE Test EMCAL Reconstruction
12#define BOOST_TEST_MAIN
13#define BOOST_TEST_DYN_LINK
14#include <boost/test/unit_test.hpp>
15#include <algorithm>
16#include <map>
17#include <vector>
18#include <gsl/span>
22
23namespace o2
24{
25namespace emcal
26{
27
28BOOST_AUTO_TEST_CASE(RecoContainer_test)
29{
30 RecoContainer testcontainer;
31
32 std::map<o2::InteractionRecord, int> truthNumberCells, truthNumberLEDMONs;
33
34 // test 1: Check appending cells to existing container
35 o2::InteractionRecord testIR(1023, 384128);
36 auto& currentEvent = testcontainer.getEventContainer(testIR);
37
38 std::vector<int> towers1 = {12, 382, 922, 1911};
39 std::vector<double> energies1 = {0.2, 10., 1.1, 0.4};
40 std::vector<double> times1 = {1, 29, 0, 2};
41
42 for (int icell = 0; icell < 4; icell++) {
43 currentEvent.setCell(towers1[icell], energies1[icell], times1[icell], ChannelType_t::HIGH_GAIN, 9238, 1, true);
44 }
45
46 BOOST_CHECK_EQUAL(currentEvent.getCells().size(), 4);
47
48 std::vector<int> towers2 = {57, 292, 4592, 11922};
49 std::vector<double> energies2 = {0.2, 10., 1.1, 0.4};
50 std::vector<double> times2 = {10, 3, 1, 5};
51 auto& newcurrent = testcontainer.getEventContainer(testIR);
52 for (int icell = 0; icell < 4; icell++) {
53 newcurrent.setCell(towers2[icell], energies2[icell], times2[icell], ChannelType_t::HIGH_GAIN, 9238, 2, true);
54 }
55
56 BOOST_CHECK_EQUAL(newcurrent.getCells().size(), 8);
57 BOOST_CHECK_EQUAL(testcontainer.getNumberOfEvents(), 1);
58 truthNumberCells[testIR] = 8;
59 truthNumberLEDMONs[testIR] = 0;
60
61 // test 2: Adding new event to container
62 o2::InteractionRecord secondIR(2021, 384130);
63 auto& secondevent = testcontainer.getEventContainer(secondIR);
64 BOOST_CHECK_EQUAL(testcontainer.getNumberOfEvents(), 2);
65 BOOST_CHECK_EQUAL(secondevent.getCells().size(), 0);
66
67 // test 3: Merge HG and LG cells
68 secondevent.setCell(1023, 1.41023, 0.2, ChannelType_t::HIGH_GAIN, 2902, 1, true);
69 secondevent.setCell(1023, 1.4013, 0.91, ChannelType_t::LOW_GAIN, 2902, 1, true);
70 secondevent.setCell(2821, 16.2, 6, ChannelType_t::HIGH_GAIN, 1293, 3, true);
71 secondevent.setCell(2821, 129., 10, ChannelType_t::LOW_GAIN, 1293, 3, true);
72 BOOST_CHECK_EQUAL(secondevent.getCells().size(), 2);
73 int nCellHG = 0, nCellLG = 0;
74 for (const auto& cell : secondevent.getCells()) {
75 switch (cell.mCellData.getType()) {
77 nCellHG++;
78 break;
80 nCellLG++;
81 break;
82
83 default:
84 break;
85 }
86 }
87 BOOST_CHECK_EQUAL(nCellHG, 1);
88 BOOST_CHECK_EQUAL(nCellLG, 1);
89
90 // test 4: test LGnoHG and HGSaturated
91 secondevent.setCell(12034, 0.3, 10, ChannelType_t::LOW_GAIN, 3942, 10, true);
92 secondevent.setCell(12392, 18., 94, ChannelType_t::HIGH_GAIN, 1209, 20, true);
93 int nLGnoHG = 0, nHGOutOfRange = 0;
94 for (const auto& cell : secondevent.getCells()) {
95 if (cell.mIsLGnoHG) {
96 nLGnoHG++;
97 }
98 if (cell.mHGOutOfRange) {
99 nHGOutOfRange++;
100 }
101 }
102 BOOST_CHECK_EQUAL(nLGnoHG, 1);
103 BOOST_CHECK_EQUAL(nHGOutOfRange, 1);
104
105 // test 5: test LEDMon Cells
106 std::vector<int> ledmonTowers = {293, 3842, 1820};
107 std::vector<double> ledmonEnergies = {5.4, 5.2, 6.2};
108 std::vector<double> ledmonTimes = {230, 303, 280};
109 for (int iledmon = 0; iledmon < 3; iledmon++) {
110 secondevent.setLEDMONCell(ledmonTowers[iledmon], ledmonEnergies[iledmon], ledmonTimes[iledmon], ChannelType_t::HIGH_GAIN, 3302, 20, true);
111 }
112 BOOST_CHECK_EQUAL(secondevent.getCells().size(), 4);
113 BOOST_CHECK_EQUAL(secondevent.getLEDMons().size(), 3);
114 truthNumberCells[secondIR] = 4;
115 truthNumberLEDMONs[secondIR] = 3;
116
117 // test 6: test sorting of collisions
118 std::vector<o2::InteractionRecord> collisions{testIR, secondIR};
119 std::sort(collisions.begin(), collisions.end(), std::less<>());
120 auto sortedCollisions = testcontainer.getOrderedInteractions();
121 BOOST_CHECK_EQUAL_COLLECTIONS(collisions.begin(), collisions.end(), sortedCollisions.begin(), sortedCollisions.end());
122
123 // test 7: read the container
124 RecoContainerReader iterator(testcontainer);
125 std::vector<o2::InteractionRecord> foundInteractions;
126 std::map<o2::InteractionRecord, int> foundNCells, foundLEDMONs;
127 while (iterator.hasNext()) {
128 auto& event = iterator.nextEvent();
129 foundInteractions.push_back(event.getInteractionRecord());
130 foundNCells[event.getInteractionRecord()] = event.getNumberOfCells();
131 foundLEDMONs[event.getInteractionRecord()] = event.getNumberOfLEDMONs();
132 if (event.getNumberOfCells()) {
133 // test sorting cells
134 event.sortCells(false);
135 int lastcell = -1;
136 for (const auto& cell : event.getCells()) {
137 if (lastcell > -1) {
138 BOOST_CHECK_LT(lastcell, cell.mCellData.getTower());
139 }
140 lastcell = cell.mCellData.getTower();
141 }
142 }
143 if (event.getNumberOfLEDMONs()) {
144 // test sorting LEDMONS
145 event.sortCells(true);
146 int lastLEDMON = -1;
147 for (const auto& ledmon : event.getLEDMons()) {
148 if (lastLEDMON > -1) {
149 BOOST_CHECK_LT(lastLEDMON, ledmon.mCellData.getTower());
150 }
151 lastLEDMON = ledmon.mCellData.getTower();
152 }
153 }
154 }
155 BOOST_CHECK_EQUAL_COLLECTIONS(collisions.begin(), collisions.end(), foundInteractions.begin(), foundInteractions.end());
156 for (auto truthCell = truthNumberCells.begin(), foundCell = foundNCells.begin(); truthCell != truthNumberCells.end(); truthCell++, foundCell++) {
157 BOOST_CHECK_EQUAL(truthCell->first.bc, foundCell->first.bc);
158 BOOST_CHECK_EQUAL(truthCell->first.orbit, foundCell->first.orbit);
159 BOOST_CHECK_EQUAL(truthCell->second, foundCell->second);
160 }
161 for (auto truthLEDMON = truthNumberLEDMONs.begin(), foundLEDMON = foundLEDMONs.begin(); truthLEDMON != truthNumberLEDMONs.end(); truthLEDMON++, foundLEDMON++) {
162 BOOST_CHECK_EQUAL(truthLEDMON->first.bc, foundLEDMON->first.bc);
163 BOOST_CHECK_EQUAL(truthLEDMON->first.orbit, foundLEDMON->first.orbit);
164 BOOST_CHECK_EQUAL(truthLEDMON->second, foundLEDMON->second);
165 }
166
167 // test 8: reset Container
168 testcontainer.reset();
169 BOOST_CHECK_EQUAL(testcontainer.getNumberOfEvents(), 0);
170}
171
172} // namespace emcal
173} // namespace o2
Reconstruction container for EMCAL Cells and LEDMONs.
void setCell(int tower, double energy, double time, ChannelType_t celltype, int hwaddress, int ddlID, bool doMergeHGLG)
Add cell information to the event container.
int getNumberOfCells() const
Get the number of cells in the event.
Iterator over reco containers.
EventContainer & nextEvent()
Get the next event in container.
bool hasNext() const
Check whehter there are more events in the container.
Handler for cells/LEDMONS/Trigger data in timeframes.
std::size_t getNumberOfEvents() const
Get number of events in container.
EventContainer & getEventContainer(const o2::InteractionRecord &currentIR)
Get container for trigger.
void reset()
Clear container.
std::vector< o2::InteractionRecord > getOrderedInteractions() const
Get sorted vector interaction records of triggers in container.
struct _cl_event * event
Definition glcorearb.h:2982
BOOST_AUTO_TEST_CASE(asynch_schedule_test)
@ HIGH_GAIN
High gain channel.
Definition Constants.h:35
@ LOW_GAIN
Low gain channel.
Definition Constants.h:34
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())