LDMX Software
Classes | Public Member Functions | Protected Attributes | List of all members
tracking::sim::PropagatorStepWriter Class Reference

Classes

struct  Config
 

Public Member Functions

 PropagatorStepWriter (const Config &cfg)
 Constructor with.
 
 ~PropagatorStepWriter ()
 
bool WriteSteps (framework::Event &event, const std::vector< PropagationSteps > &stepCollection, const std::vector< ldmx::Measurement > &measurements, const Acts::Vector3 &start_pos, const Acts::Vector3 &start_mom)
 

Protected Attributes

Config m_cfg
 the configuration object
 
std::mutex m_writeMutex
 protect multi-threaded writes
 
TFile * m_outputFile
 the output file name
 
TTree * m_outputTree
 the output tree
 
int m_eventNr
 the event number of
 
std::vector< int > m_boundaryID
 boundary identifier
 
std::vector< int > m_layerID
 layer identifier if
 
std::vector< int > m_approachID
 surface identifier
 
std::vector< int > m_sensitiveID
 surface identifier
 
std::vector< float > m_x
 global x
 
std::vector< float > m_y
 global y
 
std::vector< float > m_z
 global z
 
std::vector< float > m_dx
 global direction x
 
std::vector< float > m_dy
 global direction y
 
std::vector< float > m_dz
 global direction z
 
std::vector< int > m_step_type
 step type
 
std::vector< float > m_step_acc
 accuracy
 
std::vector< float > m_step_act
 actor check
 
std::vector< float > m_step_abt
 aborter
 
std::vector< float > m_step_usr
 user
 
std::vector< float > m_hit_x
 hit location X
 
std::vector< float > m_hit_y
 hit location Y
 
std::vector< float > m_hit_z
 hit location Z
 
std::vector< float > m_start_pos
 start position of the particle propagated
 
std::vector< float > m_start_mom
 start momentum of the particle propagated
 

Detailed Description

Definition at line 29 of file PropagatorStepWriter.h.

Constructor & Destructor Documentation

◆ PropagatorStepWriter()

tracking::sim::PropagatorStepWriter::PropagatorStepWriter ( const Config cfg)

Constructor with.

Parameters
cfgconfiguration struct
outputlogging level

Definition at line 17 of file PropagatorStepWriter.cxx.

19 : m_cfg(cfg), m_outputFile(cfg.rootFile) {
20 if (m_cfg.treeName.empty()) {
21 throw std::invalid_argument("Missing tree name");
22 }
23
24 // Setup ROOT I/O
25 if (m_outputFile == nullptr) {
26 m_outputFile = TFile::Open(m_cfg.filePath.c_str(), m_cfg.fileMode.c_str());
27 if (m_outputFile == nullptr) {
28 throw std::ios_base::failure("Could not open '" + m_cfg.filePath);
29 }
30 }
31 m_outputFile->cd();
32
33 m_outputTree = new TTree(m_cfg.treeName.c_str(),
34 "TTree from RootPropagationStepsWriter");
35 if (m_outputTree == nullptr) throw std::bad_alloc();
36
37 // Set the branches
38 m_outputTree->Branch("event_nr", &m_eventNr);
39 // m_outputTree->Branch("volume_id", &m_volumeID);
40 m_outputTree->Branch("boundary_id", &m_boundaryID);
41 m_outputTree->Branch("layer_id", &m_layerID);
42 m_outputTree->Branch("approach_id", &m_approachID);
43 m_outputTree->Branch("sensitive_id", &m_sensitiveID);
44 m_outputTree->Branch("g_x", &m_x);
45 m_outputTree->Branch("g_y", &m_y);
46 m_outputTree->Branch("g_z", &m_z);
47 m_outputTree->Branch("d_x", &m_dx);
48 m_outputTree->Branch("d_y", &m_dy);
49 m_outputTree->Branch("d_z", &m_dz);
50 m_outputTree->Branch("type", &m_step_type);
51 m_outputTree->Branch("step_acc", &m_step_acc);
52 m_outputTree->Branch("step_act", &m_step_act);
53 m_outputTree->Branch("step_abt", &m_step_abt);
54 m_outputTree->Branch("step_usr", &m_step_usr);
55 m_outputTree->Branch("hit_x", &m_hit_x);
56 m_outputTree->Branch("hit_y", &m_hit_y);
57 m_outputTree->Branch("hit_z", &m_hit_z);
58 m_outputTree->Branch("start_pos", &m_start_pos);
59 m_outputTree->Branch("start_mom", &m_start_mom);
60
61} // constructor
std::vector< int > m_boundaryID
boundary identifier
std::vector< int > m_step_type
step type
std::vector< float > m_step_act
actor check
std::vector< float > m_hit_x
hit location X
TFile * m_outputFile
the output file name
std::vector< int > m_sensitiveID
surface identifier
std::vector< float > m_dz
global direction z
std::vector< float > m_hit_z
hit location Z
std::vector< int > m_approachID
surface identifier
std::vector< float > m_dx
global direction x
std::vector< float > m_start_pos
start position of the particle propagated
std::vector< float > m_dy
global direction y
std::vector< int > m_layerID
layer identifier if
std::vector< float > m_start_mom
start momentum of the particle propagated
std::vector< float > m_step_acc
accuracy
std::vector< float > m_step_abt
aborter
std::vector< float > m_hit_y
hit location Y
Config m_cfg
the configuration object
std::string filePath
path of the output file
std::string treeName
name of the output tree

