ATLAS Offline Software
Loading...
Searching...
No Matches
TrackMeasurementThinning.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// TrackMeasurementThinning.cxx, (c) ATLAS Detector software
8// Author: David Salek (David.Salek@cern.ch)
9// Thinning tool for TrackMeasurementValidationContainer
10
14#include "GaudiKernel/ThreadLocalContext.h"
15#include <vector>
16#include <string>
17
18// Constructor
20 const std::string& n,
21 const IInterface* p ) :
22 base_class(t,n,p)
23 {
24 }
25
26// Destructor
28
29// Athena initialize and finalize
31{
32 ATH_MSG_VERBOSE("initialize() ...");
33 if (m_selectionString.empty()) {
34 ATH_MSG_FATAL("No inner detector track selection string provided!");
35 return StatusCode::FAILURE;
36 } else {ATH_MSG_INFO("Track thinning selection string: " << m_selectionString);}
37
38 //check xAOD::InDetTrackParticle collection
39 ATH_CHECK( m_SGKey.initialize (m_streamName) );
40 ATH_MSG_INFO("Using " << m_SGKey << "as the source collection for thinning.");
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 return StatusCode::SUCCESS;
47}
49{
50 ATH_MSG_VERBOSE("finalize() ...");
51 ATH_MSG_INFO("Processed "<< m_ntot <<" measurements, "<< m_npass<< " were retained ");
52 ATH_CHECK( finalizeParser());
53 return StatusCode::SUCCESS;
54}
55
56// The thinning itself
58{
59 const EventContext& ctx = Gaudi::Hive::currentContext();
60
61 // Get the cluster container
63 (m_SGKey, ctx);
64
65 // Check the event contains clusters
66 unsigned int nClusters = clusters->size();
67 if (nClusters==0) return StatusCode::SUCCESS;
68
69 // Set up a mask with the same entries as the full collection
70 std::vector<bool> mask;
71 mask.assign(nClusters,false); // default: don't keep anything
72 m_ntot += nClusters;
73
74 // Execute the text parser and update the mask
75 if (m_parser) {
76 std::vector<int> entries = m_parser->evaluateAsVector();
77 unsigned int nEntries = entries.size();
78 // check the sizes are compatible
79 if (nClusters != nEntries ) {
80 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used the same collection as the input collection??");
81 return StatusCode::FAILURE;
82 } else {
83 // set mask
84 for (unsigned int i=0; i<nClusters; ++i) if (entries[i]==1) mask[i]=true;
85 }
86 }
87 // Count the mask
88 unsigned int n_pass=0;
89 for (unsigned int i=0; i<nClusters; ++i) {
90 if (mask[i]) ++n_pass;
91 }
92 m_npass += n_pass;
93
94 // Execute the thinning service based on the mask. Finish.
95 clusters.keep (mask);
96
97 return StatusCode::SUCCESS;
98}
99
#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::TrackMeasurementValidationContainer > m_SGKey
TrackMeasurementThinning(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
virtual StatusCode doThinning() const override
Check that the current event passes this filter.
Handle for requesting thinning for a data object.
double entries
Definition listroot.cxx:49