-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyTrackWriter.cpp
More file actions
71 lines (64 loc) · 2.52 KB
/
MyTrackWriter.cpp
File metadata and controls
71 lines (64 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "MyTrackWriter.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/WriterT.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include <TFile.h>
#include <TTree.h>
MyTrackWriter::MyTrackWriter(const MyTrackWriter::Config& config, Acts::Logging::Level level)
: WriterT(config.inputTracks, "MyTrackWriter", level), m_cfg(config) {
m_outputFile = new TFile(m_cfg.filePath.c_str(), "recreate");
m_outputTree = new TTree(m_cfg.treeName.c_str(), m_cfg.treeName.c_str());
m_outputTree->Branch("event_nr", &m_eventNr);
m_outputTree->Branch("track_nr", &m_trackNr);
m_outputTree->Branch("chi2Sum", &m_chi2Sum);
m_outputTree->Branch("NDF", &m_NDF);
m_outputTree->Branch("eLOC0_fit", &m_eLOC0_fit);
m_outputTree->Branch("eLOC1_fit", &m_eLOC1_fit);
m_outputTree->Branch("ePHI_fit", &m_ePHI_fit);
m_outputTree->Branch("eTHETA_fit", &m_eTHETA_fit);
m_outputTree->Branch("eQOP_fit", &m_eQOP_fit);
m_outputTree->Branch("measurementIds", &m_measurementIds);
}
MyTrackWriter::~MyTrackWriter() {
m_outputFile->Close();
}
ProcessCode MyTrackWriter::finalize() {
m_outputFile->cd();
m_outputTree->Write();
m_outputFile->Close();
return ProcessCode::SUCCESS;
}
ProcessCode MyTrackWriter::writeT(const AlgorithmContext& ctx, const ConstTrackContainer& tracks) {
m_eventNr = ctx.eventNumber;
for (const auto& track : tracks) {
m_trackNr.push_back(track.index());
m_chi2Sum.push_back(track.chi2());
m_NDF.push_back(track.nDoF());
const auto& param = track.parameters();
m_eLOC0_fit.push_back(param[Acts::eBoundLoc0]);
m_eLOC1_fit.push_back(param[Acts::eBoundLoc1]);
m_ePHI_fit.push_back(param[Acts::eBoundPhi]);
m_eTHETA_fit.push_back(param[Acts::eBoundTheta]);
m_eQOP_fit.push_back(param[Acts::eBoundQOverP]);
std::vector<int> measurementIds;
for (const auto& state : track.trackStatesReversed()) {
if (!state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) continue;
auto measId = state.getUncalibratedSourceLink().template get<ActsExamples::IndexSourceLink>().index();
measurementIds.push_back(measId);
}
m_measurementIds.push_back(measurementIds);
}
m_outputTree->Fill();
m_trackNr.clear();
m_chi2Sum.clear();
m_NDF.clear();
m_eLOC0_fit.clear();
m_eLOC1_fit.clear();
m_ePHI_fit.clear();
m_eTHETA_fit.clear();
m_eQOP_fit.clear();
m_measurementIds.clear();
return ProcessCode::SUCCESS;
}