ATLAS Offline Software
Loading...
Searching...
No Matches
ActsPropStepRootWriterSvc Class Reference

#include <ActsPropStepRootWriterSvc.h>

Inheritance diagram for ActsPropStepRootWriterSvc:
Collaboration diagram for ActsPropStepRootWriterSvc:

Public Types

using StepVector = std::vector<Acts::detail::Step>

Public Member Functions

virtual StatusCode initialize () override
virtual StatusCode finalize () override
 ActsPropStepRootWriterSvc (const std::string &name, ISvcLocator *svc)
void write (const StepVector &steps) override

Private Types

using queue_item_t = std::pair<size_t, StepVector>

Private Member Functions

void writeThread ()
void doWrite (const StepVector &steps, size_t evtNum)
void end ()

Private Attributes

std::deque< queue_item_tm_queue
std::mutex m_writeMutex
std::thread m_writeThread
std::atomic< bool > m_doEnd
Gaudi::Property< std::string > m_filePath {this, "FilePath", "propsteps.root", "Output root file for charged particle"}
Gaudi::Property< std::string > m_treeName {this, "TreeName", "propsteps", ""}
TFile * m_outputFile {}
 the output file
TTree * m_outputTree {}
 the output tree
int m_eventNum {}
std::vector< float > m_s_pX
 global position x of the step
std::vector< float > m_s_pY
 global position y of the step
std::vector< float > m_s_pZ
 global position z of the step
std::vector< float > m_s_pR
 global position z of the step
std::vector< int > m_s_volumeID
 volume identification
std::vector< int > m_s_boundaryID
 boundary identification
std::vector< int > m_s_layerID
 layer identification
std::vector< int > m_s_approachID
 approach identification
std::vector< int > m_s_sensitiveID
 sensitive identification

Detailed Description

Definition at line 37 of file ActsPropStepRootWriterSvc.h.

Member Typedef Documentation

◆ queue_item_t

using ActsPropStepRootWriterSvc::queue_item_t = std::pair<size_t, StepVector>
private

Definition at line 51 of file ActsPropStepRootWriterSvc.h.

◆ StepVector

using ActsPropStepRootWriterSvc::StepVector = std::vector<Acts::detail::Step>

Definition at line 45 of file ActsPropStepRootWriterSvc.h.

Constructor & Destructor Documentation

◆ ActsPropStepRootWriterSvc()

ActsPropStepRootWriterSvc::ActsPropStepRootWriterSvc ( const std::string & name,
ISvcLocator * svc )

Definition at line 21 of file ActsPropStepRootWriterSvc.cxx.

22: base_class(name, svc) {
23}

Member Function Documentation

◆ doWrite()

void ActsPropStepRootWriterSvc::doWrite ( const StepVector & steps,
size_t evtNum )
private

Definition at line 120 of file ActsPropStepRootWriterSvc.cxx.

121{
122 m_eventNum = evtNum;
123 m_s_pX.clear();
124 m_s_pY.clear();
125 m_s_pZ.clear();
126 m_s_pR.clear();
127 m_s_volumeID.clear();
128 m_s_boundaryID.clear();
129 m_s_layerID.clear();
130 m_s_approachID.clear();
131 m_s_sensitiveID.clear();
132
133 for(const auto& step : steps) {
134 Acts::GeometryIdentifier::Value volumeID = 0;
135 Acts::GeometryIdentifier::Value boundaryID = 0;
136 Acts::GeometryIdentifier::Value layerID = 0;
137 Acts::GeometryIdentifier::Value approachID = 0;
138 Acts::GeometryIdentifier::Value sensitiveID = 0;
139 // get the identification from the surface first
140 if (step.surface) {
141 auto geoID = step.surface->geometryId();
142 sensitiveID = geoID.sensitive();
143 approachID = geoID.approach();
144 layerID = geoID.layer();
145 boundaryID = geoID.boundary();
146 volumeID = geoID.volume();
147 }
148 // a current volume overwrites the surface tagged one
149 if (step.geoID != Acts::GeometryIdentifier()) {
150 volumeID = step.geoID.volume();
151 }
152 // now fill
153 m_s_sensitiveID.push_back(sensitiveID);
154 m_s_approachID.push_back(approachID);
155 m_s_layerID.push_back(layerID);
156 m_s_boundaryID.push_back(boundaryID);
157 m_s_volumeID.push_back(volumeID);
158
159 m_s_pX.push_back(step.position.x());
160 m_s_pY.push_back(step.position.y());
161 m_s_pZ.push_back(step.position.z());
162 m_s_pR.push_back(Acts::VectorHelpers::perp(step.position));
163 }
164
165 m_outputTree->Fill();
166}
std::vector< int > m_s_boundaryID
boundary identification
std::vector< float > m_s_pR
global position z of the step
TTree * m_outputTree
the output tree
std::vector< int > m_s_volumeID
volume identification
std::vector< float > m_s_pZ
global position z of the step
std::vector< int > m_s_approachID
approach identification
std::vector< float > m_s_pX
global position x of the step
std::vector< int > m_s_layerID
layer identification
std::vector< int > m_s_sensitiveID
sensitive identification
std::vector< float > m_s_pY
global position y of the step

