ATLAS Offline Software
Loading...
Searching...
No Matches
IsolationBuilder.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7// IsolationBuilder.cxx
8// Implementation file for class IsolationBuilder
10
11// Isolation includes
12#include "IsolationBuilder.h"
13#include "xAODEgamma/Egamma.h"
15#include "xAODEgamma/Photon.h"
16#include "xAODEgamma/Electron.h"
17
18IsolationBuilder::IsolationBuilder(const std::string& name,
19 ISvcLocator* pSvcLocator)
20 : ::AthReentrantAlgorithm(name, pSvcLocator)
21{}
22
24
25StatusCode
27{
28 ATH_MSG_INFO("Initializing " << name() << "...");
29
30 std::set<xAOD::Iso::IsolationFlavour> runIsoType;
31
32 if (m_elisoInts.size()) {
33 ATH_MSG_DEBUG("Initializing central electrons");
34 ATH_CHECK(initializeIso(runIsoType,
44 }
45
46 if (m_phisoInts.size()) {
47 ATH_MSG_DEBUG("Initializing central photons");
48 ATH_CHECK(initializeIso(runIsoType,
58 }
59
60 if (m_feisoInts.size()) {
61 ATH_MSG_DEBUG("Initializing forward electrons");
62 ATH_CHECK(initializeIso(runIsoType,
64 nullptr,
71 }
72
73 if (m_muisoInts.size()) {
74 ATH_MSG_DEBUG("Initializing muons");
75 ATH_CHECK(initializeIso(runIsoType,
85 }
86
87 // Retrieve the tools (there three Calo ones are the same in fact)
88 if (!m_cellIsolationTool.empty() &&
89 runIsoType.find(xAOD::Iso::etcone) != runIsoType.end()) {
91 } else {
92 m_cellIsolationTool.disable();
93 }
94
95 if (!m_topoIsolationTool.empty() &&
96 runIsoType.find(xAOD::Iso::topoetcone) != runIsoType.end()) {
98 } else {
99 m_topoIsolationTool.disable();
100 }
101
102 if (!m_pflowIsolationTool.empty() &&
103 runIsoType.find(xAOD::Iso::neflowisol) != runIsoType.end()) {
105 } else {
106 m_pflowIsolationTool.disable();
107 }
108
109 if (!m_trackIsolationTool.empty() &&
110 runIsoType.find(xAOD::Iso::IsolationFlavour::ptcone) !=
111 runIsoType.end()) {
113 } else {
114 m_trackIsolationTool.disable();
115 }
116
117 // initialise data handles
118 ATH_CHECK(m_cellsKey.initialize(!m_cellIsolationTool.empty()));
119
120 return StatusCode::SUCCESS;
121}
122
123StatusCode
125{
126 ATH_MSG_INFO("Finalizing " << name() << "...");
127
128 return StatusCode::SUCCESS;
129}
130
131StatusCode
132IsolationBuilder::execute(const EventContext& ctx) const
133{
134 ATH_MSG_DEBUG("Executing " << name() << "...");
135
136 // For etcone, needs the cells
137
138 const CaloCellContainer* cellColl = nullptr;
139 if (!m_cellIsolationTool.empty()) {
141 // check is only used for serial running; remove when MT scheduler used
142 if (!cellcoll.isValid()) {
143 ATH_MSG_FATAL("Failed to retrieve cell container: " << m_cellsKey.key());
144 return StatusCode::FAILURE;
145 }
146 cellColl = cellcoll.cptr();
147 }
148 // Compute isolations
149
150 if (m_elCaloIso.size()) {
151 ATH_MSG_DEBUG("About to execute Electron calo iso");
153 }
154 if (m_phCaloIso.size()) {
155 ATH_MSG_DEBUG("About to execute Photon calo iso");
157 }
158 if (m_feCaloIso.size()) {
159 ATH_MSG_DEBUG("About to execute Forward Electron calo iso");
161 }
162 if (m_muCaloIso.size()) {
163 ATH_MSG_DEBUG("About to execute muon calo iso");
165 }
166
167 if (m_elTrackIso.size()) {
168 ATH_MSG_DEBUG("About to execute Electron track iso");
170 }
171 if (m_phTrackIso.size()) {
172 ATH_MSG_DEBUG("About to execute Photon track iso");
174 }
175 if (m_muTrackIso.size()) {
176 ATH_MSG_DEBUG("About to execute Muon track iso");
178 }
179
180 return StatusCode::SUCCESS;
181}
182
183// constructor
185{
186 isoDeco.setOwner(owningAlg);
187 corrBitsetDeco.setOwner(owningAlg);
188}
189
190// declare dependencies
191void
192IsolationBuilder::CaloIsoHelpKey::declare(IDataHandleHolder* owningAlg)
193{
194 isoDeco.declare(owningAlg);
195 owningAlg->declare(corrBitsetDeco);
196
197 for (auto& coreCor : coreCorDeco) {
198 owningAlg->declare(coreCor.second);
199 }
200
201 for (auto& noncoreCor : noncoreCorDeco) {
202 noncoreCor.second.declare(owningAlg);
203 }
204}
205
206// constructor
208{
209 isoDeco.setOwner(owningAlg);
210 isoDecoV.setOwner(owningAlg);
211 corrBitsetDeco.setOwner(owningAlg);
212}
213
214// declare dependencies
215void
217{
218 isoDeco.declare(owningAlg);
219 isoDecoV.declare(owningAlg);
220 owningAlg->declare(corrBitsetDeco);
221
222 for (auto& coreCor : coreCorDeco) {
223 owningAlg->declare(coreCor.second);
224 }
225}
226
227// constructor
231{
232 for (const auto& key : keys.isoDeco) {
233 isoDeco.emplace_back(key);
234 }
235 for (const auto& coreCor : keys.coreCorDeco) {
236 coreCorDeco.emplace(coreCor);
237 }
238 for (const auto& noncoreCor : keys.noncoreCorDeco) {
239 noncoreCorDeco.emplace(
240 noncoreCor.first,
241 std::vector<SG::WriteDecorHandle<xAOD::IParticleContainer, float>>{
242 std::begin(noncoreCor.second), std::end(noncoreCor.second) });
243 }
244}
245
249{
250 for (const auto& key : keys.isoDeco) {
251 isoDeco.emplace_back(key);
252 }
253 for (const auto& key : keys.isoDecoV) {
254 isoDecoV.emplace_back(key);
255 }
256 for (const auto& coreCor : keys.coreCorDeco) {
257 coreCorDeco.emplace(coreCor);
258 }
259}
260
261bool
267
268StatusCode
270 std::set<xAOD::Iso::IsolationFlavour>& runIsoType, // out
271 std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>*
272 caloIsoMap, // out
273 std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>*
274 trackIsoMap, // out
275 const std::string& containerName,
276 const std::vector<std::vector<int>>& isoInts,
277 const std::vector<std::vector<int>>& corInts,
278 const std::vector<std::vector<int>>& corIntsExtra,
279 const std::string& customConfig)
280{
281
282 std::string prefix = containerName + ".";
283
284 for (size_t flavor = 0; flavor < isoInts.size(); flavor++) {
285 // iterate over the flavor (cell, topo, eflow, track
286 // Note: it is a configuration error if different types
287 // are included in one inner vector
288
289 CaloIsoHelpKey cisoH(this);
290 TrackIsoHelpKey tisoH(this);
291
292 // std::vector<SG::AuxElement::Decorator<float>*> Deco;
295
296 for (size_t type = 0; type < isoInts[flavor].size(); type++) {
297 // iterate over the cone sizes for a given flavor.
298 // (also check that the cone sizes really are of the same flavor;
299 // otherwise an error)
300
302 static_cast<xAOD::Iso::IsolationType>(isoInts[flavor][type]);
303 isoFlav = xAOD::Iso::isolationFlavour(isoType);
304 ATH_MSG_DEBUG("Saw isoType " << xAOD::Iso::toString(isoType) << " and isoFlav " << xAOD::Iso::toString(isoFlav));
305 if (oldIsoFlav != xAOD::Iso::numIsolationFlavours &&
306 oldIsoFlav != isoFlav) {
307 ATH_MSG_FATAL("Configuration error: can only have one type of "
308 "isolation in inner vector");
309 return StatusCode::FAILURE;
310 }
311 oldIsoFlav = isoFlav;
312 std::string isoName = prefix + xAOD::Iso::toString(isoType);
313 if (!customConfig.empty()) {
314 isoName += "_" + customConfig;
315 }
316 if (isoFlav == xAOD::Iso::etcone || isoFlav == xAOD::Iso::topoetcone ||
317 isoFlav == xAOD::Iso::neflowisol) {
318 cisoH.isoTypes.push_back(isoType);
319 cisoH.isoDeco.emplace_back(isoName);
320 } else if (isoFlav == xAOD::Iso::ptcone) {
321 tisoH.isoTypes.push_back(isoType);
322 tisoH.isoDeco.emplace_back(isoName);
323 auto coneSize =
324 static_cast<int>(round(100 * xAOD::Iso::coneSize(isoType)));
325 std::string isoNameV = prefix + "ptvarcone" + std::to_string(coneSize);
326 if (!customConfig.empty()) {
327 isoNameV += "_" + customConfig;
328 }
329 tisoH.isoDecoV.emplace_back(isoNameV);
330 } else {
331 ATH_MSG_FATAL("Configuration error: Isolation flavor "
332 << isoFlav << " not supported.");
333 return StatusCode::FAILURE;
334 }
335 }
336
337 // check that there were isolations configured
338 if (isoFlav == xAOD::Iso::numIsolationFlavours) {
339 ATH_MSG_WARNING("The configuration was malformed: an empty inner vector "
340 "was added; ignoring");
341 continue;
342 }
343
345 // Now that the isolations to calculate are determined,
346 // initialize the isolation decorations
347 // and then determine the corrections to apply,
348 // and finally add it to the IsoMap.
350
351 if (isoFlav == xAOD::Iso::etcone || isoFlav == xAOD::Iso::topoetcone ||
352 isoFlav == xAOD::Iso::neflowisol) {
353
354 // let's initialize the decos
355 ATH_MSG_DEBUG("Initializing cisoH.isoDeco");
356 ATH_CHECK(cisoH.isoDeco.initialize());
357
359 flavor, isoFlav, cisoH, corInts, false, prefix, customConfig));
361 flavor, isoFlav, cisoH, corIntsExtra, true, prefix, customConfig));
362
363 if (caloIsoMap) {
364 caloIsoMap->push_back(std::make_pair(isoFlav, cisoH));
365 } else {
367 "caloIsoMap was nullptr but the configuration attempted to use it");
368 return StatusCode::FAILURE;
369 }
370 } else if (isoFlav == xAOD::Iso::ptcone) {
371
372 // let's initialize the decos
373 ATH_MSG_DEBUG("Initializing tisoH.isoDeco");
374 ATH_CHECK(tisoH.isoDeco.initialize());
375 ATH_MSG_DEBUG("Initializing tisoH.isoDecoV");
376 ATH_CHECK(tisoH.isoDecoV.initialize());
377
379 flavor, isoFlav, tisoH, corInts, false, prefix, customConfig));
381 flavor, isoFlav, tisoH, corIntsExtra, true, prefix, customConfig));
382
383 if (trackIsoMap) {
384 trackIsoMap->push_back(std::make_pair(isoFlav, tisoH));
385 } else {
387 "trackIsoMap was nullptr but the configuration attempted to use it");
388 return StatusCode::FAILURE;
389 }
390 } else {
391 ATH_MSG_WARNING("Isolation flavour "
392 << xAOD::Iso::toCString(isoFlav)
393 << " does not exist ! Check your inputs");
394 }
395 runIsoType.insert(isoFlav);
396 }
397 return StatusCode::SUCCESS;
398}
399
400StatusCode
402 size_t flavor,
404 CaloIsoHelpKey& cisoH,
405 const std::vector<std::vector<int>>& corInts,
406 bool corrsAreExtra,
407 const std::string& prefix,
408 const std::string& customConfig)
409{
410
411 if (!corrsAreExtra) {
412 std::string bitsetName =
413 prefix + xAOD::Iso::toString(isoFlav) + "CorrBitset";
414 if (!customConfig.empty()) {
415 bitsetName += "_" + customConfig;
416 }
417
418 cisoH.corrBitsetDeco = bitsetName;
419 ATH_MSG_DEBUG("Initializing non extra corr : " << cisoH.corrBitsetDeco.key());
420 ATH_CHECK(cisoH.corrBitsetDeco.initialize());
421 }
422
423 for (size_t corrType = 0; corrType < corInts[flavor].size(); corrType++) {
424 // iterate over the calo isolation corrections
425 const auto cor = static_cast<unsigned int>(corInts[flavor][corrType]);
426 if (!corrsAreExtra)
427 cisoH.CorrList.calobitset.set(cor);
429 static_cast<xAOD::Iso::IsolationCaloCorrection>(cor);
430
431 if (isCoreCor(isoCor)) {
432 std::string isoCorName = prefix;
433 if (isoCor != xAOD::Iso::core57cells) {
434 isoCorName += xAOD::Iso::toString(isoFlav); // since this doesn't depend on the flavor, just have one
435 }
436
437 // a core correction; only store core energy, not the core area
438 isoCorName += xAOD::Iso::toString(isoCor) +
440 if (!customConfig.empty()) {
441 isoCorName += "_" + customConfig;
442 }
443 cisoH.coreCorDeco.emplace(isoCor, isoCorName);
444 cisoH.coreCorDeco[isoCor].setOwner(this);
445 ATH_MSG_DEBUG("initializing " << cisoH.coreCorDeco[isoCor].key());
446 ATH_CHECK(cisoH.coreCorDeco[isoCor].initialize());
447 } else {
448 // noncore correction
450 continue;
451 cisoH.noncoreCorDeco.emplace(
453 auto& vec = cisoH.noncoreCorDeco[isoCor];
454 vec.setOwner(this);
455 for (auto type : cisoH.isoTypes) {
456 std::string corName = prefix + xAOD::Iso::toString(type) +
457 xAOD::Iso::toString(isoCor) + "Correction";
458 if (!customConfig.empty()) {
459 corName += "_" + customConfig;
460 }
461 vec.emplace_back(corName);
462 }
463 ATH_MSG_DEBUG("Initializing " << xAOD::Iso::toString(isoCor)
464 << " Corrections");
465 ATH_CHECK(vec.initialize());
466 }
467 }
468 return StatusCode::SUCCESS;
469}
470
471StatusCode
473 size_t flavor,
475 TrackIsoHelpKey& tisoH,
476 const std::vector<std::vector<int>>& corInts,
477 bool corrsAreExtra,
478 const std::string& prefix,
479 const std::string& customConfig)
480{
481
482 if (!corrsAreExtra) {
483 std::string bitsetName =
484 prefix + xAOD::Iso::toString(isoFlav) + "CorrBitset";
485 if (!customConfig.empty()) {
486 bitsetName += "_" + customConfig;
487 }
488
489 tisoH.corrBitsetDeco = bitsetName;
490 ATH_MSG_DEBUG("Initializing " << tisoH.corrBitsetDeco.key());
491 ATH_CHECK(tisoH.corrBitsetDeco.initialize());
492 }
493
494 for (size_t corrType = 0; corrType < corInts[flavor].size(); corrType++) {
495 const auto cor = static_cast<unsigned int>(corInts[flavor][corrType]);
496 if (!corrsAreExtra)
497 tisoH.CorrList.trackbitset.set(cor);
499 static_cast<xAOD::Iso::IsolationTrackCorrection>(cor);
500
501 // all pt corrections are core type
502 std::string isoCorName = prefix + xAOD::Iso::toString(isoFlav) +
503 xAOD::Iso::toString(isoCor) + "Correction";
504
505 if (!customConfig.empty()) {
506 isoCorName += "_" + customConfig;
507 }
508 tisoH.coreCorDeco.emplace(isoCor, isoCorName);
509 tisoH.coreCorDeco[isoCor].setOwner(this);
510 ATH_MSG_DEBUG("initializing " << tisoH.coreCorDeco[isoCor].key());
511 ATH_CHECK(tisoH.coreCorDeco[isoCor].initialize());
512 }
513 return StatusCode::SUCCESS;
514}
515
516StatusCode
518 const std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>&
519 caloIsoMap,
520 const CaloCellContainer* cellColl) const
521{
522 for (const auto& pr : caloIsoMap) {
523
524 const xAOD::Iso::IsolationFlavour flav = pr.first;
525 const auto& keys = pr.second;
526 CaloIsoHelpHandles handles(keys);
527
528 ATH_MSG_DEBUG("Executing calo iso flavor: " << xAOD::Iso::toString(flav));
529
530 if (handles.isoDeco.empty()) {
531 ATH_MSG_FATAL("Have a CaloIsoHelpHandles with no actual isolations; "
532 "something wrong happened");
533 return StatusCode::FAILURE;
534 }
535 auto& readHandle =
536 handles.isoDeco[0]; // can treat the writeDecorHandle as a read handle;
537
538 if (readHandle.isAvailable()){ // This must be before readHandle.isValid() or else the isValid call
539 // will crash if the deocration already exists
540 ATH_MSG_DEBUG("read (actually a write) handle for " << keys.isoDeco[0].key() << " already exists. "
541 << "Will not recompute." );
542 return StatusCode::SUCCESS;
543 }
544
545 if (!readHandle.isValid()) {
546 ATH_MSG_FATAL("Could not retrieve read handle for "
547 << keys.isoDeco[0].key());
548 return StatusCode::FAILURE;
549 }
550
551 for (const auto *part : *readHandle) {
552 xAOD::CaloIsolation CaloIsoResult;
553 bool successfulCalc = false;
554 if (flav == xAOD::Iso::IsolationFlavour::etcone && cellColl) {
555 successfulCalc = m_cellIsolationTool->caloCellIsolation(
556 CaloIsoResult, *part, keys.isoTypes, keys.CorrList, cellColl);
557 } else if (flav == xAOD::Iso::IsolationFlavour::topoetcone) {
558 successfulCalc = m_topoIsolationTool->caloTopoClusterIsolation(
559 CaloIsoResult, *part, keys.isoTypes, keys.CorrList);
560 } else if (flav == xAOD::Iso::IsolationFlavour::neflowisol) {
561 successfulCalc = m_pflowIsolationTool->neutralEflowIsolation(
562 CaloIsoResult, *part, keys.isoTypes, keys.CorrList);
563 }
564
565 if (successfulCalc) {
566 for (unsigned int i = 0; i < keys.isoTypes.size(); i++) {
567 float iso = CaloIsoResult.etcones[i];
568 ATH_MSG_DEBUG("custom Iso " << xAOD::Iso::toCString(keys.isoTypes[i])
569 << " = " << iso / 1e3);
570 (handles.isoDeco[i])(*part) = iso;
571 }
572 // corrections
573 (handles.corrBitsetDeco)(*part) = keys.CorrList.calobitset.to_ulong();
574
575 // let's do the core corrections
576
577 // iterate over the values we want to store
578 for (auto& coreCorDecoPr : handles.coreCorDeco) {
579 // find the matching result
580 auto corIter =
581 CaloIsoResult.coreCorrections.find(coreCorDecoPr.first);
582 if (corIter == CaloIsoResult.coreCorrections.end()) {
583 ATH_MSG_FATAL("Could not find core correction of required type: "
584 << xAOD::Iso::toCString(coreCorDecoPr.first));
585 ATH_MSG_FATAL("Check configuration");
586 return StatusCode::FAILURE;
587 }
588 // now that we have the match, let's find the energy
590 float>::const_iterator it =
591 corIter->second.find(xAOD::Iso::coreEnergy);
592 if (it == corIter->second.end()) {
593 ATH_MSG_FATAL("Could not find coreEnergy correction for: "
594 << xAOD::Iso::toCString(coreCorDecoPr.first));
595 ATH_MSG_FATAL("Check configuration");
596 return StatusCode::FAILURE;
597 }
598 ATH_MSG_DEBUG("About to write core correction: "
599 << xAOD::Iso::toCString(coreCorDecoPr.first));
600 (coreCorDecoPr.second)(*part) = it->second;
601 }
602
603 // let's do the noncore corrections
604 for (auto& noncoreCorDecoPr : handles.noncoreCorDeco) {
605 // find the matching result
606 auto corIter =
607 CaloIsoResult.noncoreCorrections.find(noncoreCorDecoPr.first);
608 if (corIter == CaloIsoResult.noncoreCorrections.end()) {
609 ATH_MSG_FATAL("Could not find noncore correction of required type: "
610 << xAOD::Iso::toCString(noncoreCorDecoPr.first));
611 ATH_MSG_FATAL("Check configuration");
612 return StatusCode::FAILURE;
613 }
614
615 ATH_MSG_DEBUG("About to write noncore correction: "
616 << xAOD::Iso::toCString(noncoreCorDecoPr.first));
617 auto& vecHandles = noncoreCorDecoPr.second;
618 for (size_t i = 0; i < vecHandles.size(); i++) {
619 (vecHandles[i])(*part) = corIter->second[i];
620 }
621 }
622 } else {
623 ATH_MSG_FATAL("Call to CaloIsolationTool failed for flavor "
624 << xAOD::Iso::toCString(flav));
625 return StatusCode::FAILURE;
626 }
627 }
628 }
629 return StatusCode::SUCCESS;
630}
631
632StatusCode
634 const std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>&
635 trackIsoMap) const
636{
637 for (const auto& pr : trackIsoMap) {
638 const xAOD::Iso::IsolationFlavour flav = pr.first;
639 const auto& keys = pr.second;
640 TrackIsoHelpHandles handles(keys);
641
642 ATH_MSG_DEBUG("Executing track iso flavor: " << xAOD::Iso::toString(flav));
643
644 if (handles.isoDeco.empty()) {
645 ATH_MSG_FATAL("Have a TrackIsoHelpHandles with no actual isolations; "
646 "something wrong happened");
647 return StatusCode::FAILURE;
648 }
649 auto& readHandle =
650 handles.isoDeco[0]; // can treat the writeDecorHandle as a read handle;
651
652 if (readHandle.isAvailable()){ // This must be before readHandle.isValid() or else the isValid call
653 // will crash if the deocration already exists
654 ATH_MSG_DEBUG("Decoration for for " << keys.isoDeco[0].key() << " already exists. "
655 << "Will not recompute." );
656 return StatusCode::SUCCESS;
657 }
658
659 if (!readHandle.isValid()) {
660 ATH_MSG_FATAL("Could not retrieve read handle for "
661 << keys.isoDeco[0].key());
662 return StatusCode::FAILURE;
663 }
664
665 for (const auto *part : *readHandle) {
666 xAOD::TrackIsolation TrackIsoResult;
667 bool successfulCalc = false;
668 // check to see if we are dealing with an electron
669 const auto * eg = dynamic_cast<const xAOD::Egamma*>(part);
670 if (eg) {
671 ATH_MSG_DEBUG("Doing track isolation on an egamma particle");
672 std::unique_ptr<xAOD::Vertex> trigVtx = nullptr;
673 std::set<const xAOD::TrackParticle*> tracksToExclude;
675 tracksToExclude =
677 if (m_isTrigger) {
678 const xAOD::Electron* el = static_cast<const xAOD::Electron*>(part);
679 trigVtx = std::make_unique<xAOD::Vertex>();
680 trigVtx->makePrivateStore();
681 trigVtx->setZ(el->trackParticle()->z0() + el->trackParticle()->vz());
682 ATH_MSG_DEBUG("will use a vertex at z = " << trigVtx->z() << " to compute electron track isolation");
683 }
684 } else {
685 if (m_allTrackRemoval) { // New (from ??/??/16) : now this gives all
686 // tracks
687 tracksToExclude =
689 } else { // this is just to be able to have the 2015+2016 default case
690 // (only tracks from first vertex)
691 const auto * gam = dynamic_cast<const xAOD::Photon*>(eg);
692 if (gam && gam->nVertices() > 0) {
693 const xAOD::Vertex* phvtx = gam->vertex(0);
694 for (unsigned int itk = 0; itk < phvtx->nTrackParticles(); itk++)
695 tracksToExclude.insert(
698 phvtx->trackParticle(itk))
699 : phvtx->trackParticle(itk));
700 }
701 }
702 }
703 successfulCalc = m_trackIsolationTool->trackIsolation(TrackIsoResult,
704 *part,
705 keys.isoTypes,
706 keys.CorrList,
707 trigVtx.get(),
708 &tracksToExclude);
709 } else {
710 ATH_MSG_DEBUG("Not doing track isolation on an egamma particle");
711 successfulCalc = m_trackIsolationTool->trackIsolation(
712 TrackIsoResult, *part, keys.isoTypes, keys.CorrList);
713 }
714
715 if (successfulCalc) {
716 for (unsigned int i = 0; i < keys.isoTypes.size(); i++) {
717 float iso = TrackIsoResult.ptcones[i];
718 float isoV = TrackIsoResult.ptvarcones_10GeVDivPt[i];
719 ATH_MSG_DEBUG("custom Iso " << xAOD::Iso::toCString(keys.isoTypes[i])
720 << " = " << iso / 1e3
721 << ", var cone = " << isoV / 1e3);
722 (handles.isoDeco[i])(*part) = iso;
723 (handles.isoDecoV[i])(*part) = isoV;
724 }
725
726 // corrections
727 (handles.corrBitsetDeco)(*part) = keys.CorrList.trackbitset.to_ulong();
728 // let's do the core corrections
729 // iterate over the values we want to store
730 for (auto& coreCorDecoPr : handles.coreCorDeco) {
731 // find the matching result
732 auto corIter =
733 TrackIsoResult.coreCorrections.find(coreCorDecoPr.first);
734 if (corIter == TrackIsoResult.coreCorrections.end()) {
735 ATH_MSG_FATAL("Could not find core correction of required type: "
736 << xAOD::Iso::toCString(coreCorDecoPr.first));
737 ATH_MSG_FATAL("Check configuration");
738 return StatusCode::FAILURE;
739 }
740 ATH_MSG_DEBUG("About to write tracking core correction: "
741 << xAOD::Iso::toCString(coreCorDecoPr.first));
742 (coreCorDecoPr.second)(*part) = corIter->second;
743 }
744
745 } else {
746 ATH_MSG_FATAL("Call to TrackIsolationTool failed for flavor "
747 << xAOD::Iso::toCString(flav));
748 return StatusCode::FAILURE;
749 }
750 }
751 }
752 return StatusCode::SUCCESS;
753}
754
755void
757 std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>& caloIso)
758{
759 for (auto& iso : caloIso) {
760 iso.second.declare(this);
761 }
762}
763
764void
766 std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>&
767 trackIso)
768{
769 for (auto& iso : trackIso) {
770 iso.second.declare(this);
771 }
772}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
std::vector< size_t > vec
An algorithm that can be simultaneously executed in multiple threads.
Container class for CaloCell.
void declareIso(std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > &caloIso)
Gaudi::Property< std::string > m_ElectronContainerName
Containers (Is it best to make them as strings? Used by multiple handles)
StatusCode addTrackIsoCorrections(size_t flavor, xAOD::Iso::IsolationFlavour isoFlav, TrackIsoHelpKey &tisoH, const std::vector< std::vector< int > > &corInts, bool corrsAreExtra, const std::string &prefix, const std::string &customConfig)
called by initializeIso
virtual StatusCode initialize() override final
Gaudi::Property< std::string > m_customConfigFwd
IsolationBuilder()
Default constructor:
virtual ~IsolationBuilder()
Destructor:
Gaudi::Property< std::vector< std::vector< int > > > m_elcorIntsExtra
std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > m_elTrackIso
Gaudi::Property< std::string > m_customConfigPh
Gaudi::Property< std::vector< std::vector< int > > > m_phisoInts
Isolation types (for the alg.
ToolHandle< xAOD::INeutralEFlowIsolationTool > m_pflowIsolationTool
Tool for neutral pflow isolation calculation.
Gaudi::Property< std::string > m_customConfigMu
std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > m_muCaloIso
ToolHandle< xAOD::ICaloTopoClusterIsolationTool > m_topoIsolationTool
Tool for topo isolation calculation.
Gaudi::Property< std::vector< std::vector< int > > > m_fecorIntsExtra
Gaudi::Property< bool > m_useBremAssoc
std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > m_phTrackIso
std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > m_feCaloIso
Gaudi::Property< std::vector< std::vector< int > > > m_mucorIntsExtra
Gaudi::Property< std::vector< std::vector< int > > > m_muisoInts
Gaudi::Property< std::vector< std::vector< int > > > m_elisoInts
Isolation types.
std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > m_elCaloIso
StatusCode executeTrackIso(const std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > &trackIsoMap) const
Gaudi::Property< std::vector< std::vector< int > > > m_fecorInts
virtual StatusCode execute(const EventContext &ctx) const override final
StatusCode addCaloIsoCorrections(size_t flavor, xAOD::Iso::IsolationFlavour isoFlav, CaloIsoHelpKey &cisoH, const std::vector< std::vector< int > > &corInts, bool corrsAreExtra, const std::string &prefix, const std::string &customConfig)
called by initializeIso
Gaudi::Property< std::vector< std::vector< int > > > m_mucorInts
Gaudi::Property< std::vector< std::vector< int > > > m_phcorIntsExtra
Gaudi::Property< bool > m_isTrigger
is the alg run at trigger level
Gaudi::Property< std::string > m_FwdElectronContainerName
Gaudi::Property< bool > m_storepileupCorrection
std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > m_muTrackIso
StatusCode initializeIso(std::set< xAOD::Iso::IsolationFlavour > &runIsoType, std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > *caloIsoMap, std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > *trackIsoMap, const std::string &containerName, const std::vector< std::vector< int > > &isoInts, const std::vector< std::vector< int > > &corInts, const std::vector< std::vector< int > > &corIntsExtra, const std::string &customConfig)
called by algorithm initialize per object (electron, photon, forward electron, muon)
ToolHandle< xAOD::ICaloCellIsolationTool > m_cellIsolationTool
Tool for cell isolation calculation.
StatusCode executeCaloIso(const std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > &caloIsoMap, const CaloCellContainer *cellColl) const
Gaudi::Property< std::string > m_MuonContainerName
ToolHandle< xAOD::ITrackIsolationTool > m_trackIsolationTool
Tool for neutral pflow isolation calculation.
Gaudi::Property< std::vector< std::vector< int > > > m_feisoInts
Gaudi::Property< std::string > m_customConfigEl
std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > m_phCaloIso
Gaudi::Property< std::vector< std::vector< int > > > m_elcorInts
SG::ReadHandleKey< CaloCellContainer > m_cellsKey
Cell container.
Gaudi::Property< bool > m_allTrackRemoval
static bool isCoreCor(xAOD::Iso::IsolationCaloCorrection corr)
virtual StatusCode finalize() override final
Gaudi::Property< std::vector< std::vector< int > > > m_phcorInts
Gaudi::Property< std::string > m_PhotonContainerName
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
const TrackParticle * trackParticle(size_t i) const
Get the pointer to a given track that was used in vertex reco.
DecorHandleKeyArray< WriteDecorHandle< T, S >, WriteDecorHandleKey< T >, Gaudi::DataHandle::Writer > WriteDecorHandleKeyArray
std::set< const xAOD::TrackParticle * > getTrackParticles(const xAOD::Egamma *eg, bool useBremAssoc=true, bool allParticles=true)
Return a list of all or only the best TrackParticle associated to the object.
const xAOD::TrackParticle * getOriginalTrackParticleFromGSF(const xAOD::TrackParticle *trkPar)
Helper function for getting the "Original" Track Particle (i.e before GSF) via the GSF Track Particle...
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
IsolationFlavour isolationFlavour(IsolationType type)
convert Isolation Type into Isolation Flavour
IsolationType
Overall enumeration for isolation types in xAOD files.
IsolationFlavour
Enumeration for different ways of calculating isolation in xAOD files.
@ topoetcone
Topo-cluster ET-sum.
@ neflowisol
neutral eflow
@ ptcone
Track isolation.
@ etcone
Calorimeter isolation.
static const char * toCString(IsolationConeSize conesize)
IsolationCaloCorrection
Enumeration for different ways of correcting isolation in xAOD files.
float coneSize(IsolationConeSize type)
convert Isolation Size into cone size
std::string toString(const IsoType &iso)
Vertex_v1 Vertex
Define the latest version of the vertex class.
Egamma_v1 Egamma
Definition of the current "egamma version".
Definition Egamma.h:17
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
std::map< xAOD::Iso::IsolationCaloCorrection, SG::WriteDecorHandle< xAOD::IParticleContainer, float > > coreCorDeco
std::map< xAOD::Iso::IsolationCaloCorrection, std::vector< SG::WriteDecorHandle< xAOD::IParticleContainer, float > > > noncoreCorDeco
SG::WriteDecorHandle< xAOD::IParticleContainer, uint32_t > corrBitsetDeco
std::vector< SG::WriteDecorHandle< xAOD::IParticleContainer, float > > isoDeco
CaloIsoHelpHandles(const CaloIsoHelpKey &keys)
void declare(IDataHandleHolder *owningAlg)
only to be called after placed in the final location, to propagate dependencies
xAOD::CaloCorrection CorrList
to keep track of the corrections
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > isoDeco
The actual isolations.
std::map< xAOD::Iso::IsolationCaloCorrection, SG::WriteDecorHandleKey< xAOD::IParticleContainer > > coreCorDeco
The corrections (one per flavor)
std::vector< xAOD::Iso::IsolationType > isoTypes
the types of isolations to calculate
CaloIsoHelpKey(IDataHandleHolder *owningAlg)
constructor
SG::WriteDecorHandleKey< xAOD::IParticleContainer > corrBitsetDeco
std::map< xAOD::Iso::IsolationCaloCorrection, SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > > noncoreCorDeco
The corrections (one per flavor/type combination)
std::vector< SG::WriteDecorHandle< xAOD::IParticleContainer, float > > isoDecoV
std::map< xAOD::Iso::IsolationTrackCorrection, SG::WriteDecorHandle< xAOD::IParticleContainer, float > > coreCorDeco
TrackIsoHelpHandles(const TrackIsoHelpKey &keys)
SG::WriteDecorHandle< xAOD::IParticleContainer, uint32_t > corrBitsetDeco
std::vector< SG::WriteDecorHandle< xAOD::IParticleContainer, float > > isoDeco
std::vector< xAOD::Iso::IsolationType > isoTypes
the types of isolations to calculate
void declare(IDataHandleHolder *owningAlg)
only to be called after placed in the final location, to propagate dependencies
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > isoDecoV
SG::WriteDecorHandleKeyArray< xAOD::IParticleContainer > isoDeco
The actual isolations.
std::map< xAOD::Iso::IsolationTrackCorrection, SG::WriteDecorHandleKey< xAOD::IParticleContainer > > coreCorDeco
The corrections.
TrackIsoHelpKey(IDataHandleHolder *owningAlg)
constructor
SG::WriteDecorHandleKey< xAOD::IParticleContainer > corrBitsetDeco
xAOD::TrackCorrection CorrList
to keep track of the corrections
Iso::IsolationCaloCorrectionBitset calobitset
std::vector< float > etcones
std::map< Iso::IsolationCaloCorrection, std::vector< float > > noncoreCorrections
std::map< Iso::IsolationCaloCorrection, std::map< Iso::IsolationCorrectionParameter, float > > coreCorrections
Iso::IsolationTrackCorrectionBitset trackbitset
std::vector< float > ptcones
std::vector< float > ptvarcones_10GeVDivPt
std::map< Iso::IsolationTrackCorrection, float > coreCorrections