ATLAS Offline Software
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)
30  , m_selectionString("")
31 {
32  declareProperty("SelectionString", m_selectionString);
33 }
34 
35 // Destructor
37 
38 // Athena initialize and finalize
41 {
42  // Decide which collections need to be checked for ID TrackParticles
43  ATH_MSG_VERBOSE("initialize() ...");
44  ATH_CHECK(m_TopoClSGKey.initialize(m_streamName));
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++){
59  m_tmpAddClusterKey = m_addClusterSGKey[i];
60  ATH_CHECK(m_tmpAddClusterKey.initialize(m_streamName));
61  m_addClusterKeys.push_back(m_tmpAddClusterKey);
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 
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
86 {
87  const EventContext& ctx = Gaudi::Hive::currentContext();
88 
89  // Retrieve CalCaloTopo collection if required
90  SG::ThinningHandle<xAOD::CaloClusterContainer> importedTopoCaloCluster(
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 }
Jet.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::JetCaloClusterThinning::initialize
virtual StatusCode initialize() override
Definition: JetCaloClusterThinning.cxx:40
ThinningHandle.h
Handle for requesting thinning for a data object.
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
JetCaloClusterThinning.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
JetConstituentVector.h
This file defines helper classes to deal with jet constituents.
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
SG::ThinningHandleBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition: ThinningHandleBase.cxx:75
DerivationFramework::JetCaloClusterThinning::JetCaloClusterThinning
JetCaloClusterThinning(const std::string &t, const std::string &n, const IInterface *p)
Definition: JetCaloClusterThinning.cxx:23
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
DerivationFramework::JetCaloClusterThinning::m_selectionString
std::string m_selectionString
Definition: JetCaloClusterThinning.h:57
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
CaloCluster.h
beamspotman.n
n
Definition: beamspotman.py:729
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DMTest::links
links
Definition: CLinks_v1.cxx:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
DerivationFramework::JetCaloClusterThinning::finalize
virtual StatusCode finalize() override
Definition: JetCaloClusterThinning.cxx:74
entries
double entries
Definition: listroot.cxx:49
DerivationFramework::JetCaloClusterThinning::~JetCaloClusterThinning
virtual ~JetCaloClusterThinning()
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:72
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DerivationFramework::JetCaloClusterThinning::doThinning
virtual StatusCode doThinning() const override
Definition: JetCaloClusterThinning.cxx:85