Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
xAODTruthParticleSlimmerPhoton.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "AthLinks/ElementLink.h"
7 
9 
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/DataSvc.h"
12 #include "GaudiKernel/PhysicalConstants.h"
13 
17 
20 
22  : AthAlgorithm(name, svcLoc)
23 {
24 }
25 
27 {
29  ATH_MSG_INFO("xAOD output TruthParticleContainerPhoton name = " << m_xaodTruthParticleContainerNamePhoton.key());
31  ATH_MSG_INFO("xAOD input xAODTruthEventContainerName name = " << m_xaodTruthEventContainerName.key());
32  return StatusCode::SUCCESS;
33 }
34 
36 {
37  // If the containers already exists then assume that nothing needs to be done
38  if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNamePhoton.key()))
39  {
40  ATH_MSG_WARNING("xAOD Photon Truth Particles are already available in the event");
41  return StatusCode::SUCCESS;
42  }
43 
44  // Create new output container
46  ATH_CHECK(xTruthParticleContainerPhoton.record(std::make_unique<xAOD::TruthParticleContainer>(), std::make_unique<xAOD::TruthParticleAuxContainer>()));
47  ATH_MSG_INFO("Recorded TruthParticleContainerPhoton with key: " << m_xaodTruthParticleContainerNamePhoton.key());
48 
49  // Retrieve full TruthEventContainer container
51  if ( !xTruthEventContainer.isValid() )
52  {
53  ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName.key() << " found in StoreGate!");
54  return StatusCode::FAILURE;
55  }
56  // Set up decorators if needed
58  for (itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
59 
60  std::vector<int> uniqueID_list;
61  int zero_uniqueID=0;
62  int dup_uniqueID = 0;
63 
64  unsigned int nPart = (*itr)->nTruthParticles();
65 
66  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
67  const xAOD::TruthParticle* theParticle = (*itr)->truthParticle(iPart);
68 
69  int my_uniqueID = HepMC::uniqueID(theParticle);
70  if ( my_uniqueID == HepMC::UNDEFINED_ID ) {
71  zero_uniqueID++;
72  continue;
73  }
74  bool found = false;
75  if (uniqueID_list.size() > 0){
76  found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
77  if(found) {
78  dup_uniqueID++;
79  continue;}
80  }
81  uniqueID_list.push_back(my_uniqueID);
82 
83 
84  //Save stable Photons
85  if (MC::isStable(theParticle) && MC::isPhoton(theParticle))
86  {
87  xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
88  xTruthParticleContainerPhoton->push_back( xTruthParticle );
89 
90  // Fill with numerical content
91  *xTruthParticle=*theParticle;
92  }
93  }
94  if (zero_uniqueID != 0 || dup_uniqueID != 0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID zero particles and " <<dup_uniqueID<< " duplicated");
95  }
96 
97  return StatusCode::SUCCESS;
98 }
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
xAODTruthParticleSlimmerPhoton::m_xaodTruthParticleContainerNamePhoton
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNamePhoton
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerPhoton.h:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
TruthParticleContainer.h
xAODTruthParticleSlimmerPhoton::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerPhoton.cxx:26
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
TruthParticleAuxContainer.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
xAODTruthParticleSlimmerPhoton.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAODTruthParticleSlimmerPhoton::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerPhoton.cxx:35
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
xAODTruthParticleSlimmerPhoton::m_xaodTruthEventContainerName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
Definition: xAODTruthParticleSlimmerPhoton.h:34
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
xAODTruthParticleSlimmerPhoton::xAODTruthParticleSlimmerPhoton
xAODTruthParticleSlimmerPhoton(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerPhoton.cxx:21
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
TruthParticle.h
HepMCHelpers.h