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 - 2025, Sebouh Paul, Dmitry Kalinkin
0003 
0004 #include <catch2/catch_test_macros.hpp>
0005 #include <catch2/matchers/catch_matchers.hpp>
0006 #include <catch2/matchers/catch_matchers_floating_point.hpp>
0007 #include <edm4eic/CalorimeterHitCollection.h>
0008 #include <edm4eic/ClusterCollection.h>
0009 #include <edm4eic/MCRecoClusterParticleAssociationCollection.h>
0010 #include <edm4eic/unit_system.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <edm4hep/utils/vector_utils.h>
0013 #include <spdlog/common.h>
0014 #include <spdlog/logger.h>
0015 #include <spdlog/spdlog.h>
0016 #include <cmath>
0017 #include <memory>
0018 #include <string>
0019 #include <tuple>
0020 
0021 #include "algorithms/calorimetry/CalorimeterClusterShape.h"
0022 #include "algorithms/calorimetry/CalorimeterClusterShapeConfig.h"
0023 
0024 using eicrecon::CalorimeterClusterShape;
0025 using eicrecon::CalorimeterClusterShapeConfig;
0026 
0027 TEST_CASE("the calorimeter CoG algorithm runs", "[CalorimeterClusterShape]") {
0028   const float EPSILON = 1e-5;
0029 
0030   CalorimeterClusterShape algo("CalorimeterClusterShape");
0031 
0032   std::shared_ptr<spdlog::logger> logger =
0033       spdlog::default_logger()->clone("CalorimeterClusterShape");
0034   logger->set_level(spdlog::level::trace);
0035 
0036   CalorimeterClusterShapeConfig cfg;
0037   cfg.longitudinalShowerInfoAvailable = true;
0038 
0039   algo.applyConfig(cfg);
0040   algo.init();
0041 
0042   edm4eic::CalorimeterHitCollection hits_coll;
0043   edm4eic::MCRecoClusterParticleAssociationCollection assoc_in_coll;
0044   edm4eic::ClusterCollection clust_in_coll;
0045   auto assoc_out_coll = std::make_unique<edm4eic::MCRecoClusterParticleAssociationCollection>();
0046   auto clust_out_coll = std::make_unique<edm4eic::ClusterCollection>();
0047 
0048   auto hit1 = hits_coll.create();
0049   hit1.setCellID(0);
0050   hit1.setEnergy(0.1 * edm4eic::unit::GeV);
0051   hit1.setEnergyError(0);
0052   hit1.setTime(0);
0053   hit1.setTimeError(0);
0054   hit1.setPosition(edm4hep::Vector3f{0, 0, 1 * edm4eic::unit::mm});
0055   hit1.setDimension({0, 0, 0});
0056   hit1.setLocal(edm4hep::Vector3f{0, 0, 1 * edm4eic::unit::mm});
0057 
0058   auto hit2 = hits_coll.create();
0059   hit2.setCellID(1);
0060   hit2.setEnergy(0.1 * edm4eic::unit::GeV);
0061   hit2.setEnergyError(0);
0062   hit2.setTime(0);
0063   hit2.setTimeError(0);
0064   hit2.setPosition(edm4hep::Vector3f{-1 * edm4eic::unit::mm, 0, 2 * edm4eic::unit::mm});
0065   hit2.setDimension({0, 0, 0});
0066   hit2.setLocal(edm4hep::Vector3f{-1 * edm4eic::unit::mm, 0, 2 * edm4eic::unit::mm});
0067 
0068   // Create a cluster with 2 hits
0069   auto clust_in = clust_in_coll.create();
0070   clust_in.addToHits(hit1);
0071   clust_in.addToHitContributions(hit1.getEnergy());
0072   clust_in.addToHits(hit2);
0073   clust_in.addToHitContributions(hit2.getEnergy());
0074   clust_in.setNhits(clust_in.hits_size());
0075   clust_in.setEnergy(hit1.getEnergy() + hit2.getEnergy());
0076   clust_in.setPosition((hit1.getPosition() + hit2.getPosition()) / 2);
0077 
0078   auto assoc_in = assoc_in_coll.create();
0079   assoc_in.setWeight(0.123);
0080   assoc_in.setRec(clust_in);
0081   // assoc_in.setSim(...);
0082 
0083   // Constructing input and output as per the algorithm's expected signature
0084   auto input  = std::make_tuple(&clust_in_coll, &assoc_in_coll);
0085   auto output = std::make_tuple(clust_out_coll.get(), assoc_out_coll.get());
0086 
0087   algo.process(input, output);
0088 
0089   REQUIRE(clust_out_coll->size() == 1);
0090   auto clust_out = (*clust_out_coll)[0];
0091   REQUIRE(clust_in.getNhits() == clust_out.getNhits());
0092 
0093   REQUIRE_THAT(clust_out.getIntrinsicTheta(), Catch::Matchers::WithinAbs(M_PI / 4, EPSILON));
0094   // std::abs() checks if we land on -M_PI
0095   REQUIRE_THAT(std::abs(clust_out.getIntrinsicPhi()), Catch::Matchers::WithinAbs(M_PI, EPSILON));
0096 
0097   REQUIRE(assoc_out_coll->size() == 1);
0098   REQUIRE((*assoc_out_coll)[0].getRec() == clust_out);
0099   REQUIRE((*assoc_out_coll)[0].getWeight() == assoc_in.getWeight());
0100 }