ATLAS Offline Software
Loading...
Searching...
No Matches
FCS_StepInfoSDTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <memory>
8
9// External includes
10#include "CLHEP/Units/SystemOfUnits.h"
11
12// Athena includes
21
22// Local includes
23#include "LArFCS_StepInfoSD.h"
24#include "SDWrapper.h"
25#include "TileFCS_StepInfoSD.h"
26
30
31namespace FCS_Param {
32
33//---------------------------------------------------------------------------
34// Tool constructor
35//---------------------------------------------------------------------------
37 const std::string& name,
38 const IInterface* parent)
39 : SensitiveDetectorBase(type, name, parent),
40 m_hitCollName("MergedEventSteps"),
41 m_bpsmodcalc("EMBPresamplerCalculator", name),
42 m_embcalc("EMBCalculator", name),
43 m_emepiwcalc("EMECPosInnerWheelCalculator", name),
44 m_emeniwcalc("EMECNegInnerWheelCalculator", name),
45 m_emepowcalc("EMECPosOuterWheelCalculator", name),
46 m_emenowcalc("EMECNegOuterWheelCalculator", name),
47 m_emepscalc("EMECPresamplerCalculator", name),
48 m_emepobarcalc("EMECPosBackOuterBarretteCalculator", name),
49 m_emenobarcalc("EMECNegBackOuterBarretteCalculator", name),
50 m_heccalc("HECWheelCalculator", name),
51 m_fcal1calc("FCAL1Calculator", name),
52 m_fcal2calc("FCAL2Calculator", name),
53 m_fcal3calc("FCAL3Calculator", name),
54 m_tileCalculator("TileGeoG4SDCalc", name),
55 m_larEmID(nullptr),
56 m_larFcalID(nullptr),
57 m_larHecID(nullptr),
58 m_tileID(nullptr),
59 m_config() {
60 declareProperty("HitCollectionName", m_hitCollName);
61 declareProperty("StacVolumes", m_stacVolumes);
62 declareProperty("PresamplerVolumes", m_presBarVolumes);
63 declareProperty("PosIWVolumes", m_posIWVolumes);
64 declareProperty("NegIWVolumes", m_negIWVolumes);
65 declareProperty("PosOWVolumes", m_posOWVolumes);
66 declareProperty("NegOWVolumes", m_negOWVolumes);
67 declareProperty("PresVolumes", m_presECVolumes);
68 declareProperty("PosBOBarretteVolumes", m_pBOBVolumes);
69 declareProperty("NegBOBarretteVolumes", m_nBOBVolumes);
70 declareProperty("FCAL1Volumes", m_fcal1Volumes);
71 declareProperty("FCAL2Volumes", m_fcal2Volumes);
72 declareProperty("FCAL3Volumes", m_fcal3Volumes);
73 declareProperty("SliceVolumes", m_sliceVolumes);
74 declareProperty("TileVolumes", m_tileVolumes);
75
76 declareProperty("EMBPSCalculator", m_bpsmodcalc);
77 declareProperty("EMBCalculator", m_embcalc);
78 declareProperty("EMECPosIWCalculator", m_emepiwcalc);
79 declareProperty("EMECNegIWCalculator", m_emeniwcalc);
80 declareProperty("EMECPosOWCalculator", m_emepowcalc);
81 declareProperty("EMECNegOWCalculator", m_emenowcalc);
82 declareProperty("EMECPSCalculator", m_emepscalc);
83 declareProperty("EMECPosBOBCalculator", m_emepobarcalc);
84 declareProperty("EMECNegBOBCalculator", m_emenobarcalc);
85 declareProperty("HECWActiveCalculator", m_heccalc);
86 declareProperty("FCAL1Calculator", m_fcal1calc);
87 declareProperty("FCAL2Calculator", m_fcal2calc);
88 declareProperty("FCAL3Calculator", m_fcal3calc);
89 declareProperty("TileCalculator", m_tileCalculator);
90
91 declareProperty("shift_lar_subhit", m_config.shift_lar_subhit, "");
92 declareProperty("shorten_lar_step", m_config.shorten_lar_step, "");
93
94 declareProperty("maxRadiusLateral", m_config.m_maxRadiusLateral, "");
95 declareProperty("maxRadiusLongitudinal", m_config.m_maxRadiusLongitudinal,
96 "");
97
98 declareProperty("maxTime", m_config.m_maxTime, "");
99 declareProperty("maxTimeLAr", m_config.m_maxTimeLAr, "");
100 declareProperty("maxTimeHEC", m_config.m_maxTimeHEC, "");
101 declareProperty("maxTimeFCAL", m_config.m_maxTimeFCAL, "");
102 declareProperty("maxTimeTile", m_config.m_maxTimeTile, "");
103}
104
105//---------------------------------------------------------------------------
106// Initialize the tool
107//---------------------------------------------------------------------------
109 ATH_MSG_DEBUG("Initializing " << name());
110
111 const CaloIdManager* idMgr = nullptr;
112 CHECK(detStore()->retrieve(idMgr));
113 m_larEmID = idMgr->getEM_ID();
114 if (m_larEmID == nullptr) {
115 ATH_MSG_ERROR("Invalid LAr EM ID helper");
116 return StatusCode::FAILURE;
117 }
118 m_larFcalID = idMgr->getFCAL_ID();
119 if (m_larFcalID == nullptr) {
120 ATH_MSG_ERROR("Invalid LAr FCAL ID helper");
121 return StatusCode::FAILURE;
122 }
123 m_larHecID = idMgr->getHEC_ID();
124 if (m_larHecID == nullptr) {
125 ATH_MSG_ERROR("Invalid LAr HEC ID helper");
126 return StatusCode::FAILURE;
127 }
128 m_tileID = idMgr->getTileID();
129 if (m_tileID == nullptr) {
130 ATH_MSG_ERROR("Invalid Tile ID helper");
131 return StatusCode::FAILURE;
132 }
133
134 // No general volume list for SensitiveDetectorBase
135 m_noVolumes = true;
136
138
139 return StatusCode::SUCCESS;
140}
141
142//---------------------------------------------------------------------------
143// Initialization of Athena-components
144//---------------------------------------------------------------------------
146 // Lots of calculators !!!
147 ATH_CHECK(m_bpsmodcalc.retrieve());
148 ATH_CHECK(m_embcalc.retrieve());
149 ATH_CHECK(m_emepiwcalc.retrieve());
150 ATH_CHECK(m_emeniwcalc.retrieve());
151 ATH_CHECK(m_emepowcalc.retrieve());
152 ATH_CHECK(m_emenowcalc.retrieve());
153 ATH_CHECK(m_emepscalc.retrieve());
154 ATH_CHECK(m_emepobarcalc.retrieve());
155 ATH_CHECK(m_emenobarcalc.retrieve());
156 ATH_CHECK(m_heccalc.retrieve());
157 ATH_CHECK(m_fcal1calc.retrieve());
158 ATH_CHECK(m_fcal2calc.retrieve());
159 ATH_CHECK(m_fcal3calc.retrieve());
160 ATH_CHECK(m_tileCalculator.retrieve());
161
162 return StatusCode::SUCCESS;
163}
164
165//---------------------------------------------------------------------------
166// Collect hits for this event
167//---------------------------------------------------------------------------
169 ATH_MSG_DEBUG("Gathering hits to write out in " << name());
170
171 // Retrieve it from the SD map
172 auto sdPair = m_sdThreadMap.find(std::this_thread::get_id());
173 if(sdPair == m_sdThreadMap.end()) {
174 ATH_MSG_ERROR("No FCS_StepInfoSDWrapper instance not found");
175 return StatusCode::FAILURE;
176 }
177 auto* sdWrapper = dynamic_cast<FCS_StepInfoSDWrapper*>(sdPair->second);
178 if (!sdWrapper) {
179 ATH_MSG_ERROR("Failed to cast SD to FCS_StepInfoSDWrapper");
180 return StatusCode::FAILURE;
181 }
182 sdWrapper->EndOfAthenaEvent();
183 return StatusCode::SUCCESS;
184}
185
186//---------------------------------------------------------------------------
187// Create SD wrapper for current thread
188//---------------------------------------------------------------------------
189G4VSensitiveDetector* FCS_StepInfoSDTool::makeSD() const {
190 // Create the wrapper
191 auto* sdWrapper =
192 new FCS_StepInfoSDWrapper("FCS_StepInfoSDWrapper", m_hitCollName);
193
194 // Create the SDs.
195 sdWrapper->addSD(makeOneLArSD("Barrel::Presampler::Module::StepInfo",
197 sdWrapper->addSD(
198 makeOneLArSD("EMB::STAC::StepInfo", &*m_embcalc, m_stacVolumes));
199 sdWrapper->addSD(makeOneLArSD("EMEC::Pos::InnerWheel::StepInfo",
201 sdWrapper->addSD(makeOneLArSD("EMEC::Neg::InnerWheel::StepInfo",
203 sdWrapper->addSD(makeOneLArSD("EMEC::Pos::OuterWheel::StepInfo",
205 sdWrapper->addSD(makeOneLArSD("EMEC::Neg::OuterWheel::StepInfo",
207 sdWrapper->addSD(makeOneLArSD("Endcap::Presampler::LiquidArgon::StepInfo",
209 sdWrapper->addSD(makeOneLArSD("EMEC::Pos::BackOuterBarrette::StepInfo",
211 sdWrapper->addSD(makeOneLArSD("EMEC::Neg::BackOuterBarrette::StepInfo",
213 sdWrapper->addSD(makeOneLArSD("FCAL::Module1::Gap::StepInfo", &*m_fcal1calc,
215 sdWrapper->addSD(makeOneLArSD("FCAL::Module2::Gap::StepInfo", &*m_fcal2calc,
217 sdWrapper->addSD(makeOneLArSD("FCAL::Module3::Gap::StepInfo", &*m_fcal3calc,
219 sdWrapper->addSD(makeOneLArSD("HEC::Module::Depth::Slice::Wheel::StepInfo",
221 sdWrapper->addSD(makeOneTileSD("Tile::Scintillator::StepInfo",
223
224 m_sdThreadMap.insert( std::make_pair(std::this_thread::get_id(), sdWrapper) );
225 return sdWrapper;
226}
227
228//---------------------------------------------------------------------------
229// Create one LAr SD
230//---------------------------------------------------------------------------
232 const std::string& sdName, ILArCalculatorSvc* calc,
233 const std::vector<std::string>& volumes) const {
234 ATH_MSG_VERBOSE(name() << " makeOneSD");
235
236 // Parse the wildcard patterns for existing volume names
237 auto parsedVolumes = LArG4::findLogicalVolumes(
238 volumes, msg()); // from LArG4Code/VolumeUtils.h
239
240 // Inject the Calculator into m_config
242 config.m_LArCalculator = calc;
243 if (!calc) {
244 throw GaudiException(
245 "nullptr for ILArCalculatorSvc provided to constructor for: " + sdName,
246 name(), StatusCode::FAILURE);
247 }
248 if (msgLvl(MSG::VERBOSE)) {
249 config.verboseLevel = 10;
250 } else if (msgLvl(MSG::DEBUG)) {
251 config.verboseLevel = 5;
252 }
253 // Create the simple SD
254 auto sd = std::make_unique<LArFCS_StepInfoSD>(sdName, config);
255 auto* sdPtr = sd.get();
256 sd->setupHelpers(m_larEmID, m_larFcalID, m_larHecID, m_tileID);
257
258 // Assign the volumes to the SD, this will give ownership of the pointer to Geant
259 if (this->assignSD(std::move(sd), parsedVolumes).isFailure()) {
260 // TODO: can I just return NULL here?
261 throw GaudiException("Failed to assign sd: " + sdName, name(),
262 StatusCode::FAILURE);
263 }
264 // cppcheck-suppress returnDanglingLifetime
265 return sdPtr;
266}
267
268//---------------------------------------------------------------------------
269// Create one Tile SD
270//---------------------------------------------------------------------------
272 const std::string& sdName, ITileCalculator* calc,
273 const std::vector<std::string>& volumes) const {
274 ATH_MSG_VERBOSE(name() << " makeOneSD");
275
276 // Inject the Calculator into m_config
278 config.m_TileCalculator = calc;
279 if (!calc) {
280 throw GaudiException(
281 "nullptr for ITileCalculator provided to constructor for: " + sdName,
282 name(), StatusCode::FAILURE);
283 }
284 if (msgLvl(MSG::VERBOSE)) {
285 config.verboseLevel = 10;
286 } else if (msgLvl(MSG::DEBUG)) {
287 config.verboseLevel = 5;
288 }
289 // Create the simple SD
290 auto sd = std::make_unique<TileFCS_StepInfoSD>(sdName, config);
291 auto* sdPtr = sd.get();
292 sd->setupHelpers(m_larEmID, m_larFcalID, m_larHecID, m_tileID);
293
294 // Assign the volumes to the SD, this will give ownership of the pointer to Geant
295 if (this->assignSD(std::move(sd), volumes).isFailure()) {
296 // TODO: can I just return NULL here?
297 throw GaudiException("Failed to assign sd: " + sdName, name(),
298 StatusCode::FAILURE);
299 }
300 // cppcheck-suppress returnDanglingLifetime
301 return sdPtr;
302}
303
304} // namespace FCS_Param
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
FCS_Param::detail::SDWrapper< FCS_StepInfoSD, ISF_FCS_Parametrization::FCS_StepInfoCollection > FCS_StepInfoSDWrapper
Template instantiation for FCS_StepInfoSD.
Defines the FCS_StepInfoSDTool class.
Standalone functions for dealing with LAr G4 volumes.
This class initializes the Calo (LAr and Tile) offline identifiers.
const TileID * getTileID(void) const
const LArHEC_ID * getHEC_ID(void) const
const LArFCAL_ID * getFCAL_ID(void) const
const LArEM_ID * getEM_ID(void) const
std::vector< std::string > m_tileVolumes
std::string m_hitCollName
Hit collection name.
FCS_StepInfoSD * makeOneTileSD(const std::string &name, ITileCalculator *calc, const std::vector< std::string > &volumes) const
Helper method to create one SD.
ServiceHandle< ILArCalculatorSvc > m_emepobarcalc
std::vector< std::string > m_fcal3Volumes
std::vector< std::string > m_posOWVolumes
ServiceHandle< ILArCalculatorSvc > m_fcal2calc
std::vector< std::string > m_presECVolumes
std::vector< std::string > m_nBOBVolumes
std::vector< std::string > m_stacVolumes
G4VSensitiveDetector * makeSD() const override final
Create the SD wrapper for current worker thread.
ServiceHandle< ILArCalculatorSvc > m_bpsmodcalc
ServiceHandle< ILArCalculatorSvc > m_emepowcalc
ServiceHandle< ILArCalculatorSvc > m_emepscalc
ServiceHandle< ILArCalculatorSvc > m_fcal3calc
FCS_StepInfoSD * makeOneLArSD(const std::string &name, ILArCalculatorSvc *calc, const std::vector< std::string > &volumes) const
Helper method to create one SD.
std::vector< std::string > m_pBOBVolumes
StatusCode Gather(HitCollectionMap &) override final
Calls down to all the SDs to pack their hits into one collection.
ServiceHandle< ILArCalculatorSvc > m_emenowcalc
ServiceHandle< ILArCalculatorSvc > m_emepiwcalc
FCS_StepInfoSDTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
std::vector< std::string > m_sliceVolumes
ServiceHandle< ITileCalculator > m_tileCalculator
std::vector< std::string > m_fcal1Volumes
ServiceHandle< ILArCalculatorSvc > m_emeniwcalc
virtual StatusCode initializeCalculators()
Initialize Calculator Services.
std::vector< std::string > m_fcal2Volumes
std::vector< std::string > m_presBarVolumes
std::vector< std::string > m_negIWVolumes
std::vector< std::string > m_negOWVolumes
ServiceHandle< ILArCalculatorSvc > m_fcal1calc
ServiceHandle< ILArCalculatorSvc > m_embcalc
StatusCode initialize() override final
Initialize the tool.
ServiceHandle< ILArCalculatorSvc > m_emenobarcalc
std::vector< std::string > m_posIWVolumes
ServiceHandle< ILArCalculatorSvc > m_heccalc
A template class which wraps multiple sensitive detectors.
Definition SDWrapper.h:47
Common sensitive detector class for LAr systems.
Small wrapper around hit collection map to facilitate accessing the hit collection.
Class for collection of StepInfo class (G4 hits) copied and modified version to ISF.
StatusCode assignSD(std::unique_ptr< G4VSensitiveDetector > sd, const std::vector< std::string > &volumes) const
Assign SD to a list of volumes.
Gaudi::Property< bool > m_noVolumes
This SensitiveDetector has no volumes associated with it.
SensitiveDetectorBase(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
detail::SDWrapper< FCS_StepInfoSD, ISF_FCS_Parametrization::FCS_StepInfoCollection > FCS_StepInfoSDWrapper
Template instantiation for LArG4SimpleSD.
Definition SDWrapper.h:83
std::set< std::string > findLogicalVolumes(const std::string &pattern)
Search for logical volumes in the G4 volume store.
MsgStream & msg
Definition testRead.cxx:32