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
17
18#include <string>
19#include <vector>
20
21// Constructor
23 const std::string& t,
24 const std::string& n,
25 const IInterface* p)
26 : base_class(t, n, p)
27 , m_ntotTopo(0)
28 , m_npassTopo(0)
30{
31 declareProperty("SelectionString", m_selectionString);
32}
33
34// Destructor
36
37// Athena initialize and finalize
38StatusCode
40{
41 // Decide which collections need to be checked for ID TrackParticles
42 ATH_MSG_VERBOSE("initialize() ...");
44 ATH_MSG_INFO("Using " << m_TopoClSGKey.key()
45 << "as the source collection for topo calo clusters");
46 if (m_sgKey.empty()) {
47 ATH_MSG_FATAL("No jet collection provided for thinning.");
48 return StatusCode::FAILURE;
49 } else {
51 "Calo clusters associated with objects in "
52 << m_sgKey.key()
53 << " will be retained in this format with the rest being thinned away");
54 ATH_CHECK(m_sgKey.initialize());
55 }
56
57 for(unsigned int i=0; i < m_addClusterSGKey.size(); i++){
61 }
62
63 // Set up the text-parsing machinery for selectiong the photon directly
64 // according to user cuts
65 if (!m_selectionString.empty()) {
66 ATH_CHECK(initializeParser(m_selectionString));
67 }
68
69 return StatusCode::SUCCESS;
70}
71
72StatusCode
74{
75 ATH_MSG_VERBOSE("finalize() ...");
76 ATH_MSG_INFO("Processed " << m_ntotTopo << " topo clusters, of which "
77 << m_npassTopo << " were retained ");
78 ATH_CHECK(finalizeParser());
79 return StatusCode::SUCCESS;
80}
81
82// The thinning itself
83StatusCode
85{
86
87 // Retrieve CalCaloTopo collection if required
89 m_TopoClSGKey, ctx);
90
91 // Check the event contains tracks
92 unsigned int nTopoClusters = importedTopoCaloCluster->size();
93 if (nTopoClusters == 0)
94 return StatusCode::SUCCESS;
95
96 // Set up a mask with the same entries as the full CaloCalTopoClusters collection(s)
97 std::vector<bool> topomask;
98 topomask.assign(nTopoClusters, false);
99 m_ntotTopo += nTopoClusters;
100
101 // Retrieve jet container
102 const xAOD::JetContainer* importedJets(nullptr);
103 SG::ReadHandle<xAOD::JetContainer> importedJetsHandle{ m_sgKey, ctx };
104 importedJets = importedJetsHandle.ptr();
105 if (importedJets == nullptr) {
106 ATH_MSG_ERROR("No jet collection with name " << m_sgKey.key()
107 << " found in StoreGate!");
108 return StatusCode::FAILURE;
109 }
110 unsigned int nJets(importedJets->size());
111 if (nJets == 0)
112 return StatusCode::SUCCESS;
113 std::vector<const xAOD::Jet*> jetToCheck;
114 jetToCheck.clear();
115
116 // Execute the text parsers if requested
117 if (!m_selectionString.empty()) {
118 std::vector<int> entries = m_parser->evaluateAsVector();
119 unsigned int nEntries = entries.size();
120 // check the sizes are compatible
121 if (nJets != nEntries) {
122 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string "
123 "used jets objects??");
124 return StatusCode::FAILURE;
125 } else {
126 // identify which e-gammas to keep for the thinning check
127 for (unsigned int i = 0; i < nJets; ++i)
128 if (entries[i] == 1)
129 jetToCheck.push_back((*importedJets)[i]);
130 }
131
132 if(jetToCheck.empty())
133 return StatusCode::SUCCESS;
134
135 for( const xAOD::Jet* jet : jetToCheck){
136 const auto& links = jet->constituentLinks();
137 for( const auto& link : links ) {
138 // Check that the link is valid:
139 if( ! link.isValid() ) {
140 continue;
141 }
142 topomask.at( link.index() ) = true;
143 }
144 }
145 }
146 else{
147 for( const xAOD::Jet* jet : *importedJets){
148 const auto& links = jet->constituentLinks();
149 for( const auto& link : links ) {
150 // Check that the link is valid:
151 if( ! link.isValid() ) {
152 continue;
153 }
154 topomask.at( link.index() ) = true;
155 }
156 }
157 }
158
159 // Count up the mask contents
160 for (unsigned int i = 0; i < nTopoClusters; ++i) {
161 if (topomask[i])
162 ++m_npassTopo;
163 }
164
165 // Execute the thinning service based on the mask. Finish.
166 importedTopoCaloCluster.keep(topomask);
167
168 for(const auto & addClusterKey : m_addClusterKeys){
169 SG::ThinningHandle<xAOD::CaloClusterContainer> tempClusters(addClusterKey);
170 tempClusters.keep(topomask);
171 }
172
173 return StatusCode::SUCCESS;
174}
#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
virtual StatusCode doThinning(const EventContext &ctx) const override
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
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".