Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:07

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DDDigi/DigiContainerProcessor.h>
0016 #include <DDDigi/DigiSegmentSplitter.h>
0017 
0018 /// C/C++ include files
0019 #include <cmath>
0020 #include <limits>
0021 
0022 /// Namespace for the AIDA detector description toolkit
0023 namespace dd4hep {
0024 
0025   /// Namespace for the Digitization part of the AIDA detector description toolkit
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       /// Standard constructor
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       /// Create container with ADC counts and register it to the output segment
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   }    // End namespace digi
0071 }      // End namespace dd4hep
0072 //        Factory definition
0073 #include <DDDigi/DigiFactories.h>
0074 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiSimpleADCResponse)
0075