ATLAS Offline Software
JetGroomer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "JetRec/JetGroomer.h"
6 
8 #include "fastjet/PseudoJet.hh"
10 
11 using xAOD::JetContainer;
12 
13 using namespace JetGrooming;
14 
15 
17 
18  ATH_MSG_DEBUG("Initializing...");
19 
20  if(m_inputJetContainer.empty()){
21  ATH_MSG_ERROR("Jet grooming requested with no input ungroomed jets");
22  return StatusCode::FAILURE;
23  } else if(m_inputPseudoJets.empty()){
24  ATH_MSG_ERROR("Jet grooming requested with no input pseudojets");
25  return StatusCode::FAILURE;
26  }
27  else{
28  if(!m_finalPseudoJets.empty()){
29  ATH_MSG_WARNING("A non-empty value was found for the FinalPseudoJets WriteHandleKey -- this will be ignored!");
30  }
31 
32  ATH_CHECK(m_inputJetContainer.initialize());
34  m_finalPseudoJets = name() + "FinalPJ";
36  }
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 
42 // Common operations for any jet groomer
43 std::pair<std::unique_ptr<xAOD::JetContainer>,std::unique_ptr<SG::IAuxStore> > JetGroomer::getJets() const {
44  // Return this in case of any problems
45  auto nullreturn = std::make_pair(std::unique_ptr<xAOD::JetContainer>(nullptr), std::unique_ptr<SG::IAuxStore>(nullptr));
46 
47  // -----------------------
48  // retrieve input
50  if(!jetContHandle.isValid()) {
51  ATH_MSG_ERROR("No valid JetContainer with key "<< m_inputJetContainer.key());
52  return nullreturn;
53  }
54 
56  if(!pjContHandle.isValid()) {
57  ATH_MSG_ERROR("No valid PseudoJetContainer with key "<< m_inputPseudoJets.key());
58  return nullreturn;
59  }
60 
61  // Build the container to be returned
62  // Avoid memory leaks with unique_ptr
63  auto groomedJets = std::make_unique<xAOD::JetContainer>();
64  auto auxCont = std::make_unique<xAOD::JetAuxContainer>();
65  groomedJets->setStore(auxCont.get());
66 
67  // -----------------------
68  // Build a new pointer to a PseudoJetVector containing the final groomed PseudoJets
69  // This allows us to own the vector of PseudoJet which we will put in the evt store.
70  // Thus the contained PseudoJet will be kept frozen there and we can safely use pointer to them from the xAOD::Jet objects
71  auto groomPJVector = std::make_unique<PseudoJetVector>( );
72  groomPJVector->resize( jetContHandle->size() );
73 
74  // loop over input jets
75  for (const xAOD::Jet* parentJet: *jetContHandle){
76  // Child will create a groomed jet and insert it into the output container
77  this->insertGroomedJet(*parentJet, *pjContHandle, *groomedJets, *groomPJVector);
78  }
79 
80  // -------------------------------------
81  // record final PseudoJetVector
83  if(!pjVectorHandle.record(std::move(groomPJVector))){
84  ATH_MSG_ERROR("Can't record PseudoJetVector under key "<< m_finalPseudoJets);
85  return nullreturn;
86  }
87 
88  return std::make_pair(std::move(groomedJets),std::move(auxCont));
89 }
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
JetGrooming::JetGroomer::getJets
virtual std::pair< std::unique_ptr< xAOD::JetContainer >, std::unique_ptr< SG::IAuxStore > > getJets() const override final
Method to build the collection and return it to the caller.
Definition: JetGroomer.cxx:43
JetGrooming::JetGroomer::m_finalPseudoJets
SG::WriteHandleKey< PseudoJetVector > m_finalPseudoJets
Definition: JetGroomer.h:60
JetGrooming
Definition: JetGroomer.h:33
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
JetGrooming::JetGroomer::m_inputPseudoJets
SG::ReadHandleKey< PseudoJetContainer > m_inputPseudoJets
This is the input to the parent JetContainer. It is needed in order to re-assign the ghost constituen...
Definition: JetGroomer.h:58
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
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
JetGrooming::JetGroomer::m_inputJetContainer
SG::ReadHandleKey< xAOD::JetContainer > m_inputJetContainer
Handle Input JetContainer (this contains the parent ungroomed jets to be trimmed)
Definition: JetGroomer.h:55
JetGrooming::JetGroomer::insertGroomedJet
virtual void insertGroomedJet(const xAOD::Jet &, const PseudoJetContainer &, xAOD::JetContainer &, PseudoJetVector &) const =0
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
JetGrooming::JetGroomer::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetGroomer.cxx:16
PseudoJetContainer.h
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::JetContainer
JetContainer_v1 JetContainer
Definition of the current "jet container version".
Definition: JetContainer.h:17
JetGroomer.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.