ATLAS Offline Software
TrigTauMonitorDiTauAlgorithm.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 
7 
8 TrigTauMonitorDiTauAlgorithm::TrigTauMonitorDiTauAlgorithm(const std::string& name, ISvcLocator* pSvcLocator)
9  : TrigTauMonitorBaseAlgorithm(name, pSvcLocator)
10 {}
11 
12 
14 {
15  constexpr float threshold_offset = 10.0;
16 
17  // Offline taus
18  auto offline_taus_all = getOfflineTausAll(ctx, 0.0);
19 
20  if(m_requireOfflineTaus && offline_taus_all.empty()) return StatusCode::SUCCESS;
21 
22  for(const std::string& trigger : m_triggers) {
23  const TrigTauInfo& info = getTrigInfo(trigger);
24 
25  if(!info.isHLTDiTau()) {
26  ATH_MSG_WARNING("Chain \"" << trigger << "\" is not a di-tau trigger. Skipping...");
27  continue;
28  }
29 
30  const auto passBits = m_trigDecTool->isPassedBits(trigger);
31  const bool l1_accept_flag = passBits & TrigDefs::L1_isPassedAfterVeto;
32  const bool hlt_not_prescaled_flag = (passBits & TrigDefs::EF_prescaled) == 0;
33 
34  // Filter offline taus
35  std::vector<const xAOD::TauJet*> offline_taus = classifyTausAll(offline_taus_all, info.getHLTTauThreshold() - threshold_offset);
36 
37  // Online taus
38  std::vector<const xAOD::TauJet*> hlt_taus = getOnlineTausAll(trigger, true);
39 
40  if(m_do_variable_plots) fillDiTauVars(trigger, hlt_taus);
41  if(m_do_efficiency_plots && hlt_not_prescaled_flag) fillDiTauHLTEfficiencies(ctx, trigger, l1_accept_flag, offline_taus, hlt_taus);
42  }
43 
44  return StatusCode::SUCCESS;
45 }
46 
47 
48 void TrigTauMonitorDiTauAlgorithm::fillDiTauHLTEfficiencies(const EventContext& ctx, const std::string& trigger, const bool l1_accept_flag, const std::vector<const xAOD::TauJet*>& offline_tau_vec, const std::vector<const xAOD::TauJet*>& online_tau_vec) const
49 {
50  ATH_MSG_DEBUG("Fill DiTau HLT efficiencies: " << trigger);
51 
52  const TrigTauInfo& info = getTrigInfo(trigger);
53 
54  // Require 2 offline taus
55  if(offline_tau_vec.size() != 2) return;
56 
57  auto monGroup = getGroup(trigger+"_DiTauHLT_Efficiency");
58 
59  auto dR = Monitored::Scalar<float>("dR", 0.0);
60  auto dEta = Monitored::Scalar<float>("dEta", 0.0);
61  auto dPhi = Monitored::Scalar<float>("dPhi", 0.0);
62  auto averageMu = Monitored::Scalar<float>("averageMu", 0.0);
63  auto HLT_match = Monitored::Scalar<bool>("HLT_pass", false);
64  auto HLT_match_highPt = Monitored::Scalar<bool>("HLT_pass_highPt", false);
65  auto Total_match = Monitored::Scalar<bool>("Total_pass", false);
66  auto Total_match_highPt = Monitored::Scalar<bool>("Total_pass_highPt", false);
67 
68  // efficiency denominator : two offline taus and two online taus (this guarantees that the event passed L1), not necesarily matched
69  // efficiency numerator : hlt fires + two offline taus matched with online taus
70  bool hlt_fires = m_trigDecTool->isPassed(trigger, TrigDefs::Physics);
71  bool tau0_match = matchObjects(offline_tau_vec.at(0), online_tau_vec, 0.2);
72  bool tau1_match = matchObjects(offline_tau_vec.at(1), online_tau_vec, 0.2);
73 
74  dR = offline_tau_vec.at(0)->p4().DeltaR(offline_tau_vec.at(1)->p4());
75  dEta = std::abs(offline_tau_vec.at(0)->p4().Eta() - offline_tau_vec.at(1)->p4().Eta());
76  dPhi = offline_tau_vec.at(0)->p4().DeltaPhi(offline_tau_vec.at(1)->p4());
77  averageMu = lbAverageInteractionsPerCrossing(ctx);
78  HLT_match = hlt_fires && tau0_match && tau1_match;
79 
80  float tau0_pT = offline_tau_vec.at(0)->pt()/Gaudi::Units::GeV;
81  float tau1_pT = offline_tau_vec.at(1)->pt()/Gaudi::Units::GeV;
82  bool is_highPt = tau0_pT > info.getHLTTauThresholds().at(0) + 20.0 && tau1_pT > info.getHLTTauThresholds().at(1) + 20.0;
83 
84  // Total efficiency (without L1 matching)
86  Total_match = static_cast<bool>(HLT_match);
87  fill(monGroup, dR, dEta, dPhi, Total_match);
88 
89  if(is_highPt) {
90  Total_match_highPt = static_cast<bool>(HLT_match);
91  fill(monGroup, dR, dEta, dPhi, Total_match_highPt);
92  }
93  }
94 
95  // Require also 2 online tau candidates (thus, the efficiency is with respect to L1)
96  if(l1_accept_flag && online_tau_vec.size() == 2) {
97  fill(monGroup, dR, dEta, dPhi, averageMu, HLT_match);
98 
99  if(is_highPt) {
100  HLT_match_highPt = static_cast<bool>(HLT_match);
101  fill(monGroup, dR, dEta, dPhi, HLT_match_highPt);
102  }
103  }
104 
105  ATH_MSG_DEBUG("After fill DiTau HLT efficiencies: " << trigger);
106 }
107 
108 
109 void TrigTauMonitorDiTauAlgorithm::fillDiTauVars(const std::string& trigger, const std::vector<const xAOD::TauJet*>& tau_vec) const
110 {
111  ATH_MSG_DEBUG("Fill DiTau Variables: " << trigger);
112 
113  auto monGroup = getGroup(trigger+"_DiTauVars");
114 
115  if(tau_vec.size() != 2) return;
116 
117  auto leadHLTEt = Monitored::Scalar<float>("leadHLTEt", 0.0);
118  auto subleadHLTEt = Monitored::Scalar<float>("subleadHLTEt", 0.0);
119  auto leadHLTEta = Monitored::Scalar<float>("leadHLTEta", 0.0);
120  auto subleadHLTEta = Monitored::Scalar<float>("subleadHLTEta", 0.0);
121  auto leadHLTPhi = Monitored::Scalar<float>("leadHLTPhi", 0.0);
122  auto subleadHLTPhi = Monitored::Scalar<float>("subleadHLTPhi", 0.0);
123  auto dR = Monitored::Scalar<float>("dR", 0.0);
124  auto dEta = Monitored::Scalar<float>("dEta", 0.0);
125  auto dPhi = Monitored::Scalar<float>("dPhi", 0.0);
126 
127  auto Pt = Monitored::Scalar<float>("Pt", 0.0);
128  auto Eta = Monitored::Scalar<float>("Eta", 0.0);
129  auto Phi = Monitored::Scalar<float>("Phi", 0.0);
130  auto M = Monitored::Scalar<float>("M", 0.0);
131  auto dPt = Monitored::Scalar<float>("dPt", 0.0);
132 
133  // Get the index of the leading and the subleading tau
134  unsigned int index0 = 0, index1 = 1;
135  if(tau_vec.at(1)->p4().Pt() > tau_vec.at(0)->p4().Pt()) {
136  index0 = 1;
137  index1 = 0;
138  }
139 
140  TLorentzVector leadTau4V, subleadTau4V, diTau4V;
141  leadTau4V.SetPtEtaPhiM(0,0,0,0);
142  subleadTau4V.SetPtEtaPhiM(0,0,0,0);
143 
144  leadTau4V = tau_vec.at(index0)->p4();
145  subleadTau4V = tau_vec.at(index1)->p4();
146  diTau4V = leadTau4V + subleadTau4V;
147 
148  leadHLTEt = leadTau4V.Pt()/Gaudi::Units::GeV;
149  subleadHLTEt = subleadTau4V.Pt()/Gaudi::Units::GeV;
150  leadHLTEta = leadTau4V.Eta();
151  subleadHLTEta = subleadTau4V.Eta();
152  leadHLTPhi = leadTau4V.Phi();
153  subleadHLTPhi = subleadTau4V.Phi();
154  dR = leadTau4V.DeltaR(subleadTau4V);
155  dEta = std::abs(leadTau4V.Eta() - subleadTau4V.Eta());
156  dPhi = leadTau4V.DeltaPhi(subleadTau4V);
157 
158  dPt = std::abs((leadTau4V.Pt() - subleadTau4V.Pt())/Gaudi::Units::GeV);
159  Pt = diTau4V.Pt()/Gaudi::Units::GeV;
160  Eta = diTau4V.Eta();
161  Phi = diTau4V.Phi();
162  M = diTau4V.M()/Gaudi::Units::GeV;
163 
164  fill(monGroup, leadHLTEt, subleadHLTEt, leadHLTEta, subleadHLTEta, leadHLTPhi, subleadHLTPhi, dR, dEta, dPhi, dPt, Pt, Eta, Phi, M);
165 
166  ATH_MSG_DEBUG("After fill DiTau variables: " << trigger);
167 }
grepfile.info
info
Definition: grepfile.py:38
TrigTauMonitorDiTauAlgorithm::m_requireOfflineTaus
Gaudi::Property< bool > m_requireOfflineTaus
Definition: TrigTauMonitorDiTauAlgorithm.h:21
python.TIDAMonTool.monGroup
def monGroup(analysis_chain)
Definition: TIDAMonTool.py:297
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
AthMonitorAlgorithm::m_trigDecTool
PublicToolHandle< Trig::TrigDecisionTool > m_trigDecTool
Tool to tell whether a specific trigger is passed.
Definition: AthMonitorAlgorithm.h:340
xAOD::passBits
passBits
Definition: TrigPassBits_v1.cxx:115
TrigTauMonitorBaseAlgorithm::classifyTausAll
std::vector< const xAOD::TauJet * > classifyTausAll(const std::vector< const xAOD::TauJet * > &taus, const float threshold=0.0) const
Definition: TrigTauMonitorBaseAlgorithm.cxx:304
Phi
@ Phi
Definition: RPCdef.h:8
TrigTauMonitorBaseAlgorithm::m_do_variable_plots
Gaudi::Property< bool > m_do_variable_plots
Definition: TrigTauMonitorBaseAlgorithm.h:41
TrigTauMonitorBaseAlgorithm::getOnlineTausAll
std::vector< const xAOD::TauJet * > getOnlineTausAll(const std::string &trigger, bool include_0P=true) const
Definition: TrigTauMonitorBaseAlgorithm.cxx:55
Trk::index1
@ index1
Definition: BoundarySurfaceFace.h:48
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
TauGNNUtils::Variables::Track::dPhi
bool dPhi(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:538
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.
TrigTauMonitorDiTauAlgorithm::fillDiTauHLTEfficiencies
void fillDiTauHLTEfficiencies(const EventContext &ctx, const std::string &trigger, const bool l1_accept_flag, const std::vector< const xAOD::TauJet * > &offline_tau_vec, const std::vector< const xAOD::TauJet * > &online_tau_vec) const
Definition: TrigTauMonitorDiTauAlgorithm.cxx:48
Trk::index0
@ index0
Definition: BoundarySurfaceFace.h:47
TrigTauMonitorBaseAlgorithm::dR
double dR(const double eta1, const double phi1, const double eta2, const double phi2) const
Definition: TrigTauMonitorBaseAlgorithm.h:65
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TrigTauMonitorBaseAlgorithm
Definition: TrigTauMonitorBaseAlgorithm.h:24
TrigTauMonitorBaseAlgorithm::m_do_efficiency_plots
Gaudi::Property< bool > m_do_efficiency_plots
Definition: TrigTauMonitorBaseAlgorithm.h:40
AthMonitorAlgorithm::lbAverageInteractionsPerCrossing
virtual float lbAverageInteractionsPerCrossing(const EventContext &ctx=Gaudi::Hive::currentContext()) const
Calculate the average mu, i.e.
Definition: AthMonitorAlgorithm.cxx:222
TrigTauInfo
Definition: TrigTauInfo.h:15
TrigTauMonitorDiTauAlgorithm::m_doTotalEfficiency
Gaudi::Property< bool > m_doTotalEfficiency
Definition: TrigTauMonitorDiTauAlgorithm.h:18
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigTauMonitorBaseAlgorithm::matchObjects
bool matchObjects(const T1 *tau, const std::vector< const T2 * > &tau_vec, float threshold) const
Definition: TrigTauMonitorBaseAlgorithm.h:73
TrigTauMonitorBaseAlgorithm::m_triggers
Gaudi::Property< std::vector< std::string > > m_triggers
Definition: TrigTauMonitorBaseAlgorithm.h:32
TrigTauMonitorBaseAlgorithm::getTrigInfo
const TrigTauInfo & getTrigInfo(const std::string &trigger) const
Definition: TrigTauMonitorBaseAlgorithm.h:45
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigTauMonitorDiTauAlgorithm::processEvent
virtual StatusCode processEvent(const EventContext &ctx) const override
Definition: TrigTauMonitorDiTauAlgorithm.cxx:13
TauGNNUtils::Variables::Track::dEta
bool dEta(const xAOD::TauJet &tau, const xAOD::TauTrack &track, double &out)
Definition: TauGNNUtils.cxx:527
TrigTauMonitorDiTauAlgorithm.h
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
Definition: AthMonitorAlgorithm.cxx:164
Eta
@ Eta
Definition: RPCdef.h:8
TrigTauMonitorDiTauAlgorithm::TrigTauMonitorDiTauAlgorithm
TrigTauMonitorDiTauAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigTauMonitorDiTauAlgorithm.cxx:8
TrigTauMonitorBaseAlgorithm::getOfflineTausAll
std::vector< const xAOD::TauJet * > getOfflineTausAll(const EventContext &ctx, const float threshold=20.0) const
Definition: TrigTauMonitorBaseAlgorithm.cxx:83
TrigTauMonitorDiTauAlgorithm::fillDiTauVars
void fillDiTauVars(const std::string &trigger, const std::vector< const xAOD::TauJet * > &tau_vec) const
Definition: TrigTauMonitorDiTauAlgorithm.cxx:109