Back to home page

EIC code displayed by LXR

 
 

    


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

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 <DD4hep/InstanceCount.h>
0016 #include <DDDigi/DigiKernel.h>
0017 #include <DDDigi/DigiDepositMonitor.h>
0018 
0019 /// ROOT include filess
0020 #include <TH1F.h>
0021 #include <TH2F.h>
0022 
0023 /// C/C++ include files
0024 
0025 using namespace dd4hep::digi;
0026 
0027 /// Add 1D histogram entry with weight
0028 void Histo1D::fill(double x, double weight)    {
0029   hist->Fill(x, weight);
0030 }
0031 
0032 /// Add 2D histogram entry with weight
0033 void Histo2D::fill(double x, double y, double weight)    {
0034   hist->Fill(x, y, weight);
0035 }
0036 
0037 /// Standard constructor
0038 DigiDepositMonitor::DigiDepositMonitor(const DigiKernel& krnl, const std::string& nam)
0039   : DigiAction(krnl, nam)
0040 {
0041   m_kernel.register_initialize(std::bind(&DigiDepositMonitor::initialize,this));
0042   InstanceCount::increment(this);
0043 }
0044 
0045 /// Default destructor
0046 DigiDepositMonitor::~DigiDepositMonitor() {
0047   InstanceCount::decrement(this);
0048 }
0049 
0050 /// Initializing function: compute values which depend on properties
0051 void DigiDepositMonitor::initialize()    {
0052 }
0053 
0054 /// Book 1D histogram and register it to the kernel for output handling
0055 Histo1D DigiDepositMonitor::book1D(const std::string& name, const std::string& title,
0056                    std::size_t nbin_x, double min_x, double max_x)   {
0057   auto* h = new TH1F(name.c_str(), title.c_str(), nbin_x, min_x, max_x);
0058   m_kernel.register_monitor(this, h);
0059   return { h };
0060 }
0061 
0062 /// Book 1D histogram and register it to the kernel for output handling
0063 Histo2D DigiDepositMonitor::book2D(const std::string& name, const std::string& title,
0064                    std::size_t nbin_x, double min_x, double max_x,
0065                    std::size_t nbin_y, double min_y, double max_y)   {
0066   auto* h = new TH2F(name.c_str(), title.c_str(), nbin_x, min_x, max_x, nbin_y, min_y, max_y);
0067   m_kernel.register_monitor(this, h);
0068   return { h };
0069 }
0070 
0071 /// Standard constructor
0072 DigiDepositEnergyMonitor::DigiDepositEnergyMonitor(const kernel_t& kernel, const std::string& name)
0073   : DigiDepositMonitor(kernel, name)
0074 {
0075   declareProperty("histo1D_deposits", histo1D_deposits);
0076   declareProperty("histo1D_delta",    histo1D_delta);
0077 }
0078 
0079 /// Initializing function: overload for sub-classes to e.g. book histograms
0080 void DigiDepositEnergyMonitor::initialize()    {
0081   declare_monitor_energy(this, &DigiDepositEnergyMonitor::monitor_energy_shift);
0082   m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(), 
0083             histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0084   m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(), 
0085               histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0086 }
0087 
0088 /// Fill the monitoring histograms
0089 void DigiDepositEnergyMonitor::monitor_energy_shift(const deposit_t& deposit, double change)   {
0090   m_deposits.fill(deposit.second.deposit, 1e0);
0091   m_deltas.fill(change, 1e0);
0092 }
0093 
0094 /// Standard constructor
0095 DigiDepositTimeMonitor::DigiDepositTimeMonitor(const kernel_t& kernel, const std::string& name)
0096   : DigiDepositMonitor(kernel, name)
0097 {
0098   declareProperty("histo1D_deposits", histo1D_deposits);
0099   declareProperty("histo1D_delta",    histo1D_delta);
0100 }
0101 
0102 /// Initializing function: overload for sub-classes to e.g. book histograms
0103 void DigiDepositTimeMonitor::initialize()    {
0104   declare_monitor_time(this, &DigiDepositTimeMonitor::monitor_time_shift);
0105   m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(), 
0106             histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0107   m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(), 
0108               histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0109 }
0110 
0111 /// Fill the monitoring histograms
0112 void DigiDepositTimeMonitor::monitor_time_shift(const deposit_t& deposit, double change)   {
0113   m_deposits.fill(deposit.second.time, 1e0);
0114   m_deltas.fill(change, 1e0);
0115 }
0116 
0117 /// Standard constructor
0118 DigiDepositPositionMonitor::DigiDepositPositionMonitor(const kernel_t& kernel, const std::string& name)
0119   : DigiDepositMonitor(kernel, name)
0120 {
0121   declareProperty("histo1D_deposits", histo1D_deposits);
0122   declareProperty("histo1D_delta",    histo1D_delta);
0123 }
0124 
0125 /// Initializing function: overload for sub-classes to e.g. book histograms
0126 void DigiDepositPositionMonitor::initialize()    {
0127   declare_monitor_position(this, &DigiDepositPositionMonitor::monitor_position_shift);
0128   m_deltas = book1D(histo1D_delta.name.c_str(), histo1D_delta.title.c_str(), 
0129             histo1D_delta.nbin_x, histo1D_delta.min_x, histo1D_delta.max_x);
0130   m_deposits = book1D(histo1D_deposits.name.c_str(), histo1D_deposits.title.c_str(), 
0131               histo1D_deposits.nbin_x, histo1D_deposits.min_x, histo1D_deposits.max_x);
0132 }
0133 
0134 /// Fill the monitoring histograms
0135 void DigiDepositPositionMonitor::monitor_position_shift(const deposit_t&, const Position& position, const Position& change)   {
0136   m_deposits.fill(std::sqrt(position.Mag2()), 1e0);
0137   m_deltas.fill(std::sqrt(change.Mag2()), 1e0);
0138 }