References tracking::sim::PropagatorStepWriter::Config::fileMode, tracking::sim::PropagatorStepWriter::Config::filePath, m_approachID, m_boundaryID, m_cfg, m_dx, m_dy, m_dz, m_eventNr, m_hit_x, m_hit_y, m_hit_z, m_layerID, m_outputFile, m_outputTree, m_sensitiveID, m_start_mom, m_start_pos, m_step_abt, m_step_acc, m_step_act, m_step_type, m_step_usr, m_x, m_y, m_z, and tracking::sim::PropagatorStepWriter::Config::treeName.

◆ ~PropagatorStepWriter()

tracking::sim::PropagatorStepWriter::~PropagatorStepWriter ( )

Close the file if it's yours

Definition at line 63 of file PropagatorStepWriter.cxx.

63 {
65 if (m_cfg.rootFile == nullptr) {
66 m_outputFile->cd();
67 m_outputTree->Write();
68 m_outputFile->Close();
69 }
70} // destructor

References m_cfg, m_outputFile, m_outputTree, and tracking::sim::PropagatorStepWriter::Config::rootFile.

Member Function Documentation

◆ WriteSteps()

bool tracking::sim::PropagatorStepWriter::WriteSteps ( framework::Event event,
const std::vector< PropagationSteps > &  stepCollection,
const std::vector< ldmx::Measurement > &  measurements,
const Acts::Vector3 &  start_pos,
const Acts::Vector3 &  start_mom 
)

Definition at line 72 of file PropagatorStepWriter.cxx.

76 {
77 // Exclusive access to the tree while writing
78 std::lock_guard<std::mutex> lock(m_writeMutex);
79
80 m_outputFile->cd();
81
82 // we get the event number
83 m_eventNr = event.getEventNumber();
84
85 // fill the hits
86 m_hit_x.clear();
87 m_hit_y.clear();
88 m_hit_z.clear();
89 // m_hit_erru.clear();
90 // m_hit_errv.clear();
91
92 m_start_pos.clear();
93 m_start_mom.clear();
94
95 for (auto& meas : measurements) {
96 m_hit_x.push_back(meas.getGlobalPosition()[0]);
97 m_hit_y.push_back(meas.getGlobalPosition()[1]);
98 m_hit_z.push_back(meas.getGlobalPosition()[2]);
99 }
100
101 for (unsigned int i = 0; i < 3; i++) {
102 m_start_pos.push_back(start_pos(i));
103 m_start_mom.push_back(start_mom(i));
104 }
105
106 // loop over the step vector of each test propagation in this
107 for (auto& steps : stepCollection) {
108 // clear the vectors for each collection
109 // m_volumeID.clear();
110 m_boundaryID.clear();
111 m_layerID.clear();
112 m_approachID.clear();
113 m_sensitiveID.clear();
114 m_x.clear();
115 m_y.clear();
116 m_z.clear();
117 m_dx.clear();
118 m_dy.clear();
119 m_dz.clear();
120 m_step_type.clear();
121 m_step_acc.clear();
122 m_step_act.clear();
123 m_step_abt.clear();
124 m_step_usr.clear();
125
126 // loop over single steps
127 for (auto& step : steps) {
128 // the identification of the step
129 // Acts::GeometryIdentifier::Value volumeID = 0;
130 Acts::GeometryIdentifier::Value boundaryID = 0;
131 Acts::GeometryIdentifier::Value layerID = 0;
132 Acts::GeometryIdentifier::Value approachID = 0;
133 Acts::GeometryIdentifier::Value sensitiveID = 0;
134 // get the identification from the surface first
135 if (step.surface) {
136 auto geoID = step.surface->geometryId();
137 // volumeID = geoID.volume();
138 boundaryID = geoID.boundary();
139 layerID = geoID.layer();
140 approachID = geoID.approach();
141 sensitiveID = geoID.sensitive();
142 }
143 // a current volume overwrites the surface tagged one
144 // mg ... v36 Step does not include volume
145 // if (step.volume) {
146 // volumeID = step.volume->geometryId().volume();
147 // }
148 // now fill
149 m_sensitiveID.push_back(sensitiveID);
150 m_approachID.push_back(approachID);
151 m_layerID.push_back(layerID);
152 m_boundaryID.push_back(boundaryID);
153 // m_volumeID.push_back(volumeID);
154
155 // kinematic information
156 m_x.push_back(step.position.x());
157 m_y.push_back(step.position.y());
158 m_z.push_back(step.position.z());
159 auto direction = step.momentum.normalized();
160 m_dx.push_back(direction.x());
161 m_dy.push_back(direction.y());
162 m_dz.push_back(direction.z());
163
164 // double accuracy =
165 // step.stepSize.value(Acts::ConstrainedStep::accuracy());
166 double accuracy = step.stepSize.accuracy();
167 double actor = step.stepSize.value(Acts::ConstrainedStep::actor);
168 double aborter = step.stepSize.value(Acts::ConstrainedStep::aborter);
169 double user = step.stepSize.value(Acts::ConstrainedStep::user);
170 double act2 = actor * actor;
171 double acc2 = accuracy * accuracy;
172 double abo2 = aborter * aborter;
173 double usr2 = user * user;
174
175 // todo - fold with direction
176 if (act2 < acc2 && act2 < abo2 && act2 < usr2) {
177 m_step_type.push_back(0);
178 } else if (acc2 < abo2 && acc2 < usr2) {
179 m_step_type.push_back(1);
180 } else if (abo2 < usr2) {
181 m_step_type.push_back(2);
182 } else {
183 m_step_type.push_back(3);
184 }
185
186 // step size information
187 m_step_acc.push_back(accuracy);
188 m_step_act.push_back(actor);
189 m_step_abt.push_back(aborter);
190 m_step_usr.push_back(user);
191 }
192 m_outputTree->Fill();
193 }
194 return true;
195}
std::mutex m_writeMutex
protect multi-threaded writes

