Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:55:51

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2023, Dmitry Kalinkin
0003 
0004 #include <DD4hep/Detector.h>
0005 #include <DD4hep/IDDescriptor.h>
0006 #include <DD4hep/Readout.h>
0007 #include <Evaluator/DD4hepUnits.h>
0008 #include <algorithms/geo.h>
0009 #include <algorithms/logger.h>
0010 #include <catch2/catch_test_macros.hpp>
0011 #include <edm4eic/EDM4eicVersion.h>
0012 #if EDM4EIC_VERSION_MAJOR >= 7
0013 #include <edm4eic/MCRecoCalorimeterHitAssociationCollection.h>
0014 #endif
0015 #include <cmath>
0016 #include <edm4hep/CaloHitContributionCollection.h>
0017 #include <edm4hep/RawCalorimeterHitCollection.h>
0018 #include <edm4hep/SimCalorimeterHitCollection.h>
0019 #include <edm4hep/Vector3f.h>
0020 #include <gsl/pointers>
0021 #include <memory>
0022 #include <spdlog/common.h>
0023 #include <spdlog/logger.h>
0024 #include <spdlog/spdlog.h>
0025 #include <utility>
0026 #include <vector>
0027 
0028 #include "algorithms/calorimetry/CalorimeterHitDigi.h"
0029 #include "algorithms/calorimetry/CalorimeterHitDigiConfig.h"
0030 
0031 using eicrecon::CalorimeterHitDigi;
0032 using eicrecon::CalorimeterHitDigiConfig;
0033 
0034 TEST_CASE("the clustering algorithm runs", "[CalorimeterHitDigi]") {
0035   std::shared_ptr<spdlog::logger> logger = spdlog::default_logger()->clone("CalorimeterHitDigi");
0036   logger->set_level(spdlog::level::trace);
0037 
0038   auto detector = algorithms::GeoSvc::instance().detector();
0039   auto id_desc  = detector->readout("MockCalorimeterHits").idSpec();
0040 
0041   CalorimeterHitDigi algo("test");
0042 
0043   CalorimeterHitDigiConfig cfg;
0044   cfg.threshold     = 0. /* GeV */;
0045   cfg.corrMeanScale = "1.";
0046 
0047   // Keep smearing parameters at zero
0048   cfg.pedSigmaADC = 0;
0049   cfg.tRes        = 0. * dd4hep::ns;
0050   cfg.eRes        = {0. * sqrt(dd4hep::GeV), 0., 0. * dd4hep::GeV};
0051   cfg.readout     = "MockCalorimeterHits";
0052 
0053   SECTION("single hit with couple contributions") {
0054     cfg.capADC        = 555;
0055     cfg.dyRangeADC    = 5.0 /* GeV */;
0056     cfg.pedMeanADC    = 123;
0057     cfg.resolutionTDC = 1.0 * dd4hep::ns;
0058     algo.level(algorithms::LogLevel(spdlog::level::trace));
0059     algo.applyConfig(cfg);
0060     algo.init();
0061 
0062     auto calohits = std::make_unique<edm4hep::CaloHitContributionCollection>();
0063     auto simhits  = std::make_unique<edm4hep::SimCalorimeterHitCollection>();
0064     auto mhit     = simhits->create(
0065         id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}),     // std::uint64_t cellID,
0066         1.0 /* GeV */,                                             // float energy
0067         edm4hep::Vector3f({0. /* mm */, 0. /* mm */, 0. /* mm */}) // edm4hep::Vector3f position
0068     );
0069     mhit.addToContributions(calohits->create(
0070         0,                                                         // std::int32_t PDG
0071         0.5 /* GeV */,                                             // float energy
0072         7.0 /* ns */,                                              // float time
0073         edm4hep::Vector3f({0. /* mm */, 0. /* mm */, 0. /* mm */}) // edm4hep::Vector3f stepPosition
0074         ));
0075     mhit.addToContributions(calohits->create(
0076         0,                                                         // std::int32_t PDG
0077         0.5 /* GeV */,                                             // float energy
0078         9.0 /* ns */,                                              // float time
0079         edm4hep::Vector3f({0. /* mm */, 0. /* mm */, 0. /* mm */}) // edm4hep::Vector3f stepPosition
0080         ));
0081 
0082     auto rawhits = std::make_unique<edm4hep::RawCalorimeterHitCollection>();
0083 #if EDM4EIC_VERSION_MAJOR >= 7
0084     auto rawassocs = std::make_unique<edm4eic::MCRecoCalorimeterHitAssociationCollection>();
0085     algo.process({simhits.get()}, {rawhits.get(), rawassocs.get()});
0086 #else
0087     algo.process({simhits.get()}, {rawhits.get()});
0088 #endif
0089 
0090     REQUIRE((*rawhits).size() == 1);
0091     REQUIRE((*rawhits)[0].getCellID() == id_desc.encode({{"system", 255}, {"x", 0}, {"y", 0}}));
0092     REQUIRE((*rawhits)[0].getAmplitude() == 123 + 111);
0093     REQUIRE((*rawhits)[0].getTimeStamp() == 7); // currently, earliest contribution is returned
0094 
0095 #if EDM4EIC_VERSION_MAJOR >= 7
0096     REQUIRE((*rawassocs).size() == 1);
0097     REQUIRE((*rawassocs)[0].getSimHit() == (*simhits)[0]);
0098     REQUIRE((*rawassocs)[0].getRawHit() == (*rawhits)[0]);
0099 #endif
0100   }
0101 }