ATLAS Offline Software
CalibHitValidate.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //-----------------------------------------------------------------------
6 //
7 // Description: see CalibHitValidate.h
8 //
9 // Environment:
10 // Software developed for the ATLAS Detector at CERN LHC
11 //
12 //-----------------------------------------------------------------------
13 
14 #include "CalibHitValidate.h"
15 
18 
20 
21 //###############################################################################
22 
24  ISvcLocator* pSvcLocator)
25  : AthAlgorithm(name, pSvcLocator)
26 {
27 
28  declareProperty("CalibrationHitContainerNames",m_CalibrationHitContainerNames);
29  declareProperty("DMCalibrationHitContainerNames",m_DMCalibrationHitContainerNames);
30 }
31 
32 
33 //###############################################################################
34 
36 {
37  ATH_MSG_VERBOSE ( "Initializing " << name() );
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 //###############################################################################
43 
45 {
46  // get truth containers
47  const McEventCollection* truthEvent=0;
48  StatusCode sc0 = evtStore()->retrieve(truthEvent, "TruthEvent");
49  if (sc0.isFailure()||!truthEvent){
50  ATH_MSG_ERROR ( "No McEventCollection found");
51  return StatusCode::FAILURE;
52  }
53  auto gen = *HepMC::begin(*truthEvent->at(0));
54 
55  std::vector<std::string>::iterator containerNameIter;
56 
57  std::vector<double> hitEnergies;
58 
59  double totalEnergyAllContainers=0.;
60 
61  // calibration hit containers
62  const CaloCalibrationHitContainer* cchc;
63  std::vector<const CaloCalibrationHitContainer *> v_cchc;
64  for (containerNameIter=m_CalibrationHitContainerNames.begin();containerNameIter!=m_CalibrationHitContainerNames.end();++containerNameIter) {
65 
66 
67  double totEnergy=0.;
68 
69  if ( evtStore()->contains<CaloCalibrationHitContainer>(*containerNameIter)) {
70  StatusCode sc = evtStore()->retrieve(cchc,*containerNameIter);
71  if (sc.isFailure() ) {
72  ATH_MSG_ERROR ( "Cannot retrieve calibration hit container " << *containerNameIter );
73  return StatusCode::FAILURE;
74  }
75 
76  //loop over cells in calibration container
79 
80  for(;chIter!=chIterE;++chIter)
81  totEnergy+=(*chIter)->energyTotal();
82  }
83 
84  ATH_MSG_INFO ("container name: "<<*containerNameIter<<", energy="<<totEnergy);
85 
86  totalEnergyAllContainers += totEnergy;
87 
88  hitEnergies.push_back(totEnergy);
89  }
90 
91  // dark material calibration hit containers
92 
93  std::vector<double> hitEnergiesDM;
94 
95  std::vector<const CaloCalibrationHitContainer *> v_dmcchc;
96  for (containerNameIter=m_DMCalibrationHitContainerNames.begin();containerNameIter!=m_DMCalibrationHitContainerNames.end();++containerNameIter) {
97 
98 
99  double totEnergy=0.;
100  if ( evtStore()->contains<CaloCalibrationHitContainer>(*containerNameIter)) {
101  StatusCode sc = evtStore()->retrieve(cchc,*containerNameIter);
102  if (sc.isFailure() ) {
103  ATH_MSG_ERROR ( "Cannot retrieve DM calibration hit container " << *containerNameIter );
104  return StatusCode::FAILURE;
105  }
106 
107  //loop over cells in calibration container
110 
111  for(;chIter!=chIterE;++chIter)
112  totEnergy+=(*chIter)->energyTotal();
113  }
114 
115  ATH_MSG_INFO ("DM container name: "<<*containerNameIter<<", energy="<<totEnergy);
116 
117  totalEnergyAllContainers += totEnergy;
118 
119  hitEnergiesDM.push_back(totEnergy);
120  }
121 
122  ATH_MSG_INFO ("total energy in hits: "<<totalEnergyAllContainers<<", in primary particle: "<<gen->momentum().e());
123 
124  return StatusCode::SUCCESS;
125 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CaloCalibrationHitContainer
Definition: CaloCalibrationHitContainer.h:25
CaloCalibrationHit.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CalibHitValidate::execute
virtual StatusCode execute() override
Definition: CalibHitValidate.cxx:44
CalibHitValidate::initialize
virtual StatusCode initialize() override
Definition: CalibHitValidate.cxx:35
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CaloCalibrationHitContainer.h
master.gen
gen
Definition: master.py:32
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthenaHitsVector< CaloCalibrationHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
CalibHitValidate.h
CalibHitValidate::m_DMCalibrationHitContainerNames
std::vector< std::string > m_DMCalibrationHitContainerNames
vector of dead material calibration hit container names to use.
Definition: CalibHitValidate.h:43
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
McEventCollection.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CalibHitValidate::CalibHitValidate
CalibHitValidate(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CalibHitValidate.cxx:23
CalibHitValidate::m_CalibrationHitContainerNames
std::vector< std::string > m_CalibrationHitContainerNames
vector of calibration hit container names to use.
Definition: CalibHitValidate.h:36
HepMC::begin
GenEvent::particle_iterator begin(HepMC::GenEvent &e)
Definition: GenEvent.h:620
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139