ATLAS Offline Software
ISFG4Helper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class header
7 
8 // Geant4 includes
9 #include "G4Track.hh"
10 #include "G4ThreeVector.hh"
11 #include "G4EventManager.hh"
12 #include "G4Event.hh"
13 
14 #include "AtlasHepMC/GenParticle.h"
16 
17 // G4Atlas includes
20 
21 // ISF includes
22 #include "ISF_Event/ISFParticle.h"
23 
24 
25 // ATLAS GeoPrimitves (Amg::Vector3D etc)
27 
28 
32  const ISF::ISFParticle& parent,
33  ISF::TruthBinding* truth)
34 {
35  const G4ThreeVector& g4pos = aTrack.GetPosition();
36  const double gTime = aTrack.GetGlobalTime();
37  const Amg::Vector3D position(g4pos.x(),g4pos.y(),g4pos.z());
38 
39  const G4ThreeVector& g4mom = aTrack.GetMomentum();
40  const Amg::Vector3D momentum(g4mom.x(),g4mom.y(),g4mom.z());
41 
42  const G4ParticleDefinition &particleDefinition = *aTrack.GetDefinition();
43  double mass = particleDefinition.GetPDGMass();
44  double charge = particleDefinition.GetPDGCharge();
45  int pdgID = particleDefinition.GetPDGEncoding();
46 
47  int barcode = (truth && truth->getCurrentGenParticle() ) ? HepMC::barcode(truth->getCurrentGenParticle()) : HepMC::UNDEFINED_ID; // FIXME barcode-based
48  const int id = (truth && truth->getCurrentGenParticle() ) ? HepMC::uniqueID(truth->getCurrentGenParticle()) : HepMC::UNDEFINED_ID;
49  const int status = (truth && truth->getCurrentGenParticle() ) ? truth->getCurrentGenParticle()->status() : 1;
50  ISF::ISFParticle *isp = new ISF::ISFParticle( position,
51  momentum,
52  mass,
53  charge,
54  pdgID,
55  status,
56  gTime,
57  parent,
58  id,
59  barcode, // FIXME barcode-based
60  truth
61  );
62 
63  return isp;
64 }
65 
66 
70 {
71  VTrackInformation* trackInfo = static_cast<VTrackInformation*>(aTrack.GetUserInformation());
72  return trackInfo;
73 }
74 
75 
79  ISF::ISFParticle& baseIsp,
81  HepMC::GenParticlePtr generationZeroGenParticle)
82 {
83  if ( aTrack.GetUserInformation() ) {
84  G4ExceptionDescription description;
85  description << G4String("ISFG4Helper::attachTrackInfoToNewG4Track: ")
86  << "Trying to attach new TrackInformation object to G4Track which already has a TrackUserInformation attached (trackID: "
87  << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
88  << ", parentID " << aTrack.GetParentID() << ")";
89  G4Exception("ISFG4Helper::attachTrackInfoToNewG4Track", "TrackUserInformationAlreadyExists", FatalException, description);
90  return nullptr;
91  }
92 
93  auto* truthBinding = baseIsp.getTruthBinding();
94  if ( !truthBinding ) {
95  G4ExceptionDescription description;
96  description << G4String("ISFG4Helper::attachTrackInfoToNewG4Track: ")
97  << "No TruthBinding present in base ISFParticle (trackID: "
98  << aTrack.GetTrackID() << ", track pos: "<<aTrack.GetPosition() << ", mom: "<<aTrack.GetMomentum()
99  << ", parentID " << aTrack.GetParentID() << ", ISFParticle: "<<baseIsp<<")";
100  G4Exception("ISFG4Helper::attachTrackInfoToNewG4Track", "NoISFTruthBinding", FatalException, description);
101  return nullptr;
102  }
103 
104  TrackInformation *trackInfo = new TrackInformation( generationZeroGenParticle, &baseIsp );
105  trackInfo->SetPrimaryGenParticle( truthBinding->getPrimaryGenParticle() );
106  trackInfo->SetClassification( classification );
107  aTrack.SetUserInformation( trackInfo );
108 
109  return trackInfo;
110 }
111 
115 {
116  return ( static_cast<AtlasG4EventUserInfo*> (G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetUserInformation()) );
117 }
AtlasG4EventUserInfo
This class is attached to G4Event objects as UserInformation. It holds a pointer to the HepMC::GenEve...
Definition: AtlasG4EventUserInfo.h:21
iGeant4::ISFG4Helper::attachTrackInfoToNewG4Track
static TrackInformation * attachTrackInfoToNewG4Track(G4Track &aTrack, ISF::ISFParticle &baseIsp, VTrackInformation::TrackClassification classification, HepMC::GenParticlePtr generationZeroGenParticle=nullptr)
attach a new TrackInformation object to the given new (!) G4Track (the G4Track must not have a UserIn...
Definition: ISFG4Helper.cxx:78
ISF::TruthBinding
Definition: TruthBinding.h:18
ISF::TruthBinding::getCurrentGenParticle
HepMC::GenParticlePtr getCurrentGenParticle()
pointer to the particle in the simulation truth
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
ISF::ISFParticle
Definition: ISFParticle.h:42
GenParticle.h
dqt_zlumi_pandas.mass
mass
Definition: dqt_zlumi_pandas.py:170
GeoPrimitives.h
ISFParticle.h
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
iGeant4::ISFG4Helper::getAtlasG4EventUserInfo
static AtlasG4EventUserInfo * getAtlasG4EventUserInfo()
return pointer to current AtlasG4EventUserInfo
Definition: ISFG4Helper.cxx:114
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:113
test_pyathena.parent
parent
Definition: test_pyathena.py:15
trackInfo
Definition: TrigInDetUtils.h:13
iGeant4::ISFG4Helper::convertG4TrackToISFParticle
static ISF::ISFParticle * convertG4TrackToISFParticle(const G4Track &aTrack, const ISF::ISFParticle &parent, ISF::TruthBinding *truth=nullptr)
convert the given G4Track into an ISFParticle
Definition: ISFG4Helper.cxx:31
TrackInformation
Implementation of VTrackInformation. Instances of this class are attached as UserInformation to G4Tra...
Definition: TrackInformation.h:41
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:55
TrackInformation.h
MagicNumbers.h
charge
double charge(const T &p)
Definition: AtlasPID.h:494
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
AtlasG4EventUserInfo.h
VTrackInformation::TrackClassification
TrackClassification
Definition: VTrackInformation.h:32
merge.status
status
Definition: merge.py:17
ISFG4Helper.h
iGeant4::ISFG4Helper::getISFTrackInfo
static VTrackInformation * getISFTrackInfo(const G4Track &aTrack)
return a valid UserInformation object of the G4Track for use within the ISF
Definition: ISFG4Helper.cxx:69
VTrackInformation
Instances of classes derived from this class are attached as UserInformation to G4Tracks....
Definition: VTrackInformation.h:30
ISF::ISFParticle::getTruthBinding
const TruthBinding * getTruthBinding() const
pointer to the simulation truth - optional, can be 0
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88