LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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"
7 #include "fhiclcpp/types/Name.h"
9 #include "fhiclcpp/types/Table.h"
10 
16 
17 #include <array>
18 #include <utility>
19 #include <vector>
20 
21 namespace trkf {
45  //
46  public:
47  //
48  struct Config {
49  using Name = fhicl::Name;
52  Name("pIdHypothesis"),
53  Comment("Default particle Id Hypothesis to be used in the fit when not specified."),
54  13};
56  Name("minNumSegments"),
57  Comment("Minimum number of segments the track is split into."),
58  3};
60  Name("segmentLength"),
61  Comment("Nominal length of track segments used in the fit."),
62  14.};
64  Name("minHitsPerSegment"),
65  Comment("Exclude segments with less hits than this value."),
66  2};
68  Name("nElossSteps"),
69  Comment("Number of steps for computing energy loss uptream to current segment."),
70  10};
72  Name("eLossMode"),
73  Comment("Default is MPV Landau. Choose 1 for MIP (constant); 2 for Bethe-Bloch."),
74  0};
76  Comment("Minimum momentum value in likelihood scan."),
77  0.01};
79  Comment("Maximum momentum value in likelihood scan."),
80  7.50};
82  Name("pStepCoarse"),
83  Comment("Step in momentum value in initial coase likelihood scan."),
84  0.01};
86  Comment("Step in momentum value in fine grained likelihood scan."),
87  0.01};
89  Name("fineScanWindow"),
90  Comment("Window size for fine grained likelihood scan around result of coarse scan."),
91  0.01};
93  Name("angResol"),
94  Comment(
95  "Angular resolution parameters used in Highland formula. Formula is angResol[0]/(p*p) + "
96  "angResol[1]/p + angResol[2] + angResol[3]*p + angResol[4]*p*p. Unit is mrad."),
97  {0., 0., 3.0, 0, 0}};
99  Name("hlParams"),
100  Comment(
101  "Parameters for tuning of Highland formula. Default is pdg value of 13.6. For values as "
102  "in https://arxiv.org/abs/1703.0618 set to [0.1049,0.,11.0038,0,0]. Formula is "
103  "hlParams[0]/(p*p) + hlParams[1]/p + hlParams[2] + hlParams[3]*p + hlParams[4]*p*p."),
104  {0., 0., 13.6, 0, 0}};
106  Name("segLenTolerance"),
107  Comment("Tolerance in actual segment length (lower bound)."),
108  1.0};
110  Name("applySCEcorr"),
111  Comment("Flag to turn the Space Charge Effect correction on/off."),
112  false};
113  };
115  //
117  int minNSegs,
118  double segLen,
119  int minHitsPerSegment,
120  int nElossSteps,
121  int eLossMode,
122  double pMin,
123  double pMax,
124  double pStepCoarse,
125  double pStep,
126  double fineScanWindow,
127  const std::array<double, 5>& angResol,
128  const std::array<double, 5>& hlParams,
129  double segLenTolerance,
130  bool applySCEcorr)
131  {
132  pIdHyp_ = pIdHyp;
134  segLen_ = segLen;
138  pMin_ = pMin;
139  pMax_ = pMax;
141  pStep_ = pStep;
147  }
148  explicit TrajectoryMCSFitter(const Parameters& p)
150  p().minNumSegments(),
151  p().segmentLength(),
152  p().minHitsPerSegment(),
153  p().nElossSteps(),
154  p().eLossMode(),
155  p().pMin(),
156  p().pMax(),
157  p().pStepCoarse(),
158  p().pStep(),
159  p().fineScanWindow(),
160  p().angResol(),
161  p().hlParams(),
162  p().segLenTolerance(),
163  p().applySCEcorr())
164  {}
165  //
167  {
168  return fitMcs(traj, pIdHyp_);
169  }
170  recob::MCSFitResult fitMcs(const recob::Track& track) const { return fitMcs(track, pIdHyp_); }
172  {
173  return fitMcs(traj, pIdHyp_);
174  }
175  //
176  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj, int pid) const;
178  {
179  return fitMcs(track.Trajectory(), pid);
180  }
181  recob::MCSFitResult fitMcs(const recob::Trajectory& traj, int pid) const
182  {
184  const recob::TrackTrajectory tt(traj, std::move(flags));
185  return fitMcs(tt, pid);
186  }
187  //
189  std::vector<size_t>& breakpoints,
190  std::vector<float>& segradlengths,
191  std::vector<float>& cumseglens) const;
192  void linearRegression(const recob::TrackTrajectory& traj,
193  const size_t firstPoint,
194  const size_t lastPoint,
195  recob::tracking::Vector_t& pcdir) const;
196  double mcsLikelihood(double p,
197  double theta0x,
198  std::vector<float>& dthetaij,
199  std::vector<float>& seg_nradl,
200  std::vector<float>& cumLen,
201  bool fwd,
202  int pid) const;
203  //
204  struct ScanResult {
205  public:
206  ScanResult(double ap, double apUnc, double alogL) : p(ap), pUnc(apUnc), logL(alogL) {}
207  double p, pUnc, logL;
208  };
209  //
210  const ScanResult doLikelihoodScan(std::vector<float>& dtheta,
211  std::vector<float>& seg_nradlengths,
212  std::vector<float>& cumLen,
213  bool fwdFit,
214  int pid,
215  float detAngResol) const;
216  const ScanResult doLikelihoodScan(std::vector<float>& dtheta,
217  std::vector<float>& seg_nradlengths,
218  std::vector<float>& cumLen,
219  bool fwdFit,
220  int pid,
221  float pmin,
222  float pmax,
223  float pstep,
224  float detAngResol) const;
225  //
226  inline double HighlandFirstTerm(const double p) const
227  {
228  return hlParams_[0] / (p * p) + hlParams_[1] / p + hlParams_[2] + hlParams_[3] * p +
229  hlParams_[4] * p * p;
230  }
231  inline double DetectorAngularResolution(const double uz) const
232  {
233  return angResol_[0] / (uz * uz) + angResol_[1] / uz + angResol_[2] + angResol_[3] * uz +
234  angResol_[4] * uz * uz;
235  }
236  double mass(int pid) const
237  {
238  if (abs(pid) == 13) { return mumass; }
239  if (abs(pid) == 211) { return pimass; }
240  if (abs(pid) == 321) { return kmass; }
241  if (abs(pid) == 2212) { return pmass; }
242  return util::kBogusD;
243  }
244  double energyLossBetheBloch(const double mass, const double e2) const;
245  double energyLossLandau(const double mass2, const double E2, const double x) const;
246  //
247  double GetE(const double initial_E, const double length_travelled, const double mass) const;
248  //
249  int minNSegs() const { return minNSegs_; }
250  double segLen() const { return segLen_; }
251  double segLenTolerance() const { return segLenTolerance_; }
252  //
253  private:
254  int pIdHyp_;
256  double segLen_;
260  double pMin_;
261  double pMax_;
262  double pStepCoarse_;
263  double pStep_;
265  std::array<double, 5> angResol_;
266  std::array<double, 5> hlParams_;
269  };
270 }
271 
272 #endif
Float_t x
Definition: compare.C:6
ScanResult(double ap, double apUnc, double alogL)
double energyLossBetheBloch(const double mass, const double e2) const
Data product for reconstructed trajectory in space.
void breakTrajInSegments(const recob::TrackTrajectory &traj, std::vector< size_t > &breakpoints, std::vector< float > &segradlengths, std::vector< float > &cumseglens) const
double DetectorAngularResolution(const double uz) const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
Definition: Track.h:132
constexpr auto abs(T v)
Returns the absolute value of the argument.
recob::MCSFitResult fitMcs(const recob::TrackTrajectory &traj) const
const ScanResult doLikelihoodScan(std::vector< float > &dtheta, std::vector< float > &seg_nradlengths, std::vector< float > &cumLen, bool fwdFit, int pid, float detAngResol) const
TrajectoryMCSFitter(const Parameters &p)
Definition: type_traits.h:61
recob::MCSFitResult fitMcs(const recob::Trajectory &traj) const
std::array< double, 5 > angResol_
double mass(int pid) const
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:153
A trajectory in space reconstructed from hits.
double GetE(const double initial_E, const double length_travelled, const double mass) 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:31
void linearRegression(const recob::TrackTrajectory &traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t &pcdir) const
Provides recob::Track data product.
double energyLossLandau(const double mass2, const double E2, const double x) const
Data product for reconstructed trajectory in space.
std::array< double, 5 > hlParams_
std::vector< PointFlags_t > Flags_t
Type of point flag list.
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:66
double HighlandFirstTerm(const double p) const
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)
Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Trac...
double mcsLikelihood(double p, double theta0x, std::vector< float > &dthetaij, std::vector< float > &seg_nradl, std::vector< float > &cumLen, bool fwd, int pid) const
recob::MCSFitResult fitMcs(const recob::Track &track, int pid) const
constexpr double kBogusD
obviously bogus double value
fhicl::Sequence< double, 5 > hlParams
recob::MCSFitResult fitMcs(const recob::Trajectory &traj, int pid) const
Float_t track
Definition: plot.C:35
recob::MCSFitResult fitMcs(const recob::Track &track) const
fhicl::Sequence< double, 5 > angResol
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49