File indexing completed on 2025-01-18 09:14:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDDigi/DigiContainerProcessor.h>
0016 #include <DDDigi/DigiSegmentSplitter.h>
0017
0018
0019 #include <cmath>
0020 #include <limits>
0021
0022
0023 namespace dd4hep {
0024
0025
0026 namespace digi {
0027
0028 class DigiSimpleADCResponse : public DigiDepositsProcessor {
0029 using segmentation_t = DigiSegmentProcessContext;
0030 std::string m_response_postfix { ".adc" };
0031 std::string m_history_postfix { ".hist" };
0032 double m_signal_saturation { std::numeric_limits<double>::max() };
0033 double m_adc_offset { 0e0 };
0034 std::size_t m_adc_resolution { 1024 };
0035
0036 public:
0037
0038 DigiSimpleADCResponse(const DigiKernel& krnl, const std::string& nam)
0039 : DigiDepositsProcessor(krnl, nam)
0040 {
0041 declareProperty("saturation", m_signal_saturation);
0042 declareProperty("adc_resolution", m_adc_resolution);
0043 declareProperty("response_postfix", m_response_postfix);
0044 declareProperty("history_postfix", m_history_postfix);
0045 DEPOSIT_PROCESSOR_BIND_HANDLERS(DigiSimpleADCResponse::emulate_adc);
0046 }
0047
0048
0049 template <typename T>
0050 void emulate_adc(DigiContext& context, const T& input, work_t& work, const predicate_t& predicate) const {
0051 const char* tag = context.event->id();
0052 std::string postfix = predicate.segmentation ? "."+predicate.segmentation->identifier(predicate.id) : std::string();
0053 std::string response_name = input.name + postfix + m_response_postfix;
0054 DetectorResponse response(response_name, work.environ.output.mask);
0055 for( const auto& dep : input ) {
0056 if ( predicate(dep) ) {
0057 CellID cell = dep.first;
0058 const auto& depo = dep.second;
0059 double offset_ene = depo.deposit-m_adc_offset;
0060 ADCValue::value_t adc_count = std::round(((offset_ene) * m_adc_resolution) / m_signal_saturation);
0061 adc_count = std::min(adc_count, ADCValue::value_t(m_adc_resolution));
0062 response.emplace(cell, {adc_count, ADCValue::address_t(cell)});
0063 }
0064 }
0065 info("%s+++ %-32s %6ld ADC values. Input: %-32s %6ld deposits", tag,
0066 response_name.c_str(), response.size(), input.name.c_str(), input.size());
0067 work.environ.output.data.put(response.key, std::move(response));
0068 }
0069 };
0070 }
0071 }
0072
0073 #include <DDDigi/DigiFactories.h>
0074 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiSimpleADCResponse)
0075