ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
PhysicsValidation
GeneratorPhysVal
src
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
5
#include "
GeneratorPhysValMonitoringTool.h
"
6
#include <vector>
7
#include "GaudiKernel/IToolSvc.h"
8
#include "
AthenaBaseComps/AthCheckMacros.h
"
9
#include "TString.h"
10
#include <cmath>
11
#include <limits>
12
#include <fstream>
13
14
15
16
namespace
GeneratorPhysVal
17
{
18
19
GeneratorPhysValMonitoringTool::GeneratorPhysValMonitoringTool
(
const
std::string &
type
,
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),
29
m_number_GeneratorLevel
(nullptr),
30
m_number_SimulationLevel
(nullptr),
31
m_GeneratorSelector
(new
GeneratorSelector
)
32
{
33
34
}
35
36
GeneratorPhysValMonitoringTool::~GeneratorPhysValMonitoringTool
()
37
{}
38
39
StatusCode
GeneratorPhysValMonitoringTool::initialize
()
40
{
41
ATH_MSG_INFO
(
"Initializing "
<< name() <<
"..."
);
42
ATH_CHECK
(
ManagedMonitorToolBase::initialize
());
43
ATH_CHECK
(
m_evtInfoKey
.initialize());
44
45
return
StatusCode::SUCCESS;
46
}
47
StatusCode
GeneratorPhysValMonitoringTool::book
(
PlotBase
& plots)
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
}
59
StatusCode
GeneratorPhysValMonitoringTool::bookHistograms
()
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
67
ATH_CHECK
(
book
(
m_testPlots
));
68
ATH_CHECK
(
book
(
m_ChargedParticlePlots
));
69
ATH_CHECK
(
book
(
m_GeneratorLevelPlots
));
70
ATH_CHECK
(
book
(
m_SimulationLevelPlots
));
71
ATH_CHECK
(
book
(
m_ProductionVertexPlots
));
72
ATH_CHECK
(
book
(
m_EventInfoPlots
));
73
return
StatusCode::SUCCESS;
74
}
75
76
StatusCode
GeneratorPhysValMonitoringTool::fillHistograms
(
const
EventContext& ctx)
77
{
78
79
SG::ReadHandle<xAOD::EventInfo>
eventInfo(
m_evtInfoKey
, ctx);
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
118
StatusCode
GeneratorPhysValMonitoringTool::procHistograms
()
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
}
AthCheckMacros.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
GeneratorPhysValMonitoringTool.h
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_EventInfoPlots
GeneratorPhysVal::GeneratorEventInfo m_EventInfoPlots
Definition
GeneratorPhysValMonitoringTool.h:65
GeneratorPhysVal::GeneratorPhysValMonitoringTool::~GeneratorPhysValMonitoringTool
virtual ~GeneratorPhysValMonitoringTool()
Definition
GeneratorPhysValMonitoringTool.cxx:36
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number
TH1D * m_number
Definition
GeneratorPhysValMonitoringTool.h:68
GeneratorPhysVal::GeneratorPhysValMonitoringTool::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx)
An inheriting class should either override this function or fillHists().
Definition
GeneratorPhysValMonitoringTool.cxx:76
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ChargedParticlePlots
GeneratorPhysVal::GeneratorPlots m_ChargedParticlePlots
Definition
GeneratorPhysValMonitoringTool.h:61
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_TruthParticle
Gaudi::Property< std::vector< float > > m_binning_N_TruthParticle
Definition
GeneratorPhysValMonitoringTool.h:77
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ProductionVertexPlots
GeneratorPhysVal::GeneratorProductionVertexPlots m_ProductionVertexPlots
Definition
GeneratorPhysValMonitoringTool.h:64
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_GeneratorSelector
GeneratorSelector * m_GeneratorSelector
Definition
GeneratorPhysValMonitoringTool.h:72
GeneratorPhysVal::GeneratorPhysValMonitoringTool::bookHistograms
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
Definition
GeneratorPhysValMonitoringTool.cxx:59
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number_SimulationLevel
TH1D * m_number_SimulationLevel
Definition
GeneratorPhysValMonitoringTool.h:70
GeneratorPhysVal::GeneratorPhysValMonitoringTool::GeneratorPhysValMonitoringTool
GeneratorPhysValMonitoringTool()
GeneratorPhysVal::GeneratorPhysValMonitoringTool::book
StatusCode book(PlotBase &plots)
Definition
GeneratorPhysValMonitoringTool.cxx:47
GeneratorPhysVal::GeneratorPhysValMonitoringTool::procHistograms
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
Definition
GeneratorPhysValMonitoringTool.cxx:118
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_SimulationLevelParticle
Gaudi::Property< std::vector< float > > m_binning_N_SimulationLevelParticle
Definition
GeneratorPhysValMonitoringTool.h:79
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_GeneratorLevelParticle
Gaudi::Property< std::vector< float > > m_binning_N_GeneratorLevelParticle
Definition
GeneratorPhysValMonitoringTool.h:78
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_GeneratorLevelPlots
GeneratorPhysVal::GeneratorPlots m_GeneratorLevelPlots
Definition
GeneratorPhysValMonitoringTool.h:62
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_SimulationLevelPlots
GeneratorPhysVal::GeneratorPlots m_SimulationLevelPlots
Definition
GeneratorPhysValMonitoringTool.h:63
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition
GeneratorPhysValMonitoringTool.h:83
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number_GeneratorLevel
TH1D * m_number_GeneratorLevel
Definition
GeneratorPhysValMonitoringTool.h:69
GeneratorPhysVal::GeneratorPhysValMonitoringTool::initialize
virtual StatusCode initialize()
Definition
GeneratorPhysValMonitoringTool.cxx:39
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_testPlots
GeneratorPhysVal::GeneratorPlots m_testPlots
Definition
GeneratorPhysValMonitoringTool.h:60
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ref_mcChannelNumber
int m_ref_mcChannelNumber
Definition
GeneratorPhysValMonitoringTool.h:75
GeneratorSelector
Definition
GeneratorSelector.h:15
ManagedMonitorToolBase::regHist
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 ...
Definition
ManagedMonitorToolBase.cxx:1345
ManagedMonitorToolBase::all
@ all
Definition
ManagedMonitorToolBase.h:116
ManagedMonitorToolBase::ManagedMonitorToolBase
ManagedMonitorToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Definition
ManagedMonitorToolBase.cxx:339
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition
ManagedMonitorToolBase.cxx:617
PlotBase
Definition
PlotBase.h:35
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
GeneratorPhysVal
Definition
GeneratorEventInfo.cxx:7
xAOD::TruthVertex
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition
TruthVertex.h:15
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
type
Generated on
for ATLAS Offline Software by
1.17.0