All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sbncode/sbncode/LArRecoProducer/LArReco/TrajectoryMCSFitter.h
Go to the documentation of this file.
1 #ifndef TRAJECTORYMCSFITTER_H
2 #define TRAJECTORYMCSFITTER_H
3 
4 #include "fhiclcpp/ParameterSet.h"
5 #include "fhiclcpp/types/Atom.h"
6 #include "fhiclcpp/types/Table.h"
7 #include "canvas/Persistency/Common/Ptr.h"
11 
12 namespace trkf::sbn {
13  /**
14  * @file larreco/RecoAlg/TrajectoryMCSFitter.h
15  * @class trkf::TrajectoryMCSFitter
16  *
17  * @brief Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory
18  *
19  * Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Track or Trajectory.
20  *
21  * Inputs are: a Track or Trajectory, and various fit parameters (pIdHypothesis, minNumSegments, segmentLength, pMin, pMax, pStep, angResol)
22  *
23  * Outputs are: a recob::MCSFitResult, containing:
24  * resulting momentum, momentum uncertainty, and best likelihood value (both for fwd and bwd fit);
25  * vector of segment (radiation) lengths, vector of scattering angles, and PID hypothesis used in the fit.
26  *
27  * For configuration options see TrajectoryMCSFitter#Config
28  *
29  * @author G. Cerati (FNAL, MicroBooNE)
30  * @date 2017
31  * @version 1.0
32  */
34  //
35  public:
36  //
37  struct Config {
38  using Name = fhicl::Name;
39  using Comment = fhicl::Comment;
40  fhicl::Atom<int> pIdHypothesis {
41  Name("pIdHypothesis"),
42  Comment("Default particle Id Hypothesis to be used in the fit when not specified."),
43  13
44  };
45  fhicl::Atom<int> minNumSegments {
46  Name("minNumSegments"),
47  Comment("Minimum number of segments the track is split into."),
48  3
49  };
50  fhicl::Atom<double> segmentLength {
51  Name("segmentLength"),
52  Comment("Nominal length of track segments used in the fit."),
53  14.
54  };
55  fhicl::Atom<int> minHitsPerSegment {
56  Name("minHitsPerSegment"),
57  Comment("Exclude segments with less hits than this value."),
58  2
59  };
60  fhicl::Atom<int> nElossSteps {
61  Name("nElossSteps"),
62  Comment("Number of steps for computing energy loss uptream to current segment."),
63  10
64  };
65  fhicl::Atom<int> eLossMode {
66  Name("eLossMode"),
67  Comment("Default is MPV Landau. Choose 1 for MIP (constant); 2 for Bethe-Bloch."),
68  0
69  };
70  fhicl::Atom<double> pMin {
71  Name("pMin"),
72  Comment("Minimum momentum value in likelihood scan."),
73  0.01
74  };
75  fhicl::Atom<double> pMax {
76  Name("pMax"),
77  Comment("Maximum momentum value in likelihood scan."),
78  7.50
79  };
80  fhicl::Atom<double> pStep {
81  Name("pStep"),
82  Comment("Step in momentum value in likelihood scan."),
83  0.01
84  };
85  fhicl::Atom<double> angResol {
86  Name("angResol"),
87  Comment("Angular resolution parameter used in modified Highland formula. Unit is mrad."),
88  3.0
89  };
90  };
91  using Parameters = fhicl::Table<Config>;
92  //
93  TrajectoryMCSFitter(int pIdHyp, int minNSegs, double segLen, int minHitsPerSegment, int nElossSteps, int eLossMode, double pMin, double pMax, double pStep, double angResol){
94  pIdHyp_ = pIdHyp;
95  minNSegs_ = minNSegs;
96  segLen_ = segLen;
97  minHitsPerSegment_ = minHitsPerSegment;
98  nElossSteps_ = nElossSteps;
99  eLossMode_ = eLossMode;
100  pMin_ = pMin;
101  pMax_ = pMax;
102  pStep_ = pStep;
103  angResol_ = angResol;
104  }
105  explicit TrajectoryMCSFitter(const Parameters & p)
106  : TrajectoryMCSFitter(p().pIdHypothesis(),p().minNumSegments(),p().segmentLength(),p().minHitsPerSegment(),p().nElossSteps(),p().eLossMode(),p().pMin(),p().pMax(),p().pStep(),p().angResol()) {}
107  //
108  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj, bool momDepConst = true) const { return fitMcs(traj,pIdHyp_,momDepConst); }
109  recob::MCSFitResult fitMcs(const recob::Track& track, bool momDepConst = true) const { return fitMcs(track,pIdHyp_,momDepConst); }
110  recob::MCSFitResult fitMcs(const recob::Trajectory& traj, bool momDepConst = true) const { return fitMcs(traj,pIdHyp_,momDepConst); }
111  //
112  recob::MCSFitResult fitMcs(const recob::TrackTrajectory& traj, int pid, bool momDepConst = true) const;
113  recob::MCSFitResult fitMcs(const recob::Track& track, int pid, bool momDepConst = true) const { return fitMcs(track.Trajectory(),pid,momDepConst); }
114  recob::MCSFitResult fitMcs(const recob::Trajectory& traj, int pid, bool momDepConst = true) const {
116  const recob::TrackTrajectory tt(traj,std::move(flags));
117  return fitMcs(tt,pid,momDepConst);
118  }
119  //
120  void breakTrajInSegments(const recob::TrackTrajectory& traj, std::vector<size_t>& breakpoints, std::vector<float>& segradlengths, std::vector<float>& cumseglens) const;
121  void linearRegression(const recob::TrackTrajectory& traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t& pcdir) const;
122  double mcsLikelihood(double p, double theta0x, std::vector<float>& dthetaij, std::vector<float>& seg_nradl, std::vector<float>& cumLen, bool fwd, bool momDepConst, int pid) const;
123  //
124  struct ScanResult {
125  public:
126  ScanResult(double ap, double apUnc, double alogL) : p(ap), pUnc(apUnc), logL(alogL) {}
127  double p, pUnc, logL;
128  };
129  //
130  const ScanResult doLikelihoodScan(std::vector<float>& dtheta, std::vector<float>& seg_nradlengths, std::vector<float>& cumLen, bool fwdFit, bool momDepConst, int pid) const;
131  //
132  inline double MomentumDependentConstant(const double p) const {
133  //these are from https://arxiv.org/abs/1703.06187
134  constexpr double a = 0.1049;
135  constexpr double c = 11.0038;
136  return (a/(p*p)) + c;
137  }
138  double mass(int pid) const {
139  if (abs(pid)==13) { return mumass; }
140  if (abs(pid)==211) { return pimass; }
141  if (abs(pid)==321) { return kmass; }
142  if (abs(pid)==2212) { return pmass; }
143  return util::kBogusD;
144  }
145  double energyLossBetheBloch(const double mass,const double e2) const;
146  double energyLossLandau(const double mass2,const double E2, const double x) const;
147  //
148  double GetE(const double initial_E, const double length_travelled, const double mass) const;
149  //
150  private:
151  int pIdHyp_;
153  double segLen_;
157  double pMin_;
158  double pMax_;
159  double pStep_;
160  double angResol_;
161  };
162 }
163 
164 #endif
double energyLossLandau(const double mass2, const double E2, const double x) const
process_name opflash particleana ie x
void breakTrajInSegments(const recob::TrackTrajectory &traj, std::vector< size_t > &breakpoints, std::vector< float > &segradlengths, std::vector< float > &cumseglens) const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
pdgs p
Definition: selectors.fcl:22
double mcsLikelihood(double p, double theta0x, std::vector< float > &dthetaij, std::vector< float > &seg_nradl, std::vector< float > &cumLen, bool fwd, bool momDepConst, int pid) const
process_name use argoneut_mc_hitfinder track
recob::MCSFitResult fitMcs(const recob::Track &track, int pid, bool momDepConst=true) const
void linearRegression(const recob::TrackTrajectory &traj, const size_t firstPoint, const size_t lastPoint, recob::tracking::Vector_t &pcdir) const
process_name gaushit a
recob::MCSFitResult fitMcs(const recob::Trajectory &traj, bool momDepConst=true) const
const ScanResult doLikelihoodScan(std::vector< float > &dtheta, std::vector< float > &seg_nradlengths, std::vector< float > &cumLen, bool fwdFit, bool momDepConst, int pid) const
T abs(T value)
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
TrajectoryMCSFitter(int pIdHyp, int minNSegs, double segLen, int minHitsPerSegment, int nElossSteps, int eLossMode, double pMin, double pMax, double pStep, double angResol)
size_t NPoints() const
Returns the number of stored trajectory points.
Definition: Trajectory.h:167
A trajectory in space reconstructed from hits.
double GetE(const double initial_E, const double length_travelled, const double mass) const
BEGIN_PROLOG vertical distance to the surface Name
std::vector< PointFlags_t > Flags_t
Type of point flag list.
recob::MCSFitResult fitMcs(const recob::Track &track, bool momDepConst=true) const
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
double energyLossBetheBloch(const double mass, const double e2) const
recob::MCSFitResult fitMcs(const recob::TrackTrajectory &traj, bool momDepConst=true) const
recob::MCSFitResult fitMcs(const recob::Trajectory &traj, int pid, bool momDepConst=true) const
constexpr double kBogusD
obviously bogus double value
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a &quot;fitted&quot; track: