ATLAS Offline Software
Loading...
Searching...
No Matches
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"
12#include "CaloGeoHelpers/CaloSampling.h"
13
14using xAOD::IParticle;
18
19#undef JetECPSFractionTool_DEBUG
20
21//**********************************************************************
22
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
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);
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//**********************************************************************
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
Principal data class for CaloCell clusters.
double eSample(sampling_type sampling) const
Retrieve energy in a given sampling.
virtual double e() const =0
energy
Gaudi::Property< std::string > m_jetContainerName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_fracKey
virtual StatusCode decorate(const xAOD::JetContainer &jets) const override
Decorate a jet collection without otherwise modifying it.
JetECPSFractionTool(const std::string &myname)
Gaudi::Property< double > m_fraclimit
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
double energyFraction(const xAOD::Jet &jet) const
Handle class for adding a decoration to an object.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
CaloSampling::CaloSample CaloSample
signal_t signalType() const
const xAOD::IParticle * otherObject(std::size_t i) const
Class providing the definition of the 4-vector interface.
4-vector of jet constituent at the scale used during jet finding.
bool isCharged() const
is a charged PFO
Definition PFO_v1.cxx:251
const CaloCluster * cluster(unsigned int index) const
Retrieve a const pointer to a CaloCluster.
Definition PFO_v1.cxx:669
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
Jet_v1 Jet
Definition of the current "jet version".
PFO_v1 PFO
Definition of the current "pfo version".
Definition PFO.h:17
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
FlowElement_v1 FlowElement
Definition of the current "pfo version".
Definition FlowElement.h:16
JetContainer_v1 JetContainer
Definition of the current "jet container version".
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17