LDMX Software
EcalHelper.cxx
1#include "Ecal/EcalHelper.h"
2
3namespace ecal {
4
5std::vector<float> trackProp(const ldmx::Tracks &tracks,
6 ldmx::TrackStateType ts_type,
7 const std::string &ts_title) {
8 // Vector to hold the new track state variables
9 std::vector<float> new_track_states;
10
11 // Return if no tracks
12 if (tracks.empty()) return new_track_states;
13
14 // Otherwise loop on the tracks
15 for (auto &track : tracks) {
16 // Get track state for ts_type
17 auto trk_ts = track.getTrackState(ts_type);
18 // Continue if there's no value
19 if (!trk_ts.has_value()) continue;
20 ldmx::Track::TrackState &ecal_track_state = trk_ts.value();
21
22 // Check that the track state is filled
23 if (ecal_track_state.params_.size() < 5) continue;
24
25 float track_state_loc0 = static_cast<float>(ecal_track_state.params_[0]);
26 float track_state_loc1 = static_cast<float>(ecal_track_state.params_[1]);
27 // param 2 = phi (azimuthal), param 3 = theta (polar)
28 // param 4 = QoP
29 // ACTS (local) to LDMX (global) coordinates: (y_,z_,x_)-> (x_,y_,z_)
30 // convert qop [1/GeV] to p [MeV]
31 float p_track_state = (-1 / ecal_track_state.params_[4]) * 1000;
32 // p * sin(theta) * sin(phi)
33 float recoil_mom_x = p_track_state * sin(ecal_track_state.params_[3]) *
34 sin(ecal_track_state.params_[2]);
35 // p * cos(theta)
36 float recoil_mom_y = p_track_state * cos(ecal_track_state.params_[3]);
37 // p * sin(theta) * cos(phi)
38 float recoil_mom_z = p_track_state * sin(ecal_track_state.params_[3]) *
39 cos(ecal_track_state.params_[2]);
40
41 // Store the new track state variables
42 new_track_states.push_back(track_state_loc0);
43 new_track_states.push_back(track_state_loc1);
44 // z_-position at the ECAL (4) or Target (1)
45 if (ts_type == 4) {
46 // this should match `ECAL_SCORING_PLANE` in CKFProcessor
47 new_track_states.push_back(240.5);
48 } else if (ts_type == 1) {
49 // This should match `target_surface` in CKFProcessor
50 new_track_states.push_back(0.0);
51 }
52
53 new_track_states.push_back(recoil_mom_x);
54 new_track_states.push_back(recoil_mom_y);
55 new_track_states.push_back(recoil_mom_z);
56
57 // Break after getting the first valid track state
58 // TODO: interface this with CLUE to make sure the propageted track
59 // has an associated cluster in the ECAL
60 break;
61 }
62
63 return new_track_states;
64}
65
66// MIP tracking functions:
67
68float distTwoLines(ROOT::Math::XYZVector v1, ROOT::Math::XYZVector v2,
69 ROOT::Math::XYZVector w1, ROOT::Math::XYZVector w2) {
70 ROOT::Math::XYZVector e1 = v1 - v2;
71 ROOT::Math::XYZVector e2 = w1 - w2;
72 ROOT::Math::XYZVector crs = e1.Cross(e2);
73 if (crs.R() == 0) {
74 return 100.0; // arbitrary large number; edge case that shouldn't cause
75 // problems.
76 } else {
77 return std::abs(crs.Dot(v1 - w1) / crs.R());
78 }
79}
80
81float distPtToLine(ROOT::Math::XYZVector h1, ROOT::Math::XYZVector p1,
82 ROOT::Math::XYZVector p2) {
83 return ((h1 - p1).Cross(h1 - p2)).R() / (p1 - p2).R();
84}
85
86} // namespace ecal
Class that propagates tracks to the ECAL face.
std::vector< float > trackProp(const ldmx::Tracks &tracks, ldmx::TrackStateType ts_type, const std::string &ts_title)
Return a vector of parameters for a propagated recoil track.
Definition EcalHelper.cxx:5
float distPtToLine(ROOT::Math::XYZVector h1, ROOT::Math::XYZVector p1, ROOT::Math::XYZVector p2)
Return the minimum distance between the point h1 and the line passing through points p1 and p2.
float distTwoLines(ROOT::Math::XYZVector v1, ROOT::Math::XYZVector v2, ROOT::Math::XYZVector w1, ROOT::Math::XYZVector w2)
Returns the distance between the lines v and w, with v defined to pass through the points (v1,...