ATLAS Offline Software
Loading...
Searching...
No Matches
GenericObjectThinning.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6// GenericObjectThinning.cxx, (c) ATLAS Detector software
8// Author: James Catmore (James.Catmore@cern.ch)
9// Removes all ID tracks which do not pass a user-defined cut
10
13#include "GaudiKernel/ThreadLocalContext.h"
14#include <vector>
15#include <string>
16
17// Constructor
19 const std::string& n,
20 const IInterface* p ) :
21base_class(t,n,p),
23m_ntot(0),
24m_npass(0)
25{
26 declareProperty("SelectionString", m_selectionString);
27}
28
29// Destructor
32
33// Athena initialize and finalize
35{
36 ATH_MSG_VERBOSE("initialize() ...");
37 if (m_selectionString.empty()) {
38 ATH_MSG_FATAL("No selection string provided!");
39 return StatusCode::FAILURE;
40 } else {ATH_MSG_INFO("Selection string: " << m_selectionString);}
41
42 // Set up the text-parsing machinery for thinning the tracks directly according to user cuts
43 if (!m_selectionString.empty()) {
44 ATH_CHECK(initializeParser( m_selectionString) );
45 }
46
47 //check xAOD::InDetTrackParticle collection
48 ATH_CHECK( m_SGKey.initialize (m_streamName) );
49 ATH_MSG_INFO("Using " << m_SGKey << "as the source collection");
50
51 return StatusCode::SUCCESS;
52}
53
55{
56 ATH_MSG_VERBOSE("finalize() ...");
57 ATH_MSG_INFO("Processed "<< m_ntot <<" objects, "<< m_npass<< " were retained ");
58 ATH_CHECK(finalizeParser());
59 return StatusCode::SUCCESS;
60}
61
62// The thinning itself
64{
65 const EventContext& ctx = Gaudi::Hive::currentContext();
66
67 // Retrieve main object collection
69
70 // Check the event contains objects
71 unsigned int nObjects = particles->size();
72 if (nObjects==0) return StatusCode::SUCCESS;
73
74 // Set up a mask with the same entries as the full collection
75 std::vector<bool> mask;
76 mask.assign(nObjects,false); // default: don't keep any tracks
77 m_ntot += nObjects;
78
79 // Execute the text parser and update the mask
80 if (m_parser) {
81 std::vector<int> entries = m_parser->evaluateAsVector();
82 unsigned int nEntries = entries.size();
83 // check the sizes are compatible
84 if (nObjects != nEntries ) {
85 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used the same collection as the input collection??");
86 return StatusCode::FAILURE;
87 } else {
88 // set mask
89 for (unsigned int i=0; i<nObjects; ++i) if (entries[i]==1) mask[i]=true;
90 }
91 }
92 // Count the mask
93 m_npass += std::count (mask.begin(), mask.end(), true);
94
95 // Execute the thinning based on the mask. Finish.
96 particles.keep (mask);
97
98 return StatusCode::SUCCESS;
99}
100
#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)
Handle for requesting thinning for a data object.
SG::ThinningHandleKey< xAOD::IParticleContainer > m_SGKey
virtual StatusCode doThinning() const override
GenericObjectThinning(const std::string &t, const std::string &n, const IInterface *p)
Handle for requesting thinning for a data object.
double entries
Definition listroot.cxx:49