Skip to content

Commit bac0ea0

Browse files
authored
[EMCAL-604] Initialize Unit Tests for the EMCal Geometry class (#13095)
- GetCellIndex as first function to be tested: - Check sm number, module number, phi and eta index for all valid cells - Check two exceptions for invalid cells - Check against on-the-fly calculation in the testGeometry.cxx file itself - Minor correction in Geometry.cxx to improve readability of the code
1 parent 7d0dc4f commit bac0ea0

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

Detectors/EMCAL/base/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ o2_add_test(Mapper
4242
LABELS emcal
4343
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage)
4444

45+
o2_add_test(Geometry
46+
SOURCES test/testGeometry.cxx
47+
PUBLIC_LINK_LIBRARIES O2::EMCALBase
48+
COMPONENT_NAME emcal
49+
LABELS emcal
50+
ENVIRONMENT O2_ROOT=${CMAKE_BINARY_DIR}/stage)
51+
4552
o2_add_test(RCUTrailer
4653
SOURCES test/testRCUTrailer.cxx
4754
PUBLIC_LINK_LIBRARIES O2::EMCALBase

Detectors/EMCAL/base/src/Geometry.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ std::tuple<int, int, int, int> Geometry::CalculateCellIndex(Int_t absId) const
10261026

10271027
Int_t nModule = tmp / mNCellsInModule;
10281028
tmp = tmp % mNCellsInModule;
1029-
Int_t nIphi = tmp / mNPHIdiv, nIeta = tmp % mNPHIdiv;
1029+
Int_t nIphi = tmp / mNPHIdiv, nIeta = tmp % mNETAdiv;
10301030
return std::make_tuple(nSupMod, nModule, nIphi, nIeta);
10311031
}
10321032

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 Base
12+
#define BOOST_TEST_MAIN
13+
#define BOOST_TEST_DYN_LINK
14+
#include <boost/test/unit_test.hpp>
15+
#include <fmt/format.h>
16+
#include "EMCALBase/Geometry.h"
17+
#include <iostream>
18+
#include <fstream>
19+
20+
std::tuple<int, int, int, int> GetRefCellIndex(int CellId);
21+
22+
/// \macro Test implementation of the EMCAL Geometry
23+
///
24+
/// Test coverage:
25+
/// - GetCellIndex (get #sm, #mod, phi index and eta index): all cells (0-17663)
26+
/// - Invalid CellId: exception test for cell -1 and 17664
27+
BOOST_AUTO_TEST_CASE(Geometry_test)
28+
{
29+
auto testgeometry = o2::emcal::Geometry::GetInstanceFromRunNumber(300000);
30+
31+
// Check GetCellIndex function for all valid cells by comparing to GetRefCellIndex function
32+
for (int iCell = 0; iCell < 17664; iCell++) {
33+
auto [smod, mod, iphi, ieta] = testgeometry->GetCellIndex(iCell);
34+
auto [smod_ref, mod_ref, iphi_ref, ieta_ref] = GetRefCellIndex(iCell);
35+
BOOST_CHECK_EQUAL(smod, smod_ref);
36+
BOOST_CHECK_EQUAL(mod, mod_ref);
37+
BOOST_CHECK_EQUAL(iphi, iphi_ref);
38+
BOOST_CHECK_EQUAL(ieta, ieta_ref);
39+
} // And then check the exeptions of -1 and 17664
40+
BOOST_CHECK_EXCEPTION(testgeometry->GetCellIndex(-1), o2::emcal::InvalidCellIDException, [](o2::emcal::InvalidCellIDException const& mCellID) { return -1; });
41+
BOOST_CHECK_EXCEPTION(testgeometry->GetCellIndex(17664), o2::emcal::InvalidCellIDException, [](o2::emcal::InvalidCellIDException const& mCellID) { return 17664; });
42+
}
43+
44+
std::tuple<int, int, int, int> GetRefCellIndex(int CellId)
45+
{
46+
// Four cells per module:
47+
int ieta = CellId % 2; // cells 0 and 2 (in each module) have eta index 0
48+
int iphi = (CellId % 4 == 2 || CellId % 4 == 3) ? 1 : 0; // cells 0 and 1 (in each module) have phi index 0
49+
50+
int smod = 0, mod = 0; // Super module number and module number
51+
if (CellId >= 0 && CellId < 11520) { // The first 10 super modules are full modules
52+
smod = CellId / 1152; // Their number is their cell number divided by the cells per sm (rounded down)
53+
mod = (CellId % 1152) / 4; // And the module is the cell number within the sm (%) divided by four (four cells in one module)
54+
} else if (CellId >= 11520 && CellId < 12288) { // First two one thirds
55+
smod = 10 + (CellId - 11520) / 384; // +10 to account for the - 11520
56+
mod = ((CellId - 11520) % 384) / 4; // -11520 to subtract all cells in full super modules
57+
} else if (CellId >= 12288 && CellId < 16896) { // Six two third modules
58+
smod = 12 + (CellId - 12288) / 768;
59+
mod = ((CellId - 12288) % 768) / 4;
60+
} else if (CellId >= 16896 && CellId < 17664) { // Second two one third modules
61+
smod = 18 + (CellId - 16896) / 384;
62+
mod = ((CellId - 16896) % 384) / 4;
63+
}
64+
65+
return std::make_tuple(smod, mod, iphi, ieta);
66+
}

0 commit comments

Comments
 (0)