ATLAS Offline Software
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
8 #include "MCTruth/TrackHelper.h"
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 
23 namespace 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
EnergyConservationTest.h
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
G4UA
for nSW
Definition: CalibrationDefaultProcessing.h:19
TrackHelper.h
G4UA::EnergyConservationTest::UserSteppingAction
virtual void UserSteppingAction(const G4Step *) override
Definition: EnergyConservationTest.cxx:67
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
G4UA::EnergyConservationTest::EndOfEventAction
virtual void EndOfEventAction(const G4Event *) override
Definition: EnergyConservationTest.cxx:45
xAOD::EventInfo_v1::Error
@ Error
The sub-detector issued an error.
Definition: EventInfo_v1.h:349
TrackHelper
Definition: TrackHelper.h:14
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
G4UA::EnergyConservationTest::EnergyConservationTest
EnergyConservationTest()
Definition: EnergyConservationTest.cxx:26
G4UA::EnergyConservationTest::e_dep
double e_dep
Definition: EnergyConservationTest.h:37
G4UA::EnergyConservationTest::m_evtStore
ServiceHandle< StoreGateSvc > m_evtStore
Pointer to StoreGate (event store by default)
Definition: EnergyConservationTest.h:34
EventInfo.h
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
TrackHelper::IsPrimary
bool IsPrimary() const
Definition: TrackHelper.cxx:15
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
G4UA::EnergyConservationTest::e_out
double e_out
Definition: EnergyConservationTest.h:37
G4UA::EnergyConservationTest::PreUserTrackingAction
virtual void PreUserTrackingAction(const G4Track *) override
Definition: EnergyConservationTest.cxx:33
G4UA::EnergyConservationTest::PostUserTrackingAction
virtual void PostUserTrackingAction(const G4Track *) override
Definition: EnergyConservationTest.cxx:39
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
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::EnergyConservationTest::e_in
double e_in
Definition: EnergyConservationTest.h:37
xAOD::EventInfo_v1::Core
@ Core
Core flags describing the event.
Definition: EventInfo_v1.h:339