LDMX Software
VertexProcessor.cxx
1#include "Tracking/Reco/VertexProcessor.h"
2
3#include <chrono>
4
5#include "Acts/MagneticField/ConstantBField.hpp"
6
7using namespace framework;
8
9namespace tracking {
10namespace reco {
11
12VertexProcessor::VertexProcessor(const std::string &name,
13 framework::Process &process)
14 : framework::Producer(name, process) {}
15
17 gctx_ = Acts::GeometryContext();
18 bctx_ = Acts::MagneticFieldContext();
19
20 h_m_ = new TH1F("m", "m", 100, 0., 1.);
21 h_m_truth_filter_ = new TH1F("m_filter", "m", 100, 0., 1.);
22 h_m_truth_ = new TH1F("m_truth", "m_truth", 100, 0., 1.);
23
24 /*
25 * this is unused, should it be? FIXME
26 auto localToGlobalBin_xyz = [](std::array<size_t, 3> bins,
27 std::array<size_t, 3> sizes) {
28 return (bins[0] * (sizes[1] * sizes[2]) + bins[1] * sizes[2] +
29 bins[2]); // xyz - field space
30 // return (bins[1] * (sizes[2] * sizes[0]) + bins[2] * sizes[0] + bins[0]);
31 // //zxy
32 };
33 */
34
35 // Setup a interpolated bfield map
36 sp_interpolated_b_field_ =
37 std::make_shared<InterpolatedMagneticField3>(loadDefaultBField(
38 field_map_, defaultTransformPos, defaultTransformBField));
39
40 ldmx_log(info) << "Check if nullptr::" << sp_interpolated_b_field_.get();
41}
42
44 // TODO:: the bfield map should be taken automatically
45 field_map_ = parameters.get<std::string>("field_map");
46
47 trk_coll_name_ = parameters.get<std::string>("trk_coll_name", "Tracks");
48
49 seeds_coll_name_ =
50 parameters.get<std::string>("seeds_coll_name", "RecoilTruthSeeds");
51
52 input_pass_name_ = parameters.get<std::string>("input_pass_name");
53}
54
56 // TODO:: Move this to an external file
57 // And move all this to a single time per processor not for each event!!
58
59 nevents_++;
60 auto start = std::chrono::high_resolution_clock::now();
61 auto &&stepper = Acts::EigenStepper<>{sp_interpolated_b_field_};
62
63 // Set up propagator with void navigator
64 propagator_ = std::make_shared<VoidPropagator>(stepper);
65
66 // Track linearizer in the proximity of the vertex location
67 using Linearizer = Acts::HelicalTrackLinearizer;
68 Linearizer::Config linearizer_config;
69 linearizer_config.bField = sp_interpolated_b_field_;
70 linearizer_config.propagator = propagator_;
71 Linearizer linearizer(linearizer_config);
72
73 // Set up Billoir Vertex Fitter
74 using VertexFitter = Acts::FullBilloirVertexFitter;
75
76 VertexFitter::Config vertex_fitter_cfg;
77
78 VertexFitter billoir_fitter(vertex_fitter_cfg);
79
80 // VertexFitter::State state(sp_interpolated_bField_->makeCache(bctx_));
81
82 // Unconstrained fit
83 // See
84 // https://github.com/acts-project/acts/blob/main/Tests/UnitTests/Core/Vertexing/FullBilloirVertexFitterTests.cpp#L149
85 // For constraint implementation
86
87 Acts::VertexingOptions vf_options(gctx_, bctx_);
88
89 // Retrieve the track collection
90 const std::vector<ldmx::Track> tracks =
91 event.getCollection<ldmx::Track>(trk_coll_name_, input_pass_name_);
92
93 // Retrieve the truth seeds
94 const std::vector<ldmx::Track> seeds =
95 event.getCollection<ldmx::Track>(seeds_coll_name_, input_pass_name_);
96
97 if (tracks.size() < 1) return;
98
99 // Transform the EDM ldmx::tracks to the format needed by ACTS
100 std::vector<Acts::BoundTrackParameters> billoir_tracks;
101
102 // TODO:: The perigee surface should be common between all tracks.
103 // So should only be created once in principle.
104 // There should be no perigeeSurface2
105
106 std::shared_ptr<Acts::PerigeeSurface> perigee_surface =
107 Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3(
108 tracks.front().getPerigeeX(), tracks.front().getPerigeeY(),
109 tracks.front().getPerigeeZ()));
110
111 for (unsigned int i_track = 0; i_track < tracks.size(); i_track++) {
112 Acts::BoundVector param_vec;
113 param_vec << tracks.at(i_track).getD0(), tracks.at(i_track).getZ0(),
114 tracks.at(i_track).getPhi(), tracks.at(i_track).getTheta(),
115 tracks.at(i_track).getQoP(), tracks.at(i_track).getT();
116
117 Acts::BoundSquareMatrix cov_mat =
118 tracking::sim::utils::unpackCov(tracks.at(i_track).getPerigeeCov());
119 auto part{Acts::GenericParticleHypothesis(Acts::ParticleHypothesis(
120 Acts::PdgParticle(tracks.at(i_track).getPdgID())))};
121 billoir_tracks.push_back(Acts::BoundTrackParameters(
122 perigee_surface, param_vec, std::move(cov_mat), part));
123 }
124
125 // Select exactly 2 tracks
126 if (billoir_tracks.size() != 2) {
127 return;
128 }
129
130 if (billoir_tracks.at(0).charge() * billoir_tracks.at(1).charge() > 0) return;
131
132 // Pion mass hypothesis
133 double pion_mass = 139.570 * Acts::UnitConstants::MeV;
134
135 TLorentzVector p1, p2;
136 p1.SetXYZM(billoir_tracks.at(0).momentum()(0),
137 billoir_tracks.at(0).momentum()(1),
138 billoir_tracks.at(0).momentum()(2), pion_mass);
139
140 p2.SetXYZM(billoir_tracks.at(1).momentum()(0),
141 billoir_tracks.at(1).momentum()(1),
142 billoir_tracks.at(1).momentum()(2), pion_mass);
143
144 std::vector<TLorentzVector> pion_seeds;
145
146 if (seeds.size() == 2) {
147 for (int i_seed = 0; i_seed < seeds.size(); i_seed++) {
148 std::shared_ptr<Acts::PerigeeSurface> perigee_surface2 =
149 Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3(
150 seeds.at(i_seed).getPerigeeX(), seeds.at(i_seed).getPerigeeY(),
151 seeds.at(i_seed).getPerigeeZ()));
152
153 Acts::BoundVector param_vec;
154 param_vec << seeds.at(i_seed).getD0(), seeds.at(i_seed).getZ0(),
155 seeds.at(i_seed).getPhi(), seeds.at(i_seed).getTheta(),
156 seeds.at(i_seed).getQoP(), seeds.at(i_seed).getT();
157
158 Acts::BoundSquareMatrix cov_mat =
159 tracking::sim::utils::unpackCov(seeds.at(i_seed).getPerigeeCov());
160 int pion_pdg_id = 211; // pi+
161 if (seeds.at(i_seed).q() < 0) pion_pdg_id = -211;
162 // BoundTrackParameters needs the particle hypothesis
163 auto part{Acts::GenericParticleHypothesis(
164 Acts::ParticleHypothesis(Acts::PdgParticle(pion_pdg_id)))};
165 auto bound_seed_params = Acts::BoundTrackParameters(
166 perigee_surface, param_vec, std::move(cov_mat), part);
167
168 TLorentzVector pion4v;
169 pion4v.SetXYZM(bound_seed_params.momentum()(0),
170 bound_seed_params.momentum()(1),
171 bound_seed_params.momentum()(2), pion_mass);
172
173 pion_seeds.push_back(pion4v);
174 } // loops on seeds
175
176 h_m_truth_->Fill((pion_seeds.at(0) + pion_seeds.at(1)).M());
177 }
178
179 if ((pion_seeds.size() == 2) &&
180 (pion_seeds.at(0) + pion_seeds.at(1)).M() > 0.490 &&
181 (pion_seeds.at(0) + pion_seeds.at(1)).M() < 0.510) {
182 // Check if the tracks have opposite charge
183 h_m_truth_filter_->Fill((p1 + p2).M());
184 }
185
186 h_m_->Fill((p1 + p2).M());
187
188 auto end = std::chrono::high_resolution_clock::now();
189 // long long microseconds =
190 // std::chrono::duration_cast<std::chrono::microseconds>(end-start).count();
191 auto diff = end - start;
192 processing_time_ += std::chrono::duration<double, std::milli>(diff).count();
193}
194
196 TFile *outfile = new TFile("VertexingResults.root", "RECREATE");
197 outfile->cd();
198
199 h_m_->Write();
200 h_m_truth_->Write();
201 h_m_truth_filter_->Write();
202 outfile->Close();
203 delete outfile;
204
205 ldmx_log(info) << "AVG Time/Event: " << std::fixed << std::setprecision(3)
206 << processing_time_ / nevents_ << " ms";
207}
208
209} // namespace reco
210} // namespace tracking
211
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class which represents the process under execution.
Definition Process.h:37
Base class for a module which produces a data product.
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
Implementation of a track object.
Definition Track.h:53
void onProcessEnd() override
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
Acts::GeometryContext gctx_
The contexts - TODO: they should move to some global location, I guess.
VertexProcessor(const std::string &name, framework::Process &process)
Constructor.
void configure(framework::config::Parameters &parameters) override
Configure the processor using the given user specified parameters.
std::string field_map_
Path to the magnetic field map.
void produce(framework::Event &event) override
Run the processor.
void onProcessStart() override
Callback for the EventProcessor to take any necessary action when the processing of events starts,...
All classes in the ldmx-sw project use this namespace.
The measurement calibrator can be a function or a class/struct able to retrieve the sim hits containe...