ATLAS Offline Software
MvaTESVariableDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // local include(s)
8 
11 
12 #define GeV 1000
13 
14 
15 
17  : TauRecToolBase(name) {
18  declareProperty("VertexCorrection", m_doVertexCorrection = true);
19 }
20 
21 
22 
24 
25  ATH_CHECK(m_aveIntPerXKey.initialize());
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 
33 
35 
36  int mu = 0;
38  if (!eventInfoDecorHandle.isPresent()) {
39  ATH_MSG_WARNING ( "EventInfo decoration not available! Will set mu=0." );
40  }
41  else {
42  // convert from float to int to ignore peculiar values used in MC
43  mu = (int)eventInfoDecorHandle(0);
44  }
45  static const SG::AuxElement::Accessor<float> acc_mu("mu");
46  acc_mu(xTau) = mu;
47 
48  if (!m_vertexContainerKey.empty()) {
49  int nVtxPU = 0;
51  if (!vertexInHandle.isValid()) {
52  ATH_MSG_WARNING ("Could not retrieve HiveDataObj with key " << vertexInHandle.key() << ", will set nVtxPU=0.");
53  }
54  else {
55  const xAOD::VertexContainer* vertexContainer = vertexInHandle.cptr();
56  for (const auto *xVertex : *vertexContainer){
57  if (xVertex->vertexType() == xAOD::VxType::PileUp)
58  ++nVtxPU;
59  }
60  }
61  static const SG::AuxElement::Accessor<int> acc_nVtxPU("nVtxPU");
62  acc_nVtxPU(xTau) = nVtxPU;
63  }
64 
65  if (!m_eventShapeKey.empty()) {
66  double rho = 0.;
68  if (!eventShape.isValid()) {
69  ATH_MSG_WARNING ("Could not retrieve EventShape with key " << m_eventShapeKey );
70  }
71  else if (!eventShape->getDensity(xAOD::EventShape::Density, rho)) {
72  ATH_MSG_WARNING ("Could not retrieve rho.");
73  }
74  static const SG::AuxElement::Accessor<float> acc_rho("rho");
75  acc_rho(xTau) = (float)rho;
76  }
77 
78  double center_lambda=0. , first_eng_dens=0. , em_probability=0. , second_lambda=0. ;
79  double mean_center_lambda=0. , mean_first_eng_dens=0. , mean_em_probability=0. , mean_second_lambda=0. ;
80  double mean_presampler_frac=0., lead_cluster_frac=0. , second_cluster_frac=0. , third_cluster_frac=0. ;
81  double clE=0., Etot=0.;
82 
83  // approximate Upsilon based on clusters, not PFOs (for online TES)
84  TLorentzVector clusters_EM_P4;
85  clusters_EM_P4.SetPtEtaPhiM(0,0,0,0);
86  TLorentzVector clusters_had_P4;
87  clusters_had_P4.SetPtEtaPhiM(0,0,0,0);
88  TLorentzVector tauIntermediateAxisEM;
89  tauIntermediateAxisEM.SetPtEtaPhiM(0,0,0,0);
90 
91  TLorentzVector tauAxis = tauRecTools::getTauAxis(xTau, m_doVertexCorrection);
92 
93  // in the trigger, we must ignore the tau vertex, otherwise ptFinalCalib computed at calo-only step and precision step will differ
94  const xAOD::Vertex* vertex = nullptr;
95  if (m_doVertexCorrection) vertex = xTau.vertex();
96 
97  // loop over tau clusters
98  std::vector<xAOD::CaloVertexedTopoCluster> vertexedClusters = xTau.vertexedClusters();
99 
100  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusters) {
101  const xAOD::CaloCluster& cluster = vertexedCluster.clust();
102 
103  TLorentzVector clusterP4 = m_doVertexCorrection? vertexedCluster.p4() : cluster.p4();
104  if (clusterP4.DeltaR(tauAxis) > 0.2) continue;
105 
106  // FIXME: should we use calE for EMTopo clusters ?
107  // what's the energy scale when calculating the cluster momentum
108  clE = cluster.calE();
109  Etot += clE;
110 
111  if (clE > lead_cluster_frac) {
112  third_cluster_frac = second_cluster_frac;
113  second_cluster_frac = lead_cluster_frac;
114  lead_cluster_frac = clE;
115  }
116  else if (clE > second_cluster_frac) {
117  third_cluster_frac = second_cluster_frac;
118  second_cluster_frac = clE;
119  }
120  else if (clE > third_cluster_frac) {
121  third_cluster_frac = clE;
122  }
123 
125  mean_center_lambda += clE*center_lambda;
126  else ATH_MSG_WARNING("Failed to retrieve moment: CENTER_LAMBDA");
127 
129  mean_first_eng_dens += clE*first_eng_dens;
130  else ATH_MSG_WARNING("Failed to retrieve moment: FIRST_ENG_DENS");
131 
133  mean_em_probability += clE*em_probability;
134 
135  // FIXME: should we use calE for EMTopo clusters ?
136  // what's the energy scale when calculating the cluster momentum
137  if (em_probability>0.5) clusters_EM_P4 += cluster.p4(xAOD::CaloCluster::State::CALIBRATED);
138  else clusters_had_P4 += cluster.p4(xAOD::CaloCluster::State::CALIBRATED);
139  }
140  else ATH_MSG_WARNING("Failed to retrieve moment: EM_PROBABILITY");
141 
143  mean_second_lambda += clE*second_lambda;
144  else ATH_MSG_WARNING("Failed to retrieve moment: SECOND_LAMBDA");
145 
146  mean_presampler_frac += (cluster.eSample(CaloSampling::PreSamplerB) + cluster.eSample(CaloSampling::PreSamplerE));
147 
148  // EM-scale equivalent of IntermediateAxis p4
149  if (vertex) {
150  xAOD::CaloVertexedTopoCluster vertexedClusterEM(cluster, xAOD::CaloCluster::State::UNCALIBRATED, vertex->position());
151  tauIntermediateAxisEM += vertexedClusterEM.p4();
152  }
153  else {
154  tauIntermediateAxisEM += cluster.p4(xAOD::CaloCluster::State::UNCALIBRATED);
155  }
156  }
157 
158  // calculate mean values
159  if (Etot>0.) {
160  mean_center_lambda /= Etot;
161  mean_first_eng_dens /= Etot;
162  mean_em_probability /= Etot;
163  mean_second_lambda /= Etot;
164  mean_presampler_frac /= Etot;
165  lead_cluster_frac /= Etot;
166  second_cluster_frac /= Etot;
167  third_cluster_frac /= Etot;
168 
169  if (mean_first_eng_dens>0.) mean_first_eng_dens = TMath::Log10(mean_first_eng_dens/Etot);
170  }
171 
172  // cluster-based upsilon, ranges from -1 to 1
173  double upsilon_cluster = -2.;
174  if (clusters_had_P4.E()+clusters_EM_P4.E()!=0.)
175  upsilon_cluster = (clusters_had_P4.E()-clusters_EM_P4.E())/(clusters_had_P4.E()+clusters_EM_P4.E());
176 
177  xTau.setDetail(xAOD::TauJetParameters::ClustersMeanCenterLambda, (float) mean_center_lambda);
178  xTau.setDetail(xAOD::TauJetParameters::ClustersMeanFirstEngDens, (float) mean_first_eng_dens);
179  xTau.setDetail(xAOD::TauJetParameters::ClustersMeanEMProbability, (float) mean_em_probability);
180  xTau.setDetail(xAOD::TauJetParameters::ClustersMeanSecondLambda, (float) mean_second_lambda);
181  xTau.setDetail(xAOD::TauJetParameters::ClustersMeanPresamplerFrac, (float) mean_presampler_frac);
182 
183  static const SG::AuxElement::Accessor<float> acc_ClusterTotalEnergy("ClusterTotalEnergy");
184  acc_ClusterTotalEnergy(xTau) = (float) Etot;
185 
186  static const SG::AuxElement::Accessor<float> acc_ptIntermediateAxisEM("ptIntermediateAxisEM");
187  acc_ptIntermediateAxisEM(xTau) = (float) tauIntermediateAxisEM.Pt();
188 
189  // online-specific, not defined in TauDefs enum
190  static const SG::AuxElement::Accessor<float> acc_LeadClusterFrac("LeadClusterFrac");
191  static const SG::AuxElement::Accessor<float> acc_UpsilonCluster("UpsilonCluster");
192  acc_LeadClusterFrac(xTau) = (float) lead_cluster_frac;
193  acc_UpsilonCluster(xTau) = (float) upsilon_cluster;
194 
195  if (inTrigger()) {
196  // for now only used by trigger, but could be used by offline 0p in the 2022 reprocessing
197  static const SG::AuxElement::Accessor<float> acc_SecondClusterFrac("SecondClusterFrac");
198  static const SG::AuxElement::Accessor<float> acc_ThirdClusterFrac("ThirdClusterFrac");
199  acc_SecondClusterFrac(xTau) = (float) second_cluster_frac;
200  acc_ThirdClusterFrac(xTau) = (float) third_cluster_frac;
201 
202  return StatusCode::SUCCESS;
203  }
204  // no seed jets in AOD
205  if (!inAOD()) {
206  // retrieve Ghost Muon Segment Count (for punch-through studies)
207  const xAOD::Jet* jetSeed = xTau.jet();
208  if (jetSeed == nullptr) {
209  ATH_MSG_ERROR("Tau jet link is invalid.");
210  return StatusCode::FAILURE;
211  }
212 
213  int nMuSeg=0;
214  if (!jetSeed->getAttribute<int>("GhostMuonSegmentCount", nMuSeg)) nMuSeg=0;
216  }
217 
218 
219  // summing corrected Pi0 PFO energies
220  TLorentzVector Pi0_totalP4;
221  Pi0_totalP4.SetPtEtaPhiM(0,0,0,0);
222 
223  for (size_t i=0; i<xTau.nPi0PFOs(); i++){
224  Pi0_totalP4 += xTau.pi0PFO(i)->p4();
225  }
226 
227  double Pi0_totalE = Pi0_totalP4.E();
228 
229  // summing tau track momenta
230  TLorentzVector charged_totalP4;
231  charged_totalP4.SetPtEtaPhiM(0,0,0,0);
232 
233  for (const xAOD::TauTrack* track : xTau.tracks()) {
234  charged_totalP4 += track->p4();
235  }
236 
237  double charged_totalE = charged_totalP4.E();
238 
239  // calculate relative difference and decorate onto tau
240  double relDiff=0.;
241  if (Pi0_totalE+charged_totalE != 0.){
242  relDiff = (charged_totalE - Pi0_totalE) / (charged_totalE + Pi0_totalE) ;
243  }
244  xTau.setDetail(xAOD::TauJetParameters::PFOEngRelDiff, (float) relDiff);
245 
246  return StatusCode::SUCCESS;
247 }
xAOD::EventShape_v1::getDensity
bool getDensity(EventDensityID id, double &v) const
Get a density variable from the object.
Definition: EventShape_v1.cxx:135
MvaTESVariableDecorator::initialize
virtual StatusCode initialize() override
Tool initializer.
Definition: MvaTESVariableDecorator.cxx:23
TauGNNUtils::Variables::Cluster::CENTER_LAMBDA
bool CENTER_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:840
xAOD::TauJetParameters::PFOEngRelDiff
@ PFOEngRelDiff
Definition: TauDefs.h:318
xAOD::CaloVertexedClusterBase::p4
virtual FourMom_t p4() const final
The full 4-momentum of the particle.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedClusterBase.h:88
xAOD::TauJet_v3::jet
const Jet * jet() const
xAOD::TauJetParameters::GhostMuonSegmentCount
@ GhostMuonSegmentCount
Definition: TauDefs.h:317
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
TauGNNUtils::Variables::Cluster::EM_PROBABILITY
bool EM_PROBABILITY(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:909
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
xAOD::TauJetParameters::ClustersMeanSecondLambda
@ ClustersMeanSecondLambda
Definition: TauDefs.h:315
TauRecToolBase::inAOD
bool inAOD() const
Definition: TauRecToolBase.h:88
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
tauRecTools::getTauAxis
TLorentzVector getTauAxis(const xAOD::TauJet &tau, bool doVertexCorrection=true)
Return the four momentum of the tau axis The tau axis is widely used to select clusters and cells in ...
Definition: Reconstruction/tauRecTools/Root/HelperFunctions.cxx:33
xAOD::CaloCluster_v1::calE
flt_t calE() const
Geet Energy in signal state CALIBRATED.
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
SG::ReadDecorHandle::isPresent
bool isPresent() const
Is the referenced container present in SG?
MvaTESVariableDecorator::execute
virtual StatusCode execute(xAOD::TauJet &xTau) const override
Execute - called for each tau candidate.
Definition: MvaTESVariableDecorator.cxx:34
xAOD::TauJetParameters::ClustersMeanPresamplerFrac
@ ClustersMeanPresamplerFrac
Definition: TauDefs.h:316
TauRecToolBase::inTrigger
bool inTrigger() const
Definition: TauRecToolBase.h:87
xAOD::Jet_v1::getAttribute
bool getAttribute(AttributeID type, T &value) const
Retrieve attribute moment by enum.
xAOD::TauJet_v3::nPi0PFOs
size_t nPi0PFOs() const
Get the number of pi0 PFO particles associated with this tau.
Definition: TauJet_v3.cxx:880
MvaTESVariableDecorator::m_doVertexCorrection
bool m_doVertexCorrection
Definition: MvaTESVariableDecorator.h:31
MvaTESVariableDecorator::m_eventShapeKey
SG::ReadHandleKey< xAOD::EventShape > m_eventShapeKey
Definition: MvaTESVariableDecorator.h:43
xAOD::TauJet_v3::pi0PFO
const PFO * pi0PFO(size_t i) const
Get the pointer to a given pi0 PFO associated with this tau.
xAOD::EventShape_v1::Density
@ Density
Definition: EventShape_v1.h:47
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
MvaTESVariableDecorator::m_aveIntPerXKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_aveIntPerXKey
Definition: MvaTESVariableDecorator.h:33
xAOD::PFO_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: PFO_v1.cxx:95
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
TauGNNUtils::Variables::Cluster::SECOND_LAMBDA
bool SECOND_LAMBDA(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:835
MvaTESVariableDecorator::MvaTESVariableDecorator
MvaTESVariableDecorator(const std::string &name="MvaTESVariableDecorator")
Definition: MvaTESVariableDecorator.cxx:16
MvaTESVariableDecorator.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::CaloCluster_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: CaloCluster_v1.cxx:465
xAOD::VxType::PileUp
@ PileUp
Pile-up vertex.
Definition: TrackingPrimitives.h:573
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ReadHandle.h
Handle class for reading from StoreGate.
xAOD::TauJetParameters::ClustersMeanEMProbability
@ ClustersMeanEMProbability
Definition: TauDefs.h:313
xAOD::TauJetParameters::ClustersMeanCenterLambda
@ ClustersMeanCenterLambda
Definition: TauDefs.h:312
xAOD::TauJet_v3::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
Definition: TauJet_v3.cxx:626
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
MvaTESVariableDecorator::m_vertexContainerKey
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainerKey
Definition: MvaTESVariableDecorator.h:38
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:521
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
xAOD::TauJet_v3::vertex
const Vertex * vertex() const
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
HelperFunctions.h
ReadDecorHandle.h
Handle class for reading a decoration on an object.
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:337
TauGNNUtils::Variables::Cluster::FIRST_ENG_DENS
bool FIRST_ENG_DENS(const xAOD::TauJet &, const xAOD::CaloVertexedTopoCluster &cluster, double &out)
Definition: TauGNNUtils.cxx:902
xAOD::TauJetParameters::ClustersMeanFirstEngDens
@ ClustersMeanFirstEngDens
Definition: TauDefs.h:314
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
xAOD::TauJet_v3::tracks
std::vector< const TauTrack * > tracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Get the v<const pointer> to a given tauTrack collection associated with this tau.
Definition: TauJet_v3.cxx:493
readCCLHist.float
float
Definition: readCCLHist.py:83
fitman.rho
rho
Definition: fitman.py:532
xAOD::TauHelpers::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters(const xAOD::TauJet &tau, double dRMax)
Definition: TauxAODHelpers.cxx:108