ATLAS Offline Software
TrigMuonTruthMon.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
15 #include "TrigMuonTruthMon.h"
16 
17 TrigMuonTruthMon :: TrigMuonTruthMon(const std::string& name, ISvcLocator* pSvcLocator )
18  : TrigMuonMonitorAlgorithm(name, pSvcLocator)
19 {}
20 
24  return sc;
25 }
26 
27 StatusCode TrigMuonTruthMon :: fillVariablesPerChain(const EventContext &ctx, const std::string &chain) const {
28  ATH_MSG_DEBUG("Filling muon truth monitoring histograms for " << name() << "...");
29 
30  SG::ReadHandle<xAOD::TruthParticleContainer> truthMuons(m_muonTruthParticlesKey, ctx); // Access truth muons
31  SG::ReadHandle<xAOD::EventInfo> eventInfo(m_EventInfoKey, ctx); // Access event info
32 
33  if (! truthMuons.isValid() ) {
34  ATH_MSG_ERROR("xAOD::TruthParticleContainer with name "<< m_muonTruthParticlesKey << " is not valid");
35  return StatusCode::FAILURE;
36  }
37 
38  auto truthEta = Monitored::Scalar<float>(chain+"_truthEta",-999.);
39  auto truthPhi = Monitored::Scalar<float>(chain+"_truthPhi",-999.);
40  auto truthPt = Monitored::Scalar<float>(chain+"_truthPt",-999.);
41  auto truthEndcapPt = Monitored::Scalar<float>(chain+"_truthEndcapPt",-999.);
42  auto truthBarrelPt = Monitored::Scalar<float>(chain+"_truthBarrelPt",-999.);
43  auto truthIntPerBC = Monitored::Scalar<float>(chain+"_truthIntPerBC",-999.);
44 
45  auto MatchedEFCBtruthEta = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthEta",-999.); // Names need to match those in the config.py file
46  auto MatchedEFCBtruthPhi = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthPhi",-999.);
47  auto MatchedEFCBtruthPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthPt",-999.);
48  auto MatchedEFCBtruthEndcapPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthEndcapPt",-999.);
49  auto MatchedEFCBtruthBarrelPt = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthBarrelPt",-999.);
50  auto MatchedEFCBtruthIntPerBC = Monitored::Scalar<float>(chain+"_MatchedEFCBtruthIntPerBC",-999.);
51  auto MatchedL1truthEta = Monitored::Scalar<float>(chain+"_MatchedL1truthEta",-999.); // Names need to match those in the config.py file
52  auto MatchedL1truthPhi = Monitored::Scalar<float>(chain+"_MatchedL1truthPhi",-999.);
53  auto MatchedL1truthPt = Monitored::Scalar<float>(chain+"_MatchedL1truthPt",-999.);
54  auto MatchedL1truthEndcapPt = Monitored::Scalar<float>(chain+"_MatchedL1truthEndcapPt",-999.);
55  auto MatchedL1truthBarrelPt = Monitored::Scalar<float>(chain+"_MatchedL1truthBarrelPt",-999.);
56  auto MatchedL1truthIntPerBC = Monitored::Scalar<float>(chain+"_MatchedL1truthIntPerBC",-999.);
57 
58  bool passed_EF = false;
59  bool passed_L1 = false;
60 
61  // Find pT cut from chain name
62  double pT_cut = 0.0;
63  std::size_t index_i = chain.find("mu")+2;
64  std::size_t index_f = chain.find("_", index_i+1);
65  if (index_f < chain.length()) {
66  pT_cut = std::stod(chain.substr(index_i, index_f - index_i));
67  }
68  else {
69  pT_cut = std::stod(chain.substr(index_i, chain.length()-1));
70  }
71  pT_cut = pT_cut + 1.0;
72 
73  for (const auto truthMu : *truthMuons) {
74 
75  // Fill truth histograms
76  double eta = 0.0; // Check eta to split pT into endcap barrel
77  eta = truthMu->eta();
78  if(std::abs(eta) > 2.5) continue; // cut on eta to only fill with muons inside detector geometry
79 
80  truthPt = truthMu->pt()/1e3;
82  if(std::abs(eta) < 1.05){
83  truthBarrelPt = truthMu->pt()/1e3;
84  fill(m_group+"_"+chain, truthBarrelPt);
85  }
86  else{ // 1.05 < |eta| < 2.5
87  truthEndcapPt = truthMu->pt()/1e3;
88  fill(m_group+"_"+chain, truthEndcapPt);
89  }
90  if (pT_cut < truthPt){ // Apply pT cut to eta and phi distributions only
91  truthEta = truthMu->eta();
92  truthPhi = truthMu->phi();
93  truthIntPerBC = eventInfo->actualInteractionsPerCrossing();
94  fill(m_group+"_"+chain, truthEta, truthPhi, truthIntPerBC);
95  }
96 
97  // Find match truth muons - EFSA matching for msonly chains, otherwise EFCB matching
98  std::string msonly = "msonly";
99  const xAOD::Muon* efmuon;
100  if(chain.find(msonly) != std::string::npos){ // Find EFCB muons
101  efmuon = m_matchTool->matchEFSA(truthMu, chain, passed_EF);
102  }
103  else{ // Find EFCB muons
104  efmuon = m_matchTool->matchEFCB(truthMu, chain, passed_EF);
105  }
106  const xAOD::MuonRoI* l1muon = m_matchTool->matchL1(truthMu, chain, passed_L1); // Find L1 muons
107 
108  if(efmuon && passed_EF){ // Fill matched muon histograms
109  MatchedEFCBtruthPt = truthMu->pt()/1e3;
110  fill(m_group+"_"+chain, MatchedEFCBtruthPt);
111  if(std::abs(eta) < 1.05){
112  MatchedEFCBtruthBarrelPt = truthMu->pt()/1e3;
113  fill(m_group+"_"+chain, MatchedEFCBtruthBarrelPt);
114  }
115  else{ // 1.05 < |eta| < 2.5
116  MatchedEFCBtruthEndcapPt = truthMu->pt()/1e3;
117  fill(m_group+"_"+chain, MatchedEFCBtruthEndcapPt);
118  }
119  if (pT_cut < truthPt){
120  MatchedEFCBtruthEta = truthMu->eta();
121  MatchedEFCBtruthPhi = truthMu->phi();
122  MatchedEFCBtruthIntPerBC = eventInfo->actualInteractionsPerCrossing();
123  fill(m_group+"_"+chain, MatchedEFCBtruthEta, MatchedEFCBtruthPhi, MatchedEFCBtruthIntPerBC);
124  }
125  }
126 
127  if(l1muon && passed_L1){ // Fill L1 muon matched histograms
128  MatchedL1truthPt = truthMu->pt()/1e3;
129  fill(m_group+"_"+chain, MatchedL1truthPt);
130  if(std::abs(eta) < 1.05){
131  MatchedL1truthBarrelPt = truthMu->pt()/1e3;
132  fill(m_group+"_"+chain, MatchedL1truthBarrelPt);
133  }
134  else{ // 1.05 < |eta| < 2.5
135  MatchedL1truthEndcapPt = truthMu->pt()/1e3;
136  fill(m_group+"_"+chain, MatchedL1truthEndcapPt);
137  }
138  if (pT_cut < truthPt){
139  MatchedL1truthEta = truthMu->eta();
140  MatchedL1truthPhi = truthMu->phi();
141  MatchedL1truthIntPerBC = eventInfo->actualInteractionsPerCrossing();
142  fill(m_group+"_"+chain, MatchedL1truthEta, MatchedL1truthPhi, MatchedL1truthIntPerBC);
143  }
144  }
145 
146  if((l1muon && passed_L1) && !(passed_EF && efmuon)){
147  ATH_MSG_DEBUG("MuonTruthMon: passed L1 but not HLT");
148  }
149 
150  if(!(passed_L1 && l1muon) && (passed_EF && efmuon)){
151  ATH_MSG_DEBUG("MuonTruthMon: passed HLT but not L1");
152  }
153 
154  passed_L1 = false;
155  passed_EF = false;
156 
157  }
158 
159  return StatusCode::SUCCESS;
160 }
createDCubeDigitHistograms.truthPhi
truthPhi
Definition: createDCubeDigitHistograms.py:50
TrigMuonMonitorAlgorithm::m_group
Gaudi::Property< std::string > m_group
Name of monitored group.
Definition: TrigMuonMonitorAlgorithm.h:141
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrigMuonMonitorAlgorithm::m_matchTool
ToolHandle< MuonMatchingTool > m_matchTool
Definition: TrigMuonMonitorAlgorithm.h:129
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TrigMuonTruthMon::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigMuonTruthMon.cxx:21
AthMonitorAlgorithm::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Key for retrieving EventInfo from StoreGate.
Definition: AthMonitorAlgorithm.h:362
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TrigMuonTruthMon::TrigMuonTruthMon
TrigMuonTruthMon(const std::string &name, ISvcLocator *pSvcLocator)
@Afile TrigMuonTruthMon.cxx
Definition: TrigMuonTruthMon.cxx:17
TrigMuonTruthMon::fillVariablesPerChain
virtual StatusCode fillVariablesPerChain(const EventContext &ctx, const std::string &chain) const override
Function that fills variables of trigger objects associated to specified trigger chains.
Definition: TrigMuonTruthMon.cxx:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CheckAppliedSFs.e3
e3
Definition: CheckAppliedSFs.py:264
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
xAOD::MuonRoI_v1
Class describing a LVL1 muon region of interest.
Definition: MuonRoI_v1.h:29
createDCubeDigitHistograms.truthPt
truthPt
truth information
Definition: createDCubeDigitHistograms.py:48
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TrigMuonMonitorAlgorithm
Base class from which analyzers can define a derived class to do specific analysis.
Definition: TrigMuonMonitorAlgorithm.h:22
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
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
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TrigMuonTruthMon.h
createDCubeDigitHistograms.truthEta
truthEta
Definition: createDCubeDigitHistograms.py:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigMuonTruthMon::m_muonTruthParticlesKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_muonTruthParticlesKey
Definition: TrigMuonTruthMon.h:33
TrigMuonMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: TrigMuonMonitorAlgorithm.cxx:13
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
xAOD::EventInfo_v1::actualInteractionsPerCrossing
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
Definition: EventInfo_v1.cxx:380