ATLAS Offline Software
RecordingEnvelope.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
6 #include "RecordingEnvelope.h"
7 
8 // Athena headers
9 #include "MCTruth/TrackHelper.h"
10 
11 //G4 headers
12 #include "G4PhysicalVolumeStore.hh"
13 #include "G4Step.hh"
14 #include "G4TransportationManager.hh"
15 #include "G4VPhysicalVolume.hh"
16 #include "G4VSolid.hh"
17 
18 
19 RecordingEnvelope::RecordingEnvelope(const std::string& envelopeVolumeName, const std::string& trackRecordCollectionName):
20  m_level(-1),
21  m_logicalVolume(nullptr),
22  m_envelopeVolumeName(envelopeVolumeName),
23  m_trackRecordCollection(trackRecordCollectionName)
24 {
25 
26 }
27 
29 {
30 
31 }
32 
33 bool RecordingEnvelope::checkDaughters(const G4LogicalVolume *possibleParent, const G4VPhysicalVolume *thePhysicalVolume, int& level) const
34 {
35  if (possibleParent->IsDaughter(thePhysicalVolume))
36  {
37  ++level;
38  return true;
39  }
40  // Otherwise Loop over the daughters
41  const G4int nDaughters(possibleParent->GetNoDaughters());
42  for(G4int daughter(0); daughter<nDaughters; ++daughter)
43  {
44  const G4VPhysicalVolume* daughterPhysVol = possibleParent->GetDaughter(daughter);
45  const G4LogicalVolume* daughterLogVol = daughterPhysVol->GetLogicalVolume();
46  if (this->checkDaughters(daughterLogVol, thePhysicalVolume,level))
47  {
48  ++level;
49  return true;
50  }
51  }
52  return false;
53 }
55 {
56  const G4VPhysicalVolume *thePhysicalVolume = G4PhysicalVolumeStore::GetInstance()->GetVolume(m_envelopeVolumeName,false);
57  m_logicalVolume=thePhysicalVolume->GetLogicalVolume();
58  const G4LogicalVolume * logicalWorld = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume()->GetLogicalVolume();
59  m_level=0;
60  return this->checkDaughters(logicalWorld, thePhysicalVolume,m_level);
61 }
62 
64 {
65  if (!m_trackRecordCollection.isValid()) m_trackRecordCollection = std::make_unique<TrackRecordCollection>(m_trackRecordCollection.name());
66  return;
67 }
68 void RecordingEnvelope::AddTrackRecord(const G4Step* aStep)
69 {
70  const std::string pname = aStep->GetTrack()->GetDefinition()->GetParticleName();
71  const int pdgcode = (pname=="geantino") ? 999 : aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
72  TrackHelper trHelp(aStep->GetTrack());
73  const int barcode = trHelp.GetBarcode();
74  const int status = trHelp.GetStatus();
75  const int id = trHelp.GetUniqueID();
76 
77  G4StepPoint *postStep=aStep->GetPostStepPoint();
78  G4ThreeVector pos=postStep->GetPosition();
79  G4ThreeVector mom=postStep->GetMomentum();
80  const double ener=postStep->GetTotalEnergy();
81  const double time=postStep->GetGlobalTime();
82 
83  G4StepPoint *preStep=aStep->GetPreStepPoint();
84  G4VPhysicalVolume *preVol=preStep->GetPhysicalVolume();
85 
86  m_trackRecordCollection->Emplace(pdgcode,status,ener,mom,pos,time,barcode,id,preVol->GetName());
87 
88  return;
89 }
RecordingEnvelope::m_level
int m_level
The number of levels beneath the world that the G4LogicalVolume called m_envelopeVolumeName lies.
Definition: RecordingEnvelope.h:69
RecordingEnvelope::BeginOfEvent
void BeginOfEvent()
Called at the start of each G4 event.
Definition: RecordingEnvelope.cxx:63
TrackHelper::GetBarcode
int GetBarcode() const
Definition: TrackHelper.cxx:35
RecordingEnvelope::m_trackRecordCollection
SG::WriteHandle< TrackRecordCollection > m_trackRecordCollection
WriteHandle to the TrackRecordCollection used by this envelope.
Definition: RecordingEnvelope.h:80
TrackHelper.h
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
TrackHelper
Definition: TrackHelper.h:14
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
RecordingEnvelope::checkDaughters
bool checkDaughters(const G4LogicalVolume *possibleParent, const G4VPhysicalVolume *thePhysicalVolume, int &level) const
Recursively called method used to hunt for the G4LogicalVolume associated with this recording envelop...
Definition: RecordingEnvelope.cxx:33
HepMC::barcode
int barcode(const T *p)
Definition: Barcode.h:16
RecordingEnvelope::~RecordingEnvelope
~RecordingEnvelope()
Destructor.
Definition: RecordingEnvelope.cxx:28
RecordingEnvelope::m_logicalVolume
G4LogicalVolume * m_logicalVolume
Pointer to the G4LogicalVolume used by this recording envelope.
Definition: RecordingEnvelope.h:74
RecordingEnvelope::RecordingEnvelope
RecordingEnvelope(const std::string &envelopeVolumeName, const std::string &trackRecordCollectionName)
Constructor.
Definition: RecordingEnvelope.cxx:19
TrackHelper::GetStatus
int GetStatus() const
Definition: TrackHelper.cxx:47
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
RecordingEnvelope::m_envelopeVolumeName
const std::string m_envelopeVolumeName
Name of the G4LogicalVolume used by this recording envelope.
Definition: RecordingEnvelope.h:77
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
RecordingEnvelope::Initialize
bool Initialize()
Finds the pointer to the G4LogicalVolume called m_envelopeVolumeName and the number of levels beneath...
Definition: RecordingEnvelope.cxx:54
RecordingEnvelope.h
merge.status
status
Definition: merge.py:17
TrackHelper::GetUniqueID
int GetUniqueID() const
Definition: TrackHelper.cxx:41
RecordingEnvelope::AddTrackRecord
void AddTrackRecord(const G4Step *aStep)
Add a TrackRecord to the TrackRecordCollection owned by this recording envelope based on the informat...
Definition: RecordingEnvelope.cxx:68