ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellContainerSDTool.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
6// Header include
8
9// CaloCellContainer sensitive detector
12
15
16#include <memory>
17
18CaloCellContainerSDTool::CaloCellContainerSDTool(const std::string& type, const std::string& name, const IInterface* parent)
19 : SensitiveDetectorBase( type , name , parent ),
20 m_EmptyCellBuilderTool("EmptyCellBuilderTool/EmptyCellBuilderTool"),
21 m_FastHitConvertTool ("FastHitConvertTool/FastHitConvertTool")
22{
23 declareProperty ("EmptyCellBuilderTool", m_EmptyCellBuilderTool, "EmptyCellBuilderTool");
24 declareProperty ("FastHitConvertTool", m_FastHitConvertTool, "FastHitConvertTool");
25}
26
28{
31 return StatusCode::SUCCESS;
32}
33
35{
36 // Get current event context
37 const EventContext& ctx = Gaudi::Hive::currentContext();
38
39 const std::string& collectionName = m_outputCollectionNames[0];
40 hitCollections.Emplace<CaloCellContainerBuilder>(collectionName);
41 auto* builder = hitCollections.Find<CaloCellContainerBuilder>(collectionName);
42 if (!builder) {
43 ATH_MSG_ERROR("SetupEvent: Failed to create CaloCellContainerBuilder.");
44 return StatusCode::FAILURE;
45 }
46
47 // Initialize cell container with empty cells.
48 if(m_EmptyCellBuilderTool->process(builder->container.get(), ctx).isFailure()){
49 ATH_MSG_ERROR("SetupEvent: Failed to process calo cell container with the empty cell builder tool.");
50 return StatusCode::FAILURE;
51 }
52
53 return StatusCode::SUCCESS;
54}
55
57{
58 // Get current event context
59 const EventContext& ctx = Gaudi::Hive::currentContext();
60
61 const std::string& collectionName = m_outputCollectionNames[0];
62 std::unique_ptr<CaloCellContainerBuilder> builder =
63 hitCollections.Extract<CaloCellContainerBuilder>(collectionName);
64 if (!builder || !builder->container) {
65 ATH_MSG_ERROR("Gather: Failed to retrieve CaloCellContainerBuilder.");
66 return StatusCode::FAILURE;
67 }
68
69 // Update the calo iterators of the calo cell container.
70 builder->container->updateCaloIterators();
71
72 // Convert FastCaloSim hits into HitCollections, taking into account sampling fractions.
73 if(m_FastHitConvertTool->process(builder->container.get(), ctx).isFailure()){
74 ATH_MSG_ERROR("Gather: Failed to process calo cell container with the fast hit convert tool.");
75 return StatusCode::FAILURE;
76 }
77
78 SG::WriteHandle<CaloCellContainer> handle{collectionName, ctx};
79 ATH_CHECK(handle.record(std::move(builder->container)));
80 return StatusCode::SUCCESS;
81}
82
83G4VSensitiveDetector* CaloCellContainerSDTool::makeSD() const
84{
85 ATH_MSG_DEBUG( "Initializing SD" );
86
87 // Create a fresh SD
88 return new CaloCellContainerSD(name(), m_outputCollectionNames[0]);
89}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
Handle class for recording to StoreGate.
Event-owned holder for the FastCaloSim CaloCellContainer.
G4VSensitiveDetector * makeSD() const override final
PublicToolHandle< ICaloCellMakerTool > m_EmptyCellBuilderTool
StatusCode initialize() override final
PublicToolHandle< ICaloCellMakerTool > m_FastHitConvertTool
CaloCellContainerSDTool(const std::string &type, const std::string &name, const IInterface *parent)
Small wrapper around hit collection map to facilitate accessing the hit collection.
T * Find(std::string const &hitCollectionName)
Get the hit collection for a given SDs.
std::unique_ptr< T > Extract(std::string const &hitCollectionName)
Extract the hit collection for a given SDs downcasted to the template parameter.
std::pair< StorageIterator, bool > Emplace(std::string const &hitCollectionName, CollectionArgs &&... args)
Insert a container in the map with in-place construction.
virtual StatusCode Gather() override
End of an athena event.
virtual StatusCode SetupEvent() override
Beginning of an athena event.
Gaudi::Property< std::vector< std::string > > m_outputCollectionNames
Names of all output collections written out by this SD.
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.