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