StepHistogramTool.cxx 4.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/

#include "CxxUtils/make_unique.h"
#include "StepHistogramTool.h"

namespace G4UA{ 


  StepHistogramTool::StepHistogramTool(const std::string& type,
                                       const std::string& name,
                                       const IInterface* parent):
    UserActionToolBase<StepHistogram>(type, name, parent),
    m_config(),
    m_histSvc("THistSvc", name){

    declareProperty("do2DHistograms", m_config.do2DHistograms);
    declareProperty("doGeneralHistograms", m_config.doGeneralHistograms);
  }

  std::unique_ptr<StepHistogram>
  StepHistogramTool::makeAndFillAction(G4AtlasUserActions& actionList)
  {
    ATH_MSG_DEBUG("Constructing a TestActionTimer");
    auto action = CxxUtils::make_unique<StepHistogram>(m_config);
    actionList.runActions.push_back( action.get() );
    actionList.eventActions.push_back( action.get() );
    actionList.steppingActions.push_back( action.get() );
    return action;
  }

  StatusCode StepHistogramTool::initialize(){
    ATH_CHECK(m_histSvc.retrieve());
    return StatusCode::SUCCESS;
  }

  void StepHistogramTool::BookHistograms(StepHistogram::HistoMapMap_t &hMap, const char* suffix, const char* subfolder)
  {
    for (auto const& x : hMap)
    {
      ATH_MSG_INFO("Currently in volume:\t" << x.first << " got histoMap " << x.second);
      for (auto const& hm : x.second)
      {
        ATH_MSG_INFO("Registering histogram:\t" << hm.first);
        std::ostringstream stringStream;
        stringStream << "/stepHisto/" << subfolder << x.first << "/" << suffix << hm.first;
        if ( m_histSvc->regHist(stringStream.str().c_str(), hm.second).isFailure() ) {
          ATH_MSG_ERROR("Could not register histogram!");
        }
      }
    }    
  }

  StatusCode StepHistogramTool::finalize() {
    ATH_MSG_INFO("Preparing histograms...");

    // Accumulate results across threads
    StepHistogram::Report report;
    m_actions.accumulate(report, &StepHistogram::getReport,
                         &StepHistogram::Report::merge);

    if (m_histSvc) {
      BookHistograms(report.histoMapMap_vol_stepSize, "stepLength/", "volumes/");
      BookHistograms(report.histoMapMap_vol_stepKineticEnergy, "stepKineticEnergy/", "volumes/");
      BookHistograms(report.histoMapMap_vol_stepPseudorapidity, "stepPseudorapidity/", "volumes/");
      BookHistograms(report.histoMapMap_vol_stepEnergyDeposit, "stepEnergyDeposit/", "volumes/");
      BookHistograms(report.histoMapMap_vol_stepEnergyNonIonDeposit, "stepEnergyNonIonDeposit/", "volumes/");
      BookHistograms(report.histoMapMap_vol_stepSecondaryKinetic, "stepSecondaryKinetic/", "volumes/");

      BookHistograms(report.histoMapMap_mat_stepSize, "stepLength/", "materials/");
      BookHistograms(report.histoMapMap_mat_stepKineticEnergy, "stepKineticEnergy/", "materials/");
      BookHistograms(report.histoMapMap_mat_stepPseudorapidity, "stepPseudorapidity/", "materials/");
      BookHistograms(report.histoMapMap_mat_stepEnergyDeposit, "stepEnergyDeposit/", "materials/");
      BookHistograms(report.histoMapMap_mat_stepEnergyNonIonDeposit, "stepEnergyNonIonDeposit/", "materials/");
      BookHistograms(report.histoMapMap_mat_stepSecondaryKinetic, "stepSecondaryKinetic/", "materials/");

      BookHistograms(report.histoMapMap_prc_stepSize, "stepLength/", "processes/");
      BookHistograms(report.histoMapMap_prc_stepKineticEnergy, "stepKineticEnergy/", "processes/");
      BookHistograms(report.histoMapMap_prc_stepPseudorapidity, "stepPseudorapidity/", "processes/");
      BookHistograms(report.histoMapMap_prc_stepEnergyDeposit, "stepEnergyDeposit/", "processes/");
      BookHistograms(report.histoMapMap_prc_stepEnergyNonIonDeposit, "stepEnergyNonIonDeposit/", "processes/");
      BookHistograms(report.histoMapMap_prc_stepSecondaryKinetic, "stepSecondaryKinetic/", "processes/");

      if (m_config.doGeneralHistograms) {
        BookHistograms(report.histoMapMap_numberOfSteps, "numberOfSteps/", "nSteps/");
        BookHistograms(report.histoMapMap_numberOfStepsPerInitialE, "numberOfStepsPerInitialE/", "nSteps/");
        BookHistograms(report.histoMapMap_InitialE, "InitialE/", "nSteps/");
        BookHistograms(report.histoMapMap_stepSecondaryKinetic, "stepKineticEnergy/", "nSteps/");
      }

      if (m_config.do2DHistograms) {
        BookHistograms(report.histoMapMap2D_vol_RZ, "2DMaps/", "volumes/");
        BookHistograms(report.histoMapMap2D_mat_RZ, "2DMaps/", "materials/");
        BookHistograms(report.histoMapMap2D_prc_RZ, "2DMaps/", "processes/");
      }
    }
    else {
      ATH_MSG_WARNING("HistSvc not initialized...");      
    }

    return StatusCode::SUCCESS;
  }

  
} // namespace G4UA