File indexing completed on 2025-06-30 07:55:51
0001
0002
0003
0004 #include <DD4hep/Detector.h>
0005 #include <DD4hep/IDDescriptor.h>
0006 #include <DD4hep/Readout.h>
0007 #include <DD4hep/Segmentations.h>
0008 #include <DD4hep/Objects.h>
0009 #include <algorithms/geo.h>
0010 #include <algorithms/interfaces/ParticleSvc.h>
0011 #include <algorithms/random.h>
0012 #include <algorithms/service.h>
0013 #include <catch2/generators/catch_generators_random.hpp>
0014 #include <catch2/interfaces/catch_interfaces_reporter.hpp>
0015 #include <catch2/reporters/catch_reporter_event_listener.hpp>
0016 #include <catch2/reporters/catch_reporter_registrars.hpp>
0017 #include <services/evaluator/EvaluatorSvc.h>
0018 #include <services/pid_lut/PIDLookupTableSvc.h>
0019 #include <cstddef>
0020 #include <cstdint>
0021 #include <memory>
0022 #include <string>
0023 #include <utility>
0024
0025 class algorithmsInitListener : public Catch::EventListenerBase {
0026 public:
0027 using Catch::EventListenerBase::EventListenerBase;
0028
0029 std::unique_ptr<const dd4hep::Detector> m_detector{nullptr};
0030
0031 void testRunStarting(Catch::TestRunInfo const& ) override {
0032 auto detector = dd4hep::Detector::make_unique("");
0033 detector->addConstant(dd4hep::Constant("MockCalorimeter_ID", "1"));
0034 dd4hep::Readout readout(std::string("MockCalorimeterHits"));
0035 dd4hep::IDDescriptor id_desc("MockCalorimeterHits", "system:8,layer:8,x:8,y:8");
0036 readout.setIDDescriptor(id_desc);
0037 detector->add(id_desc);
0038 detector->add(readout);
0039
0040 detector->addConstant(dd4hep::Constant("MockTracker_ID", "2"));
0041 dd4hep::Readout readoutTracker(std::string("MockTrackerHits"));
0042 dd4hep::IDDescriptor id_desc_tracker("MockTrackerHits", "system:8,layer:8,x:8,y:8");
0043
0044 dd4hep::Segmentation segmentation("CartesianGridXY", "TrackerHitsSeg",
0045 id_desc_tracker.decoder());
0046 readoutTracker.setIDDescriptor(id_desc_tracker);
0047 readoutTracker.setSegmentation(segmentation);
0048 detector->add(id_desc_tracker);
0049 detector->add(readoutTracker);
0050
0051 dd4hep::Readout readoutSilicon(std::string("MockSiliconHits"));
0052 dd4hep::IDDescriptor id_desc_Silicon("MockSiliconHits",
0053 "system:8,layer:4,module:12,sensor:10,x:40:-8,y:-16");
0054
0055 dd4hep::Segmentation segmentation_Silicon("CartesianGridXY", "SiliconHitsSeg",
0056 id_desc_tracker.decoder());
0057 readoutSilicon.setIDDescriptor(id_desc_Silicon);
0058 readoutSilicon.setSegmentation(segmentation_Silicon);
0059 detector->add(id_desc_Silicon);
0060 detector->add(readoutSilicon);
0061
0062 m_detector = std::move(detector);
0063
0064 auto& serviceSvc = algorithms::ServiceSvc::instance();
0065 [[maybe_unused]] auto& geoSvc = algorithms::GeoSvc::instance();
0066 serviceSvc.setInit<algorithms::GeoSvc>([this](auto&& g) { g.init(this->m_detector.get()); });
0067
0068 [[maybe_unused]] auto& randomSvc = algorithms::RandomSvc::instance();
0069 auto seed = Catch::Generators::Detail::getSeed();
0070 serviceSvc.setInit<algorithms::RandomSvc>([seed](auto&& r) {
0071 r.setProperty("seed", static_cast<std::size_t>(seed));
0072 r.init();
0073 });
0074
0075 auto& evaluatorSvc = eicrecon::EvaluatorSvc::instance();
0076 serviceSvc.add<eicrecon::EvaluatorSvc>(&evaluatorSvc);
0077
0078 auto& lutSvc = eicrecon::PIDLookupTableSvc::instance();
0079 serviceSvc.add<eicrecon::PIDLookupTableSvc>(&lutSvc);
0080
0081 auto& particleSvc = algorithms::ParticleSvc::instance();
0082 serviceSvc.add<algorithms::ParticleSvc>(&particleSvc);
0083
0084 serviceSvc.init();
0085 }
0086 };
0087
0088 CATCH_REGISTER_LISTENER(algorithmsInitListener)