ATLAS Offline Software
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 
10 #include "xAODMuon/MuonContainer.h"
12 
13 namespace 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
74  xAOD::MuonContainer::const_iterator mu_end = muons->end();
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
CP::TestMCASTTool::initialize
virtual StatusCode initialize()
Definition: TestMCASTTool.cxx:29
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
python.Dso.registry
registry
Definition: Control/AthenaServices/python/Dso.py:159
CP::TestMCASTTool::m_MSOnlyExtr
std::unique_ptr< MMCTest::TrackInfo > m_MSOnlyExtr
Definition: TestMCASTTool.h:52
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
CP::TestMCASTTool::m_MSExtr
std::unique_ptr< MMCTest::TrackInfo > m_MSExtr
Definition: TestMCASTTool.h:51
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CP::make_systematics_vector
std::vector< CP::SystematicSet > make_systematics_vector(const SystematicSet &systematics)
utility functions for working with systematics
Definition: SystematicsUtil.cxx:25
xAOD::MuonContainer
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
Definition: Event/xAOD/xAODMuon/xAODMuon/MuonContainer.h:14
CP::TestMCASTTool::m_InnerDet
std::unique_ptr< MMCTest::TrackInfo > m_InnerDet
Definition: TestMCASTTool.h:50
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::TestMCASTTool::m_sysNames
std::vector< std::string > m_sysNames
Definition: TestMCASTTool.h:43
SG::ConstAccessor< int >
CP::TestMCASTTool::m_sgKey
std::string m_sgKey
Definition: TestMCASTTool.h:39
CP::TestMCASTTool::m_sysList
std::vector< CP::SystematicSet > m_sysList
Definition: TestMCASTTool.h:44
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
MuonAuxContainer.h
xAOD::MuonAuxContainer_v5
Temporary container used until we have I/O for AuxStoreInternal.
Definition: MuonAuxContainer_v5.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
CP::TestMCASTTool::m_DebugFile
TFile * m_DebugFile
Definition: TestMCASTTool.h:46
CP::CorrectionCode::Error
@ Error
Some error happened during the object correction.
Definition: CorrectionCode.h:36
SG::ExcBadAuxVar
Exception — Attempt to retrieve nonexistent aux data item.
Definition: Control/AthContainers/AthContainers/exceptions.h:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TestMCASTTool.h
CP::TestMCASTTool::TestMCASTTool
TestMCASTTool(const std::string &name, ISvcLocator *svcLoc)
Definition: TestMCASTTool.cxx:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
Trk::Combined
@ Combined
Definition: TrackSummaryTool.h:32
CP::TestMCASTTool::m_Combined
std::unique_ptr< MMCTest::TrackInfo > m_Combined
Definition: TestMCASTTool.h:49
CP::TestMCASTTool::m_SelCategoryRaw
int m_SelCategoryRaw
Definition: TestMCASTTool.h:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CP::TestMCASTTool::m_DebugTree
TTree * m_DebugTree
Definition: TestMCASTTool.h:47
MuonContainer.h
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CP::TestMCASTTool::execute
virtual StatusCode execute()
Definition: TestMCASTTool.cxx:66
CP::TestMCASTTool::m_MCaSTool
ToolHandle< CP::IMuonCalibrationAndSmearingTool > m_MCaSTool
Definition: TestMCASTTool.h:41
CP::TestMCASTTool::m_Output
std::string m_Output
Definition: TestMCASTTool.h:37
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CP::SystematicRegistry
This module implements the central registry for handling systematic uncertainties with CP tools.
Definition: SystematicRegistry.h:25
CP::TestMCASTTool::m_SelCategory
int m_SelCategory
Definition: TestMCASTTool.h:48
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::MuonAuxContainer
MuonAuxContainer_v5 MuonAuxContainer
Definition of the current Muon auxiliary container.
Definition: MuonAuxContainer.h:19
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CP::TestMCASTTool::finalize
virtual StatusCode finalize()
Definition: TestMCASTTool.cxx:139
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
CP::SystematicRegistry::getInstance
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
Definition: SystematicRegistry.cxx:25