ATLAS Offline Software
Loading...
Searching...
No Matches
DerivationFramework::TauTrackParticleThinning Class Reference

#include <TauTrackParticleThinning.h>

Inheritance diagram for DerivationFramework::TauTrackParticleThinning:
Collaboration diagram for DerivationFramework::TauTrackParticleThinning:

Public Member Functions

 TauTrackParticleThinning (const std::string &t, const std::string &n, const IInterface *p)
virtual ~TauTrackParticleThinning ()
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual StatusCode doThinning (const EventContext &ctx) const override

Private Attributes

std::atomic< unsigned int > m_ntot {}
std::atomic< unsigned int > m_npass {}
StringProperty m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
SG::ThinningHandleKey< xAOD::TrackParticleContainerm_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
SG::ReadHandleKey< xAOD::TauJetContainerm_tauKey { this, "TauKey", "", ""}
Gaudi::Property< bool > m_doTauTracksThinning { this, "DoTauTracksThinning", false, "Apply thinning to tau tracks in addition to ID tracks"}
SG::ThinningHandleKey< xAOD::TauTrackContainerm_tauTracksSGKey { this, "TauTracksKey", "TauTracks", "StoreGate key of the tau track container" }
Gaudi::Property< std::string > m_selectionString { this, "SelectionString", "",""}
Gaudi::Property< float > m_coneSize { this, "ConeSize", -1.0, ""}

Detailed Description

Definition at line 29 of file TauTrackParticleThinning.h.

Constructor & Destructor Documentation

◆ TauTrackParticleThinning()

DerivationFramework::TauTrackParticleThinning::TauTrackParticleThinning ( const std::string & t,
const std::string & n,
const IInterface * p )

Definition at line 20 of file TauTrackParticleThinning.cxx.

22 :
23base_class(t,n,p)
24{
25}

◆ ~TauTrackParticleThinning()

DerivationFramework::TauTrackParticleThinning::~TauTrackParticleThinning ( )
virtualdefault

Member Function Documentation

◆ doThinning()

StatusCode DerivationFramework::TauTrackParticleThinning::doThinning ( const EventContext & ctx) const
overridevirtual

Definition at line 68 of file TauTrackParticleThinning.cxx.

