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

#include <EgammaTrackParticleThinning.h>

Inheritance diagram for DerivationFramework::EgammaTrackParticleThinning:
Collaboration diagram for DerivationFramework::EgammaTrackParticleThinning:

Public Member Functions

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

Private Member Functions

void setPhotonMasks (std::vector< bool > &, std::vector< bool > &, const xAOD::EgammaContainer *, const xAOD::TrackParticleContainer *, const xAOD::TrackParticleContainer *) const
void setElectronMasks (std::vector< bool > &, std::vector< bool > &, const xAOD::EgammaContainer *, const xAOD::TrackParticleContainer *, const xAOD::TrackParticleContainer *) const
void clearGSFVtx (const EventContext &ctx) const

Private Attributes

std::atomic< unsigned long int > m_ntot = 0
std::atomic< unsigned long int > m_ntotGSF = 0
std::atomic< unsigned long int > m_ntotGSFVtx = 0
std::atomic< unsigned long int > m_npass = 0
std::atomic< unsigned long int > m_nGSFPass = 0
std::atomic< unsigned long int > m_nGSFVtxPass = 0
std::atomic< unsigned long int > m_nEgammas = 0
std::atomic< unsigned long int > m_nSelEgammas = 0
StringProperty m_streamName { this, "StreamName", "", "Name of the stream being thinned" }
SG::ReadHandleKey< xAOD::EgammaContainerm_egammaKey { this, "SGKey", "", "" }
SG::ThinningHandleKey< xAOD::TrackParticleContainerm_inDetSGKey { this, "InDetTrackParticlesKey", "InDetTrackParticles", "" }
SG::ThinningHandleKey< xAOD::TrackParticleContainerm_gsfSGKey { this, "GSFTrackParticlesKey", "GSFTrackParticles", "" }
SG::ThinningHandleKey< xAOD::VertexContainerm_gsfVtxSGKey { this, "GSFConversionVerticesKey", "", "" }
StringProperty m_selectionString { this, "SelectionString", "", "" }
BooleanProperty m_bestMatchOnly { this, "BestMatchOnly", true, "" }
BooleanProperty m_bestVtxMatchOnly { this, "BestVtxMatchOnly", false, "" }
FloatProperty m_coneSize { this, "ConeSize", -1.0, "" }

Detailed Description

Definition at line 31 of file EgammaTrackParticleThinning.h.

Constructor & Destructor Documentation

◆ EgammaTrackParticleThinning()

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

Definition at line 22 of file EgammaTrackParticleThinning.cxx.

26 : base_class(t, n, p)
27{}

◆ ~EgammaTrackParticleThinning()

DerivationFramework::EgammaTrackParticleThinning::~EgammaTrackParticleThinning ( )
virtualdefault

Member Function Documentation

◆ clearGSFVtx()

void DerivationFramework::EgammaTrackParticleThinning::clearGSFVtx ( const EventContext & ctx) const
private

Definition at line 216 of file EgammaTrackParticleThinning.cxx.

218{
219 SG::ThinningHandle<xAOD::VertexContainer> importedGSFConversionVtx(
220 m_gsfVtxSGKey, ctx);
221 const xAOD::VertexContainer* gsfVtxs = importedGSFConversionVtx.cptr();
222 unsigned int nGSFVtx = gsfVtxs->size();
223 if (nGSFVtx == 0) {
224 ATH_MSG_DEBUG("No conversion vertex to thin");
225 return;
226 }
227 std::vector<bool> gsfVtxMask(nGSFVtx,false);
228 m_ntotGSFVtx += nGSFVtx;
229 ATH_MSG_DEBUG("nGSFVtx : " << nGSFVtx);
230 importedGSFConversionVtx.keep(gsfVtxMask);
231}
#define ATH_MSG_DEBUG(x)
size_type size() const noexcept
Returns the number of elements in the collection.
SG::ThinningHandleKey< xAOD::VertexContainer > m_gsfVtxSGKey
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".

◆ doThinning()

StatusCode DerivationFramework::EgammaTrackParticleThinning::doThinning ( ) const
overridevirtual

Definition at line 108 of file EgammaTrackParticleThinning.cxx.

