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/Table.h"
8 
12 
13 namespace trkf {
14  /**
15  * @file larreco/RecoAlg/TrajectoryMCSFitter.h
16  * @class trkf::TrajectoryMCSFitter
17  *
18  * @brief Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory
19  *
20  * Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory.
21  *
22  * Inputs are: a Track or Trajectory, and various fit parameters (pIdHypothesis, minNumSegments, segmentLength, pMin, pMax, pStep, angResol)
23  *
24  * Outputs are: a recob::MCSFitResult, containing:
25  * resulting momentum, momentum uncertainty, and best likelihood value (both for fwd and bwd fit);
26  * vector of comulative segment (radiation) lengths, vector of scattering angles, and PID hypothesis used in the fit.
27  * Note that the comulative segment length is what is used to compute the energy loss, but the segment length is actually slightly different,
28  * so the output can be used to reproduce the original results but they will not be identical (but very close).
29  *
30  * For configuration options see TrajectoryMCSFitter#Config
31  *
32  * @author G. Cerati (FNAL, MicroBooNE)
33  * @date 2017
34  * @version 1.0
35  */
37  //
38  public:
39  //
40  struct Config {
41  using Name = fhicl::Name;
44  Name("pIdHypothesis"),
45  Comment("Default particle Id Hypothesis to be used in the fit when not specified."),
46  13
47  };
49  Name("minNumSegments"),
50  Comment("Minimum number of segments the track is split into."),
51  3
52  };
54  Name("segmentLength"),
55  Comment("Nominal length of track segments used in the fit."),
56  14.
57  };
59  Name("minHitsPerSegment"),
60  Comment("Exclude segments with less hits than this value."),
61  2
62  };
64  Name("nElossSteps"),
65  Comment("Number of steps for computing energy loss uptream to current segment."),
66  10
67  };
69  Name("eLossMode"),
70  Comment("Default is MPV Landau. Choose 1 for MIP (constant); 2 for Bethe-Bloch."),
71  0
72  };
74  Name("pMin"),
75  Comment("Minimum momentum value in likelihood scan."),
76  0.01
77  };
79  Name("pMax"),
80  Comment("Maximum momentum value in likelihood scan."),
81  7.50
82  };
84  Name("pStepCoarse"),
85  Comment("Step in momentum value in initial coase likelihood scan."),
86  0.01
87  };
89  Name("pStep"),
90  Comment("Step in momentum value in fine grained likelihood scan."),
91  0.01
92  };
94  Name("fineScanWindow"),
95  Comment("Window size for fine grained likelihood scan around result of coarse scan."),
96  0.01
97  };
99  Name("angResol"),
100  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."),
101  {0.,0.,3.0,0,0}
102  };
104  Name("hlParams"),
105  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."),
106  {0.,0.,13.6,0,0}
107  };
109  Name("segLenTolerance"),
110  Comment("Tolerance in actual segment length (lower bound)."),
111  1.0
112  };
114  Name("applySCEcorr"),
115  Comment("Flag to turn the Space Charge Effect correction on/off."),
116  false
117  };
118  };
120  //
121  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){
122  pIdHyp_ = pIdHyp;
124  segLen_ = segLen;
128  pMin_ = pMin;
129  pMax_ = pMax;
131  pStep_ = pStep;
137  }
138  explicit TrajectoryMCSFitter(const Parameters & p)
139  : 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()) {}
140  //
141  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj) const { return fitMcs(traj,pIdHyp_); }
142  recob::MCSFitResult fitMcs(const recob::Track& track ) const { return fitMcs(track,pIdHyp_); }
143  recob::MCSFitResult fitMcs(const recob::Trajectory& traj ) const { return fitMcs(traj,pIdHyp_); }
144  //
145  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj, int pid) const;
146  recob::MCSFitResult fitMcs(const recob::Track& track, int pid) const { return fitMcs(track.Trajectory(),pid); }
147  recob::MCSFitResult fitMcs(const recob::Trajectory& traj, int pid) const {
149  const recob::TrackTrajectory tt(traj,std::move(flags));
150  return fitMcs(tt,pid);
151  }
152  //
153  void breakTrajInSegments(const recob::TrackTrajectory& traj, std::vector<size_t>& breakpoints, std::vector<float>& segradlengths, std::vector<float>& cumseglens) const;
154  void linearRegression(const recob::TrackTrajectory& traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t& pcdir) const;
155  double mcsLikelihood(double p, double theta0x, std::vector<float>& dthetaij, std::vector<float>& seg_nradl, std::vector<float>& cumLen, bool fwd, int pid) const;
156  //
157  struct ScanResult {
158  public:
159  ScanResult(double ap, double apUnc, double alogL) : p(ap), pUnc(apUnc), logL(alogL) {}
160  double p, pUnc, logL;
161  };
162  //
163  const ScanResult doLikelihoodScan(std::vector<float>& dtheta, std::vector<float>& seg_nradlengths, std::vector<float>& cumLen, bool fwdFit, int pid, float detAngResol) const;
164  const ScanResult doLikelihoodScan(std::vector<float>& dtheta, std::vector<float>& seg_nradlengths, std::vector<float>& cumLen, bool fwdFit, int pid,
165  float pmin, float pmax, float pstep, float detAngResol) const;
166  //
167  inline double HighlandFirstTerm(const double p) const {
168  return hlParams_[0]/(p*p) + hlParams_[1]/p + hlParams_[2] + hlParams_[3]*p + hlParams_[4]*p*p;
169  }
170  inline double DetectorAngularResolution(const double uz) const {
171  return angResol_[0]/(uz*uz) + angResol_[1]/uz + angResol_[2] + angResol_[3]*uz + angResol_[4]*uz*uz;
172  }
173  double mass(int pid) const {
174  if (abs(pid)==13) { return mumass; }
175  if (abs(pid)==211) { return pimass; }
176  if (abs(pid)==321) { return kmass; }
177  if (abs(pid)==2212) { return pmass; }
178  return util::kBogusD;
179  }
180  double energyLossBetheBloch(const double mass,const double e2) const;
181  double energyLossLandau(const double mass2,const double E2, const double x) const;
182  //
183  double GetE(const double initial_E, const double length_travelled, const double mass) const;
184  //
185  int minNSegs() const { return minNSegs_; }
186  double segLen() const { return segLen_; }
187  double segLenTolerance() const { return segLenTolerance_; }
188  //
189  private:
190  int pIdHyp_;
192  double segLen_;
196  double pMin_;
197  double pMax_;
198  double pStepCoarse_;
199  double pStep_;
201  std::array<double, 5> angResol_;
202  std::array<double, 5> hlParams_;
205  };
206 }
207 
208 #endif
ScanResult(double ap, double apUnc, double alogL)
double energyLossBetheBloch(const double mass, const double e2) const
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:98
ChannelGroupService::Name Name
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
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
std::array< double, 5 > angResol_
double mass(int pid) const
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
def move(depos, offset)
Definition: depos.py:107
double GetE(const double initial_E, const double length_travelled, const double mass) const
p
Definition: test.py:223
void linearRegression(const recob::TrackTrajectory &traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t &pcdir) const
double energyLossLandau(const double mass2, const double E2, const double x) const
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:67
#define Comment
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)
Definition: 018_def.c:13
Provides recob::Track data product.
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
list x
Definition: train.py:276
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
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