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_fwdelisoInts.size()) {
61 ATH_MSG_DEBUG("Initializing forward electrons");
62 ATH_CHECK(initializeIso(runIsoType,
72 }
73
74 if (m_muisoInts.size()) {
75 ATH_MSG_DEBUG("Initializing muons");
76 ATH_CHECK(initializeIso(runIsoType,
86 }
87
88 // Retrieve the tools (there three Calo ones are the same in fact)
89 if (!m_cellIsolationTool.empty() &&
90 runIsoType.find(xAOD::Iso::etcone) != runIsoType.end()) {
92 } else {
93 m_cellIsolationTool.disable();
94 }
95
96 if (!m_topoIsolationTool.empty() &&
97 runIsoType.find(xAOD::Iso::topoetcone) != runIsoType.end()) {
99 } else {
100 m_topoIsolationTool.disable();
101 }
102
103 if (!m_pflowIsolationTool.empty() &&
104 runIsoType.find(xAOD::Iso::neflowisol) != runIsoType.end()) {
106 } else {
107 m_pflowIsolationTool.disable();
108 }
109
110 if (!m_trackIsolationTool.empty() &&
111 runIsoType.find(xAOD::Iso::IsolationFlavour::ptcone) !=
112 runIsoType.end()) {
114 } else {
115 m_trackIsolationTool.disable();
116 }
117
118 // initialise data handles
119 ATH_CHECK(m_cellsKey.initialize(!m_cellIsolationTool.empty()));
120
121 return StatusCode::SUCCESS;
122}
123
124StatusCode
126{
127 ATH_MSG_INFO("Finalizing " << name() << "...");
128
129 return StatusCode::SUCCESS;
130}
131
132StatusCode
133IsolationBuilder::execute(const EventContext& ctx) const
134{
135 ATH_MSG_DEBUG("Executing " << name() << "...");
136
137 // For etcone, needs the cells
138
139 const CaloCellContainer* cellColl = nullptr;
140 if (!m_cellIsolationTool.empty()) {
142 // check is only used for serial running; remove when MT scheduler used
143 if (!cellcoll.isValid()) {
144 ATH_MSG_FATAL("Failed to retrieve cell container: " << m_cellsKey.key());
145 return StatusCode::FAILURE;
146 }
147 cellColl = cellcoll.cptr();
148 }
149 // Compute isolations
150
151 if (m_elCaloIso.size()) {
152 ATH_MSG_DEBUG("About to execute Electron calo iso");
154 }
155 if (m_phCaloIso.size()) {
156 ATH_MSG_DEBUG("About to execute Photon calo iso");
158 }
159 if (m_fwdelCaloIso.size()) {
160 ATH_MSG_DEBUG("About to execute Forward Electron calo iso");
162 }
163 if (m_muCaloIso.size()) {
164 ATH_MSG_DEBUG("About to execute muon calo iso");
166 }
167
168 if (m_elTrackIso.size()) {
169 ATH_MSG_DEBUG("About to execute Electron track iso");
171 }
172 if (m_phTrackIso.size()) {
173 ATH_MSG_DEBUG("About to execute Photon track iso");
175 }
176 if (m_fwdelTrackIso.size()) {
177 ATH_MSG_DEBUG("About to execute forward electron track iso");
179 }
180 if (m_muTrackIso.size()) {
181 ATH_MSG_DEBUG("About to execute Muon track iso");
183 }
184
185 return StatusCode::SUCCESS;
186}
187
188// constructor
190{
191 isoDeco.setOwner(owningAlg);
192 corrBitsetDeco.setOwner(owningAlg);
193}
194
195// declare dependencies
196void
197IsolationBuilder::CaloIsoHelpKey::declare(IDataHandleHolder* owningAlg)
198{
199 isoDeco.declare(owningAlg);
200 owningAlg->declare(corrBitsetDeco);
201
202 for (auto& coreCor : coreCorDeco) {
203 owningAlg->declare(coreCor.second);
204 }
205
206 for (auto& noncoreCor : noncoreCorDeco) {
207 noncoreCor.second.declare(owningAlg);
208 }
209}
210
211// constructor
213{
214 isoDeco.setOwner(owningAlg);
215 isoDecoV.setOwner(owningAlg);
216 corrBitsetDeco.setOwner(owningAlg);
217}
218
219// declare dependencies
220void
222{
223 isoDeco.declare(owningAlg);
224 isoDecoV.declare(owningAlg);
225 owningAlg->declare(corrBitsetDeco);
226
227 for (auto& coreCor : coreCorDeco) {
228 owningAlg->declare(coreCor.second);
229 }
230}
231
232// constructor
236{
237 for (const auto& key : keys.isoDeco) {
238 isoDeco.emplace_back(key);
239 }
240 for (const auto& coreCor : keys.coreCorDeco) {
241 coreCorDeco.emplace(coreCor);
242 }
243 for (const auto& noncoreCor : keys.noncoreCorDeco) {
244 noncoreCorDeco.emplace(
245 noncoreCor.first,
246 std::vector<SG::WriteDecorHandle<xAOD::IParticleContainer, float>>{
247 std::begin(noncoreCor.second), std::end(noncoreCor.second) });
248 }
249}
250
254{
255 for (const auto& key : keys.isoDeco) {
256 isoDeco.emplace_back(key);
257 }
258 for (const auto& key : keys.isoDecoV) {
259 isoDecoV.emplace_back(key);
260 }
261 for (const auto& coreCor : keys.coreCorDeco) {
262 coreCorDeco.emplace(coreCor);
263 }
264}
265
266bool
272
273StatusCode
275 std::set<xAOD::Iso::IsolationFlavour>& runIsoType, // out
276 std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>*
277 caloIsoMap, // out
278 std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>*
279 trackIsoMap, // out
280 const std::string& containerName,
281 const std::vector<std::vector<int>>& isoInts,
282 const std::vector<std::vector<int>>& corInts,
283 const std::vector<std::vector<int>>& corIntsExtra,
284 const std::string& customConfig)
285{
286
287 std::string prefix = containerName + ".";
288
289 for (size_t flavor = 0; flavor < isoInts.size(); flavor++) {
290 // iterate over the flavor (cell, topo, eflow, track
291 // Note: it is a configuration error if different types
292 // are included in one inner vector
293
294 CaloIsoHelpKey cisoH(this);
295 TrackIsoHelpKey tisoH(this);
296
297 // std::vector<SG::AuxElement::Decorator<float>*> Deco;
300
301 for (size_t type = 0; type < isoInts[flavor].size(); type++) {
302 // iterate over the cone sizes for a given flavor.
303 // (also check that the cone sizes really are of the same flavor;
304 // otherwise an error)
305
307 static_cast<xAOD::Iso::IsolationType>(isoInts[flavor][type]);
308 isoFlav = xAOD::Iso::isolationFlavour(isoType);
309 ATH_MSG_DEBUG("Saw isoType " << xAOD::Iso::toString(isoType) << " and isoFlav " << xAOD::Iso::toString(isoFlav));
310 if (oldIsoFlav != xAOD::Iso::numIsolationFlavours &&
311 oldIsoFlav != isoFlav) {
312 ATH_MSG_FATAL("Configuration error: can only have one type of "
313 "isolation in inner vector");
314 return StatusCode::FAILURE;
315 }
316 oldIsoFlav = isoFlav;
317 std::string isoName = prefix + xAOD::Iso::toString(isoType);
318 if (!customConfig.empty()) {
319 isoName += "_" + customConfig;
320 }
321 if (isoFlav == xAOD::Iso::etcone || isoFlav == xAOD::Iso::topoetcone ||
322 isoFlav == xAOD::Iso::neflowisol) {
323 cisoH.isoTypes.push_back(isoType);
324 cisoH.isoDeco.emplace_back(isoName);
325 } else if (isoFlav == xAOD::Iso::ptcone) {
326 tisoH.isoTypes.push_back(isoType);
327 tisoH.isoDeco.emplace_back(isoName);
328 auto coneSize =
329 static_cast<int>(round(100 * xAOD::Iso::coneSize(isoType)));
330 std::string isoNameV = prefix + "ptvarcone" + std::to_string(coneSize);
331 if (!customConfig.empty()) {
332 isoNameV += "_" + customConfig;
333 }
334 tisoH.isoDecoV.emplace_back(isoNameV);
335 } else {
336 ATH_MSG_FATAL("Configuration error: Isolation flavor "
337 << isoFlav << " not supported.");
338 return StatusCode::FAILURE;
339 }
340 }
341
342 // check that there were isolations configured
343 if (isoFlav == xAOD::Iso::numIsolationFlavours) {
344 ATH_MSG_WARNING("The configuration was malformed: an empty inner vector "
345 "was added; ignoring");
346 continue;
347 }
348
350 // Now that the isolations to calculate are determined,
351 // initialize the isolation decorations
352 // and then determine the corrections to apply,
353 // and finally add it to the IsoMap.
355
356 if (isoFlav == xAOD::Iso::etcone || isoFlav == xAOD::Iso::topoetcone ||
357 isoFlav == xAOD::Iso::neflowisol) {
358
359 // let's initialize the decos
360 ATH_MSG_DEBUG("Initializing cisoH.isoDeco");
361 ATH_CHECK(cisoH.isoDeco.initialize());
362
364 flavor, isoFlav, cisoH, corInts, false, prefix, customConfig));
366 flavor, isoFlav, cisoH, corIntsExtra, true, prefix, customConfig));
367 if (caloIsoMap) {
368 caloIsoMap->push_back(std::make_pair(isoFlav, cisoH));
369 } else {
371 "caloIsoMap was nullptr but the configuration attempted to use it");
372 return StatusCode::FAILURE;
373 }
374 } else if (isoFlav == xAOD::Iso::ptcone) {
375
376 // let's initialize the decos
377 ATH_MSG_DEBUG("Initializing tisoH.isoDeco");
378 ATH_CHECK(tisoH.isoDeco.initialize());
379 ATH_MSG_DEBUG("Initializing tisoH.isoDecoV");
380 ATH_CHECK(tisoH.isoDecoV.initialize());
381
383 flavor, isoFlav, tisoH, corInts, false, prefix, customConfig));
385 flavor, isoFlav, tisoH, corIntsExtra, true, prefix, customConfig));
386
387 if (trackIsoMap) {
388 trackIsoMap->push_back(std::make_pair(isoFlav, tisoH));
389 } else {
391 "trackIsoMap was nullptr but the configuration attempted to use it");
392 return StatusCode::FAILURE;
393 }
394 } else {
395 ATH_MSG_WARNING("Isolation flavour "
396 << xAOD::Iso::toCString(isoFlav)
397 << " does not exist ! Check your inputs");
398 }
399 runIsoType.insert(isoFlav);
400 }
401 return StatusCode::SUCCESS;
402}
403
404StatusCode
406 size_t flavor,
408 CaloIsoHelpKey& cisoH,
409 const std::vector<std::vector<int>>& corInts,
410 bool corrsAreExtra,
411 const std::string& prefix,
412 const std::string& customConfig)
413{
414 if (!corrsAreExtra) {
415 std::string bitsetName =
416 prefix + xAOD::Iso::toString(isoFlav) + "CorrBitset";
417 if (!customConfig.empty()) {
418 bitsetName += "_" + customConfig;
419 }
420
421 cisoH.corrBitsetDeco = bitsetName;
422 ATH_MSG_DEBUG("Initializing non extra corr : " << cisoH.corrBitsetDeco.key());
423 ATH_CHECK(cisoH.corrBitsetDeco.initialize());
424 }
425
426 for (size_t corrType = 0; corrType < corInts[flavor].size(); corrType++) {
427 // iterate over the calo isolation corrections
428 const auto cor = static_cast<unsigned int>(corInts[flavor][corrType]);
429 if (!corrsAreExtra)
430 cisoH.CorrList.calobitset.set(cor);
432 static_cast<xAOD::Iso::IsolationCaloCorrection>(cor);
433
434 if (isCoreCor(isoCor)) {
435 std::string isoCorName = prefix;
436 if (isoCor != xAOD::Iso::core57cells) {
437 isoCorName += xAOD::Iso::toString(isoFlav); // since this doesn't depend on the flavor, just have one
438 }
439
440 // a core correction; only store core energy, not the core area
441 isoCorName += xAOD::Iso::toString(isoCor) +
443 if (!customConfig.empty()) {
444 isoCorName += "_" + customConfig;
445 }
446 cisoH.coreCorDeco.emplace(isoCor, isoCorName);
447 cisoH.coreCorDeco[isoCor].setOwner(this);
448 ATH_MSG_DEBUG("initializing " << cisoH.coreCorDeco[isoCor].key());
449 ATH_CHECK(cisoH.coreCorDeco[isoCor].initialize());
450 } else {
451 // noncore correction
453 continue;
454 cisoH.noncoreCorDeco.emplace(
456 auto& vec = cisoH.noncoreCorDeco[isoCor];
457 vec.setOwner(this);
458 for (auto type : cisoH.isoTypes) {
459 std::string corName = prefix + xAOD::Iso::toString(type) +
460 xAOD::Iso::toString(isoCor) + "Correction";
461 if (!customConfig.empty()) {
462 corName += "_" + customConfig;
463 }
464 vec.emplace_back(corName);
465 }
466 ATH_MSG_DEBUG("Initializing " << xAOD::Iso::toString(isoCor)
467 << " Corrections");
468 ATH_CHECK(vec.initialize());
469 }
470 }
471 return StatusCode::SUCCESS;
472}
473
474StatusCode
476 size_t flavor,
478 TrackIsoHelpKey& tisoH,
479 const std::vector<std::vector<int>>& corInts,
480 bool corrsAreExtra,
481 const std::string& prefix,
482 const std::string& customConfig)
483{
484
485 if (!corrsAreExtra) {
486 std::string bitsetName =
487 prefix + xAOD::Iso::toString(isoFlav) + "CorrBitset";
488 if (!customConfig.empty()) {
489 bitsetName += "_" + customConfig;
490 }
491
492 tisoH.corrBitsetDeco = bitsetName;
493 ATH_MSG_DEBUG("Initializing " << tisoH.corrBitsetDeco.key());
494 ATH_CHECK(tisoH.corrBitsetDeco.initialize());
495 }
496
497 for (size_t corrType = 0; corrType < corInts[flavor].size(); corrType++) {
498 const auto cor = static_cast<unsigned int>(corInts[flavor][corrType]);
499 if (!corrsAreExtra)
500 tisoH.CorrList.trackbitset.set(cor);
502 static_cast<xAOD::Iso::IsolationTrackCorrection>(cor);
503
504 // all pt corrections are core type
505 std::string isoCorName = prefix + xAOD::Iso::toString(isoFlav) +
506 xAOD::Iso::toString(isoCor) + "Correction";
507
508 if (!customConfig.empty()) {
509 isoCorName += "_" + customConfig;
510 }
511 tisoH.coreCorDeco.emplace(isoCor, isoCorName);
512 tisoH.coreCorDeco[isoCor].setOwner(this);
513 ATH_MSG_DEBUG("initializing " << tisoH.coreCorDeco[isoCor].key());
514 ATH_CHECK(tisoH.coreCorDeco[isoCor].initialize());
515 }
516 return StatusCode::SUCCESS;
517}
518
519StatusCode
521 const std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>&
522 caloIsoMap,
523 const CaloCellContainer* cellColl) const
524{
525 for (const auto& pr : caloIsoMap) {
526
527 const xAOD::Iso::IsolationFlavour flav = pr.first;
528 const auto& keys = pr.second;
529 CaloIsoHelpHandles handles(keys);
530
531 ATH_MSG_DEBUG("Executing calo iso flavor: " << xAOD::Iso::toString(flav));
532
533 if (handles.isoDeco.empty()) {
534 ATH_MSG_FATAL("Have a CaloIsoHelpHandles with no actual isolations; "
535 "something wrong happened");
536 return StatusCode::FAILURE;
537 }
538 auto& readHandle =
539 handles.isoDeco[0]; // can treat the writeDecorHandle as a read handle;
540
541 if (readHandle.isAvailable()){ // This must be before readHandle.isValid() or else the isValid call
542 // will crash if the deocration already exists
543 ATH_MSG_DEBUG("read (actually a write) handle for " << keys.isoDeco[0].key() << " already exists. "
544 << "Will not recompute." );
545 return StatusCode::SUCCESS;
546 }
547
548 if (!readHandle.isValid()) {
549 ATH_MSG_FATAL("Could not retrieve read handle for "
550 << keys.isoDeco[0].key());
551 return StatusCode::FAILURE;
552 }
553
554 for (const auto *part : *readHandle) {
555 xAOD::CaloIsolation CaloIsoResult;
556 bool successfulCalc = false;
557 if (flav == xAOD::Iso::IsolationFlavour::etcone && cellColl) {
558 successfulCalc = m_cellIsolationTool->caloCellIsolation(
559 CaloIsoResult, *part, keys.isoTypes, keys.CorrList, cellColl);
560 } else if (flav == xAOD::Iso::IsolationFlavour::topoetcone) {
561 successfulCalc = m_topoIsolationTool->caloTopoClusterIsolation(
562 CaloIsoResult, *part, keys.isoTypes, keys.CorrList);
563 } else if (flav == xAOD::Iso::IsolationFlavour::neflowisol) {
564 successfulCalc = m_pflowIsolationTool->neutralEflowIsolation(
565 CaloIsoResult, *part, keys.isoTypes, keys.CorrList);
566 }
567
568 if (successfulCalc) {
569 for (unsigned int i = 0; i < keys.isoTypes.size(); i++) {
570 float iso = CaloIsoResult.etcones[i];
571 ATH_MSG_DEBUG("custom Iso " << xAOD::Iso::toCString(keys.isoTypes[i])
572 << " = " << iso / 1e3);
573 (handles.isoDeco[i])(*part) = iso;
574 }
575 // corrections
576 (handles.corrBitsetDeco)(*part) = keys.CorrList.calobitset.to_ulong();
577
578 // let's do the core corrections
579
580 // iterate over the values we want to store
581 for (auto& coreCorDecoPr : handles.coreCorDeco) {
582 // find the matching result
583 auto corIter =
584 CaloIsoResult.coreCorrections.find(coreCorDecoPr.first);
585 if (corIter == CaloIsoResult.coreCorrections.end()) {
586 ATH_MSG_FATAL("Could not find core correction of required type: "
587 << xAOD::Iso::toCString(coreCorDecoPr.first));
588 ATH_MSG_FATAL("Check configuration");
589 return StatusCode::FAILURE;
590 }
591 // now that we have the match, let's find the energy
593 float>::const_iterator it =
594 corIter->second.find(xAOD::Iso::coreEnergy);
595 if (it == corIter->second.end()) {
596 ATH_MSG_FATAL("Could not find coreEnergy correction for: "
597 << xAOD::Iso::toCString(coreCorDecoPr.first));
598 ATH_MSG_FATAL("Check configuration");
599 return StatusCode::FAILURE;
600 }
601 ATH_MSG_DEBUG("About to write core correction: "
602 << xAOD::Iso::toCString(coreCorDecoPr.first));
603 (coreCorDecoPr.second)(*part) = it->second;
604 }
605
606 // let's do the noncore corrections
607 for (auto& noncoreCorDecoPr : handles.noncoreCorDeco) {
608 // find the matching result
609 auto corIter =
610 CaloIsoResult.noncoreCorrections.find(noncoreCorDecoPr.first);
611 if (corIter == CaloIsoResult.noncoreCorrections.end()) {
612 ATH_MSG_FATAL("Could not find noncore correction of required type: "
613 << xAOD::Iso::toCString(noncoreCorDecoPr.first));
614 ATH_MSG_FATAL("Check configuration");
615 return StatusCode::FAILURE;
616 }
617
618 ATH_MSG_DEBUG("About to write noncore correction: "
619 << xAOD::Iso::toCString(noncoreCorDecoPr.first));
620 auto& vecHandles = noncoreCorDecoPr.second;
621 for (size_t i = 0; i < vecHandles.size(); i++) {
622 (vecHandles[i])(*part) = corIter->second[i];
623 }
624 }
625 } else {
626 ATH_MSG_FATAL("Call to CaloIsolationTool failed for flavor "
627 << xAOD::Iso::toCString(flav));
628 return StatusCode::FAILURE;
629 }
630 }
631 }
632 return StatusCode::SUCCESS;
633}
634
635StatusCode
637 const std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>&
638 trackIsoMap) const
639{
640 for (const auto& pr : trackIsoMap) {
641 const xAOD::Iso::IsolationFlavour flav = pr.first;
642 const auto& keys = pr.second;
643 TrackIsoHelpHandles handles(keys);
644
645 ATH_MSG_DEBUG("Executing track iso flavor: " << xAOD::Iso::toString(flav));
646
647 if (handles.isoDeco.empty()) {
648 ATH_MSG_FATAL("Have a TrackIsoHelpHandles with no actual isolations; "
649 "something wrong happened");
650 return StatusCode::FAILURE;
651 }
652 auto& readHandle =
653 handles.isoDeco[0]; // can treat the writeDecorHandle as a read handle;
654
655 if (readHandle.isAvailable()){ // This must be before readHandle.isValid() or else the isValid call
656 // will crash if the deocration already exists
657 ATH_MSG_DEBUG("Decoration for for " << keys.isoDeco[0].key() << " already exists. "
658 << "Will not recompute." );
659 return StatusCode::SUCCESS;
660 }
661
662 if (!readHandle.isValid()) {
663 ATH_MSG_FATAL("Could not retrieve read handle for "
664 << keys.isoDeco[0].key());
665 return StatusCode::FAILURE;
666 }
667
668 for (const auto *part : *readHandle) {
669 xAOD::TrackIsolation TrackIsoResult;
670 bool successfulCalc = false;
671 // check to see if we are dealing with an electron
672 const auto * eg = dynamic_cast<const xAOD::Egamma*>(part);
673 if (eg) {
674 ATH_MSG_DEBUG("Doing track isolation on an egamma particle");
675 std::unique_ptr<xAOD::Vertex> trigVtx = nullptr;
676 std::set<const xAOD::TrackParticle*> tracksToExclude;
678 tracksToExclude =
680 if (m_isTrigger) {
681 const xAOD::Electron* el = static_cast<const xAOD::Electron*>(part);
682 trigVtx = std::make_unique<xAOD::Vertex>();
683 trigVtx->makePrivateStore();
684 trigVtx->setZ(el->trackParticle()->z0() + el->trackParticle()->vz());
685 ATH_MSG_DEBUG("will use a vertex at z = " << trigVtx->z() << " to compute electron track isolation");
686 }
687 } else {
688 if (m_allTrackRemoval) { // New (from ??/??/16) : now this gives all
689 // tracks
690 tracksToExclude =
692 } else { // this is just to be able to have the 2015+2016 default case
693 // (only tracks from first vertex)
694 const auto * gam = dynamic_cast<const xAOD::Photon*>(eg);
695 if (gam && gam->nVertices() > 0) {
696 const xAOD::Vertex* phvtx = gam->vertex(0);
697 for (unsigned int itk = 0; itk < phvtx->nTrackParticles(); itk++)
698 tracksToExclude.insert(
701 phvtx->trackParticle(itk))
702 : phvtx->trackParticle(itk));
703 }
704 }
705 }
706 successfulCalc = m_trackIsolationTool->trackIsolation(TrackIsoResult,
707 *part,
708 keys.isoTypes,
709 keys.CorrList,
710 trigVtx.get(),
711 &tracksToExclude);
712 } else {
713 ATH_MSG_DEBUG("Not doing track isolation on an egamma particle");
714 successfulCalc = m_trackIsolationTool->trackIsolation(
715 TrackIsoResult, *part, keys.isoTypes, keys.CorrList);
716 }
717
718 if (successfulCalc) {
719 for (unsigned int i = 0; i < keys.isoTypes.size(); i++) {
720 float iso = TrackIsoResult.ptcones[i];
721 float isoV = TrackIsoResult.ptvarcones_10GeVDivPt[i];
722 ATH_MSG_DEBUG("custom Iso " << xAOD::Iso::toCString(keys.isoTypes[i])
723 << " = " << iso / 1e3
724 << ", var cone = " << isoV / 1e3);
725 (handles.isoDeco[i])(*part) = iso;
726 (handles.isoDecoV[i])(*part) = isoV;
727 }
728
729 // corrections
730 (handles.corrBitsetDeco)(*part) = keys.CorrList.trackbitset.to_ulong();
731 // let's do the core corrections
732 // iterate over the values we want to store
733 for (auto& coreCorDecoPr : handles.coreCorDeco) {
734 // find the matching result
735 auto corIter =
736 TrackIsoResult.coreCorrections.find(coreCorDecoPr.first);
737 if (corIter == TrackIsoResult.coreCorrections.end()) {
738 ATH_MSG_FATAL("Could not find core correction of required type: "
739 << xAOD::Iso::toCString(coreCorDecoPr.first));
740 ATH_MSG_FATAL("Check configuration");
741 return StatusCode::FAILURE;
742 }
743 ATH_MSG_DEBUG("About to write tracking core correction: "
744 << xAOD::Iso::toCString(coreCorDecoPr.first));
745 (coreCorDecoPr.second)(*part) = corIter->second;
746 }
747
748 } else {
749 ATH_MSG_FATAL("Call to TrackIsolationTool failed for flavor "
750 << xAOD::Iso::toCString(flav));
751 return StatusCode::FAILURE;
752 }
753 }
754 }
755 return StatusCode::SUCCESS;
756}
757
758void
760 std::vector<std::pair<xAOD::Iso::IsolationFlavour, CaloIsoHelpKey>>& caloIso)
761{
762 for (auto& iso : caloIso) {
763 iso.second.declare(this);
764 }
765}
766
767void
769 std::vector<std::pair<xAOD::Iso::IsolationFlavour, TrackIsoHelpKey>>&
770 trackIso)
771{
772 for (auto& iso : trackIso) {
773 iso.second.declare(this);
774 }
775}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(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::vector< std::vector< int > > > m_fwdelisoInts
Gaudi::Property< std::string > m_customConfigFwd
IsolationBuilder()
Default constructor:
virtual ~IsolationBuilder()
Destructor:
Gaudi::Property< std::vector< std::vector< int > > > m_fwdelcorIntsExtra
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
std::vector< std::pair< xAOD::Iso::IsolationFlavour, CaloIsoHelpKey > > m_fwdelCaloIso
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< bool > m_useBremAssoc
std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > m_phTrackIso
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
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)
std::vector< std::pair< xAOD::Iso::IsolationFlavour, TrackIsoHelpKey > > m_fwdelTrackIso
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
Gaudi::Property< std::vector< std::vector< int > > > m_fwdelcorInts
ToolHandle< xAOD::ITrackIsolationTool > m_trackIsolationTool
Tool for neutral pflow isolation calculation.
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
bool isFwdElectron(const xAOD::Egamma *eg)
is the object a Fwd electron
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