File indexing completed on 2025-04-04 08:02:27
0001
0002
0003
0004 #include <catch2/catch_test_macros.hpp>
0005 #include <catch2/generators/catch_generators.hpp>
0006 #include <edm4eic/unit_system.h>
0007 #include <edm4hep/SimTrackerHitCollection.h>
0008 #include <edm4hep/TimeSeriesCollection.h>
0009 #include <podio/RelationRange.h>
0010 #include <cmath>
0011 #include <memory>
0012 #include <string>
0013 #include <tuple>
0014 #include <vector>
0015
0016 #include "algorithms/digi/SiliconPulseGeneration.h"
0017 #include "algorithms/digi/SiliconPulseGenerationConfig.h"
0018
0019 TEST_CASE("SiliconPulseGeneration generates correct number of pulses", "[SiliconPulseGeneration]") {
0020
0021 eicrecon::SiliconPulseGeneration algo("SiliconPulseGeneration");
0022 eicrecon::SiliconPulseGenerationConfig cfg;
0023 cfg.pulse_shape_function = "LandauPulse";
0024 cfg.pulse_shape_params = {1.0,1.0};
0025
0026 algo.applyConfig(cfg);
0027 algo.init();
0028
0029 SECTION("from different hits") {
0030 auto nHits = GENERATE(1, 2, 3);
0031
0032 edm4hep::SimTrackerHitCollection hits_coll;
0033
0034 for(int i=0; i<nHits; i++) {
0035 hits_coll.create(12345 + i, 10.0, 5.0);
0036 }
0037
0038 auto pulses = std::make_unique<edm4hep::TimeSeriesCollection>();
0039
0040 auto input = std::make_tuple(&hits_coll);
0041 auto output = std::make_tuple(pulses.get());
0042
0043 algo.process(input, output);
0044
0045 REQUIRE(pulses->size() == nHits);
0046 REQUIRE((*pulses)[0].getCellID() == 12345);
0047 if(nHits > 1) {
0048 REQUIRE((*pulses)[1].getCellID() == 12346);
0049 }
0050 if(nHits > 2) {
0051 REQUIRE((*pulses)[2].getCellID() == 12347);
0052 }
0053 }
0054
0055 }
0056
0057 TEST_CASE("Test the EvaluatorSvc pulse generation with a square pulse", "[SiliconPulseGeneration]") {
0058
0059 eicrecon::SiliconPulseGeneration algo("SiliconPulseGeneration");
0060 eicrecon::SiliconPulseGenerationConfig cfg;
0061
0062
0063 std::string expression = "(time >= param0 && time < param1) ? charge : 0";
0064
0065 double startTime = 0.0 * edm4eic::unit::ns;
0066 double endTime = 1.0 * edm4eic::unit::ns;
0067 int nTimeBins = 10;
0068 double timeStep = (endTime-startTime)/nTimeBins;
0069
0070 cfg.pulse_shape_function = expression;
0071 cfg.pulse_shape_params = {startTime, endTime};
0072 cfg.ignore_thres = 1;
0073 cfg.timestep = timeStep;
0074 cfg.min_sampling_time = startTime+timeStep;
0075
0076 algo.applyConfig(cfg);
0077 algo.init();
0078
0079 double charge = 10.0*cfg.ignore_thres;
0080 double time = GENERATE_COPY(0.0, 0.5*timeStep, timeStep);
0081 float rounded_time = std::floor(time / timeStep) * timeStep;
0082
0083 edm4hep::SimTrackerHitCollection hits_coll;
0084 hits_coll.create(12345, charge, time);
0085
0086 auto pulses = std::make_unique<edm4hep::TimeSeriesCollection>();
0087
0088 auto input = std::make_tuple(&hits_coll);
0089 auto output = std::make_tuple(pulses.get());
0090
0091 algo.process(input,output);
0092
0093 REQUIRE(pulses->size() == 1);
0094 REQUIRE((*pulses)[0].getCellID() == 12345);
0095 REQUIRE((*pulses)[0].getTime() == rounded_time);
0096 auto amplitudes = (*pulses)[0].getAmplitude();
0097 REQUIRE(amplitudes.size() == nTimeBins);
0098 for(auto amplitude:amplitudes){
0099 REQUIRE(amplitude == charge);
0100 }
0101 }