ATLAS Offline Software
xAODTruthParticleSlimmerPhoton.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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  declareProperty("xAODTruthParticleContainerName", m_xaodTruthParticleContainerName = "TruthParticles");
25  declareProperty("xAODTruthParticleContainerNamePhoton", m_xaodTruthParticleContainerNamePhoton = "TruthPhotons");
26  declareProperty("xAODTruthEventContainerName", m_xaodTruthEventContainerName = "TruthEvents");
27 }
28 
30 {
31  ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName);
32  ATH_MSG_INFO("xAOD output TruthParticleContainerPhoton name = " << m_xaodTruthParticleContainerNamePhoton);
33  ATH_MSG_INFO("xAOD input xAODTruthEventContainerName name = " << m_xaodTruthEventContainerName);
34  return StatusCode::SUCCESS;
35 }
36 
38 {
39  // If the containers already exists then assume that nothing needs to be done
40  if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNamePhoton))
41  {
42  ATH_MSG_WARNING("xAOD Photon Truth Particles are already available in the event");
43  return StatusCode::SUCCESS;
44  }
45 
46  // Create new output container
47  xAOD::TruthParticleContainer *xTruthParticleContainerPhoton = new xAOD::TruthParticleContainer();
48  CHECK(evtStore()->record(xTruthParticleContainerPhoton, m_xaodTruthParticleContainerNamePhoton));
49  xAOD::TruthParticleAuxContainer *xTruthParticleAuxContainerPhoton = new xAOD::TruthParticleAuxContainer();
50  CHECK(evtStore()->record(xTruthParticleAuxContainerPhoton, m_xaodTruthParticleContainerNamePhoton + "Aux."));
51  xTruthParticleContainerPhoton->setStore(xTruthParticleAuxContainerPhoton);
52  ATH_MSG_INFO("Recorded TruthParticleContainerPhoton with key: " << m_xaodTruthParticleContainerNamePhoton);
53 
54  // Retrieve full TruthEventContainer container
55  const xAOD::TruthEventContainer *xTruthEventContainer=NULL;
56  if (evtStore()->retrieve(xTruthEventContainer, m_xaodTruthEventContainerName).isFailure())
57  {
58  ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!");
59  return StatusCode::FAILURE;
60  }
61  // Set up decorators if needed
63  for (itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
64 
65  std::vector<int> uniqueID_list;
66  int zero_uniqueID=0;
67  int dup_uniqueID = 0;
68 
69  unsigned int nPart = (*itr)->nTruthParticles();
70 
71  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
72  const xAOD::TruthParticle* theParticle = (*itr)->truthParticle(iPart);
73 
74  int my_uniqueID = HepMC::uniqueID(theParticle);
75  if ( my_uniqueID == HepMC::UNDEFINED_ID ) {
76  zero_uniqueID++;
77  continue;
78  }
79  bool found = false;
80  if (uniqueID_list.size() > 0){
81  found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
82  if(found) {
83  dup_uniqueID++;
84  continue;}
85  }
86  uniqueID_list.push_back(my_uniqueID);
87 
88 
89  //Save stable Photons
90  if (MC::isStable(theParticle) && MC::isPhoton(theParticle))
91  {
92  xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
93  xTruthParticleContainerPhoton->push_back( xTruthParticle );
94 
95  // Fill with numerical content
96  *xTruthParticle=*theParticle;
97  }
98  }
99  if (zero_uniqueID != 0 || dup_uniqueID != 0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID zero particles and " <<dup_uniqueID<< " duplicated");
100  }
101 
102  return StatusCode::SUCCESS;
103 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAODTruthParticleSlimmerPhoton::m_xaodTruthParticleContainerName
std::string m_xaodTruthParticleContainerName
Definition: xAODTruthParticleSlimmerPhoton.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
xAODTruthParticleSlimmerPhoton::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerPhoton.cxx:29
xAODTruthParticleSlimmerPhoton::m_xaodTruthParticleContainerNamePhoton
std::string m_xaodTruthParticleContainerNamePhoton
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerPhoton.h:33
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
xAOD::TruthParticleAuxContainer_v1
Auxiliary store for the truth vertices.
Definition: TruthParticleAuxContainer_v1.h:27
xAODTruthParticleSlimmerPhoton.h
xAOD::TruthParticleAuxContainer
TruthParticleAuxContainer_v1 TruthParticleAuxContainer
Declare the latest version of the truth particle auxiliary container.
Definition: TruthParticleAuxContainer.h:16
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:41
xAODTruthParticleSlimmerPhoton::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerPhoton.cxx:37
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:113
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:55
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
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.
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
xAODTruthParticleSlimmerPhoton::xAODTruthParticleSlimmerPhoton
xAODTruthParticleSlimmerPhoton(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerPhoton.cxx:21
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
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
xAODTruthParticleSlimmerPhoton::m_xaodTruthEventContainerName
std::string m_xaodTruthEventContainerName
Definition: xAODTruthParticleSlimmerPhoton.h:35
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.