ATLAS Offline Software
InDetReconstructableSelector.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 // InDetReconstructableSelector.cxx
7 // Source file for class InDetReconstructableSelector
9 // (c) ATLAS Detector software
11 
13 #include "AtlasHepMC/GenVertex.h"
14 #include "CLHEP/Units/SystemOfUnits.h"
15 #include "HepPDT/ParticleData.hh"
16 #include "GaudiKernel/IPartPropSvc.h"
17 #include "AtlasHepMC/GenParticle.h"
20 
22  const IInterface* parent)
24  m_particleDataTable{},
25  m_minPt (1000.),
26  m_maxEta ( 3.0),
27  m_selectPrimariesOnly(false),
28  m_maxRStartPrimary ( 25.0*CLHEP::mm),
29  m_maxZStartPrimary ( 200.0*CLHEP::mm),
30  m_maxRStartAll ( 360.0*CLHEP::mm),
31  m_maxZStartAll (2000.0*CLHEP::mm)
32 
33 {
34  declareInterface<IGenParticleSelector>(this);
35 
36  declareProperty("MinPt", m_minPt);
37  declareProperty("MaxEta", m_maxEta);
38  declareProperty("SelectPrimariesOnly",m_selectPrimariesOnly, "flag to restrict to primaries or not");
39  declareProperty("MaxRStartPrimary", m_maxRStartPrimary, "production vtx r for primaries");
40  declareProperty("MaxZStartPrimary", m_maxZStartPrimary, "production vtx z for primaries");
41  declareProperty("MaxRStartAll", m_maxRStartAll, "production vtx r for all");
42  declareProperty("MaxZStartAll", m_maxZStartAll, "production vtx z for all");
43 }
44 
49 
50  // get the Particle Properties Service
51  IPartPropSvc* partPropSvc = nullptr;
52  StatusCode sc = service("PartPropSvc", partPropSvc, true);
53  if (sc.isFailure()) {
54  ATH_MSG_FATAL (" Could not initialize Particle Properties Service");
55  return StatusCode::FAILURE;
56  }
57  m_particleDataTable = partPropSvc->PDT();
58 
59  ATH_MSG_INFO ("initialise in " << name());
60  return StatusCode::SUCCESS;
61 }
62 
64  ATH_MSG_INFO ("starting finalize() in " << name());
65  return StatusCode::SUCCESS;
66 }
67 
68 std::vector<HepMC::ConstGenParticlePtr>*
70 
71  if (! SimTracks) return nullptr;
72 
73  std::vector<HepMC::ConstGenParticlePtr>* genSignal =
74  new std::vector<HepMC::ConstGenParticlePtr>;
75 
76  // pile-up: vector of MCEC has more than one entry
77  DataVector<HepMC::GenEvent>::const_iterator itCollision = SimTracks->begin();
78 
79  for( ; itCollision != SimTracks->end(); ++itCollision ) {
80  const HepMC::GenEvent* genEvent = *itCollision;
81 
82  for ( const auto& particle: *genEvent) {
83 
84 
85  // 1) require stable particle from generation or simulation
86  if (!MC::isStable(particle)) continue;
87 
88  if(particle->production_vertex() == nullptr) {
89  ATH_MSG_WARNING ("GenParticle without production vertex - simulation corrupt? ");
90  ATH_MSG_DEBUG ("It's this one: " << particle);
91  continue;
92  } else {
93 
94  // 2) require track inside ID - relaxed definition including decays of neutrals (secondaries)
95  if ( std::abs(particle->production_vertex()->position().perp()) > m_maxRStartAll ||
96  std::abs(particle->production_vertex()->position().z()) > m_maxZStartAll ) continue;
97 
98  // 3) if jobOption, require strict definition of particles from within beam pipe
99  if ( m_selectPrimariesOnly &&
100  ( std::abs(particle->production_vertex()->position().perp()) > m_maxRStartPrimary ||
101  std::abs(particle->production_vertex()->position().z()) > m_maxZStartPrimary ) ) continue;
102 
103  int pdgCode = particle->pdg_id();
104  if (MC::isNucleus(pdgCode)) continue; // ignore nuclei from hadronic interactions
105  const HepPDT::ParticleData* pd = m_particleDataTable->particle(std::abs(pdgCode));
106 
107  if (!pd) { // nuclei excluded, still problems with a given type?
108  ATH_MSG_INFO ("Could not get particle data for particle "<< particle);
109  continue;
110  }
111  float charge = pd->charge();
112  if (std::abs(charge)<0.5) continue;
113 
114  if (std::abs(particle->momentum().perp()) > m_minPt && std::abs(particle->momentum().pseudoRapidity()) < m_maxEta ) {
115  genSignal->push_back(particle);
116  }
117  }
118  } // loop and select particles
119  } // loop and select pile-up vertices
120  return genSignal;
121 }
122 
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
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Trk::InDetReconstructableSelector::finalize
virtual StatusCode finalize()
Definition: InDetReconstructableSelector.cxx:63
InDetReconstructableSelector.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
charge
double charge(const T &p)
Definition: AtlasPID.h:494
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
Trk::InDetReconstructableSelector::InDetReconstructableSelector
InDetReconstructableSelector(const std::string &type, const std::string &name, const IInterface *parent)
Definition: InDetReconstructableSelector.cxx:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
Trk::InDetReconstructableSelector::selectGenSignal
virtual std::vector< HepMC::ConstGenParticlePtr > * selectGenSignal(const McEventCollection *) const
main method performing the genparticle selection; it works on the entire collection.
Definition: InDetReconstructableSelector.cxx:69
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::InDetReconstructableSelector::initialize
virtual StatusCode initialize()
initialize
Definition: InDetReconstructableSelector.cxx:48