109{
110 const EventContext& ctx = Gaudi::Hive::currentContext();
111 SG::ThinningHandle<xAOD::TrackParticleContainer> importedGSFTrackParticles(
112 m_gsfSGKey, ctx);
113
114 // Allow for not input Indet Track Particle collection
115 std::unique_ptr<SG::ThinningHandle<xAOD::TrackParticleContainer>>
116 importedTrackParticles = nullptr;
117 if (!m_inDetSGKey.empty()) {
118 importedTrackParticles =
119 std::make_unique<SG::ThinningHandle<xAOD::TrackParticleContainer>>(
120 m_inDetSGKey, ctx);
121 }
122
123 // Check the event contains tracks
124 const xAOD::TrackParticleContainer* tps = (importedTrackParticles != nullptr)
125 ? importedTrackParticles->cptr()
126 : nullptr;
127 const xAOD::TrackParticleContainer* gsfs = importedGSFTrackParticles.cptr();
128 unsigned int nTracks = tps ? tps->size() : 0;
129 unsigned int nGSF = gsfs->size();
130
131 ATH_MSG_DEBUG("nTracks : " << nTracks << " , nGSF : " << nGSF);
132 if (nTracks == 0 && nGSF == 0) {
133 ATH_MSG_DEBUG("Nothing to thin");
134 return StatusCode::SUCCESS;
135 }
136
137 // Set up a mask with the same entries as the full TrackParticle collection(s)
138 std::vector<bool> mask, gsfMask;
139 mask.assign(nTracks, false); // default: don't keep any tracks
140 gsfMask.assign(nGSF, false);
141 m_ntot += nTracks;
142 m_ntotGSF += nGSF;
143
144 // Retrieve e-gamma container
145 SG::ReadHandle<xAOD::EgammaContainer> importedEgamma(m_egammaKey, ctx);
146 if (!importedEgamma.isValid()) {
147 ATH_MSG_ERROR("No e-gamma collection with name " << m_egammaKey.key()
148 << " found in StoreGate!");
149 return StatusCode::FAILURE;
150 }
151
152 size_t nEgammas(importedEgamma->size());
153 ATH_MSG_DEBUG("nEgammas : " << nEgammas);
154 m_nEgammas += nEgammas;
155 bool doSelect = !m_selectionString.empty();
156 if (nEgammas != 0) {
157 ConstDataVector<xAOD::EgammaContainer> tofill(SG::VIEW_ELEMENTS);
158 // Execute the text parsers if requested
159 if (doSelect) {
160 std::vector<int> entries = m_parser->evaluateAsVector();
161 unsigned int nEntries = entries.size();
162 // check the sizes are compatible
163 if (nEgammas != nEntries) {
164 ATH_MSG_ERROR("Sizes incompatible! Are you sure your selection string "
165 "used e-gamma objects??");
166 return StatusCode::FAILURE;
167 } else {
168 // identify which e-gammas to keep for the thinning check
169 for (unsigned int i = 0; i < nEgammas; ++i)
170 if (entries[i] == 1)
171 tofill.push_back(importedEgamma->at(i));
172 }
173 } // end of selection
174 const xAOD::EgammaContainer* egToCheck = doSelect
175 ? tofill.asDataVector() : importedEgamma.cptr();
176 ATH_MSG_DEBUG("Setting the masks");
177 m_nSelEgammas += egToCheck->size();
178 // Are we dealing with electrons or photons?
179 if (dynamic_cast<const xAOD::ElectronContainer*>(importedEgamma.cptr()) != nullptr)
180 setElectronMasks(mask, gsfMask, egToCheck, tps, gsfs);
181 else if (dynamic_cast<const xAOD::PhotonContainer*>(importedEgamma.cptr()) != nullptr)
182 setPhotonMasks(mask, gsfMask, egToCheck, tps, gsfs);
183 else
184 ATH_MSG_WARNING("Input container is neither for Electrons, "
185 "nor for Photons ??");
186 }//end of if nEgammas != 0
187 else if (!m_gsfVtxSGKey.empty()) {
188 clearGSFVtx(ctx);
189 }
190
191 // Count up the mask contents
192 unsigned int n_pass = 0;
193 for (unsigned int i = 0; i < nTracks; ++i) {
194 if (mask[i]) {
195 ++n_pass;
196 }
197 }
198 m_npass += n_pass;
199 unsigned int n_gsf_pass = 0;
200 for (unsigned int i = 0; i < nGSF; ++i) {
201 if (gsfMask[i]) {
202 ++n_gsf_pass;
203 }
204 }
205 m_nGSFPass += n_gsf_pass;
206
207 // Execute the thinning service based on the mask. Finish.
208 importedGSFTrackParticles.keep(gsfMask);
209 if (tps) {
210 importedTrackParticles->keep(mask);
211 }
212
213 return StatusCode::SUCCESS;
214}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_inDetSGKey
SG::ThinningHandleKey< xAOD::TrackParticleContainer > m_gsfSGKey
void setPhotonMasks(std::vector< bool > &, std::vector< bool > &, const xAOD::EgammaContainer *, const xAOD::TrackParticleContainer *, const xAOD::TrackParticleContainer *) const
void setElectronMasks(std::vector< bool > &, std::vector< bool > &, const xAOD::EgammaContainer *, const xAOD::TrackParticleContainer *, const xAOD::TrackParticleContainer *) const
SG::ReadHandleKey< xAOD::EgammaContainer > m_egammaKey
double entries
Definition listroot.cxx:49
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
PhotonContainer_v1 PhotonContainer
Definition of the current "photon container version".
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
EgammaContainer_v1 EgammaContainer
Definition of the current "egamma container version".

