ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellContainerSD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Class header
7
8// Athena headers
12
13// FastCaloSim simulation include
15
16#include "G4EventManager.hh"
17
18#include <memory>
19
21 const std::string& CaloCellContainerName)
22 : G4VSensitiveDetector(name)
23 , m_caloCellContainerName(CaloCellContainerName)
24{
25}
26
31
32G4bool CaloCellContainerSD::ProcessHits(G4Step*, G4TouchableHistory*)
33{
34 // This method needs to be implemented when deriving from G4VSensitiveDetector has no use in this case
35 G4Exception("CaloCellContainerSD", "UndefinedProcessHitsCall", FatalException, "CaloCellContainerSD: Call to undefined ProcessHits.");
36 abort();
37 return true;
38}
39
40
42{
44 // ISF can initialize SDs before the per-G4Event user info is installed.
45 // Refresh from the current event when available to avoid stale caches.
47 }
49 G4Exception("CaloCellContainerSD", "MissingCaloCellContainer", FatalException, "CaloCellContainerSD: Failed to retrieve the event-owned CaloCellContainer.");
50 abort();
51 }
52
53 // Add the energies from the simulation state to the CaloCellContainer
54 for(const auto& icell : simState.cells()) {
55 CaloCell* caloCell =
56 static_cast<CaloCell*>(m_caloCellContainer->findCell(icell.first->calo_hash()));
57 caloCell->addEnergy(icell.second);
58 }
59}
60
62{
63 auto* eventManager = G4EventManager::GetEventManager();
64 if (!eventManager) {
65 return nullptr;
66 }
67
68 auto* eventInfo =
69 dynamic_cast<AtlasG4EventUserInfo*>(eventManager->GetUserInformation());
70 if (!eventInfo) {
71 return nullptr;
72 }
73
74 std::shared_ptr<HitCollectionMap> hitCollections = eventInfo->GetHitCollectionMap();
75 auto* builder = hitCollections
77 : nullptr;
78 return builder ? builder->container.get() : nullptr;
79}
This class is attached to G4Event objects as UserInformation.
std::shared_ptr< HitCollectionMap > GetHitCollectionMap() const
Get the HitCollectionMap object with shared ownership.
Event-owned holder for the FastCaloSim CaloCellContainer.
void Initialize(G4HCofThisEvent *) override final
CaloCellContainer * m_caloCellContainer
std::string m_caloCellContainerName
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
CaloCellContainer * getCaloCellContainer() const
void recordCells(TFCSSimulationState &)
CaloCellContainerSD(const std::string &name, const std::string &CaloCellContainerName)
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
void addEnergy(float energy)
add energy
Definition CaloCell.h:449