ATLAS Offline Software
JetClusterMomentsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9  : asg::AsgTool(name)
10 {
11 }
12 
14  if(m_jetContainerName.empty()){
15  ATH_MSG_ERROR("JetClusterMomentsTool needs to have its input jet container name configured!");
16  return StatusCode::FAILURE;
17  }
18 
19  if(!m_clsPtKey.empty()) m_clsPtKey = m_jetContainerName + "." + m_clsPtKey.key();
23 
24  ATH_CHECK(m_clsPtKey.initialize(SG::AllowEmpty));
28 
29  return StatusCode::SUCCESS;
30 }
31 
33 
34  // Use pointers here so we can create only the ones we're configured for
35  std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handlePt;
36  std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleSecondLambda;
37  std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleCenterLambda;
38  std::unique_ptr<SG::WriteDecorHandle<xAOD::JetContainer, float> > handleSecondR;
39 
40  if(!m_clsPtKey.empty()) handlePt = std::make_unique<SG::WriteDecorHandle<xAOD::JetContainer, float> >(m_clsPtKey);
44 
45  for(const xAOD::Jet* jet : jets){
46  // Find leading constituent cluster
47  const xAOD::CaloCluster* leadingCluster = findLeadingCluster(*jet);
48  ATH_MSG_DEBUG("Leading cluster retrieving finished.");
49  if(!leadingCluster){
50  ATH_MSG_WARNING("Jet has no CaloCluster constituents, leading cluster not found");
51  return StatusCode::FAILURE;
52  }
53  // Set info
54  if(handlePt.get() != nullptr) (*handlePt)(*jet) = leadingCluster->pt();
55  if(handleSecondLambda.get() != nullptr) (*handleSecondLambda)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::SECOND_LAMBDA);
56  if(handleCenterLambda.get() != nullptr) (*handleCenterLambda)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::CENTER_LAMBDA);
57  if(handleSecondR.get() != nullptr) (*handleSecondR)(*jet) = getMoment(leadingCluster, xAOD::CaloCluster::SECOND_R);
58  }
59  return StatusCode::SUCCESS;
60 }
61 
63 
64  // Retrieve the associated clusters.
65 
66  if ( jet.numConstituents() == 0 ) return nullptr;
67  const xAOD::CaloCluster * cl_leading = nullptr;
68 
69 
70  switch( jet.rawConstituent(0)->type() ) {
72  for (size_t i_cl = 0; i_cl < jet.numConstituents(); i_cl++){ // loop all constituents
73  const xAOD::CaloCluster * cl_current = dynamic_cast<const xAOD::CaloCluster*> (jet.rawConstituent(i_cl));
74  if (!cl_leading || cl_leading->pt() < cl_current->pt() ) cl_leading = cl_current;
75  }
76 
77  } break;
78 
79  case xAOD::Type::Jet: {
80  for (size_t i_cl = 0; i_cl < jet.numConstituents(); i_cl++){ // loop all constituents
81  const xAOD::Jet * jet_constit = dynamic_cast<const xAOD::Jet*> (jet.rawConstituent(i_cl));
82  if (!jet_constit) continue;
83  const xAOD::CaloCluster * cl_current = findLeadingCluster( *jet_constit ) ;
84  if(cl_current) if (!cl_leading || cl_leading->pt() < cl_current->pt() ) cl_leading = cl_current;
85  }
86 
87  } break;
88  default:
89  break;
90  } // end switch
91  return cl_leading;
92 }
93 
95  if (cluster){ // if we have a pointer than read the moment
96  double moment = 0.0;
97  bool isRetrieved = cluster->retrieveMoment(momentType, moment);
98  if (isRetrieved) return (float) moment;
99  }
100  ATH_MSG_WARNING("Can not retrieved moment from cluster");
101  return 0.0;
102 }
xAOD::CaloCluster_v1::SECOND_R
@ SECOND_R
Second Moment in .
Definition: CaloCluster_v1.h:123
JetClusterMomentsTool::getMoment
float getMoment(const xAOD::CaloCluster *cluster, const xAOD::CaloCluster::MomentType &momentType) const
Definition: JetClusterMomentsTool.cxx:94
JetClusterMomentsTool.h
JetClusterMomentsTool::findLeadingCluster
const xAOD::CaloCluster * findLeadingCluster(const xAOD::Jet &jet) const
Definition: JetClusterMomentsTool.cxx:62
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
asg
Definition: DataHandleTestTool.h:28
xAOD::CaloCluster_v1::CENTER_LAMBDA
@ CENTER_LAMBDA
Shower depth at Cluster Centroid.
Definition: CaloCluster_v1.h:136
JetClusterMomentsTool::m_clsCenterLambdaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsCenterLambdaKey
Definition: JetClusterMomentsTool.h:50
JetClusterMomentsTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetClusterMomentsTool.cxx:13
JetClusterMomentsTool::m_clsSecondLambdaKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondLambdaKey
Definition: JetClusterMomentsTool.h:49
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::CaloCluster_v1::SECOND_LAMBDA
@ SECOND_LAMBDA
Second Moment in .
Definition: CaloCluster_v1.h:124
JetClusterMomentsTool::m_clsSecondRKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsSecondRKey
Definition: JetClusterMomentsTool.h:51
xAOD::CaloCluster_v1::MomentType
MomentType
Enums to identify different moments.
Definition: CaloCluster_v1.h:120
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
JetClusterMomentsTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetClusterMomentsTool.cxx:32
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::CaloCluster_v1::retrieveMoment
bool retrieveMoment(MomentType type, double &value) const
Retrieve individual moment.
Definition: CaloCluster_v1.cxx:738
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
JetClusterMomentsTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetClusterMomentsTool.h:44
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Definition: CaloCluster_v1.cxx:247
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
JetClusterMomentsTool::m_clsPtKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_clsPtKey
Definition: JetClusterMomentsTool.h:48
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
JetClusterMomentsTool::JetClusterMomentsTool
JetClusterMomentsTool(const std::string &name)
Definition: JetClusterMomentsTool.cxx:8