All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackAlgo.cc
Go to the documentation of this file.
1 #include "TrackAlgo.h"
2 #include <numeric>
3 
4 // TODO: make this more sophisticated
6  if (track.is_contained) {
7  return numu::RangeMomentum(track);
8  }
9  else {
10  return numu::MCSMomentum(track);
11  }
12 }
13 
14 // TODO: make this more sophisticated
16  return track.range_momentum_muon;
17 }
18 
19 // TODO: make this more sophisticated
21  return track.mcs_muon.fwd_mcs_momentum;
22 }
23 
24 
26  // copy the dQdx list for partial sorting to find median
27  std::vector<float> dQdx = calo.dQdx();
28 
29  // if no or only 1 calo points, then no dQdx
30  if (dQdx.size() <= 1) return -9999.;
31 
32  // calculate the median
33  float median = -1;
34  if (dQdx.size() % 2 == 0 /* even */) {
35  const auto median_lo = dQdx.begin() + dQdx.size()/2 - 1;
36  const auto median_hi = dQdx.begin() + dQdx.size()/2;
37  std::nth_element(dQdx.begin(), median_lo, dQdx.end());
38  float median_lo_val = *median_lo;
39  std::nth_element(dQdx.begin(), median_hi, dQdx.end());
40  float median_hi_val = *median_hi;
41  median = (median_lo_val + median_hi_val) / 2.;
42  }
43  else /* odd */ {
44  const auto median_ptr = dQdx.begin() + dQdx.size()/2;
45  std::nth_element(dQdx.begin(), median_ptr, dQdx.end());
46  median = *median_ptr;
47  }
48 
49  // get the mean and variance
50  float mean = std::accumulate(dQdx.begin(), dQdx.end(), 0.) / dQdx.size();
51  float var = 0.;
52  for (float d: dQdx) {
53  var += (d - mean) * (d - mean);
54  }
55  var = var / dQdx.size();
56 
57  // truncated mean
58  float trunc_sum = 0.;
59  unsigned n_point = 0;
60  for (float d: dQdx) {
61  if (var < (d - mean) * (d - mean)) {
62  trunc_sum += d;
63  n_point ++;
64  }
65  }
66  // if no points available, return garbage
67  if (n_point == 0) return -9999.;
68 
69  return trunc_sum / n_point;
70 }
bool is_contained
is it contained in the &quot;containment volume&quot;?
Definition: RecoTrack.h:52
process_name use argoneut_mc_hitfinder track
float MeanTruncateddQdx(const anab::Calorimetry &calo)
Definition: TrackAlgo.cc:25
process_name can override from command line with o or output calo
Definition: pid.fcl:40
const std::vector< float > & dQdx() const
Definition: Calorimetry.h:102
float TrackMomentum(const numu::RecoTrack &track)
Definition: TrackAlgo.cc:5
float RangeMomentum(const numu::RecoTrack &track)
Definition: TrackAlgo.cc:15
float range_momentum_muon
Range momentum calculation of the track using range under the assumption it is a muon [GeV]...
Definition: RecoTrack.h:33
float MCSMomentum(const numu::RecoTrack &track)
Definition: TrackAlgo.cc:20
float fwd_mcs_momentum
MCS momentum calculation under hypothesis track is forward.
Definition: RecoTrack.h:14
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
MCSFitResult mcs_muon
MCS calculation result for Muon PID hypothesis.
Definition: RecoTrack.h:35