Process the event and put new data products into it.
24 {
25 std::vector<ldmx::TrackDeDxMassEstimate> mass_estimates;
26
27 if (!event.
exists(track_collection_, input_pass_name_)) {
28 ldmx_log(error) << "Track collection " << track_collection_ << "_"
29 << input_pass_name_ << " not in event, exiting...";
30 event.add("TrackDeDxMassEstimate", mass_estimates);
31 return;
32 }
33 const std::vector<ldmx::Track> tracks{
34 event.getCollection<
ldmx::Track>(track_collection_, input_pass_name_)};
35
36 int track_type;
37 std::string track_coll_str = track_collection_;
38 std::transform(track_coll_str.begin(), track_coll_str.end(),
39 track_coll_str.begin(), ::tolower);
40 if (track_coll_str.find("tagger") != std::string::npos) {
41 track_type = 1;
42 simhit_collection_ = "TaggerSimHits";
43 } else if (track_coll_str.find("recoil") != std::string::npos) {
44 track_type = 2;
45 simhit_collection_ = "RecoilSimHits";
46 } else {
47 track_type = 0;
48 simhit_collection_ = "";
49 }
50
51
52 if (!event.
exists(simhit_collection_, input_pass_name_)) {
53 ldmx_log(error) << " SimHit collection (" << simhit_collection_ << "_"
54 << input_pass_name_ << ") does not exists, exiting...";
55 event.add("TrackDeDxMassEstimate", mass_estimates);
56 return;
57 }
59 input_pass_name_)};
60
61
62 for (uint i = 0; i < tracks.size(); i++) {
63 auto track = tracks.at(i);
64
65 auto the_qop = track.getQoP();
66 if (the_qop == 0) {
67 ldmx_log(debug) << "Track " << i << "has zero q/p ";
68 continue;
69 }
70
71 int pdg_id = track.getPdgID();
72 float momentum = 1. / std::abs(the_qop) * 1000;
73 ldmx_log(debug) << "Track " << i << " has momentum " << momentum;
74
77 float sum_dedx_inv2 = 0.;
78 float dedx;
79 float n_simhits = 0;
80 for (auto hit : simhits) {
81
82 if (hit.getTrackID() != track.getTrackID()) continue;
83 if (hit.getEdep() >= 0 && hit.getPathLength() > 0) {
84 dedx = hit.getEdep() / hit.getPathLength() * 10;
85 sum_dedx_inv2 += 1. / (dedx * dedx);
86 n_simhits++;
87 }
88 }
89
90 if (sum_dedx_inv2 == 0) {
91 ldmx_log(debug) << "Track " << i << " has no dEdx measurements";
92 continue;
93 }
94
95
96 float the_ih = 1. / sqrt(1. / n_simhits * sum_dedx_inv2);
97
98 float mass = 0.;
99 if (the_ih > fit_res_c_) {
100 mass = momentum * sqrt((the_ih - fit_res_c_) / fit_res_k_);
101 } else {
102 ldmx_log(info) << "Track " << i << " has Ih " << the_ih
103 << " which is less than fit_res_C " << fit_res_c_;
104 mass = -100.;
105 }
106
109 mass_est.
setIh(the_ih);
114 mass_estimates.push_back(mass_est);
115 }
116
117
118 event.add("TrackDeDxMassEstimate", mass_estimates);
119}
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 setNhits(float nhits)
Set the number of hits used in the dEdx calculation.
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.