Process the event and put new data products into it.
24 {
25 if (!event.
exists(track_collection_, input_pass_name_)) {
26 ldmx_log(error) << "Track collection " << track_collection_ << "_"
27 << input_pass_name_ << " not in event, exiting...";
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
49 if (!event.
exists(simhit_collection_, input_pass_name_)) {
50 ldmx_log(error) << " SimHit collection (" << simhit_collection_ << "_"
51 << input_pass_name_ << ") does not exists, exiting...";
52 return;
53 }
55 input_pass_name_)};
56
57 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
58
59
60 for (uint i = 0; i < tracks.size(); i++) {
61 auto track = tracks.at(i);
62
63 auto the_qo_p = track.getQoP();
64 if (the_qo_p == 0) {
65 ldmx_log(debug) << "Track " << i << "has zero q/p ";
66 continue;
67 }
68
69 int pdg_id = track.getPdgID();
70 float momentum = 1. / std::abs(the_qo_p) * 1000;
71 ldmx_log(debug) << "Track " << i << " has momentum " << momentum;
72
75 float sum_d_edx_inv2 = 0.;
76 float d_edx;
77 float n_simhits = 0;
78 for (auto hit : simhits) {
79
80 if (hit.getTrackID() != track.getTrackID()) continue;
81 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
82 d_edx = hit.getEdep() / hit.getPathLength() * 10;
83 sum_d_edx_inv2 += 1. / (d_edx * d_edx);
84 n_simhits++;
85 }
86 }
87
88 if (sum_d_edx_inv2 == 0) {
89 ldmx_log(debug) << "Track " << i << " has no dEdx measurements";
90 continue;
91 }
92
93
94 float the_ih = 1. / sqrt(1. / n_simhits * sum_d_edx_inv2);
95
96 float mass = 0.;
97 if (the_ih > fit_res_c_) {
98 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
99 } else {
100 ldmx_log(info) << "Track " << i << " has Ih " << the_ih
101 << " which is less than fit_res_C " << fit_res_c_;
102 mass = -100.;
103 }
104
106 mass_est.
setIh(the_ih);
111 mass_estimates.push_back(mass_est);
112 }
113
114
115 event.add("TrackDeDxMassEstimate", mass_estimates);
116}
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.
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 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.