ATLAS Offline Software
Loading...
Searching...
No Matches
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
15DipsCondition::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
57float 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
106bool
108 const std::unique_ptr<ITrigJetHypoInfoCollector>& c) const {
109 auto result = isSatisfied(ips[0], c);
110 return result;
111}
112
113
114std::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}
std::vector< pHypoJet > HypoJetVector
Definition HypoJetDefs.h:27
std::shared_ptr< const HypoJet::IJet > pHypoJet
Definition HypoJetDefs.h:25
static Double_t ss
float evaluateDips(const float &dips_pb, const float &dips_pc, const float &dips_pu) const
std::string m_decName_isValid
std::string m_decName_pu
std::string m_decName_pc
std::string m_decName_pb
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="")
std::string toString() const override
double m_workingPoint
bool isSatisfied(const HypoJetVector &, const std::unique_ptr< ITrigJetHypoInfoCollector > &) const override
float getDipsDecValue(const pHypoJet &ip, const std::unique_ptr< ITrigJetHypoInfoCollector > &collector, const std::string &decName) const
float safeLogRatio(float num, float denom)