FairRoot/PandaRoot
Functions | Variables
fittest.C File Reference
#include "TF1.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TMath.h"
#include "TRandom3.h"
#include "TROOT.h"
#include "TGraphErrors.h"
#include "TFile.h"
#include <iostream>

Go to the source code of this file.

Functions

Double_t nastyFunction (Double_t *x, Double_t *par)
 
Double_t pandaResponse (Double_t *x, Double_t *par)
 
Double_t signalResponse (Double_t *x, Double_t *par)
 
Double_t breitWigner (Double_t *x, Double_t *par)
 
void setShape (Double_t stat, Double_t peaktobackground, Double_t beamresolution, Double_t resonancewidth, Double_t resonancemass)
 
void getCounts (Int_t n, Double_t *masses, Double_t *counts)
 
void fittest (Int_t nroftests=1, Char_t option[]="LQN", Double_t stat=200, Double_t peaktobackground=8, Double_t beamresolution=50., Double_t resonancewidth=500., Double_t resonancemass=3.526, Int_t seed=0, Bool_t silent=kFALSE)
 

Variables

Double_t xmin
 
Double_t xmax
 
TRandom3 * myran
 
TF1 * func =NULL
 
TF1 * fResponse =NULL
 
TF1 * fSignal =NULL
 
TF1 * fBW =NULL
 

Function Documentation

Double_t breitWigner ( Double_t x,
Double_t par 
)

Definition at line 66 of file fittest.C.

References Double_t, f1, and f2.

Referenced by fittest().

67 {
68  Double_t f1=par[0]*par[2]*par[2];
69  Double_t f2=(x[0]-par[1])*(x[0]-par[1])+par[2]*par[2]/4.;
70  return f1/f2;
71 }
TF1 * f1
Definition: reco_analys2.C:50
Double_t par[3]
Double_t
Double_t x
TFile * f2
void fittest ( Int_t  nroftests = 1,
Char_t  option[] = "LQN",
Double_t  stat = 200,
Double_t  peaktobackground = 8,
Double_t  beamresolution = 50.,
Double_t  resonancewidth = 500.,
Double_t  resonancemass = 3.526,
Int_t  seed = 0,
Bool_t  silent = kFALSE 
)

Definition at line 100 of file fittest.C.

References breitWigner(), count, Double_t, f, fabs(), fBW, fResponse, fSignal, getCounts(), i, masses, myran, seed, setShape(), signalResponse(), CAMath::Sqrt(), val, xmax, and xmin.

