ATLAS Offline Software
Loading...
Searching...
No Matches
MaterialTrackWriter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "GaudiKernel/IInterface.h"
8
9#include <format>
10#include "TTree.h"
11#include "TFile.h"
12
13
14namespace ActsTrk{
16
18 // Check the input collection key
20
21 m_outputTree = new TTree(m_treeName.value().c_str(), "TTree from MaterialTrackWriter");
22 Config_t cfg{};
23 cfg.prePostStepInfo = m_prePostStep;
24 cfg.surfaceInfo = m_storeSurface;
25 cfg.volumeInfo = m_storeVolume;
26 cfg.recalculateTotals = m_recalculateTotals;
27
28 m_accessor = ActsPlugins::RootMaterialTrackIo{cfg};
29 m_accessor.connectForWrite(*m_outputTree);
30 ATH_CHECK(histSvc()->regTree(std::format("/{:}/{:}", m_outStream.value(), m_treeName.value()), m_outputTree));
31
32 ATH_CHECK(m_trackingGeometryTool.retrieve(EnableTool{m_useTrackingGeo}));
33
34 return StatusCode::SUCCESS;
35}
36
38 const EventContext& ctx = Gaudi::Hive::currentContext();
39 // Get the collection from storegate
40 const RecordedMaterialTrackCollection* materialTracks{nullptr};
41 ATH_CHECK(SG::get(materialTracks, m_materialTrackCollectionKey, ctx));
42
43 const Acts::GeometryContext geoContext = m_useTrackingGeo ?
44 m_trackingGeometryTool->getGeometryContext(ctx).context()
45 : Acts::GeometryContext::dangerouslyDefaultConstruct();
46 std::unique_lock lock{m_writeMutex};
47
48 // Loop over the material tracks and write them out
49 for (const auto& materialTrack : *materialTracks) {
50 // write & fill
51 m_accessor.write(geoContext, ctx.evt(), materialTrack);
52 m_outputTree->Fill();
53 }
54
55 // return success
56 return StatusCode::SUCCESS;
57}
58}
#define ATH_CHECK
Evaluate an expression and check for errors.
Gaudi::Property< std::string > m_outStream
The output file name.
virtual StatusCode initialize() override
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
The tracking geometry service to retrive the geometry context.
Gaudi::Property< std::string > m_treeName
The output file name.
Gaudi::Property< bool > m_recalculateTotals
Re-calculate total values from individual steps (for cross-checks)
Gaudi::Property< bool > m_useTrackingGeo
SG::ReadHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to read.
virtual StatusCode execute() override
ActsPlugins::RootMaterialTrackIo::Config Config_t
Gaudi::Property< bool > m_storeVolume
Write the volume to which the material step correpond.
ActsPlugins::RootMaterialTrackIo m_accessor
The read - write payload.
Gaudi::Property< bool > m_storeSurface
Write the surface to which the material step correpond.
TTree * m_outputTree
The output file and tree.
std::mutex m_writeMutex
mutex used to protect multi-threaded writes
Gaudi::Property< bool > m_prePostStep
Write out pre and post step (for G4), otherwise central step position.
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
std::vector< Acts::RecordedMaterialTrack > RecordedMaterialTrackCollection
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.