All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackStoppingChi2Alg.cc
Go to the documentation of this file.
2 
3 #include "TF1.h"
4 #include "TGraph.h"
5 
6 
8  fFitRange(p.get<float>("FitRange"))
9  , fMaxdEdx(p.get<float>("MaxdEdx"))
10  , fMinHits(p.get<unsigned int>("MinHits"))
11 {
12 }
13 
14 sbn::StoppingChi2Fit sbn::TrackStoppingChi2Alg::RunFit(const std::vector<float> &dEdxVec, const std::vector<float> &resRangeVec) const
15 {
16  if (dEdxVec.size() != resRangeVec.size())
17  throw cet::exception("TrackStoppingChi2Alg") << "dEdx and Res Range do not have same length: " << dEdxVec.size() << " and " << resRangeVec.size() << std::endl;
18 
19  if (dEdxVec.size() < fMinHits)
20  return StoppingChi2Fit();
21 
22  const auto graph(std::make_unique<TGraph>(dEdxVec.size(), &resRangeVec[0], &dEdxVec[0]));
23 
24  // Try and fit a flat polynomial
25  graph->Fit("pol0", "Q");
26  const TF1* polFit = graph->GetFunction("pol0");
27  const float pol0Chi2(polFit ? polFit->GetChisquare() : -5.f);
28  const float pol0Fit(polFit ? polFit->GetParameter(0) : -5.f);
29 
30  // Try to fit an exponential
31  graph->Fit("expo", "Q");
32  const TF1* expFit = graph->GetFunction("expo");
33  const float expChi2(expFit ? expFit->GetChisquare() : -5.f);
34 
35  return StoppingChi2Fit(pol0Chi2, expChi2, pol0Fit);
36 }
37 
39 {
40 
41  std::vector<float> dEdxVec, resRangeVec;
42  // Fill the dEdx vs res range vectors, ignoring the first/last points
43  for (size_t i = 1; i < calo.dEdx().size() - 1; i++) {
44  const float thisdEdx(calo.dEdx()[i]);
45  const float thisResRange(calo.ResidualRange()[i]);
46  if (thisResRange > fFitRange || thisdEdx > fMaxdEdx)
47  continue;
48 
49  dEdxVec.push_back(thisdEdx);
50  resRangeVec.push_back(thisResRange);
51  }
52 
53  return this->RunFit(dEdxVec, resRangeVec);
54 }
55 
57 {
58  if(calo.XYZ().size() == 0)
59  return StoppingChi2Fit();
60 
61  geo::Point_t start(calo.XYZ().front());
62  geo::Point_t end(calo.XYZ().back());
63 
64  std::vector<float> dEdxVec, resRangeVec;
65  // Fill the dEdx vs res range vectors, ignoring the first/last points
66  for (size_t i = 1; i < calo.dEdx().size() - 1; i++) {
67  const float thisdEdx(calo.dEdx()[i]);
68  const float thisResRange(calo.ResidualRange()[i]);
69  if (thisResRange > fFitRange || thisdEdx > fMaxdEdx)
70  continue;
71 
72  dEdxVec.push_back(thisdEdx);
73  resRangeVec.push_back(thisResRange);
74  }
75 
76  if(fTpcGeo.MinDistToWall(start) > fTpcGeo.MinDistToWall(end))
77  {
78  std::reverse(dEdxVec.begin(), dEdxVec.end());
79  std::reverse(resRangeVec.begin(), resRangeVec.end());
80  }
81 
82  return this->RunFit(dEdxVec, resRangeVec);
83 }
pdgs p
Definition: selectors.fcl:22
const std::vector< Point_t > & XYZ() const
Definition: Calorimetry.h:114
const std::vector< float > & ResidualRange() const
Definition: Calorimetry.h:103
process_name can override from command line with o or output calo
Definition: pid.fcl:40
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
TrackStoppingChi2Alg(fhicl::ParameterSet const &p)
const std::vector< float > & dEdx() const
Definition: Calorimetry.h:101
StoppingChi2Fit RunFitForCosmicID(const anab::Calorimetry &calo) const
StoppingChi2Fit RunFit(const std::vector< float > &dEdxVec, const std::vector< float > &resRangeVec) const
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:184