ATLAS Offline Software
InDetPrimaryConversionSelector.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // InDetPrimaryConversionSelector.cxx
7 // Source file for class InDetPrimaryConversionSelector
9 // (c) ATLAS Detector software
11 
13 #include "AtlasHepMC/GenVertex.h"
14 #include "CLHEP/Geometry/Point3D.h"
15 #include "CLHEP/Units/SystemOfUnits.h"
16 #include "HepPDT/ParticleData.hh"
17 #include "GaudiKernel/IPartPropSvc.h"
18 #include "AtlasHepMC/GenParticle.h"
21 
23  const IInterface* parent)
25  m_particleDataTable{},
26  m_minPt ( 500. ),
27  m_maxEta ( 2.5 ),
28  m_maxRStartAll ( 800.0*CLHEP::mm),
29  m_maxZStartAll (2000.0*CLHEP::mm)
30 
31 {
32  declareInterface<IGenParticleSelector>(this);
33 
34  declareProperty("MinPt", m_minPt);
35  declareProperty("MaxEta", m_maxEta);
36  declareProperty("MaxRStartAll", m_maxRStartAll, "production vtx r for all");
37  declareProperty("MaxZStartAll", m_maxZStartAll, "production vtx z for all");
38 }
39 
44 
45  // get the Particle Properties Service
46  IPartPropSvc* partPropSvc = nullptr;
47  StatusCode sc = service("PartPropSvc", partPropSvc, true);
48  if (sc.isFailure()) {
49  ATH_MSG_FATAL (" Could not initialize Particle Properties Service");
50  return StatusCode::FAILURE;
51  }
52  m_particleDataTable = partPropSvc->PDT();
53 
54  ATH_MSG_INFO ("initialise in " << name());
55  return StatusCode::SUCCESS;
56 }
57 
59  ATH_MSG_INFO ("starting finalize() in " << name());
60  return StatusCode::SUCCESS;
61 }
62 
63 std::vector<HepMC::ConstGenParticlePtr>*
65 
66  if (! SimTracks) return nullptr;
67 
68  std::vector<HepMC::ConstGenParticlePtr>* genSignal =
69  new std::vector<HepMC::ConstGenParticlePtr>;
70  // pile-up: vector of MCEC has more than one entry
71  DataVector<HepMC::GenEvent>::const_iterator itCollision = SimTracks->begin();
72 
73  for( ; itCollision != SimTracks->end(); ++itCollision ) {
74  const HepMC::GenEvent* genEvent = *itCollision;
75 
76  for (const auto& particle: *genEvent) {
77 
78  // 1) require stable particle from generation or simulation
79  if (!MC::isStable(particle)) continue;
80 
81  if(!particle->production_vertex()) {
82  ATH_MSG_WARNING ("GenParticle without production vertex - simulation corrupt? ");
83  ATH_MSG_DEBUG ("It's this one: " << particle);
84  continue;
85  } else {
86 
87  // 2) require track inside ID - relaxed definition including decays of neutrals (secondaries)
88  if ( std::fabs(particle->production_vertex()->position().perp()) > m_maxRStartAll ||
89  std::fabs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue;
90 
91  int pdgCode = particle->pdg_id();
92  if (MC::isNucleus(pdgCode)) continue; // ignore nuclei from hadronic interactions
93  const HepPDT::ParticleData* pd = m_particleDataTable->particle(abs(pdgCode));
94 
95  if (!pd) { // nuclei excluded, still problems with a given type?
96  ATH_MSG_INFO ("Could not get particle data for particle GenParticle= " << particle);
97  continue;
98  }
99 
100  ATH_MSG_DEBUG ("found particle = " << particle);
101 
102  // assume for the moment we're only running over single gamma MC files ...
103  auto prodVertex = particle->production_vertex();
104  if ( std::abs(pdgCode) == 11 ) {
105  ATH_MSG_DEBUG ("Electron/Positron detected -- checking for production process ...");
106 #ifdef HEPMC3
107  for ( const auto& inParticle: prodVertex->particles_in()) {
108 #else
109  HepMC::GenVertex::particles_in_const_iterator ItinParticle = prodVertex->particles_in_const_begin();
110  HepMC::GenVertex::particles_out_const_iterator ItinParticleEnd = prodVertex->particles_in_const_end();
111  for ( ; ItinParticle != ItinParticleEnd; ++ItinParticle) {
112  auto inParticle=*ItinParticle;
113 #endif
114  ATH_MSG_DEBUG(" --> checking morther: " << inParticle );
115  if ( MC::isPhoton(inParticle) || MC::isElectron(inParticle) ){
116  if (std::fabs(particle->momentum().perp()) > m_minPt && std::fabs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
117  genSignal->push_back(particle);
118  ATH_MSG_DEBUG ("Selected this electron/positron!");
119  break;
120  } // if (particle pt, eta)
121  } // if (mother is gamma wit barcode ...)
122  } // loop over mother particles
123  } // if (have electron/positron)
124  } // if (have stable particle)
125  } // loop and select particles
126  } // loop and select pile-up vertices
127  return genSignal;
128 }
129 
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
isNucleus
bool isNucleus(const T &p)
Definition: AtlasPID.h:212
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GenVertex.h
GenParticle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
McEventCollection.h
Trk::InDetPrimaryConversionSelector::InDetPrimaryConversionSelector
InDetPrimaryConversionSelector(const std::string &type, const std::string &name, const IInterface *parent)
Definition: InDetPrimaryConversionSelector.cxx:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::InDetPrimaryConversionSelector::finalize
virtual StatusCode finalize()
Definition: InDetPrimaryConversionSelector.cxx:58
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:13
test_pyathena.parent
parent
Definition: test_pyathena.py:15
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
InDetPrimaryConversionSelector.h
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:22
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
Trk::InDetPrimaryConversionSelector::selectGenSignal
virtual std::vector< HepMC::ConstGenParticlePtr > * selectGenSignal(const McEventCollection *) const
main method performing the genparticle selection; it works on the entire collection.
Definition: InDetPrimaryConversionSelector.cxx:64
AthAlgTool
Definition: AthAlgTool.h:26
HepMCHelpers.h
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Trk::InDetPrimaryConversionSelector::initialize
virtual StatusCode initialize()
initialize
Definition: InDetPrimaryConversionSelector.cxx:43