ATLAS Offline Software
Loading...
Searching...
No Matches
SDWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "SDWrapper.h"
6
7// Geant4 includes
8#include "G4SDManager.hh"
9
10// Framework utilities
11
12// Project includes
14
15// Local includes
16#include "FCS_StepInfoSD.h"
17
18namespace FCS_Param {
19
20namespace detail {
21
22//-------------------------------------------------------------------------
23// Construct with a hit collection name
24//-------------------------------------------------------------------------
25template <class SDType, class HitContainerType>
27 const std::string& name, const std::string& hitCollectionName)
28 : G4VSensitiveDetector(name),
29 m_hitCollName(hitCollectionName),
30 m_hitColl(hitCollectionName) {}
31
32//-------------------------------------------------------------------------
33// Add a unique SD to the list
34//-------------------------------------------------------------------------
35template <class SDType, class HitContainerType>
37 m_sdList.push_back(sd);
38}
39
40//-------------------------------------------------------------------------
41// Initialize the hit collection at the beginning of the G4 event
42//-------------------------------------------------------------------------
43template <class SDType, class HitContainerType>
45 if (!m_hitColl.isValid()) {
46 if (verboseLevel >= 5) {
47 G4cout << GetName() << " \tDEBUG\t"
48 << "Initializing hit container: " << m_hitCollName << G4endl;
49 }
50 m_hitColl = std::make_unique<HitContainerType>();
51 }
52}
53
54//-------------------------------------------------------------------------
55// This should not be called
56//-------------------------------------------------------------------------
57template <class SDType, class HitContainerType>
59 G4TouchableHistory*) {
60 G4ExceptionDescription description;
61 description << "ProcessHits: this SD shouldn't be assigned to volumes!";
62 G4Exception(GetName(), "SDError", FatalException, description);
63 return false;
64}
65
66//-------------------------------------------------------------------------
67// Gather the hits into the WriteHandle from all the SDs
68//-------------------------------------------------------------------------
69template <class SDType, class HitContainerType>
71 if (!m_hitColl.isValid()) {
72 G4cerr << GetName() << " \tERROR\t" << "Hit collection WriteHandle is "
73 << "invalid!" << G4endl;
74 throw std::runtime_error("Invalid hit container WriteHandle: " +
75 m_hitColl.name());
76 }
77 // Loop over each SD and fill the container
78 for (auto& sd : m_sdList) {
79 sd->EndOfAthenaEvent(&*m_hitColl);
80 }
81}
82
83//-------------------------------------------------------------------------
84// Explit template instantiations
85//-------------------------------------------------------------------------
86template class SDWrapper<FCS_StepInfoSD,
88
89} // namespace detail
90
91} // namespace FCS_Param
A template class which wraps multiple sensitive detectors.
virtual bool ProcessHits(G4Step *, G4TouchableHistory *) override final
This method should not be called. It will throw.
Definition SDWrapper.cxx:58
virtual void Initialize(G4HCofThisEvent *) override final
Beginning of G4 event; initialize the hit collection.
Definition SDWrapper.cxx:44
SDWrapper(const std::string &name, const std::string &hitCollectionName)
Construct the wrapper from the output collection name.
Definition SDWrapper.cxx:26
void EndOfAthenaEvent()
Gather the hits into the WriteHandle from all the SDs.
Definition SDWrapper.cxx:70
SDList_t m_sdList
The list of sensitive detectors that I own and manage.
void addSD(SDType *sd)
Add an SD to this wrapper.
Definition SDWrapper.cxx:36
SG::WriteHandle< HitContainerType > m_hitColl
The hit container handle.
Common sensitive detector class for LAr systems.
Class for collection of StepInfo class (G4 hits) copied and modified version to ISF.
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91