ATLAS Offline Software
GNTauCondition.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "./GNTauCondition.h"
10 
11 #include <sstream>
12 #include <cmath>
13 #include <TLorentzVector.h>
14 
15 GNTauCondition::GNTauCondition(double workingPoint,
16  const std::string &decName_ptau,
17  const std::string &decName_pu,
18  const std::string &decName_isValid) :
19  m_workingPoint(workingPoint),
20  m_decName_ptau(decName_ptau),
21  m_decName_pu(decName_pu),
22  m_decName_isValid(decName_isValid)
23 {
24 
25 }
26 
28  const std::unique_ptr<ITrigJetHypoInfoCollector> &collector,
29  const std::string &decName) const
30 {
31 
32  float momentValue = -1;
33  if (!(ip->getAttribute(decName, momentValue)))
34  {
35  if (collector)
36  {
37  auto j_addr = static_cast<const void *>(ip.get());
38 
39  std::stringstream ss0;
40  ss0 << "GNTauCondition: "
41  << " unable to retrieve " << decName << '\n';
42  std::stringstream ss1;
43  ss1 << " jet : (" << j_addr << ")";
44  collector->collect(ss0.str(), ss1.str());
45  }
46 
47  throw std::runtime_error("Impossible to retrieve decorator \'" + decName + "\' for jet hypo");
48  }
49 
50  return momentValue;
51 }
52 
53 float GNTauCondition::evaluateGNTau(const float &gntau_ptau,
54  const float &gntau_pu) const {
55  return safeLogRatio(gntau_ptau, gntau_pu);
56 }
57 
59  const std::unique_ptr<ITrigJetHypoInfoCollector> &collector) const
60 {
61  if (!m_decName_isValid.empty()) {
62  // short circuit if gntau is invalid and we ask for a check
63  //
64  // we have to dynamic cast to xAOD jets here because there's no char
65  // accessor on IJet and it's not clear if we need one generally.
66  const auto* jet = dynamic_cast<const HypoJet::xAODJetAsIJet*>(ip.get());
67  if (!jet) throw std::runtime_error("Fast gntau has to run on xAOD::Jet");
68  char valid = (*jet->xAODJet())->getAttribute<char>(m_decName_isValid);
69  if (valid == 0) return false;
70  }
71 
72  // if we got this far check the gntau hypo
73  float gntau_ptau = getGNTauDecValue(ip, collector, m_decName_ptau);
74  float gntau_pu = getGNTauDecValue(ip, collector, m_decName_pu);
75  float gntau_output = evaluateGNTau(gntau_ptau, gntau_pu);
76 
77  bool pass = (gntau_output >= m_workingPoint);
78 
79  if (collector)
80  {
81  const void *address = static_cast<const void *>(this);
82 
83  std::stringstream ss0;
84  ss0 << "GNTauCondition: (" << address
85  << ")"
86  << " pass: " << std::boolalpha << pass << '\n';
87 
88  auto j_addr = static_cast<const void *>(ip.get());
89  std::stringstream ss1;
90  ss1 << " jet : (" << j_addr << ") "
91  << m_decName_ptau << " value: " << gntau_ptau << '\n';
92 
93  collector->collect(ss0.str(), ss1.str());
94  }
95 
96  return pass;
97 }
98 
99 bool
101  const std::unique_ptr<ITrigJetHypoInfoCollector>& c) const {
102  auto result = isSatisfied(ips[0], c);
103  return result;
104 }
105 
106 
107 std::string GNTauCondition::toString() const {
108  std::stringstream ss;
109  ss << "GNTauCondition (" << this << ") "
110  << " Cleaning decs: "
111  << m_decName_ptau << ", "
112  << m_decName_pu << ", "
113  <<'\n';
114 
115  return ss.str();
116 }
GNTauCondition::m_decName_pu
std::string m_decName_pu
Definition: GNTauCondition.h:50
get_generator_info.result
result
Definition: get_generator_info.py:21
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
safeLogRatio
float safeLogRatio(float num, float denom)
Definition: safeLogRatio.cxx:9
GNTauCondition::m_decName_isValid
std::string m_decName_isValid
Definition: GNTauCondition.h:51
IJet.h
xAODJetAsIJet.h
ITrigJetHypoInfoCollector::collect
virtual void collect(const std::string &, const std::string &)=0
pHypoJet
std::shared_ptr< const HypoJet::IJet > pHypoJet
Definition: HypoJetDefs.h:25
calibdata.valid
list valid
Definition: calibdata.py:45
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
GNTauCondition.h
GNTauCondition::getGNTauDecValue
float getGNTauDecValue(const pHypoJet &ip, const std::unique_ptr< ITrigJetHypoInfoCollector > &collector, const std::string &decName) const
Definition: GNTauCondition.cxx:27
find_tgc_unfilled_channelids.ip
ip
Definition: find_tgc_unfilled_channelids.py:3
HypoJetVector
std::vector< pHypoJet > HypoJetVector
Definition: HypoJetDefs.h:27
GNTauCondition::toString
std::string toString() const override
Definition: GNTauCondition.cxx:107
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
ITrigJetHypoInfoCollector.h
GNTauCondition::m_decName_ptau
std::string m_decName_ptau
Definition: GNTauCondition.h:49
GNTauCondition::isSatisfied
bool isSatisfied(const HypoJetVector &, const std::unique_ptr< ITrigJetHypoInfoCollector > &) const override
Definition: GNTauCondition.cxx:100
GNTauCondition::m_workingPoint
double m_workingPoint
Definition: GNTauCondition.h:48
GNTauCondition::GNTauCondition
GNTauCondition(double workingPoint, const std::string &decName_ptau, const std::string &decName_pu, const std::string &decName_isValid="")
Definition: GNTauCondition.cxx:15
safeLogRatio.h
HypoJet::xAODJetAsIJet
Definition: xAODJetAsIJet.h:16
python.compressB64.c
def c
Definition: compressB64.py:93
GNTauCondition::evaluateGNTau
float evaluateGNTau(const float &gntau_ptau, const float &gntau_pu) const
Definition: GNTauCondition.cxx:53