101 {
102  Double_t mass[2],width[2],chisqr;
103  Double_t xbins[13]={3.523, 3.525, 3.5252, 3.5254, 3.5256, 3.5258, 3.5260, 3.5262, 3.5264, 3.5266, 3.5268, 3.527, 3.529};
104  Double_t masses[12], counts[12];
105 
106  myran=new TRandom3(seed);
107 
108  xmin=xbins[0];xmax=xbins[12];
109 
110  for (Int_t i=0; i<13; i++)
111  {
112  masses[i]=(xbins[i]+xbins[i+1])/2.;
113  }
114 
115  char command[128];
116  sprintf(command,"output_stat=%i_p2b=%i_pres=%i_width=%i.root",(int) stat, (int) peaktobackground, (int) beamresolution, (int) resonancewidth);
117  TFile *f=new TFile(command,"RECREATE");
118 
119  TH1D *hisData=new TH1D("hisData","",12,xbins);
120  TH1D *his=new TH1D("hisWidth","",100,resonancewidth-10*beamresolution,resonancewidth+10*beamresolution);
121  TH1D *his2=new TH1D("hisMass","",100,-resonancewidth*2e-7+(xmin+xmax)/2.,resonancewidth*2e-7+(xmin+xmax)/2.);
122 
123  TH1D *his3=new TH1D("hiseMass","",100,0,beamresolution);
124  TH1D *his4=new TH1D("hiseWidth","",100,0,resonancewidth);
125 
126  TH2D *hisMassvsError=new TH2D("hisMassvsError","",100,-resonancewidth*2e-7+(xmin+xmax)/2.,resonancewidth*2e-7+(xmin+xmax)/2.,100,0,beamresolution);
127  TH2D *hisWidthvsError=new TH2D("hisWidthvsError","",100,resonancewidth-10*beamresolution,resonancewidth+10*beamresolution,100,0,resonancewidth);
128 
129  TH1D *hisxsq=new TH1D("hisxsq","",100,0,5);
130 
131  Double_t sumemass=0;
132  Double_t sumewidth=0;
133  Int_t count=0;
134 
135  TGraphErrors *grData=new TGraphErrors(12);
136 
137  for (Int_t i=0; i<nroftests; i++)
138  {
139  setShape(stat,peaktobackground,beamresolution,resonancewidth,resonancemass);
140  getCounts(12,masses,counts);
141  for (Int_t j=0; j<12; j++)
142  {
143  hisData->SetBinContent(j+1,counts[j]);
144  grData->SetPointError(j,0,TMath::Sqrt(counts[j]));
145  grData->SetPoint(j,masses[j],counts[j]);
146  }
147 
148  if (!silent) cout << i << " of the " << nroftests << endl;
149  Int_t retval = hisData->Fit("fResponse",option);
150  if (0==retval)
151  {
152  count++;
153  mass[0]=fResponse->GetParameter(4);
154  mass[1]=fResponse->GetParError(4);
155  width[0]=fabs(1e6*fResponse->GetParameter(5));
156  width[1]=fabs(1e6*fResponse->GetParError(5));
157  chisqr=fResponse->GetChisquare()/fResponse->GetNDF();
158 
159  if (!silent)
160  {
161  cout << "Chisq = " << chisqr << endl;
162  cout << "Mass = " << (Double_t) mass[0] << " +- " << (Double_t) mass[1] << " GeV" << endl;
163  cout << "Width = " << (Double_t) width[0] << " +- " << (Double_t) width[1] << " keV" << endl;
164  }
165  his->Fill(width[0]);
166  his2->Fill(mass[0]);
167  hisxsq->Fill(chisqr);
168 
169  his3->Fill(mass[1]*1e6);
170  his4->Fill(width[1]);
171 
172  hisMassvsError->Fill(mass[0],mass[1]*1e6);
173  hisWidthvsError->Fill(width[0],width[1]);
174 
175  sumemass+=mass[1];
176  sumewidth+=width[1];
177 
178  if (NULL==fSignal)
179  {
180  fSignal=new TF1("fSignal",signalResponse,xmin,xmax,6);
181  fSignal->SetNpx(1000);
182  fSignal->SetLineColor(kRed);
183  }
184 
185  for (Int_t i=0; i<6; i++)
186  {
187  fSignal->SetParameter(i,fResponse->GetParameter(i));
188  }
189 
190  if (NULL==fBW)
191  {
192  fBW=new TF1("fBW",breitWigner,xmin,xmax,3);
193  fBW->SetNpx(1000);
194  fBW->SetLineColor(kBlue);
195  }
196 
197  fBW->SetParameter(0,fResponse->GetParameter(0));
198  fBW->SetParameter(1,fResponse->GetParameter(4));
199  fBW->SetParameter(2,fResponse->GetParameter(5));
200 
201  }
202  if (!silent)
203  {
204  cout << "Mass error " << 1e6*sumemass/((Double_t) count) << endl;
205  cout << "Width error " << sumewidth/((Double_t) count) << endl;
206  }
207  }
208 
209  TH1D *dum=new TH1D("dum","",100,xmin,xmax);
210  dum->SetMinimum(0);
211  dum->SetMaximum(1.2*fResponse->Eval(resonancemass));
212 
213  Double_t val=1.1*fResponse->Eval(resonancemass)/fBW->Eval(resonancemass);
214  fBW->SetParameter(0,val*fBW->GetParameter(0));
215 
216  dum->Write();
217  fResponse->Write();
218  fBW->Write();
219  grData->Write();
220  hisData->Write();
221  his->Write();
222  his2->Write();
223  his3->Write();
224  his4->Write();
225  hisxsq->Write();
226  hisMassvsError->Write();
227  hisWidthvsError->Write();
228 
229  f->Close();
230 }
TRandom3 * myran
Definition: fittest.C:14
Double_t signalResponse(Double_t *x, Double_t *par)
Definition: fittest.C:52
void setShape(Double_t stat, Double_t peaktobackground, Double_t beamresolution, Double_t resonancewidth, Double_t resonancemass)
Definition: fittest.C:73
Int_t i
Definition: run_full.C:25
Double_t val[nBoxes][nFEBox]
Definition: createCalib.C:11
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double_t xmax
Definition: fittest.C:12
TF1 * fBW
Definition: fittest.C:19
TF1 * fResponse
Definition: fittest.C:17
Double_t xmin
Definition: fittest.C:11
Double_t
unsigned int seed
Double_t masses[5]
Definition: dedx_bands.C:112
TFile * f
Definition: bump_analys.C:12
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TF1 * fSignal
Definition: fittest.C:18
HISThit_ene Fill(sum_hit_ene)
Double_t breitWigner(Double_t *x, Double_t *par)
Definition: fittest.C:66
void getCounts(Int_t n, Double_t *masses, Double_t *counts)
Definition: fittest.C:91
int count
if(fWindowIsBox)
void getCounts ( Int_t  n,
Double_t masses,
Double_t counts 
)

Definition at line 91 of file fittest.C.

References fResponse, i, myran, and n.

Referenced by fittest().

92 {
93  for (Int_t i=0; i<n; i++)
94  {
95  counts[i]=myran->Poisson(fResponse->Eval(masses[i]));
96  }
97  return;
98 }
TRandom3 * myran
Definition: fittest.C:14
Int_t i
Definition: run_full.C:25
int n
TF1 * fResponse
Definition: fittest.C:17
Double_t masses[5]
Definition: dedx_bands.C:112
Double_t nastyFunction ( Double_t x,
Double_t par 
)

Definition at line 21 of file fittest.C.

