ATLAS Offline Software
xAODTruthParticleSlimmerElectron.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("xAODTruthParticleContainerNameElectron", m_xaodTruthParticleContainerNameElectron = "TruthElectrons");
26  declareProperty("xAODTruthEventContainerName", m_xaodTruthEventContainerName = "TruthEvents");
27  declareProperty("el_pt_selection", m_el_pt_selection = 1. * Gaudi::Units::GeV); //User provides units in MeV!
28  declareProperty("abseta_selection", m_abseta_selection = 5.);
29 }
30 
32 {
33  ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName);
34  ATH_MSG_INFO("xAOD output TruthParticleContainerElectron name = " << m_xaodTruthParticleContainerNameElectron);
35  ATH_MSG_INFO("xAOD input xAODTruthEventContainerName name = " << m_xaodTruthEventContainerName);
36  return StatusCode::SUCCESS;
37 }
38 
40 {
41  // If the containers already exists then assume that nothing needs to be done
42  if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNameElectron))
43  {
44  ATH_MSG_WARNING("xAOD Electron Truth Particles are already available in the event");
45  return StatusCode::SUCCESS;
46  }
47 
48  // Create new output container
49  xAOD::TruthParticleContainer *xTruthParticleContainerElectron = new xAOD::TruthParticleContainer();
50  CHECK(evtStore()->record(xTruthParticleContainerElectron, m_xaodTruthParticleContainerNameElectron));
51  xAOD::TruthParticleAuxContainer *xTruthParticleAuxContainerElectron = new xAOD::TruthParticleAuxContainer();
52  CHECK(evtStore()->record(xTruthParticleAuxContainerElectron, m_xaodTruthParticleContainerNameElectron + "Aux."));
53  xTruthParticleContainerElectron->setStore(xTruthParticleAuxContainerElectron);
54  ATH_MSG_INFO("Recorded TruthParticleContainerElectron with key: " << m_xaodTruthParticleContainerNameElectron);
55 
56  // Retrieve full TruthEventContainer container
57  const xAOD::TruthEventContainer *xTruthEventContainer=NULL;
58  if (evtStore()->retrieve(xTruthEventContainer, m_xaodTruthEventContainerName).isFailure())
59  {
60  ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!");
61  return StatusCode::FAILURE;
62  }
63  // Set up decorators if needed
65  for (itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
66 
67  unsigned int nPart = (*itr)->nTruthParticles();
68  std::vector<int> uniqueID_list;
69  int zero_uniqueID=0;
70  int dup_uniqueID=0;
71  for (unsigned int iPart = 0; iPart < nPart; ++iPart) {
72  const xAOD::TruthParticle* theParticle = (*itr)->truthParticle(iPart);
73  int my_uniqueID = HepMC::uniqueID(theParticle);
74  if (my_uniqueID == HepMC::UNDEFINED_ID ) {
75  zero_uniqueID++;
76  continue;
77  }
78  bool found = false;
79  if (uniqueID_list.size() > 0){
80  found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
81  if(found) {
82  dup_uniqueID++;
83  continue;}
84  }
85  uniqueID_list.push_back(my_uniqueID);
86 
87 
88  //Save stable Electrons
89  if (MC::isStable(theParticle) && MC::isElectron(theParticle))
90  {
91  xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
92  xTruthParticleContainerElectron->push_back( xTruthParticle );
93 
94  // Fill with numerical content
95  *xTruthParticle=*theParticle;
96  }
97  }
98  if (zero_uniqueID!=0 || dup_uniqueID!=0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID=0 particles and " << dup_uniqueID <<" duplicated");
99  }
100 
101  return StatusCode::SUCCESS;
102 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
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
xAODTruthParticleSlimmerElectron.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
xAODTruthParticleSlimmerElectron::m_xaodTruthEventContainerName
std::string m_xaodTruthEventContainerName
Definition: xAODTruthParticleSlimmerElectron.h:35
TruthParticleContainer.h
xAODTruthParticleSlimmerElectron::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerElectron.cxx:39
xAODTruthParticleSlimmerElectron::m_abseta_selection
double m_abseta_selection
Definition: xAODTruthParticleSlimmerElectron.h:39
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
xAOD::TruthParticleAuxContainer
TruthParticleAuxContainer_v1 TruthParticleAuxContainer
Declare the latest version of the truth particle auxiliary container.
Definition: TruthParticleAuxContainer.h:15
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::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h: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:116
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
AthAlgorithm
Definition: AthAlgorithm.h:47
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
xAODTruthParticleSlimmerElectron::m_xaodTruthParticleContainerName
std::string m_xaodTruthParticleContainerName
Definition: xAODTruthParticleSlimmerElectron.h:34
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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
xAODTruthParticleSlimmerElectron::m_el_pt_selection
double m_el_pt_selection
Selection values for keeping taus and leptons.
Definition: xAODTruthParticleSlimmerElectron.h:38
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition: HepMCHelpers.h:45
CondAlgsOpts.found
int found
Definition: CondAlgsOpts.py:101
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAODTruthParticleSlimmerElectron::xAODTruthParticleSlimmerElectron
xAODTruthParticleSlimmerElectron(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerElectron.cxx:21
xAODTruthParticleSlimmerElectron::m_xaodTruthParticleContainerNameElectron
std::string m_xaodTruthParticleContainerNameElectron
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerElectron.h:33
TruthParticle.h
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAODTruthParticleSlimmerElectron::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerElectron.cxx:31