LDMX Software
TrackDeDxMassEstimator.cxx
1// LDMX
3
5
6// STL
7#include <algorithm> // for std::transform
8#include <cctype> // for ::tolower
9#include <iostream>
10
11namespace recon {
12
14 fit_res_c_ = ps.get<double>("fit_res_c");
15 fit_res_k_ = ps.get<double>("fit_res_k");
16 input_pass_name_ = ps.get<std::string>("input_pass_name", "");
17 track_collection_ =
18 ps.get<std::string>("track_collection", "RecoilTruthSeeds");
19
20 ldmx_log(info) << "Track Collection used for TrackDeDxMassEstimator "
21 << track_collection_;
22}
23
25 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
26
27 if (!event.exists(track_collection_, input_pass_name_)) {
28 ldmx_log(error) << "Track collection " << track_collection_ << "_"
29 << input_pass_name_ << " not in event, exiting...";
30 event.add("TrackDeDxMassEstimate", mass_estimates);
31 return;
32 }
33 const std::vector<ldmx::Track> tracks{
34 event.getCollection<ldmx::Track>(track_collection_, input_pass_name_)};
35
36 int track_type;
37 std::string track_coll_str = track_collection_;
38 std::transform(track_coll_str.begin(), track_coll_str.end(),
39 track_coll_str.begin(), ::tolower);
40 if (track_coll_str.find("tagger") != std::string::npos) {
41 track_type = 1;
42 simhit_collection_ = "TaggerSimHits";
43 } else if (track_coll_str.find("recoil") != std::string::npos) {
44 track_type = 2;
45 simhit_collection_ = "RecoilSimHits";
46 } else {
47 track_type = 0;
48 simhit_collection_ = "";
49 }
50
51 // Retrieve the simhits
52 if (!event.exists(simhit_collection_, input_pass_name_)) {
53 ldmx_log(error) << " SimHit collection (" << simhit_collection_ << "_"
54 << input_pass_name_ << ") does not exists, exiting...";
55 event.add("TrackDeDxMassEstimate", mass_estimates);
56 return;
57 }
58 auto simhits{event.getCollection<ldmx::SimTrackerHit>(simhit_collection_,
59 input_pass_name_)};
60
61 // Loop over the collection of tracks
62 for (uint i = 0; i < tracks.size(); i++) {
63 auto track = tracks.at(i);
64 // If track momentum doen't exist, skip
65 auto the_qop = track.getQoP();
66 if (the_qop == 0) {
67 ldmx_log(debug) << "Track " << i << "has zero q/p ";
68 continue;
69 }
70
71 int pdg_id = track.getPdgID();
72 float momentum = 1. / std::abs(the_qop) * 1000; // unit: MeV
73 ldmx_log(debug) << "Track " << i << " has momentum " << momentum;
74
77 float sum_dedx_inv2 = 0.;
78 float dedx;
79 float n_simhits = 0;
80 for (auto hit : simhits) {
81 // Check if the hit is associated with the track
82 if (hit.getTrackID() != track.getTrackID()) continue;
83 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
84 dedx = hit.getEdep() / hit.getPathLength() * 10; // unit: MeV/cm
85 sum_dedx_inv2 += 1. / (dedx * dedx);
86 n_simhits++;
87 }
88 } // end of loop over measurements
89
90 if (sum_dedx_inv2 == 0) {
91 ldmx_log(debug) << "Track " << i << " has no dEdx measurements";
92 continue;
93 }
94
95 // Ih = (1/N * sum_i^N(dE/dx_i)^-2)^-1/2
96 float the_ih = 1. / sqrt(1. / n_simhits * sum_dedx_inv2);
97
98 float mass = 0.;
99 if (the_ih > fit_res_c_) {
100 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
101 } else {
102 ldmx_log(info) << "Track " << i << " has Ih " << the_ih
103 << " which is less than fit_res_C " << fit_res_c_;
104 mass = -100.;
105 }
106
107 mass_est.setMomentum(momentum);
108 mass_est.setNhits(n_simhits);
109 mass_est.setIh(the_ih);
110 mass_est.setMass(mass);
111 mass_est.setTrackIndex(i);
112 mass_est.setTrackType(track_type);
113 mass_est.setPdgId(pdg_id);
114 mass_estimates.push_back(mass_est);
115 }
116
117 // Add the mass estimates to the event
118 event.add("TrackDeDxMassEstimate", mass_estimates);
119}
120} // namespace recon
121
#define DECLARE_PRODUCER(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Class that represents the estimated mass of a particle using tracker dE/dx information.
Class that estimates the mass of a particle using tracker dE/dx information.
Implements an event buffer system for storing event data.
Definition Event.h:42
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:105
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
Represents a simulated tracker hit in the simulation.
Represents the estimated mass of a particle using tracker dE/dx information.
void setTrackType(int track_type)
Set the type of the track.
void setPdgId(int pdg_id)
Set the PDG ID of the track.
void setIh(float the_ih)
Set the Ih of the particle/track.
void setMomentum(float momentum)
Set the momentum of the particle/track.
void setNhits(float nhits)
Set the number of hits used in the dEdx calculation.
void setMass(float mass)
Set the estimated mass of the particle/track.
void setTrackIndex(int track_index)
Set the index of the track.
Implementation of a track object.
Definition Track.h:53
virtual void produce(framework::Event &event) override
Process the event and put new data products into it.
virtual void configure(framework::config::Parameters &ps) override
Callback for the EventProcessor to configure itself from the given set of parameters.