27 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
29 if (!event.
exists(track_collection_, input_pass_name_)) {
30 ldmx_log(error) <<
"Track collection " << track_collection_ <<
"_"
31 << input_pass_name_ <<
" not in event, exiting...";
32 event.add(
"TrackDeDxMassEstimate", mass_estimates);
35 const std::vector<ldmx::Track> tracks{
36 event.getCollection<
ldmx::Track>(track_collection_, input_pass_name_)};
39 std::string track_coll_str = track_collection_;
40 std::transform(track_coll_str.begin(), track_coll_str.end(),
41 track_coll_str.begin(), ::tolower);
43 bool is_truth = track_coll_str.find(
"truth") != std::string::npos;
46 if (track_coll_str.find(
"tagger") != std::string::npos) {
48 simhit_collection_ =
"TaggerSimHits";
49 }
else if (track_coll_str.find(
"recoil") != std::string::npos) {
51 simhit_collection_ =
"RecoilSimHits";
54 simhit_collection_ =
"";
59 simhit_collection_ =
"";
63 std::vector<ldmx::SimTrackerHit> simhits;
65 if (!event.
exists(simhit_collection_, input_pass_name_)) {
66 ldmx_log(error) <<
" SimHit collection (" << simhit_collection_ <<
"_"
67 << input_pass_name_ <<
") does not exists, exiting...";
68 event.add(
"TrackDeDxMassEstimate", mass_estimates);
76 for (uint i = 0; i < tracks.size(); i++) {
77 auto track = tracks.at(i);
79 auto the_qop = track.getQoP();
81 ldmx_log(debug) <<
"Track " << i <<
"has zero q/p ";
85 int pdg_id = track.getPdgID();
86 float momentum = 1. / std::abs(the_qop) * 1000;
87 ldmx_log(debug) <<
"Track " << i <<
" has momentum " << momentum;
90 float sum_dedx_inv2 = 0.;
96 for (
auto hit : simhits) {
97 if (hit.getTrackID() != track.getTrackID())
continue;
98 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
99 dedx = hit.getEdep() / hit.getPathLength() * 10;
100 sum_dedx_inv2 += 1. / (dedx * dedx);
106 for (
auto dedx_meas : track.getDedxMeasurements()) {
108 dedx = dedx_meas * 10;
109 sum_dedx_inv2 += 1. / (dedx * dedx);
115 if (sum_dedx_inv2 == 0) {
116 ldmx_log(debug) <<
"Track " << i <<
" has no dEdx measurements";
121 float the_ih = 1. / sqrt(1. / n_hits * sum_dedx_inv2);
124 if (the_ih > fit_res_c_) {
125 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
127 ldmx_log(info) <<
"Track " << i <<
" has Ih " << the_ih
128 <<
" which is less than fit_res_C " << fit_res_c_;
134 mass_est.
setIh(the_ih);
139 mass_estimates.push_back(mass_est);
143 event.add(
"TrackDeDxMassEstimate", mass_estimates);
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.