ATLAS Offline Software
Loading...
Searching...
No Matches
TauElectronVetoVariables.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef XAOD_ANALYSIS
6
8
12
13#include "GaudiKernel/SystemOfUnits.h"
14
15#include <algorithm>
16#include <cmath>
17#include <unordered_map>
18#include <array>
19
20#include "TVector2.h"
21
22using Gaudi::Units::GeV;
23
26
28 ATH_CHECK( m_caloExtensionTool.retrieve() );
29 if (!m_ParticleCacheKey.key().empty()) {
30 ATH_CHECK(m_ParticleCacheKey.initialize());
31 } else {
32 m_useOldCalo = true;
33 }
34 return StatusCode::SUCCESS;
35}
36
37
38
40 if (pTau.nTracks() < 1) {
41 return StatusCode::SUCCESS;
42 }
43 ATH_MSG_DEBUG("in execute()");
44 float detPhiTrk = 0.;
45 float detEtaTrk = 0.;
46 float sumETCellsLAr = 0.;
47 float eta0cut = 0.075;
48 float eta1cut = 0.0475;
49 float eta2cut = 0.075;
50 float eta3cut = 1.5;
51 float phi0cut = 0.3;
52 float phi1cut = 0.3;
53 float phi2cut = 0.075;
54 float phi3cut = 0.075;
55 const CaloCell *pCell;
56 int trackIndex = -1;
57
58 //---------------------------------------------------------------------
59 // Calculate eta, phi impact point of leading track at calorimeter layers EM 0,1,2,3
60 //---------------------------------------------------------------------
62 constexpr size_t numberOfEM_Layers{4};
63 constexpr double invalidCoordinate{-11111.};
64 constexpr double invalidCoordinateThreshold{-11110.};
65 std::array<double, numberOfEM_Layers> extrapolatedEta{};
66 std::array<double, numberOfEM_Layers> extrapolatedPhi{};
67 extrapolatedEta.fill(invalidCoordinate);
68 extrapolatedPhi.fill(invalidCoordinate);
69
70 /*get the CaloExtension object*/
71 const Trk::CaloExtension * caloExtension = nullptr;
72 std::unique_ptr<Trk::CaloExtension> uniqueExtension ;
73 const xAOD::TrackParticle *orgTrack = pTau.track(0)->track();
74 trackIndex = orgTrack->index();
75 if (m_useOldCalo) {
76 /* If CaloExtensionBuilder is unavailable, use the calo extension tool */
77 ATH_MSG_VERBOSE("Using the CaloExtensionTool");
78 uniqueExtension = m_caloExtensionTool->caloExtension(
79 Gaudi::Hive::currentContext(), *orgTrack);
80 caloExtension = uniqueExtension.get();
81 } else {
82 /*get the CaloExtension object*/
83 ATH_MSG_VERBOSE("Using the CaloExtensionBuilder Cache");
85 caloExtension = (*particleCache)[trackIndex];
86 ATH_MSG_VERBOSE("Getting element " << trackIndex << " from the particleCache");
87 if( not caloExtension ){
88 ATH_MSG_VERBOSE("Cache does not contain a calo extension -> Calculating with the a CaloExtensionTool" );
89 uniqueExtension = m_caloExtensionTool->caloExtension(
90 Gaudi::Hive::currentContext(), *orgTrack);
91 caloExtension = uniqueExtension.get();
92 }
93 }
94 if( not caloExtension){
95 ATH_MSG_DEBUG("extrapolation of leading track to calo surfaces failed : caloExtension is nullptr" );
96 return StatusCode::RECOVERABLE;
97 }
98 const std::vector<Trk::CurvilinearParameters>& clParametersVector = caloExtension->caloLayerIntersections();
99 if(clParametersVector.empty() ){
100 ATH_MSG_DEBUG("extrapolation of leading track to calo surfaces failed : caloLayerIntersection is empty" );
101 return StatusCode::RECOVERABLE;
102 }
103 // loop over calo layers
104 for( const Trk::CurvilinearParameters& cur : clParametersVector ){
105 // only use entry layer
106 if( !parsIdHelper.isEntryToVolume(cur.cIdentifier()) ) continue;
107 CaloSampling::CaloSample sample = parsIdHelper.caloSample(cur.cIdentifier());
108 int index = -1;
109 if( sample == CaloSampling::PreSamplerE || sample == CaloSampling::PreSamplerB ) index = 0;
110 else if( sample == CaloSampling::EME1 || sample == CaloSampling::EMB1 ) index = 1;
111 else if( sample == CaloSampling::EME2 || sample == CaloSampling::EMB2 ) index = 2;
112 else if( sample == CaloSampling::EME3 || sample == CaloSampling::EMB3 ) index = 3;
113 if( index < 0 ) continue;
114 extrapolatedEta[index] = cur.position().eta();
115 extrapolatedPhi[index] = cur.position().phi();
116 }
117 for (size_t i = 0; i < numberOfEM_Layers; ++i) {
118 if ( extrapolatedEta[i] < invalidCoordinateThreshold || extrapolatedPhi[i] < invalidCoordinateThreshold ){
119 ATH_MSG_DEBUG("extrapolation of leading track to calo surfaces failed for sampling : " << i );
120 return StatusCode::SUCCESS;
121 }
122 }
123
124 // Loop through jets, get links to clusters
125 std::bitset<200000> cellSeen{};
126 const std::unordered_map<int, int> samplingLookup{
127 {4,0}, {5,1}, {6,2}, {7,3}, {8,12},
128 {15, 12}, {16,13}, {17,14}, {18,12}, {19, 13}, {20,14}
129 };
130 const auto notFound{samplingLookup.end()};
131
132 std::vector<xAOD::CaloVertexedTopoCluster> vertexedClusterList = pTau.vertexedClusters();
133 for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusterList){
134
135 const xAOD::CaloCluster& cluster = vertexedCluster.clust();
136 auto cell_links = cluster.getCellLinks();
137 if (cell_links == nullptr) {
138 ATH_MSG_DEBUG("NO Cell links found for cluster with pT " << cluster.pt());
139 continue;
140 }
142 CaloClusterCellLink::const_iterator pCellIterE = cluster.getCellLinks()->end();
143 for (; pCellIter != pCellIterE; ++pCellIter) {
144 double cellEta{}, cellPhi{}, cellET{};
145 pCell = *pCellIter;
146 if (cellSeen.test(pCell->caloDDE()->calo_hash())) continue;
147 else cellSeen.set(pCell->caloDDE()->calo_hash());
148 if (m_doVertexCorrection && pTau.vertex()!=nullptr) {
149 CaloVertexedCell vxCell (*pCell, pTau.vertex()->position());
150 cellPhi = vxCell.phi();
151 cellEta = vxCell.eta();
152 cellET = vxCell.et();
153 } else {
154 cellPhi = pCell->phi();
155 cellEta = pCell->eta();
156 cellET = pCell->et();
157 }
158 int sampling = pCell->caloDDE()->getSampling();
159 if (const auto & pElement {samplingLookup.find(sampling)};pElement != notFound){
160 sampling = pElement->second;
161 }
162 int i = 2;
163 if (sampling < 4) i = sampling;
164 if (sampling == 12 || sampling == 13 || sampling == 14) i = 3;
165 detPhiTrk = TVector2::Phi_mpi_pi(cellPhi-extrapolatedPhi[i]);
166 detEtaTrk = std::abs( cellEta - extrapolatedEta[i] );
167 if ((sampling == 0 && detEtaTrk < eta0cut && detPhiTrk < phi0cut) ||
168 (sampling == 1 && detEtaTrk < eta1cut && detPhiTrk < phi1cut) ||
169 (sampling == 2 && detEtaTrk < eta2cut && detPhiTrk < phi2cut) ||
170 (sampling == 3 && detEtaTrk < eta3cut && detPhiTrk < phi3cut)) {
171 sumETCellsLAr += cellET;
172 }
173 } //end cell loop
174 }// end jet constituent loop
175
176 pTau.setDetail(xAOD::TauJetParameters::sumEMCellEtOverLeadTrkPt , static_cast<float>( ( sumETCellsLAr / ( pTau.track(0)->pt() ) ) ) );
177 return StatusCode::SUCCESS;
178}
179
180#endif
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
Evaluate cell kinematics with a different vertex.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
virtual double phi() const override final
get phi (through CaloDetDescrElement)
Definition CaloCell.h:375
const CaloDetDescrElement * caloDDE() const
get pointer to CaloDetDescrElement (data member)
Definition CaloCell.h:321
virtual double eta() const override final
get eta (through CaloDetDescrElement)
Definition CaloCell.h:382
virtual double et() const override final
get et
Definition CaloCell.h:423
CaloCell_ID::CaloSample getSampling() const
cell sampling
Evaluate cell kinematics with a different vertex.
virtual double eta() const final
The pseudorapidity of the particle.
virtual double phi() const final
The aximuthal angle of the particle.
virtual double et() const
transverse energy defined to be e*sin(theta)
size_t index() const
Return the index of this element within its container.
SG::ReadHandleKey< CaloExtensionCollection > m_ParticleCacheKey
Gaudi::Property< bool > m_useOldCalo
ToolHandle< Trk::IParticleCaloExtensionTool > m_caloExtensionTool
TauElectronVetoVariables(const std::string &name)
virtual StatusCode initialize() override
Tool initializer.
virtual StatusCode execute(xAOD::TauJet &pTau) const override
Execute - called for each tau candidate.
Gaudi::Property< bool > m_doVertexCorrection
TauRecToolBase(const std::string &name)
Tracking class to hold the extrapolation through calorimeter Layers Both the caloEntryLayerIntersecti...
const std::vector< CurvilinearParameters > & caloLayerIntersections() const
access to the intersections with the calorimeter layers.
helper class to encode and decode a TrackParametersIdentifier
bool isEntryToVolume(TrackParametersIdentifier id) const
returns true if the id belongs to the volume entrance
CaloSampling::CaloSample caloSample(TrackParametersIdentifier id) const
CaloSample encoded in id, returns CaloSampling::Unknown if id is not valid.
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Evaluate cluster kinematics with a different vertex / signal state.
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
const TauTrack * track(size_t i, TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged, int *container_index=0) const
Get the pointer to a given tauTrack associated with this tau /*container index needed by trackNonCons...
void setDetail(TauJetParameters::Detail detail, int value)
const Vertex * vertex() const
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
virtual double pt() const
The transverse momentum ( ) of the particle.
const TrackParticle * track() const
const Amg::Vector3D & position() const
Returns the 3-pos.
CurvilinearParametersT< TrackParametersDim, Charged, PlaneSurface > CurvilinearParameters
Definition index.py:1
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TauJet_v3 TauJet
Definition of the current "tau version".