Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
// Class header
#include "ISF_FastCaloSimParametrization/CaloCellContainerSD.h"
// Athena headers
#include "MCTruth/TrackHelper.h"
// FastCaloSim simulation include
#include "ISF_FastCaloSimEvent/TFCSSimulationState.h"
CaloCellContainerSD::CaloCellContainerSD(const std::string& name, const std::string& CaloCellContainerName, PublicToolHandle<FastHitConvertTool> FastHitConvertTool)
: G4VSensitiveDetector( name ),
m_EmptyCellBuilderTool("EmptyCellBuilderTool/EmptyCellBuilderTool"),
m_caloCellContainer (CaloCellContainerName),
m_FastHitConvertTool (FastHitConvertTool)
{
if(m_EmptyCellBuilderTool.retrieve().isFailure()) {
G4Exception("CaloCellContainerSD", "FailedEmptyCellBuilderToolRetrieval", FatalException, "CaloCellContainerSD: Failed to retrieve the empty cell builder tool.");
abort();
}
}
void CaloCellContainerSD::StartOfAthenaEvent(const EventContext& ctx){
if (!m_caloCellContainer.isValid()) m_caloCellContainer = std::make_unique<CaloCellContainer>(SG::VIEW_ELEMENTS);
//Initialize cell container with empty cells
if(m_EmptyCellBuilderTool->process(&*m_caloCellContainer, ctx).isFailure()){
G4Exception("CaloCellContainerSD", "FailedEmptyCellBuilderToolProcess", FatalException, "CaloCellContainerSD: Failed to process calo cell container with the empty cell builder tool.");
abort();
}
return;
}
void CaloCellContainerSD::EndOfAthenaEvent(const EventContext& ctx){
// Update the calo iterators of the calo cell container
m_caloCellContainer->updateCaloIterators();
// Convert FastCaloSim hits into HitCollections, taking into account sampling fractions
if(m_FastHitConvertTool->process(&*m_caloCellContainer, ctx).isFailure()){
G4Exception("CaloCellContainerSD", "FailedFastHitConvertToolProcess", FatalException, "CaloCellContainerSD: Failed to process calo cell container with the fast hit convert tool.");
abort();
}
return;
}
G4bool CaloCellContainerSD::ProcessHits(G4Step*, G4TouchableHistory* ){
// This method needs to be implemented when deriving from G4VSensitiveDetector has no use in this case
G4Exception("CaloCellContainerSD", "UndefinedProcessHitsCall", FatalException, "CaloCellContainerSD: Call to undefined ProcessHits.");
abort();
return true;
}
void CaloCellContainerSD::recordCells(TFCSSimulationState& simState)
{
// Add the energies from the simulation state to the CaloCellContainer
for(const auto& icell : simState.cells()) {
CaloCell* caloCell = (CaloCell*)m_caloCellContainer->findCell(icell.first->calo_hash());
caloCell->addEnergy(icell.second);
}
}