◆ finalize()

StatusCode DerivationFramework::EgammaTrackParticleThinning::finalize ( )
overridevirtual

Definition at line 87 of file EgammaTrackParticleThinning.cxx.

88{
89 ATH_MSG_INFO("Selected " << m_nSelEgammas <<" out of " << m_nEgammas
90 << " objects from " << m_egammaKey.key());
91 ATH_MSG_INFO("Kept " << m_nGSFPass << " out of " << m_ntotGSF
92 << " objects from " << m_gsfSGKey.key());
93 if (!m_gsfVtxSGKey.empty()) {
94 ATH_MSG_INFO("Kept " << m_nGSFVtxPass << " out of " << m_ntotGSFVtx
95 << " vertices from " << m_gsfVtxSGKey.key());
96 }
97 if (!m_inDetSGKey.empty()) {
98 ATH_MSG_INFO("Kept " << m_npass << "out of " << m_ntot << " objects from "
99 << m_inDetSGKey.key());
100 }
101
102 ATH_CHECK(finalizeParser());
103 return StatusCode::SUCCESS;
104}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode DerivationFramework::EgammaTrackParticleThinning::initialize ( )
overridevirtual

Definition at line 35 of file EgammaTrackParticleThinning.cxx.

36{
37 // Decide which collections need to be checked for ID TrackParticles
38 ATH_CHECK(m_egammaKey.initialize());
39
41 ATH_MSG_INFO("Using " << m_gsfSGKey.key()
42 << " as the source collection for GSF track particles");
43 ATH_MSG_INFO((m_bestMatchOnly ? "Best match " : "ALL ")
44 << "GSF track particles associated with objects in "
45 << m_egammaKey.key() << '\n'
46 << " will be marked as kept true in the ThinningHandle "
47 << "otherwise as kept false");
48
49 ATH_CHECK(m_inDetSGKey.initialize(m_streamName, !m_inDetSGKey.empty()));
50 if (!m_inDetSGKey.empty()) {
52 "Using "
53 << m_inDetSGKey.key()
54 << " as the source collection for inner detector track particles");
55
56 ATH_MSG_INFO("Inner detector track particles refitted to produce"
57 << m_gsfSGKey.key() << '\n'
58 << " will be retained when the corresponding "
59 << m_gsfSGKey.key() << " track particle will be retained");
60 if (m_coneSize > 0) {
62 "Inner detector track particles in a cone dr "
63 << m_coneSize << " around the " << m_egammaKey.key() << '\n'
64 << " obects will be marked as kept true in the ThinningHandle "
65 << "otherwise as kept false");
66 }
67 }
68
70 if (!m_gsfVtxSGKey.empty()) {
71 ATH_MSG_INFO("Using " << m_gsfVtxSGKey.key()
72 << " as the source collection for GSF conversion vertices");
73 ATH_MSG_INFO((m_bestVtxMatchOnly ? "Best match " : "ALL ")
74 << " GSF conversion vertices will be kept");
75 }
76
77 // Set up the text-parsing machinery for selectiong the objects directly
78 // according to user cuts
79 if (!m_selectionString.empty()) {
80 ATH_CHECK(initializeParser(m_selectionString));
81 }
82
83 return StatusCode::SUCCESS;
84}

◆ setElectronMasks()

void DerivationFramework::EgammaTrackParticleThinning::setElectronMasks ( std::vector< bool > & mask,
std::vector< bool > & gsfMask,
const xAOD::EgammaContainer * egammas,
const xAOD::TrackParticleContainer * tps,
const xAOD::TrackParticleContainer * gsfs ) const
private

Definition at line 324 of file EgammaTrackParticleThinning.cxx.

