Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:17:09

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024, Sebouh Paul
0003 
0004 #include <DD4hep/Detector.h>       // for Detector
0005 #include <DD4hep/IDDescriptor.h>   // for IDDescriptor
0006 #include <DD4hep/Readout.h>        // for Readout
0007 #include <Evaluator/DD4hepUnits.h> // for MeV, mm, keV, ns
0008 #include <algorithms/geo.h>
0009 #include <catch2/catch_test_macros.hpp> // for AssertionHandler, operator""_catch_sr, StringRef, REQUIRE, operator<, operator==, operator>, TEST_CASE
0010 #include <edm4eic/CalorimeterHitCollection.h> // for CalorimeterHitCollection, MutableCalorimeterHit, CalorimeterHitMutableCollectionIterator
0011 #include <edm4hep/Vector3f.h> // for Vector3f
0012 #include <spdlog/common.h>    // for level_enum
0013 #include <spdlog/logger.h>    // for logger
0014 #include <spdlog/spdlog.h>    // for default_logger
0015 #include <array>              // for array
0016 #include <cmath>              // for sqrt, abs
0017 #include <cstddef>
0018 #include <gsl/pointers>
0019 #include <memory> // for allocator, unique_ptr, make_unique, shared_ptr, __shared_ptr_access
0020 #include <string>
0021 #include <utility> // for pair
0022 #include <vector>
0023 
0024 #include "algorithms/calorimetry/HEXPLIT.h"       // for HEXPLIT
0025 #include "algorithms/calorimetry/HEXPLITConfig.h" // for HEXPLITConfig
0026 
0027 using eicrecon::HEXPLIT;
0028 using eicrecon::HEXPLITConfig;
0029 
0030 TEST_CASE("the subcell-splitting algorithm runs", "[HEXPLIT]") {
0031   HEXPLIT algo("HEXPLIT");
0032 
0033   std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("HEXPLIT");
0034   logger->set_level(spdlog::level::trace);
0035 
0036   HEXPLITConfig cfg;
0037   cfg.MIP  = 472. * dd4hep::keV;
0038   cfg.tmax = 1000. * dd4hep::ns;
0039 
0040   auto detector = algorithms::GeoSvc::instance().detector();
0041   auto id_desc  = detector->readout("MockCalorimeterHits").idSpec();
0042 
0043   //create a geometry for the fake detector.
0044   double side_length   = 31.3 * dd4hep::mm;
0045   double layer_spacing = 25.1 * dd4hep::mm;
0046   double thickness     = 3 * dd4hep::mm;
0047 
0048   //dimension of a cell
0049   auto dimension = edm4hep::Vector3f(2 * side_length, sqrt(3) * side_length, thickness);
0050 
0051   algo.applyConfig(cfg);
0052   algo.init();
0053 
0054   edm4eic::CalorimeterHitCollection hits_coll;
0055 
0056   //create a set of 5 hits in consecutive layers, all of which overlap in a single rhombus,
0057   // centered at (3/8, sqrt(3)/8)*side_length
0058   std::array<double, 5> layer = {0, 1, 2, 3, 4};
0059   std::array<double, 5> x     = {0, 0.75 * side_length, 0, 0.75 * side_length, 0};
0060   std::array<double, 5> y     = {sqrt(3) / 2 * side_length, -0.25 * sqrt(3) * side_length, 0,
0061                                  0.25 * sqrt(3) * side_length, sqrt(3) / 2 * side_length};
0062   std::array<double, 5> E = {50 * dd4hep::MeV, 50 * dd4hep::MeV, 50 * dd4hep::MeV, 50 * dd4hep::MeV,
0063                              50 * dd4hep::MeV};
0064   for (std::size_t i = 0; i < 5; i++) {
0065     hits_coll.create(
0066         id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),   // std::uint64_t cellID,
0067         E[i],                                                    // float energy,
0068         0.0,                                                     // float energyError,
0069         0.0,                                                     // float time,
0070         0.0,                                                     // float timeError,
0071         edm4hep::Vector3f(x[i], y[i], layer[i] * layer_spacing), // edm4hep::Vector3f position,
0072         dimension,                                               // edm4hep::Vector3f dimension,
0073         0,                                                       // std::int32_t sector,
0074         layer[i],                                                // std::int32_t layer,
0075         edm4hep::Vector3f(x[i], y[i], layer[i] * layer_spacing)  // edm4hep::Vector3f local
0076     );
0077   }
0078 
0079   auto subcellhits_coll = std::make_unique<edm4eic::CalorimeterHitCollection>();
0080   algo.process({&hits_coll}, {subcellhits_coll.get()});
0081 
0082   //the number of subcell hits should be equal to the
0083   //number of subcells per cell (12) times the number of cells (5)
0084   REQUIRE((*subcellhits_coll).size() == 60);
0085 
0086   //next check that the sum of the hit energies equals the energy that I gave the hits
0087   double tol  = 0.001;
0088   double Esum = 0;
0089   int i       = 0;
0090   for (auto subcell : *subcellhits_coll) {
0091     Esum += subcell.getEnergy();
0092     i++;
0093     if (i % 12 == 0) {
0094       REQUIRE(std::abs(Esum - E[i / 12 - 1]) / E[i / 12 - 1] < tol);
0095       Esum = 0;
0096     }
0097   }
0098   // next check that almost all of the energy of the hit in the middle layer
0099   // is in the subcell where the other hits overlap
0100   REQUIRE((*subcellhits_coll)[35].getEnergy() / E[2] > 0.95);
0101 }