CbmRoot
RapidityFitBlastWave.cxx
Go to the documentation of this file.
1 #include "RapidityFitBlastWave.h"
2 
3 #include "Minuit2/FCNBase.h"
4 #include "Minuit2/FunctionMinimum.h"
5 #include "Minuit2/MnHesse.h"
6 #include "Minuit2/MnMigrad.h"
7 #include "Minuit2/MnMinos.h"
8 #include "Minuit2/MnPrint.h"
9 #include "Minuit2/MnUserParameterState.h"
10 #include "Minuit2/SimplexMinimizer.h"
11 #include "TMath.h"
12 
13 #include <fstream>
14 
15 
16 using namespace ROOT::Minuit2;
17 
18 
20  double dndy(double y, double A, double eta, double T, double mass) {
21  double ret = 0.;
22  int iters = 100;
23  double deta = 2. * eta / iters;
24  for (int i = 0; i < iters; ++i) {
25  double et = -eta + (0.5 + i) * deta;
26  ret += (mass * mass / T / T + mass / T * 2. / TMath::CosH(y - et)
27  + 2. / TMath::CosH(y - et) / TMath::CosH(y - et))
28  * TMath::Exp(-mass / T * TMath::CosH(y - et));
29  }
30  return ret * deta * A * T * T * T;
31  }
32 
33  class dndyFCN : public FCNBase {
34 
35  public:
36  dndyFCN(const std::vector<double>& y_,
37  const std::vector<double>& dndy_,
38  const std::vector<double>& err_,
39  double T,
40  double mass)
41  : fPositions(y_)
42  , fMeasurements(dndy_)
43  , fErrors(err_)
44  , fT(T)
45  , fMass(mass)
46  // fPositions(y_), fMeasurements(dndy_), fErrors(err_), fT(T), fMass(mass), iter(0)
47  {}
48 
49  ~dndyFCN() {}
50 
51  double operator()(const std::vector<double>& par) const {
52  double chi2 = 0.;
53  for (unsigned int i = 0; i < fPositions.size(); ++i) {
54  double val = dndy(fPositions[i], par[0], par[1], fT, fMass);
55  chi2 += (fMeasurements[i] - val) * (fMeasurements[i] - val) / fErrors[i]
56  / fErrors[i];
57  }
58  return chi2;
59  }
60 
61  double Up() const { return 1.; }
62 
63  private:
64  std::vector<double> fPositions;
65  std::vector<double> fMeasurements;
66  std::vector<double> fErrors;
67  double fT, fMass;
68  // int iter;
69  };
70 } // namespace RapidityFitBlastWaveNamespace
71 
72 using namespace RapidityFitBlastWaveNamespace;
73 
75 
77  dndyFCN mfunc(y, dndy, err, fT, fMass);
78  std::vector<double> params(2, 0.);
79  params[0] = Parameters.A.value;
80  params[1] = Parameters.eta.value;
81  //params[2] = Parameters.yav.value;
82  MnUserParameters upar;
83  upar.Add("A",
84  Parameters.A.value,
85  Parameters.A.error,
86  Parameters.A.xmin,
87  Parameters.A.xmax);
88  upar.Add("eta",
89  Parameters.eta.value,
90  Parameters.eta.error,
91  Parameters.eta.xmin,
92  Parameters.eta.xmax);
93  //upar.Add("yav", Parameters.yav.value, Parameters.yav.error, Parameters.yav.xmin, Parameters.yav.xmax);
94  int nparams = 2;
95 
96  MnMigrad migrad(mfunc, upar);
97  //std::cout<<"start migrad "<<std::endl;
98  FunctionMinimum min = migrad();
99  MnHesse hess;
100  hess(mfunc, min);
101  RapidityFitBlastWaveParameters ret = Parameters;
102  ret.A.value = (min.UserParameters()).Params()[0];
103  ret.A.error = (min.UserParameters()).Errors()[0];
104  ret.eta.value = (min.UserParameters()).Params()[1];
105  ret.eta.error = (min.UserParameters()).Errors()[1];
106  //ret.yav.value = (min.UserParameters()).Params()[2];
107  //ret.yav.error = (min.UserParameters()).Errors()[2];
108 
109  params[0] = ret.A.value;
110  params[1] = ret.eta.value;
111  //params[2] = ret.yav.value;
112  std::cout << "A = " << params[0] << " "
113  << " eta = " << params[1] << " "
114  << " chi2/ndf = " << mfunc(params) / (y.size() - nparams)
115  << std::endl;
116 
117  ret.chi2ndf = mfunc(params) / (y.size() - nparams);
118 
119  return ret;
120 }
RapidityFitBlastWaveNamespace::dndyFCN::operator()
double operator()(const std::vector< double > &par) const
Definition: RapidityFitBlastWave.cxx:51
RapidityFitBlastWaveParameters::A
RapidityFitBlastWaveParameter A
Definition: RapidityFitBlastWave.h:29
RapidityFitBlastWave.h
RapidityFitBlastWave::~RapidityFitBlastWave
~RapidityFitBlastWave(void)
Definition: RapidityFitBlastWave.cxx:74
RapidityFitBlastWaveNamespace::dndyFCN::fT
double fT
Definition: RapidityFitBlastWave.cxx:67
RapidityFitBlastWaveNamespace::dndyFCN::fPositions
std::vector< double > fPositions
Definition: RapidityFitBlastWave.cxx:64
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
RapidityFitBlastWaveParameters
Definition: RapidityFitBlastWave.h:28
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:33
RapidityFitBlastWaveParameter::value
double value
Definition: RapidityFitBlastWave.h:10
RapidityFitBlastWaveParameters::chi2ndf
double chi2ndf
Definition: RapidityFitBlastWave.h:30
RapidityFitBlastWaveNamespace::dndyFCN::fErrors
std::vector< double > fErrors
Definition: RapidityFitBlastWave.cxx:66
RapidityFitBlastWaveNamespace::dndy
double dndy(double y, double A, double eta, double T, double mass)
Definition: RapidityFitBlastWave.cxx:20
RapidityFitBlastWaveParameter::error
double error
Definition: RapidityFitBlastWave.h:11
RapidityFitBlastWaveNamespace::dndyFCN::dndyFCN
dndyFCN(const std::vector< double > &y_, const std::vector< double > &dndy_, const std::vector< double > &err_, double T, double mass)
Definition: RapidityFitBlastWave.cxx:36
RapidityFitBlastWaveNamespace::dndyFCN::Up
double Up() const
Definition: RapidityFitBlastWave.cxx:61
RapidityFitBlastWaveParameters::eta
RapidityFitBlastWaveParameter eta
Definition: RapidityFitBlastWave.h:29
RapidityFitBlastWaveNamespace::dndyFCN::~dndyFCN
~dndyFCN()
Definition: RapidityFitBlastWave.cxx:49
RapidityFitBlastWaveNamespace::dndyFCN
Definition: RapidityFitBlastWave.cxx:33
RapidityFitBlastWaveNamespace
Definition: RapidityFitBlastWave.cxx:19
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
RapidityFitBlastWave::PerformFit
RapidityFitBlastWaveParameters PerformFit()
Definition: RapidityFitBlastWave.cxx:76
RapidityFitBlastWaveNamespace::dndyFCN::fMeasurements
std::vector< double > fMeasurements
Definition: RapidityFitBlastWave.cxx:65