◆ end()

void ActsPropStepRootWriterSvc::end ( )
private

Definition at line 169 of file ActsPropStepRootWriterSvc.cxx.

170{
171 m_outputFile->cd();
172 m_outputTree->Write();
173 //m_outputFile->Close();
174}
TFile * m_outputFile
the output file

◆ finalize()

StatusCode ActsPropStepRootWriterSvc::finalize ( )
overridevirtual

Definition at line 60 of file ActsPropStepRootWriterSvc.cxx.

61{
62 end();
63
64 return StatusCode::SUCCESS;
65}

◆ initialize()

StatusCode ActsPropStepRootWriterSvc::initialize ( )
overridevirtual

Definition at line 26 of file ActsPropStepRootWriterSvc.cxx.

27{
28
29 std::string filePath = m_filePath;
30 m_outputFile = TFile::Open(filePath.c_str(), "RECREATE");
31 if(m_outputFile == nullptr) {
32 ATH_MSG_ERROR("Unable to open output file at " << m_filePath);
33 return StatusCode::FAILURE;
34 }
35 m_outputFile->cd();
36
37 std::string treeName = m_treeName;
38 m_outputTree = new TTree(treeName.c_str(), "Acts Propagation Steps");
39 if(m_outputTree == nullptr) {
40 ATH_MSG_ERROR("Unable to create TTree");
41 return StatusCode::FAILURE;
42 }
43
44 m_outputTree->Branch("event_nr", &m_eventNum);
45 m_outputTree->Branch("step_x", &m_s_pX);
46 m_outputTree->Branch("step_y", &m_s_pY);
47 m_outputTree->Branch("step_z", &m_s_pZ);
48 m_outputTree->Branch("step_r", &m_s_pR);
49 m_outputTree->Branch("volume_id", &m_s_volumeID);
50 m_outputTree->Branch("boundary_id", &m_s_boundaryID);
51 m_outputTree->Branch("layer_id", &m_s_layerID);
52 m_outputTree->Branch("approach_id", &m_s_approachID);
53 m_outputTree->Branch("sensitive_id", &m_s_sensitiveID);
54
55
56 return StatusCode::SUCCESS;
57}
#define ATH_MSG_ERROR(x)
Gaudi::Property< std::string > m_filePath
Gaudi::Property< std::string > m_treeName
str filePath
Definition hancool.py:27

◆ write()

void ActsPropStepRootWriterSvc::write ( const StepVector & steps)
override

Definition at line 68 of file ActsPropStepRootWriterSvc.cxx.

69{
70
71 const auto& ctx = Gaudi::Hive::currentContext();
72
73 std::lock_guard<std::mutex> lock(m_writeMutex);
74
75 //for(size_t i=0;i<ecells.size();++i) {
76 //m_queue.emplace_back(ctx.eventID().event_number(), std::move(ecells[i]));
77 //}
78 doWrite(steps, ctx.eventID().event_number());
79}
void doWrite(const StepVector &steps, size_t evtNum)

◆ writeThread()

void ActsPropStepRootWriterSvc::writeThread ( )
private

Definition at line 82 of file ActsPropStepRootWriterSvc.cxx.

