KaliVeda
Toolkit for HIC analysis
KVEvaporationSpectrum.cpp
1 #include "KVEvaporationSpectrum.h"
2 #include "TH1.h"
3 #include "TGraph.h"
4 
6 
7 
8 
11 KVEvaporationSpectrum::KVEvaporationSpectrum(const TString& name, int ncomponents, bool constrain_sigma)
12  : spe_calc{ncomponents,constrain_sigma}, TF1(name, &spe_calc, 0., 500., ncomponents*(constrain_sigma ? 3 : 4))
13 {
14  // \param[in] constrain_sigma if false, let the width of the gaussian be a free parameter
15 
16  if(ncomponents==1)
17  {
18  SetParNames("N", "B", "T");
19  SetParLimits(0,1.,1.e+09);
20  SetParLimits(1,0.,100.);
21  SetParLimits(2,1.e-2,100.);
22  if(!constrain_sigma)
23  {
24  SetParName(3, "#sigma");
25  SetParLimits(3,.1,20.);
26  }
27  }
28  else
29  {
30  int npar = constrain_sigma ? 3 : 4;
31  for(int nc=0; nc<ncomponents; ++nc)
32  {
33  SetParName(nc*npar,Form("N_%d",nc+1));
34  SetParName(nc*npar+1,Form("B_%d",nc+1));
35  SetParName(nc*npar+2,Form("T_%d",nc+1));
36  SetParLimits(nc*npar,1.,1.e+09);
37  SetParLimits(nc*npar+1,0.,100.);
38  SetParLimits(nc*npar+2,1.e-2,100.);
39  if(!constrain_sigma)
40  {
41  SetParName(nc*npar+3, Form("#sigma_%d",nc+1));
42  SetParLimits(nc*npar+3,.1,20.);
43  }
44  }
45  }
46  SetNpx(500);
47  SetLineColor(kBlue+2);
48 }
49 
50 
51 
59 
61 {
62  // Deduce initial parameter values from contents of histogram
63  //
64  // - assuming standard evaporation spectrum
65  // - position of maximum => B+T
66  // - mean value of spectrum => B+2T
67  //
68  auto npar=get_npar();
69  int ncomp = GetNComponents();
70  SetParameter(0, spec->GetEntries()/ncomp);
71  auto sp_max = spec->GetBinCenter(spec->GetMaximumBin());
72  auto sp_mean = spec->GetMean();
73  auto B = 2*sp_max - sp_mean;
74  auto T = sp_mean - sp_max;
75  SetParameter(1,B);
76  SetParameter(2,T);
77  if(npar>3)
79  if(ncomp>1)
80  {
81  for(int nc=1; nc<ncomp; ++nc)
82  {
83  SetParameter(nc*npar, spec->GetEntries()/ncomp);
84  SetParameter(nc*npar+1, B+nc*2);
85  SetParameter(nc*npar+2, T+nc*5);
86  if(npar>3)
88  }
89  }
90 }
91 
92 
93 
95 
96 TMultiGraph* KVEvaporationSpectrum::GetComponents(const std::vector<Color_t>& line_colors) const
97 {
98  static std::vector<Style_t> line_styles = {2, 7, 9, 3, 4, 5, 6, 8, 10, 11};
99  auto mg = new TMultiGraph;
100 
101  double tot_stat = 0;
102  for(int nc=0; nc<GetNComponents(); ++nc)
103  tot_stat += GetParameter(nc*get_npar());
104 
105  for(int nc=0; nc<GetNComponents(); ++nc)
106  {
107  auto g = new TGraph;
108  g->SetLineWidth(2);
109  g->SetLineStyle(line_styles[nc]);
110  g->SetLineColor(line_colors[nc]);
111 
112  g->SetTitle(Form("B=%.1f MeV T=%.1f MeV (%.0f%%)", GetParameter(nc*get_npar()+1), GetParameter(nc*get_npar()+2), 100*GetParameter(nc*get_npar())/tot_stat));
113 
114  double xmin,xmax;
115  GetRange(xmin,xmax);
116  int npoints = GetNpx();
117  auto dx = (xmax-xmin)/(npoints-1.);
118  for(int i=0; i<npoints; ++i)
119  {
120  double x = xmin+i*dx;
121  g->SetPoint(i, x, spe_calc.SC(&x,GetParameters()+nc*get_npar()));
122  }
123  mg->Add(g,"l");
124  }
125 
126  return mg;
127 }
128 
129 
130 
132 
134 {
135  auto N=par[0];
136  auto B=par[1];
137  auto T=par[2];
138  auto E=x[0];
139  if(E>=(B+T)) return N*((E-B)/pow(T,2.))*TMath::Exp(-(E-B)/T);
140  double sigma;
141  if(con_sig)
142  {
143  sigma = norm_const*T;
144  return N*TMath::Gaus(E,B+T,sigma,kTRUE);
145  }
146  sigma=par[3];
147  return (norm_const*sigma/T)*N*TMath::Gaus(E,B+T,sigma,kTRUE);
148 }
149 
150 
151 
157 
159 {
160  // return sum of Nc components
161  // par[0],[1],[2]: N,B,T of 1st component
162  // par[3],[4],[5]: N,B,T of 2nd component
163  // etc.
164 
165  double sum = 0;
166  for(int i=0; i<Nc; ++i)
167  {
168  // temperatures of components must increase
169  if(i && (par[i*3+2]<par[(i-1)*3+2]))
170  return 0;
171 
172  sum += SC(x, &par[i*3]);
173  }
174  return sum;
175 }
176 
177 
constexpr Bool_t kTRUE
#define N
Option_t Option_t SetLineColor
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t g
float xmin
float xmax
char * Form(const char *fmt,...)
Fittable parametrisation of energy spectra for evaporated particles.
void SetInitialParameters(const TH1 *)
multi_comp_spectrum_calculator spe_calc
TMultiGraph * GetComponents(const std::vector< Color_t > &line_colors={kGray+3, kGray+2, kGray+1, kGray}) const
virtual Double_t GetParameter(const TString &name) const
virtual Double_t * GetParameters() const
virtual void GetRange(Double_t &xmin, Double_t &xmax) const
virtual void SetParameter(const TString &name, Double_t value)
virtual Int_t GetNpx() const
virtual Double_t GetBinCenter(Int_t bin) const
virtual Double_t GetMean(Int_t axis=1) const
virtual Double_t GetEntries() const
virtual Int_t GetMaximumBin() const
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
const Double_t sigma
Double_t x[n]
double T(double x)
Double_t Gaus(Double_t x, Double_t mean=0, Double_t sigma=1, Bool_t norm=kFALSE)
Double_t Exp(Double_t x)
constexpr Double_t E()
Double_t Sqrt(Double_t x)
constexpr Double_t TwoPi()
ClassImp(TPyArg)