ATLAS Offline Software
Loading...
Searching...
No Matches
CosmicPerigeeAction.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//athena headers
9//Geant4 headers
10#include "G4Geantino.hh"
11#include "G4ChargedGeantino.hh"
12#include "G4MuonPlus.hh"
13#include "G4MuonMinus.hh"
14#include "G4Step.hh"
15
16namespace G4UA
17{
18
19 //---------------------------------------------------------------------------
22 , m_trackRecordCollection("CosmicPerigee")
23 , m_hasBeenSaved(false)
24 , m_idZ(3490.) // ID maximum Z coordiate by default.
25 , m_idR(1150.) // ID outer radius by default.
26 {
27 }
28
29 //---------------------------------------------------------------------------
31 {
32 if (!m_trackRecordCollection.isValid()) {
33 m_trackRecordCollection = std::make_unique<TrackRecordCollection>(
35 }
36
37 //FIXME need a nice way of getting the maximum size of the ID envelope in R and Z.
38 //EnvelopeGeometryManager *gm=EnvelopeGeometryManager::GetGeometryManager();
39 //m_idR = gm->IdetOuterRadius();
40 //m_idZ = gm->IdetMaxZ();
41 }
42
43 //---------------------------------------------------------------------------
45 {
46 }
47
48 //---------------------------------------------------------------------------
50 {
51 // reset the field
52 m_hasBeenSaved = false;
53 }
54
55 //---------------------------------------------------------------------------
57 {
58 // See if this is a new track
59 if (aStep->GetPreStepPoint()->GetStepStatus() == fUndefined)
60 m_hasBeenSaved = false;
61
62 // See if we've already saved it
63 if (m_hasBeenSaved) return;
64
65 // Only save muons or tracks in the ID
66 if (aStep->GetTrack()->GetDefinition() != G4MuonPlus::Definition() &&
67 aStep->GetTrack()->GetDefinition() != G4MuonMinus::Definition() &&
68 ( aStep->GetPostStepPoint()->GetPosition().rho() > m_idR ||
69 aStep->GetPostStepPoint()->GetPosition().z() > m_idZ ||
70 aStep->GetPostStepPoint()->GetPosition().z() < -m_idZ ) ){
71 // Both not a muon and not in the ID
72 return;
73 }
74
75 // Check momentum
76 if (aStep->GetTrack()->GetMomentum().mag() < m_config.pMinPrimary) return;
77
78 // First order approximation of the answer to "is this the perigee"
79 // if it is now moving away from the perigee and has not been saved, save it
80 // That is true if mom dot pos > 0
81 if ( aStep->GetTrack()->GetMomentum().x() * aStep->GetPostStepPoint()->GetPosition().x() +
82 aStep->GetTrack()->GetMomentum().y() * aStep->GetPostStepPoint()->GetPosition().y() < 0) return;
83
84 // Save the vertex...
85 m_hasBeenSaved = true;
86
87 // Decide whether to save the prestep or poststep point
88 // - which one is closer to Perigee?
89 G4StepPoint* preStep = aStep->GetPreStepPoint();
90 G4StepPoint* postStep = aStep->GetPostStepPoint();
91 G4StepPoint* theStep = preStep;
92 if ( fabs( preStep->GetMomentumDirection().x() * preStep->GetPosition().x() +
93 preStep->GetMomentumDirection().y() * preStep->GetPosition().y() ) >
94 fabs( postStep->GetMomentumDirection().x() * postStep->GetPosition().x() +
95 postStep->GetMomentumDirection().y() * postStep->GetPosition().y() ) )
96 {
97 // Using the post step point
98 theStep = postStep;
99 }
100
101 // Could the following code be optimized?
102 // There seems to be a bit of object copying.
103 int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
104 double ener = theStep->GetTotalEnergy();
105 G4ThreeVector pos = theStep->GetPosition();
106 G4ThreeVector mom = theStep->GetMomentum();
107 double time = theStep->GetGlobalTime();
108 G4VPhysicalVolume *preVol = theStep->GetPhysicalVolume();
109
110 if (aStep->GetTrack()->GetDefinition() == G4Geantino::Definition() ) pdgcode=999;
111 if (aStep->GetTrack()->GetDefinition() == G4ChargedGeantino::Definition() ) pdgcode=998;
112
113 // Create the TimedTrackRecord
114 TrackHelper trHelp(aStep->GetTrack());
115 const int barcode = trHelp.GetBarcode(); // FIXME barcode based
116 const int id = trHelp.GetUniqueID();
117 const int status = trHelp.GetStatus();
119 pdgcode,
120 status,
121 ener,
122 mom,
123 pos,
124 time,
125 barcode, // FIXME barcode based
126 id,
127 preVol->GetName());
128 }
129
130} // namespace G4UA
virtual void EndOfEventAction(const G4Event *) override
Config m_config
Configuration options.
virtual void UserSteppingAction(const G4Step *) override
CosmicPerigeeAction(const Config &config)
SG::WriteHandle< TrackRecordCollection > m_trackRecordCollection
Output track track record.
virtual void BeginOfEventAction(const G4Event *) override
bool m_hasBeenSaved
State members.
virtual void PreUserTrackingAction(const G4Track *) override
int GetBarcode() const
int GetUniqueID() const
int GetStatus() const