ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4UserActions
src
MomentumConservation.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 "
MomentumConservation.h
"
6
#include "G4Event.hh"
7
#include "G4Step.hh"
8
#include "G4PrimaryVertex.hh"
9
#include "G4PrimaryParticle.hh"
10
#include <iostream>
11
12
13
namespace
G4UA
14
{
15
16
MomentumConservation::MomentumConservation
()
17
:
AthMessaging
(
"MomentumConservation"
),
18
_sum_edep
(0),
_sum_eesc
(0)
19
{}
20
21
void
MomentumConservation::EndOfEventAction
(
const
G4Event* anEvent)
22
{
23
24
// Energy conservation:
25
26
// Get energy of primaries
27
double
eprim = 0;
28
//G4FourVector p4prim;
29
for
(
int
iv = 0; iv < anEvent->GetNumberOfPrimaryVertex(); ++iv) {
30
const
G4PrimaryVertex* v = anEvent->GetPrimaryVertex(iv);
31
for
(
int
ip = 0; ip < v->GetNumberOfParticle(); ++ip) {
32
const
G4PrimaryParticle* p = v->GetPrimary(ip);
35
eprim += p->GetMomentum().mag();
//< Just KE
36
}
37
}
38
39
// Get energy from neutrinos (which aren't stacked)
40
double
eneut = 0;
41
//vector<G4Track*> tracks = theTruthManager->GetSecondaries();
42
43
// Energy conservation check
44
const
double
efinal =
_sum_edep
+
_sum_eesc
+ eneut;
45
ATH_MSG_INFO
(
"Energy conservation check: "
46
<<
"initial = "
<< eprim/CLHEP::GeV <<
" GeV, "
47
<<
"final = "
<< efinal/CLHEP::GeV <<
" GeV"
);
48
49
50
// Momentum conservation:
52
53
// Reset for next event
54
_sum_edep
= 0;
55
_sum_eesc
= 0;
56
57
}
58
59
void
MomentumConservation::UserSteppingAction
(
const
G4Step* aStep){
60
61
if
(aStep->GetPostStepPoint()->GetPhysicalVolume() != 0) {
62
const
double
edep = aStep->GetTotalEnergyDeposit();
63
_sum_edep
+= edep;
64
}
else
{
66
const
double
eesc = aStep->GetPostStepPoint()->GetTotalEnergy();
67
_sum_eesc
+= eesc;
68
}
69
70
}
71
72
}
// namespace G4UA
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
MomentumConservation.h
AthMessaging::AthMessaging
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Definition
AthMessaging.cxx:13
G4UA::MomentumConservation::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition
MomentumConservation.cxx:59
G4UA::MomentumConservation::_sum_edep
double _sum_edep
Sum of energy deposited in the detector.
Definition
MomentumConservation.h:33
G4UA::MomentumConservation::_sum_eesc
double _sum_eesc
Sum of energy escaping the detector (volume = 0).
Definition
MomentumConservation.h:36
G4UA::MomentumConservation::MomentumConservation
MomentumConservation()
Definition
MomentumConservation.cxx:16
G4UA::MomentumConservation::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition
MomentumConservation.cxx:21
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
Generated on
for ATLAS Offline Software by
1.17.0