diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/EventCleaningTool.h b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/EventCleaningTool.h new file mode 100644 index 0000000000000000000000000000000000000000..7c425c5918832f025f682454c6efaf208bf83178 --- /dev/null +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/EventCleaningTool.h @@ -0,0 +1,79 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef __EVENTCLEANINGTOOL__ +#define __EVENTCLEANINGTOOL__ + +/** + @class EventCleaningTool + @brief Class for selecting jets that pass cleaning cuts + + @author Julia Gonski + @date Nov 2016 +*/ + +// Stdlib includes +#include <string> +#include <vector> +#include <unordered_map> + +// Base classes +#include "AsgTools/AsgTool.h" +#include "AsgTools/AnaToolHandle.h" + +// Local includes +#include "PATCore/TAccept.h" +#include "IEventCleaningTool.h" +#include "xAODJet/Jet.h" +#include "xAODEventInfo/EventInfo.h" +#include "JetSelectorTools/JetCleaningTool.h" +#include "JetInterface/IJetSelector.h" + +namespace ECUtils +{ + +class EventCleaningTool : public virtual IEventCleaningTool, + public asg::AsgTool +{ + + /// Create a proper constructor for Athena + ASG_TOOL_CLASS(EventCleaningTool,IEventCleaningTool) + + public: + + /** Standard constructor */ + EventCleaningTool(const std::string& name="EventCleaningTool"); + + /** Standard destructor */ + virtual ~EventCleaningTool(); + + /** Initialize method */ + virtual StatusCode initialize() override; + + /** Initialize method */ + virtual StatusCode finalize(); + + virtual bool acceptEvent(const xAOD::JetContainer* jets) const override; + + virtual int keepJet(const xAOD::Jet& jet) const override; + + private: + double m_pt; + double m_eta; + std::string m_jvt; + std::string m_or; + std::string m_prefix; + bool m_decorate; + std::string m_cleaningLevel; + asg::AnaToolHandle<IJetSelector> m_jetCleaningTool; //! + + std::unique_ptr<SG::AuxElement::Decorator<char>> m_dec_jetClean; + std::unique_ptr<SG::AuxElement::Accessor<char>> m_acc_passJvt; + std::unique_ptr<SG::AuxElement::Accessor<char>> m_acc_passOR; + + +}; // End: class definition +}//ECUtils + +#endif diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/IEventCleaningTool.h b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/IEventCleaningTool.h new file mode 100644 index 0000000000000000000000000000000000000000..c3e270d4e4ab1d743e0b0a78cfe549161a21df94 --- /dev/null +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/IEventCleaningTool.h @@ -0,0 +1,43 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef ASSOCIATIONUTILS_IEVENTCLEANINGTOOL_H +#define ASSOCIATIONUTILS_IEVENTCLEANINGTOOL_H + +// Framework includes +#include "AsgTools/IAsgTool.h" + +// EDM includes +#include "xAODJet/JetContainer.h" + + +namespace ECUtils +{ + + /// @class IEventCleaningTool + /// @brief Interface for the event cleaning tool + /// + /// @author Julia Gonski <j.gonski@cern.ch> + /// + class IEventCleaningTool : public virtual asg::IAsgTool + { + + /// Declare the interface + ASG_TOOL_INTERFACE(IEventCleaningTool) + + public: + + /// Top-level method for performing full overlap-removal. + /// The individual OR methods will be called in the recommended order, + /// and the considered objects will be decorated with the output result. + virtual bool + acceptEvent(const xAOD::JetContainer* jets) const = 0; + + virtual int keepJet(const xAOD::Jet& jet) const =0; + +}; // class IEventCleaningTool + +} // namespace ECUtils + +#endif diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/JetSelectorToolsDict.h b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/JetSelectorToolsDict.h index 06fb16f0c35c523ebd1769221d2eb1e59974dabf..3359300bc33cb19fe21c01048be43127741cbbee 100644 --- a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/JetSelectorToolsDict.h +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/JetSelectorToolsDict.h @@ -11,7 +11,7 @@ // Includes for the dictionary generation: #include "JetSelectorTools/JetCleaningTool.h" - +#include "JetSelectorTools/EventCleaningTool.h" #include "JetSelectorTools/JetAttributeSelector.h" #endif // JETSELECTORTOOLS_JETSELECTORTOOLSDICT_H diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/selection.xml b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/selection.xml index 8bcb8ccad471f2474012334f5f6ab8584bfb3ce0..efe974762b8ee9e044bbff90c144b36eb2de2347 100644 --- a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/selection.xml +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/selection.xml @@ -1,6 +1,7 @@ <lcgdict> <!-- Jet cleaning tools --> <class name="JetCleaningTool" /> + <class name="ECUtils::EventCleaningTool" /> <class name="JetAttributeSelector" /> <class name="JetAttributeRatioSelector" /> <class name="JetAbsAttributeSelector" /> diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/Root/EventCleaningTool.cxx b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/Root/EventCleaningTool.cxx new file mode 100644 index 0000000000000000000000000000000000000000..676042656b2b50adef1317300b6a9ee831682f14 --- /dev/null +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/Root/EventCleaningTool.cxx @@ -0,0 +1,140 @@ +/* + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +*/ + +/****************************************************************************** +Name: EventCleaningTool + +Author: Julia Gonski +Created: Nov 2016 + +Description: Class for selecting events that pass recommended jet cleaning procedure +******************************************************************************/ + +// This class header and package headers +#include "JetSelectorTools/EventCleaningTool.h" +#include "JetSelectorTools/JetCleaningTool.h" +#include "JetSelectorTools/Helpers.h" + +// The xAOD jet type +#include "xAODJet/Jet.h" +#include "xAODEventInfo/EventInfo.h" + +// xAOD/ASG includes +#include "AsgTools/AsgMessaging.h" + +// STL includes +#include <iostream> +#include <cmath> +#include <cfloat> + +// ROOT includes +#include "TEnv.h" + +namespace ECUtils { + +//============================================================================= +// Constructors +//============================================================================= +EventCleaningTool::EventCleaningTool(const std::string& name) + : asg::AsgTool(name) + , m_pt() + , m_eta() + , m_jvt() + , m_or() + , m_prefix() + , m_decorate() + , m_cleaningLevel() + , m_jetCleaningTool("JetCleaningTool/JetCleaningTool") +{ + declareProperty( "PtCut" , m_pt = 20000.0 ); + declareProperty( "EtaCut" , m_eta = 4.5 ); + declareProperty( "JvtDecorator" , m_jvt = "passJvt" ); + declareProperty( "OrDecorator" , m_or = "passOR" ); + declareProperty( "JetCleanPrefix", m_prefix = "" ); + declareProperty( "DoDecorations", m_decorate = true ); + declareProperty( "CleaningLevel" , m_cleaningLevel = "LooseBad"); + m_jetCleaningTool.declarePropertyFor(this, "JetCleaningTool"); +} + + +//============================================================================= +// Destructor +//============================================================================= +EventCleaningTool::~EventCleaningTool() {} + +//============================================================================= +// Initialize +//============================================================================= +StatusCode EventCleaningTool::initialize() +{ + if(m_jvt == "" || m_or == ""){ + ATH_MSG_ERROR( "Tool initialized with unknown decorator names." ); + return StatusCode::FAILURE; + } + if (m_cleaningLevel == ""){ + ATH_MSG_ERROR( "Tool initialized with unknown cleaning level." ); + return StatusCode::FAILURE; + } + + //initialize jet cleaning tool + ATH_CHECK(m_jetCleaningTool.setProperty("CutLevel", m_cleaningLevel )); + ATH_CHECK(m_jetCleaningTool.retrieve()); + ATH_MSG_INFO( "Event cleaning tool configured with cut level " << m_cleaningLevel ); + + //create the decorators + m_acc_passJvt = std::make_unique<SG::AuxElement::Accessor<char>>(m_prefix + m_jvt); + m_acc_passOR = std::make_unique<SG::AuxElement::Accessor<char>>(m_prefix + m_or); + if(m_decorate) m_dec_jetClean = std::make_unique<SG::AuxElement::Decorator<char>>(m_prefix + "jetClean_" + m_cleaningLevel); + + return StatusCode::SUCCESS; +} + +bool EventCleaningTool::acceptEvent(const xAOD::JetContainer* jets) const +{ + bool pass_pt = 0; + bool pass_eta = 0; + bool pass_accept = 0; + int jvtDecision = 0; + int orDecision = 0; + bool isThisJetGood = 0; + bool isEventAllGood = 1; + ATH_MSG_DEBUG("m_or: " << m_or << ", m_jvt: " << m_jvt); + + for (auto thisJet : *jets){ //loop over decorated jet collection + pass_pt = thisJet->pt() > m_pt; + pass_eta = fabs(thisJet->eta()) < m_eta; + pass_accept = keepJet(*thisJet); + jvtDecision = (*m_acc_passJvt)(*thisJet); + orDecision = !(*m_acc_passOR)(*thisJet); //recall, passOR==0 means that the jet is not an overlap and should be kept! + + ATH_MSG_DEBUG("Jet info: pT: " << pass_pt << ", eta: " << pass_eta << ", accept? " << pass_accept << ", jvt: " << jvtDecision << ", or: " << orDecision); + if(pass_pt && pass_eta && jvtDecision && orDecision){//only consider jets for cleaning if they pass these requirements. + isThisJetGood = pass_accept; + isEventAllGood = isEventAllGood && isThisJetGood; //any event with a bad jet is rejected + } + 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 + ATH_MSG_DEBUG("Is jet good? " << isThisJetGood); + if(m_decorate) (*m_dec_jetClean)(*thisJet) = isThisJetGood; + } + ATH_MSG_DEBUG("Is event good? " << isEventAllGood); + return isEventAllGood; +} + +int EventCleaningTool::keepJet(const xAOD::Jet& jet) const +{ + return m_jetCleaningTool->keep(jet); +} + +//============================================================================= +// Finalize +//============================================================================= +StatusCode EventCleaningTool::finalize() +{ + return StatusCode::SUCCESS; + +} + +}//ECUtils + + diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/python/ConfiguredJetCleaningTools.py b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/python/ConfiguredJetCleaningTools.py index 9902790edf8d05d94ed2b928640b68e56b0c2aee..d15e78e74735031852d7e883013e4b9917693007 100644 --- a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/python/ConfiguredJetCleaningTools.py +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/python/ConfiguredJetCleaningTools.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration ##============================================================================= ## Name: ConfiguredJetCleaningTools @@ -17,6 +17,7 @@ from AthenaCommon import CfgMgr # Import the needed stuff specific to the JetCleaning from JetSelectorTools.JetSelectorToolsConf import JetCleaningTool +from JetSelectorTools.JetSelectorToolsConf import ECUtils__EventCleaningTool as EventCleaningTool from JetSelectorTools.JetCleaningCutDefs import * @@ -40,7 +41,15 @@ from JetSelectorTools.JetCleaningCutDefs import * # # return tool - +def recEventCleaningTool(name='EventCleaningTool'): + """ + Arguments: + name - set the name of the master tool. + """ + # Configure the master tool + ecTool = EventCleaningTool(name) + + return ecTool def ConfiguredJetCleaningTool_Loose( name, **kw ): diff --git a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/src/components/JetSelectorTools_entries.cxx b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/src/components/JetSelectorTools_entries.cxx index ceb2a64492c39fd066e4202e1e7e07eaa15d64c6..85078b215089101e4dc0f1cee703dbbd9b9bd354 100644 --- a/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/src/components/JetSelectorTools_entries.cxx +++ b/PhysicsAnalysis/JetMissingEtID/JetSelectorTools/src/components/JetSelectorTools_entries.cxx @@ -1,12 +1,15 @@ #include "GaudiKernel/DeclareFactoryEntries.h" #include "JetSelectorTools/JetCleaningTool.h" +#include "JetSelectorTools/EventCleaningTool.h" DECLARE_TOOL_FACTORY( JetCleaningTool ) +DECLARE_TOOL_FACTORY( ECUtils::EventCleaningTool ) DECLARE_FACTORY_ENTRIES( JetSelectorTools ) { DECLARE_TOOL( JetCleaningTool ); + DECLARE_TOOL( ECUtils::EventCleaningTool ); }