ATLAS Offline Software
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 
17 CaloCellContainerSD::CaloCellContainerSD(const std::string& name, const std::string& CaloCellContainerName, PublicToolHandle<ICaloCellMakerTool> FastHitConvertTool)
18  : G4VSensitiveDetector( name ),
19  m_EmptyCellBuilderTool("EmptyCellBuilderTool/EmptyCellBuilderTool"),
20  m_caloCellContainer (CaloCellContainerName),
21  m_FastHitConvertTool (std::move(FastHitConvertTool))
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 
30 void 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 
43 void CaloCellContainerSD::EndOfAthenaEvent(const EventContext& ctx){
44 
45  // Update the calo iterators of the calo cell container
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 
57 G4bool 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 }
CaloCellContainerSD::CaloCellContainerSD
CaloCellContainerSD(const std::string &name, const std::string &CaloCellContainerName, PublicToolHandle< ICaloCellMakerTool > FastHitConvertTool)
Definition: CaloCellContainerSD.cxx:17
CaloCellContainerSD.h
FastHitConvertTool
Definition: FastHitConvertTool.h:44
WriteCellNoiseToCool.icell
icell
Definition: WriteCellNoiseToCool.py:339
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
TFCSSimulationState::cells
Cellmap_t & cells()
Definition: TFCSSimulationState.h:72
CaloCellContainerSD::recordCells
void recordCells(TFCSSimulationState &)
Definition: CaloCellContainerSD.cxx:65
TrackHelper.h
CaloCellContainerSD::m_EmptyCellBuilderTool
PublicToolHandle< ICaloCellMakerTool > m_EmptyCellBuilderTool
Definition: CaloCellContainerSD.h:41
CaloCellContainerSD::m_caloCellContainer
SG::WriteHandle< CaloCellContainer > m_caloCellContainer
Definition: CaloCellContainerSD.h:43
CaloCellContainerSD::m_FastHitConvertTool
PublicToolHandle< ICaloCellMakerTool > m_FastHitConvertTool
Definition: CaloCellContainerSD.h:45
CaloCellContainerSD::ProcessHits
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override final
Definition: CaloCellContainerSD.cxx:57
CaloCellContainerSD::EndOfAthenaEvent
void EndOfAthenaEvent(const EventContext &ctx)
Definition: CaloCellContainerSD.cxx:43
TBMuToCaloAlg_jobOptions.CaloCellContainerName
CaloCellContainerName
Definition: TBMuToCaloAlg_jobOptions.py:9
CaloCellContainer::findCell
const CaloCell * findCell(const IdentifierHash theHash) const
fast find method given identifier hash.
Definition: CaloCellContainer.cxx:345
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CaloCellContainerSD::StartOfAthenaEvent
void StartOfAthenaEvent(const EventContext &ctx)
Definition: CaloCellContainerSD.cxx:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloCellContainer::updateCaloIterators
void updateCaloIterators()
fill calo iterators and the index of first and last cell IT IS THE RESPONSABILITY OF THE PRODUCER TO ...
Definition: CaloCellContainer.cxx:268
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
TFCSSimulationState.h
CaloCell::addEnergy
virtual void addEnergy(float energy)
add energy
Definition: CaloCell.cxx:141
TFCSSimulationState
Definition: TFCSSimulationState.h:32