Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:11

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/DigiKernel.h>
0017 
0018 #include <DD4hep/DD4hepUnits.h>
0019 #include <DD4hep/Detector.h>
0020 #include <DD4hep/VolumeManager.h>
0021 
0022 /// C/C++ include files
0023 #include <limits>
0024 
0025 /// Namespace for the AIDA detector description toolkit
0026 namespace dd4hep {
0027   /// Namespace for the Digitization part of the AIDA detector description toolkit
0028   namespace digi {
0029 
0030     /// Actor to smear geographically energy deposits
0031     /**
0032      *
0033      *
0034      *  \author  M.Frank
0035      *  \version 1.0
0036      *  \ingroup DD4HEP_DIGITIZATION
0037      */
0038     class DigiDepositSmearPositionResolution : public DigiDepositsProcessor   {
0039     protected:
0040       /// Property: Resolution in loacl sensor's U coordinates along (1, 0, 0)
0041       double m_resolution_u     { 0e0 * dd4hep::mm };
0042       /// Property: Resolution in loacl sensor's V coordinates along (0, 1, 0)
0043       double m_resolution_v     { 0e0 * dd4hep::mm };
0044 
0045       /// Optional local position monitor
0046       DigiDepositMonitor* m_local_monitor { nullptr };
0047 
0048     public:
0049       /// Standard constructor
0050       DigiDepositSmearPositionResolution(const DigiKernel& krnl, const std::string& nam)
0051         : DigiDepositsProcessor(krnl, nam)
0052       {
0053         declareProperty("resolution_u",               m_resolution_u);
0054         declareProperty("resolution_v",               m_resolution_v);
0055         DEPOSIT_PROCESSOR_BIND_HANDLERS(DigiDepositSmearPositionResolution::smear);
0056       }
0057 
0058       /// Create deposit mapping with updates on same cellIDs
0059       template <typename T> void
0060       smear(DigiContext& context, T& cont, work_t& /* work */, const predicate_t& predicate)  const  {
0061         VolumeManager volMgr = m_kernel.detectorDescription().volumeManager();
0062         auto& random = context.randomGenerator();
0063         std::size_t updated = 0UL;
0064 
0065         for( auto& dep : cont )    {
0066           if ( predicate(dep) )   {
0067             CellID cell = dep.first;
0068             EnergyDeposit& depo = dep.second;
0069             auto*     ctxt = volMgr.lookupContext(cell);
0070             Position  local_pos = ctxt->worldToLocal(depo.position);
0071             double    delta_u   = m_resolution_u * random.gaussian();
0072             double    delta_v   = m_resolution_v * random.gaussian();
0073             Position  delta_pos(delta_u, delta_v, 0e0);
0074             Position  oldpos = depo.position;
0075             Position  newpos = ctxt->localToWorld(local_pos + delta_pos);
0076 
0077             if ( m_local_monitor ) m_local_monitor->position_shift(dep, local_pos, delta_pos);
0078             delta_pos = newpos - oldpos;
0079             if ( m_monitor ) m_monitor->position_shift(dep, oldpos, delta_pos);
0080 
0081             info("+++ %016lX Smeared position [%9.2e %9.2e %9.2e] by [%9.2e %9.2e %9.2e] to [%9.2e %9.2e %9.2e] [mm]",
0082                  oldpos.X(), oldpos.Y(), oldpos.Z(), delta_pos.X(), delta_pos.Y(), delta_pos.Z(),
0083                  newpos.X(), newpos.Y(), newpos.Z());
0084 
0085             depo.position = newpos;
0086             depo.flag |= EnergyDeposit::POSITION_SMEARED;
0087             ++updated;
0088           }
0089         }
0090         info("%s+++ %-32s Smear position(resolution): updated %6ld out of %6ld entries from mask: %04X",
0091              context.event->id(), cont.name.c_str(), updated, cont.size(), cont.key.mask());
0092       }
0093     };
0094   }    // End namespace digi
0095 }      // End namespace dd4hep
0096 
0097 #include <DDDigi/DigiFactories.h>
0098 DECLARE_DIGIACTION_NS(dd4hep::digi,DigiDepositSmearPositionResolution)