PrimaryParticleInformation.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file PrimaryParticleInformation.cxx
3 //
4 /// \version $Id: PrimaryParticleInformation.cxx,v 1.5 2012-09-24 15:19:29 brebel Exp $
5 /// \author seligman@nevis.columbia.edu, brebel@fnal.gov
6 ////////////////////////////////////////////////////////////////////////
7 #include "nutools/G4Base/PrimaryParticleInformation.h"
9 
10 namespace g4b{
11 
12  //-------------------------------------------------
13  G4Allocator<PrimaryParticleInformation> PrimaryParticleInformationAllocator;
14 
15  //-------------------------------------------------
17  {
18  if (!IsInMCTruth()) return nullptr;
19  auto const* truth = GetMCTruth();
20  if (!truth) return nullptr;
21  auto const index = MCParticleIndex();
22  if (index >= (std::size_t) truth->NParticles()) return nullptr; // or should we throw?
23  return &(truth->GetParticle(index));
24  } // PrimaryParticleInformation::GetMCParticle()
25 
26 
27  //-------------------------------------------------
29  {
30  if ( fMCTruth )
31  std::cout << *fMCTruth;
32  }
33 
34 }// namespace
const simb::MCTruth * GetMCTruth() const
simb::MCParticle const * GetMCParticle() const
G4Allocator< PrimaryParticleInformation > PrimaryParticleInformationAllocator
basic interface to Geant4 for ART-based software
GeneratedParticleIndex_t MCParticleIndex() const
Returns the index of the corresponding particle in truth record.