ATLAS Offline Software
IsolationTrackDecorator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // IsolationDecorator.cxx, (c) ATLAS Detector software
8 
11 #include <vector>
12 #include <string>
13 
14 #include "CLHEP/Units/SystemOfUnits.h"
15 
22 
23 // Constructor
25  const std::string& n,
26  const IInterface* p):
27  base_class(t, n, p){}
28 
29 // Athena initialize and finalize
31 {
32  ATH_MSG_DEBUG("initialize() ...");
33 
34  // load the matching tool
35  if( ! m_caloIsolationTool.empty() ) {
36  ATH_CHECK( m_caloIsolationTool.retrieve() );
37  ATH_MSG_INFO( "Successfully retrived the CaloIsolationTool!" );
38  }
39 
40  if( ! m_trackIsolationTool.empty() ) {
41  ATH_CHECK( m_trackIsolationTool.retrieve() );
42  ATH_MSG_INFO( "Successfully retrived the TrackIsolationTool!" );
43  }
44 
45  ATH_CHECK(m_trackContainerKey.initialize());
46 
47  m_trkCorrList.trackbitset.set(static_cast<unsigned int>(xAOD::Iso::coreTrackPtr));
48  m_topoconeCorrList.calobitset.set(static_cast<unsigned int>(xAOD::Iso::coreCone));
49  m_topoconeCorrList.calobitset.set(static_cast<unsigned int>(xAOD::Iso::pileupCorrection));
50  m_topoclusCorrList.calobitset.set(static_cast<unsigned int>(xAOD::Iso::pileupCorrection));
51 
53  m_ptconeTypes.clear();
54  m_ptvarconeTypes.clear();
55  m_topoetconeTypes.clear();
56 
57  for(unsigned int i=0; i<m_iso.size(); i++){
58  xAOD::Iso::IsolationType isoType = static_cast<xAOD::Iso::IsolationType>(m_iso[i]);
59  xAOD::Iso::IsolationFlavour flavour = static_cast<xAOD::Iso::IsolationFlavour>(isoType/10.);
60 
61  if(flavour == xAOD::Iso::ptcone) {
62  m_ptconeTypes.push_back(isoType);
63  m_ptconeDecoratorsKey.emplace_back(m_trackContainerKey.key() + "." + m_prefix + m_iso_suffix[i]);
64  }
65  if(flavour == xAOD::Iso::ptvarcone) {
66  m_ptvarconeTypes.push_back(isoType);
67  m_ptvarconeDecoratorsKey.emplace_back(m_trackContainerKey.key() + "." + m_prefix + m_iso_suffix[i]);
68  }
69  if(flavour == xAOD::Iso::topoetcone) {
70  m_topoetconeTypes.push_back(isoType);
71  m_topoetconeDecoratorsKey.emplace_back(m_trackContainerKey.key() + "." + m_prefix + m_iso_suffix[i]);
72  m_topoetconeNonCoreConeDecoratorsKey.emplace_back(m_trackContainerKey.key() + "." + m_prefix + m_iso_suffix[i] + "NonCoreCone");
73  }
74  }
75  ATH_CHECK(m_ptconeDecoratorsKey.initialize());
76  ATH_CHECK(m_ptvarconeDecoratorsKey.initialize());
77  ATH_CHECK(m_topoetconeDecoratorsKey.initialize());
78  ATH_CHECK(m_topoetconeNonCoreConeDecoratorsKey.initialize());
79 
80  // Set up the text-parsing machinery for thinning the tracks directly according to user cuts
81  if (not m_selectionString.empty()) {
82  ATH_CHECK(initializeParser(m_selectionString));
83  }
84 
85  if(not m_selFlag.empty()){
86  m_dec_trkFlagKey = m_trackContainerKey.key() + "." + m_selFlag;
87  } else {
88  m_dec_trkFlagKey = m_trackContainerKey.key() + ".no_key";
89  }
90  ATH_CHECK(m_dec_trkFlagKey.initialize());
91 
92  return StatusCode::SUCCESS;
93 }
94 
96 {
97  ATH_MSG_DEBUG("finalize() ...");
98  ATH_CHECK(finalizeParser());
99 
100  return StatusCode::SUCCESS;
101 }
102 
104 {
105  const EventContext& ctx = Gaudi::Hive::currentContext();
106  // retrieve track container
107  SG::ReadHandle<xAOD::TrackParticleContainer> toDecorate(m_trackContainerKey,ctx);
108  ATH_CHECK( toDecorate.isValid() );
109 
110  // Execute the text parser and update the mask
111  std::vector<int> entries(toDecorate->size(), 1);
112  if (m_parser) {
113  entries = m_parser->evaluateAsVector();
114  if (entries.size() != toDecorate->size()) {
115  ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used ID TrackParticles?");
116  return StatusCode::FAILURE;
117  }
118  }
119 
120  // build the decorators
121  std::vector<SG::WriteDecorHandle<xAOD::TrackParticleContainer, float>> ptconeDecorators;
122  for(unsigned int i=0; i<m_ptconeTypes.size(); i++){
123  ptconeDecorators.emplace_back(m_ptconeDecoratorsKey[i], ctx);
124  }
125  std::vector<SG::WriteDecorHandle<xAOD::TrackParticleContainer, float>> ptvarconeDecorators;
126  for(unsigned int i=0; i<m_ptvarconeTypes.size(); i++){
127  ptvarconeDecorators.emplace_back(m_ptconeDecoratorsKey[i], ctx);
128  }
129  std::vector<SG::WriteDecorHandle<xAOD::TrackParticleContainer, float>> topoetconeDecorators;
130  for(unsigned int i=0; i<m_topoetconeTypes.size(); i++){
131  topoetconeDecorators.emplace_back(m_topoetconeDecoratorsKey[i], ctx);
132  }
133  std::vector<SG::WriteDecorHandle<xAOD::TrackParticleContainer, float>> topoetconeNonCoreConeDecorators;
134  for(unsigned int i=0; i<m_topoetconeTypes.size(); i++){
135  topoetconeNonCoreConeDecorators.emplace_back(m_topoetconeNonCoreConeDecoratorsKey[i], ctx);
136  }
137 
138  SG::WriteDecorHandle<xAOD::TrackParticleContainer, int> dec_trkFlag(m_dec_trkFlagKey, ctx);
139 
141  int ipar=0;
142  for(auto particle : *toDecorate) {
143  bool IsPassed=true;
144 
146  if (!entries[ipar++]) IsPassed=false;
147 
149  if(not m_selFlag.empty()){
150  if(dec_trkFlag(*particle)!=m_selFlagValue) IsPassed=false;
151  }
152 
153  if(m_iso.size()>0){
154  if(IsPassed){
156  xAOD::TrackIsolation resultTrack;
157  xAOD::TrackIsolation resultTrackVar;
158  xAOD::CaloIsolation resultCalo;
159  xAOD::CaloIsolation resultCaloNonCoreCone;
160  if(m_ptconeTypes.size()) {
161 
162  if (m_trackIsolationTool->trackIsolation(resultTrack, *particle, m_ptconeTypes, m_trkCorrList)){
163  for(unsigned int i=0; i<m_ptconeTypes.size(); i++){
164  ptconeDecorators[i](*particle) = resultTrack.ptcones[i];
165  }
166  }else{
167  ATH_MSG_WARNING("Failed to apply the track isolation for a particle");
168  }
169  }
170 
171  if(m_ptvarconeTypes.size()) {
172 
173  std::vector<xAOD::Iso::IsolationType> ptconeTypes = {};
174  for(auto isoType : m_ptvarconeTypes) {
175  int iso_tmp = static_cast<int>(isoType);
176  iso_tmp -= m_diff_ptvarcone;
177  ptconeTypes.push_back(static_cast<xAOD::Iso::IsolationType>(iso_tmp));
178  }
179 
180  if (m_trackIsolationTool->trackIsolation(resultTrackVar, *particle, ptconeTypes, m_trkCorrList)){
181  for(unsigned int i=0; i<m_ptvarconeTypes.size(); i++){
182  ptvarconeDecorators[i](*particle) = resultTrackVar.ptvarcones_10GeVDivPt[i];
183  }
184  }else{
185  ATH_MSG_WARNING("Failed to apply the track isolation for a particle");
186  }
187  }
188 
189  if(m_topoetconeTypes.size()) {
190 
191  if (m_caloIsolationTool->caloTopoClusterIsolation(resultCalo, *particle, m_topoetconeTypes, m_topoconeCorrList)){
192  for(unsigned int i=0; i<m_topoetconeTypes.size(); i++){
193  topoetconeDecorators[i](*particle) = resultCalo.etcones[i];
194  }
195  }else{
196  ATH_MSG_WARNING("Failed to apply the track isolation for a particle");
197  }
198 
199  if (m_caloIsolationTool->caloTopoClusterIsolation(resultCaloNonCoreCone, *particle, m_topoetconeTypes, m_topoclusCorrList)){
200  for(unsigned int i=0; i<m_topoetconeTypes.size(); i++){
201  topoetconeNonCoreConeDecorators[i](*particle) = resultCaloNonCoreCone.etcones[i];
202  }
203  }else {
204  ATH_MSG_WARNING("Failed to apply the topo calo isolation for a particle ( non CoreCone )");
205  }
206 
207  }
208 
209  }else{
210  for(unsigned int i=0; i<m_ptconeTypes.size(); i++){
211  ptconeDecorators[i](*particle) = -999.e3;
212  }
213  for(unsigned int i=0; i<m_ptvarconeTypes.size(); i++){
214  ptvarconeDecorators[i](*particle) = -999.e3;
215  }
216  for(unsigned int i=0; i<m_topoetconeTypes.size(); i++){
217  topoetconeDecorators[i](*particle) = -999.e3;
218  topoetconeNonCoreConeDecorators[i](*particle) = -999.e3;
219  }
220  }
221  }
222  }
223 
224  return StatusCode::SUCCESS;
225 }
xAOD::Iso::topoetcone
@ topoetcone
Topo-cluster ET-sum.
Definition: IsolationFlavour.h:25
SGxAODProxyLoader.h
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::TrackIsolation::ptvarcones_10GeVDivPt
std::vector< float > ptvarcones_10GeVDivPt
Definition: IsolationCommon.h:37
IsolationTrackDecorator.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAOD::Iso::IsolationFlavour
IsolationFlavour
Enumeration for different ways of calculating isolation in xAOD files.
Definition: IsolationFlavour.h:17
xAOD::Iso::coreTrackPtr
@ coreTrackPtr
tracks pointer
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:66
DerivationFramework::IsolationTrackDecorator::initialize
virtual StatusCode initialize() override
Definition: IsolationTrackDecorator.cxx:30
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::CaloIsolation
Definition: IsolationCommon.h:22
xAOD::Iso::ptvarcone
@ ptvarcone
mini isolation
Definition: IsolationFlavour.h:28
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::Iso::IsolationType
IsolationType
Overall enumeration for isolation types in xAOD files.
Definition: IsolationType.h:26
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::Iso::ptcone
@ ptcone
Track isolation.
Definition: IsolationFlavour.h:22
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
xAOD::TrackIsolation
Definition: IsolationCommon.h:33
DerivationFramework::IsolationTrackDecorator::finalize
virtual StatusCode finalize() override
Definition: IsolationTrackDecorator.cxx:95
errorcheck.h
Helpers for checking error return status codes and reporting errors.
xAOD::CaloIsolation::etcones
std::vector< float > etcones
Definition: IsolationCommon.h:30
xAOD::Iso::coreCone
@ coreCone
core energy (in dR<0.1).
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:29
EventInfo.h
MultipleProxyLoader.h
xAOD::TrackIsolation::ptcones
std::vector< float > ptcones
Definition: IsolationCommon.h:36
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::IsolationTrackDecorator::IsolationTrackDecorator
IsolationTrackDecorator(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: IsolationTrackDecorator.cxx:24
entries
double entries
Definition: listroot.cxx:49
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TrackingPrimitives.h
TrackParticleContainer.h
DerivationFramework::IsolationTrackDecorator::addBranches
virtual StatusCode addBranches() const override
Definition: IsolationTrackDecorator.cxx:103
xAOD::Iso::pileupCorrection
@ pileupCorrection
fully corrected
Definition: Event/xAOD/xAODPrimitives/xAODPrimitives/IsolationCorrection.h:35