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.getParameter<double>("fit_res_C");
15 fit_res_K_ = ps.getParameter<double>("fit_res_K");
16 input_pass_name_ = ps.getParameter<std::string>("input_pass_name", "");
17 track_collection_ =
18 ps.getParameter<std::string>("track_collection", "RecoilTruthSeeds");
19
20 ldmx_log(info) << "Track Collection used for TrackDeDxMassEstimator "
21 << track_collection_;
22}
23
25 if (!event.exists(track_collection_)) {
26 ldmx_log(error) << "Track collection " << track_collection_
27 << " not in event";
28 return;
29 }
30 const std::vector<ldmx::Track> tracks{
31 event.getCollection<ldmx::Track>(track_collection_, input_pass_name_)};
32
33 int track_type;
34 std::string track_coll_str = track_collection_;
35 std::transform(track_coll_str.begin(), track_coll_str.end(),
36 track_coll_str.begin(), ::tolower);
37 if (track_coll_str.find("tagger") != std::string::npos) {
38 track_type = 1;
39 simhit_collection_ = "TaggerSimHits";
40 } else if (track_coll_str.find("recoil") != std::string::npos) {
41 track_type = 2;
42 simhit_collection_ = "RecoilSimHits";
43 } else {
44 track_type = 0;
45 simhit_collection_ = "";
46 }
47
48 // Retrieve the simhits
49 if (!event.exists(simhit_collection_)) return;
50 auto simhits{event.getCollection<ldmx::SimTrackerHit>(simhit_collection_,
51 input_pass_name_)};
52
53 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates_;
54
55 // Loop over the collection of tracks
56 for (uint i = 0; i < tracks.size(); i++) {
57 auto track = tracks.at(i);
58 // If track momentum doen't exist, skip
59 auto theQoP = track.getQoP();
60 if (theQoP == 0) {
61 ldmx_log(debug) << "Track " << i << "has zero q/p ";
62 continue;
63 }
64
65 float momentum = 1. / std::abs(theQoP) * 1000; // unit: MeV
66 ldmx_log(debug) << "Track " << i << " has momentum " << momentum;
67
70 float sum_dEdx_inv2 = 0.;
71 float dEdx;
72 float n_simhits = 0;
73 for (auto hit : simhits) {
74 // Check if the hit is associated with the track
75 if (hit.getTrackID() != track.getTrackID()) continue;
76 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
77 dEdx = hit.getEdep() / hit.getPathLength() * 10; // unit: MeV/cm
78 sum_dEdx_inv2 += 1. / (dEdx * dEdx);
79 n_simhits++;
80 }
81 } // end of loop over measurements
82
83 if (sum_dEdx_inv2 == 0) {
84 ldmx_log(debug) << "Track " << i << " has no dEdx measurements";
85 continue;
86 }
87
88 // Ih = (1/N * sum_i^N(dE/dx_i)^-2)^-1/2
89 float theIh = 1. / sqrt(1. / n_simhits * sum_dEdx_inv2);
90
91 float mass = 0.;
92 if (theIh > fit_res_C_) {
93 mass = momentum * sqrt((theIh - fit_res_C_) / fit_res_K_);
94 } else {
95 ldmx_log(info) << "Track " << i << " has Ih " << theIh
96 << " which is less than fit_res_C " << fit_res_C_;
97 mass = -100.;
98 }
99
100 mass_est.setMomentum(momentum);
101 mass_est.setIh(theIh);
102 mass_est.setMass(mass);
103 mass_est.setTrackIndex(i);
104 mass_est.setTrackType(track_type);
105 mass_estimates_.push_back(mass_est);
106 }
107
108 // Add the mass estimates to the event
109 event.add("TrackDeDxMassEstimate", mass_estimates_);
110}
111} // namespace recon
112
113DECLARE_PRODUCER_NS(recon, TrackDeDxMassEstimator)
#define DECLARE_PRODUCER_NS(NS, 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:92
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
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 setMomentum(float momentum)
Set the momentum of the particle/track.
void setIh(float theIh)
Set the Ih of the particle/track.
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.