ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4DebuggingTools
src
EnergyConservationTest.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 "
EnergyConservationTest.h
"
6
7
// For determining if something was a primary
8
#include "
MCTruth/TrackHelper.h
"
9
// For setting the error state if need be
10
#include "
xAODEventInfo/EventInfo.h
"
11
12
// For the G4 information
13
#include "G4Step.hh"
14
#include "G4Track.hh"
15
16
// for std::fabs
17
#include <cmath>
18
19
#include "GaudiKernel/Bootstrap.h"
20
#include "GaudiKernel/ISvcLocator.h"
21
#include "GaudiKernel/IMessageSvc.h"
22
23
namespace
G4UA
24
{
25
26
EnergyConservationTest::EnergyConservationTest
():
27
AthMessaging
(
Gaudi
::svcLocator()->service< IMessageSvc >(
"MessageSvc"
),
"EnergyConservationTest"
),
28
m_evtStore
(
"StoreGateSvc/StoreGateSvc"
,
"EnergyConservationTest"
),
29
m_detStore
(
"StoreGateSvc/DetectorStore"
,
"EnergyConservationTest"
),
30
e_in
(0),
e_out
(0),
e_dep
(0)
31
{}
32
33
void
EnergyConservationTest::PreUserTrackingAction
(
const
G4Track* t)
34
{
35
TrackHelper
theHelper(t);
36
if
(theHelper.
IsPrimary
())
e_in
+= t->GetTotalEnergy();
37
}
38
39
void
EnergyConservationTest::PostUserTrackingAction
(
const
G4Track* t)
40
{
41
// If it has any energy left *after* being tracked, it should have left the world
42
if
(!t->GetNextVolume())
e_out
+= t->GetTotalEnergy();
43
}
44
45
void
EnergyConservationTest::EndOfEventAction
(
const
G4Event*)
46
{
47
ATH_MSG_DEBUG
(
"Event info: "
<<
e_in
<<
" in, "
<<
e_out
<<
" out, "
<<
e_dep
<<
" deposited."
);
48
if
( std::fabs(
e_in
-
e_out
-
e_dep
) > 10000. ) {
// 10 GeV threshold, which is really pretty generous!
49
ATH_MSG_ERROR
(
"Energy conservation error! "
<<
e_in
<<
" in, "
<<
e_out
<<
" out, "
<<
e_dep
<<
" deposited."
);
50
51
// Set error state in eventInfo
52
const
xAOD::EventInfo
* ei = 0;
53
if
(
m_evtStore
->retrieve( ei ).isFailure() || !ei ){
54
ATH_MSG_WARNING
(
"Failed to retrieve EventInfo"
);
55
}
else
{
56
ei->
updateErrorState
(
xAOD::EventInfo::Core
,
xAOD::EventInfo::Error
);
57
ATH_MSG_WARNING
(
"Set error state in event info!"
);
58
}
59
}
60
61
// reset
62
e_in
=0.;
63
e_out
=0.;
64
e_dep
=0.;
65
}
66
67
void
EnergyConservationTest::UserSteppingAction
(
const
G4Step* s)
68
{
69
e_dep
+= s->GetTotalEnergyDeposit();
70
}
71
72
}
// namespace G4UA
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
EnergyConservationTest.h
TrackHelper.h
AthMessaging::AthMessaging
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Definition
AthMessaging.cxx:13
G4UA::EnergyConservationTest::EnergyConservationTest
EnergyConservationTest()
Definition
EnergyConservationTest.cxx:26
G4UA::EnergyConservationTest::e_out
double e_out
Definition
EnergyConservationTest.h:37
G4UA::EnergyConservationTest::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition
EnergyConservationTest.cxx:45
G4UA::EnergyConservationTest::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default).
Definition
EnergyConservationTest.h:34
G4UA::EnergyConservationTest::e_in
double e_in
Definition
EnergyConservationTest.h:37
G4UA::EnergyConservationTest::PostUserTrackingAction
virtual void PostUserTrackingAction(const G4Track *) override
Definition
EnergyConservationTest.cxx:39
G4UA::EnergyConservationTest::e_dep
double e_dep
Definition
EnergyConservationTest.h:37
G4UA::EnergyConservationTest::m_detStore
ServiceHandle< StoreGateSvc > m_detStore
Pointer to StoreGate (detector store by default).
Definition
EnergyConservationTest.h:36
G4UA::EnergyConservationTest::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition
EnergyConservationTest.cxx:67
G4UA::EnergyConservationTest::PreUserTrackingAction
virtual void PreUserTrackingAction(const G4Track *) override
Definition
EnergyConservationTest.cxx:33
TrackHelper
Definition
TrackHelper.h:20
TrackHelper::IsPrimary
bool IsPrimary() const
Definition
TrackHelper.cxx:37
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition
EventInfo_v1.h:339
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition
EventInfo_v1.h:349
xAOD::EventInfo_v1::updateErrorState
bool updateErrorState(const EventFlagSubDet subDet, const EventFlagErrorState state) const
Update the error state for one particular sub-detector.
Definition
EventInfo_v1.cxx:856
G4UA
for nSW
Definition
CalibrationDefaultProcessing.h:19
Gaudi
=============================================================================
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:273
xAOD::EventInfo
EventInfo_v1 EventInfo
Definition of the latest event info version.
Definition
IEventInfoCnvTool.h:16
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0