83{
84 using namespace std::chrono_literals;
85 // wait until we have events
86 while(m_queue.empty()) {
87 std::this_thread::sleep_for(2s);
88 if (m_doEnd) return;
89 }
90
91 while(true) {
92 std::unique_lock<std::mutex> lock(m_writeMutex);
93
94 if (m_queue.empty()) {
95 lock.unlock();
96 if (!m_doEnd) {
97 std::this_thread::sleep_for(0.5s);
98 continue;
99 } else {
100 ATH_MSG_INFO("Writer thread caught termination signal. Shutting down.");
101 end();
102 return;
103 }
104 }
105
106 queue_item_t queue_item = std::move(m_queue.front());
107 m_queue.pop_front();
108
109 lock.unlock();
110
111 size_t eventNum = queue_item.first;
112 StepVector steps = std::move(queue_item.second);
113
114 doWrite(steps, eventNum);
115 }
116
117}
#define ATH_MSG_INFO(x)
std::deque< queue_item_t > m_queue
std::vector< Acts::detail::Step > StepVector
std::pair< size_t, StepVector > queue_item_t

Member Data Documentation

◆ m_doEnd

std::atomic<bool> ActsPropStepRootWriterSvc::m_doEnd
private

Definition at line 57 of file ActsPropStepRootWriterSvc.h.

◆ m_eventNum

int ActsPropStepRootWriterSvc::m_eventNum {}
private

Definition at line 74 of file ActsPropStepRootWriterSvc.h.

74{};

◆ m_filePath

Gaudi::Property<std::string> ActsPropStepRootWriterSvc::m_filePath {this, "FilePath", "propsteps.root", "Output root file for charged particle"}
private

Definition at line 64 of file ActsPropStepRootWriterSvc.h.

64{this, "FilePath", "propsteps.root", "Output root file for charged particle"};

◆ m_outputFile

TFile* ActsPropStepRootWriterSvc::m_outputFile {}
private

the output file

Definition at line 72 of file ActsPropStepRootWriterSvc.h.

72{};

◆ m_outputTree

TTree* ActsPropStepRootWriterSvc::m_outputTree {}
private

the output tree

Definition at line 73 of file ActsPropStepRootWriterSvc.h.

73{};

◆ m_queue

std::deque<queue_item_t> ActsPropStepRootWriterSvc::m_queue
private

Definition at line 54 of file ActsPropStepRootWriterSvc.h.

◆ m_s_approachID

std::vector<int> ActsPropStepRootWriterSvc::m_s_approachID
private

approach identification

Definition at line 82 of file ActsPropStepRootWriterSvc.h.

◆ m_s_boundaryID

std::vector<int> ActsPropStepRootWriterSvc::m_s_boundaryID
private

boundary identification

Definition at line 80 of file ActsPropStepRootWriterSvc.h.

◆ m_s_layerID

std::vector<int> ActsPropStepRootWriterSvc::m_s_layerID
private

layer identification

Definition at line 81 of file ActsPropStepRootWriterSvc.h.

◆ m_s_pR

std::vector<float> ActsPropStepRootWriterSvc::m_s_pR
private

global position z of the step

Definition at line 78 of file ActsPropStepRootWriterSvc.h.

◆ m_s_pX

std::vector<float> ActsPropStepRootWriterSvc::m_s_pX
private

global position x of the step

Definition at line 75 of file ActsPropStepRootWriterSvc.h.

◆ m_s_pY

std::vector<float> ActsPropStepRootWriterSvc::m_s_pY
private

global position y of the step

Definition at line 76 of file ActsPropStepRootWriterSvc.h.

◆ m_s_pZ

std::vector<float> ActsPropStepRootWriterSvc::m_s_pZ
private

global position z of the step

Definition at line 77 of file ActsPropStepRootWriterSvc.h.

◆ m_s_sensitiveID

std::vector<int> ActsPropStepRootWriterSvc::m_s_sensitiveID
private

sensitive identification

Definition at line 83 of file ActsPropStepRootWriterSvc.h.

◆ m_s_volumeID

std::vector<int> ActsPropStepRootWriterSvc::m_s_volumeID
private

volume identification

Definition at line 79 of file ActsPropStepRootWriterSvc.h.

◆ m_treeName

Gaudi::Property<std::string> ActsPropStepRootWriterSvc::m_treeName {this, "TreeName", "propsteps", ""}
private

Definition at line 65 of file ActsPropStepRootWriterSvc.h.

65{this, "TreeName", "propsteps", ""};

◆ m_writeMutex

std::mutex ActsPropStepRootWriterSvc::m_writeMutex
private

Definition at line 55 of file ActsPropStepRootWriterSvc.h.

◆ m_writeThread

std::thread ActsPropStepRootWriterSvc::m_writeThread
private

Definition at line 56 of file ActsPropStepRootWriterSvc.h.


The documentation for this class was generated from the following files: