ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
7// For determining if something was a primary
9// For setting the error state if need be
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
23namespace G4UA
24{
25
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
34 {
35 TrackHelper theHelper(t);
36 if(theHelper.IsPrimary()) e_in += t->GetTotalEnergy();
37 }
38
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
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 {
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
68 {
69 e_dep += s->GetTotalEnergyDeposit();
70 }
71
72} // namespace G4UA
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
virtual void EndOfEventAction(const G4Event *) override
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default)
virtual void PostUserTrackingAction(const G4Track *) override
ServiceHandle< StoreGateSvc > m_detStore
Pointer to StoreGate (detector store by default)
virtual void UserSteppingAction(const G4Step *) override
virtual void PreUserTrackingAction(const G4Track *) override
bool IsPrimary() const
@ Core
Core flags describing the event.
@ Error
The sub-detector issued an error.
bool updateErrorState(const EventFlagSubDet subDet, const EventFlagErrorState state) const
Update the error state for one particular sub-detector.
=============================================================================
EventInfo_v1 EventInfo
Definition of the latest event info version.