ATLAS Offline Software
Loading...
Searching...
No Matches
TestMCASTTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TestMCASTTool.h"
6
7#include <cmath>
8
12
13namespace CP {
14
15 TestMCASTTool::TestMCASTTool(const std::string& name, ISvcLocator* svcLoc) :
16 AthAlgorithm(name, svcLoc), m_MCaSTool("CP::MuonCalibrationAndSmearingTool/MuonCalibrationAndSmearingTool", this) {
17 declareProperty("Output", m_Output = "MCaST_Debug.root");
18 declareProperty("SGKey", m_sgKey = "Muons");
19 declareProperty("MuonCalibrationAndSmearingTool", m_MCaSTool);
20
21 m_DebugFile = nullptr;
22 m_DebugTree = nullptr;
23 m_Combined = nullptr;
24 m_InnerDet = nullptr;
25 m_MSExtr = nullptr;
26 m_MSOnlyExtr = nullptr;
27 }
28
30 ATH_MSG_INFO("Initialising");
31 ATH_MSG_DEBUG("SGKey = " << m_sgKey);
32 ATH_MSG_DEBUG("MuonCalibrationAndSmearingTool = " << m_MCaSTool);
33 ATH_CHECK(m_MCaSTool.retrieve());
34
36 const CP::SystematicSet& recommendedSystematics = registry.recommendedSystematics();
37 m_sysList = CP::make_systematics_vector(recommendedSystematics);
38 m_sysList.push_back(CP::SystematicSet());
39
40 for (std::vector<CP::SystematicSet>::iterator sysItr = m_sysList.begin() + 1; sysItr != m_sysList.end(); ++sysItr) {
41 std::string syst_name = (*sysItr).name();
42 m_sysNames.push_back(syst_name);
43 }
44
45 std::vector<std::string> empty_list;
46
47 m_Combined = std::make_unique<MMCTest::TrackInfo>("CB", m_sysNames);
48 m_InnerDet = std::make_unique<MMCTest::TrackInfo>("ID", m_sysNames);
49 m_MSExtr = std::make_unique<MMCTest::TrackInfo>("ME", m_sysNames);
50 m_MSOnlyExtr = std::make_unique<MMCTest::TrackInfo>("MSOE", empty_list);
51
52 m_DebugFile = new TFile(m_Output.c_str(), "RECREATE", "Smearing and non-Smearing of Muons");
53 m_DebugTree = new TTree("CorrectionsTree", "This Tree contains the information of the muon after smearing effects");
54
55 m_DebugTree->Branch("Muon_Sel_Category_Raw", &m_SelCategoryRaw);
56 m_DebugTree->Branch("Muon_Sel_Category", &m_SelCategory);
57
58 m_Combined->Register(m_DebugTree);
59 m_InnerDet->Register(m_DebugTree);
60 m_MSExtr->Register(m_DebugTree);
61 m_MSOnlyExtr->Register(m_DebugTree);
62
63 return StatusCode::SUCCESS;
64 }
65
67 //---\\---// Retrieving muons from container
68 const xAOD::MuonContainer* muons = 0;
69 ATH_CHECK(evtStore()->retrieve(muons, m_sgKey));
70 ATH_MSG_DEBUG("Number of muons: " << muons->size());
71
72 //---\\---// Looping over muons
75
77 ATH_CHECK(evtStore()->record(mymuons, "CalibMuons"));
79 ATH_CHECK(evtStore()->record(mymuonsaux, "CalibMuonsAux."));
80 mymuons->setStore(mymuonsaux);
81
82 m_Combined->Reset();
83 m_InnerDet->Reset();
84 m_MSExtr->Reset();
85 m_MSOnlyExtr->Reset();
86
87 for (; mu_itr != mu_end; ++mu_itr) {
88 //---\\---// Simple preselection
89 if ((*mu_itr)->muonType() != xAOD::Muon::Combined) continue;
90
91 const xAOD::TrackParticle* cbTrack = (*mu_itr)->trackParticle(xAOD::Muon::CombinedTrackParticle);
92 if (cbTrack) m_Combined->Fill(cbTrack);
93
94 const xAOD::TrackParticle* idTrack = (*mu_itr)->trackParticle(xAOD::Muon::InnerDetectorTrackParticle);
95 if (idTrack) m_InnerDet->Fill(idTrack);
96
97 const xAOD::TrackParticle* meTrack = nullptr;
98 try {
99 meTrack = (*mu_itr)->trackParticle(xAOD::Muon::ExtrapolatedMuonSpectrometerTrackParticle);
100 } catch (SG::ExcBadAuxVar& b) { meTrack = (*mu_itr)->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle); }
101 if (meTrack) m_MSExtr->Fill(meTrack);
102
103 const xAOD::TrackParticle* msoeTrack = nullptr;
104 try {
105 msoeTrack = (*mu_itr)->trackParticle(xAOD::Muon::MSOnlyExtrapolatedMuonSpectrometerTrackParticle);
106 } catch (SG::ExcBadAuxVar& b) { msoeTrack = (*mu_itr)->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle); }
107 if (msoeTrack) m_MSOnlyExtr->Fill(msoeTrack);
108
109 //---\\---// Calibrating muon
110 ATH_MSG_DEBUG("Calibrating muon");
111 for (std::vector<CP::SystematicSet>::iterator sysItr = m_sysList.begin() + 1; sysItr != m_sysList.end(); ++sysItr) {
112 if (m_MCaSTool->applySystematicVariation(*sysItr) != StatusCode::SUCCESS) { continue; }
113 xAOD::Muon* mu = 0;
114 if (m_MCaSTool->correctedCopy(**mu_itr, mu) == CP::CorrectionCode::Error) {
115 ATH_MSG_WARNING("Failed to correct the muon!");
116 continue;
117 }
118
119 std::string syst_name = (*sysItr).name();
120
121 static const SG::ConstAccessor<int> raw_MCaST_CategoryAcc ("raw_MCaST_Category");
122 static const SG::ConstAccessor<int> MCaST_CategoryAcc ("MCaST_Category");
123 static const SG::ConstAccessor<float> InnerDetectorPtAcc ("InnerDetectorPt");
124 static const SG::ConstAccessor<float> MuonSpectrometerPtAcc ("MuonSpectrometerPt");
125 m_SelCategoryRaw = raw_MCaST_CategoryAcc (*mu);
126 m_SelCategory = MCaST_CategoryAcc (*mu);
127 m_Combined->SetCalibPt(mu->pt(), syst_name);
128 m_InnerDet->SetCalibPt(InnerDetectorPtAcc (*mu), syst_name);
129 m_MSExtr->SetCalibPt(MuonSpectrometerPtAcc (*mu), syst_name);
130 delete mu;
131 }
132
133 m_DebugTree->Fill();
134 }
135
136 return StatusCode::SUCCESS;
137 }
138
140 m_DebugFile->Write();
141 return StatusCode::SUCCESS;
142 }
143
144} // namespace CP
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helper class to provide constant type-safe access to aux data.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
@ Error
Some error happened during the object correction.
This module implements the central registry for handling systematic uncertainties with CP tools.
const SystematicSet & recommendedSystematics() const
returns: the recommended set of systematics
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Class to wrap a set of SystematicVariations.
std::unique_ptr< MMCTest::TrackInfo > m_InnerDet
std::string m_sgKey
std::unique_ptr< MMCTest::TrackInfo > m_Combined
TestMCASTTool(const std::string &name, ISvcLocator *svcLoc)
virtual StatusCode finalize()
std::vector< CP::SystematicSet > m_sysList
std::unique_ptr< MMCTest::TrackInfo > m_MSOnlyExtr
virtual StatusCode execute()
ToolHandle< CP::IMuonCalibrationAndSmearingTool > m_MCaSTool
std::unique_ptr< MMCTest::TrackInfo > m_MSExtr
virtual StatusCode initialize()
std::vector< std::string > m_sysNames
std::string m_Output
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
Helper class to provide constant type-safe access to aux data.
Exception — Attempt to retrieve nonexistent aux data item.
Select isolated Photons, Electrons and Muons.
std::vector< CP::SystematicSet > make_systematics_vector(const SystematicSet &systematics)
utility functions for working with systematics
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
MuonAuxContainer_v5 MuonAuxContainer
Definition of the current Muon auxiliary container.
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".