330{
331 DerivationFramework::TracksInCone trIC;
332 for (const auto *egamma : *egammas) {
333 const xAOD::Electron* electron =
335 ? static_cast<const xAOD::Electron*>(egamma)
336 : nullptr;
337
338 if (!electron) {
339 ATH_MSG_ERROR("Did not get an electron object in "
340 "EgammaTrackParticleThinning::setElectronMasks");
341 return;
342 }
343 if (tps && m_coneSize > 0.0)
344 trIC.select(electron,
346 tps,
347 mask); // check InDet tracks in a cone around the e-gammas
348
349 unsigned int nGSFLinks = m_bestMatchOnly ? 1 : electron->nTrackParticles();
350 for (unsigned int i = 0; i < nGSFLinks; ++i) {
351 if (!(electron->trackParticleLink(i).isValid())) {
352 continue;
353 }
354 int gsfIndex = electron->trackParticleLink(i).index();
355 gsfMask[gsfIndex] = true;
356 if (tps) {
357 const ElementLink<xAOD::TrackParticleContainer>& origTrackLink =
358 orig(*((*gsfs)[gsfIndex]));
359 if (origTrackLink.isValid()) {
360 int inDetIndex = origTrackLink.index();
361 mask[inDetIndex] = true;
362 }
363 }
364 }
365 }
366}
@ Electron
The object is an electron.
Definition ObjectType.h:46
Electron_v1 Electron
Definition of the current "egamma version".
void select(const xAOD::IParticle *particle, float coneSize, const xAOD::TrackParticleContainer *tracks, std::vector< bool > &mask)

◆ setPhotonMasks()

void DerivationFramework::EgammaTrackParticleThinning::setPhotonMasks ( std::vector< bool > & mask,
std::vector< bool > & gsfMask,
const xAOD::EgammaContainer * egammas,
const xAOD::TrackParticleContainer * tps,
const xAOD::TrackParticleContainer * gsfs ) const
private

Definition at line 234 of file EgammaTrackParticleThinning.cxx.

240{
241 if (m_gsfVtxSGKey.empty()) {
242 ATH_MSG_ERROR("Thinning track particles/vertices associated to photons"
243 "but no conversion vertex key provided");
244 return;
245 }
246
247 SG::ThinningHandle<xAOD::VertexContainer> importedGSFConversionVtx(
248 m_gsfVtxSGKey, Gaudi::Hive::currentContext());
249 const xAOD::VertexContainer* gsfVtxs = importedGSFConversionVtx.cptr();
250 unsigned int nGSFVtx = gsfVtxs->size(), n_gsfVtx_pass = 0;
251 std::vector<bool> gsfVtxMask(nGSFVtx,false);
252 m_ntotGSFVtx += nGSFVtx;
253 ATH_MSG_DEBUG("nGSFVtx : " << nGSFVtx);
254
255 DerivationFramework::TracksInCone trIC;
256 for (const auto* egamma : *egammas) {
257 const xAOD::Photon* photon = egamma->type() == xAOD::Type::Photon
258 ? static_cast<const xAOD::Photon*>(egamma)
259 : nullptr;
260 if (!photon) {
261 ATH_MSG_ERROR("Did not get a photon object in "
262 "EgammaTrackParticleThinning::setPhotonMasks");
263 return;
264 }
265 if (tps && m_coneSize > 0.0) {
266 trIC.select(photon, m_coneSize, tps, mask);
267 } // check InDet tracks in a cone around the e-gammas
268
269 std::vector<ElementLink<xAOD::VertexContainer>> vertexLinks =
270 photon->vertexLinks();
271 unsigned int nLinks = vertexLinks.size();
272 if (nLinks == 0) {
273 continue;
274 }
275 if (!m_bestVtxMatchOnly) {
276 for (unsigned int i = 0; i < nLinks; ++i) {
277 if (!(vertexLinks[i])) {
278 continue;
279 }
280 if (!(vertexLinks[i]).isValid()) {
281 continue;
282 }
283 gsfVtxMask[vertexLinks[i].index()] = true;
284 }
285 }
286 if (m_bestMatchOnly) {
287 nLinks = 1;
288 }
289 for (unsigned int i = 0; i < nLinks; ++i) {
290 if (!(vertexLinks[i]).isValid()) {
291 continue;
292 }
293 gsfVtxMask[vertexLinks[i].index()] = true;
294 const xAOD::Vertex* vx = *(vertexLinks[i]);
295 if (!vx) {
296 continue;
297 }
299 for (const auto& link : trackParticleLinks) {
300 if (!link.isValid()) {
301 continue;
302 }
303 gsfMask[link.index()] = true;
304 if (tps) {
305 const ElementLink<xAOD::TrackParticleContainer>& origTrackLink =
306 orig(*((*gsfs)[link.index()]));
307 if (origTrackLink.isValid()) {
308 int inDetIndex = origTrackLink.index();
309 mask[inDetIndex] = true;
310 }
311 }
312 }
313 }
314 }
315 importedGSFConversionVtx.keep(gsfVtxMask);
316 for (bool b : gsfVtxMask) {
317 if (b)
318 ++n_gsfVtx_pass;
319 }
320 m_nGSFVtxPass += n_gsfVtx_pass;
321}
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
const TrackParticleLinks_t & trackParticleLinks() const
Get all the particles associated with the vertex.
@ Photon
The object is a photon.
Definition ObjectType.h:47
std::vector< ElementLink< xAOD::TrackParticleContainer > > trackParticleLinks(const xAOD::TauJet *tau, xAOD::TauJetParameters::TauTrackFlag flag=xAOD::TauJetParameters::TauTrackFlag::classifiedCharged)
Vertex_v1 Vertex
Define the latest version of the vertex class.
Photon_v1 Photon
Definition of the current "egamma version".

