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.pos_.size() < 3 || ecal_track_state.mom_.size() < 3)
24 continue;
25
26 // pos_ is (x, y, z) in mm (LDMX global); mom_ is (px, py, pz) in MeV
27 new_track_states.push_back(static_cast<float>(ecal_track_state.pos_[0]));
28 new_track_states.push_back(static_cast<float>(ecal_track_state.pos_[1]));
29 new_track_states.push_back(static_cast<float>(ecal_track_state.pos_[2]));
30 new_track_states.push_back(static_cast<float>(ecal_track_state.mom_[0]));
31 new_track_states.push_back(static_cast<float>(ecal_track_state.mom_[1]));
32 new_track_states.push_back(static_cast<float>(ecal_track_state.mom_[2]));
33
34 // Break after getting the first valid track state
35 // TODO: interface this with CLUE to make sure the propagated track
36 // has an associated cluster in the ECAL
37 break;
38 }
39
40 return new_track_states;
41}
42
43// MIP tracking functions:
44
45float distTwoLines(ROOT::Math::XYZVector v1, ROOT::Math::XYZVector v2,
46 ROOT::Math::XYZVector w1, ROOT::Math::XYZVector w2) {
47 ROOT::Math::XYZVector e1 = v1 - v2;
48 ROOT::Math::XYZVector e2 = w1 - w2;
49 ROOT::Math::XYZVector crs = e1.Cross(e2);
50 if (crs.R() == 0) {
51 return 100.0; // arbitrary large number; edge case that shouldn't cause
52 // problems.
53 } else {
54 return std::abs(crs.Dot(v1 - w1) / crs.R());
55 }
56}
57
58float distPtToLine(ROOT::Math::XYZVector h1, ROOT::Math::XYZVector p1,
59 ROOT::Math::XYZVector p2) {
60 return ((h1 - p1).Cross(h1 - p2)).R() / (p1 - p2).R();
61}
62
63} // 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,...