ATLAS Offline Software
Loading...
Searching...
No Matches
GeneratorPhysValMonitoringTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <vector>
7#include "GaudiKernel/IToolSvc.h"
10#include "TString.h"
11#include <cmath>
12#include <limits>
13#include <fstream>
14
15
16
17namespace GeneratorPhysVal
18{
19
21 const std::string &name, const IInterface *parent) :
22 ManagedMonitorToolBase(type, name, parent),
23 m_testPlots(0, "test/", "test"), // for testing
24 m_ChargedParticlePlots(0,"ChargedParticle/","ChargedParticle"), // save charged particles
25 m_GeneratorLevelPlots(0,"GeneratorLevel/","GeneratorLevel"), // save generator level particle
26 m_SimulationLevelPlots(0,"SimulationLevel/","SimulationLevel"), // save simulation level particle
27 m_ProductionVertexPlots(0,"ProductionVertex/","ProductionVertex"), // save production vertex
28 m_EventInfoPlots(0,"EventInfo/","EventInfo"), // save EventInfo
29 m_number(nullptr),
33 {
34
35 }
36
39
41 {
42 ATH_MSG_INFO("Initializing " << name() << "...");
44 ATH_CHECK(m_evtInfoKey.initialize());
45
46 return StatusCode::SUCCESS;
47 }
49{
50 plots.initialize();
51 std::vector<HistData> hists = plots.retrieveBookedHistograms();
52
53 for (auto& hist : hists)
54 {
55 ATH_MSG_INFO("Initializing " << hist.first << " " << hist.first->GetName() << " " << hist.second << "...");
56 ATH_CHECK(regHist(hist.first, hist.second, all));
57 }
58 return StatusCode::SUCCESS;
59}
61 {
62 ATH_MSG_INFO("Booking hists " << name() << "...");
63 std::string dir_test("nplots/");
64 ATH_CHECK(regHist(m_number = new TH1D("N_TruthParticle","Number of Truth Particles; n ;Events" ,m_binning_N_TruthParticle[0], m_binning_N_TruthParticle[1], m_binning_N_TruthParticle[2]), dir_test, all));
65 ATH_CHECK(regHist(m_number_GeneratorLevel = new TH1D("N_GeneratorLevelParticle","Number of Generator Level Particles; n ;Events" ,m_binning_N_GeneratorLevelParticle[0], m_binning_N_GeneratorLevelParticle[1], m_binning_N_GeneratorLevelParticle[2]), dir_test, all));
66 ATH_CHECK(regHist(m_number_SimulationLevel = new TH1D("N_SimulationLevelParticle","Number of Simulation Level Particles; n ;Events" ,m_binning_N_SimulationLevelParticle[0], m_binning_N_SimulationLevelParticle[1], m_binning_N_SimulationLevelParticle[2]), dir_test, all));
67
74 return StatusCode::SUCCESS;
75 }
76
78 {
79
80 const EventContext& ctx = Gaudi::Hive::currentContext();
82
83 m_EventInfoPlots.check_eventNumber(eventInfo);
84 m_ref_mcChannelNumber = m_EventInfoPlots.check_mcChannelNumber(std::move(eventInfo),m_ref_mcChannelNumber);
85
86 const xAOD::TruthParticleContainer *TruthParticles(nullptr);
87 if (!TruthParticles)
88 {
89 TruthParticles = evtStore()->tryConstRetrieve<xAOD::TruthParticleContainer>("TruthParticles");
90 }
91
92 const std::vector< TLorentzVector > SelectedGeneratorLevel = m_GeneratorSelector->GetGeneratorLevel(TruthParticles);
93 const std::vector< TLorentzVector > SelectedSimulationLevel = m_GeneratorSelector->GetSimulationLevel(TruthParticles);
94
95
96 for (const auto particle : *TruthParticles)
97 {
98
99 if (particle->charge()){
100 m_ChargedParticlePlots.fill(particle);
101 }
102
103 m_testPlots.fill(particle);
104
105 const xAOD::TruthVertex* vtx = particle->prodVtx();
106 if (vtx) {
107 m_ProductionVertexPlots.fillProdVtx(vtx);
108 }
109 }
110
111 m_number_GeneratorLevel->Fill((double)SelectedGeneratorLevel.size());
112 m_number_SimulationLevel->Fill((double)SelectedSimulationLevel.size());
113 m_GeneratorLevelPlots.fill(SelectedGeneratorLevel);
114 m_SimulationLevelPlots.fill(SelectedSimulationLevel);
115
116 m_number->Fill((double)TruthParticles->size());
117 return StatusCode::SUCCESS;
118 }
119
121 {
122 ATH_MSG_INFO("Finalising hists " << name() << "...");
123 m_testPlots.finalize();
124 m_ChargedParticlePlots.finalize();
125 m_GeneratorLevelPlots.finalize();
126 m_SimulationLevelPlots.finalize();
127 m_ProductionVertexPlots.finalize();
128 m_EventInfoPlots.finalize();
129 return StatusCode::SUCCESS;
130
131 }
132}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
ServiceHandle< StoreGateSvc > & evtStore()
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< std::vector< float > > m_binning_N_TruthParticle
GeneratorPhysVal::GeneratorProductionVertexPlots m_ProductionVertexPlots
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
Gaudi::Property< std::vector< float > > m_binning_N_SimulationLevelParticle
Gaudi::Property< std::vector< float > > m_binning_N_GeneratorLevelParticle
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
virtual StatusCode regHist(TH1 *h, const std::string &system, Interval_t interval, MgmtAttr_t histo_mgmt=ATTRIB_MANAGED, const std::string &chain="", const std::string &merge="")
Registers a TH1 (including TH2, TH3, and TProfile) to be included in the output stream using logical ...
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.