ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
iGeant4::ISFTrajectory Class Reference

#include <ISFTrajectory.h>

Inheritance diagram for iGeant4::ISFTrajectory:
Collaboration diagram for iGeant4::ISFTrajectory:

Public Member Functions

 ISFTrajectory ()
 
 ISFTrajectory (const G4Track *aTrack, ISF::ITruthSvc *truthSvc)
 
 ~ISFTrajectory ()
 
void AppendStep (const G4Step *aStep)
 

Private Attributes

ISF::ITruthSvcm_truthRecordSvcQuick
 

Detailed Description

Definition at line 17 of file ISFTrajectory.h.

Constructor & Destructor Documentation

◆ ISFTrajectory() [1/2]

iGeant4::ISFTrajectory::ISFTrajectory ( )

Definition at line 30 of file ISFTrajectory.cxx.

31  : G4Trajectory()
32  , m_truthRecordSvcQuick(nullptr)
33 {
34 }

◆ ISFTrajectory() [2/2]

iGeant4::ISFTrajectory::ISFTrajectory ( const G4Track *  aTrack,
ISF::ITruthSvc truthSvc 
)

Definition at line 36 of file ISFTrajectory.cxx.

38  : G4Trajectory(aTrack)
39  , m_truthRecordSvcQuick(truthSvc)
40 {
41 }

◆ ~ISFTrajectory()

iGeant4::ISFTrajectory::~ISFTrajectory ( )

Definition at line 43 of file ISFTrajectory.cxx.

44 {
45 
46 }

Member Function Documentation

◆ AppendStep()

void iGeant4::ISFTrajectory::AppendStep ( const G4Step *  aStep)

Definition at line 48 of file ISFTrajectory.cxx.

