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