69{
70
71 // Retrieve main TrackParticle collection
72 SG::ThinningHandle<xAOD::TrackParticleContainer> importedTrackParticles
73 (m_inDetSGKey, ctx);
74
75 // Check the event contains tracks
76 unsigned int nTracks = importedTrackParticles->size();
77 if (nTracks==0) return StatusCode::SUCCESS;
78
79 // Set up a mask with the same entries as the full TrackParticle collection
80 std::vector<bool> mask;
81 mask.assign(nTracks,false); // default: don't keep any tracks
82 m_ntot += nTracks;
83
84 // Retrieve containers
85 // ... taus
86 SG::ReadHandle<xAOD::TauJetContainer> importedTaus(m_tauKey,ctx);
87 if (!importedTaus.isValid()) {
88 ATH_MSG_ERROR("No tau collection with name " << m_tauKey.key() << " found in StoreGate!");
89 return StatusCode::FAILURE;
90 }
91 unsigned int nTaus(importedTaus->size());
92 std::vector<const xAOD::TauJet*> tauToCheck; tauToCheck.clear();
93
94 // Execute the text parser if requested
95 if (!m_selectionString.empty()) {
96 std::vector<int> entries = m_parser->evaluateAsVector();
97 unsigned int nEntries = entries.size();
98 // check the sizes are compatible
99 if (nTaus != nEntries ) {
100 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string used taus??");
101 return StatusCode::FAILURE;
102 } else {
103 // identify which taus to keep for the thinning check
104 for (unsigned int i=0; i<nTaus; ++i) if (entries[i]==1) tauToCheck.push_back((*importedTaus)[i]);
105 }
106 } else {
107 // use all taus if no selection string is passed
108 for (unsigned int i=0; i<nTaus; ++i) tauToCheck.push_back((*importedTaus)[i]);
109 }
110
111 // Set elements in the mask to true if there is a corresponding ElementLink from a reconstructed object
112 // ... taus
113 DerivationFramework::TracksInCone trIC;
114 if (m_selectionString=="") { // check all taus as user didn't provide a selection string
115 for (const auto *tauIt : *importedTaus) {
116 if (m_coneSize>0.0) trIC.select(tauIt,m_coneSize,importedTrackParticles.cptr(),mask); // check tracks in a cone around the tau if req'd
117 for (unsigned int i=0; i<tauIt->nTracks(); ++i) {
119 mask[index] = true;
120 }
121 }
122 } else { // check only taus passing user selection string
123 for (auto & tauIt : tauToCheck) {
124 if (m_coneSize>0.0) trIC.select(tauIt,m_coneSize,importedTrackParticles.cptr(),mask); // check tracks in a cone around the tau if req'd
125 for (unsigned int i=0; i<tauIt->nTracks(); ++i) {
127 mask[index] = true;
128 }
129 }
130 }
131
132 // Count up the mask contents
133 unsigned int n_pass=0;
134 for (unsigned int i=0; i<nTracks; ++i) {
135 if (mask[i]) ++n_pass;
136 }
137 m_npass += n_pass;
138
139 // Execute the thinning service based on the mask.
140 importedTrackParticles.keep (mask);
141
142 // Apply thinning to tau track collection if requested
144 SG::ThinningHandle<xAOD::TauTrackContainer> importedTauTracks
145 (m_tauTracksSGKey, ctx);
146 if( importedTauTracks->empty() ) {
147 return StatusCode::SUCCESS;
148 }
149 std::vector< bool > mask_tautracks( importedTauTracks->size(), false );
150
151 for( const xAOD::TauJet* tau : tauToCheck ) {
152 // Get all the associated charged tau tracks:
153 auto ttLinks = tau->tauTrackLinks(xAOD::TauJetParameters::TauTrackFlag::classifiedCharged );
154 // Process the links:
155 for( const auto& ttLink : ttLinks ) {
156 if( ! ttLink.isValid() ) {
157 continue;
158 }
159 if( ttLink.dataID() != m_tauTracksSGKey.key() ) {
160 ATH_MSG_FATAL( "Charged tau track does not come from "
161 "container \"" << m_tauTracksSGKey << "\"" );
162 return StatusCode::FAILURE;
163 }
164 // If it is, set the mask for it:
165 mask_tautracks.at( ttLink.index() ) = true;
166 }
167 // Select the tau tracks in a cone if it was requested (NOT RECOMMENDED):
168 if( m_coneSize > 0.0 ) {
169 trIC.select( tau, m_coneSize, importedTauTracks.cptr(), mask_tautracks );
170 }
171 }
172
173 importedTauTracks.keep(mask_tautracks);
174
175 }
176
177 return StatusCode::SUCCESS;
178
179}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
SG::ReadHandleKey< xAOD::TauJetContainer > m_tauKey
SG::ThinningHandleKey< xAOD::TauTrackContainer > m_tauTracksSGKey
double entries
Definition listroot.cxx:49
str index
Definition DeMoScan.py:362
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
TauJet_v3 TauJet
Definition of the current "tau version".
void select(const xAOD::IParticle *particle, float coneSize, const xAOD::TrackParticleContainer *tracks, std::vector< bool > &mask)

◆ finalize()

StatusCode DerivationFramework::TauTrackParticleThinning::finalize ( )
overridevirtual

Definition at line 59 of file TauTrackParticleThinning.cxx.

60{
61 ATH_MSG_VERBOSE("finalize() ...");
62 ATH_MSG_INFO("Processed "<< m_ntot <<" tracks, "<< m_npass<< " were retained ");
63 ATH_CHECK( finalizeParser() );
64 return StatusCode::SUCCESS;
65}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)

◆ initialize()

StatusCode DerivationFramework::TauTrackParticleThinning::initialize ( )
overridevirtual

Definition at line 31 of file TauTrackParticleThinning.cxx.

