ATLAS Offline Software
EventCleaningTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /******************************************************************************
6 Name: EventCleaningTool
7 
8 Author: Julia Gonski
9 Created: Nov 2016
10 
11 Description: Class for selecting events that pass recommended jet cleaning procedure
12 ******************************************************************************/
13 
14 // This class header and package headers
18 
19 // The xAOD jet type
20 #include "xAODJet/Jet.h"
22 
23 // xAOD/ASG includes
27 
28 
29 // STL includes
30 #include <iostream>
31 #include <cmath>
32 #include <cfloat>
33 
34 // ROOT includes
35 #include "TEnv.h"
36 
37 namespace ECUtils {
38 
39 //=============================================================================
40 // Constructors
41 //=============================================================================
43  : asg::AsgTool(name)
44  , m_jetCleaningTool("JetCleaningTool/JetCleaningTool")
45 {
46  m_jetCleaningTool.declarePropertyFor(this, "JetCleaningTool");
47 }
48 
49 
50 //=============================================================================
51 // Destructor
52 //=============================================================================
53 EventCleaningTool::~EventCleaningTool() {}
54 
55 //=============================================================================
56 // Initialize
57 //=============================================================================
59 {
60  if(m_passJvtKey.key() == "" || m_passORKey.key() == ""){
61  ATH_MSG_ERROR( "Tool initialized with unknown decorator names." );
62  return StatusCode::FAILURE;
63  }
64  if (m_cleaningLevel == ""){
65  ATH_MSG_ERROR( "Tool initialized with unknown cleaning level." );
66  return StatusCode::FAILURE;
67  }
68  if(m_jetContainerName == ""){
69  ATH_MSG_ERROR( "Tool initialized with no jet container name." );
70  return StatusCode::FAILURE;
71  }
72 
73  //initialize jet cleaning tool
74  ATH_CHECK(m_jetCleaningTool.setProperty("JetContainer", m_jetContainerName ));
75  ATH_CHECK(m_jetCleaningTool.setProperty("CutLevel", m_cleaningLevel ));
76  ATH_CHECK(m_jetCleaningTool.setProperty("UseDecorations", m_useDecorations )); //for AODs we can't use decorations
77  ATH_CHECK(m_jetCleaningTool.retrieve());
78  ATH_MSG_INFO( "Event cleaning tool configured with cut level " << m_cleaningLevel );
79 
80  m_passJvtKey = m_jetContainerName + "." + m_prefix + m_passJvtKey.key();
81  m_passORKey = m_jetContainerName + "." + m_prefix + m_passORKey.key();
82  m_jetCleanKey = m_jetContainerName + "." + m_prefix + "jetClean_" + m_cleaningLevel;
83 
84  ATH_CHECK(m_passJvtKey.initialize());
85  ATH_CHECK(m_passORKey.initialize());
86  ATH_CHECK(m_jetCleanKey.initialize(m_decorate));
87 
88 #ifndef XAOD_STANDALONE
89  if(m_suppressInputDeps){
90  // The user has promised that this will be produced by the same alg.
91  // Tell the scheduler to ignore it to avoid circular dependencies.
92  renounce(m_passJvtKey);
93  renounce(m_passORKey);
94  }
95  if(m_suppressOutputDeps) {
96  renounce(m_jetCleanKey);
97  }
98 #endif
99 
100  return StatusCode::SUCCESS;
101 }
102 
103 bool EventCleaningTool::acceptEvent(const xAOD::JetContainer* jets) const
104 {
105  bool pass_pt = 0;
106  bool pass_eta = 0;
107  bool pass_accept = 0;
108  int jvtDecision = 0;
109  int orDecision = 0;
110  bool isThisJetGood = 0;
111  bool isEventAllGood = 1;
112 
113  SG::ReadDecorHandle<xAOD::JetContainer, char> jvtHandle(m_passJvtKey);
114  SG::ReadDecorHandle<xAOD::JetContainer, char> orHandle(m_passORKey);
115  SG::WriteDecorHandle<xAOD::JetContainer, char> jetCleanHandle(m_jetCleanKey);
116 
117  for (auto thisJet : *jets){ //loop over decorated jet collection
118  pass_pt = thisJet->pt() > m_pt;
119  pass_eta = fabs(thisJet->eta()) < m_eta;
120  pass_accept = keepJet(*thisJet);
121  jvtDecision = jvtHandle(*thisJet);
122  orDecision = !(orHandle(*thisJet)); //recall, passOR==0 means that the jet is not an overlap and should be kept!
123 
124  ATH_MSG_DEBUG("Jet info: pT: " << pass_pt << ", eta: " << pass_eta << ", accept? " << pass_accept << ", jvt: " << jvtDecision << ", or: " << orDecision);
125  if(pass_pt && pass_eta && jvtDecision && orDecision){//only consider jets for cleaning if they pass these requirements.
126  isThisJetGood = pass_accept;
127  isEventAllGood = isEventAllGood && isThisJetGood; //any event with a bad jet is rejected
128  }
129  else isThisJetGood = pass_accept; //if it fails any one of these, it shouldn't be able to kill the whole event, but we still need to know cleaning
130  ATH_MSG_DEBUG("Is jet good? " << isThisJetGood);
131  if(m_decorate) jetCleanHandle(*thisJet) = isThisJetGood;
132  }
133  ATH_MSG_DEBUG("Is event good? " << isEventAllGood);
134  return isEventAllGood;
135 }
136 
137 int EventCleaningTool::keepJet(const xAOD::Jet& jet) const
138 {
139  return m_jetCleaningTool->keep(jet);
140 }
141 
142 }//ECUtils
143 
144 
Jet.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Helpers.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
asg
Definition: DataHandleTestTool.h:28
AsgMessaging.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EventCleaningTool.h
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
JetCleaningTool.h
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
WriteDecorHandle.h
Handle class for adding a decoration to an object.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
EventInfo.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ReadDecorHandle.h
Handle class for reading a decoration on an object.
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
ECUtils
Definition: EventCleaningTool.h:35
ECUtils::EventCleaningTool::EventCleaningTool
EventCleaningTool(const std::string &name="EventCleaningTool")
Create a proper constructor for Athena.
Definition: EventCleaningTool.cxx:49