References Double_t, f1, and f2.

Referenced by pandaResponse(), and signalResponse().

22 {
23  Double_t f1=TMath::Exp((-(par[0]-x[0])*(par[0]-x[0]))/(2.*par[1]*par[1]));
24  Double_t f2=(x[0]-par[2])*(x[0]-par[2])+par[3]*par[3]/4.;
25  return f1/f2;
26 }
TF1 * f1
Definition: reco_analys2.C:50
Double_t par[3]
Double_t
Double_t x
TFile * f2
Double_t pandaResponse ( Double_t x,
Double_t par 
)

Definition at line 37 of file fittest.C.

References Double_t, f1, f2, func, nastyFunction(), Pi, CAMath::Sqrt(), xmax, and xmin.

Referenced by setShape().

38 {
39  if (!func) func=new TF1("func",nastyFunction,xmin,xmax,4);
40  func->SetNpx(1000);
41  Double_t xx =x[0];
42  func->SetParameter(0,xx);
43  func->SetParameter(1,par[3]);
44  func->SetParameter(2,par[4]);
45  func->SetParameter(3,par[5]);
46  Double_t f1 = func->Integral(xx-10*par[3],xx+10*par[3]);
47  Double_t f2 = par[1]+f1*par[2]*par[5]*par[5]/(4.*TMath::Sqrt(2*TMath::Pi())*par[3]);
48  return par[0]*f2;
49 }
TF1 * f1
Definition: reco_analys2.C:50
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double_t par[3]
Double_t xmax
Definition: fittest.C:12
Double_t nastyFunction(Double_t *x, Double_t *par)
Definition: fittest.C:21
Double_t xmin
Definition: fittest.C:11
Double_t
Double_t x
TFile * f2
TF1 * func
Definition: fittest.C:16
Double_t Pi
void setShape ( Double_t  stat,
Double_t  peaktobackground,
Double_t  beamresolution,
Double_t  resonancewidth,
Double_t  resonancemass 
)

Definition at line 73 of file fittest.C.

References fResponse, pandaResponse(), xmax, and xmin.

Referenced by fittest().

74 {
75  if (NULL==fResponse)
76  {
77  fResponse=new TF1("fResponse",pandaResponse,xmin,xmax,6);
78  fResponse->SetNpx(1000);
79  }
80 
81  fResponse->SetParameter(0,stat);
82  fResponse->SetParameter(1,1./peaktobackground);
83  fResponse->FixParameter(2,1);
84  fResponse->FixParameter(3,beamresolution*1e-6);
85  fResponse->SetParameter(4,resonancemass);
86  fResponse->SetParameter(5,resonancewidth*1e-6);
87 
88  return;
89 }
Double_t xmax
Definition: fittest.C:12
TF1 * fResponse
Definition: fittest.C:17
Double_t xmin
Definition: fittest.C:11
Double_t pandaResponse(Double_t *x, Double_t *par)
Definition: fittest.C:37
Double_t signalResponse ( Double_t x,
Double_t par 
)

Definition at line 52 of file fittest.C.

References Double_t, f1, f2, func, nastyFunction(), Pi, CAMath::Sqrt(), xmax, and xmin.

Referenced by fittest().

53 {
54  if (!func) func=new TF1("func",nastyFunction,xmin,xmax,4);
55  func->SetNpx(1000);
56  Double_t xx =x[0];
57  func->SetParameter(0,xx);
58  func->SetParameter(1,par[3]);
59  func->SetParameter(2,par[4]);
60  func->SetParameter(3,par[5]);
61  Double_t f1 = func->Integral(xx-10*par[3],xx+10*par[3]);
62  Double_t f2 = f1*par[2]*par[5]*par[5]/(4.*TMath::Sqrt(2*TMath::Pi())*par[3]);
63  return par[0]*f2;
64 }
TF1 * f1
Definition: reco_analys2.C:50
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double_t par[3]
Double_t xmax
Definition: fittest.C:12
Double_t nastyFunction(Double_t *x, Double_t *par)
Definition: fittest.C:21
Double_t xmin
Definition: fittest.C:11
Double_t
Double_t x
TFile * f2
TF1 * func
Definition: fittest.C:16
Double_t Pi

Variable Documentation

TF1* fBW =NULL

Definition at line 19 of file fittest.C.

Referenced by fittest().

TF1* fResponse =NULL

Definition at line 17 of file fittest.C.

Referenced by fittest(), getCounts(), and setShape().

TF1* fSignal =NULL

Definition at line 18 of file fittest.C.

Referenced by fittest().

TF1* func =NULL

Definition at line 16 of file fittest.C.

Referenced by pandaResponse(), and signalResponse().

TRandom3* myran

Definition at line 14 of file fittest.C.

Referenced by fittest(), and getCounts().

Double_t xmax

Definition at line 12 of file fittest.C.

Referenced by fittest(), pandaResponse(), setShape(), and signalResponse().

Double_t xmin

Definition at line 11 of file fittest.C.

Referenced by fittest(), pandaResponse(), setShape(), and signalResponse().