ATLAS Offline Software
GeneratorPhysValMonitoringTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
17 namespace GeneratorPhysVal
18 {
19 
21  const std::string &name,
22  const IInterface *parent) : 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),
30  m_number_GeneratorLevel(nullptr),
31  m_number_SimulationLevel(nullptr),
32  m_GeneratorSelector(new GeneratorSelector)
33 
34  {
35 
36  }
37 
39  {}
40 
42  {
43  ATH_MSG_INFO("Initializing " << name() << "...");
46 
47  return StatusCode::SUCCESS;
48  }
50 {
51  plots.initialize();
52  std::vector<HistData> hists = plots.retrieveBookedHistograms();
53 
54  for (auto& hist : hists)
55  {
56  ATH_MSG_INFO("Initializing " << hist.first << " " << hist.first->GetName() << " " << hist.second << "...");
57  ATH_CHECK(regHist(hist.first, hist.second, all));
58  }
59  return StatusCode::SUCCESS;
60 }
62  {
63  ATH_MSG_INFO("Booking hists " << name() << "...");
64  std::string dir_test("nplots/");
65  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));
66  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));
67  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));
68 
75  return StatusCode::SUCCESS;
76  }
77 
79  {
80 
81  const EventContext& ctx = Gaudi::Hive::currentContext();
83 
86 
87  const xAOD::TruthParticleContainer *TruthParticles(nullptr);
88  if (!TruthParticles)
89  {
90  TruthParticles = evtStore()->tryConstRetrieve<xAOD::TruthParticleContainer>("TruthParticles");
91  }
92 
93  const std::vector< TLorentzVector > SelectedGeneratorLevel = m_GeneratorSelector->GetGeneratorLevel(TruthParticles);
94  const std::vector< TLorentzVector > SelectedSimulationLevel = m_GeneratorSelector->GetSimulationLevel(TruthParticles);
95 
96 
97  for (const auto &particle : *TruthParticles)
98  {
99 
100  if (particle->charge()){
102  }
103 
105 
106  const xAOD::TruthVertex* vtx = particle->prodVtx();
107  if (vtx) {
109  }
110  }
111 
112  m_number_GeneratorLevel->Fill((double)SelectedGeneratorLevel.size());
113  m_number_SimulationLevel->Fill((double)SelectedSimulationLevel.size());
114  m_GeneratorLevelPlots.fill(SelectedGeneratorLevel);
115  m_SimulationLevelPlots.fill(SelectedSimulationLevel);
116 
117  m_number->Fill((double)TruthParticles->size());
118  return StatusCode::SUCCESS;
119  }
120 
122  {
123  ATH_MSG_INFO("Finalising hists " << name() << "...");
130  return StatusCode::SUCCESS;
131 
132  }
133 }
GeneratorSelector::GetGeneratorLevel
const std::vector< TLorentzVector > GetGeneratorLevel(const xAOD::TruthParticleContainer *cont)
Definition: GeneratorSelector.h:22
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_GeneratorSelector
GeneratorSelector * m_GeneratorSelector
Definition: GeneratorPhysValMonitoringTool.h:72
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_evtInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
Definition: GeneratorPhysValMonitoringTool.h:83
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
GeneratorPhysVal::GeneratorEventInfo::check_eventNumber
void check_eventNumber(SG::ReadHandle< xAOD::EventInfo > evt)
Definition: GeneratorEventInfo.cxx:16
PlotBase
Definition: PlotBase.h:34
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_GeneratorLevelPlots
GeneratorPhysVal::GeneratorPlots m_GeneratorLevelPlots
Definition: GeneratorPhysValMonitoringTool.h:62
AthCheckMacros.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_testPlots
GeneratorPhysVal::GeneratorPlots m_testPlots
Definition: GeneratorPhysValMonitoringTool.h:60
GeneratorSelector::GetSimulationLevel
const std::vector< TLorentzVector > GetSimulationLevel(const xAOD::TruthParticleContainer *cont)
Definition: GeneratorSelector.h:35
ManagedMonitorToolBase
Provides functionality for users to implement and save histograms, ntuples, and summary data,...
Definition: ManagedMonitorToolBase.h:74
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number_GeneratorLevel
TH1D * m_number_GeneratorLevel
Definition: GeneratorPhysValMonitoringTool.h:69
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
plotmaker.hist
hist
Definition: plotmaker.py:148
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_GeneratorLevelParticle
Gaudi::Property< std::vector< float > > m_binning_N_GeneratorLevelParticle
Definition: GeneratorPhysValMonitoringTool.h:78
TH1D
Definition: rootspy.cxx:342
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_TruthParticle
Gaudi::Property< std::vector< float > > m_binning_N_TruthParticle
Definition: GeneratorPhysValMonitoringTool.h:77
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ChargedParticlePlots
GeneratorPhysVal::GeneratorPlots m_ChargedParticlePlots
Definition: GeneratorPhysValMonitoringTool.h:61
GeneratorPhysVal::GeneratorPhysValMonitoringTool::GeneratorPhysValMonitoringTool
GeneratorPhysValMonitoringTool()
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number
TH1D * m_number
Definition: GeneratorPhysValMonitoringTool.h:68
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
GeneratorPhysVal::GeneratorPhysValMonitoringTool::~GeneratorPhysValMonitoringTool
virtual ~GeneratorPhysValMonitoringTool()
Definition: GeneratorPhysValMonitoringTool.cxx:38
PlotBase::finalize
void finalize()
Definition: PlotBase.cxx:47
ManagedMonitorToolBase::initialize
virtual StatusCode initialize()
Definition: ManagedMonitorToolBase.cxx:668
GeneratorPhysVal::GeneratorPlots::fill
void fill(const xAOD::IParticle *part)
Definition: GeneratorPlots.h:27
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ref_mcChannelNumber
int m_ref_mcChannelNumber
Definition: GeneratorPhysValMonitoringTool.h:75
GeneratorPhysVal::GeneratorEventInfo::check_mcChannelNumber
int check_mcChannelNumber(SG::ReadHandle< xAOD::EventInfo > evt, int ref)
Definition: GeneratorEventInfo.cxx:21
GeneratorPhysVal::GeneratorPhysValMonitoringTool::fillHistograms
virtual StatusCode fillHistograms()
An inheriting class should either override this function or fillHists().
Definition: GeneratorPhysValMonitoringTool.cxx:78
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_ProductionVertexPlots
GeneratorPhysVal::GeneratorProductionVertexPlots m_ProductionVertexPlots
Definition: GeneratorPhysValMonitoringTool.h:64
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
AthLegacySequence.h
GeneratorPhysVal::GeneratorPhysValMonitoringTool::procHistograms
virtual StatusCode procHistograms()
An inheriting class should either override this function or finalHists().
Definition: GeneratorPhysValMonitoringTool.cxx:121
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
GeneratorPhysVal::GeneratorPhysValMonitoringTool::initialize
virtual StatusCode initialize()
Definition: GeneratorPhysValMonitoringTool.cxx:41
GeneratorPhysVal::GeneratorPhysValMonitoringTool::bookHistograms
virtual StatusCode bookHistograms()
An inheriting class should either override this function or bookHists().
Definition: GeneratorPhysValMonitoringTool.cxx:61
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_number_SimulationLevel
TH1D * m_number_SimulationLevel
Definition: GeneratorPhysValMonitoringTool.h:70
GeneratorPhysVal::GeneratorPhysValMonitoringTool::book
StatusCode book(PlotBase &plots)
Definition: GeneratorPhysValMonitoringTool.cxx:49
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_EventInfoPlots
GeneratorPhysVal::GeneratorEventInfo m_EventInfoPlots
Definition: GeneratorPhysValMonitoringTool.h:65
ManagedMonitorToolBase::all
@ all
Definition: ManagedMonitorToolBase.h:116
covarianceTool.plots
plots
Definition: covarianceTool.py:698
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_SimulationLevelPlots
GeneratorPhysVal::GeneratorPlots m_SimulationLevelPlots
Definition: GeneratorPhysValMonitoringTool.h:63
GeneratorPhysVal
Definition: GeneratorEventInfo.cxx:7
GeneratorSelector
Definition: GeneratorSelector.h:15
GeneratorPhysVal::GeneratorPhysValMonitoringTool::m_binning_N_SimulationLevelParticle
Gaudi::Property< std::vector< float > > m_binning_N_SimulationLevelParticle
Definition: GeneratorPhysValMonitoringTool.h:79
GeneratorPhysVal::GeneratorProductionVertexPlots::fillProdVtx
void fillProdVtx(const xAOD::TruthVertex *vtx)
Definition: GeneratorProductionVertexPlots.h:29
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:1453
GeneratorPhysValMonitoringTool.h