CbmRoot
RapidityFit.h
Go to the documentation of this file.
1 #ifndef RAPIDITYFIT_H
2 #define RAPIDITYFIT_H
3 
4 #include <cmath>
5 #include <string>
6 #include <vector>
7 
9  bool toFit;
10  double value;
11  double error;
12  double xmin, xmax;
13  std::string name;
14  RapidityFitParameter(std::string name_ = "",
15  bool toFit_ = true,
16  double val = 1.,
17  double err = 0.,
18  double vmin = -2.,
19  double vmax = 2.)
20  : toFit(toFit_)
21  , value(val)
22  , error(err)
23  , xmin(vmin)
24  , xmax(vmax)
25  , name(name_) {}
26 };
27 
30  double chi2ndf;
31  RapidityFitParameters(double A_ = 200., double sig_ = 1., double yav_ = 0.)
32  : A(RapidityFitParameter("A", true, A_, 100., 0., 2000.))
33  , sig(RapidityFitParameter("sig", true, sig_, 0.5, 0., 10.))
34  , yav(RapidityFitParameter("yav", true, yav_, 0.3, 0., 10.))
35  , chi2ndf(1.) {
36  // A = RapidityFitParameter("A", true, A_, 100., 0., 2000.);
37  // sig = RapidityFitParameter("sig", true, sig_, 0.5, 0., 10.);
38  // yav = RapidityFitParameter("yav", true, yav_, 0.3, 0., 10.);
39  }
40  RapidityFitParameter GetParamater(const std::string& name) const {
41  if (A.name == name) return A;
42  if (sig.name == name) return sig;
43  if (yav.name == name) return yav;
44  return RapidityFitParameter();
45  }
46  void SetParameter(const std::string& name,
47  const RapidityFitParameter& param) {
48  if (A.name == name) A = param;
49  if (sig.name == name) sig = param;
50  if (yav.name == name) yav = param;
51  }
52  void SetParameter(const std::string& name,
53  double val,
54  double err,
55  double xmin,
56  double xmax) {
57  if (A.name == name)
58  A = RapidityFitParameter(name, true, val, err, xmin, xmax);
59  if (sig.name == name)
60  sig = RapidityFitParameter(name, true, val, err, xmin, xmax);
61  if (yav.name == name)
62  yav = RapidityFitParameter(name, true, val, err, xmin, xmax);
63  }
64  void SetParameterFitFlag(const std::string& name, bool toFit) {
65  if (A.name == name) A.toFit = toFit;
66  if (sig.name == name) sig.toFit = toFit;
67  if (yav.name == name) yav.toFit = toFit;
68  }
71  }
72 };
73 
74 namespace RapidityFitNamespace {
75  double TwoGauss(double y, double A, double sig, double y0);
76 };
77 
78 class RapidityFit {
79  std::vector<double> y, dndy, err;
81 
82 public:
83  RapidityFit(const std::vector<double>& y_,
84  const std::vector<double>& dndy_,
85  const std::vector<double>& err_,
86  double A_ = 200.,
87  double sig_ = 1.,
88  double yav_ = 0.2)
89  : y(y_), dndy(dndy_), err(err_), Parameters(A_, sig_, yav_) {}
90  ~RapidityFit(void);
91  void SetFitFlag(const std::string& name, bool flag) {
92  Parameters.SetParameterFitFlag(name, flag);
93  }
94  void SetData(const std::vector<double>& y_,
95  const std::vector<double>& dndy_,
96  const std::vector<double>& err_) {
97  y = y_;
98  dndy = dndy_;
99  err = err_;
100  }
101 
103 };
104 
105 #endif
RapidityFitParameter::toFit
bool toFit
Definition: RapidityFit.h:9
RapidityFitParameter::error
double error
Definition: RapidityFit.h:11
RapidityFitParameter::value
double value
Definition: RapidityFit.h:10
RapidityFitParameters
Definition: RapidityFit.h:28
RapidityFitParameters::sig
RapidityFitParameter sig
Definition: RapidityFit.h:29
RapidityFitParameters::GetParamater
RapidityFitParameter GetParamater(const std::string &name) const
Definition: RapidityFit.h:40
RapidityFit::RapidityFit
RapidityFit(const std::vector< double > &y_, const std::vector< double > &dndy_, const std::vector< double > &err_, double A_=200., double sig_=1., double yav_=0.2)
Definition: RapidityFit.h:83
RapidityFitParameters::A
RapidityFitParameter A
Definition: RapidityFit.h:29
RapidityFitParameters::SetParameter
void SetParameter(const std::string &name, const RapidityFitParameter &param)
Definition: RapidityFit.h:46
RapidityFit::SetData
void SetData(const std::vector< double > &y_, const std::vector< double > &dndy_, const std::vector< double > &err_)
Definition: RapidityFit.h:94
RapidityFitNamespace
Definition: RapidityFit.cxx:19
RapidityFit::PerformFit
RapidityFitParameters PerformFit()
Definition: RapidityFit.cxx:64
RapidityFitParameter::RapidityFitParameter
RapidityFitParameter(std::string name_="", bool toFit_=true, double val=1., double err=0., double vmin=-2., double vmax=2.)
Definition: RapidityFit.h:14
RapidityFitParameters::chi2ndf
double chi2ndf
Definition: RapidityFit.h:30
RapidityFit::err
std::vector< double > err
Definition: RapidityFit.h:79
RapidityFitParameter::xmin
double xmin
Definition: RapidityFit.h:12
RapidityFitParameters::yav
RapidityFitParameter yav
Definition: RapidityFit.h:29
RapidityFit::SetFitFlag
void SetFitFlag(const std::string &name, bool flag)
Definition: RapidityFit.h:91
RapidityFit
Definition: RapidityFit.h:78
RapidityFitNamespace::TwoGauss
double TwoGauss(double y, double A, double sig, double y0)
Definition: RapidityFit.cxx:20
RapidityFit::Parameters
RapidityFitParameters Parameters
Definition: RapidityFit.h:80
RapidityFitParameters::SetParameterFitFlag
void SetParameterFitFlag(const std::string &name, bool toFit)
Definition: RapidityFit.h:64
RapidityFitParameter::name
std::string name
Definition: RapidityFit.h:13
RapidityFitParameter
Definition: RapidityFit.h:8
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
RapidityFitParameters::RapidityFitParameters
RapidityFitParameters(double A_=200., double sig_=1., double yav_=0.)
Definition: RapidityFit.h:31
RapidityFitParameters::GetRapidityFitParameters
RapidityFitParameters GetRapidityFitParameters()
Definition: RapidityFit.h:69
RapidityFit::y
std::vector< double > y
Definition: RapidityFit.h:79
RapidityFit::~RapidityFit
~RapidityFit(void)
Definition: RapidityFit.cxx:62
RapidityFitParameter::xmax
double xmax
Definition: RapidityFit.h:12
RapidityFitParameters::SetParameter
void SetParameter(const std::string &name, double val, double err, double xmin, double xmax)
Definition: RapidityFit.h:52
RapidityFit::dndy
std::vector< double > dndy
Definition: RapidityFit.h:79