LDMX Software
tracking::reco::VertexProcessor Class Reference

Public Member Functions

 VertexProcessor (const std::string &name, framework::Process &process)
 Constructor.
 
virtual ~VertexProcessor ()=default
 Destructor.
 
void onProcessStart () override
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
void onProcessEnd () override
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
void configure (framework::config::Parameters &parameters) override
 Configure the processor using the given user specified parameters.
 
void produce (framework::Event &event) override
 Run the processor.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Attributes

Acts::GeometryContext gctx_
 The contexts - TODO: they should move to some global location, I guess.
 
Acts::MagneticFieldContext bctx_
 
int nevents_ {0}
 
std::shared_ptr< InterpolatedMagneticField3 > sp_interpolated_b_field_
 
std::string field_map_ {""}
 Path to the magnetic field map.
 
std::string trk_coll_name_ {"Tracks"}
 
std::string seeds_coll_name_ {"RecoilTruthSeeds"}
 
std::string input_pass_name_ {""}
 
std::shared_ptr< VoidPropagator > propagator_
 
double processing_time_ {0.}
 
TH1F * h_m_
 
TH1F * h_m_truth_filter_
 
TH1F * h_m_truth_
 

Additional Inherited Members

- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Definition at line 47 of file VertexProcessor.h.

Constructor & Destructor Documentation

◆ VertexProcessor()

tracking::reco::VertexProcessor::VertexProcessor ( const std::string & name,
framework::Process & process )

Constructor.

Parameters
nameThe name of the instance of this object.
processThe process running this producer.

Definition at line 12 of file VertexProcessor.cxx.

Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void tracking::reco::VertexProcessor::configure ( framework::config::Parameters & parameters)
overridevirtual

Configure the processor using the given user specified parameters.

Parameters
parametersSet of parameters used to configure this processor.

Reimplemented from framework::EventProcessor.

Definition at line 43 of file VertexProcessor.cxx.