Member Data Documentation

◆ m_bestMatchOnly

BooleanProperty DerivationFramework::EgammaTrackParticleThinning::m_bestMatchOnly { this, "BestMatchOnly", true, "" }
private

Definition at line 69 of file EgammaTrackParticleThinning.h.

69{ this, "BestMatchOnly", true, "" };

◆ m_bestVtxMatchOnly

BooleanProperty DerivationFramework::EgammaTrackParticleThinning::m_bestVtxMatchOnly { this, "BestVtxMatchOnly", false, "" }
private

Definition at line 70 of file EgammaTrackParticleThinning.h.

70{ this, "BestVtxMatchOnly", false, "" };

◆ m_coneSize

FloatProperty DerivationFramework::EgammaTrackParticleThinning::m_coneSize { this, "ConeSize", -1.0, "" }
private

Definition at line 71 of file EgammaTrackParticleThinning.h.

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

◆ m_egammaKey

SG::ReadHandleKey<xAOD::EgammaContainer> DerivationFramework::EgammaTrackParticleThinning::m_egammaKey { this, "SGKey", "", "" }
private

Definition at line 56 of file EgammaTrackParticleThinning.h.

56{ this, "SGKey", "", "" };

◆ m_gsfSGKey

SG::ThinningHandleKey<xAOD::TrackParticleContainer> DerivationFramework::EgammaTrackParticleThinning::m_gsfSGKey { this, "GSFTrackParticlesKey", "GSFTrackParticles", "" }
private

Definition at line 62 of file EgammaTrackParticleThinning.h.

62{ this, "GSFTrackParticlesKey", "GSFTrackParticles", "" };

◆ m_gsfVtxSGKey

SG::ThinningHandleKey<xAOD::VertexContainer> DerivationFramework::EgammaTrackParticleThinning::m_gsfVtxSGKey { this, "GSFConversionVerticesKey", "", "" }
private

Definition at line 65 of file EgammaTrackParticleThinning.h.

65{ this, "GSFConversionVerticesKey", "", "" };

◆ m_inDetSGKey

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

Definition at line 59 of file EgammaTrackParticleThinning.h.

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

◆ m_nEgammas

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_nEgammas = 0
mutableprivate

Definition at line 50 of file EgammaTrackParticleThinning.h.

◆ m_nGSFPass

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_nGSFPass = 0
mutableprivate

Definition at line 48 of file EgammaTrackParticleThinning.h.

◆ m_nGSFVtxPass

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_nGSFVtxPass = 0
mutableprivate

Definition at line 49 of file EgammaTrackParticleThinning.h.

◆ m_npass

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_npass = 0
mutableprivate

Definition at line 47 of file EgammaTrackParticleThinning.h.

◆ m_nSelEgammas

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_nSelEgammas = 0
mutableprivate

Definition at line 51 of file EgammaTrackParticleThinning.h.

◆ m_ntot

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_ntot = 0
mutableprivate

Definition at line 44 of file EgammaTrackParticleThinning.h.

◆ m_ntotGSF

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_ntotGSF = 0
mutableprivate

Definition at line 45 of file EgammaTrackParticleThinning.h.

◆ m_ntotGSFVtx

std::atomic<unsigned long int> DerivationFramework::EgammaTrackParticleThinning::m_ntotGSFVtx = 0
mutableprivate

Definition at line 46 of file EgammaTrackParticleThinning.h.

◆ m_selectionString

StringProperty DerivationFramework::EgammaTrackParticleThinning::m_selectionString { this, "SelectionString", "", "" }
private

Definition at line 67 of file EgammaTrackParticleThinning.h.

67{ this, "SelectionString", "", "" };

◆ m_streamName

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

Definition at line 54 of file EgammaTrackParticleThinning.h.

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

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