ATLAS Offline Software
TrigBjetBtagHypoTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // ************************************************
6 //
7 // NAME: TrigBjetBtagHypoTool.cxx
8 // PACKAGE: Trigger/TrigHypothesis/TrigBjetHypoTool
9 //
10 // AUTHOR: Carlo Varni
11 // EMAIL: carlo.varni@cern.ch
12 //
13 // ************************************************
14 
17 #include "TrigBjetBtagHypoTool.h"
18 #include "xAODBTagging/BTagging.h"
20 
22  const std::string& name,
23  const IInterface* parent ) :
25  m_decisionId( HLT::Identifier::fromToolName( name ) ) {}
26 
27  // -----------------------------------------------------------------------------------------------------------------
28 
30 
31  ATH_MSG_DEBUG( "declareProperty review:" );
32  ATH_MSG_DEBUG( "Tool configured for chain/id: " << m_decisionId );
33 
34  if ( not m_monTool.name().empty() ) {
35  ATH_CHECK( m_monTool.retrieve() );
36  ATH_MSG_DEBUG("MonTool name: " << m_monTool);
37  }
38  ATH_CHECK(m_checks.retrieve());
39 
40  for (const auto& monpair: m_monMap) {
41  m_monPairs.emplace_back(monpair.first, monpair.second);
42  }
43 
44  return StatusCode::SUCCESS;
45  }
46 
47 // -----------------------------------------------------------------------------------------------------------------
48 
49 StatusCode TrigBjetBtagHypoTool::decide( std::vector< TrigBjetBtagHypoToolInfo >& bTagInfos ) const {
50 
51  ATH_MSG_DEBUG( "Executing "<< name() );
52 
53  for ( TrigBjetBtagHypoToolInfo& bTagInfo : bTagInfos ) {
54 
55  // -------------------------------------
56  // Check the HypoTool's chain is active
57  if ( not TrigCompositeUtils::passed( getId().numeric(),bTagInfo.previousDecisionIDs ) )
58  continue;
59 
60  // -------------------------------------
61  // Check Primary Vertex
62  const xAOD::Vertex *vertex = *(bTagInfo.vertexEL);
63 
64  ATH_MSG_DEBUG( "Event Vertex [x,y,z]=["
65  << vertex->x()
66  << ","<< vertex->y()
67  << ","<< vertex->z() << "]" );
68 
69  ATH_MSG_DEBUG( " ** Vertex Type = " << vertex->vertexType() );
70 
71  // -------------------------------------
72  // Compute trigger decision
73  bool pass = true;
74  std::string stage = "pass";
75 
76  // check beamspot info, see https://cern.ch/beam-bits
77  int bits = bTagInfo.beamSpot->beamStatus();
78  // beamspot is converged if first and second bit are set
79  bool converged = ((bits | 0b011) == bits);
80  // beamspot is online if thrid bit is set
81  bool online = ((bits | 0b100) == bits);
82 
84  "Beamspot status: 0x" << std::hex << bits << ", "
85  "converged: " << std::boolalpha << converged << ", "
86  "online: " << online);
87 
88  if (m_vetoBadBeamspot && !converged && online) {
89  ATH_MSG_DEBUG( "Beamspot has problems" );
90  ATH_MSG_DEBUG( "Trigger decision is FALSE" );
91  pass = false;
92  stage = "no beamspot";
93  } else if ( vertex->vertexType() != xAOD::VxType::VertexType::PriVtx ) {
94  ATH_MSG_DEBUG( "Vertex is not a valid primary vertex!" );
95  ATH_MSG_DEBUG( "Trigger decision is FALSE" );
96  pass = false;
97  stage = "no primary vertex";
98  } else {
99  const xAOD::BTagging *btagging = *(bTagInfo.btaggingEL);
100 
101  // monitor floats
102  std::vector<Monitored::Scalar<float>> mons;
103  for (const auto& monpair: m_monPairs) {
104  mons.emplace_back(monpair.second, monpair.first(*btagging));
105  }
106 
107  static const SG::ConstAccessor<char> SV1_isDefaultsAcc("SV1_isDefaults");
108  static const SG::ConstAccessor<float> SV1_masssvxAcc("SV1_masssvx");
109  static const SG::ConstAccessor<float> SV1_efracsvxAcc("SV1_efracsvx");
110  if ( not SV1_isDefaultsAcc(*btagging) ){
111  mons.emplace_back("SV1_masssvx",SV1_masssvxAcc(*btagging));
112  mons.emplace_back("SV1_efracsvx",SV1_efracsvxAcc(*btagging));
113  }
114 
115  static const SG::ConstAccessor<char> JetFitter_isDefaultsAcc("JetFitter_isDefaults");
116  static const SG::ConstAccessor<float> JetFitter_massAcc("JetFitter_mass");
117  static const SG::ConstAccessor<float> JetFitter_energyFractionAcc("JetFitter_energyFraction");
118  if ( not JetFitter_isDefaultsAcc(*btagging) ){
119  mons.emplace_back("JetFitter_mass",JetFitter_massAcc(*btagging));
120  mons.emplace_back("JetFitter_energyFraction",JetFitter_energyFractionAcc(*btagging));
121  }
122 
123 
124 
125  std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> mons_wrappers(
126  mons.begin(), mons.end());
127  Monitored::Group(m_monTool, mons_wrappers);
128 
129  for (const auto& check: m_checks) {
130  if (!check->passThreshold(*btagging)) {
131  pass = false;
132  stage = "fail";
133  break;
134  }
135  }
136  }
137 
139 
140 
141  // -------------------------------------
142  if ( pass ) {
143  ATH_MSG_DEBUG( "Selection cut satisfied, accepting the event" );
144  TrigCompositeUtils::addDecisionID( getId().numeric(),bTagInfo.decision );
145  } else {
146  ATH_MSG_DEBUG( "Selection cut not satisfied, rejecting the event" );
147  }
148 
149  ATH_MSG_DEBUG( "PRINTING DECISION" );
150  ATH_MSG_DEBUG( *bTagInfo.decision );
151  }
152 
153  return StatusCode::SUCCESS;
154 }
155 
156 
157 // -----------------------------------------------------------------------------------------------------------------
158 
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
python.FPGATrackSimAnalysisConfig.stage
stage
Definition: FPGATrackSimAnalysisConfig.py:604
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
BTagging.h
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
TrigBjetBtagHypoTool::TrigBjetBtagHypoTool
TrigBjetBtagHypoTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: TrigBjetBtagHypoTool.cxx:21
TrigCompositeUtils::addDecisionID
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
Definition: TrigCompositeUtilsRoot.cxx:61
TrigBjetBtagHypoTool::m_vetoBadBeamspot
Gaudi::Property< bool > m_vetoBadBeamspot
Definition: TrigBjetBtagHypoTool.h:77
TrigBjetBtagHypoTool::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
DeclareProperty: to monitor method used to perform the cut.
Definition: TrigBjetBtagHypoTool.h:70
SG::ConstAccessor< char >
TrigBjetBtagHypoTool::getId
const HLT::Identifier getId() const
Definition: TrigBjetBtagHypoTool.cxx:160
TileSynchronizeBch.online
online
Definition: TileSynchronizeBch.py:88
TrigBjetBtagHypoTool::m_checks
ToolHandleArray< IBJetHypoDiscriminantCheck > m_checks
Definition: TrigBjetBtagHypoTool.h:66
TrigBjetBtagHypoTool.h
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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
TrigBjetBtagHypoTool::initialize
virtual StatusCode initialize() override
Definition: TrigBjetBtagHypoTool.cxx:29
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::BTagging_v1
Definition: BTagging_v1.h:39
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
LArNewCalib_Delay_OFC_Cali.check
check
Definition: LArNewCalib_Delay_OFC_Cali.py:208
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
TrigBjetBtagHypoTool::decide
StatusCode decide(std::vector< TrigBjetBtagHypoToolInfo > &) const
Definition: TrigBjetBtagHypoTool.cxx:49
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
HLTIdentifier.h
TrigBjetBtagHypoTool::TrigBjetBtagHypoToolInfo
Definition: TrigBjetBtagHypoTool.h:38
TrigBjetBtagHypoTool::m_decisionId
HLT::Identifier m_decisionId
Definition: TrigBjetBtagHypoTool.h:64
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
AthAlgTool
Definition: AthAlgTool.h:26
TrigBjetBtagHypoTool::m_monPairs
std::vector< std::pair< SG::AuxElement::ConstAccessor< float >, std::string > > m_monPairs
Definition: TrigBjetBtagHypoTool.h:75
TrigBjetBtagHypoTool::m_monMap
Gaudi::Property< std::map< std::string, std::string > > m_monMap
Definition: TrigBjetBtagHypoTool.h:73
TrigBjetBtagHypoTool::decisionId
TrigCompositeUtils::DecisionID decisionId() const
Definition: TrigBjetBtagHypoTool.cxx:159