24 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
26 if (!event.
exists(track_collection_, input_pass_name_)) {
27 ldmx_log(error) <<
"Track collection " << track_collection_ <<
"_"
28 << input_pass_name_ <<
" not in event, exiting...";
29 event.add(
"TrackDeDxMassEstimate", mass_estimates);
32 const std::vector<ldmx::Track> tracks{
33 event.getCollection<
ldmx::Track>(track_collection_, input_pass_name_)};
36 std::string track_coll_str = track_collection_;
37 std::transform(track_coll_str.begin(), track_coll_str.end(),
38 track_coll_str.begin(), ::tolower);
40 bool is_truth = track_coll_str.find(
"truth") != std::string::npos;
43 if (track_coll_str.find(
"tagger") != std::string::npos) {
45 simhit_collection_ =
"TaggerSimHits";
46 }
else if (track_coll_str.find(
"recoil") != std::string::npos) {
48 simhit_collection_ =
"RecoilSimHits";
51 simhit_collection_ =
"";
56 simhit_collection_ =
"";
60 std::vector<ldmx::SimTrackerHit> simhits;
62 if (!event.
exists(simhit_collection_, input_pass_name_)) {
63 ldmx_log(error) <<
" SimHit collection (" << simhit_collection_ <<
"_"
64 << input_pass_name_ <<
") does not exists, exiting...";
65 event.add(
"TrackDeDxMassEstimate", mass_estimates);
73 for (uint i = 0; i < tracks.size(); i++) {
74 auto track = tracks.at(i);
76 auto the_qop = track.getQoP();
78 ldmx_log(debug) <<
"Track " << i <<
"has zero q/p ";
82 int pdg_id = track.getPdgID();
83 float momentum = 1. / std::abs(the_qop) * 1000;
84 ldmx_log(debug) <<
"Track " << i <<
" has momentum " << momentum;
87 float sum_dedx_inv2 = 0.;
93 for (
auto hit : simhits) {
94 if (hit.getTrackID() != track.getTrackID())
continue;
95 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
96 dedx = hit.getEdep() / hit.getPathLength() * 10;
97 sum_dedx_inv2 += 1. / (dedx * dedx);
103 for (
auto dedx_meas : track.getDedxMeasurements()) {
105 dedx = dedx_meas * 10;
106 sum_dedx_inv2 += 1. / (dedx * dedx);
112 if (sum_dedx_inv2 == 0) {
113 ldmx_log(debug) <<
"Track " << i <<
" has no dEdx measurements";
118 float the_ih = 1. / sqrt(1. / n_hits * sum_dedx_inv2);
121 if (the_ih > fit_res_c_) {
122 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
124 ldmx_log(info) <<
"Track " << i <<
" has Ih " << the_ih
125 <<
" which is less than fit_res_C " << fit_res_c_;
131 mass_est.
setIh(the_ih);
136 mass_estimates.push_back(mass_est);
140 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.