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"
9#include "TString.h"
10#include <cmath>
11#include <limits>
12#include <fstream>
13
14
15
16namespace GeneratorPhysVal
17{
18
20 const std::string &name, const IInterface *parent) :
21 ManagedMonitorToolBase(type, name, parent),
22 m_testPlots(0, "test/", "test"), // for testing
23 m_ChargedParticlePlots(0,"ChargedParticle/","ChargedParticle"), // save charged particles
24 m_GeneratorLevelPlots(0,"GeneratorLevel/","GeneratorLevel"), // save generator level particle
25 m_SimulationLevelPlots(0,"SimulationLevel/","SimulationLevel"), // save simulation level particle
26 m_ProductionVertexPlots(0,"ProductionVertex/","ProductionVertex"), // save production vertex
27 m_EventInfoPlots(0,"EventInfo/","EventInfo"), // save EventInfo
28 m_number(nullptr),
32 {
33
34 }
35
38
40 {
41 ATH_MSG_INFO("Initializing " << name() << "...");
43 ATH_CHECK(m_evtInfoKey.initialize());
44
45 return StatusCode::SUCCESS;
46 }
48{
49 plots.initialize();
50 std::vector<HistData> hists = plots.retrieveBookedHistograms();
51
52 for (auto& hist : hists)
53 {
54 ATH_MSG_INFO("Initializing " << hist.first << " " << hist.first->GetName() << " " << hist.second << "...");
55 ATH_CHECK(regHist(hist.first, hist.second, all));
56 }
57 return StatusCode::SUCCESS;
58}
60 {
61 ATH_MSG_INFO("Booking hists " << name() << "...");
62 std::string dir_test("nplots/");
63 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));
64 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));
65 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));
66
73 return StatusCode::SUCCESS;
74 }
75
76 StatusCode GeneratorPhysValMonitoringTool::fillHistograms(const EventContext& ctx)
77 {
78
80
81 m_EventInfoPlots.check_eventNumber(eventInfo);
82 m_ref_mcChannelNumber = m_EventInfoPlots.check_mcChannelNumber(std::move(eventInfo),m_ref_mcChannelNumber);
83
84 const xAOD::TruthParticleContainer *TruthParticles(nullptr);
85 if (!TruthParticles)
86 {
87 TruthParticles = evtStore()->tryConstRetrieve<xAOD::TruthParticleContainer>("TruthParticles");
88 }
89
90 const std::vector< TLorentzVector > SelectedGeneratorLevel = m_GeneratorSelector->GetGeneratorLevel(TruthParticles);
91 const std::vector< TLorentzVector > SelectedSimulationLevel = m_GeneratorSelector->GetSimulationLevel(TruthParticles);
92
93
94 for (const auto particle : *TruthParticles)
95 {
96
97 if (particle->charge()){
98 m_ChargedParticlePlots.fill(particle);
99 }
100
101 m_testPlots.fill(particle);
102
103 const xAOD::TruthVertex* vtx = particle->prodVtx();
104 if (vtx) {
105 m_ProductionVertexPlots.fillProdVtx(vtx);
106 }
107 }
108
109 m_number_GeneratorLevel->Fill((double)SelectedGeneratorLevel.size());
110 m_number_SimulationLevel->Fill((double)SelectedSimulationLevel.size());
111 m_GeneratorLevelPlots.fill(SelectedGeneratorLevel);
112 m_SimulationLevelPlots.fill(SelectedSimulationLevel);
113
114 m_number->Fill((double)TruthParticles->size());
115 return StatusCode::SUCCESS;
116 }
117
119 {
120 ATH_MSG_INFO("Finalising hists " << name() << "...");
121 m_testPlots.finalize();
122 m_ChargedParticlePlots.finalize();
123 m_GeneratorLevelPlots.finalize();
124 m_SimulationLevelPlots.finalize();
125 m_ProductionVertexPlots.finalize();
126 m_EventInfoPlots.finalize();
127 return StatusCode::SUCCESS;
128
129 }
130}
#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.
virtual StatusCode fillHistograms(const EventContext &ctx)
An inheriting class should either override this function or fillHists().
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 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.