32{
33 // Decide which collections need to be checked for ID TrackParticles
34 ATH_MSG_VERBOSE("initialize() ...");
35 ATH_CHECK( m_inDetSGKey.initialize (m_streamName) );
36 ATH_MSG_INFO("Using " << m_inDetSGKey << "as the source collection for inner detector track particles");
37 if (m_tauKey.key().empty()) {
38 ATH_MSG_FATAL("No tau collection provided for thinning.");
39 return StatusCode::FAILURE;
40 } else { ATH_MSG_INFO("Inner detector track particles associated with objects in " << m_tauKey.key() << " will be retained in this format with the rest being thinned away");}
41 ATH_CHECK(m_tauKey.initialize());
43 if (m_tauTracksSGKey.key().empty()) {
44 ATH_MSG_FATAL("No tau tracks collection provided for thinning, despite this option being requested.");
45 return StatusCode::FAILURE;
46 } else {
47 ATH_MSG_INFO("Tau track thinning requested; tau tracks with the SG key " << m_tauTracksSGKey.key() << " will be thinned if not associated with objects in " << m_tauKey.key());
49 }
50 }
51
52 // Set up the text-parsing machinery for selectiong the tau directly according to user cuts
53 if (!m_selectionString.empty()) {
54 ATH_CHECK(initializeParser(m_selectionString) );
55 }
56 return StatusCode::SUCCESS;
57}

Member Data Documentation

◆ m_coneSize

Gaudi::Property<float> DerivationFramework::TauTrackParticleThinning::m_coneSize { this, "ConeSize", -1.0, ""}
private

Definition at line 52 of file TauTrackParticleThinning.h.

53{ this, "ConeSize", -1.0, ""};

◆ m_doTauTracksThinning

Gaudi::Property<bool> DerivationFramework::TauTrackParticleThinning::m_doTauTracksThinning { this, "DoTauTracksThinning", false, "Apply thinning to tau tracks in addition to ID tracks"}
private

Definition at line 46 of file TauTrackParticleThinning.h.

47{ this, "DoTauTracksThinning", false, "Apply thinning to tau tracks in addition to ID tracks"};

◆ m_inDetSGKey

SG::ThinningHandleKey<xAOD::TrackParticleContainer> DerivationFramework::TauTrackParticleThinning::m_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
private

Definition at line 42 of file TauTrackParticleThinning.h.

43{ this, "InDetTrackParticlesKey", "InDetTrackParticles", "" };

◆ m_npass

std::atomic<unsigned int> DerivationFramework::TauTrackParticleThinning::m_npass {}
mutableprivate

Definition at line 39 of file TauTrackParticleThinning.h.

39{};

◆ m_ntot

std::atomic<unsigned int> DerivationFramework::TauTrackParticleThinning::m_ntot {}
mutableprivate

Definition at line 38 of file TauTrackParticleThinning.h.

38{};

◆ m_selectionString

Gaudi::Property<std::string> DerivationFramework::TauTrackParticleThinning::m_selectionString { this, "SelectionString", "",""}
private

Definition at line 50 of file TauTrackParticleThinning.h.

51{ this, "SelectionString", "",""};

◆ m_streamName

StringProperty DerivationFramework::TauTrackParticleThinning::m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
private

Definition at line 40 of file TauTrackParticleThinning.h.

41{ this, "StreamName", "", "Name of the stream being thinned" };

◆ m_tauKey

SG::ReadHandleKey<xAOD::TauJetContainer> DerivationFramework::TauTrackParticleThinning::m_tauKey { this, "TauKey", "", ""}
private

Definition at line 44 of file TauTrackParticleThinning.h.

45{ this, "TauKey", "", ""};

◆ m_tauTracksSGKey

SG::ThinningHandleKey<xAOD::TauTrackContainer> DerivationFramework::TauTrackParticleThinning::m_tauTracksSGKey { this, "TauTracksKey", "TauTracks", "StoreGate key of the tau track container" }
private

Definition at line 48 of file TauTrackParticleThinning.h.

49{ this, "TauTracksKey", "TauTracks", "StoreGate key of the tau track container" };

The documentation for this class was generated from the following files: