ATLAS Offline Software
JetECPSFractionTool.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 // JetECPSFractionTool.cxx
6 
10 #include "xAODPFlow/PFO.h"
11 #include "xAODPFlow/FlowElement.h"
12 #include "CaloGeoHelpers/CaloSampling.h"
13 
14 using xAOD::IParticle;
15 using xAOD::CaloCluster;
17 using xAOD::JetFourMom_t;
18 
19 #undef JetECPSFractionTool_DEBUG
20 
21 //**********************************************************************
22 
23 JetECPSFractionTool::JetECPSFractionTool(const std::string& myname)
24 : asg::AsgTool(myname) {
25 }
26 
27 //**********************************************************************
28 
30 
31  if(m_jetContainerName.empty()){
32  ATH_MSG_ERROR("JetECPSFractionTool needs to have its input jet container name configured!");
33  return StatusCode::FAILURE;
34  }
35 
36  // Prepend jet collection name
37  m_fracKey = m_jetContainerName + "." + m_fracKey.key();
38 
39  ATH_CHECK(m_fracKey.initialize());
40  return StatusCode::SUCCESS;
41 }
42 
43 //**********************************************************************
44 
46 
48 
49  for(const xAOD::Jet* jet : jets) fracHandle(*jet) = energyFraction(*jet);
50  return StatusCode::SUCCESS;
51 }
52 
53 //**********************************************************************
54 
56  // Loop over jet constituents.
57  double jetECPSEnergy = 0.0;
58  double jetConstitEnergy = 0.0;
59  for ( const JetConstituent* pcon : jet.getConstituents() ) {
60  if ( pcon == nullptr ) {
61  ATH_MSG_WARNING("Constituent is missing.");
62  continue;
63  }
64  const IParticle* ppar = pcon->rawConstituent();
65  if(ppar == nullptr){
66  ATH_MSG_WARNING("Constituent has no associated raw constituent.");
67  continue;
68  }
69  double conEnergy = pcon->e();
70 
71  // If constituent is pflow, then look to see if it is cluster-based.
72  const CaloCluster* pclu = nullptr;
73  if ( ppar->type() == xAOD::Type::ParticleFlow){
74  const xAOD::PFO* ppfl = static_cast<const xAOD::PFO*>(ppar);
75  if ( !ppfl->isCharged() ) {
76  pclu = ppfl->cluster(0); // Assume PFO has exactly one cluster.
77  if ( pclu != nullptr ) ATH_MSG_VERBOSE(" Constituent is a PFO pointing to a cluster");
78  else ATH_MSG_WARNING(" Constituent is cluster-based PFO but the cluster is not found.");
79  } else {
80  ATH_MSG_VERBOSE(" Constituent is a PFO pointing to a track");
81  }
82  }
83  else if ( ppar->type() == xAOD::Type::FlowElement){
84  const xAOD::FlowElement* pfe = static_cast<const xAOD::FlowElement*>(ppar);
85  if(!(pfe->signalType() & xAOD::FlowElement::PFlow)){
86  ATH_MSG_WARNING(" Constituent is a FlowElement but not a PFO. This isn't supported; skipping.");
87  continue;
88  }
89  if ( !pfe->isCharged() ) {
90  pclu = dynamic_cast<const CaloCluster*>(pfe->otherObject(0)); // Assume PFO has exactly one cluster.
91  if ( pclu != nullptr ) ATH_MSG_VERBOSE(" Constituent is a PFO pointing to a cluster");
92  else ATH_MSG_WARNING(" Constituent is a non-charge PFO but no cluster is found.");
93  }
94  else ATH_MSG_VERBOSE(" Constituent is a charged PFO");
95  }
96  else {
97  // Not a PFO. Check if constituent is a cluster.
98  pclu = dynamic_cast<const CaloCluster*>(ppar);
99  if ( pclu != nullptr ) ATH_MSG_VERBOSE(" Constituent is a cluster");
100  }
101  if ( pclu == nullptr ) {
102  ATH_MSG_VERBOSE(" Skipping non-cluster constituent.");
103  continue;
104  }
105  ATH_MSG_VERBOSE(" Processing constituent cluster.");
106  // Extract the energy in the ECPS layer.
107  double ecpsEnergy = pclu->eSample(CaloSampling::PreSamplerE);
108  // Extract the energy assigned to the cluster.
109  // Calculate the cluster energy sum from its layer energies.
110  // This will not be the same as the cluster energy for LC clusters.
111  double layerEnergy = 0.0;
112  for ( size_t isam=CaloSampling::PreSamplerB; isam<CaloSampling::Unknown; ++isam ) {
113  layerEnergy += pclu->eSample((xAOD::CaloCluster::CaloSample) isam);
114  }
115  ATH_MSG_DEBUG("Constit ecps/all/cluster = " << ecpsEnergy << "/" << layerEnergy << "/" << conEnergy);
116  // If the ECPS energy fraction is above threshold, add this cluster's
117  // energy to the ECPS energy sum.
118  if ( ecpsEnergy > m_fraclimit*layerEnergy ) jetECPSEnergy += conEnergy;
119  jetConstitEnergy += conEnergy;
120  }
121  if ( jetConstitEnergy <= 0.0 ) {
122  return 0.0;
123  }
124 #ifdef JetECPSFractionTool_DEBUG
125  double jetEnergy = jet.jetP4("JetConstitScaleMomentum").e();
126  ATH_MSG_INFO("Jet ecps/all/jetE = " << jetECPSEnergy << "/" << jetConstitEnergy << "/" << jetEnergy);
127 #endif
128  double frac = jetECPSEnergy/jetConstitEnergy;
129  ATH_MSG_DEBUG("Jet ecps/all = " << jetECPSEnergy << "/" << jetConstitEnergy << " = " << frac);
130  return frac;
131 }
132 
133 //**********************************************************************
GetLCDefs::Unknown
@ Unknown
Definition: GetLCDefs.h:21
CaloCluster::eSample
double eSample(sampling_type sampling) const
Retrieve energy in a given sampling.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:975
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
JetECPSFractionTool::energyFraction
double energyFraction(const xAOD::Jet &jet) const
Definition: JetECPSFractionTool.cxx:55
asg
Definition: DataHandleTestTool.h:28
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JetECPSFractionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: JetECPSFractionTool.cxx:29
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
xAOD::FlowElement_v1::PFlow
@ PFlow
Definition: FlowElement_v1.h:45
xAOD::FlowElement_v1::isCharged
bool isCharged() const
Definition: FlowElement_v1.cxx:56
PFO.h
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FlowElement.h
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
CaloCluster.h
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
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:256
xAOD::FlowElement
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition: FlowElement.h:16
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
xAOD::FlowElement_v1::signalType
signal_t signalType() const
CaloCluster
Principal data class for CaloCell clusters.
Definition: Calorimeter/CaloEvent/CaloEvent/CaloCluster.h:79
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
WriteDecorHandle.h
Handle class for adding a decoration to an object.
xAOD::PFO_v1::isCharged
bool isCharged() const
is a charged PFO
Definition: PFO_v1.cxx:251
xAOD::JetFourMom_t
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition: JetTypes.h:17
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
xAOD::FlowElement_v1::otherObject
const xAOD::IParticle * otherObject(std::size_t i) const
Definition: FlowElement_v1.cxx:196
JetECPSFractionTool::m_fracKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fracKey
Definition: JetECPSFractionTool.h:54
xAOD::JetConstituent
4-vector of jet constituent at the scale used during jet finding.
Definition: JetConstituentVector.h:61
defineDB.jets
list jets
Definition: JetTagCalibration/share/defineDB.py:24
xAOD::PFO_v1::cluster
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition: PFO_v1.cxx:669
JetECPSFractionTool::m_jetContainerName
Gaudi::Property< std::string > m_jetContainerName
Definition: JetECPSFractionTool.h:51
JetECPSFractionTool::m_fraclimit
Gaudi::Property< double > m_fraclimit
Definition: JetECPSFractionTool.h:49
JetECPSFractionTool::decorate
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
Definition: JetECPSFractionTool.cxx:45
IParticle
Definition: Event/EventKernel/EventKernel/IParticle.h:43
JetECPSFractionTool.h
JetECPSFractionTool::JetECPSFractionTool
JetECPSFractionTool(const std::string &myname)
Definition: JetECPSFractionTool.cxx:23
xAOD::FlowElement_v1
A detector object made of other lower level object(s)
Definition: FlowElement_v1.h:25