ATLAS Offline Software
Loading...
Searching...
No Matches
JetConstituentModifierBase.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// Source file for the JetConstituentModifierBase.h
6// // Michael Nelson, CERN & University of Oxford
7
10#include "xAODPFlow/PFO.h"
13
14#include <exception>
15
17#ifndef XAOD_STANDALONE
18 declareInterface<IJetConstituentModifier>(this);
19#endif
20 declareProperty("InputType", m_inputType);
21 declareProperty("ApplyToChargedPFO", m_applyToChargedPFO);
22 declareProperty("ApplyToNeutralPFO", m_applyToNeutralPFO);
23}
24
25StatusCode JetConstituentModifierBase::process(xAOD::IParticleContainer* cont, const EventContext& ctx) const
26{
27 // Test that we are operating on the type of object that
28 // we will be writing out.
29 // By implication, any supporting containers should not
30 // be the ones passed to this method...
31 if(!cont->empty() && cont->front()->type() != m_inputType) {
32 ATH_MSG_ERROR("Object type mismatch! This tool expects " << m_inputType
33 << ", but received " << cont->front()->type());
34 return StatusCode::FAILURE;
35 }
36
37 ATH_CHECK(process_impl(cont, ctx));
38
39 return StatusCode::SUCCESS;
40}
41
42
44{
45 switch(m_inputType) {
46 // The main (only?) application is origin-correcting LC topoclusters
47 // By convention we leave the raw p4 unmodified
49 {
50 xAOD::CaloCluster* clus = static_cast<xAOD::CaloCluster*>(obj);
51 clus->setCalEta(eta);
52 clus->setCalPhi(phi);
53 }
54 break;
55 default:
56 // Should not get here, because type-checking should happen in process()
57 ATH_MSG_ERROR("No specialisation for object type " << m_inputType);
58 return StatusCode::FAILURE;
59 }
60 return StatusCode::SUCCESS;
61}
62
63StatusCode JetConstituentModifierBase::setEnergyPt(xAOD::IParticle* obj, float e, float pt) const
64{
65 switch(m_inputType) {
67 {
68 xAOD::CaloCluster* clus = static_cast<xAOD::CaloCluster*>(obj);
69 // Clusters get pt via the energy
70 // This currently leaves the mass unaltered.
71 clus->setCalE(e);
72 }
73 break;
75 {
76 xAOD::PFO* pfo = static_cast<xAOD::PFO*>(obj);
77 if( (m_applyToChargedPFO && pfo->isCharged()) ||
78 (m_applyToNeutralPFO && !pfo->isCharged()) ) {
79 // KTJ: Temporary fix
80 // Defeats the purpose, but we need to use this to reset the 4-vec cache
81 pfo->setP4(pt, pfo->eta(), pfo->phi());
82 }
83 }
84 break;
86 {
87 xAOD::FlowElement* pfo = static_cast<xAOD::FlowElement*>(obj);
88 if( (m_applyToChargedPFO && pfo->isCharged()) ||
89 (m_applyToNeutralPFO && !pfo->isCharged()) ) {
90 pfo->setP4(pt, pfo->eta(), pfo->phi(), 0.);
91 }
92 }
93 break;
95 {
96 xAOD::TrackCaloCluster* tcc = static_cast<xAOD::TrackCaloCluster*>(obj);
97 if( tcc->taste() != 0) {
98 tcc->setParameters(pt, tcc->eta(), tcc->phi(), tcc->m(), xAOD::TrackCaloCluster::Taste(tcc->taste()), tcc->trackParticleLink(), tcc->caloClusterLinks());
99 }
100 }
101 break;
102 default:
103 // Should not get here, because type-checking should happen in process()
104 ATH_MSG_ERROR("No specialisation for object type " << m_inputType);
105 return StatusCode::FAILURE;
106 }
107 return StatusCode::SUCCESS;
108}
109
111 switch(m_inputType) {
113 {
114 xAOD::CaloCluster* clus = static_cast<xAOD::CaloCluster*>(obj);
115 // This currently leaves the mass unaltered
116 clus->setCalE(p4.e());
117 clus->setCalEta(p4.eta());
118 clus->setCalPhi(p4.phi());
119 }
120 break;
122 {
123 xAOD::PFO* pfo = static_cast<xAOD::PFO*>(obj);
124 // The PFO setter defaults to m=0
125 if( (m_applyToChargedPFO && pfo->isCharged()) ||
126 (m_applyToNeutralPFO && !pfo->isCharged()) ) {
127 pfo->setP4(p4.pt(),p4.eta(),p4.phi(),p4.mass());
128 }
129 }
130 break;
132 {
133 xAOD::FlowElement* pfo = static_cast<xAOD::FlowElement*>(obj);
134 if( (m_applyToChargedPFO && pfo->isCharged()) ||
135 (m_applyToNeutralPFO && !pfo->isCharged()) ) {
136 pfo->setP4(p4.pt(),p4.eta(),p4.phi(),p4.mass());
137 }
138 }
139 break;
141 {
142 xAOD::TrackCaloCluster* tcc = static_cast<xAOD::TrackCaloCluster*>(obj);
143 if( tcc->taste() != 0) {
144 tcc->setParameters(p4.pt(), p4.eta(), p4.phi(), p4.mass(), xAOD::TrackCaloCluster::Taste(tcc->taste()), tcc->trackParticleLink(), tcc->caloClusterLinks());
145 }
146 break;
147 }
148
149 default:
150 // Should not get here, because type-checking should happen in process()
151 ATH_MSG_ERROR("No specialisation for object type " << m_inputType);
152 return StatusCode::FAILURE;
153 }
154 return StatusCode::SUCCESS;
155}
156
157
158float JetConstituentModifierBase::getCorrectionFactor(xAOD::IParticle* obj, const float& corrected_energy, const float& corrected_pt) const {
159 float factor = 0.;
160 switch(m_inputType) {
162 {
163 xAOD::CaloCluster* clus = static_cast<xAOD::CaloCluster*>(obj);
164 factor = clus->calE() > 0. ? corrected_energy / clus->calE() : 0.;
165 }
166 break;
168 {
169 xAOD::PFO* pfo = static_cast<xAOD::PFO*>(obj);
170 factor = pfo->pt() > 0. ? corrected_pt / pfo->pt() : 0.;
171 }
172 break;
174 {
175 xAOD::FlowElement* pfo = static_cast<xAOD::FlowElement*>(obj);
176 factor = pfo->pt() > 0. ? corrected_pt / pfo->pt() : 0.;
177 }
178 break;
180 {
181 xAOD::TrackCaloCluster* tcc = static_cast<xAOD::TrackCaloCluster*>(obj);
182 factor = tcc->pt() > 0. ? corrected_pt / tcc->pt() : 0.;
183 }
184 break;
185 default:
186 ATH_MSG_ERROR("No specialisation for object type " << m_inputType);
187 }
188 return factor;
189}
190
192 float weight = 0.;
193 switch(m_inputType) {
195 {
196 xAOD::CaloCluster* clus = static_cast<xAOD::CaloCluster*>(obj);
197 weight = clus->calE() > 0. ? corrected_p4.e() / clus->calE() : 0.;
198 }
199 break;
201 {
202 xAOD::PFO* pfo = static_cast<xAOD::PFO*>(obj);
203 // The PFO setter defaults to m=0
204 if( (m_applyToChargedPFO && pfo->isCharged()) || (m_applyToNeutralPFO && !pfo->isCharged()) ) {
205 weight = pfo->pt() > 0. ? corrected_p4.pt() / pfo->pt() : 0.;
206 }
207 }
208 break;
210 {
211 xAOD::FlowElement* pfo = static_cast<xAOD::FlowElement*>(obj);
212 if( (m_applyToChargedPFO && pfo->isCharged()) || (m_applyToNeutralPFO && !pfo->isCharged()) ) {
213 weight = pfo->pt() > 0. ? corrected_p4.pt() / pfo->pt() : 0.;
214 }
215 }
216 break;
218 {
219 xAOD::TrackCaloCluster* tcc = static_cast<xAOD::TrackCaloCluster*>(obj);
220 if( tcc->taste() != 0) {
221 weight = tcc->pt() > 0. ? corrected_p4.pt() / tcc->pt() : 0.;
222 }
223 break;
224 }
225
226 default:
227 throw std::runtime_error("No specialisation for object type " + std::to_string(m_inputType));
228 }
229 return weight;
230}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const T * front() const
Access the first element in the collection as an rvalue.
bool empty() const noexcept
Returns true if the collection is empty.
float getCorrectionFactor(xAOD::IParticle *obj, const float &corrected_energy, const float &corrected_pt) const
StatusCode setEnergyPt(xAOD::IParticle *obj, float e, float pt) const
JetConstituentModifierBase(const std::string &name)
StatusCode setEtaPhi(xAOD::IParticle *obj, float eta, float phi) const
virtual StatusCode process_impl(xAOD::IParticleContainer *, const EventContext &) const
StatusCode setP4(xAOD::IParticle *obj, const xAOD::JetFourMom_t &p4) const
StatusCode process(xAOD::IParticleContainer *cont, const EventContext &ctx) const override final
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
void setCalPhi(flt_t)
Set for signal state CALIBRATED.
void setCalEta(flt_t)
Set for signal state CALIBRATED.
flt_t calE() const
Geet Energy in signal state CALIBRATED.
void setCalE(flt_t)
Set Energy for signal state CALIBRATED.
virtual double pt() const override
void setP4(float pt, float eta, float phi, float m)
virtual double phi() const override
The azimuthal angle ( ) of the particle.
virtual double eta() const override
The pseudorapidity ( ) of the particle.
Class providing the definition of the 4-vector interface.
bool isCharged() const
is a charged PFO
Definition PFO_v1.cxx:251
void setP4(const FourMom_t &vec)
set the 4-vec
Definition PFO_v1.cxx:107
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition PFO_v1.cxx:60
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition PFO_v1.cxx:67
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition PFO_v1.cxx:52
virtual double m() const
The invariant mass of the particle..
virtual double phi() const
The azimuthal angle ( ) of the particle (has range to .).
virtual int taste() const
The taste of the particle.
Taste
Type of TrackCaloCluster - Charged - Neutral - Combined.
const ElementLink< xAOD::TrackParticleContainer > & trackParticleLink() const
virtual double pt() const
The transverse momentum ( ) of the particle.
virtual double eta() const
The pseudorapidity ( ) of the particle.
const std::vector< ElementLink< xAOD::CaloClusterContainer > > & caloClusterLinks() const
Returns a vector to the links (which can be invalid) to the xAOD::CaloClusters associated with this T...
void setParameters(float pt, float eta, float phi, float m, TrackCaloCluster_v1::Taste taste, const ElementLink< xAOD::TrackParticleContainer > &particle, const std::vector< ElementLink< xAOD::CaloClusterContainer > > &clusters)
@ ParticleFlow
The object is a particle-flow object.
Definition ObjectType.h:41
@ FlowElement
The object is a track-calo-cluster.
Definition ObjectType.h:52
@ CaloCluster
The object is a calorimeter cluster.
Definition ObjectType.h:39
@ TrackCaloCluster
The object is a track-calo-cluster.
Definition ObjectType.h:51
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
TrackCaloCluster_v1 TrackCaloCluster
Reference the current persistent version:
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17