28 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
30 if (!event.
exists(track_collection_, input_pass_name_)) {
31 ldmx_log(error) <<
"Track collection " << track_collection_ <<
"_"
32 << input_pass_name_ <<
" not in event, exiting...";
33 event.add(out_collection_, mass_estimates);
36 const std::vector<ldmx::Track> tracks{
37 event.getCollection<
ldmx::Track>(track_collection_, input_pass_name_)};
40 std::string track_coll_str = track_collection_;
41 std::transform(track_coll_str.begin(), track_coll_str.end(),
42 track_coll_str.begin(), ::tolower);
44 bool is_truth = track_coll_str.find(
"truth") != std::string::npos;
47 if (track_coll_str.find(
"tagger") != std::string::npos) {
49 simhit_collection_ =
"TaggerSimHits";
50 }
else if (track_coll_str.find(
"recoil") != std::string::npos) {
52 simhit_collection_ =
"RecoilSimHits";
55 simhit_collection_ =
"";
60 simhit_collection_ =
"";
64 std::vector<ldmx::SimTrackerHit> simhits;
66 if (!event.
exists(simhit_collection_, input_pass_name_)) {
67 ldmx_log(error) <<
" SimHit collection (" << simhit_collection_ <<
"_"
68 << input_pass_name_ <<
") does not exists, exiting...";
69 event.add(out_collection_, mass_estimates);
77 for (uint i = 0; i < tracks.size(); i++) {
78 auto track = tracks.at(i);
80 auto the_qop = track.getQoP();
82 ldmx_log(debug) <<
"Track " << i <<
"has zero q/p ";
86 int pdg_id = track.getPdgID();
87 float momentum = 1. / std::abs(the_qop) * 1000;
88 ldmx_log(debug) <<
"Track " << i <<
" has momentum " << momentum;
91 float sum_dedx_inv2 = 0.;
97 for (
auto hit : simhits) {
98 if (hit.getTrackID() != track.getTrackID())
continue;
99 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
100 dedx = hit.getEdep() / hit.getPathLength() * 10;
101 sum_dedx_inv2 += 1. / (dedx * dedx);
107 for (
auto dedx_meas : track.getDedxMeasurements()) {
109 dedx = dedx_meas * 10;
110 sum_dedx_inv2 += 1. / (dedx * dedx);
116 if (sum_dedx_inv2 == 0) {
117 ldmx_log(debug) <<
"Track " << i <<
" has no dEdx measurements";
122 float the_ih = 1. / sqrt(1. / n_hits * sum_dedx_inv2);
124 float mass2 = (the_ih - fit_res_c_) * momentum * momentum / fit_res_k_;
127 if (the_ih > fit_res_c_) {
128 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
130 ldmx_log(info) <<
"Track " << i <<
" has Ih " << the_ih
131 <<
" which is less than fit_res_C " << fit_res_c_;
137 mass_est.
setIh(the_ih);
143 mass_estimates.push_back(mass_est);
147 event.add(out_collection_, 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.