43 {
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}
const T & get(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:78
std::string field_map_
Path to the magnetic field map.

References field_map_, and framework::config::Parameters::get().

◆ onProcessEnd()

void tracking::reco::VertexProcessor::onProcessEnd ( )
overridevirtual

Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.

Reimplemented from framework::EventProcessor.

Definition at line 198 of file VertexProcessor.cxx.

198 {
199 TFile *outfile = new TFile("VertexingResults.root", "RECREATE");
200 outfile->cd();
201
202 h_m_->Write();
203 h_m_truth_->Write();
204 h_m_truth_filter_->Write();
205 outfile->Close();
206 delete outfile;
207
208 ldmx_log(info) << "AVG Time/Event: " << std::fixed << std::setprecision(3)
209 << processing_time_ / nevents_ << " ms";
210}

◆ onProcessStart()

void tracking::reco::VertexProcessor::onProcessStart ( )
overridevirtual

Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.

Reimplemented from framework::EventProcessor.

Definition at line 16 of file VertexProcessor.cxx.

16 {
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}
Acts::GeometryContext gctx_
The contexts - TODO: they should move to some global location, I guess.

References field_map_, and gctx_.

◆ produce()

void tracking::reco::VertexProcessor::produce ( framework::Event & event)
overridevirtual

Run the processor.

Parameters
eventThe event to process.

Implements framework::Producer.

Definition at line 55 of file VertexProcessor.cxx.

55 {
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 Acts::Vector3 perigee_acts = tracking::sim::utils::ldmx2Acts(
107 Acts::Vector3(tracks.front().getPerigeeX(), tracks.front().getPerigeeY(),
108 tracks.front().getPerigeeZ()));
109 std::shared_ptr<Acts::PerigeeSurface> perigee_surface =
110 Acts::Surface::makeShared<Acts::PerigeeSurface>(perigee_acts);
111
112 for (unsigned int i_track = 0; i_track < tracks.size(); i_track++) {
113 Acts::BoundVector param_vec;
114 param_vec << tracks.at(i_track).getD0(), tracks.at(i_track).getZ0(),
115 tracks.at(i_track).getPhi(), tracks.at(i_track).getTheta(),
116 tracks.at(i_track).getQoP(), tracks.at(i_track).getT();
117
118 Acts::BoundSquareMatrix cov_mat =
119 tracking::sim::utils::unpackCov(tracks.at(i_track).getPerigeeCov());
120 auto part{Acts::GenericParticleHypothesis(Acts::ParticleHypothesis(
121 Acts::PdgParticle(tracks.at(i_track).getPdgID())))};
122 billoir_tracks.push_back(Acts::BoundTrackParameters(
123 perigee_surface, param_vec, std::move(cov_mat), part));
124 }
125
126 // Select exactly 2 tracks
127 if (billoir_tracks.size() != 2) {
128 return;
129 }
130
131 if (billoir_tracks.at(0).charge() * billoir_tracks.at(1).charge() > 0) return;
132
133 // Pion mass hypothesis
134 double pion_mass = 139.570 * Acts::UnitConstants::MeV;
135
136 TLorentzVector p1, p2;
137 p1.SetXYZM(billoir_tracks.at(0).momentum()(0),
138 billoir_tracks.at(0).momentum()(1),
139 billoir_tracks.at(0).momentum()(2), pion_mass);
140
141 p2.SetXYZM(billoir_tracks.at(1).momentum()(0),
142 billoir_tracks.at(1).momentum()(1),
143 billoir_tracks.at(1).momentum()(2), pion_mass);
144
145 std::vector<TLorentzVector> pion_seeds;
146
147 if (seeds.size() == 2) {
148 for (int i_seed = 0; i_seed < seeds.size(); i_seed++) {
149 Acts::Vector3 seed_perigee_acts =
150 tracking::sim::utils::ldmx2Acts(Acts::Vector3(
151 seeds.at(i_seed).getPerigeeX(), seeds.at(i_seed).getPerigeeY(),
152 seeds.at(i_seed).getPerigeeZ()));
153 std::shared_ptr<Acts::PerigeeSurface> perigee_surface2 =
154 Acts::Surface::makeShared<Acts::PerigeeSurface>(seed_perigee_acts);
155
156 Acts::BoundVector param_vec;
157 param_vec << seeds.at(i_seed).getD0(), seeds.at(i_seed).getZ0(),
158 seeds.at(i_seed).getPhi(), seeds.at(i_seed).getTheta(),
159 seeds.at(i_seed).getQoP(), seeds.at(i_seed).getT();
160
161 Acts::BoundSquareMatrix cov_mat =
162 tracking::sim::utils::unpackCov(seeds.at(i_seed).getPerigeeCov());
163 int pion_pdg_id = 211; // pi+
164 if (seeds.at(i_seed).getCharge() < 0) pion_pdg_id = -211;
165 // BoundTrackParameters needs the particle hypothesis
166 auto part{Acts::GenericParticleHypothesis(
167 Acts::ParticleHypothesis(Acts::PdgParticle(pion_pdg_id)))};
168 auto bound_seed_params = Acts::BoundTrackParameters(
169 perigee_surface, param_vec, std::move(cov_mat), part);
170
171 TLorentzVector pion4v;
172 pion4v.SetXYZM(bound_seed_params.momentum()(0),
173 bound_seed_params.momentum()(1),
174 bound_seed_params.momentum()(2), pion_mass);
175
176 pion_seeds.push_back(pion4v);
177 } // loops on seeds
178
179 h_m_truth_->Fill((pion_seeds.at(0) + pion_seeds.at(1)).M());
180 }
181
182 if ((pion_seeds.size() == 2) &&
183 (pion_seeds.at(0) + pion_seeds.at(1)).M() > 0.490 &&
184 (pion_seeds.at(0) + pion_seeds.at(1)).M() < 0.510) {
185 // Check if the tracks have opposite charge
186 h_m_truth_filter_->Fill((p1 + p2).M());
187 }
188
189 h_m_->Fill((p1 + p2).M());
190
191 auto end = std::chrono::high_resolution_clock::now();
192 // long long microseconds =
193 // std::chrono::duration_cast<std::chrono::microseconds>(end-start).count();
194 auto diff = end - start;
195 processing_time_ += std::chrono::duration<double, std::milli>(diff).count();
196}
Implementation of a track object.
Definition Track.h:53

References gctx_.

Member Data Documentation

◆ bctx_

Acts::MagneticFieldContext tracking::reco::VertexProcessor::bctx_
private

Definition at line 81 of file VertexProcessor.h.

◆ field_map_

std::string tracking::reco::VertexProcessor::field_map_ {""}
private

Path to the magnetic field map.

Definition at line 90 of file VertexProcessor.h.

90{""};

Referenced by configure(), and onProcessStart().

◆ gctx_

Acts::GeometryContext tracking::reco::VertexProcessor::gctx_
private

The contexts - TODO: they should move to some global location, I guess.

Definition at line 80 of file VertexProcessor.h.

Referenced by onProcessStart(), and produce().

◆ h_m_

TH1F* tracking::reco::VertexProcessor::h_m_
private

Definition at line 106 of file VertexProcessor.h.

◆ h_m_truth_

TH1F* tracking::reco::VertexProcessor::h_m_truth_
private

Definition at line 108 of file VertexProcessor.h.

◆ h_m_truth_filter_

TH1F* tracking::reco::VertexProcessor::h_m_truth_filter_
private

Definition at line 107 of file VertexProcessor.h.

◆ input_pass_name_

std::string tracking::reco::VertexProcessor::input_pass_name_ {""}
private

Definition at line 98 of file VertexProcessor.h.

98{""};

◆ nevents_

int tracking::reco::VertexProcessor::nevents_ {0}
private

Definition at line 84 of file VertexProcessor.h.

84{0};

◆ processing_time_

double tracking::reco::VertexProcessor::processing_time_ {0.}
private

Definition at line 104 of file VertexProcessor.h.

104{0.};

◆ propagator_

std::shared_ptr<VoidPropagator> tracking::reco::VertexProcessor::propagator_
private

Definition at line 101 of file VertexProcessor.h.

◆ seeds_coll_name_

std::string tracking::reco::VertexProcessor::seeds_coll_name_ {"RecoilTruthSeeds"}
private

Definition at line 96 of file VertexProcessor.h.

96{"RecoilTruthSeeds"};

◆ sp_interpolated_b_field_

std::shared_ptr<InterpolatedMagneticField3> tracking::reco::VertexProcessor::sp_interpolated_b_field_
private

Definition at line 87 of file VertexProcessor.h.

◆ trk_coll_name_

std::string tracking::reco::VertexProcessor::trk_coll_name_ {"Tracks"}
private

Definition at line 94 of file VertexProcessor.h.

94{"Tracks"};

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