ATLAS Offline Software
Loading...
Searching...
No Matches
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
6#include "G4Event.hh"
7#include "G4Step.hh"
8#include "G4PrimaryVertex.hh"
9#include "G4PrimaryParticle.hh"
10#include <iostream>
11
12
13namespace G4UA
14{
15
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
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
#define ATH_MSG_INFO(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
virtual void UserSteppingAction(const G4Step *) override
double _sum_edep
Sum of energy deposited in the detector.
double _sum_eesc
Sum of energy escaping the detector (volume = 0)
virtual void EndOfEventAction(const G4Event *) override