ATLAS Offline Software
Loading...
Searching...
No Matches
ClustersInCone.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ClustersInCone.h"
7#include "GaudiKernel/MsgStream.h"
9#include "xAODEgamma/Egamma.h"
10#include "xAODMuon/Muon.h"
11
12// Select for generic IParticle
13void
15 const xAOD::IParticle* particle,
16 const float coneSize,
17 const xAOD::CaloClusterContainer* clusters,
18 std::vector<bool>& mask)
19{
20 float particleEta = particle->eta();
21 float particlePhi = particle->phi();
22 unsigned int i(0);
23 for (xAOD::CaloClusterContainer::const_iterator clIt = clusters->begin();
24 clIt != clusters->end();
25 ++clIt, ++i) {
26 float deltaEta = (*clIt)->eta() - particleEta;
27 float deltaPhi = P4Helpers::deltaPhi((*clIt)->phi(), particlePhi);
28 float deltaR = sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi);
29 if (deltaR < coneSize) {
30 mask[i] = true;
31 }
32 }
33 }
34
35// Overload for Egamma
36void
38 const xAOD::Egamma* particle,
39 const float coneSize,
40 const xAOD::CaloClusterContainer* clusters,
41 std::vector<bool>& mask)
42{
43 float particleEta = particle->caloCluster()->etaBE(2);
44 float particlePhi = particle->caloCluster()->phiBE(2);
45 unsigned int i(0);
46 for (xAOD::CaloClusterContainer::const_iterator clIt = clusters->begin();
47 clIt != clusters->end();
48 ++clIt, ++i) {
49 float deltaEta = (*clIt)->eta() - particleEta;
50 float deltaPhi = P4Helpers::deltaPhi((*clIt)->phi(), particlePhi);
51 float deltaR = sqrt(deltaEta * deltaEta + deltaPhi * deltaPhi);
52 if (deltaR < coneSize) {
53 mask[i] = true;
54 }
55 }
56 }
57
58// Helper for the muon overload
59bool
61 float& eta,
62 float& phi)
63{
64 const auto* cluster = mu->cluster();
65 if (cluster) {
66 float etaT = 0, phiT = 0;
67 int nSample = 0;
68 for (unsigned int i = 0; i < CaloSampling::Unknown; i++) {
69 auto s = static_cast<CaloSampling::CaloSample>(i);
70 if (!cluster->hasSampling(s))
71 continue;
72 etaT += cluster->etaSample(s);
73 phiT += cluster->phiSample(s);
74 nSample++;
75 }
76 if (nSample > 0) {
77 eta = etaT / nSample;
78 phi = phiT / nSample;
79 } else {
80 return false;
81 }
82 } else {
83 return false;
84 }
85 return true;
86}
87
88// Overload for Muons
89void
91 const xAOD::Muon* particle,
92 const float coneSize,
93 const xAOD::CaloClusterContainer* clusters,
94 std::vector<bool>& mask,
95 MsgStream& msg)
96{
97 float particleEta = particle->eta();
98 float particlePhi = particle->phi();
99 if (!GetExtrapEtaPhi(particle, particleEta, particlePhi)) {
100 msg << MSG::WARNING
101 << "Failed to get the eta-phi of the muon calo extention " << endmsg;
102 }
103 unsigned int i(0);
104 float coneSize2 = coneSize * coneSize;
105 for (xAOD::CaloClusterContainer::const_iterator clIt = clusters->begin();
106 clIt != clusters->end();
107 ++clIt, ++i) {
108 float deltaEta = (*clIt)->eta() - particleEta;
109 float deltaPhi = P4Helpers::deltaPhi((*clIt)->phi(), particlePhi);
110 if (deltaEta * deltaEta + deltaPhi * deltaPhi < coneSize2) {
111 mask[i] = true;
112 }
113 }
114 }
Scalar eta() const
pseudorapidity method
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Scalar phi() const
phi method
#define endmsg
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
Class providing the definition of the 4-vector interface.
bool GetExtrapEtaPhi(const xAOD::Muon *mu, float &eta, float &phi)
void select(const xAOD::IParticle *particle, const float coneSize, const xAOD::CaloClusterContainer *clusters, std::vector< bool > &mask)
double deltaR(double eta1, double eta2, double phi1, double phi2)
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Definition P4Helpers.h:34
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Muon_v1 Muon
Reference the current persistent version:
CaloClusterContainer_v1 CaloClusterContainer
Define the latest version of the calorimeter cluster container.
MsgStream & msg
Definition testRead.cxx:32