ATLAS Offline Software
Loading...
Searching...
No Matches
ScoringPlane.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "ScoringPlane.h"
6#include "G4Step.hh"
7#include "CLHEP/Units/SystemOfUnits.h"
8#include "TTree.h"
9#include "TFile.h"
10
11
12namespace G4UA
13{
14
15 //----------------------------------------------------------------------------
16 // Constructor
17 //----------------------------------------------------------------------------
20 m_evt(0), m_ntr(0), m_pdg(0), m_cha(0), m_ene(0),
21 m_vx(0), m_vy(0), m_vz(0),
22 m_x0(0), m_y0(0), m_z0(0), m_t0(0),
23 m_px0(0), m_py0(0), m_pz0(0),
24 m_x1(0), m_y1(0), m_z1(0), m_t1(0),
25 m_px1(0), m_py1(0), m_pz1(0),
26 m_x(0), m_y(0), m_z(0)
27 {
28 }
29
33
35 {
36
37 m_tree0 = std::make_unique<TTree>("t0", "ATHENA event tree");
38
39 m_tree0->Branch("evt", &m_evt, "evt/I");
40 m_tree0->Branch("ntr", &m_ntr, "ntr/I");
41
42 m_tree1 = std::make_unique<TTree>("t1", "ATHENA particle tree");
43
44 m_tree1->Branch("evt", &m_evt, "evt/I");
45 m_tree1->Branch("ntr", &m_ntr, "ntr/I");
46 m_tree1->Branch("pdg", &m_pdg, "pdg/I");
47 m_tree1->Branch("cha", &m_cha, "cha/D");
48 m_tree1->Branch("ene", &m_ene, "ene/D");
49 m_tree1->Branch("x0", &m_x0, "x0/D");
50 m_tree1->Branch("y0", &m_y0, "y0/D");
51 m_tree1->Branch("z0", &m_z0, "z0/D");
52 m_tree1->Branch("t0", &m_t0, "t0/D");
53 m_tree1->Branch("px0", &m_px0, "px0/D");
54 m_tree1->Branch("py0", &m_py0, "py0/D");
55 m_tree1->Branch("pz0", &m_pz0, "pz0/D");
56 m_tree1->Branch("x1", &m_x1, "x1/D");
57 m_tree1->Branch("y1", &m_y1, "y1/D");
58 m_tree1->Branch("z1", &m_z1, "z1/D");
59 m_tree1->Branch("t1", &m_t1, "t1/D");
60 m_tree1->Branch("px1", &m_px1, "px1/D");
61 m_tree1->Branch("py1", &m_py1, "py1/D");
62 m_tree1->Branch("pz1", &m_pz1, "pz1/D");
63 m_tree1->Branch("vx", &m_vx, "vx/D");
64 m_tree1->Branch("vy", &m_vy, "vy/D");
65 m_tree1->Branch("vz", &m_vz, "vz/D");
66 m_tree1->Branch("x", &m_x, "x/D");
67 m_tree1->Branch("y", &m_y, "y/D");
68 m_tree1->Branch("z", &m_z, "z/D");
69
70 m_evt = 0;
71
72 G4cout<<"ScoringPlane: placing scoring plane at [mm]: " << m_config.plane << G4endl;
73 G4cout<<"ScoringPlane: stop and kill particles: " << m_config.pkill << G4endl;
74 G4cout<<"ScoringPlane: output root filename: " << m_config.fname << G4endl;
75 }
76
77 void ScoringPlane::EndOfRunAction(const G4Run*){
78 TFile* file = new TFile(m_config.fname.c_str(), "RECREATE", "ATHENA ufo simulation");
79
80 m_tree0->Write();
81 m_tree1->Write();
82
83 file->Close();
84 }
85
86 void ScoringPlane::UserSteppingAction(const G4Step* aStep)
87 {
88 m_z0 = aStep->GetPreStepPoint()->GetPosition().z();
89 m_z1 = aStep->GetPostStepPoint()->GetPosition().z();
90
91 if (m_z0*m_config.plane < 0) return; // take only particles on one side
92 if (m_z1*m_config.plane < 0) return; // take only particles on one side
93 if (std::fabs(m_z0) < std::fabs(m_config.plane)) return; // take only particles flowing towards the IP
94 if (std::fabs(m_z1) > std::fabs(m_config.plane)) return; // take only particles flowing towards the IP
95
96 m_ntr++;
97
98 m_pdg = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
99 m_cha = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
100 m_ene = aStep->GetTrack()->GetTotalEnergy();
101 m_vx = aStep->GetTrack()->GetVertexPosition().x();
102 m_vy = aStep->GetTrack()->GetVertexPosition().y();
103 m_vz = aStep->GetTrack()->GetVertexPosition().z();
104
105 m_x0 = aStep->GetPreStepPoint()->GetPosition().x();
106 m_y0 = aStep->GetPreStepPoint()->GetPosition().y();
107 m_t0 = aStep->GetPreStepPoint()->GetGlobalTime()/CLHEP::ns;
108 m_px0 = aStep->GetPreStepPoint()->GetMomentum().x();
109 m_py0 = aStep->GetPreStepPoint()->GetMomentum().y();
110 m_pz0 = aStep->GetPreStepPoint()->GetMomentum().z();
111
112 m_x1 = aStep->GetPostStepPoint()->GetPosition().x();
113 m_y1 = aStep->GetPostStepPoint()->GetPosition().y();
114 m_t1 = aStep->GetPostStepPoint()->GetGlobalTime()/CLHEP::ns;
115 m_px1 = aStep->GetPostStepPoint()->GetMomentum().x();
116 m_py1 = aStep->GetPostStepPoint()->GetMomentum().y();
117 m_pz1 = aStep->GetPostStepPoint()->GetMomentum().z();
118
119 m_z = m_config.plane;
120 m_x = m_x0 + (m_z0!=m_z1 ? (m_x1-m_x0)/(m_z1-m_z0)*(m_z-m_z0) : (m_x1-m_x0)*0.5);
121 m_y = m_y0 + (m_z0!=m_z1 ? (m_y1-m_y0)/(m_z1-m_z0)*(m_z-m_z0) : (m_y1-m_y0)*0.5);
122
123 m_tree1->Fill();
124
125 if (m_config.pkill == 1) aStep->GetTrack()->SetTrackStatus(fStopAndKill);
126 else if (m_config.pkill == 2) aStep->GetTrack()->SetTrackStatus(fKillTrackAndSecondaries);
127
128 //G4cout<<
129 // " z0: " << std::setw(10) << m_z0
130 // << " z1: " << std::setw(10) << m_z1
131 // << " x0: " << std::setw(10) << m_x0
132 // << " x1: " << std::setw(10) << m_x1
133 // << " x: " << std::setw(10) << m_x
134 // << " y0: " << std::setw(10) << m_y0
135 // << " y1: " << std::setw(10) << m_y1
136 // << " y: " << std::setw(10) << m_y << G4endl;
137
138 }
139
141 {
142 m_evt++;
143 m_ntr = 0;
144 }
145
147 {
148 m_tree0->Fill();
149 }
150
151} // namespace G4UA
ScoringPlane(const Config &config)
virtual void BeginOfRunAction(const G4Run *) override
std::unique_ptr< TTree > m_tree1
virtual void EndOfRunAction(const G4Run *) override
virtual void UserSteppingAction(const G4Step *) override
std::unique_ptr< TTree > m_tree0
virtual void BeginOfEventAction(const G4Event *) override
virtual void EndOfEventAction(const G4Event *) override
TFile * file