49 {
50 
51  // only use truth service if there are new any secondaries
52  const int numSecondaries = aStep->GetSecondaryInCurrentStep()->size();
53  //const int numSecondaries = aStep->GetNumberOfSecondariesInCurrentStep(); //Once we switch to G4 10.2 or later
54 
55  if (numSecondaries) {
56 
57  G4Track* track=aStep->GetTrack();
58 #ifdef _ISFTRAJECTORY_DEBUG_
59  std::cout << "A new track "
60  << " (trackID " << track->GetTrackID()
61  << "), track pos: "<<track->GetPosition()
62  << ", mom: "<<track->GetMomentum()
63  << ", parentID " << track->GetParentID()
64  << ", numSec="<<numSecondaries<<" is in AppendStep." << std::endl;
65 #endif
66  // OK, there was an interaction. look at the track, if it
67  // is not a secondary (i.e. we have a connected tree) we
68  // apply the MC truth machinery...
69  TrackHelper tHelper(track);
70  if (tHelper.IsSecondary()) {
71 #ifdef _ISFTRAJECTORY_DEBUG_
72  std::cout<<"is secondary, returning"<<std::endl;
73 #endif
74  return;
75  }
76 
77  // get base ISFParticle
79  if (!trackInfo) {
80  G4ExceptionDescription description;
81  description << G4String("AppendStep: ") + "No VTrackInformation associated with G4Track (trackID: "
82  << track->GetTrackID() << ", track pos: "<<track->GetPosition() << ", mom: "<<track->GetMomentum()
83  << ", parentID " << track->GetParentID() << ")";
84  G4Exception("iGeant4::ISFTrajectory", "NoVTrackInformation", FatalException, description);
85  return; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
86  }
87 
88  ISF::ISFParticle* baseIsp = trackInfo->GetBaseISFParticle();
89  if (!baseIsp) {
90  G4ExceptionDescription description;
91  description << G4String("AppendStep: ") + "NULL ISFParticle pointer for current G4Step (trackID "
92  << track->GetTrackID() << ", track pos: "<<track->GetPosition() << ", mom: "<<track->GetMomentum()
93  << ", parentID " << track->GetParentID() << ", numSec="<<numSecondaries << ")";
94  G4Exception("iGeant4::ISFTrajectory", "NoISFParticle", FatalException, description);
95  return; //The G4Exception call above should abort the job, but Coverity does not seem to pick this up.
96  }
97 
98  AtlasDetDescr::AtlasRegion geoID = baseIsp->nextGeoID();
99 
100  auto* atlasG4EvtUserInfo = ISFG4Helper::getAtlasG4EventUserInfo();
101  if (atlasG4EvtUserInfo->GetCurrentGenParticle() &&
102  atlasG4EvtUserInfo->GetCurrentGenParticle()->end_vertex()) {
103  HepMC::GenParticlePtr currentGenParticle = atlasG4EvtUserInfo->GetCurrentGenParticle();
104  G4ExceptionDescription description;
105  description << G4String("AppendStep: ") + "Currently Traced Particle has an end vertex!\n";
106  description << "G4Track Properties: trackID = " << track->GetTrackID()<< ", Step Number = "<<track->GetCurrentStepNumber() << ", parentID = " << track->GetParentID() << ", TrackStatus = " << track->GetTrackStatus() << "\n";
107  description << "G4Step Properties: number of secondaries in the current step: " << aStep->GetSecondaryInCurrentStep()->size() << "\n";
108  description << "currentGenParticle : " << currentGenParticle << ", barcode: " << HepMC::barcode(currentGenParticle) << "\n";
109  description << "currentGenParticle->end_vertex(): " << currentGenParticle->end_vertex() << ", barcode: " << HepMC::barcode(currentGenParticle->end_vertex()) << "\n";
110  description << "ISFParticle (from TrackInformation): " << *baseIsp;
111  HepMC::GenParticlePtr currentTrackInfoGenParticle = trackInfo->GetCurrentGenParticle();
112  if (currentTrackInfoGenParticle) {
113  description << "currentTrackInfoGenParticle : " << currentTrackInfoGenParticle << ", barcode: " << HepMC::barcode(currentTrackInfoGenParticle) << "\n";
114  if (currentTrackInfoGenParticle->end_vertex()) {
115  description << "currentTrackInfoGenParticle->end_vertex(): " << currentTrackInfoGenParticle->end_vertex() << ", barcode: " << HepMC::barcode(currentTrackInfoGenParticle->end_vertex()) << "\n";
116  }
117  else {
118  description << "currentTrackInfoGenParticle has no end_vertex!\n";
119  }
120  }
121  else {
122  description << " trackInfo->GetHepMCParticle() == nullptr \n";
123  }
124  G4Exception("iGeant4::ISFTrajectory", "EndVertexExists", FatalException, description);
125  }
126  iGeant4::Geant4TruthIncident truth(aStep, *baseIsp, geoID, atlasG4EvtUserInfo);
127 
128  if (m_truthRecordSvcQuick) {
130 
131  // read the TrackInformation to determine whether the G4Track was
132  // returned to the ISF in this step
133  if ( trackInfo->GetReturnedToISF()==true ) {
134  // make sure that the TruthBinding of the ISFParticle points to the newest
135  // HepMC::GenParticle instance in case it got updated by the
136  // ITruthSvc::registerTruthIncident call above
137  auto currentGenPart = atlasG4EvtUserInfo->GetCurrentGenParticle();
138  baseIsp->getTruthBinding()->setCurrentGenParticle( currentGenPart );
139  int newBarcode = HepMC::barcode(currentGenPart); // FIXME barcode-based
140  baseIsp->setBarcode( newBarcode ); // FIXME barcode-based
141  baseIsp->setStatus( currentGenPart->status() );
142  int id = HepMC::uniqueID(currentGenPart);
143  baseIsp->setId( id );
144  }
145  }
146  else {
147  G4ExceptionDescription description;
148  description << G4String("AppendStep: ") + "m_truthRecordSvcQuick is NULL!";
149  G4Exception("iGeant4::ISFTrajectory", "NoTruthRecordSvc", FatalException, description);
150  }
151  }
152 
153  G4Trajectory::AppendStep(aStep);
154 }

Member Data Documentation

◆ m_truthRecordSvcQuick

ISF::ITruthSvc* iGeant4::ISFTrajectory::m_truthRecordSvcQuick
private

Definition at line 26 of file ISFTrajectory.h.


The documentation for this class was generated from the following files:
ISF::ITruthSvc::registerTruthIncident
virtual void registerTruthIncident(ITruthIncident &truthincident, bool saveAllChildren=false) const =0
Register a truth incident.
AtlasDetDescr::AtlasRegion
AtlasRegion
Definition: AtlasRegion.h:27
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
ISF::ISFParticle
Definition: ISFParticle.h:42
iGeant4::Geant4TruthIncident
Definition: Geant4TruthIncident.h:44
iGeant4::ISFTrajectory::m_truthRecordSvcQuick
ISF::ITruthSvc * m_truthRecordSvcQuick
Definition: ISFTrajectory.h:26
TrackHelper
Definition: TrackHelper.h:14
ISF::ISFParticle::nextGeoID
AtlasDetDescr::AtlasRegion nextGeoID() const
next geoID the particle will be simulated in
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
iGeant4::ISFG4Helper::getAtlasG4EventUserInfo
static AtlasG4EventUserInfo * getAtlasG4EventUserInfo()
return pointer to current AtlasG4EventUserInfo
Definition: ISFG4Helper.cxx:114
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:109
trackInfo
Definition: TrigInDetUtils.h:13
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
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
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88