ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellContainerSD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Class header
6#include <utility>
7
9
10// Athena headers
11#include "MCTruth/TrackHelper.h"
12
13// FastCaloSim simulation include
15
16
17CaloCellContainerSD::CaloCellContainerSD(const std::string& name, const std::string& CaloCellContainerName, PublicToolHandle<ICaloCellMakerTool> FastHitConvertTool)
18 : G4VSensitiveDetector( name ),
19 m_EmptyCellBuilderTool("EmptyCellBuilderTool/EmptyCellBuilderTool"),
20 m_caloCellContainer (CaloCellContainerName),
22{
23 if(m_EmptyCellBuilderTool.retrieve().isFailure()) {
24 G4Exception("CaloCellContainerSD", "FailedEmptyCellBuilderToolRetrieval", FatalException, "CaloCellContainerSD: Failed to retrieve the empty cell builder tool.");
25 abort();
26 }
27}
28
29
30void CaloCellContainerSD::StartOfAthenaEvent(const EventContext& ctx){
31
32 if (!m_caloCellContainer.isValid()) m_caloCellContainer = std::make_unique<CaloCellContainer>(SG::VIEW_ELEMENTS);
33
34 //Initialize cell container with empty cells
35 if(m_EmptyCellBuilderTool->process(&*m_caloCellContainer, ctx).isFailure()){
36 G4Exception("CaloCellContainerSD", "FailedEmptyCellBuilderToolProcess", FatalException, "CaloCellContainerSD: Failed to process calo cell container with the empty cell builder tool.");
37 abort();
38 }
39
40 return;
41}
42
43void CaloCellContainerSD::EndOfAthenaEvent(const EventContext& ctx){
44
45 // Update the calo iterators of the calo cell container
46 m_caloCellContainer->updateCaloIterators();
47
48 // Convert FastCaloSim hits into HitCollections, taking into account sampling fractions
49 if(m_FastHitConvertTool->process(&*m_caloCellContainer, ctx).isFailure()){
50 G4Exception("CaloCellContainerSD", "FailedFastHitConvertToolProcess", FatalException, "CaloCellContainerSD: Failed to process calo cell container with the fast hit convert tool.");
51 abort();
52 }
53
54 return;
55}
56
57G4bool CaloCellContainerSD::ProcessHits(G4Step*, G4TouchableHistory* ){
58 // This method needs to be implemented when deriving from G4VSensitiveDetector has no use in this case
59 G4Exception("CaloCellContainerSD", "UndefinedProcessHitsCall", FatalException, "CaloCellContainerSD: Call to undefined ProcessHits.");
60 abort();
61 return true;
62}
63
64
66{
67 // Add the energies from the simulation state to the CaloCellContainer
68 for(const auto& icell : simState.cells()) {
69 CaloCell* caloCell = (CaloCell*)m_caloCellContainer->findCell(icell.first->calo_hash());
70 caloCell->addEnergy(icell.second);
71 }
72
73}
void StartOfAthenaEvent(const EventContext &ctx)
void EndOfAthenaEvent(const EventContext &ctx)
PublicToolHandle< ICaloCellMakerTool > m_FastHitConvertTool
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
void recordCells(TFCSSimulationState &)
PublicToolHandle< ICaloCellMakerTool > m_EmptyCellBuilderTool
SG::WriteHandle< CaloCellContainer > m_caloCellContainer
CaloCellContainerSD(const std::string &name, const std::string &CaloCellContainerName, PublicToolHandle< ICaloCellMakerTool > FastHitConvertTool)
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
void addEnergy(float energy)
add energy
Definition CaloCell.h:449
This is for the Doxygen-Documentation.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
STL namespace.