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));
32
33 return StatusCode::SUCCESS;
34}
35
36StatusCode MaterialTrackWriter::execute (const EventContext& ctx) {
37 // Get the collection from storegate
38 const RecordedMaterialTrackCollection* materialTracks{nullptr};
39 ATH_CHECK(SG::get(materialTracks, m_materialTrackCollectionKey, ctx));
40
41 const Acts::GeometryContext geoContext = m_useTrackingGeo ?
42 m_ctxProvider.getGeometryContext(ctx)
43 : Acts::GeometryContext::dangerouslyDefaultConstruct();
44 std::unique_lock lock{m_writeMutex};
45
46 // Loop over the material tracks and write them out
47 for (const auto& materialTrack : *materialTracks) {
48 // write & fill
49 m_accessor.write(geoContext, ctx.evt(), materialTrack);
50 m_outputTree->Fill();
51 }
52
53 // return success
54 return StatusCode::SUCCESS;
55}
56}
#define ATH_CHECK
Evaluate an expression and check for errors.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Gaudi::Property< std::string > m_outStream
The output file name.
virtual StatusCode initialize() override
ContextUtility m_ctxProvider
Context provider for geometry, magnetic field and calibration contexts.
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.
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
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
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.