ATLAS Offline Software
Loading...
Searching...
No Matches
JetCaloClusterThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6// JetCaloClusterThinning.cxx, (c) ATLAS Detector software
7// @author Danilo E. Ferreira de Lima <dferreir@cern.ch>
9
11
13#include "xAODJet/Jet.h"
14
15#include "GaudiKernel/ThreadLocalContext.h"
18
19#include <string>
20#include <vector>
21
22// Constructor
24 const std::string& t,
25 const std::string& n,
26 const IInterface* p)
27 : base_class(t, n, p)
28 , m_ntotTopo(0)
29 , m_npassTopo(0)
31{
32 declareProperty("SelectionString", m_selectionString);
33}
34
35// Destructor
37
38// Athena initialize and finalize
39StatusCode
41{
42 // Decide which collections need to be checked for ID TrackParticles
43 ATH_MSG_VERBOSE("initialize() ...");
45 ATH_MSG_INFO("Using " << m_TopoClSGKey.key()
46 << "as the source collection for topo calo clusters");
47 if (m_sgKey.empty()) {
48 ATH_MSG_FATAL("No jet collection provided for thinning.");
49 return StatusCode::FAILURE;
50 } else {
52 "Calo clusters associated with objects in "
53 << m_sgKey.key()
54 << " will be retained in this format with the rest being thinned away");
55 ATH_CHECK(m_sgKey.initialize());
56 }
57
58 for(unsigned int i=0; i < m_addClusterSGKey.size(); i++){
62 }
63
64 // Set up the text-parsing machinery for selectiong the photon directly
65 // according to user cuts
66 if (!m_selectionString.empty()) {
67 ATH_CHECK(initializeParser(m_selectionString));
68 }
69
70 return StatusCode::SUCCESS;
71}
72
73StatusCode
75{
76 ATH_MSG_VERBOSE("finalize() ...");
77 ATH_MSG_INFO("Processed " << m_ntotTopo << " topo clusters, of which "
78 << m_npassTopo << " were retained ");
79 ATH_CHECK(finalizeParser());
80 return StatusCode::SUCCESS;
81}
82
83// The thinning itself
84StatusCode
86{
87 const EventContext& ctx = Gaudi::Hive::currentContext();
88
89 // Retrieve CalCaloTopo collection if required
91 m_TopoClSGKey, ctx);
92
93 // Check the event contains tracks
94 unsigned int nTopoClusters = importedTopoCaloCluster->size();
95 if (nTopoClusters == 0)
96 return StatusCode::SUCCESS;
97
98 // Set up a mask with the same entries as the full CaloCalTopoClusters collection(s)
99 std::vector<bool> topomask;
100 topomask.assign(nTopoClusters, false);
101 m_ntotTopo += nTopoClusters;
102
103 // Retrieve jet container
104 const xAOD::JetContainer* importedJets(nullptr);
105 SG::ReadHandle<xAOD::JetContainer> importedJetsHandle{ m_sgKey, ctx };
106 importedJets = importedJetsHandle.ptr();
107 if (importedJets == nullptr) {
108 ATH_MSG_ERROR("No jet collection with name " << m_sgKey.key()
109 << " found in StoreGate!");
110 return StatusCode::FAILURE;
111 }
112 unsigned int nJets(importedJets->size());
113 if (nJets == 0)
114 return StatusCode::SUCCESS;
115 std::vector<const xAOD::Jet*> jetToCheck;
116 jetToCheck.clear();
117
118 // Execute the text parsers if requested
119 if (!m_selectionString.empty()) {
120 std::vector<int> entries = m_parser->evaluateAsVector();
121 unsigned int nEntries = entries.size();
122 // check the sizes are compatible
123 if (nJets != nEntries) {
124 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string "
125 "used jets objects??");
126 return StatusCode::FAILURE;
127 } else {
128 // identify which e-gammas to keep for the thinning check
129 for (unsigned int i = 0; i < nJets; ++i)
130 if (entries[i] == 1)
131 jetToCheck.push_back((*importedJets)[i]);
132 }
133
134 if(jetToCheck.empty())
135 return StatusCode::SUCCESS;
136
137 for( const xAOD::Jet* jet : jetToCheck){
138 const auto& links = jet->constituentLinks();
139 for( const auto& link : links ) {
140 // Check that the link is valid:
141 if( ! link.isValid() ) {
142 continue;
143 }
144 topomask.at( link.index() ) = true;
145 }
146 }
147 }
148 else{
149 for( const xAOD::Jet* jet : *importedJets){
150 const auto& links = jet->constituentLinks();
151 for( const auto& link : links ) {
152 // Check that the link is valid:
153 if( ! link.isValid() ) {
154 continue;
155 }
156 topomask.at( link.index() ) = true;
157 }
158 }
159 }
160
161 // Count up the mask contents
162 for (unsigned int i = 0; i < nTopoClusters; ++i) {
163 if (topomask[i])
164 ++m_npassTopo;
165 }
166
167 // Execute the thinning service based on the mask. Finish.
168 importedTopoCaloCluster.keep(topomask);
169
170 for(const auto & addClusterKey : m_addClusterKeys){
171 SG::ThinningHandle<xAOD::CaloClusterContainer> tempClusters(addClusterKey);
172 tempClusters.keep(topomask);
173 }
174
175 return StatusCode::SUCCESS;
176}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
This file defines helper classes to deal with jet constituents.
Handle for requesting thinning for a data object.
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ReadHandleKey< xAOD::JetContainer > m_sgKey
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_TopoClSGKey
JetCaloClusterThinning(const std::string &t, const std::string &n, const IInterface *p)
Gaudi::Property< std::vector< std::string > > m_addClusterSGKey
std::vector< SG::ThinningHandleKey< xAOD::CaloClusterContainer > > m_addClusterKeys
SG::ThinningHandleKey< xAOD::CaloClusterContainer > m_tmpAddClusterKey
virtual StatusCode doThinning() const override
const_pointer_type ptr()
Dereference the pointer.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
double entries
Definition listroot.cxx:49
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".