Member Data Documentation

◆ m_approachID

std::vector<int> tracking::sim::PropagatorStepWriter::m_approachID
protected

surface identifier

Definition at line 64 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_boundaryID

std::vector<int> tracking::sim::PropagatorStepWriter::m_boundaryID
protected

boundary identifier

Definition at line 62 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_cfg

Config tracking::sim::PropagatorStepWriter::m_cfg
protected

the configuration object

Definition at line 55 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter(), and ~PropagatorStepWriter().

◆ m_dx

std::vector<float> tracking::sim::PropagatorStepWriter::m_dx
protected

global direction x

Definition at line 69 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_dy

std::vector<float> tracking::sim::PropagatorStepWriter::m_dy
protected

global direction y

Definition at line 70 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_dz

std::vector<float> tracking::sim::PropagatorStepWriter::m_dz
protected

global direction z

Definition at line 71 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_eventNr

int tracking::sim::PropagatorStepWriter::m_eventNr
protected

the event number of

Definition at line 59 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_hit_x

std::vector<float> tracking::sim::PropagatorStepWriter::m_hit_x
protected

hit location X

Definition at line 77 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_hit_y

std::vector<float> tracking::sim::PropagatorStepWriter::m_hit_y
protected

hit location Y

Definition at line 78 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_hit_z

std::vector<float> tracking::sim::PropagatorStepWriter::m_hit_z
protected

hit location Z

Definition at line 79 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_layerID

std::vector<int> tracking::sim::PropagatorStepWriter::m_layerID
protected

layer identifier if

Definition at line 63 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_outputFile

TFile* tracking::sim::PropagatorStepWriter::m_outputFile
protected

the output file name

Definition at line 57 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter(), and ~PropagatorStepWriter().

◆ m_outputTree

TTree* tracking::sim::PropagatorStepWriter::m_outputTree
protected

the output tree

Definition at line 58 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter(), and ~PropagatorStepWriter().

◆ m_sensitiveID

std::vector<int> tracking::sim::PropagatorStepWriter::m_sensitiveID
protected

surface identifier

Definition at line 65 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_start_mom

std::vector<float> tracking::sim::PropagatorStepWriter::m_start_mom
protected

start momentum of the particle propagated

Definition at line 83 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_start_pos

std::vector<float> tracking::sim::PropagatorStepWriter::m_start_pos
protected

start position of the particle propagated

Definition at line 81 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_step_abt

std::vector<float> tracking::sim::PropagatorStepWriter::m_step_abt
protected

aborter

Definition at line 75 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_step_acc

std::vector<float> tracking::sim::PropagatorStepWriter::m_step_acc
protected

accuracy

Definition at line 73 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_step_act

std::vector<float> tracking::sim::PropagatorStepWriter::m_step_act
protected

actor check

Definition at line 74 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_step_type

std::vector<int> tracking::sim::PropagatorStepWriter::m_step_type
protected

step type

Definition at line 72 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_step_usr

std::vector<float> tracking::sim::PropagatorStepWriter::m_step_usr
protected

user

Definition at line 76 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_writeMutex

std::mutex tracking::sim::PropagatorStepWriter::m_writeMutex
protected

protect multi-threaded writes

Definition at line 56 of file PropagatorStepWriter.h.

◆ m_x

std::vector<float> tracking::sim::PropagatorStepWriter::m_x
protected

global x

Definition at line 66 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_y

std::vector<float> tracking::sim::PropagatorStepWriter::m_y
protected

global y

Definition at line 67 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().

◆ m_z

std::vector<float> tracking::sim::PropagatorStepWriter::m_z
protected

global z

Definition at line 68 of file PropagatorStepWriter.h.

Referenced by PropagatorStepWriter().


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