All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
larreco/larreco/RecoAlg/TrajectoryMCSFitter.h
Go to the documentation of this file.
1 #ifndef TRAJECTORYMCSFITTER_H
2 #define TRAJECTORYMCSFITTER_H
3 
4 // Framework includes
5 #include "fhiclcpp/types/Atom.h"
6 #include "fhiclcpp/types/Comment.h"
7 #include "fhiclcpp/types/Name.h"
8 #include "fhiclcpp/types/Sequence.h"
9 #include "fhiclcpp/types/Table.h"
10 
16 
17 #include <array>
18 #include <utility>
19 #include <vector>
20 
21 namespace trkf {
22  /**
23  * @file larreco/RecoAlg/TrajectoryMCSFitter.h
24  * @class trkf::TrajectoryMCSFitter
25  *
26  * @brief Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory
27  *
28  * Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory.
29  *
30  * Inputs are: a Track or Trajectory, and various fit parameters (pIdHypothesis, minNumSegments, segmentLength, pMin, pMax, pStep, angResol)
31  *
32  * Outputs are: a recob::MCSFitResult, containing:
33  * resulting momentum, momentum uncertainty, and best likelihood value (both for fwd and bwd fit);
34  * vector of comulative segment (radiation) lengths, vector of scattering angles, and PID hypothesis used in the fit.
35  * Note that the comulative segment length is what is used to compute the energy loss, but the segment length is actually slightly different,
36  * so the output can be used to reproduce the original results but they will not be identical (but very close).
37  *
38  * For configuration options see TrajectoryMCSFitter#Config
39  *
40  * @author G. Cerati (FNAL, MicroBooNE)
41  * @date 2017
42  * @version 1.0
43  */
45  //
46  public:
47  //
48  struct Config {
49  using Name = fhicl::Name;
50  using Comment = fhicl::Comment;
51  fhicl::Atom<int> pIdHypothesis {
52  Name("pIdHypothesis"),
53  Comment("Default particle Id Hypothesis to be used in the fit when not specified."),
54  13
55  };
56  fhicl::Atom<int> minNumSegments {
57  Name("minNumSegments"),
58  Comment("Minimum number of segments the track is split into."),
59  3
60  };
61  fhicl::Atom<double> segmentLength {
62  Name("segmentLength"),
63  Comment("Nominal length of track segments used in the fit."),
64  14.
65  };
66  fhicl::Atom<int> minHitsPerSegment {
67  Name("minHitsPerSegment"),
68  Comment("Exclude segments with less hits than this value."),
69  2
70  };
71  fhicl::Atom<int> nElossSteps {
72  Name("nElossSteps"),
73  Comment("Number of steps for computing energy loss uptream to current segment."),
74  10
75  };
76  fhicl::Atom<int> eLossMode {
77  Name("eLossMode"),
78  Comment("Default is MPV Landau. Choose 1 for MIP (constant); 2 for Bethe-Bloch."),
79  0
80  };
81  fhicl::Atom<double> pMin {
82  Name("pMin"),
83  Comment("Minimum momentum value in likelihood scan."),
84  0.01
85  };
86  fhicl::Atom<double> pMax {
87  Name("pMax"),
88  Comment("Maximum momentum value in likelihood scan."),
89  7.50
90  };
91  fhicl::Atom<double> pStepCoarse {
92  Name("pStepCoarse"),
93  Comment("Step in momentum value in initial coase likelihood scan."),
94  0.01
95  };
96  fhicl::Atom<double> pStep {
97  Name("pStep"),
98  Comment("Step in momentum value in fine grained likelihood scan."),
99  0.01
100  };
101  fhicl::Atom<double> fineScanWindow {
102  Name("fineScanWindow"),
103  Comment("Window size for fine grained likelihood scan around result of coarse scan."),
104  0.01
105  };
106  fhicl::Sequence<double, 5> angResol {
107  Name("angResol"),
108  Comment("Angular resolution parameters used in Highland formula. Formula is angResol[0]/(p*p) + angResol[1]/p + angResol[2] + angResol[3]*p + angResol[4]*p*p. Unit is mrad."),
109  {0.,0.,3.0,0,0}
110  };
111  fhicl::Sequence<double, 5> hlParams {
112  Name("hlParams"),
113  Comment("Parameters for tuning of Highland formula. Default is pdg value of 13.6. For values as in https://arxiv.org/abs/1703.0618 set to [0.1049,0.,11.0038,0,0]. Formula is hlParams[0]/(p*p) + hlParams[1]/p + hlParams[2] + hlParams[3]*p + hlParams[4]*p*p."),
114  {0.,0.,13.6,0,0}
115  };
116  fhicl::Atom<double> segLenTolerance {
117  Name("segLenTolerance"),
118  Comment("Tolerance in actual segment length (lower bound)."),
119  1.0
120  };
121  fhicl::Atom<bool> applySCEcorr {
122  Name("applySCEcorr"),
123  Comment("Flag to turn the Space Charge Effect correction on/off."),
124  false
125  };
126  };
127  using Parameters = fhicl::Table<Config>;
128  //
129  TrajectoryMCSFitter(int pIdHyp, int minNSegs, double segLen, int minHitsPerSegment, int nElossSteps, int eLossMode, double pMin, double pMax, double pStepCoarse, double pStep, double fineScanWindow, const std::array<double, 5>& angResol, const std::array<double, 5>& hlParams, double segLenTolerance, bool applySCEcorr){
130  pIdHyp_ = pIdHyp;
131  minNSegs_ = minNSegs;
132  segLen_ = segLen;
133  minHitsPerSegment_ = minHitsPerSegment;
134  nElossSteps_ = nElossSteps;
135  eLossMode_ = eLossMode;
136  pMin_ = pMin;
137  pMax_ = pMax;
138  pStepCoarse_ = pStepCoarse;
139  pStep_ = pStep;
140  fineScanWindow_ = fineScanWindow;
141  angResol_ = angResol;
143  segLenTolerance_ = segLenTolerance;
144  applySCEcorr_ = applySCEcorr;
145  }
146  explicit TrajectoryMCSFitter(const Parameters & p)
147  : TrajectoryMCSFitter(p().pIdHypothesis(),p().minNumSegments(),p().segmentLength(),p().minHitsPerSegment(),p().nElossSteps(),p().eLossMode(),p().pMin(),p().pMax(),p().pStepCoarse(),p().pStep(),p().fineScanWindow(),p().angResol(),p().hlParams(),p().segLenTolerance(),p().applySCEcorr()) {}
148  //
149  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj) const { return fitMcs(traj,pIdHyp_); }
150  recob::MCSFitResult fitMcs(const recob::Track& track ) const { return fitMcs(track,pIdHyp_); }
151  recob::MCSFitResult fitMcs(const recob::Trajectory& traj ) const { return fitMcs(traj,pIdHyp_); }
152  //
153  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj, int pid) const;
154  recob::MCSFitResult fitMcs(const recob::Track& track, int pid) const { return fitMcs(track.Trajectory(),pid); }
155  recob::MCSFitResult fitMcs(const recob::Trajectory& traj, int pid) const {
157  const recob::TrackTrajectory tt(traj,std::move(flags));
158  return fitMcs(tt,pid);
159  }
160  //
161  void breakTrajInSegments(const recob::TrackTrajectory& traj, std::vector<size_t>& breakpoints, std::vector<float>& segradlengths, std::vector<float>& cumseglens) const;
162  void linearRegression(const recob::TrackTrajectory& traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t& pcdir) const;
163  double mcsLikelihood(double p, double theta0x, std::vector<float>& dthetaij, std::vector<float>& seg_nradl, std::vector<float>& cumLen, bool fwd, int pid) const;
164  //
165  struct ScanResult {
166  public:
167  ScanResult(double ap, double apUnc, double alogL) : p(ap), pUnc(apUnc), logL(alogL) {}
168  double p, pUnc, logL;
169  };
170  //
171  const ScanResult doLikelihoodScan(std::vector<float>& dtheta, std::vector<float>& seg_nradlengths, std::vector<float>& cumLen, bool fwdFit, int pid, float detAngResol) const;
172  const ScanResult doLikelihoodScan(std::vector<float>& dtheta, std::vector<float>& seg_nradlengths, std::vector<float>& cumLen, bool fwdFit, int pid,
173  float pmin, float pmax, float pstep, float detAngResol) const;
174  //
175  inline double HighlandFirstTerm(const double p) const {
176  return hlParams_[0]/(p*p) + hlParams_[1]/p + hlParams_[2] + hlParams_[3]*p + hlParams_[4]*p*p;
177  }
178  inline double DetectorAngularResolution(const double uz) const {
179  return angResol_[0]/(uz*uz) + angResol_[1]/uz + angResol_[2] + angResol_[3]*uz + angResol_[4]*uz*uz;
180  }
181  double mass(int pid) const {
182  if (abs(pid)==13) { return mumass; }
183  if (abs(pid)==211) { return pimass; }
184  if (abs(pid)==321) { return kmass; }
185  if (abs(pid)==2212) { return pmass; }
186  return util::kBogusD;
187  }
188  double energyLossBetheBloch(const double mass,const double e2) const;
189  double energyLossLandau(const double mass2,const double E2, const double x) const;
190  //
191  double GetE(const double initial_E, const double length_travelled, const double mass) const;
192  //
193  int minNSegs() const { return minNSegs_; }
194  double segLen() const { return segLen_; }
195  double segLenTolerance() const { return segLenTolerance_; }
196  //
197  private:
198  int pIdHyp_;
200  double segLen_;
204  double pMin_;
205  double pMax_;
206  double pStepCoarse_;
207  double pStep_;
209  std::array<double, 5> angResol_;
210  std::array<double, 5> hlParams_;
213  };
214 }
215 
216 #endif
Data product for reconstructed trajectory in space.
double DetectorAngularResolution(const double uz) const
process_name opflash particleana ie x
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
pdgs p
Definition: selectors.fcl:22
process_name use argoneut_mc_hitfinder track
recob::MCSFitResult fitMcs(const recob::TrackTrajectory &traj) const
T abs(T value)
recob::MCSFitResult fitMcs(const recob::Trajectory &traj) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< Coord_t >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space. See recob::tracking::Coord_t for more details on the ...
Definition: TrackingTypes.h:29
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
BEGIN_PROLOG hlParams
BEGIN_PROLOG vertical distance to the surface Name
Data product for reconstructed trajectory in space.
std::vector< PointFlags_t > Flags_t
Type of point flag list.
Provides recob::Track data product.
Class storing the result of the Maximum Likelihood fit of Multiple Coulomb Scattering angles between ...
Definition: MCSFitResult.h:19
A trajectory in space reconstructed from hits.
Definition: Trajectory.h:67
TrajectoryMCSFitter(int pIdHyp, int minNSegs, double segLen, int minHitsPerSegment, int nElossSteps, int eLossMode, double pMin, double pMax, double pStepCoarse, double pStep, double fineScanWindow, const std::array< double, 5 > &angResol, const std::array< double, 5 > &hlParams, double segLenTolerance, bool applySCEcorr)
float mass
Definition: dedx.py:47
Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Trac...
recob::MCSFitResult fitMcs(const recob::Track &track, int pid) const
constexpr double kBogusD
obviously bogus double value
recob::MCSFitResult fitMcs(const recob::Trajectory &traj, int pid) const
recob::MCSFitResult fitMcs(const recob::Track &track) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: