ATLAS Offline Software
ZdcMCTruthAlg.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 #include "ZdcRec/ZdcMCTruthAlg.h"
6 
10 
11 ZdcMCTruthAlg::ZdcMCTruthAlg(const std::string& name, ISvcLocator* pSvcLocator)
12  : AthAlgorithm(name, pSvcLocator),
13  m_zdcID(nullptr)
14 {
15 
16 }
17 
18 
20 {;}
21 
22 
25 {
26  ATH_MSG_INFO("Initializing " << name());
27 
28  if (detStore()->retrieve( m_zdcID ).isFailure() ) {
29  ATH_MSG_ERROR("execute: Could not retrieve ZdcID object from the detector store");
30  return StatusCode::FAILURE;
31  }else{
32  ATH_MSG_DEBUG("execute: retrieved ZdcID");
33  }
34 
35  //Initialize input hit container read handles
37 
38  //Initialize output ZdcModuleContainer read handles
39  m_zdcModuleContainerName = "ZdcModules";
40  m_zdcSumContainerName = "ZdcSums";
41 
42  //Per module AuxDecor handles
48  ATH_CHECK( m_zdcModuleTruthEMEnergy.initialize());
52  ATH_CHECK( m_zdcModuleTruthEscEnergy.initialize());
53 
54  //RPD decorations required for processing
60  ATH_CHECK( m_rpdTileRowNumber.initialize());
62  ATH_CHECK( m_rpdTileColumnNumber.initialize());
63 
64  //Sums container auxDecor handles
66  ATH_CHECK( m_zdcSumTruthTotalEnergy.initialize());
68  ATH_CHECK( m_zdcSumTruthInvisEnergy.initialize());
70  ATH_CHECK( m_zdcSumTruthEMEnergy.initialize());
72  ATH_CHECK( m_zdcSumTruthNonEMEnergy.initialize());
73  m_zdcSumTruthEscEnergy = m_zdcSumContainerName + ".TruthEscapedEnergy" + m_auxSuffix;
74  ATH_CHECK( m_zdcSumTruthEscEnergy.initialize());
75 
76  return StatusCode::SUCCESS;
77 }
78 
80 {
81 
82  /******************************************
83  * Get the CaloCalibrationHitContainer (input)
84  ******************************************/
86  if (!calibHitContainer.isValid()) {
87  ATH_MSG_ERROR("Could not get Calibration hit container " << calibHitContainer.name() << " from store " << calibHitContainer.store());
88  return StatusCode::FAILURE;
89  }
90 
91  ATH_MSG_DEBUG ("--> ZDC: ZdcMCTruthAlg execute starting on "
92  << getContext().evt()
93  << "th event");
94 
95  /******************************************
96  * Get the ZdcModuleContainer and
97  * ZdcModuleSumContainer (output)
98  ******************************************/
99  xAOD::ZdcModuleContainer const* moduleContainer = nullptr;
100  ATH_CHECK(evtStore()->retrieve(moduleContainer, m_zdcModuleContainerName));
101 
102  xAOD::ZdcModuleContainer const* moduleSumContainer = nullptr;
103  ATH_CHECK(evtStore()->retrieve(moduleSumContainer, m_zdcSumContainerName));
104 
105  //Create local variables to hold the per module and per side sums
106  float totalMod[2][7]={{0.0},{0.0}}, invisMod[2][7]={{0.0},{0.0}}, emMod[2][7]={{0.0},{0.0}}, nonEMMod[2][7]={{0.0},{0.0}}, escMod[2][7]={{0.0},{0.0}};
107  float totalSide[2]={0.0}, invisSide[2]={0.0}, emSide[2]={0.0}, nonEMSide[2]={0.0}, escSide[2]={0.0};
108  bool foundMod[2][7] = {{false},{false}};
109 
110  /******************************************
111  * Sum all hits in each module
112  ******************************************/
113  for (const auto hit : *calibHitContainer){
114  Identifier id = hit->cellID();
115  int side = (m_zdcID->side(id) > 0) ? 1 : 0;
116  int mod = m_zdcID->module(id);
117 
118  emMod[side][mod] += hit->energyEM();
119  nonEMMod[side][mod] += hit->energyNonEM();
120  invisMod[side][mod] += hit->energyInvisible();
121  totalMod[side][mod] += hit->energyTotal();
122  escMod[side][mod] += hit->energyEscaped();
123  }
124 
125  /******************************************
126  * Decorate the ZdcModuleContainer with the
127  * per module sums and add the per module
128  * sums to the per side sums
129  ******************************************/
139  for (const auto zdcModule : *moduleContainer){
140  if(zdcModule->zdcSide() == 0) continue;
141  int side = (zdcModule->zdcSide() > 0) ? 1 : 0;
142  int mod = zdcModule->zdcModule();
143  foundMod[side][mod] = true;
144 
145  //Add row/column info for RPD processing
146  if(mod == 4){
147  int lucrodId = (side == 0) ? 4 : 2;
148  int rpdChannel = zdcModule->zdcChannel();
149  int lucrodChannel = rpdChannel%8;
150  if(rpdChannel > 7)
151  lucrodId ++;
152 
153  ATH_MSG_DEBUG("Accessing LUCROD ID " << lucrodId <<
154  ", lucrodChannel=" << lucrodChannel <<
155  " for RPD side " << zdcModule->zdcSide() <<
156  ", channel " << rpdChannel);
157 
158  float xpos = ZdcLucrodMapRun3::getInstance()->getLucrod(lucrodId)["x"][lucrodChannel];
159  float ypos = ZdcLucrodMapRun3::getInstance()->getLucrod(lucrodId)["y"][lucrodChannel];
160  unsigned int row = ZdcLucrodMapRun3::getInstance()->getLucrod(lucrodId)["row"][lucrodChannel];
161  unsigned int col = ZdcLucrodMapRun3::getInstance()->getLucrod(lucrodId)["col"][lucrodChannel];
162  rpdTileXpositionRelative(*zdcModule) = xpos;
163  rpdTileYpositionRelative(*zdcModule) = ypos;
164  rpdTileRowNumber (*zdcModule) = row;
165  rpdTileColumnNumber (*zdcModule) = col;
166  }
167 
168  //Only save RPD truth in channel 0
169  if(mod == 4 && zdcModule->zdcChannel() != 0) continue;
170 
171  zdcModuleTruthTotalEnergy(*zdcModule) = totalMod[side][mod];
172  zdcModuleTruthInvisEnergy(*zdcModule) = invisMod[side][mod];
173  zdcModuleTruthEMEnergy (*zdcModule) = emMod [side][mod];
174  zdcModuleTruthNonEMEnergy(*zdcModule) = nonEMMod[side][mod];
175  zdcModuleTruthEscEnergy (*zdcModule) = escMod [side][mod];
176 
177  totalSide[side] += totalMod[side][mod];
178  invisSide[side] += invisMod[side][mod];
179  emSide[side] += emMod [side][mod];
180  nonEMSide[side] += nonEMMod[side][mod];
181  escSide[side] += escMod [side][mod];
182  }
183 
184  for(int iside : {0,1}){
185  for(int mod = 0; mod < 7; ++mod){
186  ATH_MSG_DEBUG("ZDC " << iside << ":" << mod << " total energy = " << totalMod[iside][mod]);
187  if(!foundMod[iside][mod]){
188  ATH_MSG_DEBUG("Failed to find " << iside << ":" << mod);
189  }
190  }
191  }
192 
193  ATH_MSG_DEBUG("ZDC A total energy = " << totalSide[1] <<
194  ", invisible energy = " << invisSide[1] <<
195  ", EM energy = " << emSide[1] <<
196  ", non EM energy = " << nonEMSide[1] <<
197  ", escaped energy = " << escSide[1]);
198 
199  ATH_MSG_DEBUG("ZDC C total energy = " << totalSide[0] <<
200  ", invisible energy = " << invisSide[0] <<
201  ", EM energy = " << emSide[0] <<
202  ", non EM energy = " << nonEMSide[0] <<
203  ", escaped energy = " << escSide[0]);
204 
205 
206  /******************************************
207  * Decorate the Sums container with the
208  * per side sums
209  ******************************************/
215  for (const auto zdcSum : *moduleSumContainer){
216  if (zdcSum->zdcSide() == 0) continue;
217  int side = (zdcSum->zdcSide()==-1) ? 0 : 1;
218  ATH_MSG_DEBUG("Filling zdcSum container side " << side);
219 
220  zdcSumTruthTotalEnergy(*zdcSum) = totalSide[side];
221  zdcSumTruthInvisEnergy(*zdcSum) = invisSide[side];
222  zdcSumTruthEMEnergy (*zdcSum) = emSide [side];
223  zdcSumTruthNonEMEnergy(*zdcSum) = nonEMSide[side];
224  zdcSumTruthEscEnergy (*zdcSum) = escSide [side];
225  }
226 
227  return StatusCode::SUCCESS;
228 }
229 
230 
232 {
233  ATH_MSG_DEBUG( "--> ZDC: ZdcMCTruthAlg finalize complete" );
234 
235  return StatusCode::SUCCESS;
236 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
query_example.row
row
Definition: query_example.py:24
ZdcMCTruthAlg::m_zdcModuleTruthEMEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleTruthEMEnergy
Definition: ZdcMCTruthAlg.h:46
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ZdcMCTruthAlg::m_zdcSumTruthNonEMEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcSumTruthNonEMEnergy
Definition: ZdcMCTruthAlg.h:56
ZdcMCTruthAlg::m_rpdTileColumnNumber
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_rpdTileColumnNumber
Definition: ZdcMCTruthAlg.h:52
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
ZdcID::module
int module(const Identifier &id) const
Definition: ZdcID.h:163
ZdcMCTruthAlg::m_zdcModuleTruthTotalEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleTruthTotalEnergy
Definition: ZdcMCTruthAlg.h:44
ZdcMCTruthAlg::m_zdcSumTruthInvisEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcSumTruthInvisEnergy
Definition: ZdcMCTruthAlg.h:54
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
ZdcMCTruthAlg::ZdcMCTruthAlg
ZdcMCTruthAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ZdcMCTruthAlg.cxx:11
ZdcMCTruthAlg::m_zdcModuleContainerName
std::string m_zdcModuleContainerName
Definition: ZdcMCTruthAlg.h:41
ZdcMCTruthAlg::m_zdcSumTruthEMEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcSumTruthEMEnergy
Definition: ZdcMCTruthAlg.h:55
ZdcLucrodMapRun3::getLucrod
const nlohmann::json & getLucrod(int i) const
Definition: ZdcLucrodMapRun3.h:23
ZdcMCTruthAlg::m_zdcSumTruthTotalEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcSumTruthTotalEnergy
Definition: ZdcMCTruthAlg.h:53
ZdcMCTruthAlg::finalize
StatusCode finalize()
Definition: ZdcMCTruthAlg.cxx:231
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
ZdcMCTruthAlg.h
TRT::Hit::side
@ side
Definition: HitInfo.h:83
ZdcMCTruthAlg::execute
StatusCode execute()
Definition: ZdcMCTruthAlg.cxx:79
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ZdcMCTruthAlg::m_auxSuffix
Gaudi::Property< std::string > m_auxSuffix
Definition: ZdcMCTruthAlg.h:38
ZdcMCTruthAlg::m_zdcSumTruthEscEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcSumTruthEscEnergy
Definition: ZdcMCTruthAlg.h:57
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
maskDeadModules.mod
mod
Definition: maskDeadModules.py:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
ZdcMCTruthAlg::m_rpdTileRowNumber
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_rpdTileRowNumber
Definition: ZdcMCTruthAlg.h:51
ZdcLucrodMapRun3.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
ZdcMCTruthAlg::initialize
StatusCode initialize()
Definition: ZdcMCTruthAlg.cxx:24
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
ZdcMCTruthAlg::m_zdcModuleTruthInvisEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleTruthInvisEnergy
Definition: ZdcMCTruthAlg.h:45
ZdcMCTruthAlg::m_zdcModuleTruthEscEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleTruthEscEnergy
Definition: ZdcMCTruthAlg.h:48
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
query_example.col
col
Definition: query_example.py:7
ZdcMCTruthAlg::~ZdcMCTruthAlg
virtual ~ZdcMCTruthAlg()
Definition: ZdcMCTruthAlg.cxx:19
ZdcModule.h
ZdcID::side
int side(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: ZdcID.h:157
ZdcMCTruthAlg::m_zdcModuleTruthNonEMEnergy
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_zdcModuleTruthNonEMEnergy
Definition: ZdcMCTruthAlg.h:47
ZdcMCTruthAlg::m_CaloCalibrationHitContainerKey
SG::ReadHandleKey< CaloCalibrationHitContainer > m_CaloCalibrationHitContainerKey
Definition: ZdcMCTruthAlg.h:40
ZdcMCTruthAlg::m_zdcID
const ZdcID * m_zdcID
Definition: ZdcMCTruthAlg.h:36
ZdcMCTruthAlg::m_rpdTileYpositionRelative
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_rpdTileYpositionRelative
Definition: ZdcMCTruthAlg.h:50
ZdcMCTruthAlg::m_rpdTileXpositionRelative
SG::WriteDecorHandleKey< xAOD::ZdcModuleContainer > m_rpdTileXpositionRelative
Definition: ZdcMCTruthAlg.h:49
ZdcMCTruthAlg::m_zdcSumContainerName
std::string m_zdcSumContainerName
Definition: ZdcMCTruthAlg.h:42
ZdcLucrodMapRun3::getInstance
static const ZdcLucrodMapRun3 * getInstance()
Definition: ZdcLucrodMapRun3.cxx:10
Identifier
Definition: IdentifierFieldParser.cxx:14